# transparency_gui.cpp

Go to the documentation of this file.

    00001 /* $Id: transparency_gui.cpp 15299 2009-01-31 20:16:06Z smatz $ */
    00002
    00005 #include "stdafx.h"
    00006 #include "openttd.h"
    00007 #include "window_gui.h"
    00008 #include "transparency.h"
    00009 #include "sound_func.h"
    00010
    00011 #include "table/sprites.h"
    00012 #include "table/strings.h"
    00013
    00014 TransparencyOptionBits _transparency_opt;
    00015 TransparencyOptionBits _transparency_lock;
    00016 TransparencyOptionBits _invisibility_opt;
    00017
    00018 class TransparenciesWindow : public Window
    00019 {
    00020   enum TransparencyToolbarWidgets{
    00021     TTW_WIDGET_SIGNS = 3,
    00022     TTW_WIDGET_TREES,
    00023     TTW_WIDGET_HOUSES,
    00024     TTW_WIDGET_INDUSTRIES,
    00025     TTW_WIDGET_BUILDINGS,
    00026     TTW_WIDGET_BRIDGES,
    00027     TTW_WIDGET_STRUCTURES,
    00028     TTW_WIDGET_CATENARY,
    00029     TTW_WIDGET_LOADING,
    00030     TTW_WIDGET_END,
    00031
    00032     /* Panel with buttons for invisibility */
    00033     TTW_BUTTONS = 12,
    00034   };
    00035
    00036 public:
    00037   TransparenciesWindow(const WindowDesc *desc, int window_number) : Window(desc, window_number)
    00038   {
    00039     this->FindWindowPlacementAndResize(desc);
    00040   }
    00041
    00042   virtual void OnPaint()
    00043   {
    00044     /* must be sure that the widgets show the transparency variable changes
    00045      * also when we use shortcuts */
    00046     for (uint i = TTW_WIDGET_SIGNS; i < TTW_WIDGET_END; i++) {
    00047       this->SetWidgetLoweredState(i, IsTransparencySet((TransparencyOption)(i - TTW_WIDGET_SIGNS)));
    00048     }
    00049
    00050     this->DrawWidgets();
    00051     for (uint i = TO_SIGNS; i < TO_END; i++) {
    00052       if (HasBit(_transparency_lock, i)) DrawSprite(SPR_LOCK, PAL_NONE, this->widget[TTW_WIDGET_SIGNS + i].left + 1, this->widget[TTW_WIDGET_SIGNS + i].top + 1);
    00053     }
    00054
    00055     /* Do not draw button for invisible loading indicators */
    00056     for (uint i = TTW_WIDGET_SIGNS; i <= TTW_WIDGET_CATENARY; i++) {
    00057       const Widget *wi = &this->widget[i];
    00058       DrawFrameRect(wi->left + 1, 38, wi->right - 1, 46, COLOUR_PALE_GREEN, HasBit(_invisibility_opt, i - TTW_WIDGET_SIGNS) ? FR_LOWERED : FR_NONE);
    00059     }
    00060   }
    00061
    00062   virtual void OnClick(Point pt, int widget)
    00063   {
    00064     if (widget >= TTW_WIDGET_SIGNS && widget < TTW_WIDGET_END) {
    00065       if (_ctrl_pressed) {
    00066         /* toggle the bit of the transparencies lock variable */
    00067         ToggleTransparencyLock((TransparencyOption)(widget - TTW_WIDGET_SIGNS));
    00068         this->SetDirty();
    00069       } else {
    00070         /* toggle the bit of the transparencies variable and play a sound */
    00071         ToggleTransparency((TransparencyOption)(widget - TTW_WIDGET_SIGNS));
    00072         SndPlayFx(SND_15_BEEP);
    00073         MarkWholeScreenDirty();
    00074       }
    00075     } else if (widget == TTW_BUTTONS) {
    00076       uint x = pt.x / 22;
    00077
    00078       if (x > TTW_WIDGET_BRIDGES - TTW_WIDGET_SIGNS) x--;
    00079       if (x > TTW_WIDGET_CATENARY - TTW_WIDGET_SIGNS) return;
    00080
    00081       ToggleInvisibility((TransparencyOption)x);
    00082       SndPlayFx(SND_15_BEEP);
    00083
    00084       /* Redraw whole screen only if transparency is set */
    00085       if (IsTransparencySet((TransparencyOption)x)) {
    00086         MarkWholeScreenDirty();
    00087       } else {
    00088         this->InvalidateWidget(TTW_BUTTONS);
    00089       }
    00090     }
    00091   }
    00092 };
    00093
    00094 static const Widget _transparency_widgets[] = {
    00095 { WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_DARK_GREEN,   0,  10,   0,  13, STR_00C5,                 STR_018B_CLOSE_WINDOW},
    00096 {  WWT_CAPTION,   RESIZE_NONE,  COLOUR_DARK_GREEN,  11, 206,   0,  13, STR_TRANSPARENCY_TOOLB,   STR_018C_WINDOW_TITLE_DRAG_THIS},
    00097 {WWT_STICKYBOX,   RESIZE_NONE,  COLOUR_DARK_GREEN, 207, 218,   0,  13, STR_NULL,                 STR_STICKY_BUTTON},
    00098
    00099 /* transparency widgets:
    00100  * transparent signs, trees, houses, industries, company's buildings, bridges, unmovable structures, catenary and loading indicators */
    00101 {   WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,   0,  21,  14,  35, SPR_IMG_SIGN,         STR_TRANSPARENT_SIGNS_DESC},
    00102 {   WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,  22,  43,  14,  35, SPR_IMG_PLANTTREES,   STR_TRANSPARENT_TREES_DESC},
    00103 {   WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,  44,  65,  14,  35, SPR_IMG_TOWN,         STR_TRANSPARENT_HOUSES_DESC},
    00104 {   WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,  66,  87,  14,  35, SPR_IMG_INDUSTRY,     STR_TRANSPARENT_INDUSTRIES_DESC},
    00105 {   WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,  88, 109,  14,  35, SPR_IMG_COMPANY_LIST, STR_TRANSPARENT_BUILDINGS_DESC},
    00106 {   WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN, 110, 152,  14,  35, SPR_IMG_BRIDGE,       STR_TRANSPARENT_BRIDGES_DESC},
    00107 {   WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN, 153, 174,  14,  35, SPR_IMG_TRANSMITTER,  STR_TRANSPARENT_STRUCTURES_DESC},
    00108 {   WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN, 175, 196,  14,  35, SPR_BUILD_X_ELRAIL,   STR_TRANSPARENT_CATENARY_DESC},
    00109 {   WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN, 197, 218,  14,  35, SPR_IMG_TRAINLIST,    STR_TRANSPARENT_LOADING_DESC},
    00110
    00111 {    WWT_PANEL,   RESIZE_NONE,  COLOUR_DARK_GREEN,   0, 218,  36,  48, 0x0,                  STR_TRANSPARENT_INVISIBLE_DESC},
    00112
    00113 {   WIDGETS_END},
    00114 };
    00115
    00116 static const WindowDesc _transparency_desc = {
    00117   WDP_ALIGN_TBR, 94, 219, 49, 219, 49,
    00118   WC_TRANSPARENCY_TOOLBAR, WC_NONE,
    00119   WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
    00120   _transparency_widgets,
    00121 };
    00122
    00123 void ShowTransparencyToolbar(void)
    00124 {
    00125   AllocateWindowDescFront<TransparenciesWindow>(&_transparency_desc, 0);
    00126 }