peter1138@6427: /* $Id$ */ peter1138@6427: rubidium@9111: /** @file transparency_gui.cpp The transparency GUI. */ rubidium@9111: peter1138@6427: #include "stdafx.h" peter1138@6427: #include "openttd.h" peter1138@6427: #include "gui.h" rubidium@8107: #include "window_gui.h" peter1138@6427: #include "variables.h" belugas@7849: #include "transparency.h" rubidium@8157: #include "sound_func.h" belugas@7849: rubidium@8264: #include "table/sprites.h" rubidium@8264: #include "table/strings.h" rubidium@8264: belugas@7849: TransparencyOptionBits _transparency_opt; maedhros@8527: TransparencyOptionBits _transparency_lock; smatz@8806: TransparencyOptionBits _invisibility_opt; peter1138@6427: belugas@6496: enum TransparencyToolbarWidgets{ belugas@6496: TTW_WIDGET_SIGNS = 3, ///< Make signs background transparent belugas@6496: TTW_WIDGET_TREES, ///< Make trees transparent belugas@6496: TTW_WIDGET_HOUSES, ///< Make houses transparent belugas@6496: TTW_WIDGET_INDUSTRIES, ///< Make Industries transparent belugas@6496: TTW_WIDGET_BUILDINGS, ///< Make player buildings and structures transparent belugas@6496: TTW_WIDGET_BRIDGES, ///< Make bridges transparent belugas@6496: TTW_WIDGET_STRUCTURES, ///< Make unmovable structures transparent smatz@8528: TTW_WIDGET_CATENARY, ///< Make catenary transparent peter1138@8657: TTW_WIDGET_LOADING, ///< Make loading indicators transparent peter1138@6598: TTW_WIDGET_END, ///< End of toggle buttons smatz@8806: smatz@8806: /* Panel with buttons for invisibility */ smatz@8806: TTW_BUTTONS = 12, ///< Panel with 'invisibility' buttons belugas@6496: }; belugas@6496: peter1138@6427: static void TransparencyToolbWndProc(Window *w, WindowEvent *e) peter1138@6427: { peter1138@6427: switch (e->event) { peter1138@6427: case WE_PAINT: belugas@6496: /* must be sure that the widgets show the transparency variable changes belugas@6496: * also when we use shortcuts */ peter1138@6598: for (uint i = TTW_WIDGET_SIGNS; i < TTW_WIDGET_END; i++) { rubidium@7997: w->SetWidgetLoweredState(i, IsTransparencySet((TransparencyOption)(i - TTW_WIDGET_SIGNS))); peter1138@6427: } belugas@8448: peter1138@6427: DrawWindowWidgets(w); maedhros@8527: for (uint i = TO_SIGNS; i < TO_END; i++) { maedhros@8527: if (HasBit(_transparency_lock, i)) DrawSprite(SPR_LOCK, PAL_NONE, w->widget[TTW_WIDGET_SIGNS + i].left + 1, w->widget[TTW_WIDGET_SIGNS + i].top + 1); maedhros@8527: } smatz@8806: smatz@8806: /* Do not draw button for invisible loading indicators */ smatz@8806: for (uint i = 0; i < 8; i++) { smatz@8806: if (i < TTW_WIDGET_BRIDGES - TTW_WIDGET_SIGNS) { smatz@8806: DrawFrameRect(i * 22, 38, i * 22 + 19, 46, true, HasBit(_invisibility_opt, i) ? FR_LOWERED : FR_NONE); smatz@8806: } else if (i == TTW_WIDGET_BRIDGES - TTW_WIDGET_SIGNS) { smatz@8806: DrawFrameRect(i * 22, 38, i * 22 + 41, 46, true, HasBit(_invisibility_opt, i) ? FR_LOWERED : FR_NONE); smatz@8806: } else { // i > TTW_WIDGET_BRIDGES - TTW_WIDGET_SIGNS smatz@8806: DrawFrameRect((i + 1) * 22, 38, (i + 1) * 22 + 19, 46, true, HasBit(_invisibility_opt, i) ? FR_LOWERED : FR_NONE); smatz@8806: } smatz@8806: } smatz@8806: peter1138@6427: break; peter1138@6427: peter1138@6427: case WE_CLICK: smatz@8528: if (e->we.click.widget >= TTW_WIDGET_SIGNS && e->we.click.widget < TTW_WIDGET_END) { maedhros@8527: if (_ctrl_pressed) { maedhros@8527: /* toggle the bit of the transparencies lock variable */ maedhros@8527: ToggleTransparencyLock((TransparencyOption)(e->we.click.widget - TTW_WIDGET_SIGNS)); maedhros@8527: SetWindowDirty(w); maedhros@8527: } else { maedhros@8527: /* toggle the bit of the transparencies variable and play a sound */ maedhros@8527: ToggleTransparency((TransparencyOption)(e->we.click.widget - TTW_WIDGET_SIGNS)); maedhros@8527: SndPlayFx(SND_15_BEEP); maedhros@8527: MarkWholeScreenDirty(); maedhros@8527: } smatz@8806: } else if (e->we.click.widget == TTW_BUTTONS) { smatz@8806: uint x = e->we.click.pt.x / 22; smatz@8806: smatz@8806: if (x > TTW_WIDGET_BRIDGES - TTW_WIDGET_SIGNS) x--; smatz@8806: if (x > TTW_WIDGET_CATENARY - TTW_WIDGET_SIGNS) break; smatz@8806: smatz@8806: ToggleInvisibility((TransparencyOption)x); smatz@8806: SndPlayFx(SND_15_BEEP); smatz@8806: smatz@8806: /* Redraw whole screen only if transparency is set */ smatz@8806: if (IsTransparencySet((TransparencyOption)x)) { smatz@8806: MarkWholeScreenDirty(); smatz@8806: } else { smatz@8806: w->InvalidateWidget(TTW_BUTTONS); smatz@8806: } peter1138@6427: } smatz@8806: peter1138@6427: break; peter1138@6427: } peter1138@6427: } peter1138@6427: peter1138@6427: static const Widget _transparency_widgets[] = { peter1138@6427: { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, smatz@8528: { WWT_CAPTION, RESIZE_NONE, 7, 11, 206, 0, 13, STR_TRANSPARENCY_TOOLB, STR_018C_WINDOW_TITLE_DRAG_THIS}, smatz@8528: {WWT_STICKYBOX, RESIZE_NONE, 7, 207, 218, 0, 13, STR_NULL, STR_STICKY_BUTTON}, peter1138@6427: belugas@6496: /* transparency widgets: peter1138@8657: * transparent signs, trees, houses, industries, player's buildings, bridges, unmovable structures, catenary and loading indicators */ maedhros@6600: { WWT_IMGBTN, RESIZE_NONE, 7, 0, 21, 14, 35, SPR_IMG_SIGN, STR_TRANSPARENT_SIGNS_DESC}, peter1138@6427: { WWT_IMGBTN, RESIZE_NONE, 7, 22, 43, 14, 35, SPR_IMG_PLANTTREES, STR_TRANSPARENT_TREES_DESC}, peter1138@6427: { WWT_IMGBTN, RESIZE_NONE, 7, 44, 65, 14, 35, SPR_IMG_TOWN, STR_TRANSPARENT_HOUSES_DESC}, peter1138@6427: { WWT_IMGBTN, RESIZE_NONE, 7, 66, 87, 14, 35, SPR_IMG_INDUSTRY, STR_TRANSPARENT_INDUSTRIES_DESC}, peter1138@6427: { WWT_IMGBTN, RESIZE_NONE, 7, 88, 109, 14, 35, SPR_IMG_COMPANY_LIST, STR_TRANSPARENT_BUILDINGS_DESC}, peter1138@6427: { WWT_IMGBTN, RESIZE_NONE, 7, 110, 152, 14, 35, SPR_IMG_BRIDGE, STR_TRANSPARENT_BRIDGES_DESC}, peter1138@6427: { WWT_IMGBTN, RESIZE_NONE, 7, 153, 174, 14, 35, SPR_IMG_TRANSMITTER, STR_TRANSPARENT_STRUCTURES_DESC}, smatz@8528: { WWT_IMGBTN, RESIZE_NONE, 7, 175, 196, 14, 35, SPR_BUILD_X_ELRAIL, STR_TRANSPARENT_CATENARY_DESC}, smatz@8528: { WWT_IMGBTN, RESIZE_NONE, 7, 197, 218, 14, 35, SPR_IMG_TRAINLIST, STR_TRANSPARENT_LOADING_DESC}, peter1138@6427: smatz@8806: { WWT_PANEL, RESIZE_NONE, 7, 0, 218, 36, 48, 0x0, STR_TRANSPARENT_INVISIBLE_DESC}, smatz@8806: peter1138@6427: { WIDGETS_END}, peter1138@6427: }; peter1138@6427: peter1138@6427: static const WindowDesc _transparency_desc = { smatz@8806: WDP_ALIGN_TBR, 58+36, 219, 49, 219, 49, peter1138@6427: WC_TRANSPARENCY_TOOLBAR, WC_NONE, peter1138@6427: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, peter1138@6427: _transparency_widgets, peter1138@6427: TransparencyToolbWndProc peter1138@6427: }; peter1138@6427: peter1138@6427: void ShowTransparencyToolbar(void) peter1138@6427: { peter1138@6427: AllocateWindowDescFront(&_transparency_desc, 0); peter1138@6427: }