13 |
15 |
14 TransparencyOptionBits _transparency_opt; |
16 TransparencyOptionBits _transparency_opt; |
15 TransparencyOptionBits _transparency_lock; |
17 TransparencyOptionBits _transparency_lock; |
16 TransparencyOptionBits _invisibility_opt; |
18 TransparencyOptionBits _invisibility_opt; |
17 |
19 |
18 enum TransparencyToolbarWidgets{ |
20 class TransparenciesWindow : public Window |
19 TTW_WIDGET_SIGNS = 3, ///< Make signs background transparent |
21 { |
20 TTW_WIDGET_TREES, ///< Make trees transparent |
22 enum TransparencyToolbarWidgets{ |
21 TTW_WIDGET_HOUSES, ///< Make houses transparent |
23 TTW_WIDGET_SIGNS = 3, ///< Make signs background transparent |
22 TTW_WIDGET_INDUSTRIES, ///< Make Industries transparent |
24 TTW_WIDGET_TREES, ///< Make trees transparent |
23 TTW_WIDGET_BUILDINGS, ///< Make player buildings and structures transparent |
25 TTW_WIDGET_HOUSES, ///< Make houses transparent |
24 TTW_WIDGET_BRIDGES, ///< Make bridges transparent |
26 TTW_WIDGET_INDUSTRIES, ///< Make Industries transparent |
25 TTW_WIDGET_STRUCTURES, ///< Make unmovable structures transparent |
27 TTW_WIDGET_BUILDINGS, ///< Make player buildings and structures transparent |
26 TTW_WIDGET_CATENARY, ///< Make catenary transparent |
28 TTW_WIDGET_BRIDGES, ///< Make bridges transparent |
27 TTW_WIDGET_LOADING, ///< Make loading indicators transparent |
29 TTW_WIDGET_STRUCTURES, ///< Make unmovable structures transparent |
28 TTW_WIDGET_END, ///< End of toggle buttons |
30 TTW_WIDGET_CATENARY, ///< Make catenary transparent |
|
31 TTW_WIDGET_LOADING, ///< Make loading indicators transparent |
|
32 TTW_WIDGET_END, ///< End of toggle buttons |
29 |
33 |
30 /* Panel with buttons for invisibility */ |
34 /* Panel with buttons for invisibility */ |
31 TTW_BUTTONS = 12, ///< Panel with 'invisibility' buttons |
35 TTW_BUTTONS = 12, ///< Panel with 'invisibility' buttons |
|
36 }; |
|
37 |
|
38 public: |
|
39 TransparenciesWindow(const WindowDesc *desc, int window_number) : Window(desc, window_number) |
|
40 { |
|
41 this->FindWindowPlacementAndResize(desc); |
|
42 } |
|
43 |
|
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 } |
|
51 |
|
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); |
|
65 } |
|
66 } |
|
67 } |
|
68 |
|
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 } |
|
98 } |
32 }; |
99 }; |
33 |
|
34 static void TransparencyToolbWndProc(Window *w, WindowEvent *e) |
|
35 { |
|
36 switch (e->event) { |
|
37 case WE_PAINT: |
|
38 /* must be sure that the widgets show the transparency variable changes |
|
39 * also when we use shortcuts */ |
|
40 for (uint i = TTW_WIDGET_SIGNS; i < TTW_WIDGET_END; i++) { |
|
41 w->SetWidgetLoweredState(i, IsTransparencySet((TransparencyOption)(i - TTW_WIDGET_SIGNS))); |
|
42 } |
|
43 |
|
44 DrawWindowWidgets(w); |
|
45 for (uint i = TO_SIGNS; i < TO_END; i++) { |
|
46 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); |
|
47 } |
|
48 |
|
49 /* Do not draw button for invisible loading indicators */ |
|
50 for (uint i = 0; i < 8; i++) { |
|
51 if (i < TTW_WIDGET_BRIDGES - TTW_WIDGET_SIGNS) { |
|
52 DrawFrameRect(i * 22, 38, i * 22 + 19, 46, true, HasBit(_invisibility_opt, i) ? FR_LOWERED : FR_NONE); |
|
53 } else if (i == TTW_WIDGET_BRIDGES - TTW_WIDGET_SIGNS) { |
|
54 DrawFrameRect(i * 22, 38, i * 22 + 41, 46, true, HasBit(_invisibility_opt, i) ? FR_LOWERED : FR_NONE); |
|
55 } else { // i > TTW_WIDGET_BRIDGES - TTW_WIDGET_SIGNS |
|
56 DrawFrameRect((i + 1) * 22, 38, (i + 1) * 22 + 19, 46, true, HasBit(_invisibility_opt, i) ? FR_LOWERED : FR_NONE); |
|
57 } |
|
58 } |
|
59 |
|
60 break; |
|
61 |
|
62 case WE_CLICK: |
|
63 if (e->we.click.widget >= TTW_WIDGET_SIGNS && e->we.click.widget < TTW_WIDGET_END) { |
|
64 if (_ctrl_pressed) { |
|
65 /* toggle the bit of the transparencies lock variable */ |
|
66 ToggleTransparencyLock((TransparencyOption)(e->we.click.widget - TTW_WIDGET_SIGNS)); |
|
67 SetWindowDirty(w); |
|
68 } else { |
|
69 /* toggle the bit of the transparencies variable and play a sound */ |
|
70 ToggleTransparency((TransparencyOption)(e->we.click.widget - TTW_WIDGET_SIGNS)); |
|
71 SndPlayFx(SND_15_BEEP); |
|
72 MarkWholeScreenDirty(); |
|
73 } |
|
74 } else if (e->we.click.widget == TTW_BUTTONS) { |
|
75 uint x = e->we.click.pt.x / 22; |
|
76 |
|
77 if (x > TTW_WIDGET_BRIDGES - TTW_WIDGET_SIGNS) x--; |
|
78 if (x > TTW_WIDGET_CATENARY - TTW_WIDGET_SIGNS) break; |
|
79 |
|
80 ToggleInvisibility((TransparencyOption)x); |
|
81 SndPlayFx(SND_15_BEEP); |
|
82 |
|
83 /* Redraw whole screen only if transparency is set */ |
|
84 if (IsTransparencySet((TransparencyOption)x)) { |
|
85 MarkWholeScreenDirty(); |
|
86 } else { |
|
87 w->InvalidateWidget(TTW_BUTTONS); |
|
88 } |
|
89 } |
|
90 |
|
91 break; |
|
92 } |
|
93 } |
|
94 |
100 |
95 static const Widget _transparency_widgets[] = { |
101 static const Widget _transparency_widgets[] = { |
96 { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
102 { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
97 { WWT_CAPTION, RESIZE_NONE, 7, 11, 206, 0, 13, STR_TRANSPARENCY_TOOLB, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
103 { WWT_CAPTION, RESIZE_NONE, 7, 11, 206, 0, 13, STR_TRANSPARENCY_TOOLB, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
98 {WWT_STICKYBOX, RESIZE_NONE, 7, 207, 218, 0, 13, STR_NULL, STR_STICKY_BUTTON}, |
104 {WWT_STICKYBOX, RESIZE_NONE, 7, 207, 218, 0, 13, STR_NULL, STR_STICKY_BUTTON}, |