mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
(svn r16970) -Codechange: Transparency window uses nested widgets only.
This commit is contained in:
parent
1d180848d6
commit
a1d236f3b8
@ -7,6 +7,7 @@
|
|||||||
#include "window_gui.h"
|
#include "window_gui.h"
|
||||||
#include "transparency.h"
|
#include "transparency.h"
|
||||||
#include "sound_func.h"
|
#include "sound_func.h"
|
||||||
|
#include "core/math_func.hpp"
|
||||||
|
|
||||||
#include "table/sprites.h"
|
#include "table/sprites.h"
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
@ -41,28 +42,42 @@ enum TransparencyToolbarWidgets {
|
|||||||
class TransparenciesWindow : public Window
|
class TransparenciesWindow : public Window
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TransparenciesWindow(const WindowDesc *desc, int window_number) : Window(desc, window_number)
|
TransparenciesWindow(const WindowDesc *desc, int window_number) : Window()
|
||||||
{
|
{
|
||||||
this->FindWindowPlacementAndResize(desc);
|
this->InitNested(desc, window_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnPaint()
|
virtual void OnPaint()
|
||||||
{
|
{
|
||||||
/* must be sure that the widgets show the transparency variable changes
|
OnInvalidateData(0); // Must be sure that the widgets show the transparency variable changes, also when we use shortcuts.
|
||||||
* also when we use shortcuts */
|
|
||||||
for (uint i = TTW_WIDGET_BEGIN; i < TTW_WIDGET_END; i++) {
|
|
||||||
this->SetWidgetLoweredState(i, IsTransparencySet((TransparencyOption)(i - TTW_WIDGET_BEGIN)));
|
|
||||||
}
|
|
||||||
|
|
||||||
this->DrawWidgets();
|
this->DrawWidgets();
|
||||||
for (uint i = TO_SIGNS; i < TO_END; i++) {
|
}
|
||||||
if (HasBit(_transparency_lock, i)) DrawSprite(SPR_LOCK, PAL_NONE, this->widget[TTW_WIDGET_BEGIN + i].left + 1, this->widget[TTW_WIDGET_BEGIN + i].top + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Do not draw button for invisible loading indicators */
|
virtual void DrawWidget(const Rect &r, int widget) const
|
||||||
for (uint i = TTW_WIDGET_BEGIN; i <= TTW_WIDGET_CATENARY; i++) {
|
{
|
||||||
const Widget *wi = &this->widget[i];
|
switch (widget) {
|
||||||
DrawFrameRect(wi->left + 1, 38, wi->right - 1, 46, COLOUR_PALE_GREEN, HasBit(_invisibility_opt, i - TTW_WIDGET_BEGIN) ? FR_LOWERED : FR_NONE);
|
case TTW_WIDGET_SIGNS:
|
||||||
|
case TTW_WIDGET_TREES:
|
||||||
|
case TTW_WIDGET_HOUSES:
|
||||||
|
case TTW_WIDGET_INDUSTRIES:
|
||||||
|
case TTW_WIDGET_BUILDINGS:
|
||||||
|
case TTW_WIDGET_BRIDGES:
|
||||||
|
case TTW_WIDGET_STRUCTURES:
|
||||||
|
case TTW_WIDGET_CATENARY:
|
||||||
|
case TTW_WIDGET_LOADING: {
|
||||||
|
uint i = widget - TTW_WIDGET_BEGIN;
|
||||||
|
if (HasBit(_transparency_lock, i)) DrawSprite(SPR_LOCK, PAL_NONE, r.left + 1, r.top + 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TTW_WIDGET_BUTTONS:
|
||||||
|
for (uint i = TTW_WIDGET_BEGIN; i < TTW_WIDGET_END; i++) {
|
||||||
|
if (i == TTW_WIDGET_LOADING) continue; // Do not draw button for invisible loading indicators.
|
||||||
|
|
||||||
|
const NWidgetCore *wi = this->nested_array[i];
|
||||||
|
DrawFrameRect(wi->pos_x + 1, r.top + 2, wi->pos_x + wi->current_x - 2, r.bottom - 2, COLOUR_PALE_GREEN,
|
||||||
|
HasBit(_invisibility_opt, i - TTW_WIDGET_BEGIN) ? FR_LOWERED : FR_NONE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,44 +95,32 @@ public:
|
|||||||
MarkWholeScreenDirty();
|
MarkWholeScreenDirty();
|
||||||
}
|
}
|
||||||
} else if (widget == TTW_WIDGET_BUTTONS) {
|
} else if (widget == TTW_WIDGET_BUTTONS) {
|
||||||
uint x = pt.x / 22;
|
uint i;
|
||||||
|
for (i = TTW_WIDGET_BEGIN; i < TTW_WIDGET_END; i++) {
|
||||||
|
const NWidgetCore *nwid = this->nested_array[i];
|
||||||
|
if (IsInsideBS(pt.x, nwid->pos_x, nwid->current_x))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (i == TTW_WIDGET_LOADING || i == TTW_WIDGET_END) return;
|
||||||
|
|
||||||
if (x > TTW_WIDGET_BRIDGES - TTW_WIDGET_BEGIN) x--;
|
ToggleInvisibility((TransparencyOption)(i - TTW_WIDGET_BEGIN));
|
||||||
if (x > TTW_WIDGET_CATENARY - TTW_WIDGET_BEGIN) return;
|
|
||||||
|
|
||||||
ToggleInvisibility((TransparencyOption)x);
|
|
||||||
SndPlayFx(SND_15_BEEP);
|
SndPlayFx(SND_15_BEEP);
|
||||||
|
|
||||||
/* Redraw whole screen only if transparency is set */
|
/* Redraw whole screen only if transparency is set */
|
||||||
if (IsTransparencySet((TransparencyOption)x)) {
|
if (IsTransparencySet((TransparencyOption)(i - TTW_WIDGET_BEGIN))) {
|
||||||
MarkWholeScreenDirty();
|
MarkWholeScreenDirty();
|
||||||
} else {
|
} else {
|
||||||
this->InvalidateWidget(TTW_WIDGET_BUTTONS);
|
this->InvalidateWidget(TTW_WIDGET_BUTTONS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
static const Widget _transparency_widgets[] = {
|
virtual void OnInvalidateData(int data)
|
||||||
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 10, 0, 13, STR_BLACK_CROSS, STR_TOOLTIP_CLOSE_WINDOW},
|
{
|
||||||
{ WWT_CAPTION, RESIZE_NONE, COLOUR_DARK_GREEN, 11, 206, 0, 13, STR_TRANSPARENCY_TOOLB, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS},
|
for (uint i = TTW_WIDGET_BEGIN; i < TTW_WIDGET_END; i++) {
|
||||||
{WWT_STICKYBOX, RESIZE_NONE, COLOUR_DARK_GREEN, 207, 218, 0, 13, STR_NULL, STR_STICKY_BUTTON},
|
this->SetWidgetLoweredState(i, IsTransparencySet((TransparencyOption)(i - TTW_WIDGET_BEGIN)));
|
||||||
|
}
|
||||||
/* transparency widgets:
|
}
|
||||||
* transparent signs, trees, houses, industries, company's buildings, bridges, unmovable structures, catenary and loading indicators */
|
|
||||||
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 21, 14, 35, SPR_IMG_SIGN, STR_TRANSPARENT_SIGNS_DESC},
|
|
||||||
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_DARK_GREEN, 22, 43, 14, 35, SPR_IMG_PLANTTREES, STR_TRANSPARENT_TREES_DESC},
|
|
||||||
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_DARK_GREEN, 44, 65, 14, 35, SPR_IMG_TOWN, STR_TRANSPARENT_HOUSES_DESC},
|
|
||||||
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_DARK_GREEN, 66, 87, 14, 35, SPR_IMG_INDUSTRY, STR_TRANSPARENT_INDUSTRIES_DESC},
|
|
||||||
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_DARK_GREEN, 88, 109, 14, 35, SPR_IMG_COMPANY_LIST, STR_TRANSPARENT_BUILDINGS_DESC},
|
|
||||||
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_DARK_GREEN, 110, 152, 14, 35, SPR_IMG_BRIDGE, STR_TRANSPARENT_BRIDGES_DESC},
|
|
||||||
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_DARK_GREEN, 153, 174, 14, 35, SPR_IMG_TRANSMITTER, STR_TRANSPARENT_STRUCTURES_DESC},
|
|
||||||
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_DARK_GREEN, 175, 196, 14, 35, SPR_BUILD_X_ELRAIL, STR_TRANSPARENT_CATENARY_DESC},
|
|
||||||
{ WWT_IMGBTN, RESIZE_NONE, COLOUR_DARK_GREEN, 197, 218, 14, 35, SPR_IMG_TRAINLIST, STR_TRANSPARENT_LOADING_DESC},
|
|
||||||
|
|
||||||
{ WWT_PANEL, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 218, 36, 48, 0x0, STR_TRANSPARENT_INVISIBLE_DESC},
|
|
||||||
|
|
||||||
{ WIDGETS_END},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const NWidgetPart _nested_transparency_widgets[] = {
|
static const NWidgetPart _nested_transparency_widgets[] = {
|
||||||
@ -127,15 +130,15 @@ static const NWidgetPart _nested_transparency_widgets[] = {
|
|||||||
NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN, TTW_WIDGET_STICKYBOX),
|
NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN, TTW_WIDGET_STICKYBOX),
|
||||||
EndContainer(),
|
EndContainer(),
|
||||||
NWidget(NWID_HORIZONTAL),
|
NWidget(NWID_HORIZONTAL),
|
||||||
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_WIDGET_SIGNS), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_SIGN, STR_TRANSPARENT_SIGNS_DESC),
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_WIDGET_SIGNS), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_SIGN, STR_TRANSPARENT_SIGNS_DESC),
|
||||||
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_WIDGET_TREES), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_PLANTTREES, STR_TRANSPARENT_TREES_DESC),
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_WIDGET_TREES), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_PLANTTREES, STR_TRANSPARENT_TREES_DESC),
|
||||||
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_WIDGET_HOUSES), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TOWN, STR_TRANSPARENT_HOUSES_DESC),
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_WIDGET_HOUSES), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_TOWN, STR_TRANSPARENT_HOUSES_DESC),
|
||||||
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_WIDGET_INDUSTRIES), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_INDUSTRY, STR_TRANSPARENT_INDUSTRIES_DESC),
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_WIDGET_INDUSTRIES), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_INDUSTRY, STR_TRANSPARENT_INDUSTRIES_DESC),
|
||||||
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_WIDGET_BUILDINGS), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_COMPANY_LIST, STR_TRANSPARENT_BUILDINGS_DESC),
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_WIDGET_BUILDINGS), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_COMPANY_LIST, STR_TRANSPARENT_BUILDINGS_DESC),
|
||||||
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_WIDGET_BRIDGES), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE, STR_TRANSPARENT_BRIDGES_DESC),
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_WIDGET_BRIDGES), SetMinimalSize(43, 22), SetFill(0, 1), SetDataTip(SPR_IMG_BRIDGE, STR_TRANSPARENT_BRIDGES_DESC),
|
||||||
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_WIDGET_STRUCTURES), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRANSMITTER, STR_TRANSPARENT_STRUCTURES_DESC),
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_WIDGET_STRUCTURES), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_TRANSMITTER, STR_TRANSPARENT_STRUCTURES_DESC),
|
||||||
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_WIDGET_CATENARY), SetMinimalSize(22, 22), SetDataTip(SPR_BUILD_X_ELRAIL, STR_TRANSPARENT_CATENARY_DESC),
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_WIDGET_CATENARY), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_BUILD_X_ELRAIL, STR_TRANSPARENT_CATENARY_DESC),
|
||||||
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_WIDGET_LOADING), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAINLIST, STR_TRANSPARENT_LOADING_DESC),
|
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, TTW_WIDGET_LOADING), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_TRAINLIST, STR_TRANSPARENT_LOADING_DESC),
|
||||||
EndContainer(),
|
EndContainer(),
|
||||||
/* Panel with 'inivisibility' buttons. */
|
/* Panel with 'inivisibility' buttons. */
|
||||||
NWidget(WWT_PANEL, COLOUR_DARK_GREEN, TTW_WIDGET_END), SetMinimalSize(219, 13), SetDataTip(0x0, STR_TRANSPARENT_INVISIBLE_DESC),
|
NWidget(WWT_PANEL, COLOUR_DARK_GREEN, TTW_WIDGET_END), SetMinimalSize(219, 13), SetDataTip(0x0, STR_TRANSPARENT_INVISIBLE_DESC),
|
||||||
@ -146,7 +149,7 @@ static const WindowDesc _transparency_desc(
|
|||||||
WDP_ALIGN_TBR, 94, 219, 49, 219, 49,
|
WDP_ALIGN_TBR, 94, 219, 49, 219, 49,
|
||||||
WC_TRANSPARENCY_TOOLBAR, WC_NONE,
|
WC_TRANSPARENCY_TOOLBAR, WC_NONE,
|
||||||
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
|
||||||
_transparency_widgets, _nested_transparency_widgets, lengthof(_nested_transparency_widgets)
|
NULL, _nested_transparency_widgets, lengthof(_nested_transparency_widgets)
|
||||||
);
|
);
|
||||||
|
|
||||||
void ShowTransparencyToolbar()
|
void ShowTransparencyToolbar()
|
||||||
|
Loading…
Reference in New Issue
Block a user