annotate src/widget.cpp @ 12403:0024ba6bb40e draft

(svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
author alberth <alberth@openttd.org>
date Wed, 15 Jul 2009 22:17:08 +0000 (2009-07-15)
parents 62259c3dc887
children 375cd4fb8ae3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1 /* $Id$ */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2
9111
d48433370037 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium <rubidium@openttd.org>
parents: 8969
diff changeset
3 /** @file widget.cpp Handling of the default/simple widgets. */
6432
fc703c6dc92c (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas <belugas@openttd.org>
parents: 6278
diff changeset
4
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
5 #include "stdafx.h"
10208
39cf8eebfda5 (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents: 10207
diff changeset
6 #include "company_func.h"
8224
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8131
diff changeset
7 #include "gfx_func.h"
8106
47b1794a7eca (svn r11667) -Codechange: split window.h into a header that defines some 'global' window related types, on that defined 'global' window functions and one that defines functions and types only used by *_gui.cpps.
rubidium <rubidium@openttd.org>
parents: 8082
diff changeset
8 #include "window_gui.h"
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
9 #include "debug.h"
11465
4fc1be7900f4 (svn r15823) -Codechange: prepare the WWT_FRAME and WWT_DROPDOWN(IN) widget types for rtl languages.
yexo <yexo@openttd.org>
parents: 11461
diff changeset
10 #include "strings_func.h"
8131
e300ac8001ae (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium <rubidium@openttd.org>
parents: 8121
diff changeset
11
8264
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8254
diff changeset
12 #include "table/sprites.h"
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8254
diff changeset
13 #include "table/strings.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
14
11799
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
15 static const char *UPARROW = "\xEE\x8A\xA0"; ///< String containing an upwards pointing arrow.
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
16 static const char *DOWNARROW = "\xEE\x8A\xAA"; ///< String containing a downwards pointing arrow.
8349
cbb2e614bcfa (svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
peter1138 <peter1138@openttd.org>
parents: 8335
diff changeset
17
9773
fcce76c3bb3d (svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents: 9770
diff changeset
18 /**
fcce76c3bb3d (svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents: 9770
diff changeset
19 * Compute the vertical position of the draggable part of scrollbar
fcce76c3bb3d (svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents: 9770
diff changeset
20 * @param sb Scrollbar list data
fcce76c3bb3d (svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents: 9770
diff changeset
21 * @param top Top position of the scrollbar (top position of the up-button)
fcce76c3bb3d (svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents: 9770
diff changeset
22 * @param bottom Bottom position of the scrollbar (bottom position of the down-button)
fcce76c3bb3d (svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents: 9770
diff changeset
23 * @return A Point, with x containing the top coordinate of the draggable part, and
fcce76c3bb3d (svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents: 9770
diff changeset
24 * y containing the bottom coordinate of the draggable part
fcce76c3bb3d (svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents: 9770
diff changeset
25 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
26 static Point HandleScrollbarHittest(const Scrollbar *sb, int top, int bottom)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
27 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
28 Point pt;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
29 int height, count, pos, cap;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
30
9773
fcce76c3bb3d (svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents: 9770
diff changeset
31 top += 10; // top points to just below the up-button
fcce76c3bb3d (svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents: 9770
diff changeset
32 bottom -= 9; // bottom points to top of the down-button
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
33
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
34 height = (bottom - top);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
35
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
36 pos = sb->pos;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
37 count = sb->count;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
38 cap = sb->cap;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
39
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
40 if (count != 0) top += height * pos / count;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
41
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
42 if (cap > count) cap = count;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
43 if (count != 0) bottom -= (count - pos - cap) * height / count;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
44
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
45 pt.x = top;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
46 pt.y = bottom - 1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
47 return pt;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
48 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
49
12102
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
50 /**
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
51 * Compute new position of the scrollbar after a click and updates the window flags.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
52 * @param w Window on which a scroll was performed.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
53 * @param wtp Scrollbar widget type.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
54 * @param mi Minimum coordinate of the scroll bar.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
55 * @param ma Maximum coordinate of the scroll bar.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
56 * @param x The X coordinate of the mouse click.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
57 * @param y The Y coordinate of the mouse click.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
58 */
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
59 static void ScrollbarClickPositioning(Window *w, WidgetType wtp, int x, int y, int mi, int ma)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
60 {
12102
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
61 int pos;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
62 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
63
12102
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
64 switch (wtp) {
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
65 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
66 /* 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
67 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
68 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
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 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
78 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
79 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
80
ce8dc35932c3 (svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium <rubidium@openttd.org>
parents: 8418
diff changeset
81 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
82 /* 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
83 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
84 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
85 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
86 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
87 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
88
ce8dc35932c3 (svn r12405) -Codechange: some coding style and 'untodoifying' some comments that were certainly not todos.
rubidium <rubidium@openttd.org>
parents: 8418
diff changeset
89 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
90 }
8969
01cc3ee6ecb1 (svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium <rubidium@openttd.org>
parents: 8857
diff changeset
91 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
92 /* 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
93 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
94 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
95 _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
96 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
97 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
98 _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
99 } 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
100 /* 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
101 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
102
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
103 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
104 _scroller_click_timeout = 6;
12102
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
105 if (sb->pos + sb->cap < sb->count) sb->pos++;
5584
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 _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
108 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
109 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
110
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
111 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
112 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
113 } else if (pos > pt.y) {
12102
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
114 sb->pos = min(sb->pos + sb->cap, max(sb->count - sb->cap, 0));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
115 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
116 _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
117 _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
118 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
119 _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
120 _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
121 }
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
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
124 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
125 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
126
12102
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
127 /** Special handling for the scrollbar widget type.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
128 * Handles the special scrolling buttons and other scrolling.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
129 * @param w Window on which a scroll was performed.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
130 * @param wi Pointer to the scrollbar widget.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
131 * @param x The X coordinate of the mouse click.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
132 * @param y The Y coordinate of the mouse click.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
133 */
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
134 void ScrollbarClickHandler(Window *w, const Widget *wi, int x, int y)
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
135 {
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
136 int mi, ma;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
137
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
138 switch (wi->type) {
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
139 case WWT_SCROLLBAR:
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
140 /* vertical scroller */
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
141 mi = wi->top;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
142 ma = wi->bottom;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
143 break;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
144
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
145 case WWT_SCROLL2BAR:
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
146 /* 2nd vertical scroller */
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
147 mi = wi->top;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
148 ma = wi->bottom;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
149 break;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
150
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
151 case WWT_HSCROLLBAR:
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
152 /* horizontal scroller */
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
153 mi = wi->left;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
154 ma = wi->right;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
155 break;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
156
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
157 default: NOT_REACHED();
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
158 }
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
159 ScrollbarClickPositioning(w, wi->type, x, y, mi, ma);
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
160 }
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
161
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
162 /** Special handling for the scrollbar widget type.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
163 * Handles the special scrolling buttons and other scrolling.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
164 * @param w Window on which a scroll was performed.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
165 * @param nw Pointer to the scrollbar widget.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
166 * @param x The X coordinate of the mouse click.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
167 * @param y The Y coordinate of the mouse click.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
168 */
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
169 void ScrollbarClickHandler(Window *w, const NWidgetCore *nw, int x, int y)
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
170 {
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
171 int mi, ma;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
172
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
173 switch (nw->type) {
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
174 case WWT_SCROLLBAR:
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
175 /* vertical scroller */
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
176 mi = nw->pos_y;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
177 ma = nw->pos_y + nw->current_y;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
178 break;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
179
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
180 case WWT_SCROLL2BAR:
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
181 /* 2nd vertical scroller */
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
182 mi = nw->pos_y;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
183 ma = nw->pos_y + nw->current_y;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
184 break;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
185
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
186 case WWT_HSCROLLBAR:
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
187 /* horizontal scroller */
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
188 mi = nw->pos_x;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
189 ma = nw->pos_x + nw->current_x;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
190 break;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
191
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
192 default: NOT_REACHED();
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
193 }
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
194 ScrollbarClickPositioning(w, nw->type, x, y, mi, ma);
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
195 }
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
196
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
197 /** 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
198 * 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
199 * @param *w Window to look inside
6481
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6432
diff changeset
200 * @param x The Window client X coordinate
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6432
diff changeset
201 * @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
202 * @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
203 */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
204 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
205 {
12102
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
206 if (w->nested_root != NULL) {
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
207 NWidgetCore *nw = w->nested_root->GetWidgetFromPos(x, y);
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
208 return (nw != NULL) ? nw->index : -1;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
209 }
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
210
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
211 int found_index = -1;
12082
d092f17a921d (svn r16491) -Codechange: Added parentheses around bitwise operators for code style.
alberth <alberth@openttd.org>
parents: 11999
diff changeset
212 /* Go through the widgets and check if we find the widget that the coordinate is inside. */
d092f17a921d (svn r16491) -Codechange: Added parentheses around bitwise operators for code style.
alberth <alberth@openttd.org>
parents: 11999
diff changeset
213 for (uint index = 0; index < w->widget_count; 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
214 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
215 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
216
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
217 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
218 !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
219 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
220 }
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 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
224 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
225
9773
fcce76c3bb3d (svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents: 9770
diff changeset
226 /**
fcce76c3bb3d (svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents: 9770
diff changeset
227 * Draw frame rectangle.
fcce76c3bb3d (svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents: 9770
diff changeset
228 * @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
229 * @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
230 * @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
231 * @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
232 * @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
233 * @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
234 */
11085
8da1855e9f14 (svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents: 11084
diff changeset
235 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
236 {
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
237 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
238 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
239 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
240 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
241
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
242 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
243 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
244 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
245 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
246
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
247 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
248 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
249 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
250 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
251 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
252 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
253 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
254 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
255 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
256 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
257 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
258 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
259 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
260 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
261 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
262 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
263 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
264 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
265
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
266 /**
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
267 * Draw an image button.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
268 * @param r Rectangle of the button.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
269 * @param type Widget type (#WWT_IMGBTN or #WWT_IMGBTN_2).
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
270 * @param colour Colour of the button.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
271 * @param clicked Button is lowered.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
272 * @param img Sprite to draw.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
273 */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
274 static inline void DrawImageButtons(const Rect &r, WidgetType type, Colours colour, bool clicked, SpriteID img)
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
275 {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
276 assert(img != 0);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
277 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
278
12373
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
279 int left, top;
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
280 if ((type & WWT_MASK) == WWT_IMGBTN_2) {
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
281 if (clicked) img++; // Show different image when clicked for #WWT_IMGBTN_2.
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
282 left = WD_IMGBTN2_LEFT;
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
283 top = WD_IMGBTN2_TOP;
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
284 } else {
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
285 left = WD_IMGBTN_LEFT;
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
286 top = WD_IMGBTN_TOP;
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
287 }
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
288 DrawSprite(img, PAL_NONE, r.left + left + clicked, r.top + top + clicked);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
289 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
290
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
291 /**
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
292 * Draw the label-part of a widget.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
293 * @param r Rectangle of the label background.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
294 * @param type Widget type (#WWT_TEXTBTN, #WWT_TEXTBTN_2, or #WWT_LABEL).
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
295 * @param clicked Label is rendered lowered.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
296 * @param str Text to draw.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
297 */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
298 static inline void DrawLabel(const Rect &r, WidgetType type, bool clicked, StringID str)
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
299 {
12274
ab8191734216 (svn r16689) -Codechange: Allow for rendering of parameterized text of nested widgets in Window::DrawWidget, adapt intro and town directory windows.
alberth <alberth@openttd.org>
parents: 12255
diff changeset
300 if (str == STR_NULL) return;
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
301 if ((type & WWT_MASK) == WWT_TEXTBTN_2 && clicked) str++;
12195
ee5c5c8f0557 (svn r16609) -Codechange: Introduction of widget sizes and offsets used while drawing.
alberth <alberth@openttd.org>
parents: 12159
diff changeset
302 DrawString(r.left + clicked, r.right + clicked, ((r.top + r.bottom + 1) >> 1) - (FONT_HEIGHT_NORMAL / 2) + clicked, str, TC_FROMSTRING, SA_CENTER);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
303 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
304
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
305 /**
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
306 * Draw text.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
307 * @param r Rectangle of the background.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
308 * @param colour Colour of the text.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
309 * @param str Text to draw.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
310 */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
311 static inline void DrawText(const Rect &r, TextColour colour, StringID str)
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
312 {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
313 if (str != STR_NULL) DrawString(r.left, r.right, r.top, str, colour);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
314 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
315
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
316 /**
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
317 * Draw an inset widget.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
318 * @param r Rectangle of the background.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
319 * @param colour Colour of the inset.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
320 * @param str Text to draw.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
321 */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
322 static inline void DrawInset(const Rect &r, Colours colour, StringID str)
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
323 {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
324 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_LOWERED | FR_DARKENED);
12195
ee5c5c8f0557 (svn r16609) -Codechange: Introduction of widget sizes and offsets used while drawing.
alberth <alberth@openttd.org>
parents: 12159
diff changeset
325 if (str != STR_NULL) DrawString(r.left + WD_INSET_LEFT, r.right - WD_INSET_RIGHT, r.top + WD_INSET_TOP, str);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
326 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
327
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
328 /**
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
329 * Draw a matrix widget.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
330 * @param r Rectangle of the matrix background.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
331 * @param colour Colour of the background.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
332 * @param clicked Matrix is rendered lowered.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
333 * @param data Data of the widget.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
334 */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
335 static inline void DrawMatrix(const Rect &r, Colours colour, bool clicked, uint16 data)
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
336 {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
337 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
338
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
339 int c = GB(data, 0, 8);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
340 int amt1 = (r.right - r.left + 1) / c;
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
341
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
342 int d = GB(data, 8, 8);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
343 int amt2 = (r.bottom - r.top + 1) / d;
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
344
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
345 int col = _colour_gradient[colour & 0xF][6];
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
346
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
347 int x = r.left;
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
348 for (int ctr = c; ctr > 1; ctr--) {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
349 x += amt1;
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
350 GfxFillRect(x, r.top + 1, x, r.bottom - 1, col);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
351 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
352
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
353 x = r.top;
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
354 for (int ctr = d; ctr > 1; ctr--) {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
355 x += amt2;
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
356 GfxFillRect(r.left + 1, x, r.right - 1, x, col);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
357 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
358
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
359 col = _colour_gradient[colour & 0xF][4];
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
360
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
361 x = r.left - 1;
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
362 for (int ctr = c; ctr > 1; ctr--) {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
363 x += amt1;
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
364 GfxFillRect(x, r.top + 1, x, r.bottom - 1, col);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
365 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
366
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
367 x = r.top - 1;
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
368 for (int ctr = d; ctr > 1; ctr--) {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
369 x += amt2;
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
370 GfxFillRect(r.left + 1, x, r.right - 1, x, col);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
371 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
372 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
373
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
374 /**
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
375 * Draw a vertical scrollbar.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
376 * @param r Rectangle of the scrollbar widget.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
377 * @param colour Colour of the scrollbar widget.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
378 * @param up_clicked Up-arrow is clicked.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
379 * @param bar_dragged Bar is dragged.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
380 * @param down_clicked Down-arrow is clicked.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
381 * @param scrollbar Scrollbar size, offset, and capacity information.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
382 */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
383 static inline void DrawVerticalScrollbar(const Rect &r, Colours colour, bool up_clicked, bool bar_dragged, bool down_clicked, const Scrollbar *scrollbar)
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
384 {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
385 /* draw up/down buttons */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
386 DrawFrameRect(r.left, r.top, r.right, r.top + 9, colour, (up_clicked) ? FR_LOWERED : FR_NONE);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
387 DrawString(r.left + up_clicked, r.right + up_clicked, r.top + up_clicked, UPARROW, TC_BLACK, SA_CENTER);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
388
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
389 DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, colour, (down_clicked) ? FR_LOWERED : FR_NONE);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
390 DrawString(r.left + down_clicked, r.right + down_clicked, r.bottom - 9 + down_clicked, DOWNARROW, TC_BLACK, SA_CENTER);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
391
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
392 int c1 = _colour_gradient[colour & 0xF][3];
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
393 int c2 = _colour_gradient[colour & 0xF][7];
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
394
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
395 /* draw "shaded" background */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
396 GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c2);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
397 GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c1, FILLRECT_CHECKER);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
398
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
399 /* draw shaded lines */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
400 GfxFillRect(r.left + 2, r.top + 10, r.left + 2, r.bottom - 10, c1);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
401 GfxFillRect(r.left + 3, r.top + 10, r.left + 3, r.bottom - 10, c2);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
402 GfxFillRect(r.left + 7, r.top + 10, r.left + 7, r.bottom - 10, c1);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
403 GfxFillRect(r.left + 8, r.top + 10, r.left + 8, r.bottom - 10, c2);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
404
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
405 Point pt = HandleScrollbarHittest(scrollbar, r.top, r.bottom);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
406 DrawFrameRect(r.left, pt.x, r.right, pt.y, colour, bar_dragged ? FR_LOWERED : FR_NONE);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
407 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
408
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
409 /**
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
410 * Draw a horizontal scrollbar.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
411 * @param r Rectangle of the scrollbar widget.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
412 * @param colour Colour of the scrollbar widget.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
413 * @param left_clicked Left-arrow is clicked.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
414 * @param bar_dragged Bar is dragged.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
415 * @param right_clicked Right-arrow is clicked.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
416 * @param scrollbar Scrollbar size, offset, and capacity information.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
417 */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
418 static inline void DrawHorizontalScrollbar(const Rect &r, Colours colour, bool left_clicked, bool bar_dragged, bool right_clicked, const Scrollbar *scrollbar)
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
419 {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
420 DrawFrameRect(r.left, r.top, r.left + 9, r.bottom, colour, left_clicked ? FR_LOWERED : FR_NONE);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
421 DrawSprite(SPR_ARROW_LEFT, PAL_NONE, r.left + 1 + left_clicked, r.top + 1 + left_clicked);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
422
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
423 DrawFrameRect(r.right - 9, r.top, r.right, r.bottom, colour, right_clicked ? FR_LOWERED : FR_NONE);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
424 DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, r.right - 8 + right_clicked, r.top + 1 + right_clicked);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
425
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
426 int c1 = _colour_gradient[colour & 0xF][3];
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
427 int c2 = _colour_gradient[colour & 0xF][7];
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
428
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
429 /* draw "shaded" background */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
430 GfxFillRect(r.left + 10, r.top, r.right - 10, r.bottom, c2);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
431 GfxFillRect(r.left + 10, r.top, r.right - 10, r.bottom, c1, FILLRECT_CHECKER);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
432
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
433 /* draw shaded lines */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
434 GfxFillRect(r.left + 10, r.top + 2, r.right - 10, r.top + 2, c1);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
435 GfxFillRect(r.left + 10, r.top + 3, r.right - 10, r.top + 3, c2);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
436 GfxFillRect(r.left + 10, r.top + 7, r.right - 10, r.top + 7, c1);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
437 GfxFillRect(r.left + 10, r.top + 8, r.right - 10, r.top + 8, c2);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
438
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
439 /* draw actual scrollbar */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
440 Point pt = HandleScrollbarHittest(scrollbar, r.left, r.right);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
441 DrawFrameRect(pt.x, r.top, pt.y, r.bottom, colour, bar_dragged ? FR_LOWERED : FR_NONE);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
442 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
443
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
444 /**
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
445 * Draw a frame widget.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
446 * @param r Rectangle of the frame.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
447 * @param colour Colour of the frame.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
448 * @param str Text of the frame.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
449 */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
450 static inline void DrawFrame(const Rect &r, Colours colour, StringID str)
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
451 {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
452 int x2 = r.left; // by default the left side is the left side of the widget
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
453
12195
ee5c5c8f0557 (svn r16609) -Codechange: Introduction of widget sizes and offsets used while drawing.
alberth <alberth@openttd.org>
parents: 12159
diff changeset
454 if (str != STR_NULL) x2 = DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top, str);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
455
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
456 int c1 = _colour_gradient[colour][3];
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
457 int c2 = _colour_gradient[colour][7];
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
458
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
459 if (_dynlang.text_dir == TD_LTR) {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
460 /* Line from upper left corner to start of text */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
461 GfxFillRect(r.left, r.top + 4, r.left + 4, r.top + 4, c1);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
462 GfxFillRect(r.left + 1, r.top + 5, r.left + 4, r.top + 5, c2);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
463
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
464 /* Line from end of text to upper right corner */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
465 GfxFillRect(x2, r.top + 4, r.right - 1, r.top + 4, c1);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
466 GfxFillRect(x2, r.top + 5, r.right - 2, r.top + 5, c2);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
467 } else {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
468 /* Line from upper left corner to start of text */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
469 GfxFillRect(r.left, r.top + 4, x2 - 2, r.top + 4, c1);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
470 GfxFillRect(r.left + 1, r.top + 5, x2 - 2, r.top + 5, c2);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
471
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
472 /* Line from end of text to upper right corner */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
473 GfxFillRect(r.right - 5, r.top + 4, r.right - 1, r.top + 4, c1);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
474 GfxFillRect(r.right - 5, r.top + 5, r.right - 2, r.top + 5, c2);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
475 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
476
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
477 /* Line from upper left corner to bottom left corner */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
478 GfxFillRect(r.left, r.top + 5, r.left, r.bottom - 1, c1);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
479 GfxFillRect(r.left + 1, r.top + 6, r.left + 1, r.bottom - 2, c2);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
480
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
481 /* Line from upper right corner to bottom right corner */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
482 GfxFillRect(r.right - 1, r.top + 5, r.right - 1, r.bottom - 2, c1);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
483 GfxFillRect(r.right, r.top + 4, r.right, r.bottom - 1, c2);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
484
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
485 GfxFillRect(r.left + 1, r.bottom - 1, r.right - 1, r.bottom - 1, c1);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
486 GfxFillRect(r.left, r.bottom, r.right, r.bottom, c2);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
487 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
488
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
489 /**
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
490 * Draw a sticky box.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
491 * @param r Rectangle of the box.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
492 * @param colour Colour of the sticky box.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
493 * @param clicked Box is lowered.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
494 */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
495 static inline void DrawStickyBox(const Rect &r, Colours colour, bool clicked)
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
496 {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
497 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
12373
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
498 DrawSprite((clicked) ? SPR_PIN_UP : SPR_PIN_DOWN, PAL_NONE, r.left + WD_STICKYBOX_LEFT + clicked, r.top + WD_STICKYBOX_TOP + clicked);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
499 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
500
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
501 /**
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
502 * Draw a resize box.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
503 * @param r Rectangle of the box.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
504 * @param colour Colour of the resize box.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
505 * @param at_left Resize box is at left-side of the window,
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
506 * @param clicked Box is lowered.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
507 */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
508 static inline void DrawResizeBox(const Rect &r, Colours colour, bool at_left, bool clicked)
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
509 {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
510 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
511 if (at_left) {
12373
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
512 DrawSprite(SPR_WINDOW_RESIZE_LEFT, PAL_NONE, r.left + WD_RESIZEBOX_RIGHT + clicked, r.top + WD_RESIZEBOX_TOP + clicked);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
513 } else {
12373
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
514 DrawSprite(SPR_WINDOW_RESIZE_RIGHT, PAL_NONE, r.left + WD_RESIZEBOX_LEFT + clicked, r.top + WD_RESIZEBOX_TOP + clicked);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
515 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
516 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
517
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
518 /**
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
519 * Draw a close box.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
520 * @param r Rectangle of the box.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
521 * @param colour Colour of the close box.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
522 * @param str Cross to draw (#STR_BLACK_CROSS or #STR_SILVER_CROSS).
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
523 */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
524 static inline void DrawCloseBox(const Rect &r, Colours colour, StringID str)
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
525 {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
526 assert(str == STR_BLACK_CROSS || str == STR_SILVER_CROSS); // black or silver cross
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
527 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_NONE);
12373
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
528 DrawString(r.left + WD_CLOSEBOX_LEFT, r.right - WD_CLOSEBOX_RIGHT, r.top + WD_CLOSEBOX_TOP, str, TC_FROMSTRING, SA_CENTER);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
529 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
530
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
531 /**
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
532 * Draw a caption bar.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
533 * @param r Rectangle of the bar.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
534 * @param colour Colour of the window.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
535 * @param owner 'Owner' of the window.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
536 * @param str Text to draw in the bar.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
537 */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
538 static inline void DrawCaption(const Rect &r, Colours colour, Owner owner, StringID str)
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
539 {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
540 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_BORDERONLY);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
541 DrawFrameRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, colour, (owner == INVALID_OWNER) ? FR_LOWERED | FR_DARKENED : FR_LOWERED | FR_DARKENED | FR_BORDERONLY);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
542
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
543 if (owner != INVALID_OWNER) {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
544 GfxFillRect(r.left + 2, r.top + 2, r.right - 2, r.bottom - 2, _colour_gradient[_company_colours[owner]][4]);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
545 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
546
12274
ab8191734216 (svn r16689) -Codechange: Allow for rendering of parameterized text of nested widgets in Window::DrawWidget, adapt intro and town directory windows.
alberth <alberth@openttd.org>
parents: 12255
diff changeset
547 if (str != STR_NULL) DrawString(r.left + WD_CAPTIONTEXT_LEFT, r.right - WD_CAPTIONTEXT_RIGHT, r.top + WD_CAPTIONTEXT_TOP, str, TC_FROMSTRING, SA_CENTER);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
548 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
549
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
550 static inline void DrawDropdown(const Rect &r, Colours colour, bool clicked, StringID str)
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
551 {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
552 if (_dynlang.text_dir == TD_LTR) {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
553 DrawFrameRect(r.left, r.top, r.right - 12, r.bottom, colour, FR_NONE);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
554 DrawFrameRect(r.right - 11, r.top, r.right, r.bottom, colour, clicked ? FR_LOWERED : FR_NONE);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
555 DrawString(r.right - (clicked ? 10 : 11), r.right, r.top + (clicked ? 2 : 1), STR_ARROW_DOWN, TC_BLACK, SA_CENTER);
12195
ee5c5c8f0557 (svn r16609) -Codechange: Introduction of widget sizes and offsets used while drawing.
alberth <alberth@openttd.org>
parents: 12159
diff changeset
556 if (str != STR_NULL) DrawString(r.left + WD_DROPDOWNTEXT_LEFT, r.right - WD_DROPDOWNTEXT_RIGHT, r.top + WD_DROPDOWNTEXT_TOP, str, TC_BLACK);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
557 } else {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
558 DrawFrameRect(r.left + 12, r.top, r.right, r.bottom, colour, FR_NONE);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
559 DrawFrameRect(r.left, r.top, r.left + 11, r.bottom, colour, clicked ? FR_LOWERED : FR_NONE);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
560 DrawString(r.left + clicked, r.left + 11, r.top + (clicked ? 2 : 1), STR_ARROW_DOWN, TC_BLACK, SA_CENTER);
12195
ee5c5c8f0557 (svn r16609) -Codechange: Introduction of widget sizes and offsets used while drawing.
alberth <alberth@openttd.org>
parents: 12159
diff changeset
561 if (str != STR_NULL) DrawString(r.left + WD_DROPDOWNTEXT_RIGHT, r.right - WD_DROPDOWNTEXT_LEFT, r.top + WD_DROPDOWNTEXT_TOP, str, TC_BLACK);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
562 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
563 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
564
8857
a75a0c683fea (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8737
diff changeset
565 /**
a75a0c683fea (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8737
diff changeset
566 * 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
567 */
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
568 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
569 {
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
570 if (this->nested_root != NULL) {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
571 this->nested_root->Draw(this);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
572 return;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
573 }
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
574
10647
592ae9307430 (svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents: 10238
diff changeset
575 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
576
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
577 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
578 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
579 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
580 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
581
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
582 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
583 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
584 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
585 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
586 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
587 continue;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
588 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
589
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
590 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
591 case WWT_IMGBTN:
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
592 case WWT_IMGBTN_2:
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
593 DrawImageButtons(r, wi->type,wi->colour, clicked, wi->data);
8320
06495654aee6 (svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138 <peter1138@openttd.org>
parents: 8284
diff changeset
594 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
595
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
596 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
597 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
598 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
599 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
600
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
601 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
602 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
603 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
604
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
605 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
606 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
607 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
608 /* 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
609
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
610 case WWT_LABEL:
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
611 DrawLabel(r, wi->type, clicked, wi->data);
6278
b57f385b355c (svn r9088) -Add : a new type of widget, called WWT_TEXT. It is a simple truncated string. It will be usefull on windows where lot of simple text is always drawn on the WE_PAINT event, making the code clearer. For now, left, right (total size of the window), top, color and data are necessary to use it. Maybe more features will be available soon.
belugas <belugas@openttd.org>
parents: 5824
diff changeset
612 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
613
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
614 case WWT_TEXT:
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
615 DrawText(r, (TextColour)wi->colour, wi->data);
8320
06495654aee6 (svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138 <peter1138@openttd.org>
parents: 8284
diff changeset
616 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
617
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
618 case WWT_INSET:
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
619 DrawInset(r, wi->colour, wi->data);
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
620 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
621
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
622 case WWT_MATRIX:
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
623 DrawMatrix(r, wi->colour, clicked, wi->data);
8320
06495654aee6 (svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138 <peter1138@openttd.org>
parents: 8284
diff changeset
624 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
625
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
626 /* vertical scrollbar */
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
627 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
628 assert(wi->data == 0);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
629 DrawVerticalScrollbar(r, wi->colour, (this->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_UP,
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
630 (this->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_MIDDLE,
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
631 (this->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_DOWN, &this->vscroll);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
632 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
633
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
634 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
635 assert(wi->data == 0);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
636 DrawVerticalScrollbar(r, wi->colour, (this->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_UP | WF_SCROLL2),
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
637 (this->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_MIDDLE | WF_SCROLL2),
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
638 (this->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_DOWN | WF_SCROLL2), &this->vscroll2);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
639 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
640
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
641 /* horizontal scrollbar */
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
642 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
643 assert(wi->data == 0);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
644 DrawHorizontalScrollbar(r, wi->colour, (this->flags4 & (WF_SCROLL_UP | WF_HSCROLL)) == (WF_SCROLL_UP | WF_HSCROLL),
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
645 (this->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL)) == (WF_SCROLL_MIDDLE | WF_HSCROLL),
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
646 (this->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL)) == (WF_SCROLL_DOWN | WF_HSCROLL), &this->hscroll);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
647 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
648
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
649 case WWT_FRAME:
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
650 DrawFrame(r, wi->colour, wi->data);
8320
06495654aee6 (svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138 <peter1138@openttd.org>
parents: 8284
diff changeset
651 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
652
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
653 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
654 assert(wi->data == 0);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
655 DrawStickyBox(r, wi->colour, !!(this->flags4 & WF_STICKY));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
656 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
657
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
658 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
659 assert(wi->data == 0);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
660 DrawResizeBox(r, wi->colour, wi->left < (this->width / 2), !!(this->flags4 & WF_SIZING));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
661 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
662
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
663 case WWT_CLOSEBOX:
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
664 DrawCloseBox(r, wi->colour, wi->data);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
665 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
666
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
667 case WWT_CAPTION:
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
668 DrawCaption(r, wi->colour, this->owner, wi->data);
8320
06495654aee6 (svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138 <peter1138@openttd.org>
parents: 8284
diff changeset
669 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
670
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
671 case WWT_DROPDOWN:
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
672 DrawDropdown(r, wi->colour, clicked, wi->data);
8335
5d87abba6871 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138 <peter1138@openttd.org>
parents: 8320
diff changeset
673 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
674 }
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
675
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
676 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
677 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
678 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
679 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
680
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
681
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
682 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
683 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
684 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
685
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
686 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
687
11799
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
688 /**
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
689 * Evenly distribute the combined horizontal length of two consecutive widgets.
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
690 * @param w Window containing the widgets.
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
691 * @param a Left widget to resize.
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
692 * @param b Right widget to resize.
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
693 * @note Widgets are assumed to lie against each other.
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
694 */
5824
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
695 static void ResizeWidgets(Window *w, byte a, byte b)
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
696 {
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
697 int16 offset = w->widget[a].left;
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
698 int16 length = w->widget[b].right - offset;
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
699
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
700 w->widget[a].right = (length / 2) + offset;
5824
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
701
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
702 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
703 }
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
704
11799
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
705 /**
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
706 * Evenly distribute the combined horizontal length of three consecutive widgets.
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
707 * @param w Window containing the widgets.
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
708 * @param a Left widget to resize.
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
709 * @param b Middle widget to resize.
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
710 * @param c Right widget to resize.
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
711 * @note Widgets are assumed to lie against each other.
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
712 */
5824
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
713 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
714 {
5824
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
715 int16 offset = w->widget[a].left;
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
716 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
717
5824
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
718 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
719 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
720
5824
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
721 w->widget[a].right += offset;
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
722 w->widget[b].right += offset;
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
723
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
724 /* 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
725 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
726 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
727 }
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
728
5824
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
729 /** 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
730 * 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
731 * @param w Window to modify
5824
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
732 * @param left The leftmost widget to resize
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
733 * @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
734 */
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
735 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
736 {
5824
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
737 int16 num_widgets = right - left + 1;
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
738
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
739 if (num_widgets < 2) NOT_REACHED();
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
740
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
741 switch (num_widgets) {
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
742 case 2: ResizeWidgets(w, left, right); break;
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
743 case 3: ResizeWidgets(w, left, left + 1, right); break;
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
744 default: {
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
745 /* 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
746 * 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
747 * 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
748 * 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
749 int16 offset = w->widget[left].left;
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
750 int16 length = w->widget[right].right - offset;
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
751 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
752
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
753 /* 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
754 * 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
755 * 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
756 * 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
757 *
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
758 * num_widgets/2 (rounding down)
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
759 * ---------------
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
760 * num_widgets
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
761 *
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
762 * 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
763 int16 middle = ((length * num_widgets) / (2 * num_widgets)) + offset;
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
764
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
765 /* 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
766 w->widget[widget].right = middle;
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
767 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
768 /* Now resize the left and right of the middle */
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
769 ResizeButtons(w, left, widget);
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
770 ResizeButtons(w, widget + 1, right);
19c4635a0be0 (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni <bjarni@openttd.org>
parents: 5822
diff changeset
771 }
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
772 }
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
773 }
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
774
8857
a75a0c683fea (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8737
diff changeset
775 /** 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
776 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
777 {
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
778 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
779 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
780
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
781 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
782 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
783 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
784 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
785 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
786 }
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
787
9834
efa04139a798 (svn r13977) -Codechange: Let ResizeWindowForWidget() handle hidden (zero height or zero width) widgets.
peter1138 <peter1138@openttd.org>
parents: 9779
diff changeset
788 /* 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
789 * 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
790 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
791 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
792
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
793 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
794 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
795
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
796 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
797 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
798 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
799 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
800 }
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
801
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
802 /**
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
803 * 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
804 * @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
805 * @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
806 */
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
807 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
808 {
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
809 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
810
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
811 int offset = this->IsWidgetLowered(widget) ? 1 : 0;
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
812 int base, top;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
813 if (this->widget != NULL) {
12310
a0c352de6782 (svn r16727) -Codechange: Introducing WD_SORTBUTTON_ARROW_WIDTH constant.
alberth <alberth@openttd.org>
parents: 12274
diff changeset
814 base = offset + (_dynlang.text_dir == TD_LTR ? this->widget[widget].right - WD_SORTBUTTON_ARROW_WIDTH : this->widget[widget].left);
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
815 top = this->widget[widget].top;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
816 } else {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
817 assert(this->nested_array != NULL);
12310
a0c352de6782 (svn r16727) -Codechange: Introducing WD_SORTBUTTON_ARROW_WIDTH constant.
alberth <alberth@openttd.org>
parents: 12274
diff changeset
818 base = offset + this->nested_array[widget]->pos_x + (_dynlang.text_dir == TD_LTR ? this->nested_array[widget]->current_x - WD_SORTBUTTON_ARROW_WIDTH : 0);
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
819 top = this->nested_array[widget]->pos_y;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
820 }
12310
a0c352de6782 (svn r16727) -Codechange: Introducing WD_SORTBUTTON_ARROW_WIDTH constant.
alberth <alberth@openttd.org>
parents: 12274
diff changeset
821 DrawString(base, base + WD_SORTBUTTON_ARROW_WIDTH, 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
822 }
11461
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
11799
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
825 /**
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
826 * @defgroup NestedWidgets Hierarchical widgets.
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
827 * Hierarchical widgets, also known as nested widgets, are widgets stored in a tree. At the leafs of the tree are (mostly) the 'real' widgets
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
828 * visible to the user. At higher levels, widgets get organized in container widgets, until all widgets of the window are merged.
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
829 *
11964
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
830 * \section nestedwidgetkinds Hierarchical widget kinds
11799
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
831 * A leaf widget is one of
11964
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
832 * <ul>
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
833 * <li> #NWidgetLeaf for widgets visible for the user, or
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
834 * <li> #NWidgetSpacer for creating (flexible) empty space between widgets.
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
835 * </ul>
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
836 * The purpose of a leaf widget is to provide interaction with the user by displaying settings, and/or allowing changing the settings.
11799
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
837 *
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
838 * A container widget is one of
11964
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
839 * <ul>
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
840 * <li> #NWidgetHorizontal for organizing child widgets in a (horizontal) row. The row switches order depending on the language setting (thus supporting
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
841 * right-to-left languages),
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
842 * <li> #NWidgetHorizontalLTR for organizing child widgets in a (horizontal) row, always in the same order. All childs below this container will also
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
843 * never swap order.
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
844 * <li> #NWidgetVertical for organizing child widgets underneath each other.
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
845 * <li> #NWidgetBackground for adding a background behind its child widget.
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
846 * <li> #NWidgetStacked for stacking child widgets on top of each other.
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
847 * </ul>
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
848 * The purpose of a container widget is to structure its leafs and sub-containers to allow proper resizing.
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
849 *
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
850 * \section nestedwidgetscomputations Hierarchical widget computations
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
851 * The first 'computation' is the creation of the nested widgets tree by calling the constructors of the widgets listed above and calling \c Add() for every child,
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
852 * or by means of specifying the tree as a collection of nested widgets parts and instantiating the tree from the array.
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
853 *
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
854 * After the creation step,
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
855 * - The leafs have their own minimal size (\e min_x, \e min_y), filling (\e fill_x, \e fill_y), and resize steps (\e resize_x, \e resize_y).
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
856 * - Containers only know what their children are, \e fill_x, \e fill_y, \e resize_x, and \e resize_y are not initialized.
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
857 *
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
858 * Computations in the nested widgets take place as follows:
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
859 * <ol>
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
860 * <li> A bottom-up sweep by recursively calling NWidgetBase::SetupSmallestSize() to initialize the smallest size (\e smallest_x, \e smallest_y) and
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
861 * to propagate filling and resize steps upwards to the root of the tree.
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
862 * <li> A top-down sweep by recursively calling NWidgetBase::AssignSizePosition() with #ST_ARRAY or #ST_SMALLEST to make the smallest sizes consistent over
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
863 * the entire tree, and to assign the top-left (\e pos_x, \e pos_y) position of each widget in the tree. This step uses \e fill_x and \e fill_y at each
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
864 * node in the tree to decide how to fill each widget towards consistent sizes. Also the current size (\e current_x and \e current_y) is set.
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
865 * For generating a widget array (#ST_ARRAY), resize step sizes are made consistent.
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
866 * <li> After initializing the smallest size in the widget tree with #ST_SMALLEST, the tree can be resized (the current size modified) by calling
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
867 * NWidgetBase::AssignSizePosition() at the root with #ST_RESIZE and the new size of the window. For proper functioning, the new size should be the smallest
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
868 * size + a whole number of resize steps in both directions (ie you can only resize in steps of length resize_{x,y} from smallest_{x,y}).
11964
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
869 * </ol>
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
870 * After the second step, the current size of the widgets are set to the smallest size.
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
871 *
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
872 * To resize, perform the last step with the new window size. This can be done as often as desired.
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
873 * When the smallest size of at least one widget changes, the whole procedure has to be redone from the start.
11799
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
874 *
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
875 * @see NestedWidgetParts
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
876 */
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
877
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
878 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
879 * Base class constructor.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
880 * @param tp Nested widget type.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
881 */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
882 NWidgetBase::NWidgetBase(WidgetType tp) : ZeroedMemoryAllocator()
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
883 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
884 this->type = tp;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
885 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
886
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
887 /* ~NWidgetContainer() takes care of #next and #prev data members. */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
888
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
889 /**
12323
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
890 * @fn int NWidgetBase::SetupSmallestSize(Window *w)
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
891 * Compute smallest size needed by the widget.
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
892 *
11961
69a41fde01e1 (svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents: 11836
diff changeset
893 * The smallest size of a widget is the smallest size that a widget needs to
12323
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
894 * display itself properly. In addition, filling and resizing of the widget are computed.
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
895 * If \a w is not \c NULL, the function calls #Window::GetWidgetContentSize for each leaf widget and
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
896 * background widget without child with a non-negative index.
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
897 *
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
898 * @param w Optional window owning the widget.
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
899 * @return Biggest index in the widget array of all child widgets (\c -1 if no index is used).
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
900 *
12323
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
901 * @note After the computation, the results can be queried by accessing the #smallest_x and #smallest_y data members of the widget.
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
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
904 /**
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
905 * @fn void NWidgetBase::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl)
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
906 * Assign size and position to the widget.
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
907 * @param sizing Type of resizing to perform.
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
908 * @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
909 * @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
910 * @param given_width Width allocated to the widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
911 * @param given_height Height allocated to the widget.
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
912 * @param allow_resize_x Horizontal resizing is allowed (only used when \a sizing is #ST_ARRAY).
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
913 * @param allow_resize_y Vertical resizing is allowed (only used when \a sizing in #ST_ARRAY).
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
914 * @param rtl Adapt for right-to-left languages (position contents of horizontal containers backwards).
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
915 *
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
916 * Afterwards, \e pos_x and \e pos_y contain the top-left position of the widget, \e smallest_x and \e smallest_y contain
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
917 * the smallest size such that all widgets of the window are consistent, and \e current_x and \e current_y contain the current size.
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
918 */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
919
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
920 /**
12100
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
921 * @fn void FillNestedArray(NWidgetCore **array, uint length)
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
922 * Fill the Window::nested_array array with pointers to nested widgets in the tree.
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
923 * @param array Base pointer of the array.
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
924 * @param length Length of the array.
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
925 */
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
926
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
927 /**
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
928 * Store size and position.
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
929 * @param sizing Type of resizing to perform.
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
930 * @param x Horizontal offset of the widget relative to the left edge of the window.
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
931 * @param y Vertical offset of the widget relative to the top edge of the window.
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
932 * @param given_width Width allocated to the widget.
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
933 * @param given_height Height allocated to the widget.
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
934 * @param allow_resize_x Horizontal resizing is allowed (only used when \a sizing is #ST_ARRAY).
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
935 * @param allow_resize_y Vertical resizing is allowed (only used when \a sizing in #ST_ARRAY).
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
936 */
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
937 inline void NWidgetBase::StoreSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y)
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
938 {
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
939 this->pos_x = x;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
940 this->pos_y = y;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
941 if (sizing == ST_ARRAY || sizing == ST_SMALLEST) {
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
942 this->smallest_x = given_width;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
943 this->smallest_y = given_height;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
944 }
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
945 this->current_x = given_width;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
946 this->current_y = given_height;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
947 if (sizing == ST_ARRAY && !allow_resize_x) this->resize_x = 0;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
948 if (sizing == ST_ARRAY && !allow_resize_y) this->resize_y = 0;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
949 }
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
950
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
951 /**
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
952 * @fn void NWidgetBase::StoreWidgets(Widget *widgets, int length, bool left_moving, bool top_moving, bool rtl)
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
953 * Store all child widgets with a valid index into the widget array.
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
954 * @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
955 * @param length Length of the array.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
956 * @param left_moving Left edge of the widget may move due to resizing (right edge if \a rtl).
11964
9bbab6c40225 (svn r16370) -Doc: Improvements to the nested widgets documentation, added explanation about computations, fixed typo in param description.
alberth <alberth@openttd.org>
parents: 11963
diff changeset
957 * @param top_moving Top edge of the widget may move due to resizing.
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
958 * @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
959 *
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
960 * @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
961 * 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
962 */
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 /**
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
965 * @fn void Draw(const Window *w)
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
966 * Draw the widgets of the tree.
12274
ab8191734216 (svn r16689) -Codechange: Allow for rendering of parameterized text of nested widgets in Window::DrawWidget, adapt intro and town directory windows.
alberth <alberth@openttd.org>
parents: 12255
diff changeset
967 * The function calls #Window::DrawWidget for each widget with a non-negative index, after the widget itself is painted.
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
968 * @param w Window that owns the tree.
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
969 */
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
970
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
971 /**
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
972 * Mark the widget as 'dirty' (in need of repaint).
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
973 * @param w Window owning the widget.
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
974 */
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
975 void NWidgetBase::Invalidate(const Window *w) const
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
976 {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
977 int abs_left = w->left + this->pos_x;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
978 int abs_top = w->top + this->pos_y;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
979 SetDirtyBlocks(abs_left, abs_top, abs_left + this->current_x, abs_top + this->current_y);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
980 }
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
981
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
982 /**
12102
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
983 * @fn NWidgetCore *GetWidgetFromPos(int x, int y)
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
984 * Retrieve a widget by its position.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
985 * @param x Horizontal position relative to the left edge of the window.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
986 * @param y Vertical position relative to the top edge of the window.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
987 * @return Returns the deepest nested widget that covers the given position, or \c NULL if no widget can be found.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
988 */
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
989
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
990 /**
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
991 * @fn NWidgetBase *GetWidgetOfType(WidgetType tp)
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
992 * Retrieve a widget by its type.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
993 * @param tp Widget type to search for.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
994 * @return Returns the first widget of the specified type, or \c NULL if no widget can be found.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
995 */
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
996
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
997 /**
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
998 * Constructor for resizable nested widgets.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
999 * @param tp Nested widget type.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1000 * @param fill_x Allow horizontal filling from initial size.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1001 * @param fill_y Allow vertical filling from initial size.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1002 */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1003 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
1004 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1005 this->fill_x = fill_x;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1006 this->fill_y = fill_y;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1007 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1008
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1009 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1010 * Set minimal size of the widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1011 * @param min_x Horizontal minimal size of the widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1012 * @param min_y Vertical minimal size of the widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1013 */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1014 void NWidgetResizeBase::SetMinimalSize(uint min_x, uint min_y)
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1015 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1016 this->min_x = min_x;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1017 this->min_y = min_y;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1018 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1019
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1020 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1021 * Set the filling of the widget from initial size.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1022 * @param fill_x Allow horizontal filling from initial size.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1023 * @param fill_y Allow vertical filling from initial size.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1024 */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1025 void NWidgetResizeBase::SetFill(bool fill_x, bool fill_y)
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1026 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1027 this->fill_x = fill_x;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1028 this->fill_y = fill_y;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1029 }
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 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1032 * Set resize step of the widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1033 * @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
1034 * @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
1035 */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1036 void NWidgetResizeBase::SetResize(uint resize_x, uint resize_y)
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1037 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1038 this->resize_x = resize_x;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1039 this->resize_y = resize_y;
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
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1042 void NWidgetResizeBase::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1043 {
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1044 StoreSizePosition(sizing, x, y, given_width, given_height, allow_resize_x, allow_resize_y);
11461
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 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1048 * Initialization of a 'real' widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1049 * @param tp Type of the widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1050 * @param colour Colour of the widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1051 * @param fill_x Default horizontal filling.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1052 * @param fill_y Default vertical filling.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1053 * @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
1054 * @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
1055 */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1056 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
1057 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1058 this->colour = colour;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1059 this->index = -1;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1060 this->widget_data = widget_data;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1061 this->tool_tip = tool_tip;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1062 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1063
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1064 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1065 * 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
1066 * @param index Index to use.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1067 */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1068 void NWidgetCore::SetIndex(int index)
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1069 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1070 assert(index >= 0);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1071 this->index = index;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1072 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1073
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1074 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1075 * Set data and tool tip of the nested widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1076 * @param widget_data Data to use.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1077 * @param tool_tip Tool tip string to use.
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 void NWidgetCore::SetDataTip(uint16 widget_data, StringID tool_tip)
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 this->widget_data = widget_data;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1082 this->tool_tip = tool_tip;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1083 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1084
12100
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
1085 void NWidgetCore::FillNestedArray(NWidgetCore **array, uint length)
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
1086 {
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
1087 if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
1088 }
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
1089
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1090 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
1091 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1092 if (this->index < 0) return;
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 assert(this->index < length);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1095 Widget *w = widgets + this->index;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1096 assert(w->type == WWT_LAST);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1097
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1098 DisplayFlags flags = RESIZE_NONE; // resize flags.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1099 /* Compute vertical resizing. */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1100 if (top_moving) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1101 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
1102 } else if(this->resize_y > 0) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1103 flags |= RESIZE_BOTTOM;
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 /* Compute horizontal resizing. */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1106 if (left_moving) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1107 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
1108 } else if (this->resize_x > 0) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1109 flags |= RESIZE_RIGHT;
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 /* Copy nested widget data into its widget array entry. */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1113 w->type = this->type;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1114 w->display_flags = flags;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1115 w->colour = this->colour;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1116 w->left = this->pos_x;
11961
69a41fde01e1 (svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents: 11836
diff changeset
1117 w->right = this->pos_x + this->smallest_x - 1;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1118 w->top = this->pos_y;
11961
69a41fde01e1 (svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents: 11836
diff changeset
1119 w->bottom = this->pos_y + this->smallest_y - 1;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1120 w->data = this->widget_data;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1121 w->tooltips = this->tool_tip;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1122 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1123
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1124 /**
12102
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1125 * @fn Scrollbar *NWidgetCore::FindScrollbar(Window *w, bool allow_next = true)
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1126 * Find the scrollbar of the widget through the Window::nested_array.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1127 * @param w Window containing the widgets and the scrollbar,
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1128 * @param allow_next Search may be extended to the next widget.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1129 *
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1130 * @todo This implementation uses the constraint that a scrollbar must be the next item in the #Window::nested_array, and the scrollbar
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1131 * data is stored in the #Window structure (#Window::vscroll, #Window::vscroll2, and #Window::hscroll).
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1132 * Alternative light-weight implementations may be considered, eg by sub-classing a canvas-like widget, and/or by having
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1133 * an explicit link between the scrollbar and the widget being scrolled.
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1134 */
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1135
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1136 /**
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1137 * Constructor container baseclass.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1138 * @param tp Type of the container.
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 NWidgetContainer::NWidgetContainer(WidgetType tp) : NWidgetBase(tp)
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 this->head = NULL;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1143 this->tail = NULL;
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
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1146 NWidgetContainer::~NWidgetContainer()
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 while (this->head != NULL) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1149 NWidgetBase *wid = this->head->next;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1150 delete this->head;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1151 this->head = wid;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1152 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1153 this->tail = NULL;
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
12102
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1156 NWidgetBase *NWidgetContainer::GetWidgetOfType(WidgetType tp)
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1157 {
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1158 if (this->type == tp) return this;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1159 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1160 NWidgetBase *nwid = child_wid->GetWidgetOfType(tp);
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1161 if (nwid != NULL) return nwid;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1162 }
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1163 return NULL;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1164 }
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1165
11461
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 * Append widget \a wid to container.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1168 * @param wid Widget to append.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1169 */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1170 void NWidgetContainer::Add(NWidgetBase *wid)
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1171 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1172 assert(wid->next == NULL && wid->prev == NULL);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1173
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1174 if (this->head == NULL) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1175 this->head = wid;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1176 this->tail = wid;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1177 } else {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1178 assert(this->tail != NULL);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1179 assert(this->tail->next == NULL);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1180
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1181 this->tail->next = wid;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1182 wid->prev = this->tail;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1183 this->tail = wid;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1184 }
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
12100
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
1187 void NWidgetContainer::FillNestedArray(NWidgetCore **array, uint length)
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
1188 {
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
1189 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
1190 child_wid->FillNestedArray(array, length);
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
1191 }
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
1192 }
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
1193
11528
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1194 /**
11966
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1195 * Return the biggest possible size of a nested widget.
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1196 * @param base Base size of the widget.
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1197 * @param max_space Available space for the widget.
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1198 * @param step Stepsize of the widget.
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1199 * @return Biggest possible size of the widget, assuming that \a base may only be incremented by \a step size steps.
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1200 */
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1201 static inline uint ComputeMaxSize(uint base, uint max_space, uint step)
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1202 {
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1203 if (base >= max_space || step == 0) return base;
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1204 if (step == 1) return max_space;
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1205 int increment = max_space - base;
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1206 increment -= increment % step;
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1207 return base + increment;
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1208 }
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1209
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1210 /**
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1211 * Compute the offset of a widget due to not entirely using the available space.
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1212 * @param space Space used by the widget.
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1213 * @param max_space Available space for the widget.
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1214 * @return Offset for centering widget.
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1215 */
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1216 static inline uint ComputeOffset(uint space, uint max_space)
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1217 {
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1218 if (space >= max_space) return 0;
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1219 return (max_space - space) / 2;
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1220 }
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1221
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1222
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1223 /**
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1224 * Widgets stacked on top of each other.
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1225 * @param tp Kind of stacking, must be either #NWID_SELECTION or #NWID_LAYERED.
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1226 */
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1227 NWidgetStacked::NWidgetStacked(WidgetType tp) : NWidgetContainer(tp)
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1228 {
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1229 }
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1230
12323
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1231 int NWidgetStacked::SetupSmallestSize(Window *w)
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1232 {
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1233 /* First sweep, recurse down and compute minimal size and filling. */
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1234 int biggest_index = -1;
11961
69a41fde01e1 (svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents: 11836
diff changeset
1235 this->smallest_x = 0;
69a41fde01e1 (svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents: 11836
diff changeset
1236 this->smallest_y = 0;
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1237 this->fill_x = (this->head != NULL);
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1238 this->fill_y = (this->head != NULL);
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1239 this->resize_x = (this->head != NULL) ? 1 : 0;
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1240 this->resize_y = (this->head != NULL) ? 1 : 0;
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1241 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
12323
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1242 int idx = child_wid->SetupSmallestSize(w);
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1243 biggest_index = max(biggest_index, idx);
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1244
11961
69a41fde01e1 (svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents: 11836
diff changeset
1245 this->smallest_x = max(this->smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
69a41fde01e1 (svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents: 11836
diff changeset
1246 this->smallest_y = max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1247 this->fill_x &= child_wid->fill_x;
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1248 this->fill_y &= child_wid->fill_y;
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1249 this->resize_x = LeastCommonMultiple(this->resize_x, child_wid->resize_x);
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1250 this->resize_y = LeastCommonMultiple(this->resize_y, child_wid->resize_y);
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1251 }
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1252 return biggest_index;
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1253 }
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1254
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1255 void NWidgetStacked::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl)
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1256 {
11961
69a41fde01e1 (svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents: 11836
diff changeset
1257 assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1258 StoreSizePosition(sizing, x, y, given_width, given_height, allow_resize_x, allow_resize_y);
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1259
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1260 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1261 uint hor_step = child_wid->GetHorizontalStepSize(sizing);
11966
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1262 uint child_width = ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding_left - child_wid->padding_right, hor_step);
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1263 uint child_pos_x = (rtl ? child_wid->padding_right : child_wid->padding_left) + ComputeOffset(child_width, given_width - child_wid->padding_left - child_wid->padding_right);
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1264
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1265 uint vert_step = child_wid->GetVerticalStepSize(sizing);
11966
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1266 uint child_height = ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding_top - child_wid->padding_bottom, vert_step);
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1267 uint child_pos_y = child_wid->padding_top + ComputeOffset(child_height, given_height - child_wid->padding_top - child_wid->padding_bottom);
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
1268
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1269 child_wid->AssignSizePosition(sizing, x + child_pos_x, y + child_pos_y, child_width, child_height, (this->resize_x > 0), (this->resize_y > 0), rtl);
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1270 }
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1271 }
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1272
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1273 void NWidgetStacked::StoreWidgets(Widget *widgets, int length, bool left_moving, bool top_moving, bool rtl)
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1274 {
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1275 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1276 child_wid->StoreWidgets(widgets, length, left_moving, top_moving, rtl);
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1277 }
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1278 }
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1279
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1280 void NWidgetStacked::Draw(const Window *w)
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1281 {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1282 assert(this->type == NWID_LAYERED); // Currently, NWID_SELECTION is not supported.
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1283 /* Render from back to front. */
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1284 for (NWidgetBase *child_wid = this->tail; child_wid != NULL; child_wid = child_wid->prev) {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1285 child_wid->Draw(w);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1286 }
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1287 }
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1288
12102
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1289 NWidgetCore *NWidgetStacked::GetWidgetFromPos(int x, int y)
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1290 {
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1291 if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return NULL;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1292 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1293 NWidgetCore *nwid = child_wid->GetWidgetFromPos(x, y);
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1294 if (nwid != NULL) return nwid;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1295 }
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1296 return NULL;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1297 }
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1298
12255
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1299 NWidgetPIPContainer::NWidgetPIPContainer(WidgetType tp, NWidContainerFlags flags) : NWidgetContainer(tp)
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1300 {
12255
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1301 this->flags = flags;
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1302 }
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1303
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1304 /**
11528
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1305 * Set additional pre/inter/post space for the container.
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1306 *
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1307 * @param pip_pre Additional space in front of the first child widget (above
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1308 * for the vertical container, at the left for the horizontal container).
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1309 * @param pip_inter Additional space between two child widgets.
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1310 * @param pip_post Additional space after the last child widget (below for the
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1311 * vertical container, at the right for the horizontal container).
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1312 */
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1313 void NWidgetPIPContainer::SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post)
11528
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1314 {
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1315 this->pip_pre = pip_pre;
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1316 this->pip_inter = pip_inter;
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1317 this->pip_post = pip_post;
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1318 }
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1319
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1320 void NWidgetPIPContainer::Draw(const Window *w)
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1321 {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1322 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1323 child_wid->Draw(w);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1324 }
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1325 }
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1326
12102
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1327 NWidgetCore *NWidgetPIPContainer::GetWidgetFromPos(int x, int y)
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1328 {
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1329 if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return NULL;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1330
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1331 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1332 NWidgetCore *nwid = child_wid->GetWidgetFromPos(x, y);
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1333 if (nwid != NULL) return nwid;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1334 }
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1335 return NULL;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1336 }
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1337
11799
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
1338 /** Horizontal container widget. */
12255
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1339 NWidgetHorizontal::NWidgetHorizontal(NWidContainerFlags flags) : NWidgetPIPContainer(NWID_HORIZONTAL, flags)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1340 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1341 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1342
12323
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1343 int NWidgetHorizontal::SetupSmallestSize(Window *w)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1344 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1345 int biggest_index = -1;
11965
a34cf1819c8d (svn r16371) -Codechange (r16367): Properly align comments.
alberth <alberth@openttd.org>
parents: 11964
diff changeset
1346 this->smallest_x = 0; // Sum of minimal size of all childs.
a34cf1819c8d (svn r16371) -Codechange (r16367): Properly align comments.
alberth <alberth@openttd.org>
parents: 11964
diff changeset
1347 this->smallest_y = 0; // Biggest child.
a34cf1819c8d (svn r16371) -Codechange (r16367): Properly align comments.
alberth <alberth@openttd.org>
parents: 11964
diff changeset
1348 this->fill_x = false; // true if at least one child allows fill_x.
a34cf1819c8d (svn r16371) -Codechange (r16367): Properly align comments.
alberth <alberth@openttd.org>
parents: 11964
diff changeset
1349 this->fill_y = true; // true if all childs allow fill_y.
a34cf1819c8d (svn r16371) -Codechange (r16367): Properly align comments.
alberth <alberth@openttd.org>
parents: 11964
diff changeset
1350 this->resize_x = 0; // smallest non-zero child widget resize step.
a34cf1819c8d (svn r16371) -Codechange (r16367): Properly align comments.
alberth <alberth@openttd.org>
parents: 11964
diff changeset
1351 this->resize_y = 1; // smallest common child resize step
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1352
12255
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1353 /* 1. Forward call, collect biggest nested array index, and longest child length. */
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1354 uint longest = 0; // Longest child found.
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1355 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
12323
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1356 int idx = child_wid->SetupSmallestSize(w);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1357 biggest_index = max(biggest_index, idx);
12255
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1358 longest = max(longest, child_wid->smallest_x);
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1359 }
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1360 /* 2. For containers that must maintain equal width, extend child minimal size. */
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1361 if (this->flags & NC_EQUALSIZE) {
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1362 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1363 if (child_wid->fill_x) child_wid->smallest_x = longest;
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1364 }
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1365 }
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1366 /* 3. Move PIP space to the childs, compute smallest, fill, and resize values of the container. */
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1367 if (this->head != NULL) this->head->padding_left += this->pip_pre;
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1368 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
1369 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
1370 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
1371 } 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
1372 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
1373 }
bf92950ea00b (svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents: 11500
diff changeset
1374
11961
69a41fde01e1 (svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents: 11836
diff changeset
1375 this->smallest_x += child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right;
69a41fde01e1 (svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents: 11836
diff changeset
1376 this->smallest_y = max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1377 this->fill_x |= child_wid->fill_x;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1378 this->fill_y &= child_wid->fill_y;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1379
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1380 if (child_wid->resize_x > 0) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1381 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
1382 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1383 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
1384 }
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
1385 /* 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
1386 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
1387
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1388 return biggest_index;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1389 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1390
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1391 void NWidgetHorizontal::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1392 {
11961
69a41fde01e1 (svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents: 11836
diff changeset
1393 assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1394
11961
69a41fde01e1 (svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents: 11836
diff changeset
1395 uint additional_length = given_width - this->smallest_x; // Additional width given to us.
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1396 StoreSizePosition(sizing, x, y, given_width, given_height, allow_resize_x, allow_resize_y);
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1397
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1398 /* In principle, the additional horizontal space is distributed evenly over the available resizable childs. Due to step sizes, this may not always be feasible.
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1399 * To make resizing work as good as possible, first childs with biggest step sizes are done. These may get less due to rounding down.
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1400 * This additional space is then given to childs with smaller step sizes. This will give a good result when resize steps of each child is a multiple
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1401 * of the child with the smallest non-zero stepsize.
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1402 *
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1403 * Since child sizes are computed out of order, positions cannot be calculated until all sizes are known. That means it is not possible to compute the child
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1404 * size and position, and directly call child->AssignSizePosition() with the computed values.
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1405 * Instead, computed child widths and heights are stored in child->current_x and child->current_y values. That is allowed, since this method overwrites those values
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1406 * then we call the child.
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1407 */
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1408
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1409 /* First loop: Find biggest stepsize, find number of childs that want a piece of the pie, handle vertical size for all childs, handle horizontal size for non-resizing childs. */
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1410 int num_changing_childs = 0; // Number of childs that can change size.
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1411 uint biggest_stepsize = 0;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1412 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1413 uint hor_step = child_wid->GetHorizontalStepSize(sizing);
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1414 if (hor_step > 0) {
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1415 num_changing_childs++;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1416 biggest_stepsize = max(biggest_stepsize, hor_step);
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1417 } else {
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1418 child_wid->current_x = child_wid->smallest_x;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1419 }
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1420
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1421 uint vert_step = child_wid->GetVerticalStepSize(sizing);
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1422 child_wid->current_y = ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding_top - child_wid->padding_bottom, vert_step);
11461
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
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1425 /* Second loop: Allocate the additional horizontal space over the resizing childs, starting with the biggest resize steps. */
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1426 while (biggest_stepsize > 0) {
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1427 uint next_biggest_stepsize = 0;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1428 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1429 uint hor_step = child_wid->GetHorizontalStepSize(sizing);
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1430 if (hor_step > biggest_stepsize) continue; // Already done
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1431 if (hor_step == biggest_stepsize) {
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1432 uint increment = additional_length / num_changing_childs;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1433 num_changing_childs--;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1434 if (hor_step > 1) increment -= increment % hor_step;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1435 child_wid->current_x = child_wid->smallest_x + increment;
12117
aecfa01ba5fb (svn r16530) -Fix [FS#2964], (r16501): Deduct additional widget length given away to a child from the total (Hirundo).
alberth <alberth@openttd.org>
parents: 12102
diff changeset
1436 additional_length -= increment;
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1437 continue;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1438 }
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1439 next_biggest_stepsize = max(next_biggest_stepsize, hor_step);
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1440 }
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1441 biggest_stepsize = next_biggest_stepsize;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1442 }
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1443 assert(num_changing_childs == 0);
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1444
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1445 /* Third loop: Compute position and call the child. */
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1446 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
1447 allow_resize_x = (this->resize_x > 0);
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1448 NWidgetBase *child_wid = rtl ? this->tail : this->head;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1449 while (child_wid != NULL) {
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1450 uint child_width = child_wid->current_x;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1451 uint child_x = x + position + (rtl ? child_wid->padding_right : child_wid->padding_left);
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1452 uint child_y = y + child_wid->padding_top + ComputeOffset(child_wid->current_y, given_height - child_wid->padding_top - child_wid->padding_bottom);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1453
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1454 child_wid->AssignSizePosition(sizing, child_x, child_y, child_width, child_wid->current_y, allow_resize_x, (this->resize_y > 0), rtl);
11511
bf92950ea00b (svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents: 11500
diff changeset
1455 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
1456 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
1457
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1458 child_wid = rtl ? child_wid->prev : child_wid->next;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1459 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1460 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1462 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
1463 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1464 NWidgetBase *child_wid = rtl ? this->tail : this->head;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1465 while (child_wid != NULL) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1466 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
1467 left_moving |= (child_wid->resize_x > 0);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1468
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1469 child_wid = rtl ? child_wid->prev : child_wid->next;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1470 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1471 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1472
11799
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
1473 /** Horizontal left-to-right container widget. */
12255
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1474 NWidgetHorizontalLTR::NWidgetHorizontalLTR(NWidContainerFlags flags) : NWidgetHorizontal(flags)
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
1475 {
d29f1358f95b (svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents: 11495
diff changeset
1476 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
1477 }
d29f1358f95b (svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents: 11495
diff changeset
1478
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1479 void NWidgetHorizontalLTR::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl)
11500
d29f1358f95b (svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents: 11495
diff changeset
1480 {
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1481 NWidgetHorizontal::AssignSizePosition(sizing, x, y, given_width, given_height, allow_resize_x, allow_resize_y, false);
11500
d29f1358f95b (svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents: 11495
diff changeset
1482 }
d29f1358f95b (svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents: 11495
diff changeset
1483
d29f1358f95b (svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents: 11495
diff changeset
1484 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
1485 {
d29f1358f95b (svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents: 11495
diff changeset
1486 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
1487 }
d29f1358f95b (svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents: 11495
diff changeset
1488
11799
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
1489 /** Vertical container widget. */
12255
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1490 NWidgetVertical::NWidgetVertical(NWidContainerFlags flags) : NWidgetPIPContainer(NWID_VERTICAL, flags)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1491 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1492 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1493
12323
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1494 int NWidgetVertical::SetupSmallestSize(Window *w)
11461
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 int biggest_index = -1;
11965
a34cf1819c8d (svn r16371) -Codechange (r16367): Properly align comments.
alberth <alberth@openttd.org>
parents: 11964
diff changeset
1497 this->smallest_x = 0; // Biggest child.
a34cf1819c8d (svn r16371) -Codechange (r16367): Properly align comments.
alberth <alberth@openttd.org>
parents: 11964
diff changeset
1498 this->smallest_y = 0; // Sum of minimal size of all childs.
a34cf1819c8d (svn r16371) -Codechange (r16367): Properly align comments.
alberth <alberth@openttd.org>
parents: 11964
diff changeset
1499 this->fill_x = true; // true if all childs allow fill_x.
a34cf1819c8d (svn r16371) -Codechange (r16367): Properly align comments.
alberth <alberth@openttd.org>
parents: 11964
diff changeset
1500 this->fill_y = false; // true if at least one child allows fill_y.
a34cf1819c8d (svn r16371) -Codechange (r16367): Properly align comments.
alberth <alberth@openttd.org>
parents: 11964
diff changeset
1501 this->resize_x = 1; // smallest common child resize step
a34cf1819c8d (svn r16371) -Codechange (r16367): Properly align comments.
alberth <alberth@openttd.org>
parents: 11964
diff changeset
1502 this->resize_y = 0; // smallest non-zero child widget resize step.
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1503
12255
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1504 /* 1. Forward call, collect biggest nested array index, and longest child length. */
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1505 uint highest = 0; // Highest child found.
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1506 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
12323
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1507 int idx = child_wid->SetupSmallestSize(w);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1508 biggest_index = max(biggest_index, idx);
12255
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1509 highest = max(highest, child_wid->smallest_y);
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1510 }
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1511 /* 2. For containers that must maintain equal width, extend child minimal size. */
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1512 if (this->flags & NC_EQUALSIZE) {
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1513 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1514 if (child_wid->fill_y) child_wid->smallest_y = highest;
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1515 }
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1516 }
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1517 /* 3. Move PIP space to the childs, compute smallest, fill, and resize values of the container. */
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1518 if (this->head != NULL) this->head->padding_top += this->pip_pre;
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1519 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
1520 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
1521 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
1522 } 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
1523 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
1524 }
bf92950ea00b (svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents: 11500
diff changeset
1525
11961
69a41fde01e1 (svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents: 11836
diff changeset
1526 this->smallest_y += child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom;
69a41fde01e1 (svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents: 11836
diff changeset
1527 this->smallest_x = max(this->smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1528 this->fill_y |= child_wid->fill_y;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1529 this->fill_x &= child_wid->fill_x;
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 (child_wid->resize_y > 0) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1532 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
1533 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1534 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
1535 }
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
1536 /* 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
1537 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
1538
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1539 return biggest_index;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1540 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1541
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1542 void NWidgetVertical::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1543 {
11961
69a41fde01e1 (svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents: 11836
diff changeset
1544 assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1545
11961
69a41fde01e1 (svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents: 11836
diff changeset
1546 int additional_length = given_height - this->smallest_y; // Additional height given to us.
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1547 StoreSizePosition(sizing, x, y, given_width, given_height, allow_resize_x, allow_resize_y);
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1548
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1549 /* Like the horizontal container, the vertical container also distributes additional height evenly, starting with the childs with the biggest resize steps.
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1550 * It also stores computed widths and heights into current_x and current_y values of the child.
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1551 */
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1552
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1553 /* First loop: Find biggest stepsize, find number of childs that want a piece of the pie, handle horizontal size for all childs, handle vertical size for non-resizing childs. */
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1554 int num_changing_childs = 0; // Number of childs that can change size.
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1555 uint biggest_stepsize = 0;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1556 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1557 uint vert_step = child_wid->GetVerticalStepSize(sizing);
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1558 if (vert_step > 0) {
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1559 num_changing_childs++;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1560 biggest_stepsize = max(biggest_stepsize, vert_step);
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1561 } else {
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1562 child_wid->current_y = child_wid->smallest_y;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1563 }
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1564
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1565 uint hor_step = child_wid->GetHorizontalStepSize(sizing);
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1566 child_wid->current_x = ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding_left - child_wid->padding_right, hor_step);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1567 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1568
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1569 /* Second loop: Allocate the additional vertical space over the resizing childs, starting with the biggest resize steps. */
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1570 while (biggest_stepsize > 0) {
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1571 uint next_biggest_stepsize = 0;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1572 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1573 uint vert_step = child_wid->GetVerticalStepSize(sizing);
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1574 if (vert_step > biggest_stepsize) continue; // Already done
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1575 if (vert_step == biggest_stepsize) {
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1576 uint increment = additional_length / num_changing_childs;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1577 num_changing_childs--;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1578 if (vert_step > 1) increment -= increment % vert_step;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1579 child_wid->current_y = child_wid->smallest_y + increment;
12117
aecfa01ba5fb (svn r16530) -Fix [FS#2964], (r16501): Deduct additional widget length given away to a child from the total (Hirundo).
alberth <alberth@openttd.org>
parents: 12102
diff changeset
1580 additional_length -= increment;
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1581 continue;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1582 }
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1583 next_biggest_stepsize = max(next_biggest_stepsize, vert_step);
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1584 }
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1585 biggest_stepsize = next_biggest_stepsize;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1586 }
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1587 assert(num_changing_childs == 0);
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1588
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1589 /* Third loop: Compute position and call the child. */
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1590 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
1591 allow_resize_y = (this->resize_y > 0);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1592 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1593 uint child_x = x + (rtl ? child_wid->padding_right : child_wid->padding_left) +
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1594 ComputeOffset(child_wid->current_x, given_width - child_wid->padding_left - child_wid->padding_right);
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1595 uint child_height = child_wid->current_y;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1596
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1597 child_wid->AssignSizePosition(sizing, child_x, y + position + child_wid->padding_top, child_wid->current_x, child_height, (this->resize_x > 0), allow_resize_y, rtl);
11511
bf92950ea00b (svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents: 11500
diff changeset
1598 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
1599 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
1600 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1601 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1602
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1603 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
1604 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1605 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
1606 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
1607 top_moving |= (child_wid->resize_y > 0);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1608 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1609 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1610
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1611 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1612 * Generic spacer widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1613 * @param length Horizontal size of the spacer widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1614 * @param height Vertical size of the spacer widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1615 */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1616 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
1617 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1618 this->SetMinimalSize(length, height);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1619 this->SetResize(0, 0);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1620 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1621
12323
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1622 int NWidgetSpacer::SetupSmallestSize(Window *w)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1623 {
11961
69a41fde01e1 (svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents: 11836
diff changeset
1624 this->smallest_x = this->min_x;
69a41fde01e1 (svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents: 11836
diff changeset
1625 this->smallest_y = this->min_y;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1626 return -1;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1627 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1628
12100
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
1629 void NWidgetSpacer::FillNestedArray(NWidgetCore **array, uint length)
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
1630 {
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
1631 }
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
1632
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1633 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
1634 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1635 /* Spacer widgets are never stored in the widget array. */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1636 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1637
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1638 void NWidgetSpacer::Draw(const Window *w)
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1639 {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1640 /* Spacer widget is never visible. */
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1641 }
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1642
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1643 void NWidgetSpacer::Invalidate(const Window *w) const
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1644 {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1645 /* Spacer widget never need repainting. */
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1646 }
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1647
12102
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1648 NWidgetCore *NWidgetSpacer::GetWidgetFromPos(int x, int y)
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1649 {
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1650 return NULL;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1651 }
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1652
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1653 NWidgetBase *NWidgetSpacer::GetWidgetOfType(WidgetType tp)
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1654 {
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1655 return (this->type == tp) ? this : NULL;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1656 }
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1657
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1658 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1659 * Constructor parent nested widgets.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1660 * @param tp Type of parent widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1661 * @param colour Colour of the parent widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1662 * @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
1663 * @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
1664 * vertical container will be inserted while adding the first
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1665 * child widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1666 */
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1667 NWidgetBackground::NWidgetBackground(WidgetType tp, Colours colour, int index, NWidgetPIPContainer *child) : NWidgetCore(tp, colour, true, true, 0x0, STR_NULL)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1668 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1669 this->SetIndex(index);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1670 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
1671 assert(index >= 0);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1672 this->child = child;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1673 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1674
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1675 NWidgetBackground::~NWidgetBackground()
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1676 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1677 if (this->child != NULL) delete this->child;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1678 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1679
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1680 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1681 * Add a child to the parent.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1682 * @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
1683 *
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1684 * 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
1685 * 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
1686 */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1687 void NWidgetBackground::Add(NWidgetBase *nwid)
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1688 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1689 if (this->child == NULL) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1690 this->child = new NWidgetVertical();
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1691 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1692 this->child->Add(nwid);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1693 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1694
11528
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1695 /**
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1696 * Set additional pre/inter/post space for the background widget.
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1697 *
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1698 * @param pip_pre Additional space in front of the first child widget (above
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1699 * for the vertical container, at the left for the horizontal container).
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1700 * @param pip_inter Additional space between two child widgets.
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1701 * @param pip_post Additional space after the last child widget (below for the
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1702 * vertical container, at the right for the horizontal container).
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1703 * @note Using this function implies that the widget has (or will have) child widgets.
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1704 */
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1705 void NWidgetBackground::SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post)
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1706 {
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1707 if (this->child == NULL) {
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1708 this->child = new NWidgetVertical();
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1709 }
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1710 this->child->SetPIP(pip_pre, pip_inter, pip_post);
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1711 }
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1712
12323
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1713 int NWidgetBackground::SetupSmallestSize(Window *w)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1714 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1715 int biggest_index = this->index;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1716 if (this->child != NULL) {
12323
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1717 int idx = this->child->SetupSmallestSize(w);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1718 biggest_index = max(biggest_index, idx);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1719
11961
69a41fde01e1 (svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents: 11836
diff changeset
1720 this->smallest_x = this->child->smallest_x;
69a41fde01e1 (svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents: 11836
diff changeset
1721 this->smallest_y = this->child->smallest_y;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1722 this->fill_x = this->child->fill_x;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1723 this->fill_y = this->child->fill_y;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1724 this->resize_x = this->child->resize_x;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1725 this->resize_y = this->child->resize_y;
11961
69a41fde01e1 (svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents: 11836
diff changeset
1726 } else {
12323
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1727 Dimension d = {this->min_x, this->min_y};
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1728 if (w != NULL) { // A non-NULL window pointer acts as switch to turn dynamic widget size on.
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1729 if (this->index >= 0) d = maxdim(d, w->GetWidgetContentSize(this->index));
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1730 if (this->type == WWT_FRAME || this->type == WWT_INSET) d = maxdim(d, GetStringBoundingBox(this->widget_data));
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1731 }
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1732 this->smallest_x = d.width;
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1733 this->smallest_y = d.height;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1734 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1735
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1736 return biggest_index;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1737 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1738
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1739 void NWidgetBackground::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1740 {
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1741 StoreSizePosition(sizing, x, y, given_width, given_height, allow_resize_x, allow_resize_y);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1742
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
1743 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
1744 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
1745 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
1746 uint height = given_height - this->child->padding_top - this->child->padding_bottom;
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1747 this->child->AssignSizePosition(sizing, x + x_offset, y + this->child->padding_top, width, height, (this->resize_x > 0), (this->resize_y > 0), rtl);
11511
bf92950ea00b (svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents: 11500
diff changeset
1748 }
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1749 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1750
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1751 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
1752 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1753 NWidgetCore::StoreWidgets(widgets, length, left_moving, top_moving, rtl);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1754 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
1755 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1756
12100
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
1757 void NWidgetBackground::FillNestedArray(NWidgetCore **array, uint length)
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
1758 {
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
1759 if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
1760 if (this->child != NULL) this->child->FillNestedArray(array, length);
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
1761 }
be22d89e79ae (svn r16513) -Codechange: Add nested widgets root and array to Window, and NWidgetBase::FillNestedArray() to fill the array.
alberth <alberth@openttd.org>
parents: 12091
diff changeset
1762
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1763 void NWidgetBackground::Draw(const Window *w)
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1764 {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1765 if (this->current_x == 0 || this->current_y == 0) return;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1766
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1767 Rect r;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1768 r.left = this->pos_x;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1769 r.right = this->pos_x + this->current_x - 1;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1770 r.top = this->pos_y;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1771 r.bottom = this->pos_y + this->current_y - 1;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1772
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1773 const DrawPixelInfo *dpi = _cur_dpi;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1774 if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top) return;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1775
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1776 switch (this->type) {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1777 case WWT_PANEL:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1778 assert(this->widget_data == 0);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1779 DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, this->IsLowered() ? FR_LOWERED : FR_NONE);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1780 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1781
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1782 case WWT_FRAME:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1783 DrawFrame(r, this->colour, this->widget_data);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1784 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1785
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1786 case WWT_INSET:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1787 DrawInset(r, this->colour, this->widget_data);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1788 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1789
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1790 default:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1791 NOT_REACHED();
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1792 }
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1793
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1794 if (this->child != NULL) this->child->Draw(w);
12274
ab8191734216 (svn r16689) -Codechange: Allow for rendering of parameterized text of nested widgets in Window::DrawWidget, adapt intro and town directory windows.
alberth <alberth@openttd.org>
parents: 12255
diff changeset
1795 if (this->index >= 0) w->DrawWidget(r, this->index);
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1796
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1797 if (this->IsDisabled()) {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1798 GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, _colour_gradient[this->colour & 0xF][2], FILLRECT_CHECKER);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1799 }
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1800 }
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1801
12102
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1802 NWidgetCore *NWidgetBackground::GetWidgetFromPos(int x, int y)
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1803 {
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1804 NWidgetCore *nwid = NULL;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1805 if (IsInsideBS(x, this->pos_x, this->current_x) && IsInsideBS(y, this->pos_y, this->current_y)) {
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1806 if (this->child != NULL) nwid = this->child->GetWidgetFromPos(x, y);
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1807 if (nwid == NULL) nwid = this;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1808 }
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1809 return nwid;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1810 }
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1811
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1812 Scrollbar *NWidgetBackground::FindScrollbar(Window *w, bool allow_next)
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1813 {
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1814 if (this->index > 0 && allow_next && this->child == NULL && (uint)(this->index) + 1 < w->nested_array_size) {
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1815 NWidgetCore *next_wid = w->nested_array[this->index + 1];
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1816 if (next_wid != NULL) return next_wid->FindScrollbar(w, false);
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1817 }
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1818 return NULL;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1819 }
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1820
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1821 NWidgetBase *NWidgetBackground::GetWidgetOfType(WidgetType tp)
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1822 {
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1823 NWidgetBase *nwid = NULL;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1824 if (this->child != NULL) nwid = this->child->GetWidgetOfType(tp);
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1825 if (nwid == NULL && this->type == tp) nwid = this;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1826 return nwid;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1827 }
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
1828
12373
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1829 /** Reset the cached dimensions. */
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1830 /* static */ void NWidgetLeaf::InvalidateDimensionCache()
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1831 {
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1832 stickybox_dimension.width = stickybox_dimension.height = 0;
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1833 resizebox_dimension.width = resizebox_dimension.height = 0;
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1834 closebox_dimension.width = closebox_dimension.height = 0;
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1835 }
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1836
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1837 Dimension NWidgetLeaf::stickybox_dimension = {0, 0};
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1838 Dimension NWidgetLeaf::resizebox_dimension = {0, 0};
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1839 Dimension NWidgetLeaf::closebox_dimension = {0, 0};
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1840
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1841 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1842 * Nested leaf widget.
11799
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
1843 * @param tp Type of leaf widget.
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
1844 * @param colour Colour of the leaf widget.
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
1845 * @param index Index in the widget array used by the window system.
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
1846 * @param data Data of the widget.
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
1847 * @param tip Tooltip of the widget.
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1848 */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1849 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
1850 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1851 this->SetIndex(index);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1852 this->SetMinimalSize(0, 0);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1853 this->SetResize(0, 0);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1854
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1855 switch (tp) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1856 case WWT_EMPTY:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1857 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1858
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1859 case WWT_PUSHBTN:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1860 this->SetFill(false, false);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1861 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1862
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1863 case WWT_IMGBTN:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1864 case WWT_PUSHIMGBTN:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1865 case WWT_IMGBTN_2:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1866 this->SetFill(false, false);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1867 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1868
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1869 case WWT_TEXTBTN:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1870 case WWT_PUSHTXTBTN:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1871 case WWT_TEXTBTN_2:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1872 case WWT_LABEL:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1873 case WWT_TEXT:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1874 case WWT_MATRIX:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1875 case WWT_EDITBOX:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1876 this->SetFill(false, false);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1877 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1878
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1879 case WWT_SCROLLBAR:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1880 case WWT_SCROLL2BAR:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1881 this->SetFill(false, true);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1882 this->SetResize(0, 1);
12195
ee5c5c8f0557 (svn r16609) -Codechange: Introduction of widget sizes and offsets used while drawing.
alberth <alberth@openttd.org>
parents: 12159
diff changeset
1883 this->min_x = WD_VSCROLLBAR_WIDTH;
11730
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11528
diff changeset
1884 this->SetDataTip(0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1885 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1886
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1887 case WWT_CAPTION:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1888 this->SetFill(true, false);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1889 this->SetResize(1, 0);
12195
ee5c5c8f0557 (svn r16609) -Codechange: Introduction of widget sizes and offsets used while drawing.
alberth <alberth@openttd.org>
parents: 12159
diff changeset
1890 this->min_y = WD_CAPTION_HEIGHT;
11730
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11528
diff changeset
1891 this->SetDataTip(data, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1892 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1893
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1894 case WWT_HSCROLLBAR:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1895 this->SetFill(true, false);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1896 this->SetResize(1, 0);
12195
ee5c5c8f0557 (svn r16609) -Codechange: Introduction of widget sizes and offsets used while drawing.
alberth <alberth@openttd.org>
parents: 12159
diff changeset
1897 this->min_y = WD_HSCROLLBAR_HEIGHT;
11730
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11528
diff changeset
1898 this->SetDataTip(0x0, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1899 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1900
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1901 case WWT_STICKYBOX:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1902 this->SetFill(false, false);
12373
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1903 this->SetMinimalSize(WD_STICKYBOX_WIDTH, 14);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1904 this->SetDataTip(STR_NULL, STR_STICKY_BUTTON);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1905 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1906
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1907 case WWT_RESIZEBOX:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1908 this->SetFill(false, false);
12373
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1909 this->SetMinimalSize(WD_RESIZEBOX_WIDTH, 12);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1910 this->SetDataTip(STR_NULL, STR_RESIZE_BUTTON);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1911 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1912
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1913 case WWT_CLOSEBOX:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1914 this->SetFill(false, false);
12195
ee5c5c8f0557 (svn r16609) -Codechange: Introduction of widget sizes and offsets used while drawing.
alberth <alberth@openttd.org>
parents: 12159
diff changeset
1915 this->SetMinimalSize(WD_CLOSEBOX_WIDTH, 14);
11730
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11528
diff changeset
1916 this->SetDataTip(STR_BLACK_CROSS, STR_TOOLTIP_CLOSE_WINDOW);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1917 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1918
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1919 case WWT_DROPDOWN:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1920 this->SetFill(false, false);
12195
ee5c5c8f0557 (svn r16609) -Codechange: Introduction of widget sizes and offsets used while drawing.
alberth <alberth@openttd.org>
parents: 12159
diff changeset
1921 this->min_y = WD_DROPDOWN_HEIGHT;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1922 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1923
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1924 default:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1925 NOT_REACHED();
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1926 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1927 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1928
12323
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1929 int NWidgetLeaf::SetupSmallestSize(Window *w)
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1930 {
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1931 Dimension d = {this->min_x, this->min_y}; // At least minimal size is needed.
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1932
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1933 if (w != NULL) { // A non-NULL window pointer acts as switch to turn dynamic widget sizing on.
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1934 Dimension d2 = {0, 0};
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1935 if (this->index >= 0) d2 = maxdim(d2, w->GetWidgetContentSize(this->index)); // If appropriate, ask window for smallest size.
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1936
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1937 /* Check size requirements of the widget itself too.
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1938 * Also, add the offset used for rendering.
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1939 */
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1940 switch (this->type) {
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1941 case WWT_EMPTY:
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1942 case WWT_MATRIX:
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1943 case WWT_SCROLLBAR:
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1944 case WWT_SCROLL2BAR:
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1945 case WWT_HSCROLLBAR:
12373
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1946 break;
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1947
12323
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1948 case WWT_STICKYBOX:
12373
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1949 if (NWidgetLeaf::stickybox_dimension.width == 0) {
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1950 NWidgetLeaf::stickybox_dimension = maxdim(GetSpriteSize(SPR_PIN_UP), GetSpriteSize(SPR_PIN_DOWN));
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1951 NWidgetLeaf::stickybox_dimension.width += WD_STICKYBOX_LEFT + WD_STICKYBOX_RIGHT;
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1952 NWidgetLeaf::stickybox_dimension.height += WD_STICKYBOX_TOP + WD_STICKYBOX_BOTTOM;
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1953 }
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1954 d2 = maxdim(d2, NWidgetLeaf::stickybox_dimension);
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1955 break;
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1956
12323
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1957 case WWT_RESIZEBOX:
12373
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1958 if (NWidgetLeaf::resizebox_dimension.width == 0) {
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1959 NWidgetLeaf::resizebox_dimension = maxdim(GetSpriteSize(SPR_WINDOW_RESIZE_LEFT), GetSpriteSize(SPR_WINDOW_RESIZE_RIGHT));
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1960 NWidgetLeaf::resizebox_dimension.width += WD_RESIZEBOX_LEFT + WD_RESIZEBOX_RIGHT;
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1961 NWidgetLeaf::resizebox_dimension.height += WD_RESIZEBOX_TOP + WD_RESIZEBOX_BOTTOM;
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1962 }
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1963 d2 = maxdim(d2, NWidgetLeaf::resizebox_dimension);
12323
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1964 break;
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1965
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1966 case WWT_PUSHBTN:
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1967 case WWT_EDITBOX:
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1968 d2.width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1969 d2.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1970 break;
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1971
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1972 case WWT_IMGBTN:
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1973 case WWT_PUSHIMGBTN:
12373
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1974 d2 = maxdim(d2, GetSpriteSize(this->widget_data));
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1975 d2.height += WD_IMGBTN_TOP + WD_IMGBTN_BOTTOM;
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1976 d2.width += WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT;
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1977 break;
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1978
12323
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1979 case WWT_IMGBTN_2:
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1980 d2 = maxdim(d2, GetSpriteSize(this->widget_data));
12373
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1981 d2 = maxdim(d2, GetSpriteSize(this->widget_data + 1));
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1982 d2.height += WD_IMGBTN2_TOP + WD_IMGBTN2_BOTTOM;
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1983 d2.width += WD_IMGBTN2_LEFT + WD_IMGBTN2_RIGHT;
12323
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1984 break;
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1985
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1986 case WWT_CLOSEBOX:
12373
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1987 if (NWidgetLeaf::closebox_dimension.width == 0) {
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1988 NWidgetLeaf::closebox_dimension = maxdim(GetStringBoundingBox(STR_BLACK_CROSS), GetStringBoundingBox(STR_SILVER_CROSS));
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1989 NWidgetLeaf::closebox_dimension.width += WD_CLOSEBOX_LEFT + WD_CLOSEBOX_RIGHT;
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1990 NWidgetLeaf::closebox_dimension.height += WD_CLOSEBOX_TOP + WD_CLOSEBOX_BOTTOM;
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1991 }
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1992 d2 = maxdim(d2, NWidgetLeaf::closebox_dimension);
12323
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1993 break;
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1994
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1995 case WWT_TEXTBTN:
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1996 case WWT_PUSHTXTBTN:
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1997 case WWT_TEXTBTN_2:
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1998 d2 = maxdim(d2, GetStringBoundingBox(this->widget_data));
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1999 d2.width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2000 d2.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2001 break;
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2002
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2003 case WWT_LABEL:
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2004 case WWT_TEXT:
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2005 d2 = maxdim(d2, GetStringBoundingBox(this->widget_data));
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2006 break;
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2007
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2008 case WWT_CAPTION:
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2009 d2 = maxdim(d2, GetStringBoundingBox(this->widget_data));
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2010 d2.width += WD_CAPTIONTEXT_LEFT + WD_CAPTIONTEXT_RIGHT;
12373
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
2011 d2.height += WD_CAPTIONTEXT_TOP + WD_CAPTIONTEXT_BOTTOM;
12323
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2012 break;
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2013
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2014 case WWT_DROPDOWN:
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2015 d2 = maxdim(d2, GetStringBoundingBox(this->widget_data));
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2016 d2.width += WD_DROPDOWNTEXT_LEFT + WD_DROPDOWNTEXT_RIGHT;
12373
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
2017 d2.height += WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM;
12323
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2018 break;
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2019
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2020 default:
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2021 NOT_REACHED();
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2022 }
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2023 d = maxdim(d, d2);
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2024 }
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2025 this->smallest_x = d.width;
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2026 this->smallest_y = d.height;
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2027 /* All other data is already at the right place. */
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2028 return this->index;
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2029 }
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2030
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2031 void NWidgetLeaf::Draw(const Window *w)
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2032 {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2033 if (this->current_x == 0 || this->current_y == 0) return;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2034
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2035 Rect r;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2036 r.left = this->pos_x;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2037 r.right = this->pos_x + this->current_x - 1;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2038 r.top = this->pos_y;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2039 r.bottom = this->pos_y + this->current_y - 1;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2040
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2041 const DrawPixelInfo *dpi = _cur_dpi;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2042 if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top) return;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2043
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2044 bool clicked = this->IsLowered();
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2045 switch (this->type) {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2046 case WWT_EMPTY:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2047 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2048
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2049 case WWT_PUSHBTN:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2050 assert(this->widget_data == 0);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2051 DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, (clicked) ? FR_LOWERED : FR_NONE);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2052 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2053
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2054 case WWT_IMGBTN:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2055 case WWT_PUSHIMGBTN:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2056 case WWT_IMGBTN_2:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2057 DrawImageButtons(r, this->type,this->colour, clicked, this->widget_data);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2058 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2059
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2060 case WWT_TEXTBTN:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2061 case WWT_PUSHTXTBTN:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2062 case WWT_TEXTBTN_2:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2063 DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, (clicked) ? FR_LOWERED : FR_NONE);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2064 DrawLabel(r, this->type, clicked, this->widget_data);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2065 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2066
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2067 case WWT_LABEL:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2068 DrawLabel(r, this->type, clicked, this->widget_data);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2069 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2070
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2071 case WWT_TEXT:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2072 DrawText(r, (TextColour)this->colour, this->widget_data);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2073 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2074
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2075 case WWT_MATRIX:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2076 DrawMatrix(r, this->colour, clicked, this->widget_data);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2077 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2078
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2079 case WWT_EDITBOX:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2080 DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, FR_LOWERED | FR_DARKENED);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2081 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2082
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2083 case WWT_SCROLLBAR:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2084 assert(this->widget_data == 0);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2085 DrawVerticalScrollbar(r, this->colour, (w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_UP,
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2086 (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_MIDDLE,
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2087 (w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_DOWN, &w->vscroll);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2088 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2089
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2090 case WWT_SCROLL2BAR:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2091 assert(this->widget_data == 0);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2092 DrawVerticalScrollbar(r, this->colour, (w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_UP | WF_SCROLL2),
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2093 (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_MIDDLE | WF_SCROLL2),
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2094 (w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_DOWN | WF_SCROLL2), &w->vscroll2);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2095 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2096
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2097 case WWT_CAPTION:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2098 DrawCaption(r, this->colour, w->owner, this->widget_data);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2099 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2100
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2101 case WWT_HSCROLLBAR:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2102 assert(this->widget_data == 0);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2103 DrawHorizontalScrollbar(r, this->colour, (w->flags4 & (WF_SCROLL_UP | WF_HSCROLL)) == (WF_SCROLL_UP | WF_HSCROLL),
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2104 (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL)) == (WF_SCROLL_MIDDLE | WF_HSCROLL),
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2105 (w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL)) == (WF_SCROLL_DOWN | WF_HSCROLL), &w->hscroll);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2106 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2107
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2108 case WWT_STICKYBOX:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2109 assert(this->widget_data == 0);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2110 DrawStickyBox(r, this->colour, !!(w->flags4 & WF_STICKY));
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2111 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2112
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2113 case WWT_RESIZEBOX:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2114 assert(this->widget_data == 0);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2115 DrawResizeBox(r, this->colour, this->pos_x < (uint)(w->width / 2), !!(w->flags4 & WF_SIZING));
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2116 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2117
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2118 case WWT_CLOSEBOX:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2119 DrawCloseBox(r, this->colour, this->widget_data);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2120 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2121
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2122 case WWT_DROPDOWN:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2123 DrawDropdown(r, this->colour, clicked, this->widget_data);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2124 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2125
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2126 default:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2127 NOT_REACHED();
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2128 }
12274
ab8191734216 (svn r16689) -Codechange: Allow for rendering of parameterized text of nested widgets in Window::DrawWidget, adapt intro and town directory windows.
alberth <alberth@openttd.org>
parents: 12255
diff changeset
2129 if (this->index >= 0) w->DrawWidget(r, this->index);
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2130
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2131 if (this->IsDisabled()) {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2132 GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, _colour_gradient[this->colour & 0xF][2], FILLRECT_CHECKER);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2133 }
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2134 }
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2135
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2136 void NWidgetLeaf::Invalidate(const Window *w) const
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2137 {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2138 if (this->type == WWT_EMPTY) return; // Don't repaint dummy widgets.
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2139 NWidgetBase::Invalidate(w);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2140 }
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2141
12102
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
2142 NWidgetCore *NWidgetLeaf::GetWidgetFromPos(int x, int y)
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
2143 {
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
2144 return (IsInsideBS(x, this->pos_x, this->current_x) && IsInsideBS(y, this->pos_y, this->current_y)) ? this : NULL;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
2145 }
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
2146
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
2147 Scrollbar *NWidgetLeaf::FindScrollbar(Window *w, bool allow_next)
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
2148 {
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
2149 if (this->type == WWT_SCROLLBAR) return &w->vscroll;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
2150 if (this->type == WWT_SCROLL2BAR) return &w->vscroll2;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
2151
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
2152 if (this->index > 0 && allow_next && (uint)(this->index) + 1 < w->nested_array_size) {
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
2153 NWidgetCore *next_wid = w->nested_array[this->index + 1];
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
2154 if (next_wid != NULL) return next_wid->FindScrollbar(w, false);
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
2155 }
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
2156 return NULL;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
2157 }
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
2158
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
2159 NWidgetBase *NWidgetLeaf::GetWidgetOfType(WidgetType tp)
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
2160 {
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
2161 return (this->type == tp) ? this : NULL;
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
2162 }
a381834fd694 (svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
alberth <alberth@openttd.org>
parents: 12101
diff changeset
2163
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2164 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2165 * Intialize nested widget tree and convert to widget array.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2166 * @param nwid Nested widget tree.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2167 * @param rtl Direction of the language.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2168 * @return Widget array with the converted widgets.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2169 * @note Caller should release returned widget array with \c free(widgets).
11799
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
2170 * @ingroup NestedWidgets
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2171 */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2172 Widget *InitializeNWidgets(NWidgetBase *nwid, bool rtl)
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2173 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2174 /* Initialize nested widgets. */
12323
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2175 int biggest_index = nwid->SetupSmallestSize(NULL);
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
2176 nwid->AssignSizePosition(ST_ARRAY, 0, 0, nwid->smallest_x, nwid->smallest_y, (nwid->resize_x > 0), (nwid->resize_y > 0), rtl);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2177
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2178 /* 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
2179 Widget *widgets = MallocT<Widget>(biggest_index + 2);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2180 int i;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2181 for (i = 0; i < biggest_index + 2; i++) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2182 widgets[i].type = WWT_LAST;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2183 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2184
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2185 /* Store nested widgets in the array. */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2186 nwid->StoreWidgets(widgets, biggest_index + 1, false, false, rtl);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2187
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2188 /* Check that all widgets are used. */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2189 for (i = 0; i < biggest_index + 2; i++) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2190 if (widgets[i].type == WWT_LAST) break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2191 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2192 assert(i == biggest_index + 1);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2193
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2194 /* Fill terminating widget */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2195 static const Widget last_widget = {WIDGETS_END};
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2196 widgets[biggest_index + 1] = last_widget;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2197
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2198 return widgets;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2199 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2200
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2201 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2202 * 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
2203 * @param orig Pointer to original widget array.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2204 * @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
2205 * @param report Report differences to 'misc' debug stream.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2206 * @return Both widget arrays are equal.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2207 */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2208 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
2209 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2210 #define CHECK(var, prn) \
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2211 if (ow->var != gw->var) { \
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2212 same = false; \
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2213 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
2214 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2215 #define CHECK_COORD(var) \
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2216 if (ow->var != gw->var) { \
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2217 same = false; \
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2218 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
2219 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2220
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2221 bool same = true;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2222 for(int idx = 0; ; idx++) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2223 const Widget *ow = orig + idx;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2224 const Widget *gw = gen + idx;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2225
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2226 CHECK(type, "%d")
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2227 CHECK(display_flags, "0x%x")
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2228 CHECK(colour, "%d")
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2229 CHECK_COORD(left)
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2230 CHECK_COORD(right)
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2231 CHECK_COORD(top)
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2232 CHECK_COORD(bottom)
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2233 CHECK(data, "%u")
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2234 CHECK(tooltips, "%u")
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2235
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2236 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
2237 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2238
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2239 return same;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2240
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2241 #undef CHECK
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2242 #undef CHECK_COORD
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2243 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2244
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2245 /* == Conversion code from NWidgetPart array to NWidgetBase* tree == */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2246
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2247 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2248 * 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
2249 *
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2250 * 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
2251 * settings that follow it, until encountering a #EndContainer, another
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2252 * #NWidget, or the end of the parts array.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2253 *
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2254 * @param parts Array with parts of the nested widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2255 * @param count Length of the \a parts array.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2256 * @param dest Address of pointer to use for returning the composed widget.
11750
924e26095f16 (svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
2257 * @param fill_dest Fill the composed widget with child widgets.
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12373
diff changeset
2258 * @param biggest_index Pointer to biggest nested widget index in the tree encountered so far.
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2259 * @return Number of widget part elements used to compose the widget.
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12373
diff changeset
2260 * @precond \c biggest_index != NULL.
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2261 */
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12373
diff changeset
2262 static int MakeNWidget(const NWidgetPart *parts, int count, NWidgetBase **dest, bool *fill_dest, int *biggest_index)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2263 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2264 int num_used = 0;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2265
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2266 *dest = NULL;
11750
924e26095f16 (svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
2267 *fill_dest = false;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2268
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2269 while (count > num_used) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2270 switch (parts->type) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2271 case NWID_SPACER:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2272 if (*dest != NULL) return num_used;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2273 *dest = new NWidgetSpacer(0, 0);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2274 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2275
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2276 case NWID_HORIZONTAL:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2277 if (*dest != NULL) return num_used;
12255
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
2278 *dest = new NWidgetHorizontal(parts->u.cont_flags);
11750
924e26095f16 (svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
2279 *fill_dest = true;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2280 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2281
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
2282 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
2283 if (*dest != NULL) return num_used;
12255
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
2284 *dest = new NWidgetHorizontalLTR(parts->u.cont_flags);
11750
924e26095f16 (svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
2285 *fill_dest = true;
11500
d29f1358f95b (svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents: 11495
diff changeset
2286 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
2287
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2288 case WWT_PANEL:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2289 case WWT_INSET:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2290 case WWT_FRAME:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2291 if (*dest != NULL) return num_used;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2292 *dest = new NWidgetBackground(parts->type, parts->u.widget.colour, parts->u.widget.index);
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12373
diff changeset
2293 *biggest_index = max(*biggest_index, (int)parts->u.widget.index);
11750
924e26095f16 (svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
2294 *fill_dest = true;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2295 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2296
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2297 case NWID_VERTICAL:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2298 if (*dest != NULL) return num_used;
12255
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
2299 *dest = new NWidgetVertical(parts->u.cont_flags);
11750
924e26095f16 (svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
2300 *fill_dest = true;
924e26095f16 (svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
2301 break;
924e26095f16 (svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
2302
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12373
diff changeset
2303 case WPT_FUNCTION: {
11750
924e26095f16 (svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
2304 if (*dest != NULL) return num_used;
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12373
diff changeset
2305 /* Ensure proper functioning even when the called code simply writes its largest index. */
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12373
diff changeset
2306 int biggest = -1;
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12373
diff changeset
2307 *dest = parts->u.func_ptr(&biggest);
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12373
diff changeset
2308 *biggest_index = max(*biggest_index, biggest);
11750
924e26095f16 (svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
2309 *fill_dest = false;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2310 break;
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12373
diff changeset
2311 }
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2312
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
2313 case NWID_SELECTION:
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
2314 case NWID_LAYERED:
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
2315 if (*dest != NULL) return num_used;
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
2316 *dest = new NWidgetStacked(parts->type);
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
2317 *fill_dest = true;
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
2318 break;
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
2319
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
2320
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2321 case WPT_RESIZE: {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2322 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2323 if (nwrb != NULL) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2324 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
2325 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
2326 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2327 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2328 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2329
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2330 case WPT_RESIZE_PTR: {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2331 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2332 if (nwrb != NULL) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2333 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
2334 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
2335 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2336 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2337 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2338
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2339 case WPT_MINSIZE: {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2340 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2341 if (nwrb != NULL) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2342 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
2343 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
2344 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2345 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2346 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2347
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2348 case WPT_MINSIZE_PTR: {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2349 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2350 if (nwrb != NULL) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2351 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
2352 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
2353 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2354 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2355 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2356
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2357 case WPT_FILL: {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2358 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2359 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
2360 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2361 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2362
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2363 case WPT_DATATIP: {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2364 NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2365 if (nwc != NULL) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2366 nwc->widget_data = parts->u.data_tip.data;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2367 nwc->tool_tip = parts->u.data_tip.tooltip;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2368 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2369 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2370 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2371
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2372 case WPT_DATATIP_PTR: {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2373 NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2374 if (nwc != NULL) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2375 nwc->widget_data = parts->u.datatip_ptr->data;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2376 nwc->tool_tip = parts->u.datatip_ptr->tooltip;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2377 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2378 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2379 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2380
11811
b32bfec54ff8 (svn r16201) -Codechange: Add NWidgetBase::SetPadding method.
alberth <alberth@openttd.org>
parents: 11800
diff changeset
2381 case WPT_PADDING:
b32bfec54ff8 (svn r16201) -Codechange: Add NWidgetBase::SetPadding method.
alberth <alberth@openttd.org>
parents: 11800
diff changeset
2382 if (*dest != NULL) (*dest)->SetPadding(parts->u.padding.top, parts->u.padding.right, parts->u.padding.bottom, parts->u.padding.left);
11511
bf92950ea00b (svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents: 11500
diff changeset
2383 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
2384
bf92950ea00b (svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents: 11500
diff changeset
2385 case WPT_PIPSPACE: {
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
2386 NWidgetPIPContainer *nwc = dynamic_cast<NWidgetPIPContainer *>(*dest);
11528
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
2387 if (nwc != NULL) nwc->SetPIP(parts->u.pip.pre, parts->u.pip.inter, parts->u.pip.post);
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
2388
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
2389 NWidgetBackground *nwb = dynamic_cast<NWidgetBackground *>(*dest);
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
2390 if (nwb != NULL) nwb->SetPIP(parts->u.pip.pre, parts->u.pip.inter, parts->u.pip.post);
11511
bf92950ea00b (svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents: 11500
diff changeset
2391 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
2392 }
bf92950ea00b (svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents: 11500
diff changeset
2393
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2394 case WPT_ENDCONTAINER:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2395 return num_used;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2396
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2397 default:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2398 if (*dest != NULL) return num_used;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2399 assert((parts->type & WWT_MASK) < NWID_HORIZONTAL);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2400 *dest = new NWidgetLeaf(parts->type, parts->u.widget.colour, parts->u.widget.index, 0x0, STR_NULL);
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12373
diff changeset
2401 *biggest_index = max(*biggest_index, (int)parts->u.widget.index);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2402 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2403 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2404 num_used++;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2405 parts++;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2406 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2407
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2408 return num_used;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2409 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2410
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2411 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2412 * 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
2413 * @param parts Array with parts of the nested widgets.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2414 * @param count Length of the \a parts array.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2415 * @param parent Container to use for storing the child widgets.
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12373
diff changeset
2416 * @param biggest_index Pointer to biggest nested widget index in the tree.
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2417 * @return Number of widget part elements used to fill the container.
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12373
diff changeset
2418 * @postcond \c *biggest_index contains the largest widget index of the tree and \c -1 if no index is used.
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2419 */
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12373
diff changeset
2420 static int MakeWidgetTree(const NWidgetPart *parts, int count, NWidgetBase *parent, int *biggest_index)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2421 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2422 /* 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
2423 NWidgetContainer *nwid_cont = dynamic_cast<NWidgetContainer *>(parent);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2424 NWidgetBackground *nwid_parent = dynamic_cast<NWidgetBackground *>(parent);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2425 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
2426
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2427 int total_used = 0;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2428 while (true) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2429 NWidgetBase *sub_widget = NULL;
11750
924e26095f16 (svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
2430 bool fill_sub = false;
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12373
diff changeset
2431 int num_used = MakeNWidget(parts, count - total_used, &sub_widget, &fill_sub, biggest_index);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2432 parts += num_used;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2433 total_used += num_used;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2434
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2435 /* Break out of loop when end reached */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2436 if (sub_widget == NULL) break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2437
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2438 /* Add sub_widget to parent container. */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2439 if (nwid_cont) nwid_cont->Add(sub_widget);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2440 if (nwid_parent) nwid_parent->Add(sub_widget);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2441
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2442 /* 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
2443 WidgetType tp = sub_widget->type;
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
2444 if (fill_sub && (tp == NWID_HORIZONTAL || tp == NWID_HORIZONTAL_LTR || tp == NWID_VERTICAL
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
2445 || tp == WWT_PANEL || tp == WWT_FRAME || tp == WWT_INSET || tp == NWID_SELECTION || tp == NWID_LAYERED)) {
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12373
diff changeset
2446 int num_used = MakeWidgetTree(parts, count - total_used, sub_widget, biggest_index);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2447 parts += num_used;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2448 total_used += num_used;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2449 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2450 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2451
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2452 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
2453
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2454 assert(total_used < count);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2455 assert(parts->type == WPT_ENDCONTAINER);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2456 return total_used + 1; // *parts is also 'used'
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2457 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2458
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2459 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2460 * 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
2461 * @param parts Array with parts of the widgets.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2462 * @param count Length of the \a parts array.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2463 * @return Root of the nested widget tree, a vertical container containing the entire GUI.
11799
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
2464 * @ingroup NestedWidgetParts
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2465 */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2466 NWidgetContainer *MakeNWidgets(const NWidgetPart *parts, int count)
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2467 {
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12373
diff changeset
2468 int biggest_index = -1;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2469 NWidgetContainer *cont = new NWidgetVertical();
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12373
diff changeset
2470 MakeWidgetTree(parts, count, cont, &biggest_index);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2471 return cont;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2472 }
11836
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2473
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2474 /**
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2475 * Construct a #Widget array from a nested widget parts array, taking care of all the steps and checks.
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2476 * Also cache the result and use the cache if possible.
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2477 * @param[in] parts Array with parts of the widgets.
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2478 * @param parts_length Length of the \a parts array.
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2479 * @param[in] orig_wid Pointer to original widget array.
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2480 * @param wid_cache Pointer to the cache for storing the generated widget array (use \c NULL to prevent caching).
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2481 * @return Cached value if available, otherwise the generated widget array. If \a wid_cache is \c NULL, the caller should free the returned array.
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2482 *
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2483 * @pre Before the first call, \c *wid_cache should be \c NULL.
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2484 * @post The widget array stored in the \c *wid_cache should be free-ed by the caller.
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2485 */
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2486 const Widget *InitializeWidgetArrayFromNestedWidgets(const NWidgetPart *parts, int parts_length, const Widget *orig_wid, Widget **wid_cache)
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2487 {
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2488 const bool rtl = false; // Direction of the language is left-to-right
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2489
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2490 if (wid_cache != NULL && *wid_cache != NULL) return *wid_cache;
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2491
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2492 assert(parts != NULL && parts_length > 0);
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2493 NWidgetContainer *nwid = MakeNWidgets(parts, parts_length);
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2494 Widget *gen_wid = InitializeNWidgets(nwid, rtl);
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2495
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2496 if (!rtl && orig_wid) {
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2497 /* There are two descriptions, compare them.
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2498 * Comparing only makes sense when using a left-to-right language.
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2499 */
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2500 bool ok = CompareWidgetArrays(orig_wid, gen_wid, false);
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2501 if (ok) {
11961
69a41fde01e1 (svn r16367) -Codechange: Do not use min_x and min_y for storing smallest size to allow initialization more than once.
alberth <alberth@openttd.org>
parents: 11836
diff changeset
2502 DEBUG(misc, 1, "Nested widgets are equal, min-size(%u, %u)", nwid->smallest_x, nwid->smallest_y);
11836
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2503 } else {
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2504 DEBUG(misc, 0, "Nested widgets give different results");
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2505 CompareWidgetArrays(orig_wid, gen_wid, true);
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2506 }
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2507 }
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2508 delete nwid;
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2509
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2510 if (wid_cache != NULL) *wid_cache = gen_wid;
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2511 return gen_wid;
ef0eab75562b (svn r16226) -Codechange: Separating generation of a widget array from WindowDesc to the InitializeWidgetArrayFromNestedWidgets function.
alberth <alberth@openttd.org>
parents: 11811
diff changeset
2512 }