author | rubidium |
Mon, 24 Mar 2008 06:52:52 +0000 | |
changeset 9225 | 1c31e491e3cf |
parent 8914 | 6ebaa4b4eb2b |
child 9233 | 4daa9bb8dbf7 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6604
diff
changeset
|
3 |
/** @file widget.cpp */ |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6604
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1657
diff
changeset
|
6 |
#include "openttd.h" |
8750
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8720
diff
changeset
|
7 |
#include "core/math_func.hpp" |
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8720
diff
changeset
|
8 |
#include "player_func.h" |
8720
4e60c30e2006
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8627
diff
changeset
|
9 |
#include "gfx_func.h" |
8602
9e75e594a068
(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:
8578
diff
changeset
|
10 |
#include "window_gui.h" |
8627
448ebf3a8291
(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:
8617
diff
changeset
|
11 |
#include "window_func.h" |
8780
6f3f3ec6c69a
(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:
8760
diff
changeset
|
12 |
#include "widgets/dropdown_func.h" |
8627
448ebf3a8291
(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:
8617
diff
changeset
|
13 |
|
8760
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8750
diff
changeset
|
14 |
#include "table/sprites.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8750
diff
changeset
|
15 |
#include "table/strings.h" |
0 | 16 |
|
8907
5104ad700e31
(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:
8845
diff
changeset
|
17 |
static const char *UPARROW = "\xEE\x8A\xA0"; |
8845
e0eac76d3d16
(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:
8831
diff
changeset
|
18 |
static const char *DOWNARROW = "\xEE\x8A\xAA"; |
e0eac76d3d16
(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:
8831
diff
changeset
|
19 |
|
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2406
diff
changeset
|
20 |
static Point HandleScrollbarHittest(const Scrollbar *sb, int top, int bottom) |
0 | 21 |
{ |
22 |
Point pt; |
|
23 |
int height, count, pos, cap; |
|
24 |
||
25 |
top += 10; |
|
26 |
bottom -= 9; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
27 |
|
0 | 28 |
height = (bottom - top); |
29 |
||
30 |
pos = sb->pos; |
|
31 |
count = sb->count; |
|
32 |
cap = sb->cap; |
|
33 |
||
2026 | 34 |
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
|
35 |
|
0 | 36 |
if (cap > count) cap = count; |
2639 | 37 |
if (count != 0) bottom -= (count - pos - cap) * height / count; |
0 | 38 |
|
39 |
pt.x = top; |
|
40 |
pt.y = bottom - 1; |
|
41 |
return pt; |
|
42 |
} |
|
43 |
||
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6928
diff
changeset
|
44 |
/** Special handling for the scrollbar widget type. |
0 | 45 |
* Handles the special scrolling buttons and other |
46 |
* scrolling. |
|
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6928
diff
changeset
|
47 |
* @param w Window on which a scroll was performed. |
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6928
diff
changeset
|
48 |
* @param wi Pointer to the scrollbar widget. |
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6928
diff
changeset
|
49 |
* @param x The X coordinate of the mouse click. |
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6928
diff
changeset
|
50 |
* @param y The Y coordinate of the mouse click. */ |
0 | 51 |
void ScrollbarClickHandler(Window *w, const Widget *wi, int x, int y) |
52 |
{ |
|
53 |
int mi, ma, pos; |
|
54 |
Scrollbar *sb; |
|
55 |
||
842 | 56 |
switch (wi->type) { |
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
57 |
case WWT_SCROLLBAR: |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6604
diff
changeset
|
58 |
/* vertical scroller */ |
842 | 59 |
w->flags4 &= ~WF_HSCROLL; |
60 |
w->flags4 &= ~WF_SCROLL2; |
|
61 |
mi = wi->top; |
|
62 |
ma = wi->bottom; |
|
63 |
pos = y; |
|
64 |
sb = &w->vscroll; |
|
65 |
break; |
|
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
66 |
|
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
67 |
case WWT_SCROLL2BAR: |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6604
diff
changeset
|
68 |
/* 2nd vertical scroller */ |
842 | 69 |
w->flags4 &= ~WF_HSCROLL; |
70 |
w->flags4 |= WF_SCROLL2; |
|
71 |
mi = wi->top; |
|
72 |
ma = wi->bottom; |
|
73 |
pos = y; |
|
74 |
sb = &w->vscroll2; |
|
75 |
break; |
|
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
76 |
|
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
77 |
case WWT_HSCROLLBAR: |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6604
diff
changeset
|
78 |
/* horizontal scroller */ |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
79 |
w->flags4 &= ~WF_SCROLL2; |
842 | 80 |
w->flags4 |= WF_HSCROLL; |
81 |
mi = wi->left; |
|
82 |
ma = wi->right; |
|
83 |
pos = x; |
|
84 |
sb = &w->hscroll; |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
85 |
break; |
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
86 |
|
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
87 |
default: NOT_REACHED(); |
0 | 88 |
} |
89 |
if (pos <= mi+9) { |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6604
diff
changeset
|
90 |
/* Pressing the upper button? */ |
2597 | 91 |
w->flags4 |= WF_SCROLL_UP; |
92 |
if (_scroller_click_timeout == 0) { |
|
93 |
_scroller_click_timeout = 6; |
|
94 |
if (sb->pos != 0) sb->pos--; |
|
0 | 95 |
} |
2597 | 96 |
_left_button_clicked = false; |
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
97 |
} else if (pos >= ma - 10) { |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6604
diff
changeset
|
98 |
/* Pressing the lower button? */ |
2597 | 99 |
w->flags4 |= WF_SCROLL_DOWN; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
100 |
|
2597 | 101 |
if (_scroller_click_timeout == 0) { |
102 |
_scroller_click_timeout = 6; |
|
103 |
if ((byte)(sb->pos + sb->cap) < sb->count) |
|
104 |
sb->pos++; |
|
0 | 105 |
} |
2597 | 106 |
_left_button_clicked = false; |
0 | 107 |
} else { |
108 |
Point pt = HandleScrollbarHittest(sb, mi, ma); |
|
109 |
||
110 |
if (pos < pt.x) { |
|
111 |
sb->pos = max(sb->pos - sb->cap, 0); |
|
112 |
} else if (pos > pt.y) { |
|
113 |
sb->pos = min( |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
114 |
sb->pos + sb->cap, |
0 | 115 |
max(sb->count - sb->cap, 0) |
116 |
); |
|
117 |
} else { |
|
118 |
_scrollbar_start_pos = pt.x - mi - 9; |
|
119 |
_scrollbar_size = ma - mi - 23; |
|
120 |
w->flags4 |= WF_SCROLL_MIDDLE; |
|
121 |
_scrolling_scrollbar = true; |
|
122 |
_cursorpos_drag_start = _cursor.pos; |
|
123 |
} |
|
124 |
} |
|
125 |
||
126 |
SetWindowDirty(w); |
|
127 |
} |
|
128 |
||
2021
3be628c59488
(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
|
129 |
/** Returns the index for the widget located at the given position |
3be628c59488
(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
|
130 |
* relative to the window. It includes all widget-corner pixels as well. |
3be628c59488
(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
|
131 |
* @param *w Window to look inside |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6928
diff
changeset
|
132 |
* @param x The Window client X coordinate |
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6928
diff
changeset
|
133 |
* @param y The Window client y coordinate |
2021
3be628c59488
(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
|
134 |
* @return A widget index, or -1 if no widget was found. |
0 | 135 |
*/ |
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2406
diff
changeset
|
136 |
int GetWidgetFromPos(const Window *w, int x, int y) |
0 | 137 |
{ |
5236
e959e132a78e
(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
|
138 |
uint index; |
e959e132a78e
(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
|
139 |
int found_index = -1; |
0 | 140 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6604
diff
changeset
|
141 |
/* Go through the widgets and check if we find the widget that the coordinate is |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6604
diff
changeset
|
142 |
* inside. */ |
5236
e959e132a78e
(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
|
143 |
for (index = 0; index < w->widget_count; index++) { |
e959e132a78e
(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
|
144 |
const Widget *wi = &w->widget[index]; |
2639 | 145 |
if (wi->type == WWT_EMPTY || wi->type == WWT_FRAME) continue; |
0 | 146 |
|
2021
3be628c59488
(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
|
147 |
if (x >= wi->left && x <= wi->right && y >= wi->top && y <= wi->bottom && |
8493
3ab458f7cff4
(svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents:
8458
diff
changeset
|
148 |
!w->IsWidgetHidden(index)) { |
2639 | 149 |
found_index = index; |
0 | 150 |
} |
151 |
} |
|
152 |
||
153 |
return found_index; |
|
154 |
} |
|
155 |
||
156 |
||
4437
d06bb548e48d
(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
|
157 |
void DrawFrameRect(int left, int top, int right, int bottom, int ctab, FrameFlags flags) |
d06bb548e48d
(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
|
158 |
{ |
4444
9c9c7f962482
(svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents:
4438
diff
changeset
|
159 |
uint dark = _colour_gradient[ctab][3]; |
9c9c7f962482
(svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents:
4438
diff
changeset
|
160 |
uint medium_dark = _colour_gradient[ctab][5]; |
9c9c7f962482
(svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents:
4438
diff
changeset
|
161 |
uint medium_light = _colour_gradient[ctab][6]; |
9c9c7f962482
(svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents:
4438
diff
changeset
|
162 |
uint light = _colour_gradient[ctab][7]; |
4437
d06bb548e48d
(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
|
163 |
|
4438
bfa7b06c0afe
(svn r6210) Remove FR_NOBORDER, because it is exclusivly used in conjunction with FR_TRANSPARENT
tron
parents:
4437
diff
changeset
|
164 |
if (flags & FR_TRANSPARENT) { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
165 |
GfxFillRect(left, top, right, bottom, PALETTE_TO_TRANSPARENT | (1 << USE_COLORTABLE)); |
4437
d06bb548e48d
(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
|
166 |
} else { |
d06bb548e48d
(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
|
167 |
uint interior; |
d06bb548e48d
(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
|
168 |
|
d06bb548e48d
(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
|
169 |
if (flags & FR_LOWERED) { |
d06bb548e48d
(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
|
170 |
GfxFillRect(left, top, left, bottom, dark); |
d06bb548e48d
(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
|
171 |
GfxFillRect(left + 1, top, right, top, dark); |
d06bb548e48d
(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
|
172 |
GfxFillRect(right, top + 1, right, bottom - 1, light); |
d06bb548e48d
(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
|
173 |
GfxFillRect(left + 1, bottom, right, bottom, light); |
d06bb548e48d
(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 |
interior = (flags & FR_DARKENED ? medium_dark : medium_light); |
d06bb548e48d
(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
|
175 |
} else { |
d06bb548e48d
(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
|
176 |
GfxFillRect(left, top, left, bottom - 1, light); |
d06bb548e48d
(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
|
177 |
GfxFillRect(left + 1, top, right - 1, top, light); |
d06bb548e48d
(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
|
178 |
GfxFillRect(right, top, right, bottom - 1, dark); |
d06bb548e48d
(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 |
GfxFillRect(left, bottom, right, bottom, dark); |
d06bb548e48d
(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
|
180 |
interior = medium_dark; |
d06bb548e48d
(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
|
181 |
} |
d06bb548e48d
(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 |
if (!(flags & FR_BORDERONLY)) { |
d06bb548e48d
(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 |
GfxFillRect(left + 1, top + 1, right - 1, bottom - 1, interior); |
d06bb548e48d
(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 |
} |
d06bb548e48d
(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 |
} |
d06bb548e48d
(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 |
} |
d06bb548e48d
(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 |
|
d06bb548e48d
(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 |
|
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2406
diff
changeset
|
189 |
void DrawWindowWidgets(const Window *w) |
0 | 190 |
{ |
2548
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2448
diff
changeset
|
191 |
const DrawPixelInfo* dpi = _cur_dpi; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
192 |
|
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
193 |
for (uint i = 0; i < w->widget_count; i++) { |
5236
e959e132a78e
(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
|
194 |
const Widget *wi = &w->widget[i]; |
8493
3ab458f7cff4
(svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents:
8458
diff
changeset
|
195 |
bool clicked = w->IsWidgetLowered(i); |
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
196 |
Rect r; |
1657
eb57fee328fb
(svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents:
1363
diff
changeset
|
197 |
|
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
198 |
if (dpi->left > (r.right = wi->right) || |
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
199 |
dpi->left + dpi->width <= (r.left = wi->left) || |
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
200 |
dpi->top > (r.bottom = wi->bottom) || |
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
201 |
dpi->top + dpi->height <= (r.top = wi->top) || |
8493
3ab458f7cff4
(svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents:
8458
diff
changeset
|
202 |
w->IsWidgetHidden(i)) { |
2639 | 203 |
continue; |
204 |
} |
|
0 | 205 |
|
1657
eb57fee328fb
(svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents:
1363
diff
changeset
|
206 |
switch (wi->type & WWT_MASK) { |
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4749
diff
changeset
|
207 |
case WWT_IMGBTN: |
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4749
diff
changeset
|
208 |
case WWT_IMGBTN_2: { |
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
209 |
SpriteID img = wi->data; |
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4749
diff
changeset
|
210 |
assert(img != 0); |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
211 |
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
0 | 212 |
|
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4749
diff
changeset
|
213 |
/* show different image when clicked for WWT_IMGBTN_2 */ |
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4749
diff
changeset
|
214 |
if ((wi->type & WWT_MASK) == WWT_IMGBTN_2 && clicked) img++; |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
215 |
DrawSprite(img, PAL_NONE, r.left + 1 + clicked, r.top + 1 + clicked); |
8816
0917ba1990f2
(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:
8780
diff
changeset
|
216 |
break; |
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4749
diff
changeset
|
217 |
} |
1657
eb57fee328fb
(svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents:
1363
diff
changeset
|
218 |
|
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
219 |
case WWT_PANEL: |
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4749
diff
changeset
|
220 |
assert(wi->data == 0); |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
221 |
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
8816
0917ba1990f2
(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:
8780
diff
changeset
|
222 |
break; |
0 | 223 |
|
4939
ede0f6777b3c
(svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents:
4938
diff
changeset
|
224 |
case WWT_TEXTBTN: |
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
225 |
case WWT_TEXTBTN_2: |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
226 |
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
227 |
/* FALL THROUGH */ |
0 | 228 |
|
4345
dd12549ad473
(svn r6046) CodeChange : Rename WWT_5 Widget type to WWT_LABEL : a centered label
belugas
parents:
3762
diff
changeset
|
229 |
case WWT_LABEL: { |
4547
9786a24c4102
(svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents:
4444
diff
changeset
|
230 |
StringID str = wi->data; |
0 | 231 |
|
4939
ede0f6777b3c
(svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents:
4938
diff
changeset
|
232 |
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
|
233 |
|
8320
6ffad7a5d242
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
6977
diff
changeset
|
234 |
DrawStringCentered(((r.left + r.right + 1) >> 1) + clicked, ((r.top + r.bottom + 1) >> 1) - 5 + clicked, str, TC_FROMSTRING); |
8816
0917ba1990f2
(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:
8780
diff
changeset
|
235 |
break; |
0 | 236 |
} |
237 |
||
6604
ad6057954de6
(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:
6075
diff
changeset
|
238 |
case WWT_TEXT: { |
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
239 |
const StringID str = wi->data; |
6604
ad6057954de6
(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:
6075
diff
changeset
|
240 |
|
ad6057954de6
(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:
6075
diff
changeset
|
241 |
if (str != STR_NULL) DrawStringTruncated(r.left, r.top, str, wi->color, r.right - r.left); |
ad6057954de6
(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:
6075
diff
changeset
|
242 |
break; |
ad6057954de6
(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:
6075
diff
changeset
|
243 |
} |
ad6057954de6
(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:
6075
diff
changeset
|
244 |
|
4939
ede0f6777b3c
(svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents:
4938
diff
changeset
|
245 |
case WWT_INSET: { |
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
246 |
const StringID str = wi->data; |
1938
21bd6ef5f85e
(svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents:
1891
diff
changeset
|
247 |
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_LOWERED | FR_DARKENED); |
0 | 248 |
|
8320
6ffad7a5d242
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
6977
diff
changeset
|
249 |
if (str != STR_NULL) DrawStringTruncated(r.left + 2, r.top + 1, str, TC_FROMSTRING, r.right - r.left - 10); |
8816
0917ba1990f2
(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:
8780
diff
changeset
|
250 |
break; |
0 | 251 |
} |
252 |
||
253 |
case WWT_MATRIX: { |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
254 |
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
|
255 |
|
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
256 |
int c = GB(wi->data, 0, 8); |
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
257 |
int amt1 = (wi->right - wi->left + 1) / c; |
0 | 258 |
|
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
259 |
int d = GB(wi->data, 8, 8); |
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
260 |
int amt2 = (wi->bottom - wi->top + 1) / d; |
0 | 261 |
|
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
262 |
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
|
263 |
|
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
264 |
int x = r.left; |
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
265 |
for (int ctr = c; ctr > 1; ctr--) { |
0 | 266 |
x += amt1; |
2639 | 267 |
GfxFillRect(x, r.top + 1, x, r.bottom - 1, color); |
0 | 268 |
} |
269 |
||
270 |
x = r.top; |
|
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
271 |
for (int ctr = d; ctr > 1; ctr--) { |
0 | 272 |
x += amt2; |
2639 | 273 |
GfxFillRect(r.left + 1, x, r.right - 1, x, color); |
0 | 274 |
} |
275 |
||
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
276 |
color = _colour_gradient[wi->color & 0xF][4]; |
0 | 277 |
|
2639 | 278 |
x = r.left - 1; |
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
279 |
for (int ctr = c; ctr > 1; ctr--) { |
0 | 280 |
x += amt1; |
2639 | 281 |
GfxFillRect(x, r.top + 1, x, r.bottom - 1, color); |
0 | 282 |
} |
283 |
||
2639 | 284 |
x = r.top - 1; |
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
285 |
for (int ctr = d; ctr > 1; ctr--) { |
0 | 286 |
x += amt2; |
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
287 |
GfxFillRect(r.left + 1, x, r.right - 1, x, color); |
0 | 288 |
} |
289 |
||
8816
0917ba1990f2
(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:
8780
diff
changeset
|
290 |
break; |
0 | 291 |
} |
292 |
||
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6604
diff
changeset
|
293 |
/* vertical scrollbar */ |
0 | 294 |
case WWT_SCROLLBAR: { |
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
295 |
assert(wi->data == 0); |
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
296 |
assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere! |
893
d9e69e5060ba
(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
|
297 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6604
diff
changeset
|
298 |
/* draw up/down buttons */ |
4940
2ff872152453
(svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents:
4939
diff
changeset
|
299 |
clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_UP); |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
300 |
DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
8320
6ffad7a5d242
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
6977
diff
changeset
|
301 |
DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, TC_BLACK); |
0 | 302 |
|
4940
2ff872152453
(svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents:
4939
diff
changeset
|
303 |
clicked = (((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_DOWN)); |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
304 |
DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
8320
6ffad7a5d242
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
6977
diff
changeset
|
305 |
DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, TC_BLACK); |
0 | 306 |
|
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
307 |
int c1 = _colour_gradient[wi->color & 0xF][3]; |
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
308 |
int c2 = _colour_gradient[wi->color & 0xF][7]; |
0 | 309 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6604
diff
changeset
|
310 |
/* draw "shaded" background */ |
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
311 |
GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c2); |
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
312 |
GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c1 | (1 << PALETTE_MODIFIER_GREYOUT)); |
0 | 313 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6604
diff
changeset
|
314 |
/* draw shaded lines */ |
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
315 |
GfxFillRect(r.left + 2, r.top + 10, r.left + 2, r.bottom - 10, c1); |
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
316 |
GfxFillRect(r.left + 3, r.top + 10, r.left + 3, r.bottom - 10, c2); |
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
317 |
GfxFillRect(r.left + 7, r.top + 10, r.left + 7, r.bottom - 10, c1); |
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
318 |
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
|
319 |
|
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
320 |
Point pt = HandleScrollbarHittest(&w->vscroll, r.top, r.bottom); |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
321 |
DrawFrameRect(r.left, pt.x, r.right, pt.y, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_MIDDLE ? FR_LOWERED : FR_NONE); |
842 | 322 |
break; |
323 |
} |
|
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
324 |
|
842 | 325 |
case WWT_SCROLL2BAR: { |
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
326 |
assert(wi->data == 0); |
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
327 |
assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere! |
893
d9e69e5060ba
(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
|
328 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6604
diff
changeset
|
329 |
/* draw up/down buttons */ |
4940
2ff872152453
(svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents:
4939
diff
changeset
|
330 |
clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_UP | WF_SCROLL2)); |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
331 |
DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
8320
6ffad7a5d242
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
6977
diff
changeset
|
332 |
DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, TC_BLACK); |
842 | 333 |
|
4940
2ff872152453
(svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents:
4939
diff
changeset
|
334 |
clicked = ((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_DOWN | WF_SCROLL2)); |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
335 |
DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
8320
6ffad7a5d242
(svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents:
6977
diff
changeset
|
336 |
DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, TC_BLACK); |
842 | 337 |
|
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
338 |
int c1 = _colour_gradient[wi->color & 0xF][3]; |
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
339 |
int c2 = _colour_gradient[wi->color & 0xF][7]; |
842 | 340 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6604
diff
changeset
|
341 |
/* draw "shaded" background */ |
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
342 |
GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c2); |
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
343 |
GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c1 | (1 << PALETTE_MODIFIER_GREYOUT)); |
842 | 344 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6604
diff
changeset
|
345 |
/* draw shaded lines */ |
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
346 |
GfxFillRect(r.left + 2, r.top + 10, r.left + 2, r.bottom - 10, c1); |
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
347 |
GfxFillRect(r.left + 3, r.top + 10, r.left + 3, r.bottom - 10, c2); |
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
348 |
GfxFillRect(r.left + 7, r.top + 10, r.left + 7, r.bottom - 10, c1); |
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
349 |
GfxFillRect(r.left + 8, r.top + 10, r.left + 8, r.bottom - 10, c2); |
842 | 350 |
|
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
351 |
Point pt = HandleScrollbarHittest(&w->vscroll2, r.top, r.bottom); |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
352 |
DrawFrameRect(r.left, pt.x, r.right, pt.y, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_MIDDLE | WF_SCROLL2) ? FR_LOWERED : FR_NONE); |
0 | 353 |
break; |
354 |
} |
|
355 |
||
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6604
diff
changeset
|
356 |
/* horizontal scrollbar */ |
0 | 357 |
case WWT_HSCROLLBAR: { |
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
358 |
assert(wi->data == 0); |
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
359 |
assert(r.bottom - r.top == 11); // To ensure the same sizes are used everywhere! |
893
d9e69e5060ba
(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
|
360 |
|
4940
2ff872152453
(svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents:
4939
diff
changeset
|
361 |
clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL)) == (WF_SCROLL_UP | WF_HSCROLL)); |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
362 |
DrawFrameRect(r.left, r.top, r.left + 9, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
363 |
DrawSprite(SPR_ARROW_LEFT, PAL_NONE, r.left + 1 + clicked, r.top + 1 + clicked); |
0 | 364 |
|
4940
2ff872152453
(svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents:
4939
diff
changeset
|
365 |
clicked = ((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL)) == (WF_SCROLL_DOWN | WF_HSCROLL)); |
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
366 |
DrawFrameRect(r.right - 9, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
367 |
DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, r.right - 8 + clicked, r.top + 1 + clicked); |
0 | 368 |
|
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
369 |
int c1 = _colour_gradient[wi->color & 0xF][3]; |
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
370 |
int c2 = _colour_gradient[wi->color & 0xF][7]; |
0 | 371 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6604
diff
changeset
|
372 |
/* draw "shaded" background */ |
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
373 |
GfxFillRect(r.left + 10, r.top, r.right - 10, r.bottom, c2); |
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
374 |
GfxFillRect(r.left + 10, r.top, r.right - 10, r.bottom, c1 | (1 << PALETTE_MODIFIER_GREYOUT)); |
0 | 375 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6604
diff
changeset
|
376 |
/* draw shaded lines */ |
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
377 |
GfxFillRect(r.left + 10, r.top + 2, r.right - 10, r.top + 2, c1); |
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
378 |
GfxFillRect(r.left + 10, r.top + 3, r.right - 10, r.top + 3, c2); |
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
379 |
GfxFillRect(r.left + 10, r.top + 7, r.right - 10, r.top + 7, c1); |
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
380 |
GfxFillRect(r.left + 10, r.top + 8, r.right - 10, r.top + 8, c2); |
0 | 381 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6604
diff
changeset
|
382 |
/* draw actual scrollbar */ |
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
383 |
Point pt = HandleScrollbarHittest(&w->hscroll, r.left, r.right); |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
384 |
DrawFrameRect(pt.x, r.top, pt.y, r.bottom, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL)) == (WF_SCROLL_MIDDLE | WF_HSCROLL) ? FR_LOWERED : FR_NONE); |
0 | 385 |
|
386 |
break; |
|
387 |
} |
|
388 |
||
389 |
case WWT_FRAME: { |
|
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
390 |
const StringID str = wi->data; |
860
d756b3e0e171
(svn r1341) -Fix: fix WWT_FRAME drawing when there is no text there (STR_NULL)
darkvater
parents:
845
diff
changeset
|
391 |
int x2 = r.left; // by default the left side is the left side of the widget |
0 | 392 |
|
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
393 |
if (str != STR_NULL) x2 = DrawString(r.left + 6, r.top, str, TC_FROMSTRING); |
0 | 394 |
|
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
395 |
int c1 = _colour_gradient[wi->color][3]; |
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
396 |
int c2 = _colour_gradient[wi->color][7]; |
0 | 397 |
|
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
398 |
/* Line from upper left corner to start of text */ |
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
399 |
GfxFillRect(r.left, r.top + 4, r.left + 4, r.top + 4, c1); |
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
400 |
GfxFillRect(r.left + 1, r.top + 5, r.left + 4, r.top + 5, c2); |
0 | 401 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6604
diff
changeset
|
402 |
/* Line from end of text to upper right corner */ |
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
403 |
GfxFillRect(x2, r.top + 4, r.right - 1, r.top + 4, c1); |
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
404 |
GfxFillRect(x2, r.top + 5, r.right - 2, r.top + 5, c2); |
0 | 405 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6604
diff
changeset
|
406 |
/* Line from upper left corner to bottom left corner */ |
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
407 |
GfxFillRect(r.left, r.top + 5, r.left, r.bottom - 1, c1); |
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
408 |
GfxFillRect(r.left + 1, r.top + 6, r.left + 1, r.bottom - 2, c2); |
0 | 409 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6604
diff
changeset
|
410 |
/*Line from upper right corner to bottom right corner */ |
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
411 |
GfxFillRect(r.right - 1, r.top + 5, r.right - 1, r.bottom - 2, c1); |
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
412 |
GfxFillRect(r.right, r.top + 4, r.right, r.bottom - 1, c2); |
0 | 413 |
|
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
414 |
GfxFillRect(r.left + 1, r.bottom - 1, r.right - 1, r.bottom - 1, c1); |
0 | 415 |
GfxFillRect(r.left, r.bottom, r.right, r.bottom, c2); |
416 |
||
8816
0917ba1990f2
(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:
8780
diff
changeset
|
417 |
break; |
0 | 418 |
} |
419 |
||
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
420 |
case WWT_STICKYBOX: |
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
421 |
assert(wi->data == 0); |
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
422 |
assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere! |
2703
edd58a233988
(svn r3247) - Fix: "[ 1335580 ] sticky windows not sticky anymore"
peter1138
parents:
2683
diff
changeset
|
423 |
|
edd58a233988
(svn r3247) - Fix: "[ 1335580 ] sticky windows not sticky anymore"
peter1138
parents:
2683
diff
changeset
|
424 |
clicked = !!(w->flags4 & WF_STICKY); |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
425 |
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
426 |
DrawSprite((clicked) ? SPR_PIN_UP : SPR_PIN_DOWN, PAL_NONE, r.left + 2 + clicked, r.top + 3 + clicked); |
682
7f5de4abac85
(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
|
427 |
break; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
428 |
|
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
429 |
case WWT_RESIZEBOX: |
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
430 |
assert(wi->data == 0); |
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
431 |
assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere! |
915 | 432 |
|
1657
eb57fee328fb
(svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents:
1363
diff
changeset
|
433 |
clicked = !!(w->flags4 & WF_SIZING); |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
434 |
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
435 |
DrawSprite(SPR_WINDOW_RESIZE, PAL_NONE, r.left + 3 + clicked, r.top + 3 + clicked); |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
436 |
break; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
437 |
|
2757
854d1b1d61b2
(svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents:
2703
diff
changeset
|
438 |
case WWT_CLOSEBOX: { |
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
439 |
const StringID str = wi->data; |
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
440 |
|
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
441 |
assert(str == STR_00C5 || str == STR_00C6); // black or silver cross |
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
442 |
assert(r.right - r.left == 10); // To ensure the same sizes are used everywhere |
2757
854d1b1d61b2
(svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents:
2703
diff
changeset
|
443 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
444 |
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_NONE); |
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
445 |
DrawString(r.left + 2, r.top + 2, str, TC_FROMSTRING); |
2757
854d1b1d61b2
(svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents:
2703
diff
changeset
|
446 |
break; |
854d1b1d61b2
(svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents:
2703
diff
changeset
|
447 |
} |
854d1b1d61b2
(svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents:
2703
diff
changeset
|
448 |
|
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
449 |
case WWT_CAPTION: |
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
450 |
assert(r.bottom - r.top == 13); // To ensure the same sizes are used everywhere! |
1938
21bd6ef5f85e
(svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents:
1891
diff
changeset
|
451 |
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_BORDERONLY); |
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
452 |
DrawFrameRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, wi->color, (w->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
|
453 |
|
0 | 454 |
if (w->caption_color != 0xFF) { |
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
455 |
GfxFillRect(r.left + 2, r.top + 2, r.right - 2, r.bottom - 2, _colour_gradient[_player_colors[w->caption_color]][4]); |
0 | 456 |
} |
457 |
||
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
458 |
DrawStringCenteredTruncated(r.left + 2, r.right - 2, r.top + 2, wi->data, 0x84); |
8816
0917ba1990f2
(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:
8780
diff
changeset
|
459 |
break; |
8831
c13fdbe2783a
(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:
8816
diff
changeset
|
460 |
|
c13fdbe2783a
(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:
8816
diff
changeset
|
461 |
case WWT_DROPDOWN: { |
c13fdbe2783a
(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:
8816
diff
changeset
|
462 |
assert(r.bottom - r.top == 11); // ensure consistent size |
c13fdbe2783a
(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:
8816
diff
changeset
|
463 |
|
c13fdbe2783a
(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:
8816
diff
changeset
|
464 |
StringID str = wi->data; |
c13fdbe2783a
(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:
8816
diff
changeset
|
465 |
DrawFrameRect(r.left, r.top, r.right - 12, r.bottom, wi->color, FR_NONE); |
c13fdbe2783a
(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:
8816
diff
changeset
|
466 |
DrawFrameRect(r.right - 11, r.top, r.right, r.bottom, wi->color, clicked ? FR_LOWERED : FR_NONE); |
c13fdbe2783a
(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:
8816
diff
changeset
|
467 |
DrawString(r.right - (clicked ? 8 : 9), r.top + (clicked ? 2 : 1), STR_0225, TC_BLACK); |
c13fdbe2783a
(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:
8816
diff
changeset
|
468 |
if (str != STR_NULL) DrawStringTruncated(r.left + 2, r.top + 1, str, TC_BLACK, r.right - r.left - 12); |
c13fdbe2783a
(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:
8816
diff
changeset
|
469 |
break; |
c13fdbe2783a
(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:
8816
diff
changeset
|
470 |
} |
c13fdbe2783a
(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:
8816
diff
changeset
|
471 |
|
c13fdbe2783a
(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:
8816
diff
changeset
|
472 |
case WWT_DROPDOWNIN: { |
c13fdbe2783a
(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:
8816
diff
changeset
|
473 |
assert(r.bottom - r.top == 11); // ensure consistent size |
c13fdbe2783a
(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:
8816
diff
changeset
|
474 |
|
c13fdbe2783a
(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:
8816
diff
changeset
|
475 |
StringID str = wi->data; |
c13fdbe2783a
(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:
8816
diff
changeset
|
476 |
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_LOWERED | FR_DARKENED); |
c13fdbe2783a
(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:
8816
diff
changeset
|
477 |
DrawFrameRect(r.right - 11, r.top + 1, r.right - 1, r.bottom - 1, wi->color, clicked ? FR_LOWERED : FR_NONE); |
c13fdbe2783a
(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:
8816
diff
changeset
|
478 |
DrawString(r.right - (clicked ? 8 : 9), r.top + (clicked ? 2 : 1), STR_0225, TC_BLACK); |
c13fdbe2783a
(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:
8816
diff
changeset
|
479 |
if (str != STR_NULL) DrawStringTruncated(r.left + 2, r.top + 2, str, TC_BLACK, r.right - r.left - 12); |
c13fdbe2783a
(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:
8816
diff
changeset
|
480 |
break; |
c13fdbe2783a
(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:
8816
diff
changeset
|
481 |
} |
0 | 482 |
} |
8816
0917ba1990f2
(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:
8780
diff
changeset
|
483 |
|
0917ba1990f2
(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:
8780
diff
changeset
|
484 |
if (w->IsWidgetDisabled(i)) { |
0917ba1990f2
(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:
8780
diff
changeset
|
485 |
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, _colour_gradient[wi->color & 0xF][2] | (1 << PALETTE_MODIFIER_GREYOUT)); |
0917ba1990f2
(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:
8780
diff
changeset
|
486 |
} |
5236
e959e132a78e
(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
|
487 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
488 |
|
0 | 489 |
|
490 |
if (w->flags4 & WF_WHITE_BORDER_MASK) { |
|
8458
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
491 |
DrawFrameRect(0, 0, w->width - 1, w->height - 1, 0xF, FR_BORDERONLY); |
0 | 492 |
} |
493 |
||
494 |
} |
|
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
|
495 |
|
6075
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
496 |
static void ResizeWidgets(Window *w, byte a, byte b) |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
497 |
{ |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
498 |
int16 offset = w->widget[a].left; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
499 |
int16 length = w->widget[b].right - offset; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
500 |
|
9225
1c31e491e3cf
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium
parents:
8914
diff
changeset
|
501 |
w->widget[a].right = (length / 2) + offset; |
6075
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
502 |
|
6073
d8dae377c879
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5919
diff
changeset
|
503 |
w->widget[b].left = w->widget[a].right + 1; |
d8dae377c879
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5919
diff
changeset
|
504 |
} |
d8dae377c879
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5919
diff
changeset
|
505 |
|
6075
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
506 |
static void ResizeWidgets(Window *w, byte a, byte b, byte c) |
6073
d8dae377c879
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5919
diff
changeset
|
507 |
{ |
6075
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
508 |
int16 offset = w->widget[a].left; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
509 |
int16 length = w->widget[c].right - offset; |
6073
d8dae377c879
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5919
diff
changeset
|
510 |
|
6075
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
511 |
w->widget[a].right = length / 3; |
6073
d8dae377c879
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5919
diff
changeset
|
512 |
w->widget[b].right = w->widget[a].right * 2; |
d8dae377c879
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5919
diff
changeset
|
513 |
|
6075
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
514 |
w->widget[a].right += offset; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
515 |
w->widget[b].right += offset; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
516 |
|
6073
d8dae377c879
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5919
diff
changeset
|
517 |
/* Now the right side of the buttons are set. We will now set the left sides next to them */ |
d8dae377c879
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5919
diff
changeset
|
518 |
w->widget[b].left = w->widget[a].right + 1; |
d8dae377c879
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5919
diff
changeset
|
519 |
w->widget[c].left = w->widget[b].right + 1; |
d8dae377c879
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5919
diff
changeset
|
520 |
} |
d8dae377c879
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5919
diff
changeset
|
521 |
|
6075
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
522 |
/** Evenly distribute some widgets when resizing horizontally (often a button row) |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
523 |
* When only two arguments are given, the widgets are presumed to be on a line and only the ends are given |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6928
diff
changeset
|
524 |
* @param w Window to modify |
6075
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
525 |
* @param left The leftmost widget to resize |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
526 |
* @param right The rightmost widget to resize. Since right side of it is used, remember to set it to RESIZE_RIGHT |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
527 |
*/ |
6073
d8dae377c879
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5919
diff
changeset
|
528 |
void ResizeButtons(Window *w, byte left, byte right) |
d8dae377c879
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5919
diff
changeset
|
529 |
{ |
6075
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
530 |
int16 num_widgets = right - left + 1; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
531 |
|
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
532 |
if (num_widgets < 2) NOT_REACHED(); |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
533 |
|
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
534 |
switch (num_widgets) { |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
535 |
case 2: ResizeWidgets(w, left, right); break; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
536 |
case 3: ResizeWidgets(w, left, left + 1, right); break; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
537 |
default: { |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
538 |
/* Looks like we got more than 3 widgets to resize |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
539 |
* Now we will find the middle of the space desinated for the widgets |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
540 |
* and place half of the widgets on each side of it and call recursively. |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
541 |
* Eventually we will get down to blocks of 2-3 widgets and we got code to handle those cases */ |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
542 |
int16 offset = w->widget[left].left; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
543 |
int16 length = w->widget[right].right - offset; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
544 |
byte widget = ((num_widgets - 1)/ 2) + left; // rightmost widget of the left side |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
545 |
|
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
546 |
/* Now we need to find the middle of the widgets. |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
547 |
* It will not always be the middle because if we got an uneven number of widgets, |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
548 |
* we will need it to be 2/5, 3/7 and so on |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
549 |
* To get this, we multiply with num_widgets/num_widgets. Since we calculate in int, we will get: |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
550 |
* |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
551 |
* num_widgets/2 (rounding down) |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
552 |
* --------------- |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
553 |
* num_widgets |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
554 |
* |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
555 |
* as multiplier to length. We just multiply before divide to that we stay in the int area though */ |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
556 |
int16 middle = ((length * num_widgets) / (2 * num_widgets)) + offset; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
557 |
|
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
558 |
/* Set left and right on the widgets, that's next to our "middle" */ |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
559 |
w->widget[widget].right = middle; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
560 |
w->widget[widget + 1].left = w->widget[widget].right + 1; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
561 |
/* Now resize the left and right of the middle */ |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
562 |
ResizeButtons(w, left, widget); |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
563 |
ResizeButtons(w, widget + 1, right); |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
564 |
} |
6073
d8dae377c879
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5919
diff
changeset
|
565 |
} |
d8dae377c879
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents:
5919
diff
changeset
|
566 |
} |
8845
e0eac76d3d16
(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:
8831
diff
changeset
|
567 |
|
8914
6ebaa4b4eb2b
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8907
diff
changeset
|
568 |
void ResizeWindowForWidget(Window *w, int widget, int delta_x, int delta_y) |
6ebaa4b4eb2b
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8907
diff
changeset
|
569 |
{ |
6ebaa4b4eb2b
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8907
diff
changeset
|
570 |
int right = w->widget[widget].right; |
6ebaa4b4eb2b
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8907
diff
changeset
|
571 |
int bottom = w->widget[widget].bottom; |
6ebaa4b4eb2b
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8907
diff
changeset
|
572 |
|
6ebaa4b4eb2b
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8907
diff
changeset
|
573 |
for (uint i = 0; i < w->widget_count; i++) { |
6ebaa4b4eb2b
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8907
diff
changeset
|
574 |
if (w->widget[i].left >= right) w->widget[i].left += delta_x; |
6ebaa4b4eb2b
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8907
diff
changeset
|
575 |
if (w->widget[i].right >= right) w->widget[i].right += delta_x; |
6ebaa4b4eb2b
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8907
diff
changeset
|
576 |
if (w->widget[i].top >= bottom) w->widget[i].top += delta_y; |
6ebaa4b4eb2b
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8907
diff
changeset
|
577 |
if (w->widget[i].bottom >= bottom) w->widget[i].bottom += delta_y; |
6ebaa4b4eb2b
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8907
diff
changeset
|
578 |
} |
6ebaa4b4eb2b
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8907
diff
changeset
|
579 |
|
6ebaa4b4eb2b
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8907
diff
changeset
|
580 |
w->width += delta_x; |
6ebaa4b4eb2b
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8907
diff
changeset
|
581 |
w->height += delta_y; |
6ebaa4b4eb2b
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8907
diff
changeset
|
582 |
w->resize.width += delta_x; |
6ebaa4b4eb2b
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8907
diff
changeset
|
583 |
w->resize.height += delta_y; |
6ebaa4b4eb2b
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8907
diff
changeset
|
584 |
} |
6ebaa4b4eb2b
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138
parents:
8907
diff
changeset
|
585 |
|
8845
e0eac76d3d16
(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:
8831
diff
changeset
|
586 |
/** Draw a sort button's up or down arrow symbol. |
e0eac76d3d16
(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:
8831
diff
changeset
|
587 |
* @param w Window of widget |
e0eac76d3d16
(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:
8831
diff
changeset
|
588 |
* @param widget Sort button widget |
e0eac76d3d16
(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:
8831
diff
changeset
|
589 |
* @param state State of sort button |
e0eac76d3d16
(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:
8831
diff
changeset
|
590 |
*/ |
e0eac76d3d16
(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:
8831
diff
changeset
|
591 |
void DrawSortButtonState(const Window *w, int widget, SortButtonState state) |
e0eac76d3d16
(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:
8831
diff
changeset
|
592 |
{ |
e0eac76d3d16
(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:
8831
diff
changeset
|
593 |
if (state == SBS_OFF) return; |
e0eac76d3d16
(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:
8831
diff
changeset
|
594 |
|
e0eac76d3d16
(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:
8831
diff
changeset
|
595 |
int offset = w->IsWidgetLowered(widget) ? 1 : 0; |
e0eac76d3d16
(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:
8831
diff
changeset
|
596 |
DoDrawString(state == SBS_DOWN ? DOWNARROW : UPARROW, w->widget[widget].right - 11 + offset, w->widget[widget].top + 1 + offset, TC_BLACK); |
e0eac76d3d16
(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:
8831
diff
changeset
|
597 |
} |