Hotfix: Conditional order comparator dropdown list was broken.
[openttd-joker.git] / src / transparency_gui.cpp
blob2aa4e764fc478920c117f718e446a1fe9a241cc0
1 /* $Id: transparency_gui.cpp 25290 2013-05-26 19:25:01Z frosch $ */
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
10 /** @file transparency_gui.cpp The transparency GUI. */
12 #include "stdafx.h"
13 #include "window_gui.h"
14 #include "transparency.h"
15 #include "sound_func.h"
16 #include "settings_type.h"
18 #include "widgets/transparency_widget.h"
20 #include "table/sprites.h"
21 #include "table/strings.h"
23 #include "safeguards.h"
25 TransparencyOptionBits _transparency_opt; ///< The bits that should be transparent.
26 TransparencyOptionBits _transparency_lock; ///< Prevent these bits from flipping with X.
27 TransparencyOptionBits _invisibility_opt; ///< The bits that should be invisible.
28 byte _display_opt; ///< What do we want to draw/do?
30 class TransparenciesWindow : public Window
32 public:
33 TransparenciesWindow(WindowDesc *desc, int window_number) : Window(desc)
35 this->InitNested(window_number);
38 virtual void OnPaint()
40 this->OnInvalidateData(0); // Must be sure that the widgets show the transparency variable changes, also when we use shortcuts.
41 this->DrawWidgets();
44 virtual void DrawWidget(const Rect &r, int widget) const
46 switch (widget) {
47 case WID_TT_SIGNS:
48 case WID_TT_TREES:
49 case WID_TT_HOUSES:
50 case WID_TT_INDUSTRIES:
51 case WID_TT_BUILDINGS:
52 case WID_TT_BRIDGES:
53 case WID_TT_STRUCTURES:
54 case WID_TT_CATENARY:
55 case WID_TT_LOADING:
56 case WIT_TT_TUNNELS: {
57 uint i = widget - WID_TT_BEGIN;
58 if (HasBit(_transparency_lock, i)) DrawSprite(SPR_LOCK, PAL_NONE, r.left + 1, r.top + 1);
59 break;
61 case WID_TT_BUTTONS:
62 for (uint i = WID_TT_BEGIN; i < WID_TT_END; i++) {
63 if (i == WID_TT_LOADING || i == WIT_TT_TUNNELS) continue; // Do not draw button for invisible loading indicators.
65 const NWidgetBase *wi = this->GetWidget<NWidgetBase>(i);
66 DrawFrameRect(wi->pos_x + 1, r.top + 2, wi->pos_x + wi->current_x - 2, r.bottom - 2, COLOUR_PALE_GREEN,
67 HasBit(_invisibility_opt, i - WID_TT_BEGIN) ? FR_LOWERED : FR_NONE);
69 break;
73 virtual void OnClick(Point pt, int widget, int click_count)
75 if (widget >= WID_TT_BEGIN && widget < WID_TT_END) {
76 if (_ctrl_pressed) {
77 /* toggle the bit of the transparencies lock variable */
78 ToggleTransparencyLock((TransparencyOption)(widget - WID_TT_BEGIN));
79 this->SetDirty();
80 } else {
81 /* toggle the bit of the transparencies variable and play a sound */
82 ToggleTransparency((TransparencyOption)(widget - WID_TT_BEGIN));
83 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
84 MarkWholeScreenDirty();
86 } else if (widget == WID_TT_BUTTONS) {
87 uint i;
88 for (i = WID_TT_BEGIN; i < WID_TT_END; i++) {
89 const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(i);
90 if (IsInsideBS(pt.x, nwid->pos_x, nwid->current_x)) {
91 break;
94 if (i == WID_TT_LOADING || i == WID_TT_END) return;
96 ToggleInvisibility((TransparencyOption)(i - WID_TT_BEGIN));
97 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
99 /* Redraw whole screen only if transparency is set */
100 if (IsTransparencySet((TransparencyOption)(i - WID_TT_BEGIN))) {
101 MarkWholeScreenDirty();
102 } else {
103 this->SetWidgetDirty(WID_TT_BUTTONS);
108 virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
110 Point pt = GetToolbarAlignedWindowPosition(sm_width);
111 pt.y += 2 * (sm_height - this->GetWidget<NWidgetBase>(WID_TT_BUTTONS)->current_y);
112 return pt;
116 * Some data on this window has become invalid.
117 * @param data Information about the changed data.
118 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
120 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
122 if (!gui_scope) return;
123 for (uint i = WID_TT_BEGIN; i < WID_TT_END; i++) {
124 this->SetWidgetLoweredState(i, IsTransparencySet((TransparencyOption)(i - WID_TT_BEGIN)));
129 static const NWidgetPart _nested_transparency_widgets[] = {
130 NWidget(NWID_HORIZONTAL),
131 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
132 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_TRANSPARENCY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
133 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
134 EndContainer(),
135 NWidget(NWID_HORIZONTAL),
136 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_SIGNS), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_SIGN, STR_TRANSPARENT_SIGNS_TOOLTIP),
137 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_TREES), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_PLANTTREES, STR_TRANSPARENT_TREES_TOOLTIP),
138 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_HOUSES), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_TOWN, STR_TRANSPARENT_HOUSES_TOOLTIP),
139 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_INDUSTRIES), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_INDUSTRY, STR_TRANSPARENT_INDUSTRIES_TOOLTIP),
140 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_BUILDINGS), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_COMPANY_LIST, STR_TRANSPARENT_BUILDINGS_TOOLTIP),
141 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_BRIDGES), SetMinimalSize(43, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BRIDGE, STR_TRANSPARENT_BRIDGES_TOOLTIP),
142 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_STRUCTURES), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_TRANSMITTER, STR_TRANSPARENT_STRUCTURES_TOOLTIP),
143 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_CATENARY), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_BUILD_X_ELRAIL, STR_TRANSPARENT_CATENARY_TOOLTIP),
144 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_LOADING), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_TRAINLIST, STR_TRANSPARENT_LOADING_TOOLTIP),
145 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WIT_TT_TUNNELS), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_ROAD_TUNNEL, STR_TRANSPARENT_TUNNELS_TOOLTIP),
146 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(1, 1), EndContainer(),
147 EndContainer(),
148 /* Panel with 'invisibility' buttons. */
149 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_TT_BUTTONS), SetMinimalSize(219, 13), SetDataTip(0x0, STR_TRANSPARENT_INVISIBLE_TOOLTIP),
150 EndContainer(),
153 static WindowDesc _transparency_desc(
154 WDP_MANUAL, "toolbar_transparency", 0, 0,
155 WC_TRANSPARENCY_TOOLBAR, WC_NONE,
157 _nested_transparency_widgets, lengthof(_nested_transparency_widgets)
161 * Show the transparency toolbar.
163 void ShowTransparencyToolbar()
165 AllocateWindowDescFront<TransparenciesWindow>(&_transparency_desc, 0);