Mercurial > hg > openttd
annotate src/widget.cpp @ 11511:bf92950ea00b draft
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
author | yexo <yexo@openttd.org> |
---|---|
date | Sat, 28 Mar 2009 11:13:39 +0000 (2009-03-28) |
parents | d29f1358f95b |
children | 2ee677c87220 |
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); |
11472
cb478e40b8e2
(svn r15833) -Fix: alignment of up/down arrows and closebox when in RTL 'view'
rubidium <rubidium@openttd.org>
parents:
11468
diff
changeset
|
322 DrawString(r.left + clicked, r.right + clicked, r.top + clicked, UPARROW, TC_BLACK, SA_CENTER); |
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); |
11472
cb478e40b8e2
(svn r15833) -Fix: alignment of up/down arrows and closebox when in RTL 'view'
rubidium <rubidium@openttd.org>
parents:
11468
diff
changeset
|
326 DrawString(r.left + clicked, r.right + clicked, r.bottom - 9 + clicked, DOWNARROW, TC_BLACK, SA_CENTER); |
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); |
11472
cb478e40b8e2
(svn r15833) -Fix: alignment of up/down arrows and closebox when in RTL 'view'
rubidium <rubidium@openttd.org>
parents:
11468
diff
changeset
|
353 DrawString(r.left + clicked, r.right + clicked, r.top + clicked, UPARROW, TC_BLACK, SA_CENTER); |
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); |
11472
cb478e40b8e2
(svn r15833) -Fix: alignment of up/down arrows and closebox when in RTL 'view'
rubidium <rubidium@openttd.org>
parents:
11468
diff
changeset
|
357 DrawString(r.left + clicked, r.right + clicked, r.bottom - 9 + clicked, DOWNARROW, TC_BLACK, SA_CENTER); |
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 */ |
11468
5112363fd4ae
(svn r15827) -Fix (r15823): line still was a bit too long
yexo <yexo@openttd.org>
parents:
11467
diff
changeset
|
429 GfxFillRect(r.left, r.top + 4, x2 - 2, r.top + 4, c1); |
5112363fd4ae
(svn r15827) -Fix (r15823): line still was a bit too long
yexo <yexo@openttd.org>
parents:
11467
diff
changeset
|
430 GfxFillRect(r.left + 1, r.top + 5, x2 - 2, r.top + 5, c2); |
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
|
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); |
11472
cb478e40b8e2
(svn r15833) -Fix: alignment of up/down arrows and closebox when in RTL 'view'
rubidium <rubidium@openttd.org>
parents:
11468
diff
changeset
|
480 DrawString(r.left, r.right, r.top + 2, str, TC_FROMSTRING, SA_CENTER); |
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); |
11472
cb478e40b8e2
(svn r15833) -Fix: alignment of up/down arrows and closebox when in RTL 'view'
rubidium <rubidium@openttd.org>
parents:
11468
diff
changeset
|
503 DrawString(r.right - (clicked ? 10 : 11), r.right, r.top + (clicked ? 2 : 1), STR_0225, TC_BLACK, SA_CENTER); |
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
|
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); |
11472
cb478e40b8e2
(svn r15833) -Fix: alignment of up/down arrows and closebox when in RTL 'view'
rubidium <rubidium@openttd.org>
parents:
11468
diff
changeset
|
508 DrawString(r.left + clicked, r.left + 11, r.top + (clicked ? 2 : 1), STR_0225, TC_BLACK, SA_CENTER); |
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
|
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; |
11481
6f95c792064d
(svn r15842) -Codechange: make DrawSortButtonState RTL.
rubidium <rubidium@openttd.org>
parents:
11472
diff
changeset
|
636 int base = offset + (_dynlang.text_dir == TD_LTR ? this->widget[widget].right - 11 : this->widget[widget].left); |
6f95c792064d
(svn r15842) -Codechange: make DrawSortButtonState RTL.
rubidium <rubidium@openttd.org>
parents:
11472
diff
changeset
|
637 DrawString(base, base + 11, this->widget[widget].top + 1 + offset, state == SBS_DOWN ? DOWNARROW : UPARROW, TC_BLACK, SA_CENTER); |
8349
cbb2e614bcfa
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138 <peter1138@openttd.org>
parents:
8335
diff
changeset
|
638 } |
11461
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 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
641 /* == Nested widgets == */ |
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 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
644 * Base class constructor. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
645 * @param tp Nested widget type. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
646 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
647 NWidgetBase::NWidgetBase(WidgetType tp) : ZeroedMemoryAllocator() |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
648 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
649 this->type = tp; |
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 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
652 /* ~NWidgetContainer() takes care of #next and #prev data members. */ |
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 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
655 * @fn int NWidgetBase::ComputeMinimalSize() |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
656 * @brief Compute minimal size needed by the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
657 * |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
658 * 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
|
659 * display itself properly. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
660 * 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
|
661 * @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
|
662 * |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
663 * @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
|
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 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
667 * @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
|
668 * @brief Assign minimal size and position to the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
669 * @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
|
670 * @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
|
671 * @param given_width Width allocated to the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
672 * @param given_height Height allocated to the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
673 * @param allow_resize_x Horizontal resizing is allowed. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
674 * @param allow_resize_y Vertical resizing is allowed. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
675 * @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
|
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 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
679 * @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
|
680 * @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
|
681 * @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
|
682 * @param length Length of the array. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
683 * @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
|
684 * @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
|
685 * @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
|
686 * |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
687 * @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
|
688 * 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
|
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 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
692 * Constructor for resizable nested widgets. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
693 * @param tp Nested widget type. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
694 * @param fill_x Allow horizontal filling from initial size. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
695 * @param fill_y Allow vertical filling from initial size. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
696 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
697 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
|
698 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
699 this->fill_x = fill_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
700 this->fill_y = fill_y; |
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 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
704 * Set minimal size of the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
705 * @param min_x Horizontal minimal size of the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
706 * @param min_y Vertical minimal size of the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
707 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
708 void NWidgetResizeBase::SetMinimalSize(uint min_x, uint min_y) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
709 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
710 this->min_x = min_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
711 this->min_y = min_y; |
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 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
715 * Set the filling of the widget from initial size. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
716 * @param fill_x Allow horizontal filling from initial size. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
717 * @param fill_y Allow vertical filling from initial size. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
718 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
719 void NWidgetResizeBase::SetFill(bool fill_x, bool fill_y) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
720 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
721 this->fill_x = fill_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
722 this->fill_y = fill_y; |
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 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
726 * Set resize step of the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
727 * @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
|
728 * @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
|
729 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
730 void NWidgetResizeBase::SetResize(uint resize_x, uint resize_y) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
731 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
732 this->resize_x = resize_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
733 this->resize_y = resize_y; |
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 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
736 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
|
737 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
738 this->pos_x = x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
739 this->pos_y = y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
740 this->min_x = given_width; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
741 this->min_y = given_height; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
742 if (!allow_resize_x) this->resize_x = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
743 if (!allow_resize_y) this->resize_y = 0; |
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 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
747 * Initialization of a 'real' widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
748 * @param tp Type of the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
749 * @param colour Colour of the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
750 * @param fill_x Default horizontal filling. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
751 * @param fill_y Default vertical filling. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
752 * @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
|
753 * @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
|
754 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
755 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
|
756 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
757 this->colour = colour; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
758 this->index = -1; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
759 this->widget_data = widget_data; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
760 this->tool_tip = tool_tip; |
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 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
764 * 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
|
765 * @param index Index to use. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
766 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
767 void NWidgetCore::SetIndex(int index) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
768 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
769 assert(index >= 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
770 this->index = index; |
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 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
774 * Set data and tool tip of the nested widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
775 * @param widget_data Data to use. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
776 * @param tool_tip Tool tip string to use. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
777 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
778 void NWidgetCore::SetDataTip(uint16 widget_data, StringID tool_tip) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
779 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
780 this->widget_data = widget_data; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
781 this->tool_tip = tool_tip; |
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 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
784 int NWidgetCore::ComputeMinimalSize() |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
785 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
786 /* All data is already at the right place. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
787 return this->index; |
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 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
790 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
|
791 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
792 if (this->index < 0) return; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
793 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
794 assert(this->index < length); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
795 Widget *w = widgets + this->index; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
796 assert(w->type == WWT_LAST); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
797 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
798 DisplayFlags flags = RESIZE_NONE; // resize flags. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
799 /* Compute vertical resizing. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
800 if (top_moving) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
801 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
|
802 } else if(this->resize_y > 0) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
803 flags |= RESIZE_BOTTOM; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
804 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
805 /* Compute horizontal resizing. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
806 if (left_moving) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
807 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
|
808 } else if (this->resize_x > 0) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
809 flags |= RESIZE_RIGHT; |
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 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
812 /* Copy nested widget data into its widget array entry. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
813 w->type = this->type; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
814 w->display_flags = flags; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
815 w->colour = this->colour; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
816 w->left = this->pos_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
817 w->right = this->pos_x + this->min_x - 1; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
818 w->top = this->pos_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
819 w->bottom = this->pos_y + this->min_y - 1; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
820 w->data = this->widget_data; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
821 w->tooltips = this->tool_tip; |
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 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
825 * Constructor container baseclass. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
826 * @param tp Type of the container. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
827 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
828 NWidgetContainer::NWidgetContainer(WidgetType tp) : NWidgetBase(tp) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
829 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
830 this->head = NULL; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
831 this->tail = NULL; |
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 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
834 NWidgetContainer::~NWidgetContainer() |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
835 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
836 while (this->head != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
837 NWidgetBase *wid = this->head->next; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
838 delete this->head; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
839 this->head = wid; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
840 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
841 this->tail = NULL; |
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 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
845 * Append widget \a wid to container. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
846 * @param wid Widget to append. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
847 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
848 void NWidgetContainer::Add(NWidgetBase *wid) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
849 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
850 assert(wid->next == NULL && wid->prev == NULL); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
851 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
852 if (this->head == NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
853 this->head = wid; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
854 this->tail = wid; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
855 } else { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
856 assert(this->tail != NULL); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
857 assert(this->tail->next == NULL); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
858 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
859 this->tail->next = wid; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
860 wid->prev = this->tail; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
861 this->tail = wid; |
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 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
865 NWidgetHorizontal::NWidgetHorizontal() : NWidgetContainer(NWID_HORIZONTAL) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
866 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
867 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
868 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
869 int NWidgetHorizontal::ComputeMinimalSize() |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
870 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
871 int biggest_index = -1; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
872 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
|
873 this->min_y = 0; // Biggest child. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
874 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
|
875 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
|
876 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
|
877 this->resize_y = 1; // smallest common child resize step |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
878 |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
879 if (this->head != NULL) this->head->padding_left += this->pip_pre; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
880 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
|
881 int idx = child_wid->ComputeMinimalSize(); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
882 biggest_index = max(biggest_index, idx); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
883 |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
884 if (child_wid->next != NULL) { |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
885 child_wid->padding_right += this->pip_inter; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
886 } else { |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
887 child_wid->padding_right += this->pip_post; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
888 } |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
889 |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
890 this->min_x += child_wid->min_x + child_wid->padding_left + child_wid->padding_right; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
891 this->min_y = max(this->min_y, child_wid->min_y + child_wid->padding_top + child_wid->padding_bottom); |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
892 this->fill_x |= child_wid->fill_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
893 this->fill_y &= child_wid->fill_y; |
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 if (child_wid->resize_x > 0) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
896 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
|
897 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
898 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
|
899 } |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
900 /* We need to zero the PIP settings so we can re-initialize the tree. */ |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
901 this->pip_pre = this->pip_inter = this->pip_post = 0; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
902 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
903 return biggest_index; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
904 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
905 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
906 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
|
907 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
908 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
|
909 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
910 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
|
911 this->pos_x = x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
912 this->pos_y = y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
913 this->min_x = given_width; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
914 this->min_y = given_height; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
915 if (!allow_resize_x) this->resize_x = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
916 if (!allow_resize_y) this->resize_y = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
917 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
918 /* 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
|
919 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
|
920 NWidgetBase *child_wid; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
921 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
|
922 if (child_wid->fill_x) num_changing_childs++; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
923 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
924 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
925 /* Fill and position the child widgets. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
926 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
|
927 allow_resize_x = (this->resize_x > 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
928 child_wid = rtl ? this->tail : this->head; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
929 while (child_wid != NULL) { |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
930 assert(given_height >= child_wid->min_y + child_wid->padding_top + child_wid->padding_bottom); |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
931 /* Decide about vertical filling of the child. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
932 uint child_height; // Height of the child widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
933 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
|
934 if (child_wid->fill_y) { |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
935 child_height = given_height - child_wid->padding_top - child_wid->padding_bottom; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
936 child_pos_y = child_wid->padding_top; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
937 } else { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
938 child_height = child_wid->min_y; |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
939 child_pos_y = (given_height - child_wid->padding_top - child_wid->padding_bottom - child_height) / 2 + child_wid->padding_top; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
940 } |
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 /* Decide about horizontal filling of the child. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
943 uint child_width; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
944 child_width = child_wid->min_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
945 if (child_wid->fill_x && num_changing_childs > 0) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
946 /* 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
|
947 uint increment = additional_length / num_changing_childs; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
948 additional_length -= increment; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
949 num_changing_childs--; |
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 child_width += increment; |
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 |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
954 child_wid->AssignMinimalPosition(x + position + (rtl ? child_wid->padding_right : child_wid->padding_left), y + child_pos_y, child_width, child_height, allow_resize_x, (this->resize_y > 0), rtl); |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
955 position += child_width + child_wid->padding_right + child_wid->padding_left; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
956 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
|
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 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
|
963 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
964 NWidgetBase *child_wid = rtl ? this->tail : this->head; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
965 while (child_wid != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
966 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
|
967 left_moving |= (child_wid->resize_x > 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
968 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
969 child_wid = rtl ? child_wid->prev : child_wid->next; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
970 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
971 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
972 |
11500
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
973 NWidgetHorizontalLTR::NWidgetHorizontalLTR() : NWidgetHorizontal() |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
974 { |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
975 this->type = NWID_HORIZONTAL_LTR; |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
976 } |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
977 |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
978 void NWidgetHorizontalLTR::AssignMinimalPosition(uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl) |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
979 { |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
980 NWidgetHorizontal::AssignMinimalPosition(x, y, given_width, given_height, allow_resize_x, allow_resize_y, false); |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
981 } |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
982 |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
983 void NWidgetHorizontalLTR::StoreWidgets(Widget *widgets, int length, bool left_moving, bool top_moving, bool rtl) |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
984 { |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
985 NWidgetHorizontal::StoreWidgets(widgets, length, left_moving, top_moving, false); |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
986 } |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
987 |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
988 NWidgetVertical::NWidgetVertical() : NWidgetContainer(NWID_VERTICAL) |
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 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
992 int NWidgetVertical::ComputeMinimalSize() |
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 int biggest_index = -1; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
995 this->min_x = 0; // Biggest child. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
996 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
|
997 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
|
998 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
|
999 this->resize_x = 1; // smallest common child resize step |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1000 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
|
1001 |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1002 if (this->head != NULL) this->head->padding_top += this->pip_pre; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1003 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
|
1004 int idx = child_wid->ComputeMinimalSize(); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1005 biggest_index = max(biggest_index, idx); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1006 |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1007 if (child_wid->next != NULL) { |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1008 child_wid->padding_bottom += this->pip_inter; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1009 } else { |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1010 child_wid->padding_bottom += this->pip_post; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1011 } |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1012 |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1013 this->min_y += child_wid->min_y + child_wid->padding_top + child_wid->padding_bottom; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1014 this->min_x = max(this->min_x, child_wid->min_x + child_wid->padding_left + child_wid->padding_right); |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1015 this->fill_y |= child_wid->fill_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1016 this->fill_x &= child_wid->fill_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1017 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1018 if (child_wid->resize_y > 0) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1019 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
|
1020 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1021 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
|
1022 } |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1023 /* We need to zero the PIP settings so we can re-initialize the tree. */ |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1024 this->pip_pre = this->pip_inter = this->pip_post = 0; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1025 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1026 return biggest_index; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1027 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1028 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1029 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
|
1030 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1031 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
|
1032 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1033 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
|
1034 this->pos_x = x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1035 this->pos_y = y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1036 this->min_x = given_width; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1037 this->min_y = given_height; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1038 if (!allow_resize_x) this->resize_x = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1039 if (!allow_resize_y) this->resize_y = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1040 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1041 /* 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
|
1042 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
|
1043 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
|
1044 if (child_wid->fill_y) num_changing_childs++; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1045 } |
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 /* Fill and position the child widgets. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1048 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
|
1049 allow_resize_y = (this->resize_y > 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1050 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) { |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1051 assert(given_width >= child_wid->min_x + child_wid->padding_left + child_wid->padding_right); |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1052 /* Decide about horizontal filling of the child. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1053 uint child_width; // Width of the child widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1054 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
|
1055 if (child_wid->fill_x) { |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1056 child_width = given_width - child_wid->padding_left - child_wid->padding_right; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1057 child_pos_x = (rtl ? child_wid->padding_right : child_wid->padding_left); |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1058 } else { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1059 child_width = child_wid->min_x; |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1060 child_pos_x = (given_width - child_wid->padding_left - child_wid->padding_right - child_width) / 2 + (rtl ? child_wid->padding_right : child_wid->padding_left); |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1061 } |
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 /* Decide about vertical filling of the child. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1064 uint child_height; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1065 child_height = child_wid->min_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1066 if (child_wid->fill_y && num_changing_childs > 0) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1067 /* 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
|
1068 uint increment = additional_length / num_changing_childs; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1069 additional_length -= increment; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1070 num_changing_childs--; |
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 child_height += increment; |
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 |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1075 child_wid->AssignMinimalPosition(x + child_pos_x, y + position + child_wid->padding_top, child_width, child_height, (this->resize_x > 0), allow_resize_y, rtl); |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1076 position += child_height + child_wid->padding_top + child_wid->padding_bottom; |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1077 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
|
1078 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1079 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1080 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1081 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
|
1082 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1083 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
|
1084 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
|
1085 top_moving |= (child_wid->resize_y > 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1086 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1087 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1088 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1089 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1090 * Generic spacer widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1091 * @param length Horizontal size of the spacer widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1092 * @param height Vertical size of the spacer widget. |
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 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
|
1095 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1096 this->SetMinimalSize(length, height); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1097 this->SetResize(0, 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1098 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1099 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1100 int NWidgetSpacer::ComputeMinimalSize() |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1101 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1102 /* No further computation needed. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1103 return -1; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1104 } |
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 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
|
1107 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1108 /* Spacer widgets are never stored in the widget array. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1109 } |
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 * Constructor parent nested widgets. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1113 * @param tp Type of parent widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1114 * @param colour Colour of the parent widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1115 * @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
|
1116 * @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
|
1117 * vertical container will be inserted while adding the first |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1118 * child widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1119 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1120 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
|
1121 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1122 this->SetIndex(index); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1123 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
|
1124 assert(index >= 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1125 this->child = child; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1126 } |
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 NWidgetBackground::~NWidgetBackground() |
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 if (this->child != NULL) delete this->child; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1131 } |
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 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1134 * Add a child to the parent. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1135 * @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
|
1136 * |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1137 * 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
|
1138 * 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
|
1139 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1140 void NWidgetBackground::Add(NWidgetBase *nwid) |
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 if (this->child == NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1143 this->child = new NWidgetVertical(); |
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 this->child->Add(nwid); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1146 } |
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 int NWidgetBackground::ComputeMinimalSize() |
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 int biggest_index = this->index; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1151 if (this->child != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1152 int idx = this->child->ComputeMinimalSize(); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1153 biggest_index = max(biggest_index, idx); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1154 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1155 this->min_x = this->child->min_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1156 this->min_y = this->child->min_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1157 this->fill_x = this->child->fill_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1158 this->fill_y = this->child->fill_y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1159 this->resize_x = this->child->resize_x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1160 this->resize_y = this->child->resize_y; |
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 /* 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
|
1163 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1164 return biggest_index; |
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 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1167 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
|
1168 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1169 this->pos_x = x; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1170 this->pos_y = y; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1171 this->min_x = given_width; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1172 this->min_y = given_height; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1173 if (!allow_resize_x) this->resize_x = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1174 if (!allow_resize_y) this->resize_y = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1175 |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1176 if (this->child != NULL) { |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1177 uint x_offset = (rtl ? this->child->padding_right : this->child->padding_left); |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1178 uint width = given_width - this->child->padding_right - this->child->padding_left; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1179 uint height = given_height - this->child->padding_top - this->child->padding_bottom; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1180 this->child->AssignMinimalPosition(x + x_offset, y + this->child->padding_top, width, height, (this->resize_x > 0), (this->resize_y > 0), rtl); |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1181 } |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1182 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1183 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1184 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
|
1185 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1186 NWidgetCore::StoreWidgets(widgets, length, left_moving, top_moving, rtl); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1187 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
|
1188 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1189 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1190 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1191 * Nested leaf widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1192 * @param tp Type of leaf widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1193 * @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
|
1194 * @param data Data of the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1195 * @param tip Tooltip of the widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1196 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1197 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
|
1198 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1199 this->SetIndex(index); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1200 this->SetMinimalSize(0, 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1201 this->SetResize(0, 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1202 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1203 switch (tp) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1204 case WWT_EMPTY: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1205 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1206 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1207 case WWT_PUSHBTN: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1208 this->SetFill(false, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1209 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1210 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1211 case WWT_IMGBTN: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1212 case WWT_PUSHIMGBTN: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1213 case WWT_IMGBTN_2: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1214 this->SetFill(false, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1215 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1216 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1217 case WWT_TEXTBTN: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1218 case WWT_PUSHTXTBTN: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1219 case WWT_TEXTBTN_2: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1220 case WWT_LABEL: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1221 case WWT_TEXT: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1222 case WWT_MATRIX: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1223 case WWT_EDITBOX: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1224 this->SetFill(false, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1225 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1226 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1227 case WWT_SCROLLBAR: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1228 case WWT_SCROLL2BAR: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1229 this->SetFill(false, true); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1230 this->SetResize(0, 1); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1231 this->min_x = 12; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1232 this->SetDataTip(0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1233 break; |
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 case WWT_CAPTION: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1236 this->SetFill(true, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1237 this->SetResize(1, 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1238 this->min_y = 14; |
11495
66d0ac80f849
(svn r15856) -Fix (r15819): NWidgetLeaf constructor don't use the provided window caption string
glx <glx@openttd.org>
parents:
11481
diff
changeset
|
1239 this->SetDataTip(data, STR_018C_WINDOW_TITLE_DRAG_THIS); |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1240 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1241 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1242 case WWT_HSCROLLBAR: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1243 this->SetFill(true, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1244 this->SetResize(1, 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1245 this->min_y = 12; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1246 this->SetDataTip(0x0, STR_HSCROLL_BAR_SCROLLS_LIST); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1247 break; |
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 case WWT_STICKYBOX: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1250 this->SetFill(false, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1251 this->SetMinimalSize(12, 14); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1252 this->SetDataTip(STR_NULL, STR_STICKY_BUTTON); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1253 break; |
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 case WWT_RESIZEBOX: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1256 this->SetFill(false, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1257 this->SetMinimalSize(12, 12); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1258 this->SetDataTip(STR_NULL, STR_RESIZE_BUTTON); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1259 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1260 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1261 case WWT_CLOSEBOX: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1262 this->SetFill(false, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1263 this->SetMinimalSize(11, 14); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1264 this->SetDataTip(STR_00C5, STR_018B_CLOSE_WINDOW); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1265 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1266 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1267 case WWT_DROPDOWN: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1268 this->SetFill(false, false); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1269 this->min_y = 12; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1270 break; |
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 default: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1273 NOT_REACHED(); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1274 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1275 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1276 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1277 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1278 * Intialize nested widget tree and convert to widget array. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1279 * @param nwid Nested widget tree. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1280 * @param rtl Direction of the language. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1281 * @return Widget array with the converted widgets. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1282 * @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
|
1283 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1284 Widget *InitializeNWidgets(NWidgetBase *nwid, bool rtl) |
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 /* Initialize nested widgets. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1287 int biggest_index = nwid->ComputeMinimalSize(); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1288 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
|
1289 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1290 /* 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
|
1291 Widget *widgets = MallocT<Widget>(biggest_index + 2); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1292 int i; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1293 for (i = 0; i < biggest_index + 2; i++) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1294 widgets[i].type = WWT_LAST; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1295 } |
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 /* Store nested widgets in the array. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1298 nwid->StoreWidgets(widgets, biggest_index + 1, false, false, rtl); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1299 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1300 /* Check that all widgets are used. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1301 for (i = 0; i < biggest_index + 2; i++) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1302 if (widgets[i].type == WWT_LAST) break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1303 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1304 assert(i == biggest_index + 1); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1305 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1306 /* Fill terminating widget */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1307 static const Widget last_widget = {WIDGETS_END}; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1308 widgets[biggest_index + 1] = last_widget; |
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 widgets; |
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 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1313 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1314 * 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
|
1315 * @param orig Pointer to original widget array. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1316 * @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
|
1317 * @param report Report differences to 'misc' debug stream. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1318 * @return Both widget arrays are equal. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1319 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1320 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
|
1321 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1322 #define CHECK(var, prn) \ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1323 if (ow->var != gw->var) { \ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1324 same = false; \ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1325 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
|
1326 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1327 #define CHECK_COORD(var) \ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1328 if (ow->var != gw->var) { \ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1329 same = false; \ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1330 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
|
1331 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1332 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1333 bool same = true; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1334 for(int idx = 0; ; idx++) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1335 const Widget *ow = orig + idx; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1336 const Widget *gw = gen + idx; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1337 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1338 CHECK(type, "%d") |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1339 CHECK(display_flags, "0x%x") |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1340 CHECK(colour, "%d") |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1341 CHECK_COORD(left) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1342 CHECK_COORD(right) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1343 CHECK_COORD(top) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1344 CHECK_COORD(bottom) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1345 CHECK(data, "%u") |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1346 CHECK(tooltips, "%u") |
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 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
|
1349 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1350 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1351 return same; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1352 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1353 #undef CHECK |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1354 #undef CHECK_COORD |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1355 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1356 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1357 /* == Conversion code from NWidgetPart array to NWidgetBase* tree == */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1358 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1359 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1360 * 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
|
1361 * |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1362 * 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
|
1363 * settings that follow it, until encountering a #EndContainer, another |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1364 * #NWidget, or the end of the parts array. |
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 * @param parts Array with parts of the nested widget. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1367 * @param count Length of the \a parts array. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1368 * @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
|
1369 * @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
|
1370 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1371 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
|
1372 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1373 int num_used = 0; |
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 *dest = NULL; |
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 while (count > num_used) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1378 switch (parts->type) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1379 case NWID_SPACER: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1380 if (*dest != NULL) return num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1381 *dest = new NWidgetSpacer(0, 0); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1382 break; |
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 case NWID_HORIZONTAL: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1385 if (*dest != NULL) return num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1386 *dest = new NWidgetHorizontal(); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1387 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1388 |
11500
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
1389 case NWID_HORIZONTAL_LTR: |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
1390 if (*dest != NULL) return num_used; |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
1391 *dest = new NWidgetHorizontalLTR(); |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
1392 break; |
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
1393 |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1394 case WWT_PANEL: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1395 case WWT_INSET: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1396 case WWT_FRAME: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1397 if (*dest != NULL) return num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1398 *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
|
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 case NWID_VERTICAL: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1402 if (*dest != NULL) return num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1403 *dest = new NWidgetVertical(); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1404 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1405 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1406 case WPT_RESIZE: { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1407 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1408 if (nwrb != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1409 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
|
1410 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
|
1411 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1412 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1413 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1414 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1415 case WPT_RESIZE_PTR: { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1416 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1417 if (nwrb != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1418 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
|
1419 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
|
1420 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1421 break; |
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 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1424 case WPT_MINSIZE: { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1425 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1426 if (nwrb != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1427 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
|
1428 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
|
1429 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1430 break; |
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 case WPT_MINSIZE_PTR: { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1434 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1435 if (nwrb != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1436 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
|
1437 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
|
1438 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1439 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1440 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1441 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1442 case WPT_FILL: { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1443 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1444 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
|
1445 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1446 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1447 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1448 case WPT_DATATIP: { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1449 NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1450 if (nwc != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1451 nwc->widget_data = parts->u.data_tip.data; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1452 nwc->tool_tip = parts->u.data_tip.tooltip; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1453 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1454 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1455 } |
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 case WPT_DATATIP_PTR: { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1458 NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1459 if (nwc != NULL) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1460 nwc->widget_data = parts->u.datatip_ptr->data; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1461 nwc->tool_tip = parts->u.datatip_ptr->tooltip; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1462 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1463 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1464 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1465 |
11511
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1466 case WPT_PADDING: { |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1467 NWidgetBase *nwb = *dest; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1468 if (nwb != NULL) { |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1469 nwb->padding_top = parts->u.padding.top; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1470 nwb->padding_right = parts->u.padding.right; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1471 nwb->padding_bottom = parts->u.padding.bottom; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1472 nwb->padding_left = parts->u.padding.left; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1473 } |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1474 break; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1475 } |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1476 |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1477 case WPT_PIPSPACE: { |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1478 NWidgetContainer *nwc = dynamic_cast<NWidgetContainer *>(*dest); |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1479 if (nwc != NULL) { |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1480 nwc->pip_pre = parts->u.pip.pre; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1481 nwc->pip_inter = parts->u.pip.inter; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1482 nwc->pip_post = parts->u.pip.post; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1483 } |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1484 break; |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1485 } |
bf92950ea00b
(svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents:
11500
diff
changeset
|
1486 |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1487 case WPT_ENDCONTAINER: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1488 return num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1489 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1490 default: |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1491 if (*dest != NULL) return num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1492 assert((parts->type & WWT_MASK) < NWID_HORIZONTAL); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1493 *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
|
1494 break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1495 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1496 num_used++; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1497 parts++; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1498 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1499 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1500 return num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1501 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1502 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1503 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1504 * 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
|
1505 * @param parts Array with parts of the nested widgets. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1506 * @param count Length of the \a parts array. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1507 * @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
|
1508 * @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
|
1509 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1510 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
|
1511 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1512 /* 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
|
1513 NWidgetContainer *nwid_cont = dynamic_cast<NWidgetContainer *>(parent); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1514 NWidgetBackground *nwid_parent = dynamic_cast<NWidgetBackground *>(parent); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1515 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
|
1516 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1517 int total_used = 0; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1518 while (true) { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1519 NWidgetBase *sub_widget = NULL; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1520 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
|
1521 parts += num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1522 total_used += num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1523 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1524 /* Break out of loop when end reached */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1525 if (sub_widget == NULL) break; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1526 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1527 /* Add sub_widget to parent container. */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1528 if (nwid_cont) nwid_cont->Add(sub_widget); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1529 if (nwid_parent) nwid_parent->Add(sub_widget); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1530 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1531 /* 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
|
1532 WidgetType tp = sub_widget->type; |
11500
d29f1358f95b
(svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents:
11495
diff
changeset
|
1533 if (tp == NWID_HORIZONTAL || tp == NWID_HORIZONTAL_LTR || tp == NWID_VERTICAL || tp == WWT_PANEL || tp == WWT_FRAME || tp == WWT_INSET) { |
11461
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1534 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
|
1535 parts += num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1536 total_used += num_used; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1537 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1538 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1539 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1540 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
|
1541 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1542 assert(total_used < count); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1543 assert(parts->type == WPT_ENDCONTAINER); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1544 return total_used + 1; // *parts is also 'used' |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1545 } |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1546 |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1547 /** |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1548 * 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
|
1549 * @param parts Array with parts of the widgets. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1550 * @param count Length of the \a parts array. |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1551 * @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
|
1552 */ |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1553 NWidgetContainer *MakeNWidgets(const NWidgetPart *parts, int count) |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1554 { |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1555 NWidgetContainer *cont = new NWidgetVertical(); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1556 MakeWidgetTree(parts, count, cont); |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1557 return cont; |
0ec1833138f7
(svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents:
11454
diff
changeset
|
1558 } |