Mercurial > hg > openttd
annotate src/widget.cpp @ 11999:b8e87660b9fc draft
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
author | alberth <alberth@openttd.org> |
---|---|
date | Sat, 23 May 2009 18:06:29 +0000 (2009-05-23) |
parents | de771cbe234d |
children | d092f17a921d |
rev | line source |
---|---|
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1 /* $Id$ */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2 |
9111
d48433370037
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium <rubidium@openttd.org>
parents:
8969
diff
changeset
|
3 /** @file widget.cpp Handling of the default/simple widgets. */ |
6432
fc703c6dc92c
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas <belugas@openttd.org>
parents:
6278
diff
changeset
|
4 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
5 #include "stdafx.h" |
10208
39cf8eebfda5
(svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents:
10207
diff
changeset
|
6 #include "company_func.h" |
8224
c45446125bf0
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents:
8131
diff
changeset
|
7 #include "gfx_func.h" |
8106
47b1794a7eca
(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 <rubidium@openttd.org>
parents:
8082
diff
changeset
|
8 #include "window_gui.h" |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
9 #include "debug.h" |
11465
4fc1be7900f4
(svn r15823) -Codechange: prepare the WWT_FRAME and WWT_DROPDOWN(IN) widget types for rtl languages.
yexo <yexo@openttd.org>
parents:
11461
diff
changeset
|
10 #include "strings_func.h" |
8131
e300ac8001ae
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium <rubidium@openttd.org>
parents:
8121
diff
changeset
|
11 |
8264
2495310e220f
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents:
8254
diff
changeset
|
12 #include "table/sprites.h" |
2495310e220f
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents:
8254
diff
changeset
|
13 #include "table/strings.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
14 |
11799
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
15 static const char *UPARROW = "\xEE\x8A\xA0"; ///< String containing an upwards pointing arrow. |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
16 static const char *DOWNARROW = "\xEE\x8A\xAA"; ///< String containing a downwards pointing arrow. |
8349
cbb2e614bcfa
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138 <peter1138@openttd.org>
parents:
8335
diff
changeset
|
17 |
9773
fcce76c3bb3d
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents:
9770
diff
changeset
|
18 /** |
fcce76c3bb3d
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents:
9770
diff
changeset
|
19 * Compute the vertical position of the draggable part of scrollbar |
fcce76c3bb3d
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents:
9770
diff
changeset
|
20 * @param sb Scrollbar list data |
fcce76c3bb3d
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents:
9770
diff
changeset
|
21 * @param top Top position of the scrollbar (top position of the up-button) |
fcce76c3bb3d
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents:
9770
diff
changeset
|
22 * @param bottom Bottom position of the scrollbar (bottom position of the down-button) |
fcce76c3bb3d
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents:
9770
diff
changeset
|
23 * @return A Point, with x containing the top coordinate of the draggable part, and |
fcce76c3bb3d
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents:
9770
diff
changeset
|
24 * y containing the bottom coordinate of the draggable part |
fcce76c3bb3d
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents:
9770
diff
changeset
|
25 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
26 static Point HandleScrollbarHittest(const Scrollbar *sb, int top, int bottom) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
27 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
28 Point pt; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
29 int height, count, pos, cap; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
30 |
9773
fcce76c3bb3d
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents:
9770
diff
changeset
|
31 top += 10; // top points to just below the up-button |
fcce76c3bb3d
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents:
9770
diff
changeset
|
32 bottom -= 9; // bottom points to top of the down-button |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
33 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
34 height = (bottom - top); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
35 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
36 pos = sb->pos; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
37 count = sb->count; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
38 cap = sb->cap; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
39 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
40 if (count != 0) top += height * pos / count; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
41 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
42 if (cap > count) cap = count; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
43 if (count != 0) bottom -= (count - pos - cap) * height / count; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
44 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
45 pt.x = top; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
46 pt.y = bottom - 1; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
47 return pt; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
48 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
49 |
6481
85a1a79387a2
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents:
6432
diff
changeset
|
50 /** Special handling for the scrollbar widget type. |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
51 * Handles the special scrolling buttons and other |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
52 * scrolling. |
6481
85a1a79387a2
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents:
6432
diff
changeset
|
53 * @param w Window on which a scroll was performed. |
85a1a79387a2
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents:
6432
diff
changeset
|
54 * @param wi Pointer to the scrollbar widget. |
85a1a79387a2
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents:
6432
diff
changeset
|
55 * @param x The X coordinate of the mouse click. |
85a1a79387a2
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents:
6432
diff
changeset
|
56 * @param y The Y coordinate of the mouse click. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
57 void ScrollbarClickHandler(Window *w, const Widget *wi, int x, int y) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
58 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
59 int mi, ma, pos; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
60 Scrollbar *sb; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
61 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
62 switch (wi->type) { |
8729
ce8dc35932c3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium <rubidium@openttd.org>
parents:
8418
diff
changeset
|
63 case WWT_SCROLLBAR: |
6432
fc703c6dc92c
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas <belugas@openttd.org>
parents:
6278
diff
changeset
|
64 /* vertical scroller */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
65 w->flags4 &= ~WF_HSCROLL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
66 w->flags4 &= ~WF_SCROLL2; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
67 mi = wi->top; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
68 ma = wi->bottom; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
69 pos = y; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
70 sb = &w->vscroll; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
71 break; |
8729
ce8dc35932c3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium <rubidium@openttd.org>
parents:
8418
diff
changeset
|
72 |
ce8dc35932c3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium <rubidium@openttd.org>
parents:
8418
diff
changeset
|
73 case WWT_SCROLL2BAR: |
6432
fc703c6dc92c
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas <belugas@openttd.org>
parents:
6278
diff
changeset
|
74 /* 2nd vertical scroller */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
75 w->flags4 &= ~WF_HSCROLL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
76 w->flags4 |= WF_SCROLL2; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
77 mi = wi->top; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
78 ma = wi->bottom; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
79 pos = y; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
80 sb = &w->vscroll2; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
81 break; |
8729
ce8dc35932c3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium <rubidium@openttd.org>
parents:
8418
diff
changeset
|
82 |
ce8dc35932c3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium <rubidium@openttd.org>
parents:
8418
diff
changeset
|
83 case WWT_HSCROLLBAR: |
6432
fc703c6dc92c
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas <belugas@openttd.org>
parents:
6278
diff
changeset
|
84 /* horizontal scroller */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
85 w->flags4 &= ~WF_SCROLL2; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
86 w->flags4 |= WF_HSCROLL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
87 mi = wi->left; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
88 ma = wi->right; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
89 pos = x; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
90 sb = &w->hscroll; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
91 break; |
8729
ce8dc35932c3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium <rubidium@openttd.org>
parents:
8418
diff
changeset
|
92 |
ce8dc35932c3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium <rubidium@openttd.org>
parents:
8418
diff
changeset
|
93 default: NOT_REACHED(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
94 } |
8969
01cc3ee6ecb1
(svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium <rubidium@openttd.org>
parents:
8857
diff
changeset
|
95 if (pos <= mi + 9) { |
6432
fc703c6dc92c
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas <belugas@openttd.org>
parents:
6278
diff
changeset
|
96 /* Pressing the upper button? */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
97 w->flags4 |= WF_SCROLL_UP; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
98 if (_scroller_click_timeout == 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
99 _scroller_click_timeout = 6; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
100 if (sb->pos != 0) sb->pos--; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
101 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
102 _left_button_clicked = false; |
8729
ce8dc35932c3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium <rubidium@openttd.org>
parents:
8418
diff
changeset
|
103 } else if (pos >= ma - 10) { |
6432
fc703c6dc92c
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas <belugas@openttd.org>
parents:
6278
diff
changeset
|
104 /* Pressing the lower button? */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
105 w->flags4 |= WF_SCROLL_DOWN; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
106 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
107 if (_scroller_click_timeout == 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
108 _scroller_click_timeout = 6; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
109 if ((byte)(sb->pos + sb->cap) < sb->count) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
110 sb->pos++; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
111 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
112 _left_button_clicked = false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
113 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
114 Point pt = HandleScrollbarHittest(sb, mi, ma); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
115 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
116 if (pos < pt.x) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
117 sb->pos = max(sb->pos - sb->cap, 0); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
118 } else if (pos > pt.y) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
119 sb->pos = min( |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
120 sb->pos + sb->cap, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
121 max(sb->count - sb->cap, 0) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
122 ); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
123 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
124 _scrollbar_start_pos = pt.x - mi - 9; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
125 _scrollbar_size = ma - mi - 23; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
126 w->flags4 |= WF_SCROLL_MIDDLE; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
127 _scrolling_scrollbar = true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
128 _cursorpos_drag_start = _cursor.pos; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
129 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
130 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
131 |
9116
44beb31166aa
(svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium <rubidium@openttd.org>
parents:
9111
diff
changeset
|
132 w->SetDirty(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
133 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
134 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
135 /** Returns the index for the widget located at the given position |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
136 * relative to the window. It includes all widget-corner pixels as well. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
137 * @param *w Window to look inside |
6481
85a1a79387a2
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents:
6432
diff
changeset
|
138 * @param x The Window client X coordinate |
85a1a79387a2
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents:
6432
diff
changeset
|
139 * @param y The Window client y coordinate |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
140 * @return A widget index, or -1 if no widget was found. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
141 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
142 int GetWidgetFromPos(const Window *w, int x, int y) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
143 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
144 uint index; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
145 int found_index = -1; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
146 |
6432
fc703c6dc92c
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas <belugas@openttd.org>
parents:
6278
diff
changeset
|
147 /* Go through the widgets and check if we find the widget that the coordinate is |
fc703c6dc92c
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas <belugas@openttd.org>
parents:
6278
diff
changeset
|
148 * inside. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
149 for (index = 0; index < w->widget_count; index++) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
150 const Widget *wi = &w->widget[index]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
151 if (wi->type == WWT_EMPTY || wi->type == WWT_FRAME) continue; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
152 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
153 if (x >= wi->left && x <= wi->right && y >= wi->top && y <= wi->bottom && |
7997
d109780d515b
(svn r11555) -Codechange: use the new members introduced in r11551.
rubidium <rubidium@openttd.org>
parents:
7962
diff
changeset
|
154 !w->IsWidgetHidden(index)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
155 found_index = index; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
156 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
157 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
158 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
159 return found_index; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
160 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
161 |
9773
fcce76c3bb3d
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents:
9770
diff
changeset
|
162 /** |
fcce76c3bb3d
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents:
9770
diff
changeset
|
163 * Draw frame rectangle. |
fcce76c3bb3d
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents:
9770
diff
changeset
|
164 * @param left Left edge of the frame |
fcce76c3bb3d
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents:
9770
diff
changeset
|
165 * @param top Top edge of the frame |
fcce76c3bb3d
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents:
9770
diff
changeset
|
166 * @param right Right edge of the frame |
fcce76c3bb3d
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents:
9770
diff
changeset
|
167 * @param bottom Bottom edge of the frame |
11080
02d314ea4f63
(svn r15423) -Codechange: split widget related types to their own header and add a bit of type strictness.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
168 * @param colour Colour table to use. @see _colour_gradient |
9773
fcce76c3bb3d
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents:
9770
diff
changeset
|
169 * @param flags Flags controlling how to draw the frame. @see FrameFlags |
fcce76c3bb3d
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents:
9770
diff
changeset
|
170 */ |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
11084
diff
changeset
|
171 void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
172 { |
11080
02d314ea4f63
(svn r15423) -Codechange: split widget related types to their own header and add a bit of type strictness.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
173 uint dark = _colour_gradient[colour][3]; |
02d314ea4f63
(svn r15423) -Codechange: split widget related types to their own header and add a bit of type strictness.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
174 uint medium_dark = _colour_gradient[colour][5]; |
02d314ea4f63
(svn r15423) -Codechange: split widget related types to their own header and add a bit of type strictness.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
175 uint medium_light = _colour_gradient[colour][6]; |
02d314ea4f63
(svn r15423) -Codechange: split widget related types to their own header and add a bit of type strictness.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
176 uint light = _colour_gradient[colour][7]; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
177 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
178 if (flags & FR_TRANSPARENT) { |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
11084
diff
changeset
|
179 GfxFillRect(left, top, right, bottom, PALETTE_TO_TRANSPARENT, FILLRECT_RECOLOUR); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
180 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
181 uint interior; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
182 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
183 if (flags & FR_LOWERED) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
184 GfxFillRect(left, top, left, bottom, dark); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
185 GfxFillRect(left + 1, top, right, top, dark); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
186 GfxFillRect(right, top + 1, right, bottom - 1, light); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
187 GfxFillRect(left + 1, bottom, right, bottom, light); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
188 interior = (flags & FR_DARKENED ? medium_dark : medium_light); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
189 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
190 GfxFillRect(left, top, left, bottom - 1, light); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
191 GfxFillRect(left + 1, top, right - 1, top, light); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
192 GfxFillRect(right, top, right, bottom - 1, dark); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
193 GfxFillRect(left, bottom, right, bottom, dark); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
194 interior = medium_dark; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
195 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
196 if (!(flags & FR_BORDERONLY)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
197 GfxFillRect(left + 1, top + 1, right - 1, bottom - 1, interior); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
198 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
199 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
200 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
201 |
11999
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
202 /** |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
203 * Draw an image button. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
204 * @param r Rectangle of the button. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
205 * @param type Widget type (#WWT_IMGBTN or #WWT_IMGBTN_2). |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
206 * @param colour Colour of the button. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
207 * @param clicked Button is lowered. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
208 * @param img Sprite to draw. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
209 */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
210 static inline void DrawImageButtons(const Rect &r, WidgetType type, Colours colour, bool clicked, SpriteID img) |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
211 { |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
212 assert(img != 0); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
213 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
214 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
215 /* show different image when clicked for WWT_IMGBTN_2 */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
216 if ((type & WWT_MASK) == WWT_IMGBTN_2 && clicked) img++; |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
217 DrawSprite(img, PAL_NONE, r.left + 1 + clicked, r.top + 1 + clicked); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
218 } |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
219 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
220 /** |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
221 * Draw the label-part of a widget. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
222 * @param r Rectangle of the label background. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
223 * @param type Widget type (#WWT_TEXTBTN, #WWT_TEXTBTN_2, or #WWT_LABEL). |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
224 * @param clicked Label is rendered lowered. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
225 * @param str Text to draw. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
226 */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
227 static inline void DrawLabel(const Rect &r, WidgetType type, bool clicked, StringID str) |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
228 { |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
229 if ((type & WWT_MASK) == WWT_TEXTBTN_2 && clicked) str++; |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
230 DrawString(r.left + clicked, r.right + clicked, ((r.top + r.bottom + 1) >> 1) - 5 + clicked, str, TC_FROMSTRING, SA_CENTER); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
231 } |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
232 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
233 /** |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
234 * Draw text. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
235 * @param r Rectangle of the background. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
236 * @param colour Colour of the text. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
237 * @param str Text to draw. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
238 */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
239 static inline void DrawText(const Rect &r, TextColour colour, StringID str) |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
240 { |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
241 if (str != STR_NULL) DrawString(r.left, r.right, r.top, str, colour); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
242 } |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
243 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
244 /** |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
245 * Draw an inset widget. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
246 * @param r Rectangle of the background. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
247 * @param colour Colour of the inset. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
248 * @param str Text to draw. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
249 */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
250 static inline void DrawInset(const Rect &r, Colours colour, StringID str) |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
251 { |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
252 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_LOWERED | FR_DARKENED); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
253 if (str != STR_NULL) DrawString(r.left + 2, r.right - 2, r.top + 1, str); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
254 } |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
255 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
256 /** |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
257 * Draw a matrix widget. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
258 * @param r Rectangle of the matrix background. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
259 * @param colour Colour of the background. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
260 * @param clicked Matrix is rendered lowered. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
261 * @param data Data of the widget. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
262 */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
263 static inline void DrawMatrix(const Rect &r, Colours colour, bool clicked, uint16 data) |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
264 { |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
265 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
266 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
267 int c = GB(data, 0, 8); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
268 int amt1 = (r.right - r.left + 1) / c; |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
269 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
270 int d = GB(data, 8, 8); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
271 int amt2 = (r.bottom - r.top + 1) / d; |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
272 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
273 int col = _colour_gradient[colour & 0xF][6]; |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
274 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
275 int x = r.left; |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
276 for (int ctr = c; ctr > 1; ctr--) { |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
277 x += amt1; |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
278 GfxFillRect(x, r.top + 1, x, r.bottom - 1, col); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
279 } |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
280 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
281 x = r.top; |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
282 for (int ctr = d; ctr > 1; ctr--) { |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
283 x += amt2; |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
284 GfxFillRect(r.left + 1, x, r.right - 1, x, col); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
285 } |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
286 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
287 col = _colour_gradient[colour & 0xF][4]; |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
288 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
289 x = r.left - 1; |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
290 for (int ctr = c; ctr > 1; ctr--) { |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
291 x += amt1; |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
292 GfxFillRect(x, r.top + 1, x, r.bottom - 1, col); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
293 } |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
294 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
295 x = r.top - 1; |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
296 for (int ctr = d; ctr > 1; ctr--) { |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
297 x += amt2; |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
298 GfxFillRect(r.left + 1, x, r.right - 1, x, col); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
299 } |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
300 } |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
301 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
302 /** |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
303 * Draw a vertical scrollbar. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
304 * @param r Rectangle of the scrollbar widget. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
305 * @param colour Colour of the scrollbar widget. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
306 * @param up_clicked Up-arrow is clicked. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
307 * @param bar_dragged Bar is dragged. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
308 * @param down_clicked Down-arrow is clicked. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
309 * @param scrollbar Scrollbar size, offset, and capacity information. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
310 */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
311 static inline void DrawVerticalScrollbar(const Rect &r, Colours colour, bool up_clicked, bool bar_dragged, bool down_clicked, const Scrollbar *scrollbar) |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
312 { |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
313 assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere! |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
314 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
315 /* draw up/down buttons */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
316 DrawFrameRect(r.left, r.top, r.right, r.top + 9, colour, (up_clicked) ? FR_LOWERED : FR_NONE); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
317 DrawString(r.left + up_clicked, r.right + up_clicked, r.top + up_clicked, UPARROW, TC_BLACK, SA_CENTER); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
318 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
319 DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, colour, (down_clicked) ? FR_LOWERED : FR_NONE); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
320 DrawString(r.left + down_clicked, r.right + down_clicked, r.bottom - 9 + down_clicked, DOWNARROW, TC_BLACK, SA_CENTER); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
321 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
322 int c1 = _colour_gradient[colour & 0xF][3]; |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
323 int c2 = _colour_gradient[colour & 0xF][7]; |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
324 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
325 /* draw "shaded" background */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
326 GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c2); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
327 GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c1, FILLRECT_CHECKER); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
328 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
329 /* draw shaded lines */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
330 GfxFillRect(r.left + 2, r.top + 10, r.left + 2, r.bottom - 10, c1); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
331 GfxFillRect(r.left + 3, r.top + 10, r.left + 3, r.bottom - 10, c2); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
332 GfxFillRect(r.left + 7, r.top + 10, r.left + 7, r.bottom - 10, c1); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
333 GfxFillRect(r.left + 8, r.top + 10, r.left + 8, r.bottom - 10, c2); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
334 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
335 Point pt = HandleScrollbarHittest(scrollbar, r.top, r.bottom); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
336 DrawFrameRect(r.left, pt.x, r.right, pt.y, colour, bar_dragged ? FR_LOWERED : FR_NONE); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
337 } |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
338 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
339 /** |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
340 * Draw a horizontal scrollbar. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
341 * @param r Rectangle of the scrollbar widget. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
342 * @param colour Colour of the scrollbar widget. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
343 * @param left_clicked Left-arrow is clicked. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
344 * @param bar_dragged Bar is dragged. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
345 * @param right_clicked Right-arrow is clicked. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
346 * @param scrollbar Scrollbar size, offset, and capacity information. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
347 */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
348 static inline void DrawHorizontalScrollbar(const Rect &r, Colours colour, bool left_clicked, bool bar_dragged, bool right_clicked, const Scrollbar *scrollbar) |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
349 { |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
350 assert(r.bottom - r.top == 11); // To ensure the same sizes are used everywhere! |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
351 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
352 DrawFrameRect(r.left, r.top, r.left + 9, r.bottom, colour, left_clicked ? FR_LOWERED : FR_NONE); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
353 DrawSprite(SPR_ARROW_LEFT, PAL_NONE, r.left + 1 + left_clicked, r.top + 1 + left_clicked); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
354 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
355 DrawFrameRect(r.right - 9, r.top, r.right, r.bottom, colour, right_clicked ? FR_LOWERED : FR_NONE); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
356 DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, r.right - 8 + right_clicked, r.top + 1 + right_clicked); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
357 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
358 int c1 = _colour_gradient[colour & 0xF][3]; |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
359 int c2 = _colour_gradient[colour & 0xF][7]; |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
360 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
361 /* draw "shaded" background */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
362 GfxFillRect(r.left + 10, r.top, r.right - 10, r.bottom, c2); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
363 GfxFillRect(r.left + 10, r.top, r.right - 10, r.bottom, c1, FILLRECT_CHECKER); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
364 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
365 /* draw shaded lines */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
366 GfxFillRect(r.left + 10, r.top + 2, r.right - 10, r.top + 2, c1); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
367 GfxFillRect(r.left + 10, r.top + 3, r.right - 10, r.top + 3, c2); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
368 GfxFillRect(r.left + 10, r.top + 7, r.right - 10, r.top + 7, c1); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
369 GfxFillRect(r.left + 10, r.top + 8, r.right - 10, r.top + 8, c2); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
370 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
371 /* draw actual scrollbar */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
372 Point pt = HandleScrollbarHittest(scrollbar, r.left, r.right); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
373 DrawFrameRect(pt.x, r.top, pt.y, r.bottom, colour, bar_dragged ? FR_LOWERED : FR_NONE); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
374 } |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
375 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
376 /** |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
377 * Draw a frame widget. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
378 * @param r Rectangle of the frame. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
379 * @param colour Colour of the frame. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
380 * @param str Text of the frame. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
381 */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
382 static inline void DrawFrame(const Rect &r, Colours colour, StringID str) |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
383 { |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
384 int x2 = r.left; // by default the left side is the left side of the widget |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
385 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
386 if (str != STR_NULL) x2 = DrawString(r.left + 6, r.right - 6, r.top, str); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
387 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
388 int c1 = _colour_gradient[colour][3]; |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
389 int c2 = _colour_gradient[colour][7]; |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
390 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
391 if (_dynlang.text_dir == TD_LTR) { |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
392 /* Line from upper left corner to start of text */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
393 GfxFillRect(r.left, r.top + 4, r.left + 4, r.top + 4, c1); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
394 GfxFillRect(r.left + 1, r.top + 5, r.left + 4, r.top + 5, c2); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
395 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
396 /* Line from end of text to upper right corner */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
397 GfxFillRect(x2, r.top + 4, r.right - 1, r.top + 4, c1); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
398 GfxFillRect(x2, r.top + 5, r.right - 2, r.top + 5, c2); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
399 } else { |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
400 /* Line from upper left corner to start of text */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
401 GfxFillRect(r.left, r.top + 4, x2 - 2, r.top + 4, c1); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
402 GfxFillRect(r.left + 1, r.top + 5, x2 - 2, r.top + 5, c2); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
403 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
404 /* Line from end of text to upper right corner */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
405 GfxFillRect(r.right - 5, r.top + 4, r.right - 1, r.top + 4, c1); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
406 GfxFillRect(r.right - 5, r.top + 5, r.right - 2, r.top + 5, c2); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
407 } |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
408 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
409 /* Line from upper left corner to bottom left corner */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
410 GfxFillRect(r.left, r.top + 5, r.left, r.bottom - 1, c1); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
411 GfxFillRect(r.left + 1, r.top + 6, r.left + 1, r.bottom - 2, c2); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
412 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
413 /* Line from upper right corner to bottom right corner */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
414 GfxFillRect(r.right - 1, r.top + 5, r.right - 1, r.bottom - 2, c1); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
415 GfxFillRect(r.right, r.top + 4, r.right, r.bottom - 1, c2); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
416 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
417 GfxFillRect(r.left + 1, r.bottom - 1, r.right - 1, r.bottom - 1, c1); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
418 GfxFillRect(r.left, r.bottom, r.right, r.bottom, c2); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
419 } |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
420 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
421 /** |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
422 * Draw a sticky box. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
423 * @param r Rectangle of the box. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
424 * @param colour Colour of the sticky box. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
425 * @param clicked Box is lowered. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
426 */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
427 static inline void DrawStickyBox(const Rect &r, Colours colour, bool clicked) |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
428 { |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
429 assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere! |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
430 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
431 DrawSprite((clicked) ? SPR_PIN_UP : SPR_PIN_DOWN, PAL_NONE, r.left + 2 + clicked, r.top + 3 + clicked); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
432 } |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
433 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
434 /** |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
435 * Draw a resize box. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
436 * @param r Rectangle of the box. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
437 * @param colour Colour of the resize box. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
438 * @param at_left Resize box is at left-side of the window, |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
439 * @param clicked Box is lowered. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
440 */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
441 static inline void DrawResizeBox(const Rect &r, Colours colour, bool at_left, bool clicked) |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
442 { |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
443 assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere! |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
444 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
445 if (at_left) { |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
446 DrawSprite(SPR_WINDOW_RESIZE_LEFT, PAL_NONE, r.left + 2, r.top + 3 + clicked); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
447 } else { |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
448 DrawSprite(SPR_WINDOW_RESIZE_RIGHT, PAL_NONE, r.left + 3 + clicked, r.top + 3 + clicked); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
449 } |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
450 } |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
451 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
452 /** |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
453 * Draw a close box. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
454 * @param r Rectangle of the box. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
455 * @param colour Colour of the close box. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
456 * @param str Cross to draw (#STR_BLACK_CROSS or #STR_SILVER_CROSS). |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
457 */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
458 static inline void DrawCloseBox(const Rect &r, Colours colour, StringID str) |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
459 { |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
460 assert(str == STR_BLACK_CROSS || str == STR_SILVER_CROSS); // black or silver cross |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
461 assert(r.right - r.left == 10); // To ensure the same sizes are used everywhere |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
462 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
463 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_NONE); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
464 DrawString(r.left, r.right, r.top + 2, str, TC_FROMSTRING, SA_CENTER); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
465 } |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
466 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
467 /** |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
468 * Draw a caption bar. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
469 * @param r Rectangle of the bar. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
470 * @param colour Colour of the window. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
471 * @param owner 'Owner' of the window. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
472 * @param str Text to draw in the bar. |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
473 */ |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
474 static inline void DrawCaption(const Rect &r, Colours colour, Owner owner, StringID str) |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
475 { |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
476 assert(r.bottom - r.top == 13); // To ensure the same sizes are used everywhere! |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
477 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_BORDERONLY); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
478 DrawFrameRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, colour, (owner == INVALID_OWNER) ? FR_LOWERED | FR_DARKENED : FR_LOWERED | FR_DARKENED | FR_BORDERONLY); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
479 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
480 if (owner != INVALID_OWNER) { |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
481 GfxFillRect(r.left + 2, r.top + 2, r.right - 2, r.bottom - 2, _colour_gradient[_company_colours[owner]][4]); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
482 } |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
483 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
484 DrawString(r.left + 2, r.right - 2, r.top + 2, str, TC_FROMSTRING, SA_CENTER); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
485 } |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
486 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
487 static inline void DrawDropdown(const Rect &r, Colours colour, bool clicked, StringID str) |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
488 { |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
489 assert(r.bottom - r.top == 11); // ensure consistent size |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
490 |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
491 if (_dynlang.text_dir == TD_LTR) { |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
492 DrawFrameRect(r.left, r.top, r.right - 12, r.bottom, colour, FR_NONE); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
493 DrawFrameRect(r.right - 11, r.top, r.right, r.bottom, colour, clicked ? FR_LOWERED : FR_NONE); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
494 DrawString(r.right - (clicked ? 10 : 11), r.right, r.top + (clicked ? 2 : 1), STR_ARROW_DOWN, TC_BLACK, SA_CENTER); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
495 if (str != STR_NULL) DrawString(r.left + 2, r.right - 14, r.top + 1, str, TC_BLACK); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
496 } else { |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
497 DrawFrameRect(r.left + 12, r.top, r.right, r.bottom, colour, FR_NONE); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
498 DrawFrameRect(r.left, r.top, r.left + 11, r.bottom, colour, clicked ? FR_LOWERED : FR_NONE); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
499 DrawString(r.left + clicked, r.left + 11, r.top + (clicked ? 2 : 1), STR_ARROW_DOWN, TC_BLACK, SA_CENTER); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
500 if (str != STR_NULL) DrawString(r.left + 14, r.right - 2, r.top + 1, str, TC_BLACK); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
501 } |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
502 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
503 |
8857
a75a0c683fea
(svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents:
8737
diff
changeset
|
504 /** |
a75a0c683fea
(svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents:
8737
diff
changeset
|
505 * Paint all widgets of a window. |
a75a0c683fea
(svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents:
8737
diff
changeset
|
506 */ |
9273
72a6d2e60834
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium <rubidium@openttd.org>
parents:
9116
diff
changeset
|
507 void Window::DrawWidgets() const |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
508 { |
10647
592ae9307430
(svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents:
10238
diff
changeset
|
509 const DrawPixelInfo *dpi = _cur_dpi; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
510 |
9273
72a6d2e60834
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium <rubidium@openttd.org>
parents:
9116
diff
changeset
|
511 for (uint i = 0; i < this->widget_count; i++) { |
72a6d2e60834
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium <rubidium@openttd.org>
parents:
9116
diff
changeset
|
512 const Widget *wi = &this->widget[i]; |
72a6d2e60834
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium <rubidium@openttd.org>
parents:
9116
diff
changeset
|
513 bool clicked = this->IsWidgetLowered(i); |
7962
0fcca1a5847f
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz <smatz@openttd.org>
parents:
7928
diff
changeset
|
514 Rect r; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
515 |
7962
0fcca1a5847f
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz <smatz@openttd.org>
parents:
7928
diff
changeset
|
516 if (dpi->left > (r.right = wi->right) || |
0fcca1a5847f
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz <smatz@openttd.org>
parents:
7928
diff
changeset
|
517 dpi->left + dpi->width <= (r.left = wi->left) || |
0fcca1a5847f
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz <smatz@openttd.org>
parents:
7928
diff
changeset
|
518 dpi->top > (r.bottom = wi->bottom) || |
0fcca1a5847f
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz <smatz@openttd.org>
parents:
7928
diff
changeset
|
519 dpi->top + dpi->height <= (r.top = wi->top) || |
9273
72a6d2e60834
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium <rubidium@openttd.org>
parents:
9116
diff
changeset
|
520 this->IsWidgetHidden(i)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
521 continue; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
522 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
523 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
524 switch (wi->type & WWT_MASK) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
525 case WWT_IMGBTN: |
11999
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
526 case WWT_IMGBTN_2: |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
527 DrawImageButtons(r, wi->type,wi->colour, clicked, wi->data); |
8320
06495654aee6
(svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138 <peter1138@openttd.org>
parents:
8284
diff
changeset
|
528 break; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
529 |
8729
ce8dc35932c3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium <rubidium@openttd.org>
parents:
8418
diff
changeset
|
530 case WWT_PANEL: |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
531 assert(wi->data == 0); |
11080
02d314ea4f63
(svn r15423) -Codechange: split widget related types to their own header and add a bit of type strictness.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
532 DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->colour, (clicked) ? FR_LOWERED : FR_NONE); |
8320
06495654aee6
(svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138 <peter1138@openttd.org>
parents:
8284
diff
changeset
|
533 break; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
534 |
8737
b62e473a9029
(svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium <rubidium@openttd.org>
parents:
8729
diff
changeset
|
535 case WWT_EDITBOX: |
11080
02d314ea4f63
(svn r15423) -Codechange: split widget related types to their own header and add a bit of type strictness.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
536 DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->colour, FR_LOWERED | FR_DARKENED); |
8737
b62e473a9029
(svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium <rubidium@openttd.org>
parents:
8729
diff
changeset
|
537 break; |
b62e473a9029
(svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium <rubidium@openttd.org>
parents:
8729
diff
changeset
|
538 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
539 case WWT_TEXTBTN: |
8729
ce8dc35932c3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium <rubidium@openttd.org>
parents:
8418
diff
changeset
|
540 case WWT_TEXTBTN_2: |
11080
02d314ea4f63
(svn r15423) -Codechange: split widget related types to their own header and add a bit of type strictness.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
541 DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->colour, (clicked) ? FR_LOWERED : FR_NONE); |
8729
ce8dc35932c3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium <rubidium@openttd.org>
parents:
8418
diff
changeset
|
542 /* FALL THROUGH */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
543 |
11999
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
544 case WWT_LABEL: |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
545 DrawLabel(r, wi->type, clicked, wi->data); |
6278
b57f385b355c
(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 <belugas@openttd.org>
parents:
5824
diff
changeset
|
546 break; |
b57f385b355c
(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 <belugas@openttd.org>
parents:
5824
diff
changeset
|
547 |
11999
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
548 case WWT_TEXT: |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
549 DrawText(r, (TextColour)wi->colour, wi->data); |
8320
06495654aee6
(svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138 <peter1138@openttd.org>
parents:
8284
diff
changeset
|
550 break; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
551 |
11999
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
552 case WWT_INSET: |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
553 DrawInset(r, wi->colour, wi->data); |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
554 break; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
555 |
11999
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
556 case WWT_MATRIX: |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
557 DrawMatrix(r, wi->colour, clicked, wi->data); |
8320
06495654aee6
(svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138 <peter1138@openttd.org>
parents:
8284
diff
changeset
|
558 break; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
559 |
6432
fc703c6dc92c
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas <belugas@openttd.org>
parents:
6278
diff
changeset
|
560 /* vertical scrollbar */ |
11999
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
561 case WWT_SCROLLBAR: |
7962
0fcca1a5847f
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz <smatz@openttd.org>
parents:
7928
diff
changeset
|
562 assert(wi->data == 0); |
11999
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
563 DrawVerticalScrollbar(r, wi->colour, (this->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_UP, |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
564 (this->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_MIDDLE, |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
565 (this->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_DOWN, &this->vscroll); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
566 break; |
8729
ce8dc35932c3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium <rubidium@openttd.org>
parents:
8418
diff
changeset
|
567 |
11999
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
568 case WWT_SCROLL2BAR: |
7962
0fcca1a5847f
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz <smatz@openttd.org>
parents:
7928
diff
changeset
|
569 assert(wi->data == 0); |
11999
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
570 DrawVerticalScrollbar(r, wi->colour, (this->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_UP | WF_SCROLL2), |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
571 (this->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_MIDDLE | WF_SCROLL2), |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
572 (this->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_DOWN | WF_SCROLL2), &this->vscroll2); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
573 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
574 |
6432
fc703c6dc92c
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas <belugas@openttd.org>
parents:
6278
diff
changeset
|
575 /* horizontal scrollbar */ |
11999
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
576 case WWT_HSCROLLBAR: |
7962
0fcca1a5847f
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz <smatz@openttd.org>
parents:
7928
diff
changeset
|
577 assert(wi->data == 0); |
11999
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
578 DrawHorizontalScrollbar(r, wi->colour, (this->flags4 & (WF_SCROLL_UP | WF_HSCROLL)) == (WF_SCROLL_UP | WF_HSCROLL), |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
579 (this->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL)) == (WF_SCROLL_MIDDLE | WF_HSCROLL), |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
580 (this->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL)) == (WF_SCROLL_DOWN | WF_HSCROLL), &this->hscroll); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
581 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
582 |
11999
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
583 case WWT_FRAME: |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
584 DrawFrame(r, wi->colour, wi->data); |
8320
06495654aee6
(svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138 <peter1138@openttd.org>
parents:
8284
diff
changeset
|
585 break; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
586 |
8729
ce8dc35932c3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium <rubidium@openttd.org>
parents:
8418
diff
changeset
|
587 case WWT_STICKYBOX: |
7962
0fcca1a5847f
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz <smatz@openttd.org>
parents:
7928
diff
changeset
|
588 assert(wi->data == 0); |
11999
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
589 DrawStickyBox(r, wi->colour, !!(this->flags4 & WF_STICKY)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
590 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
591 |
8729
ce8dc35932c3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium <rubidium@openttd.org>
parents:
8418
diff
changeset
|
592 case WWT_RESIZEBOX: |
7962
0fcca1a5847f
(svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz <smatz@openttd.org>
parents:
7928
diff
changeset
|
593 assert(wi->data == 0); |
11999
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
594 DrawResizeBox(r, wi->colour, wi->left < (this->width / 2), !!(this->flags4 & WF_SIZING)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
595 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
596 |
11999
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
597 case WWT_CLOSEBOX: |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
598 DrawCloseBox(r, wi->colour, wi->data); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
599 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
600 |
8729
ce8dc35932c3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium <rubidium@openttd.org>
parents:
8418
diff
changeset
|
601 case WWT_CAPTION: |
11999
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
602 DrawCaption(r, wi->colour, this->owner, wi->data); |
8320
06495654aee6
(svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138 <peter1138@openttd.org>
parents:
8284
diff
changeset
|
603 break; |
8335
5d87abba6871
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138 <peter1138@openttd.org>
parents:
8320
diff
changeset
|
604 |
11999
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
605 case WWT_DROPDOWN: |
b8e87660b9fc
(svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents:
11966
diff
changeset
|
606 DrawDropdown(r, wi->colour, clicked, wi->data); |
8335
5d87abba6871
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138 <peter1138@openttd.org>
parents:
8320
diff
changeset
|
607 break; |
5d87abba6871
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138 <peter1138@openttd.org>
parents:
8320
diff
changeset
|
608 } |
8320
06495654aee6
(svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138 <peter1138@openttd.org>
parents:
8284
diff
changeset
|
609 |
9273
72a6d2e60834
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium <rubidium@openttd.org>
parents:
9116
diff
changeset
|
610 if (this->IsWidgetDisabled(i)) { |
11080
02d314ea4f63
(svn r15423) -Codechange: split widget related types to their own header and add a bit of type strictness.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
611 GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, _colour_gradient[wi->colour & 0xF][2], FILLRECT_CHECKER); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
612 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
613 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
614 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
615 |
9273
72a6d2e60834
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium <rubidium@openttd.org>
parents:
9116
diff
changeset
|
616 if (this->flags4 & WF_WHITE_BORDER_MASK) { |
9770
9f72f4a2aee0
(svn r13907) -Codechange: Replace a number with Colours enum on DrawFrameRect usage
belugas <belugas@openttd.org>
parents:
9607
diff
changeset
|
617 DrawFrameRect(0, 0, this->width - 1, this->height - 1, COLOUR_WHITE, FR_BORDERONLY); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
618 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
619 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
620 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
621 |
11799
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
622 /** |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
623 * Evenly distribute the combined horizontal length of two consecutive widgets. |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
624 * @param w Window containing the widgets. |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
625 * @param a Left widget to resize. |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
626 * @param b Right widget to resize. |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
627 * @note Widgets are assumed to lie against each other. |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
628 */ |
5824
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
629 static void ResizeWidgets(Window *w, byte a, byte b) |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
630 { |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
631 int16 offset = w->widget[a].left; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
632 int16 length = w->widget[b].right - offset; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
633 |
8729
ce8dc35932c3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium <rubidium@openttd.org>
parents:
8418
diff
changeset
|
634 w->widget[a].right = (length / 2) + offset; |
5824
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
635 |
5822
3d41b8b9b76e
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni <bjarni@openttd.org>
parents:
5668
diff
changeset
|
636 w->widget[b].left = w->widget[a].right + 1; |
3d41b8b9b76e
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni <bjarni@openttd.org>
parents:
5668
diff
changeset
|
637 } |
3d41b8b9b76e
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni <bjarni@openttd.org>
parents:
5668
diff
changeset
|
638 |
11799
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
639 /** |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
640 * Evenly distribute the combined horizontal length of three consecutive widgets. |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
641 * @param w Window containing the widgets. |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
642 * @param a Left widget to resize. |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
643 * @param b Middle widget to resize. |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
644 * @param c Right widget to resize. |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
645 * @note Widgets are assumed to lie against each other. |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
646 */ |
5824
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
647 static void ResizeWidgets(Window *w, byte a, byte b, byte c) |
5822
3d41b8b9b76e
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni <bjarni@openttd.org>
parents:
5668
diff
changeset
|
648 { |
5824
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
649 int16 offset = w->widget[a].left; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
650 int16 length = w->widget[c].right - offset; |
5822
3d41b8b9b76e
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni <bjarni@openttd.org>
parents:
5668
diff
changeset
|
651 |
5824
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
652 w->widget[a].right = length / 3; |
5822
3d41b8b9b76e
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni <bjarni@openttd.org>
parents:
5668
diff
changeset
|
653 w->widget[b].right = w->widget[a].right * 2; |
3d41b8b9b76e
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni <bjarni@openttd.org>
parents:
5668
diff
changeset
|
654 |
5824
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
655 w->widget[a].right += offset; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
656 w->widget[b].right += offset; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
657 |
5822
3d41b8b9b76e
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni <bjarni@openttd.org>
parents:
5668
diff
changeset
|
658 /* Now the right side of the buttons are set. We will now set the left sides next to them */ |
3d41b8b9b76e
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni <bjarni@openttd.org>
parents:
5668
diff
changeset
|
659 w->widget[b].left = w->widget[a].right + 1; |
3d41b8b9b76e
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni <bjarni@openttd.org>
parents:
5668
diff
changeset
|
660 w->widget[c].left = w->widget[b].right + 1; |
3d41b8b9b76e
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni <bjarni@openttd.org>
parents:
5668
diff
changeset
|
661 } |
3d41b8b9b76e
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni <bjarni@openttd.org>
parents:
5668
diff
changeset
|
662 |
5824
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
663 /** Evenly distribute some widgets when resizing horizontally (often a button row) |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
664 * When only two arguments are given, the widgets are presumed to be on a line and only the ends are given |
6481
85a1a79387a2
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents:
6432
diff
changeset
|
665 * @param w Window to modify |
5824
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
666 * @param left The leftmost widget to resize |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
667 * @param right The rightmost widget to resize. Since right side of it is used, remember to set it to RESIZE_RIGHT |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
668 */ |
5822
3d41b8b9b76e
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni <bjarni@openttd.org>
parents:
5668
diff
changeset
|
669 void ResizeButtons(Window *w, byte left, byte right) |
3d41b8b9b76e
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni <bjarni@openttd.org>
parents:
5668
diff
changeset
|
670 { |
5824
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
671 int16 num_widgets = right - left + 1; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
672 |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
673 if (num_widgets < 2) NOT_REACHED(); |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
674 |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
675 switch (num_widgets) { |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
676 case 2: ResizeWidgets(w, left, right); break; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
677 case 3: ResizeWidgets(w, left, left + 1, right); break; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
678 default: { |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
679 /* Looks like we got more than 3 widgets to resize |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
680 * Now we will find the middle of the space desinated for the widgets |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
681 * and place half of the widgets on each side of it and call recursively. |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
682 * Eventually we will get down to blocks of 2-3 widgets and we got code to handle those cases */ |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
683 int16 offset = w->widget[left].left; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
684 int16 length = w->widget[right].right - offset; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
685 byte widget = ((num_widgets - 1)/ 2) + left; // rightmost widget of the left side |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
686 |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
687 /* Now we need to find the middle of the widgets. |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
688 * It will not always be the middle because if we got an uneven number of widgets, |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
689 * we will need it to be 2/5, 3/7 and so on |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
690 * To get this, we multiply with num_widgets/num_widgets. Since we calculate in int, we will get: |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
691 * |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
692 * num_widgets/2 (rounding down) |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
693 * --------------- |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
694 * num_widgets |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
695 * |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
696 * as multiplier to length. We just multiply before divide to that we stay in the int area though */ |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
697 int16 middle = ((length * num_widgets) / (2 * num_widgets)) + offset; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
698 |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
699 /* Set left and right on the widgets, that's next to our "middle" */ |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
700 w->widget[widget].right = middle; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
701 w->widget[widget + 1].left = w->widget[widget].right + 1; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
702 /* Now resize the left and right of the middle */ |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
703 ResizeButtons(w, left, widget); |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
704 ResizeButtons(w, widget + 1, right); |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
705 } |
5822
3d41b8b9b76e
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni <bjarni@openttd.org>
parents:
5668
diff
changeset
|
706 } |
3d41b8b9b76e
(svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni <bjarni@openttd.org>
parents:
5668
diff
changeset
|
707 } |
8349
cbb2e614bcfa
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138 <peter1138@openttd.org>
parents:
8335
diff
changeset
|
708 |
8857
a75a0c683fea
(svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents:
8737
diff
changeset
|
709 /** Resize a widget and shuffle other widgets around to fit. */ |
9834
efa04139a798
(svn r13977) -Codechange: Let ResizeWindowForWidget() handle hidden (zero height or zero width) widgets.
peter1138 <peter1138@openttd.org>
parents:
9779
diff
changeset
|
710 void ResizeWindowForWidget(Window *w, uint widget, int delta_x, int delta_y) |
8418
3a56a9f2f4c3
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138 <peter1138@openttd.org>
parents:
8411
diff
changeset
|
711 { |
3a56a9f2f4c3
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138 <peter1138@openttd.org>
parents:
8411
diff
changeset
|
712 int right = w->widget[widget].right; |
3a56a9f2f4c3
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138 <peter1138@openttd.org>
parents:
8411
diff
changeset
|
713 int bottom = w->widget[widget].bottom; |
3a56a9f2f4c3
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138 <peter1138@openttd.org>
parents:
8411
diff
changeset
|
714 |
3a56a9f2f4c3
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138 <peter1138@openttd.org>
parents:
8411
diff
changeset
|
715 for (uint i = 0; i < w->widget_count; i++) { |
9834
efa04139a798
(svn r13977) -Codechange: Let ResizeWindowForWidget() handle hidden (zero height or zero width) widgets.
peter1138 <peter1138@openttd.org>
parents:
9779
diff
changeset
|
716 if (w->widget[i].left >= right && i != widget) w->widget[i].left += delta_x; |
8418
3a56a9f2f4c3
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138 <peter1138@openttd.org>
parents:
8411
diff
changeset
|
717 if (w->widget[i].right >= right) w->widget[i].right += delta_x; |
9834
efa04139a798
(svn r13977) -Codechange: Let ResizeWindowForWidget() handle hidden (zero height or zero width) widgets.
peter1138 <peter1138@openttd.org>
parents:
9779
diff
changeset
|
718 if (w->widget[i].top >= bottom && i != widget) w->widget[i].top += delta_y; |
8418
3a56a9f2f4c3
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138 <peter1138@openttd.org>
parents:
8411
diff
changeset
|
719 if (w->widget[i].bottom >= bottom) w->widget[i].bottom += delta_y; |
3a56a9f2f4c3
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138 <peter1138@openttd.org>
parents:
8411
diff
changeset
|
720 } |
3a56a9f2f4c3
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138 <peter1138@openttd.org>
parents:
8411
diff
changeset
|
721 |
9834
efa04139a798
(svn r13977) -Codechange: Let ResizeWindowForWidget() handle hidden (zero height or zero width) widgets.
peter1138 <peter1138@openttd.org>
parents:
9779
diff
changeset
|
722 /* A hidden widget has bottom == top or right == left, we need to make it |
efa04139a798
(svn r13977) -Codechange: Let ResizeWindowForWidget() handle hidden (zero height or zero width) widgets.
peter1138 <peter1138@openttd.org>
parents:
9779
diff
changeset
|
723 * one less to fit in its new gap. */ |
efa04139a798
(svn r13977) -Codechange: Let ResizeWindowForWidget() handle hidden (zero height or zero width) widgets.
peter1138 <peter1138@openttd.org>
parents:
9779
diff
changeset
|
724 if (right == w->widget[widget].left) w->widget[widget].right--; |
efa04139a798
(svn r13977) -Codechange: Let ResizeWindowForWidget() handle hidden (zero height or zero width) widgets.
peter1138 <peter1138@openttd.org>
parents:
9779
diff
changeset
|
725 if (bottom == w->widget[widget].top) w->widget[widget].bottom--; |
efa04139a798
(svn r13977) -Codechange: Let ResizeWindowForWidget() handle hidden (zero height or zero width) widgets.
peter1138 <peter1138@openttd.org>
parents:
9779
diff
changeset
|
726 |
9843
afd919aa07c3
(svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138 <peter1138@openttd.org>
parents:
9834
diff
changeset
|
727 if (w->widget[widget].left > w->widget[widget].right) w->widget[widget].right = w->widget[widget].left; |
afd919aa07c3
(svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138 <peter1138@openttd.org>
parents:
9834
diff
changeset
|
728 if (w->widget[widget].top > w->widget[widget].bottom) w->widget[widget].bottom = w->widget[widget].top; |
afd919aa07c3
(svn r13987) -Codechange: Resize small map legend dynamically on window resize and when switching small map types, so that the legend is taller only on the industry type and only when the legend will not fit in the available space.
peter1138 <peter1138@openttd.org>
parents:
9834
diff
changeset
|
729 |
8418
3a56a9f2f4c3
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138 <peter1138@openttd.org>
parents:
8411
diff
changeset
|
730 w->width += delta_x; |
3a56a9f2f4c3
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138 <peter1138@openttd.org>
parents:
8411
diff
changeset
|
731 w->height += delta_y; |
3a56a9f2f4c3
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138 <peter1138@openttd.org>
parents:
8411
diff
changeset
|
732 w->resize.width += delta_x; |
3a56a9f2f4c3
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138 <peter1138@openttd.org>
parents:
8411
diff
changeset
|
733 w->resize.height += delta_y; |
3a56a9f2f4c3
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138 <peter1138@openttd.org>
parents:
8411
diff
changeset
|
734 } |
3a56a9f2f4c3
(svn r11988) -Codechange: Add a generic way of changing a widget's size and adjust the widgets around it to suit.
peter1138 <peter1138@openttd.org>
parents:
8411
diff
changeset
|
735 |
10238
12805d675e85
(svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium <rubidium@openttd.org>
parents:
10208
diff
changeset
|
736 /** |
12805d675e85
(svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium <rubidium@openttd.org>
parents:
10208
diff
changeset
|
737 * Draw a sort button's up or down arrow symbol. |
8349
cbb2e614bcfa
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138 <peter1138@openttd.org>
parents:
8335
diff
changeset
|
738 * @param widget Sort button widget |
cbb2e614bcfa
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138 <peter1138@openttd.org>
parents:
8335
diff
changeset
|
739 * @param state State of sort button |
cbb2e614bcfa
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138 <peter1138@openttd.org>
parents:
8335
diff
changeset
|
740 */ |
9273
72a6d2e60834
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium <rubidium@openttd.org>
parents:
9116
diff
changeset
|
741 void Window::DrawSortButtonState(int widget, SortButtonState state) const |
8349
cbb2e614bcfa
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138 <peter1138@openttd.org>
parents:
8335
diff
changeset
|
742 { |
cbb2e614bcfa
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138 <peter1138@openttd.org>
parents:
8335
diff
changeset
|
743 if (state == SBS_OFF) return; |
cbb2e614bcfa
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138 <peter1138@openttd.org>
parents:
8335
diff
changeset
|
744 |
9273
72a6d2e60834
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium <rubidium@openttd.org>
parents:
9116
diff
changeset
|
745 int offset = this->IsWidgetLowered(widget) ? 1 : 0; |
11481
6f95c792064d
(svn r15842) -Codechange: make DrawSortButtonState RTL.
rubidium <rubidium@openttd.org>
parents:
11472
diff
changeset
|
746 int base = offset + (_dynlang.text_dir == TD_LTR ? this->widget[widget].right - 11 : this->widget[widget].left); |
6f95c792064d
(svn r15842) -Codechange: make DrawSortButtonState RTL.
rubidium <rubidium@openttd.org>
parents:
11472
diff
changeset
|
747 DrawString(base, base + 11, this->widget[widget].top + 1 + offset, state == SBS_DOWN ? DOWNARROW : UPARROW, TC_BLACK, SA_CENTER); |
8349
cbb2e614bcfa
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138 <peter1138@openttd.org>
parents:
8335
diff
changeset
|
748 } |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
749 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
750 |
11799
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
751 /** |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
752 * @defgroup NestedWidgets Hierarchical widgets. |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
753 * Hierarchical widgets, also known as nested widgets, are widgets stored in a tree. At the leafs of the tree are (mostly) the 'real' widgets |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
754 * visible to the user. At higher levels, widgets get organized in container widgets, until all widgets of the window are merged. |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
755 * |
11964
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
756 * \section nestedwidgetkinds Hierarchical widget kinds |
11799
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
757 * A leaf widget is one of |
11964
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
758 * <ul> |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
759 * <li> #NWidgetLeaf for widgets visible for the user, or |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
760 * <li> #NWidgetSpacer for creating (flexible) empty space between widgets. |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
761 * </ul> |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
762 * The purpose of a leaf widget is to provide interaction with the user by displaying settings, and/or allowing changing the settings. |
11799
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
763 * |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
764 * A container widget is one of |
11964
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
765 * <ul> |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
766 * <li> #NWidgetHorizontal for organizing child widgets in a (horizontal) row. The row switches order depending on the language setting (thus supporting |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
767 * right-to-left languages), |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
768 * <li> #NWidgetHorizontalLTR for organizing child widgets in a (horizontal) row, always in the same order. All childs below this container will also |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
769 * never swap order. |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
770 * <li> #NWidgetVertical for organizing child widgets underneath each other. |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
771 * <li> #NWidgetBackground for adding a background behind its child widget. |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
772 * <li> #NWidgetStacked for stacking child widgets on top of each other. |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
773 * </ul> |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
774 * The purpose of a container widget is to structure its leafs and sub-containers to allow proper resizing. |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
775 * |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
776 * \section nestedwidgetscomputations Hierarchical widget computations |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
777 * The first 'computation' is the creation of the nested widgets tree by calling the constructors of the widgets listed above and calling \c Add() for every child, |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
778 * or by means of specifying the tree as a collection of nested widgets parts and instantiating the tree from the array. |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
779 * |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
780 * After the creation step, |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
781 * - The leafs have their own minimal size (\e min_x, \e min_y), filling (\e fill_x, \e fill_y), and resize steps (\e resize_x, \e resize_y). |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
782 * - Containers only know what their children are, \e fill_x, \e fill_y, \e resize_x, and \e resize_y are not initialized. |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
783 * |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
784 * Computations in the nested widgets take place as follows: |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
785 * <ol> |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
786 * <li> A bottom-up sweep by recursively calling NWidgetBase::SetupSmallestSize() to initialize the smallest size (\e smallest_x, \e smallest_y) and |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
787 * to propagate filling and resize steps upwards to the root of the tree. |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
788 * <li> A top-down sweep by recursively calling NWidgetBase::AssignSizePosition() to make the smallest sizes consistent over the entire tree, and to assign |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
789 * the top-left (\e pos_x, \e pos_y) position of each widget in the tree. This step uses \e fill_x and \e fill_y at each node in the tree to decide how to |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
790 * fill each widget towards consistent sizes. |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
791 * For generating a widget array, resize step sizes are made consistent. |
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
792 * </ol> |
11799
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
793 * |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
794 * @see NestedWidgetParts |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
795 */ |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
796 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
797 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
798 * Base class constructor. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
799 * @param tp Nested widget type. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
800 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
801 NWidgetBase::NWidgetBase(WidgetType tp) : ZeroedMemoryAllocator() |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
802 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
803 this->type = tp; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
804 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
805 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
806 /* ~NWidgetContainer() takes care of #next and #prev data members. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
807 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
808 /** |
11963
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
809 * @fn int NWidgetBase::SetupSmallestSize() |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
810 * @brief Compute smallest size needed by the widget. |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
811 * |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
812 * The smallest size of a widget is the smallest size that a widget needs to |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
813 * display itself properly. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
814 * In addition, filling and resizing of the widget are computed. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
815 * @return Biggest index in the widget array of all child widgets. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
816 * |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
817 * @note After the computation, the results can be queried by accessing the data members of the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
818 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
819 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
820 /** |
11963
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
821 * @fn void NWidgetBase::AssignSizePosition(uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl) |
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
822 * @brief Assign size and position to the widget. |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
823 * @param x Horizontal offset of the widget relative to the left edge of the window. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
824 * @param y Vertical offset of the widget relative to the top edge of the window. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
825 * @param given_width Width allocated to the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
826 * @param given_height Height allocated to the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
827 * @param allow_resize_x Horizontal resizing is allowed. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
828 * @param allow_resize_y Vertical resizing is allowed. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
829 * @param rtl Adapt for right-to-left languages (position contents of horizontal containers backwards). |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
830 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
831 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
832 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
833 * @fn void NWidgetBase::StoreWidgets(Widget *widgets, int length, bool left_moving, bool top_moving, bool rtl) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
834 * @brief Store all child widgets with a valid index into the widget array. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
835 * @param widgets Widget array to store the nested widgets in. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
836 * @param length Length of the array. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
837 * @param left_moving Left edge of the widget may move due to resizing (right edge if \a rtl). |
11964
9bbab6c40225
(svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents:
11963
diff
changeset
|
838 * @param top_moving Top edge of the widget may move due to resizing. |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
839 * @param rtl Adapt for right-to-left languages (position contents of horizontal containers backwards). |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
840 * |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
841 * @note When storing a nested widget, the function should check first that the type in the \a widgets array is #WWT_LAST. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
842 * This is used to detect double widget allocations as well as holes in the widget array. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
843 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
844 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
845 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
846 * Constructor for resizable nested widgets. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
847 * @param tp Nested widget type. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
848 * @param fill_x Allow horizontal filling from initial size. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
849 * @param fill_y Allow vertical filling from initial size. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
850 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
851 NWidgetResizeBase::NWidgetResizeBase(WidgetType tp, bool fill_x, bool fill_y) : NWidgetBase(tp) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
852 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
853 this->fill_x = fill_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
854 this->fill_y = fill_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
855 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
856 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
857 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
858 * Set minimal size of the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
859 * @param min_x Horizontal minimal size of the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
860 * @param min_y Vertical minimal size of the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
861 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
862 void NWidgetResizeBase::SetMinimalSize(uint min_x, uint min_y) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
863 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
864 this->min_x = min_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
865 this->min_y = min_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
866 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
867 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
868 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
869 * Set the filling of the widget from initial size. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
870 * @param fill_x Allow horizontal filling from initial size. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
871 * @param fill_y Allow vertical filling from initial size. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
872 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
873 void NWidgetResizeBase::SetFill(bool fill_x, bool fill_y) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
874 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
875 this->fill_x = fill_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
876 this->fill_y = fill_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
877 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
878 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
879 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
880 * Set resize step of the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
881 * @param resize_x Resize step in horizontal direction, value \c 0 means no resize, otherwise the step size in pixels. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
882 * @param resize_y Resize step in vertical direction, value \c 0 means no resize, otherwise the step size in pixels. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
883 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
884 void NWidgetResizeBase::SetResize(uint resize_x, uint resize_y) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
885 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
886 this->resize_x = resize_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
887 this->resize_y = resize_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
888 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
889 |
11963
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
890 void NWidgetResizeBase::AssignSizePosition(uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl) |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
891 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
892 this->pos_x = x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
893 this->pos_y = y; |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
894 this->smallest_x = given_width; |
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
895 this->smallest_y = given_height; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
896 if (!allow_resize_x) this->resize_x = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
897 if (!allow_resize_y) this->resize_y = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
898 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
899 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
900 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
901 * Initialization of a 'real' widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
902 * @param tp Type of the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
903 * @param colour Colour of the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
904 * @param fill_x Default horizontal filling. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
905 * @param fill_y Default vertical filling. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
906 * @param widget_data Data component of the widget. @see Widget::data |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
907 * @param tool_tip Tool tip of the widget. @see Widget::tootips |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
908 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
909 NWidgetCore::NWidgetCore(WidgetType tp, Colours colour, bool fill_x, bool fill_y, uint16 widget_data, StringID tool_tip) : NWidgetResizeBase(tp, fill_x, fill_y) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
910 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
911 this->colour = colour; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
912 this->index = -1; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
913 this->widget_data = widget_data; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
914 this->tool_tip = tool_tip; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
915 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
916 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
917 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
918 * Set index of the nested widget in the widget array. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
919 * @param index Index to use. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
920 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
921 void NWidgetCore::SetIndex(int index) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
922 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
923 assert(index >= 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
924 this->index = index; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
925 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
926 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
927 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
928 * Set data and tool tip of the nested widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
929 * @param widget_data Data to use. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
930 * @param tool_tip Tool tip string to use. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
931 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
932 void NWidgetCore::SetDataTip(uint16 widget_data, StringID tool_tip) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
933 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
934 this->widget_data = widget_data; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
935 this->tool_tip = tool_tip; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
936 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
937 |
11963
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
938 int NWidgetCore::SetupSmallestSize() |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
939 { |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
940 this->smallest_x = this->min_x; |
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
941 this->smallest_y = this->min_y; |
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
942 /* All other data is already at the right place. */ |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
943 return this->index; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
944 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
945 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
946 void NWidgetCore::StoreWidgets(Widget *widgets, int length, bool left_moving, bool top_moving, bool rtl) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
947 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
948 if (this->index < 0) return; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
949 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
950 assert(this->index < length); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
951 Widget *w = widgets + this->index; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
952 assert(w->type == WWT_LAST); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
953 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
954 DisplayFlags flags = RESIZE_NONE; // resize flags. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
955 /* Compute vertical resizing. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
956 if (top_moving) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
957 flags |= RESIZE_TB; // Only 1 widget can resize in the widget array. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
958 } else if(this->resize_y > 0) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
959 flags |= RESIZE_BOTTOM; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
960 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
961 /* Compute horizontal resizing. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
962 if (left_moving) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
963 flags |= RESIZE_LR; // Only 1 widget can resize in the widget array. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
964 } else if (this->resize_x > 0) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
965 flags |= RESIZE_RIGHT; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
966 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
967 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
968 /* Copy nested widget data into its widget array entry. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
969 w->type = this->type; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
970 w->display_flags = flags; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
971 w->colour = this->colour; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
972 w->left = this->pos_x; |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
973 w->right = this->pos_x + this->smallest_x - 1; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
974 w->top = this->pos_y; |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
975 w->bottom = this->pos_y + this->smallest_y - 1; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
976 w->data = this->widget_data; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
977 w->tooltips = this->tool_tip; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
978 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
979 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
980 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
981 * Constructor container baseclass. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
982 * @param tp Type of the container. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
983 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
984 NWidgetContainer::NWidgetContainer(WidgetType tp) : NWidgetBase(tp) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
985 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
986 this->head = NULL; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
987 this->tail = NULL; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
988 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
989 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
990 NWidgetContainer::~NWidgetContainer() |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
991 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
992 while (this->head != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
993 NWidgetBase *wid = this->head->next; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
994 delete this->head; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
995 this->head = wid; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
996 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
997 this->tail = NULL; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
998 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
999 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1000 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1001 * Append widget \a wid to container. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1002 * @param wid Widget to append. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1003 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1004 void NWidgetContainer::Add(NWidgetBase *wid) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1005 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1006 assert(wid->next == NULL && wid->prev == NULL); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1007 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1008 if (this->head == NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1009 this->head = wid; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1010 this->tail = wid; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1011 } else { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1012 assert(this->tail != NULL); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1013 assert(this->tail->next == NULL); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1014 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1015 this->tail->next = wid; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1016 wid->prev = this->tail; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1017 this->tail = wid; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1018 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1019 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1020 |
11528
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1021 /** |
11966
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1022 * Return the biggest possible size of a nested widget. |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1023 * @param base Base size of the widget. |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1024 * @param max_space Available space for the widget. |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1025 * @param step Stepsize of the widget. |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1026 * @return Biggest possible size of the widget, assuming that \a base may only be incremented by \a step size steps. |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1027 */ |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1028 static inline uint ComputeMaxSize(uint base, uint max_space, uint step) |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1029 { |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1030 if (base >= max_space || step == 0) return base; |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1031 if (step == 1) return max_space; |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1032 int increment = max_space - base; |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1033 increment -= increment % step; |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1034 return base + increment; |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1035 } |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1036 |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1037 /** |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1038 * Compute the offset of a widget due to not entirely using the available space. |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1039 * @param space Space used by the widget. |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1040 * @param max_space Available space for the widget. |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1041 * @return Offset for centering widget. |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1042 */ |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1043 static inline uint ComputeOffset(uint space, uint max_space) |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1044 { |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1045 if (space >= max_space) return 0; |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1046 return (max_space - space) / 2; |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1047 } |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1048 |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1049 |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1050 /** |
11800
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1051 * Widgets stacked on top of each other. |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1052 * @param tp Kind of stacking, must be either #NWID_SELECTION or #NWID_LAYERED. |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1053 */ |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1054 NWidgetStacked::NWidgetStacked(WidgetType tp) : NWidgetContainer(tp) |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1055 { |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1056 } |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1057 |
11963
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
1058 int NWidgetStacked::SetupSmallestSize() |
11800
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1059 { |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1060 /* First sweep, recurse down and compute minimal size and filling. */ |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1061 int biggest_index = -1; |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1062 this->smallest_x = 0; |
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1063 this->smallest_y = 0; |
11800
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1064 this->fill_x = (this->head != NULL); |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1065 this->fill_y = (this->head != NULL); |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1066 this->resize_x = (this->head != NULL) ? 1 : 0; |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1067 this->resize_y = (this->head != NULL) ? 1 : 0; |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1068 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) { |
11963
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
1069 int idx = child_wid->SetupSmallestSize(); |
11800
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1070 biggest_index = max(biggest_index, idx); |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1071 |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1072 this->smallest_x = max(this->smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right); |
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1073 this->smallest_y = max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom); |
11800
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1074 this->fill_x &= child_wid->fill_x; |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1075 this->fill_y &= child_wid->fill_y; |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1076 this->resize_x = LeastCommonMultiple(this->resize_x, child_wid->resize_x); |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1077 this->resize_y = LeastCommonMultiple(this->resize_y, child_wid->resize_y); |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1078 } |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1079 return biggest_index; |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1080 } |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1081 |
11963
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
1082 void NWidgetStacked::AssignSizePosition(uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl) |
11800
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1083 { |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1084 assert(given_width >= this->smallest_x && given_height >= this->smallest_y); |
11800
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1085 |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1086 this->pos_x = x; |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1087 this->pos_y = y; |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1088 this->smallest_x = given_width; |
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1089 this->smallest_y = given_height; |
11800
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1090 if (!allow_resize_x) this->resize_x = 0; |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1091 if (!allow_resize_y) this->resize_y = 0; |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1092 |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1093 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) { |
11966
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1094 uint hor_step = child_wid->GetHorizontalStepSize(); |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1095 uint child_width = ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding_left - child_wid->padding_right, hor_step); |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1096 uint child_pos_x = (rtl ? child_wid->padding_right : child_wid->padding_left) + ComputeOffset(child_width, given_width - child_wid->padding_left - child_wid->padding_right); |
11800
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1097 |
11966
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1098 uint vert_step = child_wid->GetVerticalStepSize(); |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1099 uint child_height = ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding_top - child_wid->padding_bottom, vert_step); |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1100 uint child_pos_y = child_wid->padding_top + ComputeOffset(child_height, given_height - child_wid->padding_top - child_wid->padding_bottom); |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1101 |
11963
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
1102 child_wid->AssignSizePosition(x + child_pos_x, y + child_pos_y, child_width, child_height, (this->resize_x > 0), (this->resize_y > 0), rtl); |
11800
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1103 } |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1104 } |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1105 |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1106 void NWidgetStacked::StoreWidgets(Widget *widgets, int length, bool left_moving, bool top_moving, bool rtl) |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1107 { |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1108 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) { |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1109 child_wid->StoreWidgets(widgets, length, left_moving, top_moving, rtl); |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1110 } |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1111 } |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1112 |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1113 NWidgetPIPContainer::NWidgetPIPContainer(WidgetType tp) : NWidgetContainer(tp) |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1114 { |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1115 } |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1116 |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1117 /** |
11528
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1118 * Set additional pre/inter/post space for the container. |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1119 * |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1120 * @param pip_pre Additional space in front of the first child widget (above |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1121 * for the vertical container, at the left for the horizontal container). |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1122 * @param pip_inter Additional space between two child widgets. |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1123 * @param pip_post Additional space after the last child widget (below for the |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1124 * vertical container, at the right for the horizontal container). |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1125 */ |
11800
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1126 void NWidgetPIPContainer::SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post) |
11528
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1127 { |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1128 this->pip_pre = pip_pre; |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1129 this->pip_inter = pip_inter; |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1130 this->pip_post = pip_post; |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1131 } |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1132 |
11799
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
1133 /** Horizontal container widget. */ |
11800
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1134 NWidgetHorizontal::NWidgetHorizontal() : NWidgetPIPContainer(NWID_HORIZONTAL) |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1135 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1136 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1137 |
11963
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
1138 int NWidgetHorizontal::SetupSmallestSize() |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1139 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1140 int biggest_index = -1; |
11965
a34cf1819c8d
(svn r16371) -Codechange (r16367): Properly align comments.
alberth <alberth@openttd.org>
parents:
11964
diff
changeset
|
1141 this->smallest_x = 0; // Sum of minimal size of all childs. |
a34cf1819c8d
(svn r16371) -Codechange (r16367): Properly align comments.
alberth <alberth@openttd.org>
parents:
11964
diff
changeset
|
1142 this->smallest_y = 0; // Biggest child. |
a34cf1819c8d
(svn r16371) -Codechange (r16367): Properly align comments.
alberth <alberth@openttd.org>
parents:
11964
diff
changeset
|
1143 this->fill_x = false; // true if at least one child allows fill_x. |
a34cf1819c8d
(svn r16371) -Codechange (r16367): Properly align comments.
alberth <alberth@openttd.org>
parents:
11964
diff
changeset
|
1144 this->fill_y = true; // true if all childs allow fill_y. |
a34cf1819c8d
(svn r16371) -Codechange (r16367): Properly align comments.
alberth <alberth@openttd.org>
parents:
11964
diff
changeset
|
1145 this->resize_x = 0; // smallest non-zero child widget resize step. |
a34cf1819c8d
(svn r16371) -Codechange (r16367): Properly align comments.
alberth <alberth@openttd.org>
parents:
11964
diff
changeset
|
1146 this->resize_y = 1; // smallest common child resize step |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1147 |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1148 if (this->head != NULL) this->head->padding_left += this->pip_pre; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1149 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) { |
11963
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
1150 int idx = child_wid->SetupSmallestSize(); |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1151 biggest_index = max(biggest_index, idx); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1152 |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1153 if (child_wid->next != NULL) { |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1154 child_wid->padding_right += this->pip_inter; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1155 } else { |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1156 child_wid->padding_right += this->pip_post; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1157 } |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1158 |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1159 this->smallest_x += child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right; |
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1160 this->smallest_y = max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom); |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1161 this->fill_x |= child_wid->fill_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1162 this->fill_y &= child_wid->fill_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1163 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1164 if (child_wid->resize_x > 0) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1165 if (this->resize_x == 0 || this->resize_x > child_wid->resize_x) this->resize_x = child_wid->resize_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1166 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1167 this->resize_y = LeastCommonMultiple(this->resize_y, child_wid->resize_y); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1168 } |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1169 /* We need to zero the PIP settings so we can re-initialize the tree. */ |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1170 this->pip_pre = this->pip_inter = this->pip_post = 0; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1171 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1172 return biggest_index; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1173 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1174 |
11963
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
1175 void NWidgetHorizontal::AssignSizePosition(uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl) |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1176 { |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1177 assert(given_width >= this->smallest_x && given_height >= this->smallest_y); |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1178 |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1179 uint additional_length = given_width - this->smallest_x; // Additional width given to us. |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1180 this->pos_x = x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1181 this->pos_y = y; |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1182 this->smallest_x = given_width; |
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1183 this->smallest_y = given_height; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1184 if (!allow_resize_x) this->resize_x = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1185 if (!allow_resize_y) this->resize_y = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1186 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1187 /* Count number of childs that would like a piece of the pie. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1188 int num_changing_childs = 0; // Number of childs that can change size. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1189 NWidgetBase *child_wid; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1190 for (child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) { |
11966
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1191 uint hor_step = child_wid->GetHorizontalStepSize(); |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1192 if (hor_step > 0) num_changing_childs++; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1193 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1194 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1195 /* Fill and position the child widgets. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1196 uint position = 0; // Place to put next child relative to origin of the container. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1197 allow_resize_x = (this->resize_x > 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1198 child_wid = rtl ? this->tail : this->head; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1199 while (child_wid != NULL) { |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1200 assert(given_height >= child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom); |
11966
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1201 |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1202 uint vert_step = child_wid->GetVerticalStepSize(); |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1203 uint child_height = ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding_top - child_wid->padding_bottom, vert_step); |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1204 uint child_pos_y = child_wid->padding_top + ComputeOffset(child_height, given_height - child_wid->padding_top - child_wid->padding_bottom); |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1205 |
11966
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1206 /* Decide about horizontal sizing of the child. */ |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1207 uint hor_step = child_wid->GetHorizontalStepSize(); |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1208 uint child_width = child_wid->smallest_x; |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1209 if (hor_step > 0 && num_changing_childs > 0) { |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1210 /* Hand out a piece of the pie while compensating for rounding errors. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1211 uint increment = additional_length / num_changing_childs; |
11966
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1212 if (hor_step > 1) increment -= increment % hor_step; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1213 additional_length -= increment; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1214 num_changing_childs--; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1215 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1216 child_width += increment; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1217 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1218 |
11963
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
1219 child_wid->AssignSizePosition(x + position + (rtl ? child_wid->padding_right : child_wid->padding_left), y + child_pos_y, child_width, child_height, allow_resize_x, (this->resize_y > 0), rtl); |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1220 position += child_width + child_wid->padding_right + child_wid->padding_left; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1221 if (child_wid->resize_x > 0) allow_resize_x = false; // Widget array allows only one child resizing |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1222 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1223 child_wid = rtl ? child_wid->prev : child_wid->next; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1224 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1225 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1226 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1227 void NWidgetHorizontal::StoreWidgets(Widget *widgets, int length, bool left_moving, bool top_moving, bool rtl) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1228 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1229 NWidgetBase *child_wid = rtl ? this->tail : this->head; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1230 while (child_wid != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1231 child_wid->StoreWidgets(widgets, length, left_moving, top_moving, rtl); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1232 left_moving |= (child_wid->resize_x > 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1233 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1234 child_wid = rtl ? child_wid->prev : child_wid->next; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1235 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1236 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1237 |
11799
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
1238 /** Horizontal left-to-right container widget. */ |
11500
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
1239 NWidgetHorizontalLTR::NWidgetHorizontalLTR() : NWidgetHorizontal() |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
1240 { |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
1241 this->type = NWID_HORIZONTAL_LTR; |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
1242 } |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
1243 |
11963
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
1244 void NWidgetHorizontalLTR::AssignSizePosition(uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl) |
11500
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
1245 { |
11963
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
1246 NWidgetHorizontal::AssignSizePosition(x, y, given_width, given_height, allow_resize_x, allow_resize_y, false); |
11500
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
1247 } |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
1248 |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
1249 void NWidgetHorizontalLTR::StoreWidgets(Widget *widgets, int length, bool left_moving, bool top_moving, bool rtl) |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
1250 { |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
1251 NWidgetHorizontal::StoreWidgets(widgets, length, left_moving, top_moving, false); |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
1252 } |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
1253 |
11799
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
1254 /** Vertical container widget. */ |
11800
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1255 NWidgetVertical::NWidgetVertical() : NWidgetPIPContainer(NWID_VERTICAL) |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1256 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1257 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1258 |
11963
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
1259 int NWidgetVertical::SetupSmallestSize() |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1260 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1261 int biggest_index = -1; |
11965
a34cf1819c8d
(svn r16371) -Codechange (r16367): Properly align comments.
alberth <alberth@openttd.org>
parents:
11964
diff
changeset
|
1262 this->smallest_x = 0; // Biggest child. |
a34cf1819c8d
(svn r16371) -Codechange (r16367): Properly align comments.
alberth <alberth@openttd.org>
parents:
11964
diff
changeset
|
1263 this->smallest_y = 0; // Sum of minimal size of all childs. |
a34cf1819c8d
(svn r16371) -Codechange (r16367): Properly align comments.
alberth <alberth@openttd.org>
parents:
11964
diff
changeset
|
1264 this->fill_x = true; // true if all childs allow fill_x. |
a34cf1819c8d
(svn r16371) -Codechange (r16367): Properly align comments.
alberth <alberth@openttd.org>
parents:
11964
diff
changeset
|
1265 this->fill_y = false; // true if at least one child allows fill_y. |
a34cf1819c8d
(svn r16371) -Codechange (r16367): Properly align comments.
alberth <alberth@openttd.org>
parents:
11964
diff
changeset
|
1266 this->resize_x = 1; // smallest common child resize step |
a34cf1819c8d
(svn r16371) -Codechange (r16367): Properly align comments.
alberth <alberth@openttd.org>
parents:
11964
diff
changeset
|
1267 this->resize_y = 0; // smallest non-zero child widget resize step. |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1268 |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1269 if (this->head != NULL) this->head->padding_top += this->pip_pre; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1270 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) { |
11963
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
1271 int idx = child_wid->SetupSmallestSize(); |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1272 biggest_index = max(biggest_index, idx); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1273 |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1274 if (child_wid->next != NULL) { |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1275 child_wid->padding_bottom += this->pip_inter; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1276 } else { |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1277 child_wid->padding_bottom += this->pip_post; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1278 } |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1279 |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1280 this->smallest_y += child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom; |
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1281 this->smallest_x = max(this->smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right); |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1282 this->fill_y |= child_wid->fill_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1283 this->fill_x &= child_wid->fill_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1284 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1285 if (child_wid->resize_y > 0) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1286 if (this->resize_y == 0 || this->resize_y > child_wid->resize_y) this->resize_y = child_wid->resize_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1287 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1288 this->resize_x = LeastCommonMultiple(this->resize_x, child_wid->resize_x); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1289 } |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1290 /* We need to zero the PIP settings so we can re-initialize the tree. */ |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1291 this->pip_pre = this->pip_inter = this->pip_post = 0; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1292 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1293 return biggest_index; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1294 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1295 |
11963
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
1296 void NWidgetVertical::AssignSizePosition(uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl) |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1297 { |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1298 assert(given_width >= this->smallest_x && given_height >= this->smallest_y); |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1299 |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1300 int additional_length = given_height - this->smallest_y; // Additional height given to us. |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1301 this->pos_x = x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1302 this->pos_y = y; |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1303 this->smallest_x = given_width; |
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1304 this->smallest_y = given_height; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1305 if (!allow_resize_x) this->resize_x = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1306 if (!allow_resize_y) this->resize_y = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1307 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1308 /* count number of childs that would like a piece of the pie. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1309 int num_changing_childs = 0; // Number of childs that can change size. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1310 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) { |
11966
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1311 uint vert_step = child_wid->GetVerticalStepSize(); |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1312 if (vert_step > 0) num_changing_childs++; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1313 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1314 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1315 /* Fill and position the child widgets. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1316 uint position = 0; // Place to put next child relative to origin of the container. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1317 allow_resize_y = (this->resize_y > 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1318 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) { |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1319 assert(given_width >= child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right); |
11966
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1320 |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1321 uint hor_step = child_wid->GetHorizontalStepSize(); |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1322 uint child_width = ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding_left - child_wid->padding_right, hor_step); |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1323 uint child_pos_x = (rtl ? child_wid->padding_right : child_wid->padding_left) + ComputeOffset(child_width, given_width - child_wid->padding_left - child_wid->padding_right); |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1324 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1325 /* Decide about vertical filling of the child. */ |
11966
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1326 uint vert_step = child_wid->GetVerticalStepSize(); |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1327 uint child_height = child_wid->smallest_y; |
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1328 if (vert_step > 0 && num_changing_childs > 0) { |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1329 /* Hand out a piece of the pie while compensating for rounding errors. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1330 uint increment = additional_length / num_changing_childs; |
11966
de771cbe234d
(svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents:
11965
diff
changeset
|
1331 if (vert_step > 1) increment -= increment % vert_step; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1332 additional_length -= increment; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1333 num_changing_childs--; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1334 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1335 child_height += increment; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1336 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1337 |
11963
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
1338 child_wid->AssignSizePosition(x + child_pos_x, y + position + child_wid->padding_top, child_width, child_height, (this->resize_x > 0), allow_resize_y, rtl); |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1339 position += child_height + child_wid->padding_top + child_wid->padding_bottom; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1340 if (child_wid->resize_y > 0) allow_resize_y = false; // Widget array allows only one child resizing |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1341 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1342 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1343 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1344 void NWidgetVertical::StoreWidgets(Widget *widgets, int length, bool left_moving, bool top_moving, bool rtl) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1345 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1346 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1347 child_wid->StoreWidgets(widgets, length, left_moving, top_moving, rtl); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1348 top_moving |= (child_wid->resize_y > 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1349 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1350 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1351 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1352 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1353 * Generic spacer widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1354 * @param length Horizontal size of the spacer widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1355 * @param height Vertical size of the spacer widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1356 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1357 NWidgetSpacer::NWidgetSpacer(int length, int height) : NWidgetResizeBase(NWID_SPACER, false, false) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1358 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1359 this->SetMinimalSize(length, height); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1360 this->SetResize(0, 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1361 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1362 |
11963
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
1363 int NWidgetSpacer::SetupSmallestSize() |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1364 { |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1365 this->smallest_x = this->min_x; |
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1366 this->smallest_y = this->min_y; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1367 return -1; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1368 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1369 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1370 void NWidgetSpacer::StoreWidgets(Widget *widgets, int length, bool left_moving, bool top_moving, bool rtl) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1371 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1372 /* Spacer widgets are never stored in the widget array. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1373 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1374 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1375 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1376 * Constructor parent nested widgets. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1377 * @param tp Type of parent widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1378 * @param colour Colour of the parent widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1379 * @param index Index in the widget array used by the window system. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1380 * @param child Child container widget (if supplied). If not supplied, a |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1381 * vertical container will be inserted while adding the first |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1382 * child widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1383 */ |
11800
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1384 NWidgetBackground::NWidgetBackground(WidgetType tp, Colours colour, int index, NWidgetPIPContainer *child) : NWidgetCore(tp, colour, true, true, 0x0, STR_NULL) |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1385 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1386 this->SetIndex(index); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1387 assert(tp == WWT_PANEL || tp == WWT_INSET || tp == WWT_FRAME); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1388 assert(index >= 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1389 this->child = child; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1390 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1391 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1392 NWidgetBackground::~NWidgetBackground() |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1393 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1394 if (this->child != NULL) delete this->child; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1395 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1396 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1397 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1398 * Add a child to the parent. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1399 * @param nwid Nested widget to add to the background widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1400 * |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1401 * Unless a child container has been given in the constructor, a parent behaves as a vertical container. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1402 * You can add several childs to it, and they are put underneath each other. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1403 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1404 void NWidgetBackground::Add(NWidgetBase *nwid) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1405 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1406 if (this->child == NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1407 this->child = new NWidgetVertical(); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1408 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1409 this->child->Add(nwid); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1410 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1411 |
11528
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1412 /** |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1413 * Set additional pre/inter/post space for the background widget. |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1414 * |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1415 * @param pip_pre Additional space in front of the first child widget (above |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1416 * for the vertical container, at the left for the horizontal container). |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1417 * @param pip_inter Additional space between two child widgets. |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1418 * @param pip_post Additional space after the last child widget (below for the |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1419 * vertical container, at the right for the horizontal container). |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1420 * @note Using this function implies that the widget has (or will have) child widgets. |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1421 */ |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1422 void NWidgetBackground::SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post) |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1423 { |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1424 if (this->child == NULL) { |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1425 this->child = new NWidgetVertical(); |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1426 } |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1427 this->child->SetPIP(pip_pre, pip_inter, pip_post); |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1428 } |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1429 |
11963
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
1430 int NWidgetBackground::SetupSmallestSize() |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1431 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1432 int biggest_index = this->index; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1433 if (this->child != NULL) { |
11963
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
1434 int idx = this->child->SetupSmallestSize(); |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1435 biggest_index = max(biggest_index, idx); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1436 |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1437 this->smallest_x = this->child->smallest_x; |
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1438 this->smallest_y = this->child->smallest_y; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1439 this->fill_x = this->child->fill_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1440 this->fill_y = this->child->fill_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1441 this->resize_x = this->child->resize_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1442 this->resize_y = this->child->resize_y; |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1443 } else { |
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1444 this->smallest_x = this->min_x; |
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1445 this->smallest_y = this->min_y; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1446 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1447 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1448 return biggest_index; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1449 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1450 |
11963
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
1451 void NWidgetBackground::AssignSizePosition(uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl) |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1452 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1453 this->pos_x = x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1454 this->pos_y = y; |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1455 this->smallest_x = given_width; |
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1456 this->smallest_y = given_height; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1457 if (!allow_resize_x) this->resize_x = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1458 if (!allow_resize_y) this->resize_y = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1459 |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1460 if (this->child != NULL) { |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1461 uint x_offset = (rtl ? this->child->padding_right : this->child->padding_left); |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1462 uint width = given_width - this->child->padding_right - this->child->padding_left; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1463 uint height = given_height - this->child->padding_top - this->child->padding_bottom; |
11963
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
1464 this->child->AssignSizePosition(x + x_offset, y + this->child->padding_top, width, height, (this->resize_x > 0), (this->resize_y > 0), rtl); |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1465 } |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1466 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1467 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1468 void NWidgetBackground::StoreWidgets(Widget *widgets, int length, bool left_moving, bool top_moving, bool rtl) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1469 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1470 NWidgetCore::StoreWidgets(widgets, length, left_moving, top_moving, rtl); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1471 if (this->child != NULL) this->child->StoreWidgets(widgets, length, left_moving, top_moving, rtl); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1472 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1473 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1474 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1475 * Nested leaf widget. |
11799
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
1476 * @param tp Type of leaf widget. |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
1477 * @param colour Colour of the leaf widget. |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
1478 * @param index Index in the widget array used by the window system. |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
1479 * @param data Data of the widget. |
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
1480 * @param tip Tooltip of the widget. |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1481 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1482 NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint16 data, StringID tip) : NWidgetCore(tp, colour, true, true, data, tip) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1483 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1484 this->SetIndex(index); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1485 this->SetMinimalSize(0, 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1486 this->SetResize(0, 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1487 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1488 switch (tp) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1489 case WWT_EMPTY: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1490 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1491 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1492 case WWT_PUSHBTN: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1493 this->SetFill(false, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1494 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1495 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1496 case WWT_IMGBTN: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1497 case WWT_PUSHIMGBTN: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1498 case WWT_IMGBTN_2: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1499 this->SetFill(false, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1500 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1501 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1502 case WWT_TEXTBTN: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1503 case WWT_PUSHTXTBTN: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1504 case WWT_TEXTBTN_2: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1505 case WWT_LABEL: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1506 case WWT_TEXT: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1507 case WWT_MATRIX: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1508 case WWT_EDITBOX: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1509 this->SetFill(false, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1510 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1511 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1512 case WWT_SCROLLBAR: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1513 case WWT_SCROLL2BAR: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1514 this->SetFill(false, true); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1515 this->SetResize(0, 1); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1516 this->min_x = 12; |
11730
a39da1e4c1f5
(svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents:
11528
diff
changeset
|
1517 this->SetDataTip(0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST); |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1518 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1519 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1520 case WWT_CAPTION: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1521 this->SetFill(true, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1522 this->SetResize(1, 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1523 this->min_y = 14; |
11730
a39da1e4c1f5
(svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents:
11528
diff
changeset
|
1524 this->SetDataTip(data, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS); |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1525 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1526 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1527 case WWT_HSCROLLBAR: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1528 this->SetFill(true, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1529 this->SetResize(1, 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1530 this->min_y = 12; |
11730
a39da1e4c1f5
(svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents:
11528
diff
changeset
|
1531 this->SetDataTip(0x0, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST); |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1532 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1533 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1534 case WWT_STICKYBOX: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1535 this->SetFill(false, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1536 this->SetMinimalSize(12, 14); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1537 this->SetDataTip(STR_NULL, STR_STICKY_BUTTON); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1538 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1539 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1540 case WWT_RESIZEBOX: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1541 this->SetFill(false, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1542 this->SetMinimalSize(12, 12); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1543 this->SetDataTip(STR_NULL, STR_RESIZE_BUTTON); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1544 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1545 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1546 case WWT_CLOSEBOX: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1547 this->SetFill(false, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1548 this->SetMinimalSize(11, 14); |
11730
a39da1e4c1f5
(svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents:
11528
diff
changeset
|
1549 this->SetDataTip(STR_BLACK_CROSS, STR_TOOLTIP_CLOSE_WINDOW); |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1550 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1551 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1552 case WWT_DROPDOWN: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1553 this->SetFill(false, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1554 this->min_y = 12; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1555 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1556 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1557 default: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1558 NOT_REACHED(); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1559 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1560 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1561 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1562 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1563 * Intialize nested widget tree and convert to widget array. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1564 * @param nwid Nested widget tree. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1565 * @param rtl Direction of the language. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1566 * @return Widget array with the converted widgets. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1567 * @note Caller should release returned widget array with \c free(widgets). |
11799
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
1568 * @ingroup NestedWidgets |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1569 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1570 Widget *InitializeNWidgets(NWidgetBase *nwid, bool rtl) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1571 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1572 /* Initialize nested widgets. */ |
11963
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
1573 int biggest_index = nwid->SetupSmallestSize(); |
de84ab2c6641
(svn r16369) -Codechange: Renaming ComputeMinimalSize() to SetupSmallestSize(), and AssignMinimalPosition() to AssignSizePosition(), they do not compute minimal size anymore.
alberth <alberth@openttd.org>
parents:
11961
diff
changeset
|
1574 nwid->AssignSizePosition(0, 0, nwid->smallest_x, nwid->smallest_y, (nwid->resize_x > 0), (nwid->resize_y > 0), rtl); |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1575 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1576 /* Construct a local widget array and initialize all its types to #WWT_LAST. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1577 Widget *widgets = MallocT<Widget>(biggest_index + 2); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1578 int i; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1579 for (i = 0; i < biggest_index + 2; i++) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1580 widgets[i].type = WWT_LAST; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1581 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1582 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1583 /* Store nested widgets in the array. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1584 nwid->StoreWidgets(widgets, biggest_index + 1, false, false, rtl); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1585 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1586 /* Check that all widgets are used. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1587 for (i = 0; i < biggest_index + 2; i++) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1588 if (widgets[i].type == WWT_LAST) break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1589 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1590 assert(i == biggest_index + 1); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1591 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1592 /* Fill terminating widget */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1593 static const Widget last_widget = {WIDGETS_END}; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1594 widgets[biggest_index + 1] = last_widget; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1595 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1596 return widgets; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1597 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1598 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1599 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1600 * Compare two widget arrays with each other, and report differences. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1601 * @param orig Pointer to original widget array. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1602 * @param gen Pointer to generated widget array (from the nested widgets). |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1603 * @param report Report differences to 'misc' debug stream. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1604 * @return Both widget arrays are equal. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1605 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1606 bool CompareWidgetArrays(const Widget *orig, const Widget *gen, bool report) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1607 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1608 #define CHECK(var, prn) \ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1609 if (ow->var != gw->var) { \ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1610 same = false; \ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1611 if (report) DEBUG(misc, 1, "index %d, \"" #var "\" field: original " prn ", generated " prn, idx, ow->var, gw->var); \ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1612 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1613 #define CHECK_COORD(var) \ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1614 if (ow->var != gw->var) { \ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1615 same = false; \ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1616 if (report) DEBUG(misc, 1, "index %d, \"" #var "\" field: original %d, generated %d, (difference %d)", idx, ow->var, gw->var, ow->var - gw->var); \ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1617 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1618 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1619 bool same = true; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1620 for(int idx = 0; ; idx++) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1621 const Widget *ow = orig + idx; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1622 const Widget *gw = gen + idx; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1623 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1624 CHECK(type, "%d") |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1625 CHECK(display_flags, "0x%x") |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1626 CHECK(colour, "%d") |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1627 CHECK_COORD(left) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1628 CHECK_COORD(right) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1629 CHECK_COORD(top) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1630 CHECK_COORD(bottom) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1631 CHECK(data, "%u") |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1632 CHECK(tooltips, "%u") |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1633 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1634 if (ow->type == WWT_LAST || gw->type == WWT_LAST) break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1635 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1636 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1637 return same; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1638 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1639 #undef CHECK |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1640 #undef CHECK_COORD |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1641 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1642 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1643 /* == Conversion code from NWidgetPart array to NWidgetBase* tree == */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1644 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1645 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1646 * Construct a single nested widget in \a *dest from its parts. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1647 * |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1648 * Construct a NWidgetBase object from a #NWidget function, and apply all |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1649 * settings that follow it, until encountering a #EndContainer, another |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1650 * #NWidget, or the end of the parts array. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1651 * |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1652 * @param parts Array with parts of the nested widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1653 * @param count Length of the \a parts array. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1654 * @param dest Address of pointer to use for returning the composed widget. |
11750
924e26095f16
(svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents:
11730
diff
changeset
|
1655 * @param fill_dest Fill the composed widget with child widgets. |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1656 * @return Number of widget part elements used to compose the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1657 */ |
11750
924e26095f16
(svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents:
11730
diff
changeset
|
1658 static int MakeNWidget(const NWidgetPart *parts, int count, NWidgetBase **dest, bool *fill_dest) |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1659 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1660 int num_used = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1661 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1662 *dest = NULL; |
11750
924e26095f16
(svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents:
11730
diff
changeset
|
1663 *fill_dest = false; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1664 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1665 while (count > num_used) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1666 switch (parts->type) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1667 case NWID_SPACER: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1668 if (*dest != NULL) return num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1669 *dest = new NWidgetSpacer(0, 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1670 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1671 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1672 case NWID_HORIZONTAL: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1673 if (*dest != NULL) return num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1674 *dest = new NWidgetHorizontal(); |
11750
924e26095f16
(svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents:
11730
diff
changeset
|
1675 *fill_dest = true; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1676 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1677 |
11500
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
1678 case NWID_HORIZONTAL_LTR: |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
1679 if (*dest != NULL) return num_used; |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
1680 *dest = new NWidgetHorizontalLTR(); |
11750
924e26095f16
(svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents:
11730
diff
changeset
|
1681 *fill_dest = true; |
11500
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
1682 break; |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
1683 |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1684 case WWT_PANEL: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1685 case WWT_INSET: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1686 case WWT_FRAME: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1687 if (*dest != NULL) return num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1688 *dest = new NWidgetBackground(parts->type, parts->u.widget.colour, parts->u.widget.index); |
11750
924e26095f16
(svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents:
11730
diff
changeset
|
1689 *fill_dest = true; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1690 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1691 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1692 case NWID_VERTICAL: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1693 if (*dest != NULL) return num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1694 *dest = new NWidgetVertical(); |
11750
924e26095f16
(svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents:
11730
diff
changeset
|
1695 *fill_dest = true; |
924e26095f16
(svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents:
11730
diff
changeset
|
1696 break; |
924e26095f16
(svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents:
11730
diff
changeset
|
1697 |
924e26095f16
(svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents:
11730
diff
changeset
|
1698 case WPT_FUNCTION: |
924e26095f16
(svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents:
11730
diff
changeset
|
1699 if (*dest != NULL) return num_used; |
924e26095f16
(svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents:
11730
diff
changeset
|
1700 *dest = parts->u.func_ptr(); |
924e26095f16
(svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents:
11730
diff
changeset
|
1701 *fill_dest = false; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1702 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1703 |
11800
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1704 case NWID_SELECTION: |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1705 case NWID_LAYERED: |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1706 if (*dest != NULL) return num_used; |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1707 *dest = new NWidgetStacked(parts->type); |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1708 *fill_dest = true; |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1709 break; |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1710 |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1711 |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1712 case WPT_RESIZE: { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1713 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1714 if (nwrb != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1715 assert(parts->u.xy.x >= 0 && parts->u.xy.y >= 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1716 nwrb->SetResize(parts->u.xy.x, parts->u.xy.y); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1717 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1718 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1719 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1720 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1721 case WPT_RESIZE_PTR: { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1722 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1723 if (nwrb != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1724 assert(parts->u.xy_ptr->x >= 0 && parts->u.xy_ptr->y >= 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1725 nwrb->SetResize(parts->u.xy_ptr->x, parts->u.xy_ptr->y); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1726 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1727 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1728 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1729 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1730 case WPT_MINSIZE: { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1731 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1732 if (nwrb != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1733 assert(parts->u.xy.x >= 0 && parts->u.xy.y >= 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1734 nwrb->SetMinimalSize(parts->u.xy.x, parts->u.xy.y); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1735 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1736 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1737 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1738 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1739 case WPT_MINSIZE_PTR: { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1740 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1741 if (nwrb != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1742 assert(parts->u.xy_ptr->x >= 0 && parts->u.xy_ptr->y >= 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1743 nwrb->SetMinimalSize((uint)(parts->u.xy_ptr->x), (uint)(parts->u.xy_ptr->y)); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1744 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1745 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1746 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1747 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1748 case WPT_FILL: { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1749 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1750 if (nwrb != NULL) nwrb->SetFill(parts->u.xy.x != 0, parts->u.xy.y != 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1751 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1752 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1753 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1754 case WPT_DATATIP: { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1755 NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1756 if (nwc != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1757 nwc->widget_data = parts->u.data_tip.data; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1758 nwc->tool_tip = parts->u.data_tip.tooltip; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1759 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1760 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1761 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1762 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1763 case WPT_DATATIP_PTR: { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1764 NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1765 if (nwc != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1766 nwc->widget_data = parts->u.datatip_ptr->data; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1767 nwc->tool_tip = parts->u.datatip_ptr->tooltip; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1768 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1769 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1770 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1771 |
11811
b32bfec54ff8
(svn r16201) -Codechange: Add NWidgetBase::SetPadding method.
alberth <alberth@openttd.org>
parents:
11800
diff
changeset
|
1772 case WPT_PADDING: |
b32bfec54ff8
(svn r16201) -Codechange: Add NWidgetBase::SetPadding method.
alberth <alberth@openttd.org>
parents:
11800
diff
changeset
|
1773 if (*dest != NULL) (*dest)->SetPadding(parts->u.padding.top, parts->u.padding.right, parts->u.padding.bottom, parts->u.padding.left); |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1774 break; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1775 |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1776 case WPT_PIPSPACE: { |
11800
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1777 NWidgetPIPContainer *nwc = dynamic_cast<NWidgetPIPContainer *>(*dest); |
11528
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1778 if (nwc != NULL) nwc->SetPIP(parts->u.pip.pre, parts->u.pip.inter, parts->u.pip.post); |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1779 |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1780 NWidgetBackground *nwb = dynamic_cast<NWidgetBackground *>(*dest); |
2ee677c87220
(svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents:
11511
diff
changeset
|
1781 if (nwb != NULL) nwb->SetPIP(parts->u.pip.pre, parts->u.pip.inter, parts->u.pip.post); |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1782 break; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1783 } |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1784 |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1785 case WPT_ENDCONTAINER: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1786 return num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1787 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1788 default: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1789 if (*dest != NULL) return num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1790 assert((parts->type & WWT_MASK) < NWID_HORIZONTAL); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1791 *dest = new NWidgetLeaf(parts->type, parts->u.widget.colour, parts->u.widget.index, 0x0, STR_NULL); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1792 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1793 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1794 num_used++; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1795 parts++; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1796 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1797 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1798 return num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1799 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1800 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1801 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1802 * Build a nested widget tree by recursively filling containers with nested widgets read from their parts. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1803 * @param parts Array with parts of the nested widgets. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1804 * @param count Length of the \a parts array. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1805 * @param parent Container to use for storing the child widgets. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1806 * @return Number of widget part elements used to fill the container. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1807 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1808 static int MakeWidgetTree(const NWidgetPart *parts, int count, NWidgetBase *parent) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1809 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1810 /* Given parent must be either a #NWidgetContainer or a #NWidgetBackground object. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1811 NWidgetContainer *nwid_cont = dynamic_cast<NWidgetContainer *>(parent); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1812 NWidgetBackground *nwid_parent = dynamic_cast<NWidgetBackground *>(parent); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1813 assert((nwid_cont != NULL && nwid_parent == NULL) || (nwid_cont == NULL && nwid_parent != NULL)); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1814 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1815 int total_used = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1816 while (true) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1817 NWidgetBase *sub_widget = NULL; |
11750
924e26095f16
(svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents:
11730
diff
changeset
|
1818 bool fill_sub = false; |
924e26095f16
(svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents:
11730
diff
changeset
|
1819 int num_used = MakeNWidget(parts, count - total_used, &sub_widget, &fill_sub); |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1820 parts += num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1821 total_used += num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1822 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1823 /* Break out of loop when end reached */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1824 if (sub_widget == NULL) break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1825 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1826 /* Add sub_widget to parent container. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1827 if (nwid_cont) nwid_cont->Add(sub_widget); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1828 if (nwid_parent) nwid_parent->Add(sub_widget); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1829 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1830 /* If sub-widget is a container, recursively fill that container. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1831 WidgetType tp = sub_widget->type; |
11800
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1832 if (fill_sub && (tp == NWID_HORIZONTAL || tp == NWID_HORIZONTAL_LTR || tp == NWID_VERTICAL |
3ab4d2cd4ea5
(svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents:
11799
diff
changeset
|
1833 || tp == WWT_PANEL || tp == WWT_FRAME || tp == WWT_INSET || tp == NWID_SELECTION || tp == NWID_LAYERED)) { |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1834 int num_used = MakeWidgetTree(parts, count - total_used, sub_widget); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1835 parts += num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1836 total_used += num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1837 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1838 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1839 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1840 if (count == total_used) return total_used; // Reached the end of the array of parts? |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1841 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1842 assert(total_used < count); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1843 assert(parts->type == WPT_ENDCONTAINER); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1844 return total_used + 1; // *parts is also 'used' |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1845 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1846 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1847 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1848 * Construct a nested widget tree from an array of parts. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1849 * @param parts Array with parts of the widgets. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1850 * @param count Length of the \a parts array. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1851 * @return Root of the nested widget tree, a vertical container containing the entire GUI. |
11799
3a6a820d27e2
(svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents:
11770
diff
changeset
|
1852 * @ingroup NestedWidgetParts |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1853 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1854 NWidgetContainer *MakeNWidgets(const NWidgetPart *parts, int count) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1855 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1856 NWidgetContainer *cont = new NWidgetVertical(); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1857 MakeWidgetTree(parts, count, cont); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1858 return cont; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1859 } |
11836
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1860 |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1861 /** |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1862 * Construct a #Widget array from a nested widget parts array, taking care of all the steps and checks. |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1863 * Also cache the result and use the cache if possible. |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1864 * @param[in] parts Array with parts of the widgets. |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1865 * @param parts_length Length of the \a parts array. |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1866 * @param[in] orig_wid Pointer to original widget array. |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1867 * @param wid_cache Pointer to the cache for storing the generated widget array (use \c NULL to prevent caching). |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1868 * @return Cached value if available, otherwise the generated widget array. If \a wid_cache is \c NULL, the caller should free the returned array. |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1869 * |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1870 * @pre Before the first call, \c *wid_cache should be \c NULL. |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1871 * @post The widget array stored in the \c *wid_cache should be free-ed by the caller. |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1872 */ |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1873 const Widget *InitializeWidgetArrayFromNestedWidgets(const NWidgetPart *parts, int parts_length, const Widget *orig_wid, Widget **wid_cache) |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1874 { |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1875 const bool rtl = false; // Direction of the language is left-to-right |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1876 |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1877 if (wid_cache != NULL && *wid_cache != NULL) return *wid_cache; |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1878 |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1879 assert(parts != NULL && parts_length > 0); |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1880 NWidgetContainer *nwid = MakeNWidgets(parts, parts_length); |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1881 Widget *gen_wid = InitializeNWidgets(nwid, rtl); |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1882 |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1883 if (!rtl && orig_wid) { |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1884 /* There are two descriptions, compare them. |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1885 * Comparing only makes sense when using a left-to-right language. |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1886 */ |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1887 bool ok = CompareWidgetArrays(orig_wid, gen_wid, false); |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1888 if (ok) { |
11961
69a41fde01e1
(svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents:
11836
diff
changeset
|
1889 DEBUG(misc, 1, "Nested widgets are equal, min-size(%u, %u)", nwid->smallest_x, nwid->smallest_y); |
11836
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1890 } else { |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1891 DEBUG(misc, 0, "Nested widgets give different results"); |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1892 CompareWidgetArrays(orig_wid, gen_wid, true); |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1893 } |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1894 } |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1895 delete nwid; |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1896 |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1897 if (wid_cache != NULL) *wid_cache = gen_wid; |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1898 return gen_wid; |
ef0eab75562b
(svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents:
11811
diff
changeset
|
1899 } |