mirror of https://github.com/OpenTTD/OpenTTD
(svn r13062) -Codechange: make a class of the TransparencyToolbar.
parent
ca4d92e2f2
commit
6c0d2b9132
|
@ -17,7 +17,9 @@ TransparencyOptionBits _transparency_opt;
|
|||
TransparencyOptionBits _transparency_lock;
|
||||
TransparencyOptionBits _invisibility_opt;
|
||||
|
||||
enum TransparencyToolbarWidgets{
|
||||
class TransparenciesWindow : public Window
|
||||
{
|
||||
enum TransparencyToolbarWidgets{
|
||||
TTW_WIDGET_SIGNS = 3, ///< Make signs background transparent
|
||||
TTW_WIDGET_TREES, ///< Make trees transparent
|
||||
TTW_WIDGET_HOUSES, ///< Make houses transparent
|
||||
|
@ -31,21 +33,25 @@ enum TransparencyToolbarWidgets{
|
|||
|
||||
/* Panel with buttons for invisibility */
|
||||
TTW_BUTTONS = 12, ///< Panel with 'invisibility' buttons
|
||||
};
|
||||
};
|
||||
|
||||
static void TransparencyToolbWndProc(Window *w, WindowEvent *e)
|
||||
{
|
||||
switch (e->event) {
|
||||
case WE_PAINT:
|
||||
public:
|
||||
TransparenciesWindow(const WindowDesc *desc, void *data, int window_number) : Window(desc, data, window_number)
|
||||
{
|
||||
this->FindWindowPlacementAndResize(desc);
|
||||
}
|
||||
|
||||
virtual void OnPaint()
|
||||
{
|
||||
/* must be sure that the widgets show the transparency variable changes
|
||||
* also when we use shortcuts */
|
||||
for (uint i = TTW_WIDGET_SIGNS; i < TTW_WIDGET_END; i++) {
|
||||
w->SetWidgetLoweredState(i, IsTransparencySet((TransparencyOption)(i - TTW_WIDGET_SIGNS)));
|
||||
this->SetWidgetLoweredState(i, IsTransparencySet((TransparencyOption)(i - TTW_WIDGET_SIGNS)));
|
||||
}
|
||||
|
||||
DrawWindowWidgets(w);
|
||||
DrawWindowWidgets(this);
|
||||
for (uint i = TO_SIGNS; i < TO_END; i++) {
|
||||
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);
|
||||
if (HasBit(_transparency_lock, i)) DrawSprite(SPR_LOCK, PAL_NONE, this->widget[TTW_WIDGET_SIGNS + i].left + 1, this->widget[TTW_WIDGET_SIGNS + i].top + 1);
|
||||
}
|
||||
|
||||
/* Do not draw button for invisible loading indicators */
|
||||
|
@ -58,26 +64,26 @@ static void TransparencyToolbWndProc(Window *w, WindowEvent *e)
|
|||
DrawFrameRect((i + 1) * 22, 38, (i + 1) * 22 + 19, 46, true, HasBit(_invisibility_opt, i) ? FR_LOWERED : FR_NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case WE_CLICK:
|
||||
if (e->we.click.widget >= TTW_WIDGET_SIGNS && e->we.click.widget < TTW_WIDGET_END) {
|
||||
virtual void OnClick(Point pt, int widget)
|
||||
{
|
||||
if (widget >= TTW_WIDGET_SIGNS && widget < TTW_WIDGET_END) {
|
||||
if (_ctrl_pressed) {
|
||||
/* toggle the bit of the transparencies lock variable */
|
||||
ToggleTransparencyLock((TransparencyOption)(e->we.click.widget - TTW_WIDGET_SIGNS));
|
||||
w->SetDirty();
|
||||
ToggleTransparencyLock((TransparencyOption)(widget - TTW_WIDGET_SIGNS));
|
||||
this->SetDirty();
|
||||
} else {
|
||||
/* toggle the bit of the transparencies variable and play a sound */
|
||||
ToggleTransparency((TransparencyOption)(e->we.click.widget - TTW_WIDGET_SIGNS));
|
||||
ToggleTransparency((TransparencyOption)(widget - TTW_WIDGET_SIGNS));
|
||||
SndPlayFx(SND_15_BEEP);
|
||||
MarkWholeScreenDirty();
|
||||
}
|
||||
} else if (e->we.click.widget == TTW_BUTTONS) {
|
||||
uint x = e->we.click.pt.x / 22;
|
||||
} else if (widget == TTW_BUTTONS) {
|
||||
uint x = pt.x / 22;
|
||||
|
||||
if (x > TTW_WIDGET_BRIDGES - TTW_WIDGET_SIGNS) x--;
|
||||
if (x > TTW_WIDGET_CATENARY - TTW_WIDGET_SIGNS) break;
|
||||
if (x > TTW_WIDGET_CATENARY - TTW_WIDGET_SIGNS) return;
|
||||
|
||||
ToggleInvisibility((TransparencyOption)x);
|
||||
SndPlayFx(SND_15_BEEP);
|
||||
|
@ -86,13 +92,11 @@ static void TransparencyToolbWndProc(Window *w, WindowEvent *e)
|
|||
if (IsTransparencySet((TransparencyOption)x)) {
|
||||
MarkWholeScreenDirty();
|
||||
} else {
|
||||
w->InvalidateWidget(TTW_BUTTONS);
|
||||
this->InvalidateWidget(TTW_BUTTONS);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static const Widget _transparency_widgets[] = {
|
||||
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
||||
|
@ -126,5 +130,5 @@ static const WindowDesc _transparency_desc = {
|
|||
|
||||
void ShowTransparencyToolbar(void)
|
||||
{
|
||||
AllocateWindowDescFront<Window>(&_transparency_desc, 0);
|
||||
AllocateWindowDescFront<TransparenciesWindow>(&_transparency_desc, 0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue