Files
@ r28827:f131debacb19
Branch filter:
Location: cpp/openttd-patchpack/source/src/transparency_gui.cpp - annotation
r28827:f131debacb19
7.0 KiB
text/x-c
Codechange: Use `GetVisibleRangeIterators()` in more places. (#12190)
This replaces more first/last index calculation, along with indexed array/vector access, with iterator access instead.
This replaces more first/last index calculation, along with indexed array/vector access, with iterator access instead.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r9111:983de9c5a848 r9111:983de9c5a848 r6427:94a91cd8da86 r8107:82461791b7a2 r7849:cfd99cb69695 r8157:cf41aa22cd09 r19891:7fd9bf0868c4 r7849:cfd99cb69695 r18670:f122c356353c r18670:f122c356353c r8264:d493cb51fe8a r8264:d493cb51fe8a r8264:d493cb51fe8a r21383:942c32fb8b0e r21383:942c32fb8b0e r17624:f2c5f47dceaa r17624:f2c5f47dceaa r17624:f2c5f47dceaa r17624:f2c5f47dceaa r6427:94a91cd8da86 r9196:80833565de60 r9196:80833565de60 r9196:80833565de60 r20280:ca1fc41725ff r9196:80833565de60 r20280:ca1fc41725ff r9196:80833565de60 r6496:bbfde726b81e r23499:f9bf6ad58697 r9196:80833565de60 r17377:911241be2fa4 r9273:0df9c11598cc r12523:03c4f2100c71 r8806:1fc0d9e1c2bf r28353:bfc4ab63f376 r12523:03c4f2100c71 r12523:03c4f2100c71 r18677:53c91eb23957 r18677:53c91eb23957 r18677:53c91eb23957 r18677:53c91eb23957 r18677:53c91eb23957 r18677:53c91eb23957 r18677:53c91eb23957 r18677:53c91eb23957 r27824:c503500c92b2 r28353:bfc4ab63f376 r26575:d5725bf82346 r12523:03c4f2100c71 r12523:03c4f2100c71 r26549:82dacf005b0a r26575:d5725bf82346 r28353:bfc4ab63f376 r27824:c503500c92b2 r12523:03c4f2100c71 r26575:d5725bf82346 r26549:82dacf005b0a r18677:53c91eb23957 r12523:03c4f2100c71 r12523:03c4f2100c71 r26549:82dacf005b0a r9196:80833565de60 r9196:80833565de60 r6427:94a91cd8da86 r28353:bfc4ab63f376 r9196:80833565de60 r18677:53c91eb23957 r9196:80833565de60 r9196:80833565de60 r18677:53c91eb23957 r9196:80833565de60 r9196:80833565de60 r9196:80833565de60 r18677:53c91eb23957 r19891:7fd9bf0868c4 r9196:80833565de60 r9196:80833565de60 r18677:53c91eb23957 r12523:03c4f2100c71 r18677:53c91eb23957 r13062:680961bd134a r15542:f6c6d0f8689e r12523:03c4f2100c71 r15542:f6c6d0f8689e r12523:03c4f2100c71 r27824:c503500c92b2 r8806:1fc0d9e1c2bf r18677:53c91eb23957 r19891:7fd9bf0868c4 r8806:1fc0d9e1c2bf r9196:80833565de60 r18677:53c91eb23957 r9196:80833565de60 r9196:80833565de60 r18677:53c91eb23957 r6427:94a91cd8da86 r9196:80833565de60 r6427:94a91cd8da86 r6427:94a91cd8da86 r27942:f7389062d120 r13784:714b55955586 r13784:714b55955586 r18677:53c91eb23957 r13784:714b55955586 r13784:714b55955586 r13784:714b55955586 r17476:d3b7a183536d r17476:d3b7a183536d r17476:d3b7a183536d r17476:d3b7a183536d r17476:d3b7a183536d r27942:f7389062d120 r12523:03c4f2100c71 r17476:d3b7a183536d r28353:bfc4ab63f376 r18677:53c91eb23957 r12523:03c4f2100c71 r12523:03c4f2100c71 r6427:94a91cd8da86 r6427:94a91cd8da86 r28487:2130fff7270c r11632:2ff0ad7253de r13742:180ad925befc r13742:180ad925befc r13742:180ad925befc r11632:2ff0ad7253de r11632:2ff0ad7253de r18677:53c91eb23957 r18677:53c91eb23957 r18677:53c91eb23957 r18677:53c91eb23957 r18677:53c91eb23957 r18677:53c91eb23957 r18677:53c91eb23957 r18677:53c91eb23957 r27824:c503500c92b2 r13745:49505a0400d8 r11632:2ff0ad7253de r19944:25a78576fb5e r18677:53c91eb23957 r11632:2ff0ad7253de r11632:2ff0ad7253de r11632:2ff0ad7253de r28078:5e5d6c0447b1 r20283:2a199c78224c r6427:94a91cd8da86 r13739:747ed1f003e3 r27861:6269475166e0 r11368:058349c3a02c r6427:94a91cd8da86 r17624:f2c5f47dceaa r17624:f2c5f47dceaa r17624:f2c5f47dceaa r11962:0e3a6981e508 r6427:94a91cd8da86 r9196:80833565de60 r6427:94a91cd8da86 | /*
* This file is part of OpenTTD.
* 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.
* 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.
* 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/>.
*/
/** @file transparency_gui.cpp The transparency GUI. */
#include "stdafx.h"
#include "window_gui.h"
#include "transparency.h"
#include "sound_func.h"
#include "settings_type.h"
#include "widgets/transparency_widget.h"
#include "table/sprites.h"
#include "table/strings.h"
#include "safeguards.h"
TransparencyOptionBits _transparency_opt; ///< The bits that should be transparent.
TransparencyOptionBits _transparency_lock; ///< Prevent these bits from flipping with X.
TransparencyOptionBits _invisibility_opt; ///< The bits that should be invisible.
byte _display_opt; ///< What do we want to draw/do?
class TransparenciesWindow : public Window
{
public:
TransparenciesWindow(WindowDesc *desc, int window_number) : Window(desc)
{
this->InitNested(window_number);
}
void OnPaint() override
{
this->OnInvalidateData(0); // Must be sure that the widgets show the transparency variable changes, also when we use shortcuts.
this->DrawWidgets();
}
void DrawWidget(const Rect &r, WidgetID widget) const override
{
switch (widget) {
case WID_TT_SIGNS:
case WID_TT_TREES:
case WID_TT_HOUSES:
case WID_TT_INDUSTRIES:
case WID_TT_BUILDINGS:
case WID_TT_BRIDGES:
case WID_TT_STRUCTURES:
case WID_TT_CATENARY:
case WID_TT_TEXT: {
int i = widget - WID_TT_BEGIN;
if (HasBit(_transparency_lock, i)) DrawSprite(SPR_LOCK, PAL_NONE, r.left + WidgetDimensions::scaled.fullbevel.left, r.top + WidgetDimensions::scaled.fullbevel.top);
break;
}
case WID_TT_BUTTONS: {
const Rect fr = r.Shrink(WidgetDimensions::scaled.framerect);
for (WidgetID i = WID_TT_BEGIN; i < WID_TT_END; i++) {
if (i == WID_TT_TEXT) continue; // Loading and cost/income text has no invisibility button.
const Rect wr = this->GetWidget<NWidgetBase>(i)->GetCurrentRect().Shrink(WidgetDimensions::scaled.fullbevel);
DrawFrameRect(wr.left, fr.top, wr.right, fr.bottom, COLOUR_PALE_GREEN,
HasBit(_invisibility_opt, i - WID_TT_BEGIN) ? FR_LOWERED : FR_NONE);
}
break;
}
}
}
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
{
if (widget >= WID_TT_BEGIN && widget < WID_TT_END) {
if (_ctrl_pressed) {
/* toggle the bit of the transparencies lock variable */
ToggleTransparencyLock((TransparencyOption)(widget - WID_TT_BEGIN));
this->SetDirty();
} else {
/* toggle the bit of the transparencies variable and play a sound */
ToggleTransparency((TransparencyOption)(widget - WID_TT_BEGIN));
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
MarkWholeScreenDirty();
}
} else if (widget == WID_TT_BUTTONS) {
uint i;
for (i = WID_TT_BEGIN; i < WID_TT_END; i++) {
const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(i);
if (IsInsideBS(pt.x, nwid->pos_x, nwid->current_x)) {
break;
}
}
if (i == WID_TT_TEXT|| i == WID_TT_END) return;
ToggleInvisibility((TransparencyOption)(i - WID_TT_BEGIN));
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
/* Redraw whole screen only if transparency is set */
if (IsTransparencySet((TransparencyOption)(i - WID_TT_BEGIN))) {
MarkWholeScreenDirty();
} else {
this->SetWidgetDirty(WID_TT_BUTTONS);
}
}
}
Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
{
Point pt = GetToolbarAlignedWindowPosition(sm_width);
pt.y += 2 * (sm_height - this->GetWidget<NWidgetBase>(WID_TT_BUTTONS)->current_y);
return pt;
}
/**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @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.
*/
void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
{
if (!gui_scope) return;
for (WidgetID i = WID_TT_BEGIN; i < WID_TT_END; i++) {
this->SetWidgetLoweredState(i, IsTransparencySet((TransparencyOption)(i - WID_TT_BEGIN)));
}
}
};
static constexpr NWidgetPart _nested_transparency_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_TRANSPARENCY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_SIGNS), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_SIGN, STR_TRANSPARENT_SIGNS_TOOLTIP),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_TREES), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_PLANTTREES, STR_TRANSPARENT_TREES_TOOLTIP),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_HOUSES), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_TOWN, STR_TRANSPARENT_HOUSES_TOOLTIP),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_INDUSTRIES), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_INDUSTRY, STR_TRANSPARENT_INDUSTRIES_TOOLTIP),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_BUILDINGS), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_COMPANY_LIST, STR_TRANSPARENT_BUILDINGS_TOOLTIP),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_BRIDGES), SetMinimalSize(43, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BRIDGE, STR_TRANSPARENT_BRIDGES_TOOLTIP),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_STRUCTURES), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_TRANSMITTER, STR_TRANSPARENT_STRUCTURES_TOOLTIP),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_CATENARY), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_BUILD_X_ELRAIL, STR_TRANSPARENT_CATENARY_TOOLTIP),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_TEXT), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_TRAINLIST, STR_TRANSPARENT_TEXT_TOOLTIP),
NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(1, 1), EndContainer(),
EndContainer(),
/* Panel with 'invisibility' buttons. */
NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_TT_BUTTONS), SetMinimalSize(219, 13), SetDataTip(0x0, STR_TRANSPARENT_INVISIBLE_TOOLTIP),
EndContainer(),
};
static WindowDesc _transparency_desc(__FILE__, __LINE__,
WDP_MANUAL, "toolbar_transparency", 0, 0,
WC_TRANSPARENCY_TOOLBAR, WC_NONE,
0,
std::begin(_nested_transparency_widgets), std::end(_nested_transparency_widgets)
);
/**
* Show the transparency toolbar.
*/
void ShowTransparencyToolbar()
{
AllocateWindowDescFront<TransparenciesWindow>(&_transparency_desc, 0);
}
|