Mercurial > hg > openttd
annotate src/widget.cpp @ 11467:e500d1b181c9 draft
(svn r15825) -Codechange: remove the WWT_DROPDOWNIN widget type and replace it with WWT_DROPDOWN.
author | yexo <yexo@openttd.org> |
---|---|
date | Mon, 23 Mar 2009 00:08:59 +0000 |
parents | 4fc1be7900f4 |
children | 5112363fd4ae |
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 |
8411
e0420e29320d
(svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138 <peter1138@openttd.org>
parents:
8349
diff
changeset
|
15 static const char *UPARROW = "\xEE\x8A\xA0"; |
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
|
16 static const char *DOWNARROW = "\xEE\x8A\xAA"; |
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
202 |
8857
a75a0c683fea
(svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents:
8737
diff
changeset
|
203 /** |
a75a0c683fea
(svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents:
8737
diff
changeset
|
204 * 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
|
205 */ |
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
|
206 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
|
207 { |
10647
592ae9307430
(svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents:
10238
diff
changeset
|
208 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
|
209 |
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
|
210 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
|
211 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
|
212 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
|
213 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
|
214 |
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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 continue; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
221 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
222 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
223 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
|
224 case WWT_IMGBTN: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
225 case WWT_IMGBTN_2: { |
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
|
226 SpriteID img = 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
|
227 assert(img != 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
|
228 DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->colour, (clicked) ? FR_LOWERED : FR_NONE); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
229 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
230 /* show different image when clicked for WWT_IMGBTN_2 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
231 if ((wi->type & WWT_MASK) == WWT_IMGBTN_2 && clicked) img++; |
5668
3d6d9bff3dd8
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents:
5587
diff
changeset
|
232 DrawSprite(img, PAL_NONE, r.left + 1 + clicked, r.top + 1 + clicked); |
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
|
233 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
|
234 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
235 |
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
|
236 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
|
237 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
|
238 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
|
239 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
|
240 |
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
|
241 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
|
242 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
|
243 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
|
244 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
245 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
|
246 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
|
247 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
|
248 /* 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
|
249 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
250 case WWT_LABEL: { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
251 StringID str = wi->data; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
252 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
253 if ((wi->type & WWT_MASK) == WWT_TEXTBTN_2 && clicked) str++; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
254 |
11432
a20dd0000d96
(svn r15790) -Codechange: remove the *Centered part of the old text drawing API.
rubidium <rubidium@openttd.org>
parents:
11427
diff
changeset
|
255 DrawString(r.left + clicked, r.right + clicked, ((r.top + r.bottom + 1) >> 1) - 5 + clicked, str, TC_FROMSTRING, SA_CENTER); |
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
|
256 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
|
257 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
258 |
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
|
259 case WWT_TEXT: { |
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
|
260 const StringID str = 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
|
261 |
11427
4ca1f733c741
(svn r15785) -Codechange: remove the *Truncated part of the old text drawing API.
rubidium <rubidium@openttd.org>
parents:
11426
diff
changeset
|
262 if (str != STR_NULL) DrawString(r.left, r.right, r.top, str, (TextColour)wi->colour); |
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
|
263 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
|
264 } |
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
|
265 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
266 case WWT_INSET: { |
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
|
267 const StringID str = wi->data; |
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
|
268 DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->colour, FR_LOWERED | FR_DARKENED); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
269 |
11427
4ca1f733c741
(svn r15785) -Codechange: remove the *Truncated part of the old text drawing API.
rubidium <rubidium@openttd.org>
parents:
11426
diff
changeset
|
270 if (str != STR_NULL) DrawString(r.left + 2, r.right - 2, r.top + 1, str, TC_FROMSTRING); |
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
|
271 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
|
272 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
273 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
274 case WWT_MATRIX: { |
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
|
275 DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->colour, (clicked) ? FR_LOWERED : FR_NONE); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
276 |
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
|
277 int c = GB(wi->data, 0, 8); |
ce8dc35932c3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium <rubidium@openttd.org>
parents:
8418
diff
changeset
|
278 int amt1 = (wi->right - wi->left + 1) / c; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
279 |
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
|
280 int d = GB(wi->data, 8, 8); |
ce8dc35932c3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium <rubidium@openttd.org>
parents:
8418
diff
changeset
|
281 int amt2 = (wi->bottom - wi->top + 1) / d; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
282 |
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
|
283 int colour = _colour_gradient[wi->colour & 0xF][6]; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
284 |
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
|
285 int x = r.left; |
ce8dc35932c3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium <rubidium@openttd.org>
parents:
8418
diff
changeset
|
286 for (int ctr = c; ctr > 1; ctr--) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
287 x += amt1; |
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
|
288 GfxFillRect(x, r.top + 1, x, r.bottom - 1, colour); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
289 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
290 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
291 x = r.top; |
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
|
292 for (int ctr = d; ctr > 1; ctr--) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
293 x += amt2; |
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
|
294 GfxFillRect(r.left + 1, x, r.right - 1, x, colour); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
295 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
296 |
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
|
297 colour = _colour_gradient[wi->colour & 0xF][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
|
298 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
299 x = r.left - 1; |
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
|
300 for (int ctr = c; ctr > 1; ctr--) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
301 x += amt1; |
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
|
302 GfxFillRect(x, r.top + 1, x, r.bottom - 1, colour); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
303 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
304 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
305 x = r.top - 1; |
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
|
306 for (int ctr = d; ctr > 1; ctr--) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
307 x += amt2; |
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
|
308 GfxFillRect(r.left + 1, x, r.right - 1, x, colour); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
309 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
310 |
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
|
311 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
|
312 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
313 |
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
|
314 /* vertical scrollbar */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
315 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
|
316 assert(wi->data == 0); |
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
|
317 assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere! |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
318 |
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
|
319 /* draw up/down buttons */ |
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
|
320 clicked = ((this->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_UP); |
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
|
321 DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->colour, (clicked) ? FR_LOWERED : FR_NONE); |
11436
caf4456fbbf3
(svn r15794) -Codechange: remove the DoDrawString part of the old text drawing API
rubidium <rubidium@openttd.org>
parents:
11432
diff
changeset
|
322 DrawString(r.left + 2 + clicked, r.right, r.top + clicked, UPARROW, TC_BLACK); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
323 |
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
|
324 clicked = (((this->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_DOWN)); |
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
|
325 DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->colour, (clicked) ? FR_LOWERED : FR_NONE); |
11436
caf4456fbbf3
(svn r15794) -Codechange: remove the DoDrawString part of the old text drawing API
rubidium <rubidium@openttd.org>
parents:
11432
diff
changeset
|
326 DrawString(r.left + 2 + clicked, r.right, r.bottom - 9 + clicked, DOWNARROW, TC_BLACK); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
327 |
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
|
328 int c1 = _colour_gradient[wi->colour & 0xF][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
|
329 int c2 = _colour_gradient[wi->colour & 0xF][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
|
330 |
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
|
331 /* draw "shaded" background */ |
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
|
332 GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c2); |
9607
3d6213e95b9a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch <frosch@openttd.org>
parents:
9273
diff
changeset
|
333 GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c1, 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
|
334 |
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
|
335 /* draw shaded lines */ |
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
|
336 GfxFillRect(r.left + 2, r.top + 10, r.left + 2, r.bottom - 10, c1); |
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
|
337 GfxFillRect(r.left + 3, r.top + 10, r.left + 3, r.bottom - 10, c2); |
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
|
338 GfxFillRect(r.left + 7, r.top + 10, r.left + 7, r.bottom - 10, c1); |
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
|
339 GfxFillRect(r.left + 8, r.top + 10, r.left + 8, r.bottom - 10, c2); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
340 |
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
|
341 Point pt = HandleScrollbarHittest(&this->vscroll, r.top, r.bottom); |
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
|
342 DrawFrameRect(r.left, pt.x, r.right, pt.y, wi->colour, (this->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_MIDDLE ? FR_LOWERED : FR_NONE); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
343 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
344 } |
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
|
345 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
346 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
|
347 assert(wi->data == 0); |
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
|
348 assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere! |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
349 |
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
|
350 /* draw up/down buttons */ |
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
|
351 clicked = ((this->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_UP | WF_SCROLL2)); |
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
|
352 DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->colour, (clicked) ? FR_LOWERED : FR_NONE); |
11436
caf4456fbbf3
(svn r15794) -Codechange: remove the DoDrawString part of the old text drawing API
rubidium <rubidium@openttd.org>
parents:
11432
diff
changeset
|
353 DrawString(r.left + 2 + clicked, r.right, r.top + clicked, UPARROW, TC_BLACK); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
354 |
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
|
355 clicked = ((this->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_DOWN | WF_SCROLL2)); |
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
|
356 DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->colour, (clicked) ? FR_LOWERED : FR_NONE); |
11436
caf4456fbbf3
(svn r15794) -Codechange: remove the DoDrawString part of the old text drawing API
rubidium <rubidium@openttd.org>
parents:
11432
diff
changeset
|
357 DrawString(r.left + 2 + clicked, r.right, r.bottom - 9 + clicked, DOWNARROW, TC_BLACK); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
358 |
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
|
359 int c1 = _colour_gradient[wi->colour & 0xF][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
|
360 int c2 = _colour_gradient[wi->colour & 0xF][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
|
361 |
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
|
362 /* draw "shaded" background */ |
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
|
363 GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c2); |
9607
3d6213e95b9a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch <frosch@openttd.org>
parents:
9273
diff
changeset
|
364 GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c1, 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
|
365 |
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
|
366 /* draw shaded lines */ |
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
|
367 GfxFillRect(r.left + 2, r.top + 10, r.left + 2, r.bottom - 10, c1); |
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
|
368 GfxFillRect(r.left + 3, r.top + 10, r.left + 3, r.bottom - 10, c2); |
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
|
369 GfxFillRect(r.left + 7, r.top + 10, r.left + 7, r.bottom - 10, c1); |
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
|
370 GfxFillRect(r.left + 8, r.top + 10, r.left + 8, r.bottom - 10, c2); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
371 |
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
|
372 Point pt = HandleScrollbarHittest(&this->vscroll2, r.top, r.bottom); |
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
|
373 DrawFrameRect(r.left, pt.x, r.right, pt.y, wi->colour, (this->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_MIDDLE | WF_SCROLL2) ? FR_LOWERED : FR_NONE); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
374 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
375 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
376 |
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
|
377 /* horizontal scrollbar */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
378 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
|
379 assert(wi->data == 0); |
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
|
380 assert(r.bottom - r.top == 11); // To ensure the same sizes are used everywhere! |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
381 |
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
|
382 clicked = ((this->flags4 & (WF_SCROLL_UP | WF_HSCROLL)) == (WF_SCROLL_UP | WF_HSCROLL)); |
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
|
383 DrawFrameRect(r.left, r.top, r.left + 9, r.bottom, wi->colour, (clicked) ? FR_LOWERED : FR_NONE); |
5668
3d6d9bff3dd8
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents:
5587
diff
changeset
|
384 DrawSprite(SPR_ARROW_LEFT, PAL_NONE, r.left + 1 + clicked, r.top + 1 + clicked); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
385 |
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
|
386 clicked = ((this->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL)) == (WF_SCROLL_DOWN | WF_HSCROLL)); |
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
|
387 DrawFrameRect(r.right - 9, r.top, r.right, r.bottom, wi->colour, (clicked) ? FR_LOWERED : FR_NONE); |
5668
3d6d9bff3dd8
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents:
5587
diff
changeset
|
388 DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, r.right - 8 + clicked, r.top + 1 + clicked); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
389 |
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
|
390 int c1 = _colour_gradient[wi->colour & 0xF][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
|
391 int c2 = _colour_gradient[wi->colour & 0xF][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
|
392 |
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
|
393 /* draw "shaded" background */ |
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
|
394 GfxFillRect(r.left + 10, r.top, r.right - 10, r.bottom, c2); |
9607
3d6213e95b9a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch <frosch@openttd.org>
parents:
9273
diff
changeset
|
395 GfxFillRect(r.left + 10, r.top, r.right - 10, r.bottom, c1, 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
|
396 |
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
|
397 /* draw shaded lines */ |
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
|
398 GfxFillRect(r.left + 10, r.top + 2, r.right - 10, r.top + 2, c1); |
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
|
399 GfxFillRect(r.left + 10, r.top + 3, r.right - 10, r.top + 3, c2); |
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
|
400 GfxFillRect(r.left + 10, r.top + 7, r.right - 10, r.top + 7, c1); |
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
|
401 GfxFillRect(r.left + 10, r.top + 8, r.right - 10, r.top + 8, c2); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
402 |
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
|
403 /* draw actual scrollbar */ |
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
|
404 Point pt = HandleScrollbarHittest(&this->hscroll, r.left, r.right); |
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
|
405 DrawFrameRect(pt.x, r.top, pt.y, r.bottom, wi->colour, (this->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL)) == (WF_SCROLL_MIDDLE | WF_HSCROLL) ? FR_LOWERED : FR_NONE); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
406 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
407 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
408 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
409 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
410 case WWT_FRAME: { |
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
|
411 const StringID str = 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
|
412 int x2 = r.left; // by default the left side is the left side of the widget |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
413 |
11454
9bfb4cdd8e22
(svn r15812) -Codechange: use the new DrawString API in another set of GUIs
rubidium <rubidium@openttd.org>
parents:
11436
diff
changeset
|
414 if (str != STR_NULL) x2 = DrawString(r.left + 6, r.right - 6, r.top, str, TC_FROMSTRING); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
415 |
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
|
416 int c1 = _colour_gradient[wi->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
|
417 int c2 = _colour_gradient[wi->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
|
418 |
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
|
419 if (_dynlang.text_dir == TD_LTR) { |
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
|
420 /* Line from upper left corner to start of text */ |
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
|
421 GfxFillRect(r.left, r.top + 4, r.left + 4, r.top + 4, c1); |
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
|
422 GfxFillRect(r.left + 1, r.top + 5, r.left + 4, r.top + 5, c2); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
423 |
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
|
424 /* Line from end of text to upper right corner */ |
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
|
425 GfxFillRect(x2, r.top + 4, r.right - 1, r.top + 4, c1); |
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
|
426 GfxFillRect(x2, r.top + 5, r.right - 2, r.top + 5, c2); |
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
|
427 } else { |
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
|
428 /* Line from upper left corner to start of text */ |
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
|
429 GfxFillRect(r.left, r.top + 4, x2, r.top + 4, c1); |
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
|
430 GfxFillRect(r.left + 1, r.top + 5, x2, r.top + 5, c2); |
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
|
431 |
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
|
432 /* Line from end of text to upper right corner */ |
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
|
433 GfxFillRect(r.right - 5, r.top + 4, r.right - 1, r.top + 4, c1); |
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
|
434 GfxFillRect(r.right - 5, r.top + 5, r.right - 2, r.top + 5, c2); |
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
|
435 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
436 |
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
|
437 /* Line from upper left corner to bottom left corner */ |
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
|
438 GfxFillRect(r.left, r.top + 5, r.left, r.bottom - 1, c1); |
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
|
439 GfxFillRect(r.left + 1, r.top + 6, r.left + 1, r.bottom - 2, c2); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
440 |
11368
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11085
diff
changeset
|
441 /* Line from upper right corner to bottom right corner */ |
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
|
442 GfxFillRect(r.right - 1, r.top + 5, r.right - 1, r.bottom - 2, c1); |
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
|
443 GfxFillRect(r.right, r.top + 4, r.right, r.bottom - 1, c2); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
444 |
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
|
445 GfxFillRect(r.left + 1, r.bottom - 1, r.right - 1, r.bottom - 1, c1); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
446 GfxFillRect(r.left, r.bottom, r.right, r.bottom, c2); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
447 |
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
|
448 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
|
449 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
450 |
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
|
451 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
|
452 assert(wi->data == 0); |
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
|
453 assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere! |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
454 |
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
|
455 clicked = !!(this->flags4 & WF_STICKY); |
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
|
456 DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->colour, (clicked) ? FR_LOWERED : FR_NONE); |
5668
3d6d9bff3dd8
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents:
5587
diff
changeset
|
457 DrawSprite((clicked) ? SPR_PIN_UP : SPR_PIN_DOWN, PAL_NONE, r.left + 2 + clicked, r.top + 3 + clicked); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
458 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
459 |
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
|
460 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
|
461 assert(wi->data == 0); |
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
|
462 assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere! |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
463 |
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
|
464 clicked = !!(this->flags4 & WF_SIZING); |
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
|
465 DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->colour, (clicked) ? FR_LOWERED : FR_NONE); |
11405
b1b4fea347bf
(svn r15760) -Codechange [FS#2704]: support that the resize box is at the left side of the window too (based on work by Alberth)
rubidium <rubidium@openttd.org>
parents:
11368
diff
changeset
|
466 if (wi->left < (this->width / 2)) { |
b1b4fea347bf
(svn r15760) -Codechange [FS#2704]: support that the resize box is at the left side of the window too (based on work by Alberth)
rubidium <rubidium@openttd.org>
parents:
11368
diff
changeset
|
467 DrawSprite(SPR_WINDOW_RESIZE_LEFT, PAL_NONE, r.left + 2, r.top + 3 + clicked); |
b1b4fea347bf
(svn r15760) -Codechange [FS#2704]: support that the resize box is at the left side of the window too (based on work by Alberth)
rubidium <rubidium@openttd.org>
parents:
11368
diff
changeset
|
468 } else { |
b1b4fea347bf
(svn r15760) -Codechange [FS#2704]: support that the resize box is at the left side of the window too (based on work by Alberth)
rubidium <rubidium@openttd.org>
parents:
11368
diff
changeset
|
469 DrawSprite(SPR_WINDOW_RESIZE_RIGHT, PAL_NONE, r.left + 3 + clicked, r.top + 3 + clicked); |
b1b4fea347bf
(svn r15760) -Codechange [FS#2704]: support that the resize box is at the left side of the window too (based on work by Alberth)
rubidium <rubidium@openttd.org>
parents:
11368
diff
changeset
|
470 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
471 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
472 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
473 case WWT_CLOSEBOX: { |
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
|
474 const StringID str = wi->data; |
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
|
475 |
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
|
476 assert(str == STR_00C5 || str == STR_00C6); // black or silver cross |
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
|
477 assert(r.right - r.left == 10); // To ensure the same sizes are used everywhere |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
478 |
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
|
479 DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->colour, FR_NONE); |
11454
9bfb4cdd8e22
(svn r15812) -Codechange: use the new DrawString API in another set of GUIs
rubidium <rubidium@openttd.org>
parents:
11436
diff
changeset
|
480 DrawString(r.left + 2, r.right, r.top + 2, str, TC_FROMSTRING); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
481 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
482 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
483 |
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
|
484 case WWT_CAPTION: |
ce8dc35932c3
(svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium <rubidium@openttd.org>
parents:
8418
diff
changeset
|
485 assert(r.bottom - r.top == 13); // To ensure the same sizes are used everywhere! |
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
|
486 DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->colour, FR_BORDERONLY); |
11084
e07c7d3925c8
(svn r15427) -Codechange: give w->caption_color a more sensible name as it holds the owner of whatever is shown in the window
rubidium <rubidium@openttd.org>
parents:
11082
diff
changeset
|
487 DrawFrameRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, wi->colour, (this->owner == INVALID_OWNER) ? FR_LOWERED | FR_DARKENED : FR_LOWERED | FR_DARKENED | 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
|
488 |
11084
e07c7d3925c8
(svn r15427) -Codechange: give w->caption_color a more sensible name as it holds the owner of whatever is shown in the window
rubidium <rubidium@openttd.org>
parents:
11082
diff
changeset
|
489 if (this->owner != INVALID_OWNER) { |
e07c7d3925c8
(svn r15427) -Codechange: give w->caption_color a more sensible name as it holds the owner of whatever is shown in the window
rubidium <rubidium@openttd.org>
parents:
11082
diff
changeset
|
490 GfxFillRect(r.left + 2, r.top + 2, r.right - 2, r.bottom - 2, _colour_gradient[_company_colours[this->owner]][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
|
491 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
492 |
11426
38844e2f76fd
(svn r15784) -Fix (r15779): TextAlignment and TA_* already exist on windows
glx <glx@openttd.org>
parents:
11424
diff
changeset
|
493 DrawString(r.left + 2, r.right - 2, r.top + 2, wi->data, TC_FROMSTRING, SA_CENTER); |
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
|
494 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
|
495 |
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
|
496 case WWT_DROPDOWN: { |
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
|
497 assert(r.bottom - r.top == 11); // ensure consistent size |
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
|
498 |
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
|
499 StringID str = wi->data; |
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
|
500 if (_dynlang.text_dir == TD_LTR) { |
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
|
501 DrawFrameRect(r.left, r.top, r.right - 12, r.bottom, wi->colour, FR_NONE); |
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
|
502 DrawFrameRect(r.right - 11, r.top, r.right, r.bottom, wi->colour, clicked ? FR_LOWERED : FR_NONE); |
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
|
503 DrawString(r.right - (clicked ? 8 : 9), r.right, r.top + (clicked ? 2 : 1), STR_0225, TC_BLACK); |
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
|
504 if (str != STR_NULL) DrawString(r.left + 2, r.right - 14, r.top + 1, str, TC_BLACK); |
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
|
505 } else { |
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
|
506 DrawFrameRect(r.left + 12, r.top, r.right, r.bottom, wi->colour, FR_NONE); |
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
|
507 DrawFrameRect(r.left, r.top, r.left + 11, r.bottom, wi->colour, clicked ? FR_LOWERED : FR_NONE); |
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
|
508 DrawString(r.left + 1, r.left + (clicked ? 10 : 11), r.top + (clicked ? 2 : 1), STR_0225, TC_BLACK); |
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
|
509 if (str != STR_NULL) DrawString(r.left + 14, r.right - 2, r.top + 1, str, TC_BLACK); |
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
|
510 } |
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
|
511 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
|
512 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
513 } |
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
|
514 |
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
|
515 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
|
516 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
|
517 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
518 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
519 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
520 |
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
|
521 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
|
522 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
|
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
525 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
526 |
5824
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
527 static void ResizeWidgets(Window *w, byte a, byte b) |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
528 { |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
529 int16 offset = w->widget[a].left; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
530 int16 length = w->widget[b].right - offset; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
531 |
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
|
532 w->widget[a].right = (length / 2) + offset; |
5824
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
533 |
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
|
534 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
|
535 } |
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
|
536 |
5824
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
537 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
|
538 { |
5824
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
539 int16 offset = w->widget[a].left; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
540 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
|
541 |
5824
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
542 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
|
543 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
|
544 |
5824
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
545 w->widget[a].right += offset; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
546 w->widget[b].right += offset; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
547 |
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
|
548 /* 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
|
549 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
|
550 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
|
551 } |
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
|
552 |
5824
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
553 /** 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
|
554 * 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
|
555 * @param w Window to modify |
5824
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
556 * @param left The leftmost widget to resize |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
557 * @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
|
558 */ |
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
|
559 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
|
560 { |
5824
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
561 int16 num_widgets = right - left + 1; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
562 |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
563 if (num_widgets < 2) NOT_REACHED(); |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
564 |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
565 switch (num_widgets) { |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
566 case 2: ResizeWidgets(w, left, right); break; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
567 case 3: ResizeWidgets(w, left, left + 1, right); break; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
568 default: { |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
569 /* 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
|
570 * 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
|
571 * 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
|
572 * 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
|
573 int16 offset = w->widget[left].left; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
574 int16 length = w->widget[right].right - offset; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
575 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
|
576 |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
577 /* 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
|
578 * 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
|
579 * 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
|
580 * 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
|
581 * |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
582 * num_widgets/2 (rounding down) |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
583 * --------------- |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
584 * num_widgets |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
585 * |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
586 * 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
|
587 int16 middle = ((length * num_widgets) / (2 * num_widgets)) + offset; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
588 |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
589 /* 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
|
590 w->widget[widget].right = middle; |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
591 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
|
592 /* Now resize the left and right of the middle */ |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
593 ResizeButtons(w, left, widget); |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
594 ResizeButtons(w, widget + 1, right); |
19c4635a0be0
(svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents:
5822
diff
changeset
|
595 } |
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
|
596 } |
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
|
597 } |
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
|
598 |
8857
a75a0c683fea
(svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents:
8737
diff
changeset
|
599 /** 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
|
600 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
|
601 { |
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
|
602 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
|
603 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
|
604 |
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
|
605 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
|
606 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
|
607 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
|
608 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
|
609 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
|
610 } |
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
|
611 |
9834
efa04139a798
(svn r13977) -Codechange: Let ResizeWindowForWidget() handle hidden (zero height or zero width) widgets.
peter1138 <peter1138@openttd.org>
parents:
9779
diff
changeset
|
612 /* 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
|
613 * 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
|
614 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
|
615 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
|
616 |
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
|
617 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
|
618 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
|
619 |
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
|
620 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
|
621 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
|
622 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
|
623 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
|
624 } |
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
|
625 |
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
|
626 /** |
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
|
627 * 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
|
628 * @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
|
629 * @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
|
630 */ |
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
|
631 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
|
632 { |
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
|
633 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
|
634 |
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
|
635 int offset = this->IsWidgetLowered(widget) ? 1 : 0; |
11436
caf4456fbbf3
(svn r15794) -Codechange: remove the DoDrawString part of the old text drawing API
rubidium <rubidium@openttd.org>
parents:
11432
diff
changeset
|
636 DrawString(this->widget[widget].right - 11 + offset, this->widget[widget].right, this->widget[widget].top + 1 + offset, state == SBS_DOWN ? DOWNARROW : UPARROW, TC_BLACK); |
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
|
637 } |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
638 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
639 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
640 /* == Nested widgets == */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
641 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
642 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
643 * Base class constructor. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
644 * @param tp Nested widget type. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
645 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
646 NWidgetBase::NWidgetBase(WidgetType tp) : ZeroedMemoryAllocator() |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
647 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
648 this->type = tp; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
649 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
650 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
651 /* ~NWidgetContainer() takes care of #next and #prev data members. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
652 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
653 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
654 * @fn int NWidgetBase::ComputeMinimalSize() |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
655 * @brief Compute minimal size needed by the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
656 * |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
657 * The minimal size of a widget is the smallest size that a widget needs to |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
658 * display itself properly. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
659 * 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
|
660 * @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
|
661 * |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
662 * @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
|
663 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
664 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
665 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
666 * @fn void NWidgetBase::AssignMinimalPosition(uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
667 * @brief Assign minimal size and position to the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
668 * @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
|
669 * @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
|
670 * @param given_width Width allocated to the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
671 * @param given_height Height allocated to the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
672 * @param allow_resize_x Horizontal resizing is allowed. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
673 * @param allow_resize_y Vertical resizing is allowed. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
674 * @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
|
675 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
676 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
677 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
678 * @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
|
679 * @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
|
680 * @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
|
681 * @param length Length of the array. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
682 * @param left_moving Left edge of the widget may move due to resizing (right edge if \a rtl). |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
683 * @param top_moving Top edge of the widget may move due to reisizing. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
684 * @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
|
685 * |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
686 * @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
|
687 * 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
|
688 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
689 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
690 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
691 * Constructor for resizable nested widgets. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
692 * @param tp Nested widget type. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
693 * @param fill_x Allow horizontal filling from initial size. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
694 * @param fill_y Allow vertical filling from initial size. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
695 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
696 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
|
697 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
698 this->fill_x = fill_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
699 this->fill_y = fill_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
700 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
701 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
702 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
703 * Set minimal size of the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
704 * @param min_x Horizontal minimal size of the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
705 * @param min_y Vertical minimal size of the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
706 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
707 void NWidgetResizeBase::SetMinimalSize(uint min_x, uint min_y) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
708 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
709 this->min_x = min_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
710 this->min_y = min_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
711 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
712 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
713 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
714 * Set the filling of the widget from initial size. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
715 * @param fill_x Allow horizontal filling from initial size. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
716 * @param fill_y Allow vertical filling from initial size. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
717 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
718 void NWidgetResizeBase::SetFill(bool fill_x, bool fill_y) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
719 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
720 this->fill_x = fill_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
721 this->fill_y = fill_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
722 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
723 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
724 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
725 * Set resize step of the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
726 * @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
|
727 * @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
|
728 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
729 void NWidgetResizeBase::SetResize(uint resize_x, uint resize_y) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
730 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
731 this->resize_x = resize_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
732 this->resize_y = resize_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
733 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
734 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
735 void NWidgetResizeBase::AssignMinimalPosition(uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
736 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
737 this->pos_x = x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
738 this->pos_y = y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
739 this->min_x = given_width; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
740 this->min_y = given_height; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
741 if (!allow_resize_x) this->resize_x = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
742 if (!allow_resize_y) this->resize_y = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
743 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
744 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
745 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
746 * Initialization of a 'real' widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
747 * @param tp Type of the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
748 * @param colour Colour of the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
749 * @param fill_x Default horizontal filling. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
750 * @param fill_y Default vertical filling. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
751 * @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
|
752 * @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
|
753 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
754 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
|
755 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
756 this->colour = colour; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
757 this->index = -1; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
758 this->widget_data = widget_data; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
759 this->tool_tip = tool_tip; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
760 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
761 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
762 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
763 * 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
|
764 * @param index Index to use. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
765 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
766 void NWidgetCore::SetIndex(int index) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
767 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
768 assert(index >= 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
769 this->index = index; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
770 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
771 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
772 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
773 * Set data and tool tip of the nested widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
774 * @param widget_data Data to use. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
775 * @param tool_tip Tool tip string to use. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
776 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
777 void NWidgetCore::SetDataTip(uint16 widget_data, StringID tool_tip) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
778 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
779 this->widget_data = widget_data; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
780 this->tool_tip = tool_tip; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
781 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
782 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
783 int NWidgetCore::ComputeMinimalSize() |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
784 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
785 /* All data is already at the right place. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
786 return this->index; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
787 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
788 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
789 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
|
790 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
791 if (this->index < 0) return; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
792 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
793 assert(this->index < length); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
794 Widget *w = widgets + this->index; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
795 assert(w->type == WWT_LAST); |
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 DisplayFlags flags = RESIZE_NONE; // resize flags. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
798 /* Compute vertical resizing. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
799 if (top_moving) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
800 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
|
801 } else if(this->resize_y > 0) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
802 flags |= RESIZE_BOTTOM; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
803 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
804 /* Compute horizontal resizing. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
805 if (left_moving) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
806 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
|
807 } else if (this->resize_x > 0) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
808 flags |= RESIZE_RIGHT; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
809 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
810 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
811 /* Copy nested widget data into its widget array entry. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
812 w->type = this->type; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
813 w->display_flags = flags; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
814 w->colour = this->colour; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
815 w->left = this->pos_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
816 w->right = this->pos_x + this->min_x - 1; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
817 w->top = this->pos_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
818 w->bottom = this->pos_y + this->min_y - 1; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
819 w->data = this->widget_data; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
820 w->tooltips = this->tool_tip; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
821 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
822 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
823 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
824 * Constructor container baseclass. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
825 * @param tp Type of the container. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
826 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
827 NWidgetContainer::NWidgetContainer(WidgetType tp) : NWidgetBase(tp) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
828 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
829 this->head = NULL; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
830 this->tail = NULL; |
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 NWidgetContainer::~NWidgetContainer() |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
834 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
835 while (this->head != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
836 NWidgetBase *wid = this->head->next; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
837 delete this->head; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
838 this->head = wid; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
839 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
840 this->tail = NULL; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
841 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
842 |
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 * Append widget \a wid to container. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
845 * @param wid Widget to append. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
846 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
847 void NWidgetContainer::Add(NWidgetBase *wid) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
848 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
849 assert(wid->next == NULL && wid->prev == NULL); |
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 if (this->head == NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
852 this->head = wid; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
853 this->tail = wid; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
854 } else { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
855 assert(this->tail != NULL); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
856 assert(this->tail->next == NULL); |
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 this->tail->next = wid; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
859 wid->prev = this->tail; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
860 this->tail = wid; |
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 } |
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 NWidgetHorizontal::NWidgetHorizontal() : NWidgetContainer(NWID_HORIZONTAL) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
865 { |
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 int NWidgetHorizontal::ComputeMinimalSize() |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
869 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
870 int biggest_index = -1; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
871 this->min_x = 0; // Sum of minimal size of all childs. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
872 this->min_y = 0; // Biggest child. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
873 this->fill_x = false; // true if at least one child allows fill_x. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
874 this->fill_y = true; // true if all childs allow fill_y. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
875 this->resize_x = 0; // smallest non-zero child widget resize step. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
876 this->resize_y = 1; // smallest common child resize step |
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 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
|
879 int idx = child_wid->ComputeMinimalSize(); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
880 biggest_index = max(biggest_index, idx); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
881 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
882 this->min_x += child_wid->min_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
883 this->min_y = max(this->min_y, child_wid->min_y); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
884 this->fill_x |= child_wid->fill_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
885 this->fill_y &= child_wid->fill_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
886 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
887 if (child_wid->resize_x > 0) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
888 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
|
889 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
890 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
|
891 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
892 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
893 return biggest_index; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
894 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
895 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
896 void NWidgetHorizontal::AssignMinimalPosition(uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
897 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
898 assert(given_width >= this->min_x && given_height >= this->min_y); |
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 uint additional_length = given_width - this->min_x; // Additional width given to us. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
901 this->pos_x = x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
902 this->pos_y = y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
903 this->min_x = given_width; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
904 this->min_y = given_height; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
905 if (!allow_resize_x) this->resize_x = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
906 if (!allow_resize_y) this->resize_y = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
907 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
908 /* 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
|
909 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
|
910 NWidgetBase *child_wid; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
911 for (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
|
912 if (child_wid->fill_x) num_changing_childs++; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
913 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
914 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
915 /* Fill and position the child widgets. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
916 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
|
917 allow_resize_x = (this->resize_x > 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
918 child_wid = rtl ? this->tail : this->head; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
919 while (child_wid != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
920 /* Decide about vertical filling of the child. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
921 uint child_height; // Height of the child widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
922 uint child_pos_y; // Vertical position of child relative to the top of the container. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
923 if (child_wid->fill_y) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
924 child_height = given_height; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
925 child_pos_y = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
926 } else { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
927 child_height = child_wid->min_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
928 child_pos_y = (given_height - child_height) / 2; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
929 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
930 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
931 /* Decide about horizontal filling of the child. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
932 uint child_width; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
933 child_width = child_wid->min_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
934 if (child_wid->fill_x && num_changing_childs > 0) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
935 /* 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
|
936 uint increment = additional_length / num_changing_childs; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
937 additional_length -= increment; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
938 num_changing_childs--; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
939 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
940 child_width += increment; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
941 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
942 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
943 child_wid->AssignMinimalPosition(x + position, y + child_pos_y, child_width, child_height, allow_resize_x, (this->resize_y > 0), rtl); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
944 position += child_width; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
945 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
|
946 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
947 child_wid = rtl ? child_wid->prev : child_wid->next; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
948 } |
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 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
951 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
|
952 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
953 NWidgetBase *child_wid = rtl ? this->tail : this->head; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
954 while (child_wid != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
955 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
|
956 left_moving |= (child_wid->resize_x > 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
957 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
958 child_wid = rtl ? child_wid->prev : child_wid->next; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
959 } |
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 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
962 NWidgetVertical::NWidgetVertical() : NWidgetContainer(NWID_VERTICAL) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
963 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
964 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
965 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
966 int NWidgetVertical::ComputeMinimalSize() |
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 int biggest_index = -1; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
969 this->min_x = 0; // Biggest child. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
970 this->min_y = 0; // Sum of minimal size of all childs. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
971 this->fill_x = true; // true if all childs allow fill_x. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
972 this->fill_y = false; // true if at least one child allows fill_y. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
973 this->resize_x = 1; // smallest common child resize step |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
974 this->resize_y = 0; // smallest non-zero child widget resize step. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
975 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
976 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
|
977 int idx = child_wid->ComputeMinimalSize(); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
978 biggest_index = max(biggest_index, idx); |
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 this->min_y += child_wid->min_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
981 this->min_x = max(this->min_x, child_wid->min_x); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
982 this->fill_y |= child_wid->fill_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
983 this->fill_x &= child_wid->fill_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
984 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
985 if (child_wid->resize_y > 0) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
986 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
|
987 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
988 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
|
989 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
990 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
991 return biggest_index; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
992 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
993 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
994 void NWidgetVertical::AssignMinimalPosition(uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
995 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
996 assert(given_width >= this->min_x && given_height >= this->min_y); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
997 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
998 int additional_length = given_height - this->min_y; // Additional height given to us. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
999 this->pos_x = x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1000 this->pos_y = y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1001 this->min_x = given_width; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1002 this->min_y = given_height; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1003 if (!allow_resize_x) this->resize_x = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1004 if (!allow_resize_y) this->resize_y = 0; |
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 /* 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
|
1007 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
|
1008 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
|
1009 if (child_wid->fill_y) num_changing_childs++; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1010 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1011 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1012 /* Fill and position the child widgets. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1013 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
|
1014 allow_resize_y = (this->resize_y > 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1015 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
|
1016 /* Decide about horizontal filling of the child. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1017 uint child_width; // Width of the child widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1018 uint child_pos_x; // Horizontal position of child relative to the left of the container. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1019 if (child_wid->fill_x) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1020 child_width = given_width; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1021 child_pos_x = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1022 } else { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1023 child_width = child_wid->min_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1024 child_pos_x = (given_width - child_width) / 2; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1025 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1026 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1027 /* Decide about vertical filling of the child. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1028 uint child_height; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1029 child_height = child_wid->min_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1030 if (child_wid->fill_y && num_changing_childs > 0) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1031 /* 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
|
1032 uint increment = additional_length / num_changing_childs; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1033 additional_length -= increment; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1034 num_changing_childs--; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1035 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1036 child_height += increment; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1037 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1038 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1039 child_wid->AssignMinimalPosition(x + child_pos_x, y + position, child_width, child_height, (this->resize_x > 0), allow_resize_y, rtl); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1040 position += child_height; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1041 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
|
1042 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1043 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1044 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1045 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
|
1046 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1047 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
|
1048 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
|
1049 top_moving |= (child_wid->resize_y > 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1050 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1051 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1052 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1053 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1054 * Generic spacer widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1055 * @param length Horizontal size of the spacer widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1056 * @param height Vertical size of the spacer widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1057 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1058 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
|
1059 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1060 this->SetMinimalSize(length, height); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1061 this->SetResize(0, 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1062 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1063 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1064 int NWidgetSpacer::ComputeMinimalSize() |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1065 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1066 /* No further computation needed. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1067 return -1; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1068 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1069 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1070 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
|
1071 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1072 /* Spacer widgets are never stored in the widget array. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1073 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1074 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1075 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1076 * Constructor parent nested widgets. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1077 * @param tp Type of parent widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1078 * @param colour Colour of the parent widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1079 * @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
|
1080 * @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
|
1081 * vertical container will be inserted while adding the first |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1082 * child widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1083 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1084 NWidgetBackground::NWidgetBackground(WidgetType tp, Colours colour, int index, NWidgetContainer *child) : NWidgetCore(tp, colour, true, true, 0x0, STR_NULL) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1085 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1086 this->SetIndex(index); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1087 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
|
1088 assert(index >= 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1089 this->child = child; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1090 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1091 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1092 NWidgetBackground::~NWidgetBackground() |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1093 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1094 if (this->child != NULL) delete this->child; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1095 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1096 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1097 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1098 * Add a child to the parent. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1099 * @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
|
1100 * |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1101 * 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
|
1102 * 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
|
1103 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1104 void NWidgetBackground::Add(NWidgetBase *nwid) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1105 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1106 if (this->child == NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1107 this->child = new NWidgetVertical(); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1108 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1109 this->child->Add(nwid); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1110 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1111 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1112 int NWidgetBackground::ComputeMinimalSize() |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1113 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1114 int biggest_index = this->index; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1115 if (this->child != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1116 int idx = this->child->ComputeMinimalSize(); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1117 biggest_index = max(biggest_index, idx); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1118 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1119 this->min_x = this->child->min_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1120 this->min_y = this->child->min_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1121 this->fill_x = this->child->fill_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1122 this->fill_y = this->child->fill_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1123 this->resize_x = this->child->resize_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1124 this->resize_y = this->child->resize_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1125 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1126 /* Otherwise, the program should have already set the above values. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1127 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1128 return biggest_index; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1129 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1130 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1131 void NWidgetBackground::AssignMinimalPosition(uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1132 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1133 this->pos_x = x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1134 this->pos_y = y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1135 this->min_x = given_width; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1136 this->min_y = given_height; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1137 if (!allow_resize_x) this->resize_x = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1138 if (!allow_resize_y) this->resize_y = 0; |
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 if (this->child != NULL) this->child->AssignMinimalPosition(x, y, given_width, given_height, (this->resize_x > 0), (this->resize_y > 0), rtl); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1141 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1142 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1143 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
|
1144 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1145 NWidgetCore::StoreWidgets(widgets, length, left_moving, top_moving, rtl); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1146 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
|
1147 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1148 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1149 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1150 * Nested leaf widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1151 * @param tp Type of leaf widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1152 * @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
|
1153 * @param data Data of the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1154 * @param tip Tooltip of the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1155 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1156 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
|
1157 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1158 this->SetIndex(index); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1159 this->SetMinimalSize(0, 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1160 this->SetResize(0, 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1161 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1162 switch (tp) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1163 case WWT_EMPTY: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1164 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1165 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1166 case WWT_PUSHBTN: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1167 this->SetFill(false, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1168 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1169 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1170 case WWT_IMGBTN: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1171 case WWT_PUSHIMGBTN: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1172 case WWT_IMGBTN_2: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1173 this->SetFill(false, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1174 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1175 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1176 case WWT_TEXTBTN: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1177 case WWT_PUSHTXTBTN: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1178 case WWT_TEXTBTN_2: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1179 case WWT_LABEL: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1180 case WWT_TEXT: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1181 case WWT_MATRIX: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1182 case WWT_EDITBOX: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1183 this->SetFill(false, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1184 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1185 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1186 case WWT_SCROLLBAR: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1187 case WWT_SCROLL2BAR: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1188 this->SetFill(false, true); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1189 this->SetResize(0, 1); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1190 this->min_x = 12; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1191 this->SetDataTip(0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1192 break; |
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 case WWT_CAPTION: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1195 this->SetFill(true, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1196 this->SetResize(1, 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1197 this->min_y = 14; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1198 this->SetDataTip(0x0, STR_018C_WINDOW_TITLE_DRAG_THIS); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1199 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1200 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1201 case WWT_HSCROLLBAR: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1202 this->SetFill(true, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1203 this->SetResize(1, 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1204 this->min_y = 12; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1205 this->SetDataTip(0x0, STR_HSCROLL_BAR_SCROLLS_LIST); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1206 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1207 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1208 case WWT_STICKYBOX: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1209 this->SetFill(false, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1210 this->SetMinimalSize(12, 14); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1211 this->SetDataTip(STR_NULL, STR_STICKY_BUTTON); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1212 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1213 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1214 case WWT_RESIZEBOX: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1215 this->SetFill(false, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1216 this->SetMinimalSize(12, 12); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1217 this->SetDataTip(STR_NULL, STR_RESIZE_BUTTON); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1218 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1219 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1220 case WWT_CLOSEBOX: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1221 this->SetFill(false, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1222 this->SetMinimalSize(11, 14); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1223 this->SetDataTip(STR_00C5, STR_018B_CLOSE_WINDOW); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1224 break; |
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 case WWT_DROPDOWN: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1227 this->SetFill(false, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1228 this->min_y = 12; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1229 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1230 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1231 default: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1232 NOT_REACHED(); |
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 } |
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 * Intialize nested widget tree and convert to widget array. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1238 * @param nwid Nested widget tree. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1239 * @param rtl Direction of the language. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1240 * @return Widget array with the converted widgets. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1241 * @note Caller should release returned widget array with \c free(widgets). |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1242 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1243 Widget *InitializeNWidgets(NWidgetBase *nwid, bool rtl) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1244 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1245 /* Initialize nested widgets. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1246 int biggest_index = nwid->ComputeMinimalSize(); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1247 nwid->AssignMinimalPosition(0, 0, nwid->min_x, nwid->min_y, (nwid->resize_x > 0), (nwid->resize_y > 0), rtl); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1248 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1249 /* 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
|
1250 Widget *widgets = MallocT<Widget>(biggest_index + 2); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1251 int i; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1252 for (i = 0; i < biggest_index + 2; i++) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1253 widgets[i].type = WWT_LAST; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1254 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1255 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1256 /* Store nested widgets in the array. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1257 nwid->StoreWidgets(widgets, biggest_index + 1, false, false, rtl); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1258 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1259 /* Check that all widgets are used. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1260 for (i = 0; i < biggest_index + 2; i++) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1261 if (widgets[i].type == WWT_LAST) break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1262 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1263 assert(i == biggest_index + 1); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1264 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1265 /* Fill terminating widget */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1266 static const Widget last_widget = {WIDGETS_END}; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1267 widgets[biggest_index + 1] = last_widget; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1268 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1269 return widgets; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1270 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1271 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1272 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1273 * 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
|
1274 * @param orig Pointer to original widget array. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1275 * @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
|
1276 * @param report Report differences to 'misc' debug stream. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1277 * @return Both widget arrays are equal. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1278 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1279 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
|
1280 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1281 #define CHECK(var, prn) \ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1282 if (ow->var != gw->var) { \ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1283 same = false; \ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1284 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
|
1285 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1286 #define CHECK_COORD(var) \ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1287 if (ow->var != gw->var) { \ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1288 same = false; \ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1289 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
|
1290 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1291 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1292 bool same = true; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1293 for(int idx = 0; ; idx++) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1294 const Widget *ow = orig + idx; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1295 const Widget *gw = gen + idx; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1296 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1297 CHECK(type, "%d") |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1298 CHECK(display_flags, "0x%x") |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1299 CHECK(colour, "%d") |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1300 CHECK_COORD(left) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1301 CHECK_COORD(right) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1302 CHECK_COORD(top) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1303 CHECK_COORD(bottom) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1304 CHECK(data, "%u") |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1305 CHECK(tooltips, "%u") |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1306 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1307 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
|
1308 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1309 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1310 return same; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1311 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1312 #undef CHECK |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1313 #undef CHECK_COORD |
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 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1316 /* == Conversion code from NWidgetPart array to NWidgetBase* tree == */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1317 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1318 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1319 * 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
|
1320 * |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1321 * 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
|
1322 * settings that follow it, until encountering a #EndContainer, another |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1323 * #NWidget, or the end of the parts array. |
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 * @param parts Array with parts of the nested widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1326 * @param count Length of the \a parts array. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1327 * @param dest Address of pointer to use for returning the composed widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1328 * @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
|
1329 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1330 static int MakeNWidget(const NWidgetPart *parts, int count, NWidgetBase **dest) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1331 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1332 int num_used = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1333 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1334 *dest = NULL; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1335 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1336 while (count > num_used) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1337 switch (parts->type) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1338 case NWID_SPACER: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1339 if (*dest != NULL) return num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1340 *dest = new NWidgetSpacer(0, 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1341 break; |
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 case NWID_HORIZONTAL: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1344 if (*dest != NULL) return num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1345 *dest = new NWidgetHorizontal(); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1346 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1347 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1348 case WWT_PANEL: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1349 case WWT_INSET: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1350 case WWT_FRAME: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1351 if (*dest != NULL) return num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1352 *dest = new NWidgetBackground(parts->type, parts->u.widget.colour, parts->u.widget.index); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1353 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1354 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1355 case NWID_VERTICAL: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1356 if (*dest != NULL) return num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1357 *dest = new NWidgetVertical(); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1358 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1359 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1360 case WPT_RESIZE: { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1361 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1362 if (nwrb != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1363 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
|
1364 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
|
1365 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1366 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1367 } |
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 case WPT_RESIZE_PTR: { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1370 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1371 if (nwrb != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1372 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
|
1373 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
|
1374 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1375 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1376 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1377 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1378 case WPT_MINSIZE: { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1379 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1380 if (nwrb != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1381 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
|
1382 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
|
1383 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1384 break; |
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 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1387 case WPT_MINSIZE_PTR: { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1388 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1389 if (nwrb != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1390 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
|
1391 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
|
1392 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1393 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1394 } |
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 case WPT_FILL: { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1397 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1398 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
|
1399 break; |
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 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1402 case WPT_DATATIP: { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1403 NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1404 if (nwc != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1405 nwc->widget_data = parts->u.data_tip.data; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1406 nwc->tool_tip = parts->u.data_tip.tooltip; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1407 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1408 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1409 } |
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 case WPT_DATATIP_PTR: { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1412 NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1413 if (nwc != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1414 nwc->widget_data = parts->u.datatip_ptr->data; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1415 nwc->tool_tip = parts->u.datatip_ptr->tooltip; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1416 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1417 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1418 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1419 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1420 case WPT_ENDCONTAINER: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1421 return num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1422 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1423 default: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1424 if (*dest != NULL) return num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1425 assert((parts->type & WWT_MASK) < NWID_HORIZONTAL); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1426 *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
|
1427 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1428 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1429 num_used++; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1430 parts++; |
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 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1433 return num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1434 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1435 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1436 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1437 * 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
|
1438 * @param parts Array with parts of the nested widgets. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1439 * @param count Length of the \a parts array. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1440 * @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
|
1441 * @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
|
1442 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1443 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
|
1444 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1445 /* 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
|
1446 NWidgetContainer *nwid_cont = dynamic_cast<NWidgetContainer *>(parent); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1447 NWidgetBackground *nwid_parent = dynamic_cast<NWidgetBackground *>(parent); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1448 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
|
1449 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1450 int total_used = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1451 while (true) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1452 NWidgetBase *sub_widget = NULL; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1453 int num_used = MakeNWidget(parts, count - total_used, &sub_widget); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1454 parts += num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1455 total_used += num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1456 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1457 /* Break out of loop when end reached */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1458 if (sub_widget == NULL) break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1459 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1460 /* Add sub_widget to parent container. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1461 if (nwid_cont) nwid_cont->Add(sub_widget); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1462 if (nwid_parent) nwid_parent->Add(sub_widget); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1463 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1464 /* 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
|
1465 WidgetType tp = sub_widget->type; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1466 if (tp == NWID_HORIZONTAL || tp == NWID_VERTICAL || tp == WWT_PANEL || tp == WWT_FRAME || tp == WWT_INSET) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1467 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
|
1468 parts += num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1469 total_used += num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1470 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1471 } |
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 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
|
1474 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1475 assert(total_used < count); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1476 assert(parts->type == WPT_ENDCONTAINER); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1477 return total_used + 1; // *parts is also 'used' |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1478 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1479 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1480 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1481 * 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
|
1482 * @param parts Array with parts of the widgets. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1483 * @param count Length of the \a parts array. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1484 * @return Root of the nested widget tree, a vertical container containing the entire GUI. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1485 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1486 NWidgetContainer *MakeNWidgets(const NWidgetPart *parts, int count) |
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 NWidgetContainer *cont = new NWidgetVertical(); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1489 MakeWidgetTree(parts, count, cont); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1490 return cont; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1491 } |