author | rubidium |
Tue, 30 Sep 2008 20:39:50 +0000 | |
changeset 10207 | c291a21b304e |
parent 9892 | 8dc6b933e669 |
child 10208 | 72c00af5c95d |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
9111
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
8969
diff
changeset
|
3 |
/** @file widget.cpp Handling of the default/simple widgets. */ |
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6278
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1657
diff
changeset
|
6 |
#include "openttd.h" |
8254
1496654ca5e7
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8224
diff
changeset
|
7 |
#include "core/math_func.hpp" |
1496654ca5e7
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8224
diff
changeset
|
8 |
#include "player_func.h" |
8224
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8131
diff
changeset
|
9 |
#include "gfx_func.h" |
8106
e6790dd9e750
(svn r11667) -Codechange: split window.h into a header that defines some 'global' window related types, on that defined 'global' window functions and one that defines functions and types only used by *_gui.cpps.
rubidium
parents:
8082
diff
changeset
|
10 |
#include "window_gui.h" |
8131
160939e24ed3
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8121
diff
changeset
|
11 |
#include "window_func.h" |
8284
ebdc5ba08874
(svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
8264
diff
changeset
|
12 |
#include "widgets/dropdown_func.h" |
8131
160939e24ed3
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8121
diff
changeset
|
13 |
|
8264
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
14 |
#include "table/sprites.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
15 |
#include "table/strings.h" |
0 | 16 |
|
8411
591f0c085e10
(svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138
parents:
8349
diff
changeset
|
17 |
static const char *UPARROW = "\xEE\x8A\xA0"; |
8349
e61105cb1f87
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138
parents:
8335
diff
changeset
|
18 |
static const char *DOWNARROW = "\xEE\x8A\xAA"; |
e61105cb1f87
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138
parents:
8335
diff
changeset
|
19 |
|
9773
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9770
diff
changeset
|
20 |
/** |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9770
diff
changeset
|
21 |
* Compute the vertical position of the draggable part of scrollbar |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9770
diff
changeset
|
22 |
* @param sb Scrollbar list data |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9770
diff
changeset
|
23 |
* @param top Top position of the scrollbar (top position of the up-button) |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9770
diff
changeset
|
24 |
* @param bottom Bottom position of the scrollbar (bottom position of the down-button) |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9770
diff
changeset
|
25 |
* @return A Point, with x containing the top coordinate of the draggable part, and |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9770
diff
changeset
|
26 |
* y containing the bottom coordinate of the draggable part |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9770
diff
changeset
|
27 |
*/ |
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2406
diff
changeset
|
28 |
static Point HandleScrollbarHittest(const Scrollbar *sb, int top, int bottom) |
0 | 29 |
{ |
30 |
Point pt; |
|
31 |
int height, count, pos, cap; |
|
32 |
||
9773
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9770
diff
changeset
|
33 |
top += 10; // top points to just below the up-button |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9770
diff
changeset
|
34 |
bottom -= 9; // bottom points to top of the down-button |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
35 |
|
0 | 36 |
height = (bottom - top); |
37 |
||
38 |
pos = sb->pos; |
|
39 |
count = sb->count; |
|
40 |
cap = sb->cap; |
|
41 |
||
2026 | 42 |
if (count != 0) top += height * pos / count; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
43 |
|
0 | 44 |
if (cap > count) cap = count; |
2639 | 45 |
if (count != 0) bottom -= (count - pos - cap) * height / count; |
0 | 46 |
|
47 |
pt.x = top; |
|
48 |
pt.y = bottom - 1; |
|
49 |
return pt; |
|
50 |
} |
|
51 |
||
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6432
diff
changeset
|
52 |
/** Special handling for the scrollbar widget type. |
0 | 53 |
* Handles the special scrolling buttons and other |
54 |
* scrolling. |
|
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6432
diff
changeset
|
55 |
* @param w Window on which a scroll was performed. |
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6432
diff
changeset
|
56 |
* @param wi Pointer to the scrollbar widget. |
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6432
diff
changeset
|
57 |
* @param x The X coordinate of the mouse click. |
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6432
diff
changeset
|
58 |
* @param y The Y coordinate of the mouse click. */ |
0 | 59 |
void ScrollbarClickHandler(Window *w, const Widget *wi, int x, int y) |
60 |
{ |
|
61 |
int mi, ma, pos; |
|
62 |
Scrollbar *sb; |
|
63 |
||
842 | 64 |
switch (wi->type) { |
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
65 |
case WWT_SCROLLBAR: |
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6278
diff
changeset
|
66 |
/* vertical scroller */ |
842 | 67 |
w->flags4 &= ~WF_HSCROLL; |
68 |
w->flags4 &= ~WF_SCROLL2; |
|
69 |
mi = wi->top; |
|
70 |
ma = wi->bottom; |
|
71 |
pos = y; |
|
72 |
sb = &w->vscroll; |
|
73 |
break; |
|
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
74 |
|
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
75 |
case WWT_SCROLL2BAR: |
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6278
diff
changeset
|
76 |
/* 2nd vertical scroller */ |
842 | 77 |
w->flags4 &= ~WF_HSCROLL; |
78 |
w->flags4 |= WF_SCROLL2; |
|
79 |
mi = wi->top; |
|
80 |
ma = wi->bottom; |
|
81 |
pos = y; |
|
82 |
sb = &w->vscroll2; |
|
83 |
break; |
|
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
84 |
|
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
85 |
case WWT_HSCROLLBAR: |
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6278
diff
changeset
|
86 |
/* horizontal scroller */ |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
87 |
w->flags4 &= ~WF_SCROLL2; |
842 | 88 |
w->flags4 |= WF_HSCROLL; |
89 |
mi = wi->left; |
|
90 |
ma = wi->right; |
|
91 |
pos = x; |
|
92 |
sb = &w->hscroll; |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
93 |
break; |
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
94 |
|
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
95 |
default: NOT_REACHED(); |
0 | 96 |
} |
8969
6d1c74e0e2cd
(svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium
parents:
8857
diff
changeset
|
97 |
if (pos <= mi + 9) { |
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6278
diff
changeset
|
98 |
/* Pressing the upper button? */ |
2597 | 99 |
w->flags4 |= WF_SCROLL_UP; |
100 |
if (_scroller_click_timeout == 0) { |
|
101 |
_scroller_click_timeout = 6; |
|
102 |
if (sb->pos != 0) sb->pos--; |
|
0 | 103 |
} |
2597 | 104 |
_left_button_clicked = false; |
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
105 |
} else if (pos >= ma - 10) { |
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6278
diff
changeset
|
106 |
/* Pressing the lower button? */ |
2597 | 107 |
w->flags4 |= WF_SCROLL_DOWN; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
108 |
|
2597 | 109 |
if (_scroller_click_timeout == 0) { |
110 |
_scroller_click_timeout = 6; |
|
111 |
if ((byte)(sb->pos + sb->cap) < sb->count) |
|
112 |
sb->pos++; |
|
0 | 113 |
} |
2597 | 114 |
_left_button_clicked = false; |
0 | 115 |
} else { |
116 |
Point pt = HandleScrollbarHittest(sb, mi, ma); |
|
117 |
||
118 |
if (pos < pt.x) { |
|
119 |
sb->pos = max(sb->pos - sb->cap, 0); |
|
120 |
} else if (pos > pt.y) { |
|
121 |
sb->pos = min( |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
122 |
sb->pos + sb->cap, |
0 | 123 |
max(sb->count - sb->cap, 0) |
124 |
); |
|
125 |
} else { |
|
126 |
_scrollbar_start_pos = pt.x - mi - 9; |
|
127 |
_scrollbar_size = ma - mi - 23; |
|
128 |
w->flags4 |= WF_SCROLL_MIDDLE; |
|
129 |
_scrolling_scrollbar = true; |
|
130 |
_cursorpos_drag_start = _cursor.pos; |
|
131 |
} |
|
132 |
} |
|
133 |
||
9116
f2491d3c321b
(svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents:
9111
diff
changeset
|
134 |
w->SetDirty(); |
0 | 135 |
} |
136 |
||
2021
3a8c59ea3fbe
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1938
diff
changeset
|
137 |
/** Returns the index for the widget located at the given position |
3a8c59ea3fbe
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1938
diff
changeset
|
138 |
* relative to the window. It includes all widget-corner pixels as well. |
3a8c59ea3fbe
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1938
diff
changeset
|
139 |
* @param *w Window to look inside |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6432
diff
changeset
|
140 |
* @param x The Window client X coordinate |
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6432
diff
changeset
|
141 |
* @param y The Window client y coordinate |
2021
3a8c59ea3fbe
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1938
diff
changeset
|
142 |
* @return A widget index, or -1 if no widget was found. |
0 | 143 |
*/ |
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2406
diff
changeset
|
144 |
int GetWidgetFromPos(const Window *w, int x, int y) |
0 | 145 |
{ |
5236
4c1289d5e45a
(svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents:
5196
diff
changeset
|
146 |
uint index; |
4c1289d5e45a
(svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents:
5196
diff
changeset
|
147 |
int found_index = -1; |
0 | 148 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6278
diff
changeset
|
149 |
/* Go through the widgets and check if we find the widget that the coordinate is |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6278
diff
changeset
|
150 |
* inside. */ |
5236
4c1289d5e45a
(svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents:
5196
diff
changeset
|
151 |
for (index = 0; index < w->widget_count; index++) { |
4c1289d5e45a
(svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents:
5196
diff
changeset
|
152 |
const Widget *wi = &w->widget[index]; |
2639 | 153 |
if (wi->type == WWT_EMPTY || wi->type == WWT_FRAME) continue; |
0 | 154 |
|
2021
3a8c59ea3fbe
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1938
diff
changeset
|
155 |
if (x >= wi->left && x <= wi->right && y >= wi->top && y <= wi->bottom && |
7997
df87ccd00a96
(svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents:
7962
diff
changeset
|
156 |
!w->IsWidgetHidden(index)) { |
2639 | 157 |
found_index = index; |
0 | 158 |
} |
159 |
} |
|
160 |
||
161 |
return found_index; |
|
162 |
} |
|
163 |
||
9773
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9770
diff
changeset
|
164 |
/** |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9770
diff
changeset
|
165 |
* Draw frame rectangle. |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9770
diff
changeset
|
166 |
* @param left Left edge of the frame |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9770
diff
changeset
|
167 |
* @param top Top edge of the frame |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9770
diff
changeset
|
168 |
* @param right Right edge of the frame |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9770
diff
changeset
|
169 |
* @param bottom Bottom edge of the frame |
9779
55b4f7df45cc
(svn r13920) -Codechange: uniformise the definition with the declaration of DrawFrameRect
belugas
parents:
9773
diff
changeset
|
170 |
* @param color Colour table to use. @see _colour_gradient |
9773
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9770
diff
changeset
|
171 |
* @param flags Flags controlling how to draw the frame. @see FrameFlags |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9770
diff
changeset
|
172 |
*/ |
9779
55b4f7df45cc
(svn r13920) -Codechange: uniformise the definition with the declaration of DrawFrameRect
belugas
parents:
9773
diff
changeset
|
173 |
void DrawFrameRect(int left, int top, int right, int bottom, int color, FrameFlags flags) |
4437
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
174 |
{ |
9779
55b4f7df45cc
(svn r13920) -Codechange: uniformise the definition with the declaration of DrawFrameRect
belugas
parents:
9773
diff
changeset
|
175 |
uint dark = _colour_gradient[color][3]; |
55b4f7df45cc
(svn r13920) -Codechange: uniformise the definition with the declaration of DrawFrameRect
belugas
parents:
9773
diff
changeset
|
176 |
uint medium_dark = _colour_gradient[color][5]; |
55b4f7df45cc
(svn r13920) -Codechange: uniformise the definition with the declaration of DrawFrameRect
belugas
parents:
9773
diff
changeset
|
177 |
uint medium_light = _colour_gradient[color][6]; |
55b4f7df45cc
(svn r13920) -Codechange: uniformise the definition with the declaration of DrawFrameRect
belugas
parents:
9773
diff
changeset
|
178 |
uint light = _colour_gradient[color][7]; |
4437
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
179 |
|
4438
c8b86504b83c
(svn r6210) Remove FR_NOBORDER, because it is exclusivly used in conjunction with FR_TRANSPARENT
tron
parents:
4437
diff
changeset
|
180 |
if (flags & FR_TRANSPARENT) { |
9607
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9273
diff
changeset
|
181 |
GfxFillRect(left, top, right, bottom, PALETTE_TO_TRANSPARENT, FILLRECT_RECOLOR); |
4437
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
182 |
} else { |
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
183 |
uint interior; |
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
184 |
|
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
185 |
if (flags & FR_LOWERED) { |
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
186 |
GfxFillRect(left, top, left, bottom, dark); |
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
187 |
GfxFillRect(left + 1, top, right, top, dark); |
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
188 |
GfxFillRect(right, top + 1, right, bottom - 1, light); |
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
189 |
GfxFillRect(left + 1, bottom, right, bottom, light); |
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
190 |
interior = (flags & FR_DARKENED ? medium_dark : medium_light); |
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
191 |
} else { |
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
192 |
GfxFillRect(left, top, left, bottom - 1, light); |
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
193 |
GfxFillRect(left + 1, top, right - 1, top, light); |
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
194 |
GfxFillRect(right, top, right, bottom - 1, dark); |
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
195 |
GfxFillRect(left, bottom, right, bottom, dark); |
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
196 |
interior = medium_dark; |
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
197 |
} |
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
198 |
if (!(flags & FR_BORDERONLY)) { |
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
199 |
GfxFillRect(left + 1, top + 1, right - 1, bottom - 1, interior); |
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
200 |
} |
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
201 |
} |
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
202 |
} |
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
203 |
|
49e79e135539
(svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents:
4345
diff
changeset
|
204 |
|
8857
7593af4962e6
(svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents:
8737
diff
changeset
|
205 |
/** |
7593af4962e6
(svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents:
8737
diff
changeset
|
206 |
* Paint all widgets of a window. |
7593af4962e6
(svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents:
8737
diff
changeset
|
207 |
* @param w Window |
7593af4962e6
(svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents:
8737
diff
changeset
|
208 |
*/ |
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
209 |
void Window::DrawWidgets() const |
0 | 210 |
{ |
2548
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2448
diff
changeset
|
211 |
const DrawPixelInfo* dpi = _cur_dpi; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
212 |
|
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
213 |
for (uint i = 0; i < this->widget_count; i++) { |
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
214 |
const Widget *wi = &this->widget[i]; |
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
215 |
bool clicked = this->IsWidgetLowered(i); |
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
216 |
Rect r; |
1657
af84fedacc6d
(svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents:
1363
diff
changeset
|
217 |
|
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
218 |
if (dpi->left > (r.right = wi->right) || |
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
219 |
dpi->left + dpi->width <= (r.left = wi->left) || |
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
220 |
dpi->top > (r.bottom = wi->bottom) || |
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
221 |
dpi->top + dpi->height <= (r.top = wi->top) || |
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
222 |
this->IsWidgetHidden(i)) { |
2639 | 223 |
continue; |
224 |
} |
|
0 | 225 |
|
1657
af84fedacc6d
(svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents:
1363
diff
changeset
|
226 |
switch (wi->type & WWT_MASK) { |
4938
0447845fd1b3
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4749
diff
changeset
|
227 |
case WWT_IMGBTN: |
0447845fd1b3
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4749
diff
changeset
|
228 |
case WWT_IMGBTN_2: { |
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
229 |
SpriteID img = wi->data; |
4938
0447845fd1b3
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4749
diff
changeset
|
230 |
assert(img != 0); |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
231 |
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
0 | 232 |
|
4938
0447845fd1b3
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4749
diff
changeset
|
233 |
/* show different image when clicked for WWT_IMGBTN_2 */ |
0447845fd1b3
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4749
diff
changeset
|
234 |
if ((wi->type & WWT_MASK) == WWT_IMGBTN_2 && clicked) img++; |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5587
diff
changeset
|
235 |
DrawSprite(img, PAL_NONE, r.left + 1 + clicked, r.top + 1 + clicked); |
8320
5a41b1329cdf
(svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138
parents:
8284
diff
changeset
|
236 |
break; |
4938
0447845fd1b3
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4749
diff
changeset
|
237 |
} |
1657
af84fedacc6d
(svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents:
1363
diff
changeset
|
238 |
|
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
239 |
case WWT_PANEL: |
4938
0447845fd1b3
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4749
diff
changeset
|
240 |
assert(wi->data == 0); |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
241 |
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
8320
5a41b1329cdf
(svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138
parents:
8284
diff
changeset
|
242 |
break; |
0 | 243 |
|
8737
4405e2e80db6
(svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents:
8729
diff
changeset
|
244 |
case WWT_EDITBOX: |
4405e2e80db6
(svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents:
8729
diff
changeset
|
245 |
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_LOWERED | FR_DARKENED); |
4405e2e80db6
(svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents:
8729
diff
changeset
|
246 |
break; |
4405e2e80db6
(svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents:
8729
diff
changeset
|
247 |
|
4939
bef7c24a6027
(svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents:
4938
diff
changeset
|
248 |
case WWT_TEXTBTN: |
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
249 |
case WWT_TEXTBTN_2: |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
250 |
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
251 |
/* FALL THROUGH */ |
0 | 252 |
|
4345
1da147230c79
(svn r6046) CodeChange : Rename WWT_5 Widget type to WWT_LABEL : a centered label
belugas
parents:
3762
diff
changeset
|
253 |
case WWT_LABEL: { |
4547
d37c2d172ad4
(svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents:
4444
diff
changeset
|
254 |
StringID str = wi->data; |
0 | 255 |
|
4939
bef7c24a6027
(svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents:
4938
diff
changeset
|
256 |
if ((wi->type & WWT_MASK) == WWT_TEXTBTN_2 && clicked) str++; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
257 |
|
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
6481
diff
changeset
|
258 |
DrawStringCentered(((r.left + r.right + 1) >> 1) + clicked, ((r.top + r.bottom + 1) >> 1) - 5 + clicked, str, TC_FROMSTRING); |
8320
5a41b1329cdf
(svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138
parents:
8284
diff
changeset
|
259 |
break; |
0 | 260 |
} |
261 |
||
6278
f4d4b7c1c886
(svn r9088) -Add : a new type of widget, called WWT_TEXT. It is a simple truncated string. It will be usefull on windows where lot of simple text is always drawn on the WE_PAINT event, making the code clearer. For now, left, right (total size of the window), top, color and data are necessary to use it. Maybe more features will be available soon.
belugas
parents:
5824
diff
changeset
|
262 |
case WWT_TEXT: { |
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
263 |
const StringID str = wi->data; |
6278
f4d4b7c1c886
(svn r9088) -Add : a new type of widget, called WWT_TEXT. It is a simple truncated string. It will be usefull on windows where lot of simple text is always drawn on the WE_PAINT event, making the code clearer. For now, left, right (total size of the window), top, color and data are necessary to use it. Maybe more features will be available soon.
belugas
parents:
5824
diff
changeset
|
264 |
|
f4d4b7c1c886
(svn r9088) -Add : a new type of widget, called WWT_TEXT. It is a simple truncated string. It will be usefull on windows where lot of simple text is always drawn on the WE_PAINT event, making the code clearer. For now, left, right (total size of the window), top, color and data are necessary to use it. Maybe more features will be available soon.
belugas
parents:
5824
diff
changeset
|
265 |
if (str != STR_NULL) DrawStringTruncated(r.left, r.top, str, wi->color, r.right - r.left); |
f4d4b7c1c886
(svn r9088) -Add : a new type of widget, called WWT_TEXT. It is a simple truncated string. It will be usefull on windows where lot of simple text is always drawn on the WE_PAINT event, making the code clearer. For now, left, right (total size of the window), top, color and data are necessary to use it. Maybe more features will be available soon.
belugas
parents:
5824
diff
changeset
|
266 |
break; |
f4d4b7c1c886
(svn r9088) -Add : a new type of widget, called WWT_TEXT. It is a simple truncated string. It will be usefull on windows where lot of simple text is always drawn on the WE_PAINT event, making the code clearer. For now, left, right (total size of the window), top, color and data are necessary to use it. Maybe more features will be available soon.
belugas
parents:
5824
diff
changeset
|
267 |
} |
f4d4b7c1c886
(svn r9088) -Add : a new type of widget, called WWT_TEXT. It is a simple truncated string. It will be usefull on windows where lot of simple text is always drawn on the WE_PAINT event, making the code clearer. For now, left, right (total size of the window), top, color and data are necessary to use it. Maybe more features will be available soon.
belugas
parents:
5824
diff
changeset
|
268 |
|
4939
bef7c24a6027
(svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents:
4938
diff
changeset
|
269 |
case WWT_INSET: { |
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
270 |
const StringID str = wi->data; |
1938
70baf462aff1
(svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents:
1891
diff
changeset
|
271 |
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_LOWERED | FR_DARKENED); |
0 | 272 |
|
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
6481
diff
changeset
|
273 |
if (str != STR_NULL) DrawStringTruncated(r.left + 2, r.top + 1, str, TC_FROMSTRING, r.right - r.left - 10); |
8320
5a41b1329cdf
(svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138
parents:
8284
diff
changeset
|
274 |
break; |
0 | 275 |
} |
276 |
||
277 |
case WWT_MATRIX: { |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
278 |
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
279 |
|
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
280 |
int c = GB(wi->data, 0, 8); |
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
281 |
int amt1 = (wi->right - wi->left + 1) / c; |
0 | 282 |
|
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
283 |
int d = GB(wi->data, 8, 8); |
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
284 |
int amt2 = (wi->bottom - wi->top + 1) / d; |
0 | 285 |
|
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
286 |
int color = _colour_gradient[wi->color & 0xF][6]; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
287 |
|
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
288 |
int x = r.left; |
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
289 |
for (int ctr = c; ctr > 1; ctr--) { |
0 | 290 |
x += amt1; |
2639 | 291 |
GfxFillRect(x, r.top + 1, x, r.bottom - 1, color); |
0 | 292 |
} |
293 |
||
294 |
x = r.top; |
|
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
295 |
for (int ctr = d; ctr > 1; ctr--) { |
0 | 296 |
x += amt2; |
2639 | 297 |
GfxFillRect(r.left + 1, x, r.right - 1, x, color); |
0 | 298 |
} |
299 |
||
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
300 |
color = _colour_gradient[wi->color & 0xF][4]; |
0 | 301 |
|
2639 | 302 |
x = r.left - 1; |
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
303 |
for (int ctr = c; ctr > 1; ctr--) { |
0 | 304 |
x += amt1; |
2639 | 305 |
GfxFillRect(x, r.top + 1, x, r.bottom - 1, color); |
0 | 306 |
} |
307 |
||
2639 | 308 |
x = r.top - 1; |
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
309 |
for (int ctr = d; ctr > 1; ctr--) { |
0 | 310 |
x += amt2; |
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
311 |
GfxFillRect(r.left + 1, x, r.right - 1, x, color); |
0 | 312 |
} |
313 |
||
8320
5a41b1329cdf
(svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138
parents:
8284
diff
changeset
|
314 |
break; |
0 | 315 |
} |
316 |
||
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6278
diff
changeset
|
317 |
/* vertical scrollbar */ |
0 | 318 |
case WWT_SCROLLBAR: { |
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
319 |
assert(wi->data == 0); |
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
320 |
assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere! |
893
f4698309dec7
(svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents:
884
diff
changeset
|
321 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6278
diff
changeset
|
322 |
/* draw up/down buttons */ |
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
323 |
clicked = ((this->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_UP); |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
324 |
DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
6481
diff
changeset
|
325 |
DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, TC_BLACK); |
0 | 326 |
|
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
327 |
clicked = (((this->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_DOWN)); |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
328 |
DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
6481
diff
changeset
|
329 |
DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, TC_BLACK); |
0 | 330 |
|
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
331 |
int c1 = _colour_gradient[wi->color & 0xF][3]; |
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
332 |
int c2 = _colour_gradient[wi->color & 0xF][7]; |
0 | 333 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6278
diff
changeset
|
334 |
/* draw "shaded" background */ |
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
335 |
GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c2); |
9607
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9273
diff
changeset
|
336 |
GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c1, FILLRECT_CHECKER); |
0 | 337 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6278
diff
changeset
|
338 |
/* draw shaded lines */ |
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
339 |
GfxFillRect(r.left + 2, r.top + 10, r.left + 2, r.bottom - 10, c1); |
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
340 |
GfxFillRect(r.left + 3, r.top + 10, r.left + 3, r.bottom - 10, c2); |
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
341 |
GfxFillRect(r.left + 7, r.top + 10, r.left + 7, r.bottom - 10, c1); |
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
342 |
GfxFillRect(r.left + 8, r.top + 10, r.left + 8, r.bottom - 10, c2); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
343 |
|
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
344 |
Point pt = HandleScrollbarHittest(&this->vscroll, r.top, r.bottom); |
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
345 |
DrawFrameRect(r.left, pt.x, r.right, pt.y, wi->color, (this->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_MIDDLE ? FR_LOWERED : FR_NONE); |
842 | 346 |
break; |
347 |
} |
|
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
348 |
|
842 | 349 |
case WWT_SCROLL2BAR: { |
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
350 |
assert(wi->data == 0); |
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
351 |
assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere! |
893
f4698309dec7
(svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents:
884
diff
changeset
|
352 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6278
diff
changeset
|
353 |
/* draw up/down buttons */ |
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
354 |
clicked = ((this->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_UP | WF_SCROLL2)); |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
355 |
DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
6481
diff
changeset
|
356 |
DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, TC_BLACK); |
842 | 357 |
|
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
358 |
clicked = ((this->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_DOWN | WF_SCROLL2)); |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
359 |
DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
7824
5a63d41b59ea
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
6481
diff
changeset
|
360 |
DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, TC_BLACK); |
842 | 361 |
|
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
362 |
int c1 = _colour_gradient[wi->color & 0xF][3]; |
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
363 |
int c2 = _colour_gradient[wi->color & 0xF][7]; |
842 | 364 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6278
diff
changeset
|
365 |
/* draw "shaded" background */ |
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
366 |
GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c2); |
9607
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9273
diff
changeset
|
367 |
GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c1, FILLRECT_CHECKER); |
842 | 368 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6278
diff
changeset
|
369 |
/* draw shaded lines */ |
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
370 |
GfxFillRect(r.left + 2, r.top + 10, r.left + 2, r.bottom - 10, c1); |
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
371 |
GfxFillRect(r.left + 3, r.top + 10, r.left + 3, r.bottom - 10, c2); |
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
372 |
GfxFillRect(r.left + 7, r.top + 10, r.left + 7, r.bottom - 10, c1); |
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
373 |
GfxFillRect(r.left + 8, r.top + 10, r.left + 8, r.bottom - 10, c2); |
842 | 374 |
|
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
375 |
Point pt = HandleScrollbarHittest(&this->vscroll2, r.top, r.bottom); |
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
376 |
DrawFrameRect(r.left, pt.x, r.right, pt.y, wi->color, (this->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_MIDDLE | WF_SCROLL2) ? FR_LOWERED : FR_NONE); |
0 | 377 |
break; |
378 |
} |
|
379 |
||
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6278
diff
changeset
|
380 |
/* horizontal scrollbar */ |
0 | 381 |
case WWT_HSCROLLBAR: { |
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
382 |
assert(wi->data == 0); |
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
383 |
assert(r.bottom - r.top == 11); // To ensure the same sizes are used everywhere! |
893
f4698309dec7
(svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents:
884
diff
changeset
|
384 |
|
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
385 |
clicked = ((this->flags4 & (WF_SCROLL_UP | WF_HSCROLL)) == (WF_SCROLL_UP | WF_HSCROLL)); |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
386 |
DrawFrameRect(r.left, r.top, r.left + 9, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5587
diff
changeset
|
387 |
DrawSprite(SPR_ARROW_LEFT, PAL_NONE, r.left + 1 + clicked, r.top + 1 + clicked); |
0 | 388 |
|
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
389 |
clicked = ((this->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL)) == (WF_SCROLL_DOWN | WF_HSCROLL)); |
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
390 |
DrawFrameRect(r.right - 9, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5587
diff
changeset
|
391 |
DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, r.right - 8 + clicked, r.top + 1 + clicked); |
0 | 392 |
|
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
393 |
int c1 = _colour_gradient[wi->color & 0xF][3]; |
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
394 |
int c2 = _colour_gradient[wi->color & 0xF][7]; |
0 | 395 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6278
diff
changeset
|
396 |
/* draw "shaded" background */ |
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
397 |
GfxFillRect(r.left + 10, r.top, r.right - 10, r.bottom, c2); |
9607
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9273
diff
changeset
|
398 |
GfxFillRect(r.left + 10, r.top, r.right - 10, r.bottom, c1, FILLRECT_CHECKER); |
0 | 399 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6278
diff
changeset
|
400 |
/* draw shaded lines */ |
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
401 |
GfxFillRect(r.left + 10, r.top + 2, r.right - 10, r.top + 2, c1); |
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
402 |
GfxFillRect(r.left + 10, r.top + 3, r.right - 10, r.top + 3, c2); |
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
403 |
GfxFillRect(r.left + 10, r.top + 7, r.right - 10, r.top + 7, c1); |
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
404 |
GfxFillRect(r.left + 10, r.top + 8, r.right - 10, r.top + 8, c2); |
0 | 405 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6278
diff
changeset
|
406 |
/* draw actual scrollbar */ |
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
407 |
Point pt = HandleScrollbarHittest(&this->hscroll, r.left, r.right); |
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
408 |
DrawFrameRect(pt.x, r.top, pt.y, r.bottom, wi->color, (this->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL)) == (WF_SCROLL_MIDDLE | WF_HSCROLL) ? FR_LOWERED : FR_NONE); |
0 | 409 |
|
410 |
break; |
|
411 |
} |
|
412 |
||
413 |
case WWT_FRAME: { |
|
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
414 |
const StringID str = wi->data; |
860
fad6642f6217
(svn r1341) -Fix: fix WWT_FRAME drawing when there is no text there (STR_NULL)
darkvater
parents:
845
diff
changeset
|
415 |
int x2 = r.left; // by default the left side is the left side of the widget |
0 | 416 |
|
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
417 |
if (str != STR_NULL) x2 = DrawString(r.left + 6, r.top, str, TC_FROMSTRING); |
0 | 418 |
|
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
419 |
int c1 = _colour_gradient[wi->color][3]; |
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
420 |
int c2 = _colour_gradient[wi->color][7]; |
0 | 421 |
|
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
422 |
/* Line from upper left corner to start of text */ |
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
423 |
GfxFillRect(r.left, r.top + 4, r.left + 4, r.top + 4, c1); |
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
424 |
GfxFillRect(r.left + 1, r.top + 5, r.left + 4, r.top + 5, c2); |
0 | 425 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6278
diff
changeset
|
426 |
/* Line from end of text to upper right corner */ |
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
427 |
GfxFillRect(x2, r.top + 4, r.right - 1, r.top + 4, c1); |
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
428 |
GfxFillRect(x2, r.top + 5, r.right - 2, r.top + 5, c2); |
0 | 429 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6278
diff
changeset
|
430 |
/* Line from upper left corner to bottom left corner */ |
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
431 |
GfxFillRect(r.left, r.top + 5, r.left, r.bottom - 1, c1); |
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
432 |
GfxFillRect(r.left + 1, r.top + 6, r.left + 1, r.bottom - 2, c2); |
0 | 433 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6278
diff
changeset
|
434 |
/*Line from upper right corner to bottom right corner */ |
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
435 |
GfxFillRect(r.right - 1, r.top + 5, r.right - 1, r.bottom - 2, c1); |
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
436 |
GfxFillRect(r.right, r.top + 4, r.right, r.bottom - 1, c2); |
0 | 437 |
|
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
438 |
GfxFillRect(r.left + 1, r.bottom - 1, r.right - 1, r.bottom - 1, c1); |
0 | 439 |
GfxFillRect(r.left, r.bottom, r.right, r.bottom, c2); |
440 |
||
8320
5a41b1329cdf
(svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138
parents:
8284
diff
changeset
|
441 |
break; |
0 | 442 |
} |
443 |
||
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
444 |
case WWT_STICKYBOX: |
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
445 |
assert(wi->data == 0); |
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
446 |
assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere! |
2703
a969970a5245
(svn r3247) - Fix: "[ 1335580 ] sticky windows not sticky anymore"
peter1138
parents:
2683
diff
changeset
|
447 |
|
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
448 |
clicked = !!(this->flags4 & WF_STICKY); |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
449 |
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5587
diff
changeset
|
450 |
DrawSprite((clicked) ? SPR_PIN_UP : SPR_PIN_DOWN, PAL_NONE, r.left + 2 + clicked, r.top + 3 + clicked); |
682
74c70f645d95
(svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents:
674
diff
changeset
|
451 |
break; |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
452 |
|
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
453 |
case WWT_RESIZEBOX: |
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
454 |
assert(wi->data == 0); |
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
455 |
assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere! |
915 | 456 |
|
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
457 |
clicked = !!(this->flags4 & WF_SIZING); |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
458 |
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5587
diff
changeset
|
459 |
DrawSprite(SPR_WINDOW_RESIZE, PAL_NONE, r.left + 3 + clicked, r.top + 3 + clicked); |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
460 |
break; |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
461 |
|
2757
d1ccb6600be3
(svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents:
2703
diff
changeset
|
462 |
case WWT_CLOSEBOX: { |
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
463 |
const StringID str = wi->data; |
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
464 |
|
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
465 |
assert(str == STR_00C5 || str == STR_00C6); // black or silver cross |
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
466 |
assert(r.right - r.left == 10); // To ensure the same sizes are used everywhere |
2757
d1ccb6600be3
(svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents:
2703
diff
changeset
|
467 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
468 |
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_NONE); |
7962
4a815b659fd7
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
7928
diff
changeset
|
469 |
DrawString(r.left + 2, r.top + 2, str, TC_FROMSTRING); |
2757
d1ccb6600be3
(svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents:
2703
diff
changeset
|
470 |
break; |
d1ccb6600be3
(svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents:
2703
diff
changeset
|
471 |
} |
d1ccb6600be3
(svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents:
2703
diff
changeset
|
472 |
|
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
473 |
case WWT_CAPTION: |
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
474 |
assert(r.bottom - r.top == 13); // To ensure the same sizes are used everywhere! |
1938
70baf462aff1
(svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents:
1891
diff
changeset
|
475 |
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_BORDERONLY); |
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
476 |
DrawFrameRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, wi->color, (this->caption_color == 0xFF) ? FR_LOWERED | FR_DARKENED : FR_LOWERED | FR_DARKENED | FR_BORDERONLY); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
477 |
|
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
478 |
if (this->caption_color != 0xFF) { |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
9892
diff
changeset
|
479 |
GfxFillRect(r.left + 2, r.top + 2, r.right - 2, r.bottom - 2, _colour_gradient[_company_colours[this->caption_color]][4]); |
0 | 480 |
} |
481 |
||
9892
8dc6b933e669
(svn r14040) -Codechange:Remove a hard coded value that is not even representative,
belugas
parents:
9843
diff
changeset
|
482 |
DrawStringCenteredTruncated(r.left + 2, r.right - 2, r.top + 2, wi->data, TC_FROMSTRING); |
8320
5a41b1329cdf
(svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138
parents:
8284
diff
changeset
|
483 |
break; |
8335
09a2e049b3a8
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents:
8320
diff
changeset
|
484 |
|
09a2e049b3a8
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents:
8320
diff
changeset
|
485 |
case WWT_DROPDOWN: { |
09a2e049b3a8
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents:
8320
diff
changeset
|
486 |
assert(r.bottom - r.top == 11); // ensure consistent size |
09a2e049b3a8
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents:
8320
diff
changeset
|
487 |
|
09a2e049b3a8
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents:
8320
diff
changeset
|
488 |
StringID str = wi->data; |
09a2e049b3a8
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents:
8320
diff
changeset
|
489 |
DrawFrameRect(r.left, r.top, r.right - 12, r.bottom, wi->color, FR_NONE); |
09a2e049b3a8
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents:
8320
diff
changeset
|
490 |
DrawFrameRect(r.right - 11, r.top, r.right, r.bottom, wi->color, clicked ? FR_LOWERED : FR_NONE); |
09a2e049b3a8
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents:
8320
diff
changeset
|
491 |
DrawString(r.right - (clicked ? 8 : 9), r.top + (clicked ? 2 : 1), STR_0225, TC_BLACK); |
09a2e049b3a8
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents:
8320
diff
changeset
|
492 |
if (str != STR_NULL) DrawStringTruncated(r.left + 2, r.top + 1, str, TC_BLACK, r.right - r.left - 12); |
09a2e049b3a8
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents:
8320
diff
changeset
|
493 |
break; |
09a2e049b3a8
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents:
8320
diff
changeset
|
494 |
} |
09a2e049b3a8
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents:
8320
diff
changeset
|
495 |
|
09a2e049b3a8
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents:
8320
diff
changeset
|
496 |
case WWT_DROPDOWNIN: { |
09a2e049b3a8
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents:
8320
diff
changeset
|
497 |
assert(r.bottom - r.top == 11); // ensure consistent size |
09a2e049b3a8
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents:
8320
diff
changeset
|
498 |
|
09a2e049b3a8
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents:
8320
diff
changeset
|
499 |
StringID str = wi->data; |
09a2e049b3a8
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents:
8320
diff
changeset
|
500 |
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_LOWERED | FR_DARKENED); |
09a2e049b3a8
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents:
8320
diff
changeset
|
501 |
DrawFrameRect(r.right - 11, r.top + 1, r.right - 1, r.bottom - 1, wi->color, clicked ? FR_LOWERED : FR_NONE); |
09a2e049b3a8
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents:
8320
diff
changeset
|
502 |
DrawString(r.right - (clicked ? 8 : 9), r.top + (clicked ? 2 : 1), STR_0225, TC_BLACK); |
09a2e049b3a8
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents:
8320
diff
changeset
|
503 |
if (str != STR_NULL) DrawStringTruncated(r.left + 2, r.top + 2, str, TC_BLACK, r.right - r.left - 12); |
09a2e049b3a8
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents:
8320
diff
changeset
|
504 |
break; |
09a2e049b3a8
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents:
8320
diff
changeset
|
505 |
} |
0 | 506 |
} |
8320
5a41b1329cdf
(svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138
parents:
8284
diff
changeset
|
507 |
|
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
508 |
if (this->IsWidgetDisabled(i)) { |
9607
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9273
diff
changeset
|
509 |
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, _colour_gradient[wi->color & 0xF][2], FILLRECT_CHECKER); |
8320
5a41b1329cdf
(svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138
parents:
8284
diff
changeset
|
510 |
} |
5236
4c1289d5e45a
(svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents:
5196
diff
changeset
|
511 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
512 |
|
0 | 513 |
|
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
514 |
if (this->flags4 & WF_WHITE_BORDER_MASK) { |
9770
8c260fb382f8
(svn r13907) -Codechange: Replace a number with Colours enum on DrawFrameRect usage
belugas
parents:
9607
diff
changeset
|
515 |
DrawFrameRect(0, 0, this->width - 1, this->height - 1, COLOUR_WHITE, FR_BORDERONLY); |
0 | 516 |
} |
517 |
||
518 |
} |
|
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
0
diff
changeset
|
519 |
|
5824
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
520 |
static void ResizeWidgets(Window *w, byte a, byte b) |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
521 |
{ |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
522 |
int16 offset = w->widget[a].left; |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
523 |
int16 length = w->widget[b].right - offset; |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
524 |
|
8729
1f57e8a0d5b3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8418
diff
changeset
|
525 |
w->widget[a].right = (length / 2) + offset; |
5824
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
526 |
|
5822
f71317de4ab6
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5668
diff
changeset
|
527 |
w->widget[b].left = w->widget[a].right + 1; |
f71317de4ab6
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5668
diff
changeset
|
528 |
} |
f71317de4ab6
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5668
diff
changeset
|
529 |
|
5824
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
530 |
static void ResizeWidgets(Window *w, byte a, byte b, byte c) |
5822
f71317de4ab6
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5668
diff
changeset
|
531 |
{ |
5824
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
532 |
int16 offset = w->widget[a].left; |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
533 |
int16 length = w->widget[c].right - offset; |
5822
f71317de4ab6
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5668
diff
changeset
|
534 |
|
5824
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
535 |
w->widget[a].right = length / 3; |
5822
f71317de4ab6
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5668
diff
changeset
|
536 |
w->widget[b].right = w->widget[a].right * 2; |
f71317de4ab6
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5668
diff
changeset
|
537 |
|
5824
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
538 |
w->widget[a].right += offset; |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
539 |
w->widget[b].right += offset; |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
540 |
|
5822
f71317de4ab6
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5668
diff
changeset
|
541 |
/* Now the right side of the buttons are set. We will now set the left sides next to them */ |
f71317de4ab6
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5668
diff
changeset
|
542 |
w->widget[b].left = w->widget[a].right + 1; |
f71317de4ab6
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5668
diff
changeset
|
543 |
w->widget[c].left = w->widget[b].right + 1; |
f71317de4ab6
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5668
diff
changeset
|
544 |
} |
f71317de4ab6
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5668
diff
changeset
|
545 |
|
5824
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
546 |
/** Evenly distribute some widgets when resizing horizontally (often a button row) |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
547 |
* When only two arguments are given, the widgets are presumed to be on a line and only the ends are given |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6432
diff
changeset
|
548 |
* @param w Window to modify |
5824
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
549 |
* @param left The leftmost widget to resize |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
550 |
* @param right The rightmost widget to resize. Since right side of it is used, remember to set it to RESIZE_RIGHT |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
551 |
*/ |
5822
f71317de4ab6
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5668
diff
changeset
|
552 |
void ResizeButtons(Window *w, byte left, byte right) |
f71317de4ab6
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5668
diff
changeset
|
553 |
{ |
5824
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
554 |
int16 num_widgets = right - left + 1; |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
555 |
|
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
556 |
if (num_widgets < 2) NOT_REACHED(); |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
557 |
|
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
558 |
switch (num_widgets) { |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
559 |
case 2: ResizeWidgets(w, left, right); break; |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
560 |
case 3: ResizeWidgets(w, left, left + 1, right); break; |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
561 |
default: { |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
562 |
/* Looks like we got more than 3 widgets to resize |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
563 |
* Now we will find the middle of the space desinated for the widgets |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
564 |
* and place half of the widgets on each side of it and call recursively. |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
565 |
* Eventually we will get down to blocks of 2-3 widgets and we got code to handle those cases */ |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
566 |
int16 offset = w->widget[left].left; |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
567 |
int16 length = w->widget[right].right - offset; |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
568 |
byte widget = ((num_widgets - 1)/ 2) + left; // rightmost widget of the left side |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
569 |
|
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
570 |
/* Now we need to find the middle of the widgets. |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
571 |
* It will not always be the middle because if we got an uneven number of widgets, |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
572 |
* we will need it to be 2/5, 3/7 and so on |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
573 |
* To get this, we multiply with num_widgets/num_widgets. Since we calculate in int, we will get: |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
574 |
* |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
575 |
* num_widgets/2 (rounding down) |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
576 |
* --------------- |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
577 |
* num_widgets |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
578 |
* |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
579 |
* as multiplier to length. We just multiply before divide to that we stay in the int area though */ |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
580 |
int16 middle = ((length * num_widgets) / (2 * num_widgets)) + offset; |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
581 |
|
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
582 |
/* Set left and right on the widgets, that's next to our "middle" */ |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
583 |
w->widget[widget].right = middle; |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
584 |
w->widget[widget + 1].left = w->widget[widget].right + 1; |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
585 |
/* Now resize the left and right of the middle */ |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
586 |
ResizeButtons(w, left, widget); |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
587 |
ResizeButtons(w, widget + 1, right); |
8398b44ad3bc
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
5822
diff
changeset
|
588 |
} |
5822
f71317de4ab6
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5668
diff
changeset
|
589 |
} |
f71317de4ab6
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5668
diff
changeset
|
590 |
} |
8349
e61105cb1f87
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138
parents:
8335
diff
changeset
|
591 |
|
8857
7593af4962e6
(svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents:
8737
diff
changeset
|
592 |
/** Resize a widget and shuffle other widgets around to fit. */ |
9834
7474149531c1
(svn r13977) -Codechange: Let ResizeWindowForWidget() handle hidden (zero height or zero width) widgets.
peter1138
parents:
9779
diff
changeset
|
593 |
void ResizeWindowForWidget(Window *w, uint widget, int delta_x, int delta_y) |
8418
afae92fe35f1
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8411
diff
changeset
|
594 |
{ |
afae92fe35f1
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8411
diff
changeset
|
595 |
int right = w->widget[widget].right; |
afae92fe35f1
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8411
diff
changeset
|
596 |
int bottom = w->widget[widget].bottom; |
afae92fe35f1
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8411
diff
changeset
|
597 |
|
afae92fe35f1
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8411
diff
changeset
|
598 |
for (uint i = 0; i < w->widget_count; i++) { |
9834
7474149531c1
(svn r13977) -Codechange: Let ResizeWindowForWidget() handle hidden (zero height or zero width) widgets.
peter1138
parents:
9779
diff
changeset
|
599 |
if (w->widget[i].left >= right && i != widget) w->widget[i].left += delta_x; |
8418
afae92fe35f1
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8411
diff
changeset
|
600 |
if (w->widget[i].right >= right) w->widget[i].right += delta_x; |
9834
7474149531c1
(svn r13977) -Codechange: Let ResizeWindowForWidget() handle hidden (zero height or zero width) widgets.
peter1138
parents:
9779
diff
changeset
|
601 |
if (w->widget[i].top >= bottom && i != widget) w->widget[i].top += delta_y; |
8418
afae92fe35f1
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8411
diff
changeset
|
602 |
if (w->widget[i].bottom >= bottom) w->widget[i].bottom += delta_y; |
afae92fe35f1
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8411
diff
changeset
|
603 |
} |
afae92fe35f1
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8411
diff
changeset
|
604 |
|
9834
7474149531c1
(svn r13977) -Codechange: Let ResizeWindowForWidget() handle hidden (zero height or zero width) widgets.
peter1138
parents:
9779
diff
changeset
|
605 |
/* A hidden widget has bottom == top or right == left, we need to make it |
7474149531c1
(svn r13977) -Codechange: Let ResizeWindowForWidget() handle hidden (zero height or zero width) widgets.
peter1138
parents:
9779
diff
changeset
|
606 |
* one less to fit in its new gap. */ |
7474149531c1
(svn r13977) -Codechange: Let ResizeWindowForWidget() handle hidden (zero height or zero width) widgets.
peter1138
parents:
9779
diff
changeset
|
607 |
if (right == w->widget[widget].left) w->widget[widget].right--; |
7474149531c1
(svn r13977) -Codechange: Let ResizeWindowForWidget() handle hidden (zero height or zero width) widgets.
peter1138
parents:
9779
diff
changeset
|
608 |
if (bottom == w->widget[widget].top) w->widget[widget].bottom--; |
7474149531c1
(svn r13977) -Codechange: Let ResizeWindowForWidget() handle hidden (zero height or zero width) widgets.
peter1138
parents:
9779
diff
changeset
|
609 |
|
9843
96b2f22e54da
(svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents:
9834
diff
changeset
|
610 |
if (w->widget[widget].left > w->widget[widget].right) w->widget[widget].right = w->widget[widget].left; |
96b2f22e54da
(svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents:
9834
diff
changeset
|
611 |
if (w->widget[widget].top > w->widget[widget].bottom) w->widget[widget].bottom = w->widget[widget].top; |
96b2f22e54da
(svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138
parents:
9834
diff
changeset
|
612 |
|
8418
afae92fe35f1
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8411
diff
changeset
|
613 |
w->width += delta_x; |
afae92fe35f1
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8411
diff
changeset
|
614 |
w->height += delta_y; |
afae92fe35f1
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8411
diff
changeset
|
615 |
w->resize.width += delta_x; |
afae92fe35f1
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8411
diff
changeset
|
616 |
w->resize.height += delta_y; |
afae92fe35f1
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8411
diff
changeset
|
617 |
} |
afae92fe35f1
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8411
diff
changeset
|
618 |
|
8349
e61105cb1f87
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138
parents:
8335
diff
changeset
|
619 |
/** Draw a sort button's up or down arrow symbol. |
e61105cb1f87
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138
parents:
8335
diff
changeset
|
620 |
* @param w Window of widget |
e61105cb1f87
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138
parents:
8335
diff
changeset
|
621 |
* @param widget Sort button widget |
e61105cb1f87
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138
parents:
8335
diff
changeset
|
622 |
* @param state State of sort button |
e61105cb1f87
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138
parents:
8335
diff
changeset
|
623 |
*/ |
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
624 |
void Window::DrawSortButtonState(int widget, SortButtonState state) const |
8349
e61105cb1f87
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138
parents:
8335
diff
changeset
|
625 |
{ |
e61105cb1f87
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138
parents:
8335
diff
changeset
|
626 |
if (state == SBS_OFF) return; |
e61105cb1f87
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138
parents:
8335
diff
changeset
|
627 |
|
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
628 |
int offset = this->IsWidgetLowered(widget) ? 1 : 0; |
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9116
diff
changeset
|
629 |
DoDrawString(state == SBS_DOWN ? DOWNARROW : UPARROW, this->widget[widget].right - 11 + offset, this->widget[widget].top + 1 + offset, TC_BLACK); |
8349
e61105cb1f87
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138
parents:
8335
diff
changeset
|
630 |
} |