author | rubidium |
Sat, 22 Dec 2007 23:30:28 +0000 | |
changeset 8617 | 931e0970d509 |
parent 8602 | 9e75e594a068 |
child 8627 | 448ebf3a8291 |
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" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2154
diff
changeset
|
7 |
#include "functions.h" |
2154
63a6b880b4c0
(svn r2664) Remove depedency on player.h from variables.h
tron
parents:
2064
diff
changeset
|
8 |
#include "player.h" |
1363
01d3de5d8039
(svn r1867) Include tables/sprites.h only in files which need it
tron
parents:
1177
diff
changeset
|
9 |
#include "table/sprites.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
193
diff
changeset
|
10 |
#include "table/strings.h" |
0 | 11 |
#include "viewport.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
|
12 |
#include "window_gui.h" |
0 | 13 |
|
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
|
14 |
static Point HandleScrollbarHittest(const Scrollbar *sb, int top, int bottom) |
0 | 15 |
{ |
16 |
Point pt; |
|
17 |
int height, count, pos, cap; |
|
18 |
||
19 |
top += 10; |
|
20 |
bottom -= 9; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
21 |
|
0 | 22 |
height = (bottom - top); |
23 |
||
24 |
pos = sb->pos; |
|
25 |
count = sb->count; |
|
26 |
cap = sb->cap; |
|
27 |
||
2026 | 28 |
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
|
29 |
|
0 | 30 |
if (cap > count) cap = count; |
2639 | 31 |
if (count != 0) bottom -= (count - pos - cap) * height / count; |
0 | 32 |
|
33 |
pt.x = top; |
|
34 |
pt.y = bottom - 1; |
|
35 |
return pt; |
|
36 |
} |
|
37 |
||
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6928
diff
changeset
|
38 |
/** Special handling for the scrollbar widget type. |
0 | 39 |
* Handles the special scrolling buttons and other |
40 |
* scrolling. |
|
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6928
diff
changeset
|
41 |
* @param w Window on which a scroll was performed. |
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6928
diff
changeset
|
42 |
* @param wi Pointer to the scrollbar widget. |
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6928
diff
changeset
|
43 |
* @param x The X coordinate of the mouse click. |
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6928
diff
changeset
|
44 |
* @param y The Y coordinate of the mouse click. */ |
0 | 45 |
void ScrollbarClickHandler(Window *w, const Widget *wi, int x, int y) |
46 |
{ |
|
47 |
int mi, ma, pos; |
|
48 |
Scrollbar *sb; |
|
49 |
||
842 | 50 |
switch (wi->type) { |
51 |
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
|
52 |
/* vertical scroller */ |
842 | 53 |
w->flags4 &= ~WF_HSCROLL; |
54 |
w->flags4 &= ~WF_SCROLL2; |
|
55 |
mi = wi->top; |
|
56 |
ma = wi->bottom; |
|
57 |
pos = y; |
|
58 |
sb = &w->vscroll; |
|
59 |
break; |
|
60 |
} |
|
61 |
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
|
62 |
/* 2nd vertical scroller */ |
842 | 63 |
w->flags4 &= ~WF_HSCROLL; |
64 |
w->flags4 |= WF_SCROLL2; |
|
65 |
mi = wi->top; |
|
66 |
ma = wi->bottom; |
|
67 |
pos = y; |
|
68 |
sb = &w->vscroll2; |
|
69 |
break; |
|
70 |
} |
|
71 |
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
|
72 |
/* horizontal scroller */ |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
73 |
w->flags4 &= ~WF_SCROLL2; |
842 | 74 |
w->flags4 |= WF_HSCROLL; |
75 |
mi = wi->left; |
|
76 |
ma = wi->right; |
|
77 |
pos = x; |
|
78 |
sb = &w->hscroll; |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
79 |
break; |
842 | 80 |
} |
845
0c66e26fecb2
(svn r1326) fixed compiler warnings in vehicle_gui.c and widget.c
bjarni
parents:
842
diff
changeset
|
81 |
default: return; //this should never happen |
0 | 82 |
} |
83 |
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
|
84 |
/* Pressing the upper button? */ |
2597 | 85 |
w->flags4 |= WF_SCROLL_UP; |
86 |
if (_scroller_click_timeout == 0) { |
|
87 |
_scroller_click_timeout = 6; |
|
88 |
if (sb->pos != 0) sb->pos--; |
|
0 | 89 |
} |
2597 | 90 |
_left_button_clicked = false; |
0 | 91 |
} 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
|
92 |
/* Pressing the lower button? */ |
2597 | 93 |
w->flags4 |= WF_SCROLL_DOWN; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
94 |
|
2597 | 95 |
if (_scroller_click_timeout == 0) { |
96 |
_scroller_click_timeout = 6; |
|
97 |
if ((byte)(sb->pos + sb->cap) < sb->count) |
|
98 |
sb->pos++; |
|
0 | 99 |
} |
2597 | 100 |
_left_button_clicked = false; |
0 | 101 |
} else { |
102 |
Point pt = HandleScrollbarHittest(sb, mi, ma); |
|
103 |
||
104 |
if (pos < pt.x) { |
|
105 |
sb->pos = max(sb->pos - sb->cap, 0); |
|
106 |
} else if (pos > pt.y) { |
|
107 |
sb->pos = min( |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
108 |
sb->pos + sb->cap, |
0 | 109 |
max(sb->count - sb->cap, 0) |
110 |
); |
|
111 |
} else { |
|
112 |
_scrollbar_start_pos = pt.x - mi - 9; |
|
113 |
_scrollbar_size = ma - mi - 23; |
|
114 |
w->flags4 |= WF_SCROLL_MIDDLE; |
|
115 |
_scrolling_scrollbar = true; |
|
116 |
_cursorpos_drag_start = _cursor.pos; |
|
117 |
} |
|
118 |
} |
|
119 |
||
120 |
SetWindowDirty(w); |
|
121 |
} |
|
122 |
||
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
|
123 |
/** 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
|
124 |
* 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
|
125 |
* @param *w Window to look inside |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6928
diff
changeset
|
126 |
* @param x The Window client X coordinate |
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6928
diff
changeset
|
127 |
* @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
|
128 |
* @return A widget index, or -1 if no widget was found. |
0 | 129 |
*/ |
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
|
130 |
int GetWidgetFromPos(const Window *w, int x, int y) |
0 | 131 |
{ |
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
|
132 |
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
|
133 |
int found_index = -1; |
0 | 134 |
|
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
|
135 |
/* 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
|
136 |
* 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
|
137 |
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
|
138 |
const Widget *wi = &w->widget[index]; |
2639 | 139 |
if (wi->type == WWT_EMPTY || wi->type == WWT_FRAME) continue; |
0 | 140 |
|
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
|
141 |
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
|
142 |
!w->IsWidgetHidden(index)) { |
2639 | 143 |
found_index = index; |
0 | 144 |
} |
145 |
} |
|
146 |
||
147 |
return found_index; |
|
148 |
} |
|
149 |
||
150 |
||
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
|
151 |
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
|
152 |
{ |
4444
9c9c7f962482
(svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents:
4438
diff
changeset
|
153 |
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
|
154 |
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
|
155 |
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
|
156 |
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
|
157 |
|
4438
bfa7b06c0afe
(svn r6210) Remove FR_NOBORDER, because it is exclusivly used in conjunction with FR_TRANSPARENT
tron
parents:
4437
diff
changeset
|
158 |
if (flags & FR_TRANSPARENT) { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
159 |
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
|
160 |
} 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
|
161 |
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
|
162 |
|
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 |
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
|
164 |
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
|
165 |
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
|
166 |
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
|
167 |
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
|
168 |
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
|
169 |
} 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
|
170 |
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
|
171 |
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
|
172 |
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
|
173 |
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
|
174 |
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
|
175 |
} |
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 |
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
|
177 |
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
|
178 |
} |
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 |
} |
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 |
} |
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 |
|
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
|
183 |
void DrawWindowWidgets(const Window *w) |
0 | 184 |
{ |
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
|
185 |
const DrawPixelInfo* dpi = _cur_dpi; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
186 |
|
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
|
187 |
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
|
188 |
const Widget *wi = &w->widget[i]; |
8493
3ab458f7cff4
(svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents:
8458
diff
changeset
|
189 |
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
|
190 |
Rect r; |
1657
eb57fee328fb
(svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents:
1363
diff
changeset
|
191 |
|
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
|
192 |
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
|
193 |
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
|
194 |
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
|
195 |
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
|
196 |
w->IsWidgetHidden(i)) { |
2639 | 197 |
continue; |
198 |
} |
|
0 | 199 |
|
1657
eb57fee328fb
(svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents:
1363
diff
changeset
|
200 |
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
|
201 |
case WWT_IMGBTN: |
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4749
diff
changeset
|
202 |
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
|
203 |
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
|
204 |
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
|
205 |
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
0 | 206 |
|
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4749
diff
changeset
|
207 |
/* 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
|
208 |
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
|
209 |
DrawSprite(img, PAL_NONE, r.left + 1 + clicked, r.top + 1 + clicked); |
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4749
diff
changeset
|
210 |
goto draw_default; |
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4749
diff
changeset
|
211 |
} |
1657
eb57fee328fb
(svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents:
1363
diff
changeset
|
212 |
|
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4749
diff
changeset
|
213 |
case WWT_PANEL: { |
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4749
diff
changeset
|
214 |
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
|
215 |
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
0 | 216 |
goto draw_default; |
217 |
} |
|
218 |
||
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
|
219 |
case WWT_TEXTBTN: |
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
|
220 |
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
|
221 |
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
0 | 222 |
} |
223 |
/* fall through */ |
|
224 |
||
4345
dd12549ad473
(svn r6046) CodeChange : Rename WWT_5 Widget type to WWT_LABEL : a centered label
belugas
parents:
3762
diff
changeset
|
225 |
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
|
226 |
StringID str = wi->data; |
0 | 227 |
|
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
|
228 |
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
|
229 |
|
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
|
230 |
DrawStringCentered(((r.left + r.right + 1) >> 1) + clicked, ((r.top + r.bottom + 1) >> 1) - 5 + clicked, str, TC_FROMSTRING); |
2064
c889fcc76398
(svn r2573) Codechange: Removed WDF_RESTORE_DPARAM, it's not needed with the new string system.
ludde
parents:
2026
diff
changeset
|
231 |
goto draw_default; |
0 | 232 |
} |
233 |
||
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
|
234 |
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
|
235 |
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
|
236 |
|
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
|
237 |
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
|
238 |
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
|
239 |
} |
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 |
|
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
|
241 |
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
|
242 |
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
|
243 |
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_LOWERED | FR_DARKENED); |
0 | 244 |
|
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
|
245 |
if (str != STR_NULL) DrawStringTruncated(r.left + 2, r.top + 1, str, TC_FROMSTRING, r.right - r.left - 10); |
0 | 246 |
goto draw_default; |
247 |
} |
|
248 |
||
249 |
case WWT_MATRIX: { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
250 |
int c, d, ctr; |
0 | 251 |
int x, amt1, amt2; |
252 |
int color; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
253 |
|
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 |
|
4547
9786a24c4102
(svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents:
4444
diff
changeset
|
256 |
c = GB(wi->data, 0, 8); |
0 | 257 |
amt1 = (wi->right - wi->left + 1) / c; |
258 |
||
4547
9786a24c4102
(svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents:
4444
diff
changeset
|
259 |
d = GB(wi->data, 8, 8); |
0 | 260 |
amt2 = (wi->bottom - wi->top + 1) / d; |
261 |
||
4444
9c9c7f962482
(svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents:
4438
diff
changeset
|
262 |
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 |
|
0 | 264 |
x = r.left; |
2801
c70673b84010
(svn r3349) Fix off-by-one error in drawing matrix widget, from r3181.
peter1138
parents:
2757
diff
changeset
|
265 |
for (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; |
|
2801
c70673b84010
(svn r3349) Fix off-by-one error in drawing matrix widget, from r3181.
peter1138
parents:
2757
diff
changeset
|
271 |
for (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; |
2801
c70673b84010
(svn r3349) Fix off-by-one error in drawing matrix widget, from r3181.
peter1138
parents:
2757
diff
changeset
|
279 |
for (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; |
2801
c70673b84010
(svn r3349) Fix off-by-one error in drawing matrix widget, from r3181.
peter1138
parents:
2757
diff
changeset
|
285 |
for (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 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
290 |
goto draw_default; |
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: { |
295 |
Point pt; |
|
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
|
296 |
int c1, c2; |
0 | 297 |
|
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
|
298 |
assert(wi->data == 0); |
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
|
299 |
assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere! |
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
|
300 |
|
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
|
301 |
/* 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
|
302 |
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
|
303 |
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
|
304 |
DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, TC_BLACK); |
0 | 305 |
|
4940
2ff872152453
(svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents:
4939
diff
changeset
|
306 |
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
|
307 |
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
|
308 |
DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, TC_BLACK); |
0 | 309 |
|
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
|
310 |
c1 = _colour_gradient[wi->color & 0xF][3]; |
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 |
c2 = _colour_gradient[wi->color & 0xF][7]; |
0 | 312 |
|
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
|
313 |
/* 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
|
314 |
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
|
315 |
GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c1 | (1 << PALETTE_MODIFIER_GREYOUT)); |
0 | 316 |
|
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
|
317 |
/* 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
|
318 |
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
|
319 |
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
|
320 |
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
|
321 |
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
|
322 |
|
0 | 323 |
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
|
324 |
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 | 325 |
break; |
326 |
} |
|
327 |
case WWT_SCROLL2BAR: { |
|
328 |
Point pt; |
|
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
|
329 |
int c1, c2; |
842 | 330 |
|
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
|
331 |
assert(wi->data == 0); |
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
|
332 |
assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere! |
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
|
333 |
|
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
|
334 |
/* 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
|
335 |
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
|
336 |
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
|
337 |
DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, TC_BLACK); |
842 | 338 |
|
4940
2ff872152453
(svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents:
4939
diff
changeset
|
339 |
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
|
340 |
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
|
341 |
DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, TC_BLACK); |
842 | 342 |
|
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
|
343 |
c1 = _colour_gradient[wi->color & 0xF][3]; |
e3b1575895cd
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents:
8424
diff
changeset
|
344 |
c2 = _colour_gradient[wi->color & 0xF][7]; |
842 | 345 |
|
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
|
346 |
/* 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
|
347 |
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
|
348 |
GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c1 | (1 << PALETTE_MODIFIER_GREYOUT)); |
842 | 349 |
|
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
|
350 |
/* 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
|
351 |
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
|
352 |
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
|
353 |
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
|
354 |
GfxFillRect(r.left + 8, r.top + 10, r.left + 8, r.bottom - 10, c2); |
842 | 355 |
|
356 |
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
|
357 |
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 | 358 |
break; |
359 |
} |
|
360 |
||
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
|
361 |
/* horizontal scrollbar */ |
0 | 362 |
case WWT_HSCROLLBAR: { |
363 |
Point pt; |
|
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
|
364 |
int c1, c2; |
0 | 365 |
|
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 |
assert(wi->data == 0); |
894
ab8a5f7ea3db
(svn r1380) -Fix: missed widget fixes; thanks Jango and TestMan57
darkvater
parents:
893
diff
changeset
|
367 |
assert(r.bottom - r.top == 11); // XXX - 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
|
368 |
|
4940
2ff872152453
(svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents:
4939
diff
changeset
|
369 |
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
|
370 |
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
|
371 |
DrawSprite(SPR_ARROW_LEFT, PAL_NONE, r.left + 1 + clicked, r.top + 1 + clicked); |
0 | 372 |
|
4940
2ff872152453
(svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents:
4939
diff
changeset
|
373 |
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
|
374 |
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
|
375 |
DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, r.right - 8 + clicked, r.top + 1 + clicked); |
0 | 376 |
|
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 |
c1 = _colour_gradient[wi->color & 0xF][3]; |
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 |
c2 = _colour_gradient[wi->color & 0xF][7]; |
0 | 379 |
|
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
|
380 |
/* 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
|
381 |
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
|
382 |
GfxFillRect(r.left + 10, r.top, r.right - 10, r.bottom, c1 | (1 << PALETTE_MODIFIER_GREYOUT)); |
0 | 383 |
|
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
|
384 |
/* 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
|
385 |
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
|
386 |
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
|
387 |
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
|
388 |
GfxFillRect(r.left + 10, r.top + 8, r.right - 10, r.top + 8, c2); |
0 | 389 |
|
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
|
390 |
/* draw actual scrollbar */ |
0 | 391 |
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
|
392 |
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 | 393 |
|
394 |
break; |
|
395 |
} |
|
396 |
||
397 |
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
|
398 |
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
|
399 |
int c1, c2; |
860
d756b3e0e171
(svn r1341) -Fix: fix WWT_FRAME drawing when there is no text there (STR_NULL)
darkvater
parents:
845
diff
changeset
|
400 |
int x2 = r.left; // by default the left side is the left side of the widget |
0 | 401 |
|
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
|
402 |
if (str != STR_NULL) x2 = DrawString(r.left + 6, r.top, str, TC_FROMSTRING); |
0 | 403 |
|
4444
9c9c7f962482
(svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents:
4438
diff
changeset
|
404 |
c1 = _colour_gradient[wi->color][3]; |
9c9c7f962482
(svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents:
4438
diff
changeset
|
405 |
c2 = _colour_gradient[wi->color][7]; |
0 | 406 |
|
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 |
/* 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
|
408 |
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
|
409 |
GfxFillRect(r.left + 1, r.top + 5, r.left + 4, r.top + 5, c2); |
0 | 410 |
|
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
|
411 |
/* 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
|
412 |
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
|
413 |
GfxFillRect(x2, r.top + 5, r.right - 2, r.top + 5, c2); |
0 | 414 |
|
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
|
415 |
/* 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
|
416 |
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
|
417 |
GfxFillRect(r.left + 1, r.top + 6, r.left + 1, r.bottom - 2, c2); |
0 | 418 |
|
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
|
419 |
/*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
|
420 |
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
|
421 |
GfxFillRect(r.right, r.top + 4, r.right, r.bottom - 1, c2); |
0 | 422 |
|
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
|
423 |
GfxFillRect(r.left + 1, r.bottom - 1, r.right - 1, r.bottom - 1, c1); |
0 | 424 |
GfxFillRect(r.left, r.bottom, r.right, r.bottom, c2); |
425 |
||
2064
c889fcc76398
(svn r2573) Codechange: Removed WDF_RESTORE_DPARAM, it's not needed with the new string system.
ludde
parents:
2026
diff
changeset
|
426 |
goto draw_default; |
0 | 427 |
} |
428 |
||
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
|
429 |
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
|
430 |
assert(wi->data == 0); |
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
|
431 |
assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere! |
2703
edd58a233988
(svn r3247) - Fix: "[ 1335580 ] sticky windows not sticky anymore"
peter1138
parents:
2683
diff
changeset
|
432 |
|
edd58a233988
(svn r3247) - Fix: "[ 1335580 ] sticky windows not sticky anymore"
peter1138
parents:
2683
diff
changeset
|
433 |
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
|
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((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
|
436 |
break; |
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
|
437 |
} |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
438 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
439 |
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
|
440 |
assert(wi->data == 0); |
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
|
441 |
assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere! |
915 | 442 |
|
1657
eb57fee328fb
(svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents:
1363
diff
changeset
|
443 |
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
|
444 |
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
|
445 |
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
|
446 |
break; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
447 |
} |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
448 |
|
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
|
449 |
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
|
450 |
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
|
451 |
|
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 |
assert(str == STR_00C5 || str == STR_00C6); // black or silver cross |
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
|
453 |
assert(r.right - r.left == 10); // ensure the same sizes are used everywhere |
854d1b1d61b2
(svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents:
2703
diff
changeset
|
454 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
455 |
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
|
456 |
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
|
457 |
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
|
458 |
} |
854d1b1d61b2
(svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents:
2703
diff
changeset
|
459 |
|
0 | 460 |
case WWT_CAPTION: { |
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
|
461 |
assert(r.bottom - r.top == 13); // XXX - 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
|
462 |
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
|
463 |
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
|
464 |
|
0 | 465 |
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
|
466 |
GfxFillRect(r.left + 2, r.top + 2, r.right - 2, r.bottom - 2, _colour_gradient[_player_colors[w->caption_color]][4]); |
0 | 467 |
} |
468 |
||
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
|
469 |
DrawStringCenteredTruncated(r.left + 2, r.right - 2, r.top + 2, wi->data, 0x84); |
0 | 470 |
draw_default:; |
8493
3ab458f7cff4
(svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents:
8458
diff
changeset
|
471 |
if (w->IsWidgetDisabled(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
|
472 |
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, _colour_gradient[wi->color & 0xF][2] | (1 << PALETTE_MODIFIER_GREYOUT)); |
0 | 473 |
} |
474 |
} |
|
475 |
} |
|
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
|
476 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
477 |
|
0 | 478 |
|
479 |
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
|
480 |
DrawFrameRect(0, 0, w->width - 1, w->height - 1, 0xF, FR_BORDERONLY); |
0 | 481 |
} |
482 |
||
483 |
} |
|
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
|
484 |
|
883
0c54c6fc1790
(svn r1368) -Fix: Disabled dropdown menu options are gray again (instead of blue)
truelight
parents:
876
diff
changeset
|
485 |
static const Widget _dropdown_menu_widgets[] = { |
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4749
diff
changeset
|
486 |
{ WWT_PANEL, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL}, |
5041
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
487 |
{ WWT_SCROLLBAR, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
164
diff
changeset
|
488 |
{ WIDGETS_END}, |
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
|
489 |
}; |
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
|
490 |
|
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
|
491 |
static int GetDropdownItem(const Window *w) |
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
|
492 |
{ |
2448
0a34e90cb31f
(svn r2974) -Fix: Drag and drop selection on drop down boxes didn't select correct item when some items were hidden.
peter1138
parents:
2436
diff
changeset
|
493 |
byte item, counter; |
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
|
494 |
int y; |
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 |
|
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
|
496 |
if (GetWidgetFromPos(w, _cursor.pos.x - w->left, _cursor.pos.y - w->top) < 0) |
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
|
497 |
return -1; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
498 |
|
5196
c419a5b39f8f
(svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents:
5125
diff
changeset
|
499 |
y = _cursor.pos.y - w->top - 2 + w->vscroll.pos * 10; |
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
|
500 |
|
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
|
501 |
if (y < 0) |
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
|
502 |
return - 1; |
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
|
503 |
|
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
|
504 |
item = y / 10; |
8578
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
505 |
if (item >= WP(w, dropdown_d).num_items || (HasBit(WP(w,dropdown_d).disabled_state, item) && !HasBit(WP(w,dropdown_d).hidden_state, item)) || WP(w,dropdown_d).items[item] == 0) |
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
|
506 |
return - 1; |
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
|
507 |
|
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
|
508 |
/* Skip hidden items -- +1 for each hidden item before the clicked item. */ |
2448
0a34e90cb31f
(svn r2974) -Fix: Drag and drop selection on drop down boxes didn't select correct item when some items were hidden.
peter1138
parents:
2436
diff
changeset
|
509 |
for (counter = 0; item >= counter; ++counter) |
8578
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
510 |
if (HasBit(WP(w, dropdown_d).hidden_state, counter)) item++; |
2448
0a34e90cb31f
(svn r2974) -Fix: Drag and drop selection on drop down boxes didn't select correct item when some items were hidden.
peter1138
parents:
2436
diff
changeset
|
511 |
|
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
|
512 |
return item; |
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
|
513 |
} |
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
|
514 |
|
1095 | 515 |
static void DropdownMenuWndProc(Window *w, WindowEvent *e) |
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
|
516 |
{ |
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
|
517 |
int item; |
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
|
518 |
|
2952 | 519 |
switch (e->event) { |
842 | 520 |
case WE_PAINT: { |
521 |
int x,y,i,sel; |
|
5196
c419a5b39f8f
(svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents:
5125
diff
changeset
|
522 |
int width, height; |
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
|
523 |
|
842 | 524 |
DrawWindowWidgets(w); |
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
|
525 |
|
842 | 526 |
x = 1; |
5196
c419a5b39f8f
(svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents:
5125
diff
changeset
|
527 |
y = 2 - w->vscroll.pos * 10; |
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
|
528 |
|
8578
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
529 |
sel = WP(w, dropdown_d).selected_index; |
5196
c419a5b39f8f
(svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents:
5125
diff
changeset
|
530 |
width = w->widget[0].right - 3; |
c419a5b39f8f
(svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents:
5125
diff
changeset
|
531 |
height = w->widget[0].bottom - 3; |
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
|
532 |
|
8578
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
533 |
for (i = 0; WP(w, dropdown_d).items[i] != INVALID_STRING_ID; i++, sel--) { |
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
534 |
if (HasBit(WP(w, dropdown_d).hidden_state, i)) continue; |
5196
c419a5b39f8f
(svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents:
5125
diff
changeset
|
535 |
|
c419a5b39f8f
(svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents:
5125
diff
changeset
|
536 |
if (y >= 0 && y <= height) { |
8578
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
537 |
if (WP(w, dropdown_d).items[i] != STR_NULL) { |
5196
c419a5b39f8f
(svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents:
5125
diff
changeset
|
538 |
if (sel == 0) GfxFillRect(x + 1, y, x + width, y + 9, 0); |
8578
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
539 |
DrawStringTruncated(x + 2, y, WP(w, dropdown_d).items[i], sel == 0 ? TC_WHITE : TC_BLACK, x + width); |
5196
c419a5b39f8f
(svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents:
5125
diff
changeset
|
540 |
|
8578
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
541 |
if (HasBit(WP(w, dropdown_d).disabled_state, i)) { |
5196
c419a5b39f8f
(svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents:
5125
diff
changeset
|
542 |
GfxFillRect(x, y, x + width, y + 9, |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
543 |
(1 << PALETTE_MODIFIER_GREYOUT) | _colour_gradient[_dropdown_menu_widgets[0].color][5] |
5196
c419a5b39f8f
(svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents:
5125
diff
changeset
|
544 |
); |
c419a5b39f8f
(svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents:
5125
diff
changeset
|
545 |
} |
c419a5b39f8f
(svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents:
5125
diff
changeset
|
546 |
} else { |
c419a5b39f8f
(svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents:
5125
diff
changeset
|
547 |
int c1 = _colour_gradient[_dropdown_menu_widgets[0].color][3]; |
c419a5b39f8f
(svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents:
5125
diff
changeset
|
548 |
int c2 = _colour_gradient[_dropdown_menu_widgets[0].color][7]; |
c419a5b39f8f
(svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents:
5125
diff
changeset
|
549 |
|
c419a5b39f8f
(svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents:
5125
diff
changeset
|
550 |
GfxFillRect(x + 1, y + 3, x + w->width - 5, y + 3, c1); |
c419a5b39f8f
(svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents:
5125
diff
changeset
|
551 |
GfxFillRect(x + 1, y + 4, x + w->width - 5, y + 4, c2); |
842 | 552 |
} |
553 |
} |
|
1177
6adbf59f59a3
(svn r1679) Fix: dropdown menus now returns the index of the string that was clicked even if a previous item is hidden
bjarni
parents:
1095
diff
changeset
|
554 |
y += 10; |
842 | 555 |
} |
556 |
} break; |
|
557 |
||
558 |
case WE_CLICK: { |
|
5041
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
559 |
if (e->we.click.widget != 0) break; |
842 | 560 |
item = GetDropdownItem(w); |
561 |
if (item >= 0) { |
|
8578
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
562 |
WP(w, dropdown_d).click_delay = 4; |
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
563 |
WP(w, dropdown_d).selected_index = item; |
842 | 564 |
SetWindowDirty(w); |
565 |
} |
|
566 |
} break; |
|
567 |
||
568 |
case WE_MOUSELOOP: { |
|
8578
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
569 |
Window *w2 = FindWindowById(WP(w, dropdown_d).parent_wnd_class, WP(w,dropdown_d).parent_wnd_num); |
842 | 570 |
if (w2 == NULL) { |
571 |
DeleteWindow(w); |
|
572 |
return; |
|
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
|
573 |
} |
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
|
574 |
|
8578
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
575 |
if (WP(w, dropdown_d).click_delay != 0 && --WP(w,dropdown_d).click_delay == 0) { |
842 | 576 |
WindowEvent e; |
577 |
e.event = WE_DROPDOWN_SELECT; |
|
8578
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
578 |
e.we.dropdown.button = WP(w, dropdown_d).parent_button; |
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
579 |
e.we.dropdown.index = WP(w, dropdown_d).selected_index; |
842 | 580 |
w2->wndproc(w2, &e); |
581 |
DeleteWindow(w); |
|
582 |
return; |
|
583 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
584 |
|
8578
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
585 |
if (WP(w, dropdown_d).drag_mode) { |
842 | 586 |
item = GetDropdownItem(w); |
587 |
||
588 |
if (!_left_button_clicked) { |
|
8578
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
589 |
WP(w, dropdown_d).drag_mode = false; |
2639 | 590 |
if (item < 0) return; |
8578
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
591 |
WP(w, dropdown_d).click_delay = 2; |
842 | 592 |
} else { |
2639 | 593 |
if (item < 0) return; |
842 | 594 |
} |
595 |
||
8578
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
596 |
WP(w, dropdown_d).selected_index = item; |
842 | 597 |
SetWindowDirty(w); |
598 |
} |
|
599 |
} break; |
|
600 |
||
601 |
case WE_DESTROY: { |
|
8578
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
602 |
Window *w2 = FindWindowById(WP(w, dropdown_d).parent_wnd_class, WP(w,dropdown_d).parent_wnd_num); |
842 | 603 |
if (w2 != NULL) { |
8578
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
604 |
w2->RaiseWidget(WP(w, dropdown_d).parent_button); |
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
605 |
w2->InvalidateWidget(WP(w, dropdown_d).parent_button); |
842 | 606 |
} |
607 |
} break; |
|
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
|
608 |
} |
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
|
609 |
} |
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
|
610 |
|
2448
0a34e90cb31f
(svn r2974) -Fix: Drag and drop selection on drop down boxes didn't select correct item when some items were hidden.
peter1138
parents:
2436
diff
changeset
|
611 |
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask) |
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
|
612 |
{ |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
613 |
int i; |
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
|
614 |
const Widget *wi; |
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
|
615 |
Window *w2; |
5041
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
616 |
const Window *w3; |
8493
3ab458f7cff4
(svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents:
8458
diff
changeset
|
617 |
bool is_dropdown_menu_shown = w->IsWidgetLowered(button); |
5041
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
618 |
int top, height; |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
619 |
int screen_top, screen_bottom; |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
620 |
bool scroll = false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
621 |
|
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
|
622 |
DeleteWindowById(WC_DROPDOWN_MENU, 0); |
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
|
623 |
|
4719
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
624 |
if (is_dropdown_menu_shown) return; |
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
|
625 |
|
8493
3ab458f7cff4
(svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents:
8458
diff
changeset
|
626 |
w->LowerWidget(button); |
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
|
627 |
|
8524
baf4ab1ba18d
(svn r11588) -Codechange: use the new member introduced in r11551
glx
parents:
8493
diff
changeset
|
628 |
w->InvalidateWidget(button); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
629 |
|
2639 | 630 |
for (i = 0; strings[i] != INVALID_STRING_ID; i++) {} |
631 |
if (i == 0) return; |
|
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
|
632 |
|
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
|
633 |
wi = &w->widget[button]; |
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
|
634 |
|
2448
0a34e90cb31f
(svn r2974) -Fix: Drag and drop selection on drop down boxes didn't select correct item when some items were hidden.
peter1138
parents:
2436
diff
changeset
|
635 |
if (hidden_mask != 0) { |
2639 | 636 |
uint j; |
637 |
||
2636
e2bfdc3e82b6
(svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents:
2629
diff
changeset
|
638 |
for (j = 0; strings[j] != INVALID_STRING_ID; j++) { |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8320
diff
changeset
|
639 |
if (HasBit(hidden_mask, j)) i--; |
842 | 640 |
} |
641 |
} |
|
642 |
||
5041
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
643 |
/* The preferred position is just below the dropdown calling widget */ |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
644 |
top = w->top + wi->bottom + 2; |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
645 |
height = i * 10 + 4; |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
646 |
|
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
647 |
w3 = FindWindowById(WC_STATUS_BAR, 0); |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
648 |
screen_bottom = w3 == NULL ? _screen.height : w3->top; |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
649 |
|
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
650 |
/* Check if the dropdown will fully fit below the widget */ |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
651 |
if (top + height >= screen_bottom) { |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
652 |
w3 = FindWindowById(WC_MAIN_TOOLBAR, 0); |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
653 |
screen_top = w3 == NULL ? 0 : w3->top + w3->height; |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
654 |
|
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
655 |
/* If not, check if it will fit above the widget */ |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
656 |
if (w->top + wi->top - height - 1 > screen_top) { |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
657 |
top = w->top + wi->top - height - 1; |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
658 |
} else { |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
659 |
/* ... and lastly if it won't, enable the scroll bar and fit the |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
660 |
* list in below the widget */ |
5196
c419a5b39f8f
(svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents:
5125
diff
changeset
|
661 |
int rows = (screen_bottom - 4 - top) / 10; |
c419a5b39f8f
(svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents:
5125
diff
changeset
|
662 |
height = rows * 10 + 4; |
5041
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
663 |
scroll = true; |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
664 |
} |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
665 |
} |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
666 |
|
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
|
667 |
w2 = AllocateWindow( |
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
|
668 |
w->left + wi[-1].left + 1, |
5041
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
669 |
top, |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
670 |
wi->right - wi[-1].left + 1, |
5041
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
671 |
height, |
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
|
672 |
DropdownMenuWndProc, |
4573
65b6fe8b65b4
(svn r6423) -Codechange: Replace two magic numbers by appropriate enum/define value
belugas
parents:
4547
diff
changeset
|
673 |
WC_DROPDOWN_MENU, |
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
|
674 |
_dropdown_menu_widgets); |
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
|
675 |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
676 |
w2->widget[0].color = wi->color; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
677 |
w2->widget[0].right = wi->right - wi[-1].left; |
5041
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
678 |
w2->widget[0].bottom = height - 1; |
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
|
679 |
|
8493
3ab458f7cff4
(svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents:
8458
diff
changeset
|
680 |
w2->SetWidgetHiddenState(1, !scroll); |
5041
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
681 |
|
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
682 |
if (scroll) { |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
683 |
/* We're scrolling, so enable the scroll bar and shrink the list by |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
684 |
* the scrollbar's width */ |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
685 |
w2->widget[1].color = wi->color; |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
686 |
w2->widget[1].right = w2->widget[0].right; |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
687 |
w2->widget[1].left = w2->widget[1].right - 11; |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
688 |
w2->widget[1].bottom = height - 1; |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
689 |
w2->widget[0].right -= 12; |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
690 |
|
5196
c419a5b39f8f
(svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents:
5125
diff
changeset
|
691 |
w2->vscroll.cap = (height - 4) / 10; |
c419a5b39f8f
(svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents:
5125
diff
changeset
|
692 |
w2->vscroll.count = i; |
5041
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
693 |
} |
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
694 |
|
6e292440425f
(svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents:
5017
diff
changeset
|
695 |
w2->desc_flags = WDF_DEF_WIDGET; |
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
|
696 |
w2->flags4 &= ~WF_WHITE_BORDER_MASK; |
2629
842a290af2fb
(svn r3171) - Codechange: remove static _dropdown_disabled/_dropdown_hidden variables, as a window already contains this information.
peter1138
parents:
2597
diff
changeset
|
697 |
|
8578
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
698 |
WP(w2, dropdown_d).disabled_state = disabled_mask; |
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
699 |
WP(w2, dropdown_d).hidden_state = hidden_mask; |
2636
e2bfdc3e82b6
(svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents:
2629
diff
changeset
|
700 |
|
8578
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
701 |
WP(w2, dropdown_d).parent_wnd_class = w->window_class; |
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
702 |
WP(w2, dropdown_d).parent_wnd_num = w->window_number; |
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
703 |
WP(w2, dropdown_d).parent_button = button; |
2636
e2bfdc3e82b6
(svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents:
2629
diff
changeset
|
704 |
|
8578
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
705 |
WP(w2, dropdown_d).num_items = i; |
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
706 |
WP(w2, dropdown_d).selected_index = selected; |
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
707 |
WP(w2, dropdown_d).items = strings; |
2636
e2bfdc3e82b6
(svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents:
2629
diff
changeset
|
708 |
|
8578
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
709 |
WP(w2, dropdown_d).click_delay = 0; |
55218950ce2d
(svn r11643) -Codechange: conform with the coding style for the WP macro uses.
rubidium
parents:
8524
diff
changeset
|
710 |
WP(w2, dropdown_d).drag_mode = true; |
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
|
711 |
} |
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
|
712 |
|
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
|
713 |
|
6075
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
714 |
static void ResizeWidgets(Window *w, byte a, byte b) |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
715 |
{ |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
716 |
int16 offset = w->widget[a].left; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
717 |
int16 length = w->widget[b].right - offset; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
718 |
|
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
719 |
w->widget[a].right = (length / 2) + offset; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
720 |
|
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
|
721 |
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
|
722 |
} |
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
|
723 |
|
6075
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
724 |
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
|
725 |
{ |
6075
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
726 |
int16 offset = w->widget[a].left; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
727 |
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
|
728 |
|
6075
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
729 |
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
|
730 |
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
|
731 |
|
6075
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
732 |
w->widget[a].right += offset; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
733 |
w->widget[b].right += offset; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
734 |
|
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
|
735 |
/* 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
|
736 |
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
|
737 |
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
|
738 |
} |
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
|
739 |
|
6075
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
740 |
/** Evenly distribute some widgets when resizing horizontally (often a button row) |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
741 |
* 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
|
742 |
* @param w Window to modify |
6075
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
743 |
* @param left The leftmost widget to resize |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
744 |
* @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
|
745 |
*/ |
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
|
746 |
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
|
747 |
{ |
6075
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
748 |
int16 num_widgets = right - left + 1; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
749 |
|
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
750 |
if (num_widgets < 2) NOT_REACHED(); |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
751 |
|
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
752 |
switch (num_widgets) { |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
753 |
case 2: ResizeWidgets(w, left, right); break; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
754 |
case 3: ResizeWidgets(w, left, left + 1, right); break; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
755 |
default: { |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
756 |
/* Looks like we got more than 3 widgets to resize |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
757 |
* 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
|
758 |
* 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
|
759 |
* 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
|
760 |
int16 offset = w->widget[left].left; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
761 |
int16 length = w->widget[right].right - offset; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
762 |
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
|
763 |
|
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
764 |
/* Now we need to find the middle of the widgets. |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
765 |
* 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
|
766 |
* 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
|
767 |
* 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
|
768 |
* |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
769 |
* num_widgets/2 (rounding down) |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
770 |
* --------------- |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
771 |
* num_widgets |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
772 |
* |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
773 |
* 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
|
774 |
int16 middle = ((length * num_widgets) / (2 * num_widgets)) + offset; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
775 |
|
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
776 |
/* 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
|
777 |
w->widget[widget].right = middle; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
778 |
w->widget[widget + 1].left = w->widget[widget].right + 1; |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
779 |
/* Now resize the left and right of the middle */ |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
780 |
ResizeButtons(w, left, widget); |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
781 |
ResizeButtons(w, widget + 1, right); |
33cdb35f9af5
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents:
6073
diff
changeset
|
782 |
} |
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
|
783 |
} |
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
|
784 |
} |