2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file transparency_gui.cpp The transparency GUI. */
|
|
|
|
|
2007-04-05 07:49:04 +00:00
|
|
|
#include "stdafx.h"
|
2007-12-19 20:45:46 +00:00
|
|
|
#include "window_gui.h"
|
2007-11-10 01:17:15 +00:00
|
|
|
#include "transparency.h"
|
2007-12-29 09:24:26 +00:00
|
|
|
#include "sound_func.h"
|
2012-12-23 21:09:09 +00:00
|
|
|
#include "settings_type.h"
|
2007-11-10 01:17:15 +00:00
|
|
|
|
2011-12-15 22:22:55 +00:00
|
|
|
#include "widgets/transparency_widget.h"
|
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/sprites.h"
|
|
|
|
#include "table/strings.h"
|
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
2011-05-01 19:14:12 +00:00
|
|
|
TransparencyOptionBits _transparency_opt; ///< The bits that should be transparent.
|
|
|
|
TransparencyOptionBits _transparency_lock; ///< Prevent these bits from flipping with X.
|
2021-11-21 22:10:31 +00:00
|
|
|
TransparencyOptionBits _transparency_opt_base; ///< Separate base and extra fields for config save/load.
|
|
|
|
TransparencyOptionBits _transparency_lock_base; ///< "
|
|
|
|
TransparencyOptionBits _transparency_opt_extra; ///< "
|
|
|
|
TransparencyOptionBits _transparency_lock_extra; ///< "
|
2011-05-01 19:14:12 +00:00
|
|
|
TransparencyOptionBits _invisibility_opt; ///< The bits that should be invisible.
|
|
|
|
byte _display_opt; ///< What do we want to draw/do?
|
2020-10-20 17:20:57 +00:00
|
|
|
byte _extra_display_opt;
|
2007-04-05 07:49:04 +00:00
|
|
|
|
2021-11-21 22:10:31 +00:00
|
|
|
void PreTransparencyOptionSave()
|
|
|
|
{
|
|
|
|
auto handler = [](TransparencyOptionBits value, TransparencyOptionBits &base, TransparencyOptionBits &extra) {
|
|
|
|
base = value & 0x1FF;
|
|
|
|
extra = (value >> 9) & 0x1;
|
|
|
|
};
|
|
|
|
handler(_transparency_opt, _transparency_opt_base, _transparency_opt_extra);
|
|
|
|
handler(_transparency_lock, _transparency_lock_base, _transparency_lock_extra);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PostTransparencyOptionLoad()
|
|
|
|
{
|
|
|
|
auto handler = [](TransparencyOptionBits base, TransparencyOptionBits extra) -> TransparencyOptionBits {
|
|
|
|
return (base & 0x3FF) | ((extra & 0x1) << 9);
|
|
|
|
};
|
|
|
|
_transparency_opt = handler(_transparency_opt_base, _transparency_opt_extra);
|
|
|
|
_transparency_lock = handler(_transparency_lock_base, _transparency_lock_extra);
|
|
|
|
}
|
|
|
|
|
2009-04-10 16:24:12 +00:00
|
|
|
class TransparenciesWindow : public Window
|
|
|
|
{
|
2008-05-13 00:37:29 +00:00
|
|
|
public:
|
2013-05-26 19:23:42 +00:00
|
|
|
TransparenciesWindow(WindowDesc *desc, int window_number) : Window(desc)
|
2008-05-13 00:37:29 +00:00
|
|
|
{
|
2013-05-26 19:23:42 +00:00
|
|
|
this->InitNested(window_number);
|
2008-05-13 00:37:29 +00:00
|
|
|
}
|
2008-01-30 03:34:24 +00:00
|
|
|
|
2019-03-04 07:49:37 +00:00
|
|
|
void OnPaint() override
|
2008-05-13 00:37:29 +00:00
|
|
|
{
|
2011-02-23 20:29:48 +00:00
|
|
|
this->OnInvalidateData(0); // Must be sure that the widgets show the transparency variable changes, also when we use shortcuts.
|
2008-05-17 12:48:06 +00:00
|
|
|
this->DrawWidgets();
|
2009-07-27 21:16:13 +00:00
|
|
|
}
|
2008-05-13 00:37:29 +00:00
|
|
|
|
2019-03-04 07:49:37 +00:00
|
|
|
void DrawWidget(const Rect &r, int widget) const override
|
2009-07-27 21:16:13 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-16 16:42:04 +00:00
|
|
|
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:
|
2015-07-29 23:32:55 +00:00
|
|
|
case WID_TT_LOADING:
|
|
|
|
case WIT_TT_TUNNELS: {
|
2011-12-16 16:42:04 +00:00
|
|
|
uint i = widget - WID_TT_BEGIN;
|
2009-07-27 21:16:13 +00:00
|
|
|
if (HasBit(_transparency_lock, i)) DrawSprite(SPR_LOCK, PAL_NONE, r.left + 1, r.top + 1);
|
|
|
|
break;
|
|
|
|
}
|
2011-12-16 16:42:04 +00:00
|
|
|
case WID_TT_BUTTONS:
|
|
|
|
for (uint i = WID_TT_BEGIN; i < WID_TT_END; i++) {
|
2015-07-29 23:32:55 +00:00
|
|
|
if (i == WID_TT_LOADING || i == WIT_TT_TUNNELS) continue; // Do not draw button for invisible loading indicators.
|
2009-07-27 21:16:13 +00:00
|
|
|
|
2009-09-19 11:31:12 +00:00
|
|
|
const NWidgetBase *wi = this->GetWidget<NWidgetBase>(i);
|
2009-07-27 21:16:13 +00:00
|
|
|
DrawFrameRect(wi->pos_x + 1, r.top + 2, wi->pos_x + wi->current_x - 2, r.bottom - 2, COLOUR_PALE_GREEN,
|
2011-12-16 16:42:04 +00:00
|
|
|
HasBit(_invisibility_opt, i - WID_TT_BEGIN) ? FR_LOWERED : FR_NONE);
|
2009-07-27 21:16:13 +00:00
|
|
|
}
|
|
|
|
break;
|
2008-05-13 00:37:29 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-03 19:55:40 +00:00
|
|
|
|
2019-03-04 07:49:37 +00:00
|
|
|
void OnClick(Point pt, int widget, int click_count) override
|
2008-05-13 00:37:29 +00:00
|
|
|
{
|
2011-12-16 16:42:04 +00:00
|
|
|
if (widget >= WID_TT_BEGIN && widget < WID_TT_END) {
|
2008-05-13 00:37:29 +00:00
|
|
|
if (_ctrl_pressed) {
|
|
|
|
/* toggle the bit of the transparencies lock variable */
|
2011-12-16 16:42:04 +00:00
|
|
|
ToggleTransparencyLock((TransparencyOption)(widget - WID_TT_BEGIN));
|
2008-05-13 00:37:29 +00:00
|
|
|
this->SetDirty();
|
|
|
|
} else {
|
|
|
|
/* toggle the bit of the transparencies variable and play a sound */
|
2011-12-16 16:42:04 +00:00
|
|
|
ToggleTransparency((TransparencyOption)(widget - WID_TT_BEGIN));
|
2012-12-23 21:09:09 +00:00
|
|
|
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
|
2008-05-13 00:37:29 +00:00
|
|
|
MarkWholeScreenDirty();
|
2008-04-03 19:55:40 +00:00
|
|
|
}
|
2011-12-16 16:42:04 +00:00
|
|
|
} else if (widget == WID_TT_BUTTONS) {
|
2009-07-27 21:16:13 +00:00
|
|
|
uint i;
|
2011-12-16 16:42:04 +00:00
|
|
|
for (i = WID_TT_BEGIN; i < WID_TT_END; i++) {
|
2009-09-19 11:31:12 +00:00
|
|
|
const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(i);
|
2010-07-24 10:14:39 +00:00
|
|
|
if (IsInsideBS(pt.x, nwid->pos_x, nwid->current_x)) {
|
2009-07-27 21:16:13 +00:00
|
|
|
break;
|
2010-07-24 10:14:39 +00:00
|
|
|
}
|
2009-07-27 21:16:13 +00:00
|
|
|
}
|
2011-12-16 16:42:04 +00:00
|
|
|
if (i == WID_TT_LOADING || i == WID_TT_END) return;
|
2008-04-03 19:55:40 +00:00
|
|
|
|
2011-12-16 16:42:04 +00:00
|
|
|
ToggleInvisibility((TransparencyOption)(i - WID_TT_BEGIN));
|
2012-12-23 21:09:09 +00:00
|
|
|
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
|
2008-04-03 19:55:40 +00:00
|
|
|
|
2008-05-13 00:37:29 +00:00
|
|
|
/* Redraw whole screen only if transparency is set */
|
2011-12-16 16:42:04 +00:00
|
|
|
if (IsTransparencySet((TransparencyOption)(i - WID_TT_BEGIN))) {
|
2008-05-13 00:37:29 +00:00
|
|
|
MarkWholeScreenDirty();
|
|
|
|
} else {
|
2011-12-16 16:42:04 +00:00
|
|
|
this->SetWidgetDirty(WID_TT_BUTTONS);
|
2008-05-13 00:37:29 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-05 07:49:04 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 07:49:37 +00:00
|
|
|
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
|
2009-11-28 14:30:00 +00:00
|
|
|
{
|
|
|
|
Point pt = GetToolbarAlignedWindowPosition(sm_width);
|
2011-12-16 16:42:04 +00:00
|
|
|
pt.y += 2 * (sm_height - this->GetWidget<NWidgetBase>(WID_TT_BUTTONS)->current_y);
|
2009-11-28 14:30:00 +00:00
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
2011-03-13 21:31:29 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2019-03-04 07:49:37 +00:00
|
|
|
void OnInvalidateData(int data = 0, bool gui_scope = true) override
|
2009-07-27 21:16:13 +00:00
|
|
|
{
|
2011-03-13 21:31:29 +00:00
|
|
|
if (!gui_scope) return;
|
2011-12-16 16:42:04 +00:00
|
|
|
for (uint i = WID_TT_BEGIN; i < WID_TT_END; i++) {
|
|
|
|
this->SetWidgetLoweredState(i, IsTransparencySet((TransparencyOption)(i - WID_TT_BEGIN)));
|
2009-07-27 21:16:13 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-05 07:49:04 +00:00
|
|
|
};
|
|
|
|
|
2009-04-10 16:31:29 +00:00
|
|
|
static const NWidgetPart _nested_transparency_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
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),
|
2009-04-10 16:31:29 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2011-12-16 16:42:04 +00:00
|
|
|
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_LOADING), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_TRAINLIST, STR_TRANSPARENT_LOADING_TOOLTIP),
|
2015-07-29 23:32:55 +00:00
|
|
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WIT_TT_TUNNELS), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_ROAD_TUNNEL, STR_TRANSPARENT_TUNNELS_TOOLTIP),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(1, 1), EndContainer(),
|
2009-04-10 16:31:29 +00:00
|
|
|
EndContainer(),
|
2013-01-08 22:46:42 +00:00
|
|
|
/* Panel with 'invisibility' buttons. */
|
2011-12-16 16:42:04 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_TT_BUTTONS), SetMinimalSize(219, 13), SetDataTip(0x0, STR_TRANSPARENT_INVISIBLE_TOOLTIP),
|
2009-04-10 16:31:29 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
static WindowDesc _transparency_desc(
|
2013-05-26 19:25:01 +00:00
|
|
|
WDP_MANUAL, "toolbar_transparency", 0, 0,
|
2007-04-05 07:49:04 +00:00
|
|
|
WC_TRANSPARENCY_TOOLBAR, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
0,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_transparency_widgets, lengthof(_nested_transparency_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2007-04-05 07:49:04 +00:00
|
|
|
|
2011-05-01 19:14:12 +00:00
|
|
|
/**
|
|
|
|
* Show the transparency toolbar.
|
|
|
|
*/
|
2009-05-21 22:43:25 +00:00
|
|
|
void ShowTransparencyToolbar()
|
2007-04-05 07:49:04 +00:00
|
|
|
{
|
2008-05-13 00:37:29 +00:00
|
|
|
AllocateWindowDescFront<TransparenciesWindow>(&_transparency_desc, 0);
|
2007-04-05 07:49:04 +00:00
|
|
|
}
|