| author | truebrain |
| Thu, 12 Jun 2008 19:47:02 +0000 | |
| branch | noai |
| changeset 10942 | cd3f2d07199f |
| parent 10645 | 8cbdb511a674 |
| permissions | -rw-r--r-- |
| 9574 | 1 |
/* $Id$ */ |
2 |
||
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
9869
diff
changeset
|
3 |
/** @file transparency_gui.cpp The transparency GUI. */ |
|
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
9869
diff
changeset
|
4 |
|
| 9574 | 5 |
#include "stdafx.h" |
6 |
#include "openttd.h" |
|
7 |
#include "gui.h" |
|
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
8 |
#include "window_gui.h" |
| 9574 | 9 |
#include "variables.h" |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9694
diff
changeset
|
10 |
#include "transparency.h" |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
11 |
#include "sound_func.h" |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9694
diff
changeset
|
12 |
|
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
13 |
#include "table/sprites.h" |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
14 |
#include "table/strings.h" |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
15 |
|
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9694
diff
changeset
|
16 |
TransparencyOptionBits _transparency_opt; |
| 9732 | 17 |
TransparencyOptionBits _transparency_lock; |
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
18 |
TransparencyOptionBits _invisibility_opt; |
| 9574 | 19 |
|
| 10645 | 20 |
class TransparenciesWindow : public Window |
| 9574 | 21 |
{
|
| 10645 | 22 |
enum TransparencyToolbarWidgets{
|
23 |
TTW_WIDGET_SIGNS = 3, ///< Make signs background transparent |
|
24 |
TTW_WIDGET_TREES, ///< Make trees transparent |
|
25 |
TTW_WIDGET_HOUSES, ///< Make houses transparent |
|
26 |
TTW_WIDGET_INDUSTRIES, ///< Make Industries transparent |
|
27 |
TTW_WIDGET_BUILDINGS, ///< Make player buildings and structures transparent |
|
28 |
TTW_WIDGET_BRIDGES, ///< Make bridges transparent |
|
29 |
TTW_WIDGET_STRUCTURES, ///< Make unmovable structures transparent |
|
30 |
TTW_WIDGET_CATENARY, ///< Make catenary transparent |
|
31 |
TTW_WIDGET_LOADING, ///< Make loading indicators transparent |
|
32 |
TTW_WIDGET_END, ///< End of toggle buttons |
|
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
33 |
|
| 10645 | 34 |
/* Panel with buttons for invisibility */ |
35 |
TTW_BUTTONS = 12, ///< Panel with 'invisibility' buttons |
|
36 |
}; |
|
| 9574 | 37 |
|
| 10645 | 38 |
public: |
39 |
TransparenciesWindow(const WindowDesc *desc, int window_number) : Window(desc, window_number) |
|
40 |
{
|
|
41 |
this->FindWindowPlacementAndResize(desc); |
|
42 |
} |
|
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
43 |
|
| 10645 | 44 |
virtual void OnPaint() |
45 |
{
|
|
46 |
/* must be sure that the widgets show the transparency variable changes |
|
47 |
* also when we use shortcuts */ |
|
48 |
for (uint i = TTW_WIDGET_SIGNS; i < TTW_WIDGET_END; i++) {
|
|
49 |
this->SetWidgetLoweredState(i, IsTransparencySet((TransparencyOption)(i - TTW_WIDGET_SIGNS))); |
|
50 |
} |
|
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
51 |
|
| 10645 | 52 |
this->DrawWidgets(); |
53 |
for (uint i = TO_SIGNS; i < TO_END; i++) {
|
|
54 |
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); |
|
55 |
} |
|
56 |
||
57 |
/* Do not draw button for invisible loading indicators */ |
|
58 |
for (uint i = 0; i < 8; i++) {
|
|
59 |
if (i < TTW_WIDGET_BRIDGES - TTW_WIDGET_SIGNS) {
|
|
60 |
DrawFrameRect(i * 22, 38, i * 22 + 19, 46, true, HasBit(_invisibility_opt, i) ? FR_LOWERED : FR_NONE); |
|
61 |
} else if (i == TTW_WIDGET_BRIDGES - TTW_WIDGET_SIGNS) {
|
|
62 |
DrawFrameRect(i * 22, 38, i * 22 + 41, 46, true, HasBit(_invisibility_opt, i) ? FR_LOWERED : FR_NONE); |
|
63 |
} else { // i > TTW_WIDGET_BRIDGES - TTW_WIDGET_SIGNS
|
|
64 |
DrawFrameRect((i + 1) * 22, 38, (i + 1) * 22 + 19, 46, true, HasBit(_invisibility_opt, i) ? FR_LOWERED : FR_NONE); |
|
| 9574 | 65 |
} |
| 10645 | 66 |
} |
67 |
} |
|
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
68 |
|
| 10645 | 69 |
virtual void OnClick(Point pt, int widget) |
70 |
{
|
|
71 |
if (widget >= TTW_WIDGET_SIGNS && widget < TTW_WIDGET_END) {
|
|
72 |
if (_ctrl_pressed) {
|
|
73 |
/* toggle the bit of the transparencies lock variable */ |
|
74 |
ToggleTransparencyLock((TransparencyOption)(widget - TTW_WIDGET_SIGNS)); |
|
75 |
this->SetDirty(); |
|
76 |
} else {
|
|
77 |
/* toggle the bit of the transparencies variable and play a sound */ |
|
78 |
ToggleTransparency((TransparencyOption)(widget - TTW_WIDGET_SIGNS)); |
|
79 |
SndPlayFx(SND_15_BEEP); |
|
80 |
MarkWholeScreenDirty(); |
|
81 |
} |
|
82 |
} else if (widget == TTW_BUTTONS) {
|
|
83 |
uint x = pt.x / 22; |
|
84 |
||
85 |
if (x > TTW_WIDGET_BRIDGES - TTW_WIDGET_SIGNS) x--; |
|
86 |
if (x > TTW_WIDGET_CATENARY - TTW_WIDGET_SIGNS) return; |
|
87 |
||
88 |
ToggleInvisibility((TransparencyOption)x); |
|
89 |
SndPlayFx(SND_15_BEEP); |
|
90 |
||
91 |
/* Redraw whole screen only if transparency is set */ |
|
92 |
if (IsTransparencySet((TransparencyOption)x)) {
|
|
93 |
MarkWholeScreenDirty(); |
|
94 |
} else {
|
|
95 |
this->InvalidateWidget(TTW_BUTTONS); |
|
96 |
} |
|
97 |
} |
|
| 9574 | 98 |
} |
| 10645 | 99 |
}; |
| 9574 | 100 |
|
101 |
static const Widget _transparency_widgets[] = {
|
|
102 |
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
| 9732 | 103 |
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 206, 0, 13, STR_TRANSPARENCY_TOOLB, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
104 |
{WWT_STICKYBOX, RESIZE_NONE, 7, 207, 218, 0, 13, STR_NULL, STR_STICKY_BUTTON},
|
|
| 9574 | 105 |
|
|
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9574
diff
changeset
|
106 |
/* transparency widgets: |
|
9826
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
107 |
* transparent signs, trees, houses, industries, player's buildings, bridges, unmovable structures, catenary and loading indicators */ |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
108 |
{ WWT_IMGBTN, RESIZE_NONE, 7, 0, 21, 14, 35, SPR_IMG_SIGN, STR_TRANSPARENT_SIGNS_DESC},
|
| 9574 | 109 |
{ WWT_IMGBTN, RESIZE_NONE, 7, 22, 43, 14, 35, SPR_IMG_PLANTTREES, STR_TRANSPARENT_TREES_DESC},
|
110 |
{ WWT_IMGBTN, RESIZE_NONE, 7, 44, 65, 14, 35, SPR_IMG_TOWN, STR_TRANSPARENT_HOUSES_DESC},
|
|
111 |
{ WWT_IMGBTN, RESIZE_NONE, 7, 66, 87, 14, 35, SPR_IMG_INDUSTRY, STR_TRANSPARENT_INDUSTRIES_DESC},
|
|
112 |
{ WWT_IMGBTN, RESIZE_NONE, 7, 88, 109, 14, 35, SPR_IMG_COMPANY_LIST, STR_TRANSPARENT_BUILDINGS_DESC},
|
|
113 |
{ WWT_IMGBTN, RESIZE_NONE, 7, 110, 152, 14, 35, SPR_IMG_BRIDGE, STR_TRANSPARENT_BRIDGES_DESC},
|
|
114 |
{ WWT_IMGBTN, RESIZE_NONE, 7, 153, 174, 14, 35, SPR_IMG_TRANSMITTER, STR_TRANSPARENT_STRUCTURES_DESC},
|
|
| 9732 | 115 |
{ WWT_IMGBTN, RESIZE_NONE, 7, 175, 196, 14, 35, SPR_BUILD_X_ELRAIL, STR_TRANSPARENT_CATENARY_DESC},
|
116 |
{ WWT_IMGBTN, RESIZE_NONE, 7, 197, 218, 14, 35, SPR_IMG_TRAINLIST, STR_TRANSPARENT_LOADING_DESC},
|
|
| 9574 | 117 |
|
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
118 |
{ WWT_PANEL, RESIZE_NONE, 7, 0, 218, 36, 48, 0x0, STR_TRANSPARENT_INVISIBLE_DESC},
|
|
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
119 |
|
| 9574 | 120 |
{ WIDGETS_END},
|
121 |
}; |
|
122 |
||
123 |
static const WindowDesc _transparency_desc = {
|
|
|
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9826
diff
changeset
|
124 |
WDP_ALIGN_TBR, 58+36, 219, 49, 219, 49, |
| 9574 | 125 |
WC_TRANSPARENCY_TOOLBAR, WC_NONE, |
126 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, |
|
127 |
_transparency_widgets, |
|
128 |
}; |
|
129 |
||
130 |
void ShowTransparencyToolbar(void) |
|
131 |
{
|
|
| 10645 | 132 |
AllocateWindowDescFront<TransparenciesWindow>(&_transparency_desc, 0); |
| 9574 | 133 |
} |