annotate src/widget.cpp @ 17232:5d82f4101601 draft

(svn r21972) -Fix: Replace 'None' industries in the generation window with more descriptive label.
author alberth <alberth@openttd.org>
date Sat, 05 Feb 2011 11:42:27 +0000
parents 7ac0e0454f5f
children 00953669945d
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
12778
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12710
diff changeset
3 /*
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12710
diff changeset
4 * This file is part of OpenTTD.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12710
diff changeset
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12710
diff changeset
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12710
diff changeset
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12710
diff changeset
8 */
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12710
diff changeset
9
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
10 /** @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
11
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
12 #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
13 #include "company_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
14 #include "window_gui.h"
12526
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
15 #include "viewport_func.h"
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
16 #include "zoom_func.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
17 #include "strings_func.h"
12897
323d905aa7b9 (svn r17389) -Codechange: Add support for shaded viewports.
alberth <alberth@openttd.org>
parents: 12896
diff changeset
18 #include "transparency.h"
14258
a899d4e5ee1a (svn r18809) -Codechange/Cleanup: remove unneeded headers from some files, if a header require a header make it include that header
rubidium <rubidium@openttd.org>
parents: 14063
diff changeset
19 #include "core/geometry_func.hpp"
15080
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
20 #include "settings_type.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
21
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
22 #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
23 #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
24
11799
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
25 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
26 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
27
9773
fcce76c3bb3d (svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents: 9770
diff changeset
28 /**
fcce76c3bb3d (svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents: 9770
diff changeset
29 * 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
30 * @param sb Scrollbar list data
fcce76c3bb3d (svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents: 9770
diff changeset
31 * @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
32 * @param bottom Bottom position of the scrollbar (bottom position of the down-button)
13626
0fcc5f6fa927 (svn r18150) -Codechange: make the horizontal scrollbar scroll in the opposite direction with RTL
rubidium <rubidium@openttd.org>
parents: 13614
diff changeset
33 * @param horizontal Whether the scrollbar is horizontal or not
9773
fcce76c3bb3d (svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents: 9770
diff changeset
34 * @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
35 * 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
36 */
13626
0fcc5f6fa927 (svn r18150) -Codechange: make the horizontal scrollbar scroll in the opposite direction with RTL
rubidium <rubidium@openttd.org>
parents: 13614
diff changeset
37 static Point HandleScrollbarHittest(const Scrollbar *sb, int top, int bottom, bool horizontal)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
38 {
13626
0fcc5f6fa927 (svn r18150) -Codechange: make the horizontal scrollbar scroll in the opposite direction with RTL
rubidium <rubidium@openttd.org>
parents: 13614
diff changeset
39 /* Base for reversion */
0fcc5f6fa927 (svn r18150) -Codechange: make the horizontal scrollbar scroll in the opposite direction with RTL
rubidium <rubidium@openttd.org>
parents: 13614
diff changeset
40 int rev_base = top + bottom;
9773
fcce76c3bb3d (svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents: 9770
diff changeset
41 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
42 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
43
13626
0fcc5f6fa927 (svn r18150) -Codechange: make the horizontal scrollbar scroll in the opposite direction with RTL
rubidium <rubidium@openttd.org>
parents: 13614
diff changeset
44 int height = (bottom - top);
0fcc5f6fa927 (svn r18150) -Codechange: make the horizontal scrollbar scroll in the opposite direction with RTL
rubidium <rubidium@openttd.org>
parents: 13614
diff changeset
45 int pos = sb->GetPosition();
0fcc5f6fa927 (svn r18150) -Codechange: make the horizontal scrollbar scroll in the opposite direction with RTL
rubidium <rubidium@openttd.org>
parents: 13614
diff changeset
46 int count = sb->GetCount();
0fcc5f6fa927 (svn r18150) -Codechange: make the horizontal scrollbar scroll in the opposite direction with RTL
rubidium <rubidium@openttd.org>
parents: 13614
diff changeset
47 int cap = sb->GetCapacity();
5584
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 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
50
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
51 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
52 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
53
13626
0fcc5f6fa927 (svn r18150) -Codechange: make the horizontal scrollbar scroll in the opposite direction with RTL
rubidium <rubidium@openttd.org>
parents: 13614
diff changeset
54 Point pt;
16441
86fd9bcc9d2f (svn r21157) -Codechange: remove information about the text direction out of the language "list"
rubidium <rubidium@openttd.org>
parents: 16309
diff changeset
55 if (horizontal && _current_text_dir == TD_RTL) {
13626
0fcc5f6fa927 (svn r18150) -Codechange: make the horizontal scrollbar scroll in the opposite direction with RTL
rubidium <rubidium@openttd.org>
parents: 13614
diff changeset
56 pt.x = rev_base - (bottom - 1);
0fcc5f6fa927 (svn r18150) -Codechange: make the horizontal scrollbar scroll in the opposite direction with RTL
rubidium <rubidium@openttd.org>
parents: 13614
diff changeset
57 pt.y = rev_base - top;
0fcc5f6fa927 (svn r18150) -Codechange: make the horizontal scrollbar scroll in the opposite direction with RTL
rubidium <rubidium@openttd.org>
parents: 13614
diff changeset
58 } else {
0fcc5f6fa927 (svn r18150) -Codechange: make the horizontal scrollbar scroll in the opposite direction with RTL
rubidium <rubidium@openttd.org>
parents: 13614
diff changeset
59 pt.x = top;
0fcc5f6fa927 (svn r18150) -Codechange: make the horizontal scrollbar scroll in the opposite direction with RTL
rubidium <rubidium@openttd.org>
parents: 13614
diff changeset
60 pt.y = bottom - 1;
0fcc5f6fa927 (svn r18150) -Codechange: make the horizontal scrollbar scroll in the opposite direction with RTL
rubidium <rubidium@openttd.org>
parents: 13614
diff changeset
61 }
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 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
63 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
64
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
65 /**
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
66 * 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
67 * @param w Window on which a scroll was performed.
15786
04cd1d957b49 (svn r20460) -Codechange: Remove WF_SCROLL window flags and store the state directly in the scrollbar widget instead.
frosch <frosch@openttd.org>
parents: 15785
diff changeset
68 * @param sb Scrollbar
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
69 * @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
70 * @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
71 * @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
72 * @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
73 */
15786
04cd1d957b49 (svn r20460) -Codechange: Remove WF_SCROLL window flags and store the state directly in the scrollbar widget instead.
frosch <frosch@openttd.org>
parents: 15785
diff changeset
74 static void ScrollbarClickPositioning(Window *w, NWidgetScrollbar *sb, 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
75 {
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
76 int pos;
13626
0fcc5f6fa927 (svn r18150) -Codechange: make the horizontal scrollbar scroll in the opposite direction with RTL
rubidium <rubidium@openttd.org>
parents: 13614
diff changeset
77 bool rtl = false;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
78
15787
6c4bec3b8401 (svn r20461) -Codechange: Replace WWT_HSCROLLBAR, WWT_SCROLLBAR and WWT_SCROLL2BAR with NWID_HSCROLLBAR and NWID_VSCROLLBAR.
frosch <frosch@openttd.org>
parents: 15786
diff changeset
79 if (sb->type == NWID_HSCROLLBAR) {
15786
04cd1d957b49 (svn r20460) -Codechange: Remove WF_SCROLL window flags and store the state directly in the scrollbar widget instead.
frosch <frosch@openttd.org>
parents: 15785
diff changeset
80 pos = x;
16441
86fd9bcc9d2f (svn r21157) -Codechange: remove information about the text direction out of the language "list"
rubidium <rubidium@openttd.org>
parents: 16309
diff changeset
81 rtl = _current_text_dir == TD_RTL;
15786
04cd1d957b49 (svn r20460) -Codechange: Remove WF_SCROLL window flags and store the state directly in the scrollbar widget instead.
frosch <frosch@openttd.org>
parents: 15785
diff changeset
82 } else {
04cd1d957b49 (svn r20460) -Codechange: Remove WF_SCROLL window flags and store the state directly in the scrollbar widget instead.
frosch <frosch@openttd.org>
parents: 15785
diff changeset
83 pos = y;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
84 }
8969
01cc3ee6ecb1 (svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium <rubidium@openttd.org>
parents: 8857
diff changeset
85 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
86 /* Pressing the upper button? */
15786
04cd1d957b49 (svn r20460) -Codechange: Remove WF_SCROLL window flags and store the state directly in the scrollbar widget instead.
frosch <frosch@openttd.org>
parents: 15785
diff changeset
87 SetBit(sb->disp_flags, NDB_SCROLLBAR_UP);
15894
9a746a18b3d5 (svn r20577) -Fix [FS#4043]: scroll button flickering when pressed
rubidium <rubidium@openttd.org>
parents: 15876
diff changeset
88 if (_scroller_click_timeout <= 1) {
9a746a18b3d5 (svn r20577) -Fix [FS#4043]: scroll button flickering when pressed
rubidium <rubidium@openttd.org>
parents: 15876
diff changeset
89 _scroller_click_timeout = 3;
13626
0fcc5f6fa927 (svn r18150) -Codechange: make the horizontal scrollbar scroll in the opposite direction with RTL
rubidium <rubidium@openttd.org>
parents: 13614
diff changeset
90 sb->UpdatePosition(rtl ? 1 : -1);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
91 }
16221
4f317dcb219a (svn r20922) -Fix [FS#4071]: accidentally moving the mouse of the scrollbar arrows while pressing it clicks the button next to the arrow
rubidium <rubidium@openttd.org>
parents: 15903
diff changeset
92 w->scrolling_scrollbar = sb->index;
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
93 } 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
94 /* Pressing the lower button? */
15786
04cd1d957b49 (svn r20460) -Codechange: Remove WF_SCROLL window flags and store the state directly in the scrollbar widget instead.
frosch <frosch@openttd.org>
parents: 15785
diff changeset
95 SetBit(sb->disp_flags, NDB_SCROLLBAR_DOWN);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
96
15894
9a746a18b3d5 (svn r20577) -Fix [FS#4043]: scroll button flickering when pressed
rubidium <rubidium@openttd.org>
parents: 15876
diff changeset
97 if (_scroller_click_timeout <= 1) {
9a746a18b3d5 (svn r20577) -Fix [FS#4043]: scroll button flickering when pressed
rubidium <rubidium@openttd.org>
parents: 15876
diff changeset
98 _scroller_click_timeout = 3;
13626
0fcc5f6fa927 (svn r18150) -Codechange: make the horizontal scrollbar scroll in the opposite direction with RTL
rubidium <rubidium@openttd.org>
parents: 13614
diff changeset
99 sb->UpdatePosition(rtl ? -1 : 1);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
100 }
16221
4f317dcb219a (svn r20922) -Fix [FS#4071]: accidentally moving the mouse of the scrollbar arrows while pressing it clicks the button next to the arrow
rubidium <rubidium@openttd.org>
parents: 15903
diff changeset
101 w->scrolling_scrollbar = sb->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
102 } else {
15787
6c4bec3b8401 (svn r20461) -Codechange: Replace WWT_HSCROLLBAR, WWT_SCROLLBAR and WWT_SCROLL2BAR with NWID_HSCROLLBAR and NWID_VSCROLLBAR.
frosch <frosch@openttd.org>
parents: 15786
diff changeset
103 Point pt = HandleScrollbarHittest(sb, mi, ma, sb->type == NWID_HSCROLLBAR);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
104
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
105 if (pos < pt.x) {
17026
0b2b2fbffd00 (svn r21763) -Codechange: Pass the distance to Scrollbar::UpdatePosition() in units of small or big steps.
frosch <frosch@openttd.org>
parents: 17017
diff changeset
106 sb->UpdatePosition(rtl ? 1 : -1, Scrollbar::SS_BIG);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
107 } else if (pos > pt.y) {
17026
0b2b2fbffd00 (svn r21763) -Codechange: Pass the distance to Scrollbar::UpdatePosition() in units of small or big steps.
frosch <frosch@openttd.org>
parents: 17017
diff changeset
108 sb->UpdatePosition(rtl ? -1 : 1, Scrollbar::SS_BIG);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
109 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
110 _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
111 _scrollbar_size = ma - mi - 23;
15786
04cd1d957b49 (svn r20460) -Codechange: Remove WF_SCROLL window flags and store the state directly in the scrollbar widget instead.
frosch <frosch@openttd.org>
parents: 15785
diff changeset
112 w->scrolling_scrollbar = sb->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
113 _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
114 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
115 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
116
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
117 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
118 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
119
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15579
diff changeset
120 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15579
diff changeset
121 * Special handling for the scrollbar widget type.
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
122 * 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
123 * @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
124 * @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
125 * @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
126 * @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
127 */
15783
237bdaf1dc20 (svn r20457) -Codechange: Remove _scrolling_scrollbar and WF_SCROLL_MIDDLE and instead store the widget index of the being scrolled scrollbar in the Window.
frosch <frosch@openttd.org>
parents: 15782
diff changeset
128 void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int 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
129 {
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 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
131
15787
6c4bec3b8401 (svn r20461) -Codechange: Replace WWT_HSCROLLBAR, WWT_SCROLLBAR and WWT_SCROLL2BAR with NWID_HSCROLLBAR and NWID_VSCROLLBAR.
frosch <frosch@openttd.org>
parents: 15786
diff changeset
132 if (nw->type == NWID_HSCROLLBAR) {
6c4bec3b8401 (svn r20461) -Codechange: Replace WWT_HSCROLLBAR, WWT_SCROLLBAR and WWT_SCROLL2BAR with NWID_HSCROLLBAR and NWID_VSCROLLBAR.
frosch <frosch@openttd.org>
parents: 15786
diff changeset
133 mi = nw->pos_x;
6c4bec3b8401 (svn r20461) -Codechange: Replace WWT_HSCROLLBAR, WWT_SCROLLBAR and WWT_SCROLL2BAR with NWID_HSCROLLBAR and NWID_VSCROLLBAR.
frosch <frosch@openttd.org>
parents: 15786
diff changeset
134 ma = nw->pos_x + nw->current_x;
6c4bec3b8401 (svn r20461) -Codechange: Replace WWT_HSCROLLBAR, WWT_SCROLLBAR and WWT_SCROLL2BAR with NWID_HSCROLLBAR and NWID_VSCROLLBAR.
frosch <frosch@openttd.org>
parents: 15786
diff changeset
135 } else {
6c4bec3b8401 (svn r20461) -Codechange: Replace WWT_HSCROLLBAR, WWT_SCROLLBAR and WWT_SCROLL2BAR with NWID_HSCROLLBAR and NWID_VSCROLLBAR.
frosch <frosch@openttd.org>
parents: 15786
diff changeset
136 mi = nw->pos_y;
6c4bec3b8401 (svn r20461) -Codechange: Replace WWT_HSCROLLBAR, WWT_SCROLLBAR and WWT_SCROLL2BAR with NWID_HSCROLLBAR and NWID_VSCROLLBAR.
frosch <frosch@openttd.org>
parents: 15786
diff changeset
137 ma = nw->pos_y + nw->current_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
138 }
15783
237bdaf1dc20 (svn r20457) -Codechange: Remove _scrolling_scrollbar and WF_SCROLL_MIDDLE and instead store the widget index of the being scrolled scrollbar in the Window.
frosch <frosch@openttd.org>
parents: 15782
diff changeset
139 ScrollbarClickPositioning(w, dynamic_cast<NWidgetScrollbar*>(nw), x, y, mi, ma);
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
140 }
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
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15579
diff changeset
142 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15579
diff changeset
143 * Returns the index for the widget located at the given position
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
144 * 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
145 * @param *w Window to look inside
6481
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6432
diff changeset
146 * @param x The Window client X coordinate
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6432
diff changeset
147 * @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
148 * @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
149 */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
150 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
151 {
13570
4a7574282ac8 (svn r18092) -Codechange: remove support for the unnested widgets
rubidium <rubidium@openttd.org>
parents: 13567
diff changeset
152 NWidgetCore *nw = w->nested_root->GetWidgetFromPos(x, y);
4a7574282ac8 (svn r18092) -Codechange: remove support for the unnested widgets
rubidium <rubidium@openttd.org>
parents: 13567
diff changeset
153 return (nw != NULL) ? nw->index : -1;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
154 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
155
9773
fcce76c3bb3d (svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents: 9770
diff changeset
156 /**
fcce76c3bb3d (svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents: 9770
diff changeset
157 * Draw frame rectangle.
fcce76c3bb3d (svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium <rubidium@openttd.org>
parents: 9770
diff changeset
158 * @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
159 * @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
160 * @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
161 * @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
162 * @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
163 * @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
164 */
11085
8da1855e9f14 (svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents: 11084
diff changeset
165 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
166 {
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
167 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
168 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
169 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
170 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
171
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
172 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
173 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
174 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
175 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
176
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
177 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
178 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
179 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
180 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
181 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
182 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
183 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
184 GfxFillRect(left, top, left, bottom - 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
185 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
186 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
187 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
188 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
189 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
190 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
191 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
192 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
193 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
194 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
195
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
196 /**
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
197 * 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
198 * @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
199 * @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
200 * @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
201 * @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
202 * @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
203 */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
204 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
205 {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
206 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
207 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
208
13514
b70924cfd627 (svn r18033) -Codechange: make the padding for IMGBTN_2 the same as for IMGBTN; the image doesn't move, so the extra space at the right and bottom aren't needed
rubidium <rubidium@openttd.org>
parents: 13509
diff changeset
209 if ((type & WWT_MASK) == WWT_IMGBTN_2 && clicked) img++; // Show different image when clicked for #WWT_IMGBTN_2.
b70924cfd627 (svn r18033) -Codechange: make the padding for IMGBTN_2 the same as for IMGBTN; the image doesn't move, so the extra space at the right and bottom aren't needed
rubidium <rubidium@openttd.org>
parents: 13509
diff changeset
210 DrawSprite(img, PAL_NONE, r.left + WD_IMGBTN_LEFT + clicked, r.top + WD_IMGBTN_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
211 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
212
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
213 /**
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
214 * 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
215 * @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
216 * @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
217 * @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
218 * @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
219 */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
220 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
221 {
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
222 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
223 if ((type & WWT_MASK) == WWT_TEXTBTN_2 && clicked) str++;
12710
b9e16dc0471d (svn r17173) -Codechange: Vertically align WWT_TEXT widget, generalize vertical alignment of label and text buttons.
alberth <alberth@openttd.org>
parents: 12708
diff changeset
224 Dimension d = GetStringBoundingBox(str);
b9e16dc0471d (svn r17173) -Codechange: Vertically align WWT_TEXT widget, generalize vertical alignment of label and text buttons.
alberth <alberth@openttd.org>
parents: 12708
diff changeset
225 int offset = max(0, ((int)(r.bottom - r.top + 1) - (int)d.height) / 2); // Offset for rendering the text vertically centered
15400
821c26b30fd9 (svn r20043) -Codechange: Introduce vertical alignment for DrawStringMultiLine().
alberth <alberth@openttd.org>
parents: 15302
diff changeset
226 DrawString(r.left + clicked, r.right + clicked, r.top + offset + clicked, str, TC_FROMSTRING, SA_HOR_CENTER);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
227 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
228
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
229 /**
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
230 * Draw text.
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
231 * @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
232 * @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
233 * @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
234 */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
235 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
236 {
12710
b9e16dc0471d (svn r17173) -Codechange: Vertically align WWT_TEXT widget, generalize vertical alignment of label and text buttons.
alberth <alberth@openttd.org>
parents: 12708
diff changeset
237 Dimension d = GetStringBoundingBox(str);
b9e16dc0471d (svn r17173) -Codechange: Vertically align WWT_TEXT widget, generalize vertical alignment of label and text buttons.
alberth <alberth@openttd.org>
parents: 12708
diff changeset
238 int offset = max(0, ((int)(r.bottom - r.top + 1) - (int)d.height) / 2); // Offset for rendering the text vertically centered
b9e16dc0471d (svn r17173) -Codechange: Vertically align WWT_TEXT widget, generalize vertical alignment of label and text buttons.
alberth <alberth@openttd.org>
parents: 12708
diff changeset
239 if (str != STR_NULL) DrawString(r.left, r.right, r.top + offset, str, colour);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
240 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
241
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
242 /**
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
243 * 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
244 * @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
245 * @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
246 * @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
247 */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
248 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
249 {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
250 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
251 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
252 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
253
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
254 /**
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
255 * 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
256 * @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
257 * @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
258 * @param clicked Matrix is rendered lowered.
12409
7243e41fdc5e (svn r16843) -Codechange: More documentation for the WWT_MATRIX widget, and better variable names in matrix rendering function.
alberth <alberth@openttd.org>
parents: 12408
diff changeset
259 * @param data Data of the widget, number of rows and columns of the widget.
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
260 */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
261 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
262 {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
263 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
264
12411
9fdbb4594b82 (svn r16845) -Codechange: Introduction of constants for describing the bits in a WWT_MATRIX data field.
alberth <alberth@openttd.org>
parents: 12409
diff changeset
265 int num_columns = GB(data, MAT_COL_START, MAT_COL_BITS); // Lower 8 bits of the widget data: Number of columns in the matrix.
12409
7243e41fdc5e (svn r16843) -Codechange: More documentation for the WWT_MATRIX widget, and better variable names in matrix rendering function.
alberth <alberth@openttd.org>
parents: 12408
diff changeset
266 int column_width = (r.right - r.left + 1) / num_columns; // Width of a single column in the matrix.
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
267
12411
9fdbb4594b82 (svn r16845) -Codechange: Introduction of constants for describing the bits in a WWT_MATRIX data field.
alberth <alberth@openttd.org>
parents: 12409
diff changeset
268 int num_rows = GB(data, MAT_ROW_START, MAT_ROW_BITS); // Upper 8 bits of the widget data: Number of rows in the matrix.
12409
7243e41fdc5e (svn r16843) -Codechange: More documentation for the WWT_MATRIX widget, and better variable names in matrix rendering function.
alberth <alberth@openttd.org>
parents: 12408
diff changeset
269 int row_height = (r.bottom - r.top + 1) / num_rows; // Height of a single row in the matrix.
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
270
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
271 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
272
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
273 int x = r.left;
12409
7243e41fdc5e (svn r16843) -Codechange: More documentation for the WWT_MATRIX widget, and better variable names in matrix rendering function.
alberth <alberth@openttd.org>
parents: 12408
diff changeset
274 for (int ctr = num_columns; ctr > 1; ctr--) {
7243e41fdc5e (svn r16843) -Codechange: More documentation for the WWT_MATRIX widget, and better variable names in matrix rendering function.
alberth <alberth@openttd.org>
parents: 12408
diff changeset
275 x += column_width;
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
276 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
277 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
278
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
279 x = r.top;
12409
7243e41fdc5e (svn r16843) -Codechange: More documentation for the WWT_MATRIX widget, and better variable names in matrix rendering function.
alberth <alberth@openttd.org>
parents: 12408
diff changeset
280 for (int ctr = num_rows; ctr > 1; ctr--) {
7243e41fdc5e (svn r16843) -Codechange: More documentation for the WWT_MATRIX widget, and better variable names in matrix rendering function.
alberth <alberth@openttd.org>
parents: 12408
diff changeset
281 x += row_height;
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
282 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
283 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
284
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
285 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
286
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
287 x = r.left - 1;
12409
7243e41fdc5e (svn r16843) -Codechange: More documentation for the WWT_MATRIX widget, and better variable names in matrix rendering function.
alberth <alberth@openttd.org>
parents: 12408
diff changeset
288 for (int ctr = num_columns; ctr > 1; ctr--) {
7243e41fdc5e (svn r16843) -Codechange: More documentation for the WWT_MATRIX widget, and better variable names in matrix rendering function.
alberth <alberth@openttd.org>
parents: 12408
diff changeset
289 x += column_width;
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
290 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
291 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
292
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
293 x = r.top - 1;
12409
7243e41fdc5e (svn r16843) -Codechange: More documentation for the WWT_MATRIX widget, and better variable names in matrix rendering function.
alberth <alberth@openttd.org>
parents: 12408
diff changeset
294 for (int ctr = num_rows; ctr > 1; ctr--) {
7243e41fdc5e (svn r16843) -Codechange: More documentation for the WWT_MATRIX widget, and better variable names in matrix rendering function.
alberth <alberth@openttd.org>
parents: 12408
diff changeset
295 x += row_height;
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
296 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
297 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
298 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
299
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
300 /**
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
301 * 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
302 * @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
303 * @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
304 * @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
305 * @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
306 * @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
307 * @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
308 */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
309 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
310 {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
311 /* 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
312 DrawFrameRect(r.left, r.top, r.right, r.top + 9, colour, (up_clicked) ? FR_LOWERED : FR_NONE);
15400
821c26b30fd9 (svn r20043) -Codechange: Introduce vertical alignment for DrawStringMultiLine().
alberth <alberth@openttd.org>
parents: 15302
diff changeset
313 DrawString(r.left + up_clicked, r.right + up_clicked, r.top + up_clicked, UPARROW, TC_BLACK, SA_HOR_CENTER);
11999
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 DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, colour, (down_clicked) ? FR_LOWERED : FR_NONE);
15400
821c26b30fd9 (svn r20043) -Codechange: Introduce vertical alignment for DrawStringMultiLine().
alberth <alberth@openttd.org>
parents: 15302
diff changeset
316 DrawString(r.left + down_clicked, r.right + down_clicked, r.bottom - 9 + down_clicked, DOWNARROW, TC_BLACK, SA_HOR_CENTER);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
317
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
318 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
319 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
320
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
321 /* 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
322 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
323 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
324
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
325 /* draw shaded lines */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
326 GfxFillRect(r.left + 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
327 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
328 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
329 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
330
13626
0fcc5f6fa927 (svn r18150) -Codechange: make the horizontal scrollbar scroll in the opposite direction with RTL
rubidium <rubidium@openttd.org>
parents: 13614
diff changeset
331 Point pt = HandleScrollbarHittest(scrollbar, r.top, r.bottom, false);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
332 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
333 }
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 /**
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
336 * 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
337 * @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
338 * @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
339 * @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
340 * @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
341 * @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
342 * @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
343 */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
344 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
345 {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
346 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
347 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
348
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
349 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
350 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
351
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
352 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
353 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
354
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
355 /* 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
356 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
357 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
358
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
359 /* 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
360 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
361 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
362 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
363 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
364
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
365 /* draw actual scrollbar */
13626
0fcc5f6fa927 (svn r18150) -Codechange: make the horizontal scrollbar scroll in the opposite direction with RTL
rubidium <rubidium@openttd.org>
parents: 13614
diff changeset
366 Point pt = HandleScrollbarHittest(scrollbar, r.left, r.right, true);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
367 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
368 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
369
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
370 /**
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
371 * Draw 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
372 * @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
373 * @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
374 * @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
375 */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
376 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
377 {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
378 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
379
12195
ee5c5c8f0557 (svn r16609) -Codechange: Introduction of widget sizes and offsets used while drawing.
alberth <alberth@openttd.org>
parents: 12159
diff changeset
380 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
381
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
382 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
383 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
384
13644
05b6dd4a2a90 (svn r18168) -Codechange: Adjust a frame's child's padding to account for text height, and draw the top bar appropriately.
peter1138 <peter1138@openttd.org>
parents: 13626
diff changeset
385 /* If the frame has text, adjust the top bar to fit half-way through */
05b6dd4a2a90 (svn r18168) -Codechange: Adjust a frame's child's padding to account for text height, and draw the top bar appropriately.
peter1138 <peter1138@openttd.org>
parents: 13626
diff changeset
386 int dy1 = 4;
05b6dd4a2a90 (svn r18168) -Codechange: Adjust a frame's child's padding to account for text height, and draw the top bar appropriately.
peter1138 <peter1138@openttd.org>
parents: 13626
diff changeset
387 if (str != STR_NULL) dy1 = FONT_HEIGHT_NORMAL / 2 - 1;
05b6dd4a2a90 (svn r18168) -Codechange: Adjust a frame's child's padding to account for text height, and draw the top bar appropriately.
peter1138 <peter1138@openttd.org>
parents: 13626
diff changeset
388 int dy2 = dy1 + 1;
05b6dd4a2a90 (svn r18168) -Codechange: Adjust a frame's child's padding to account for text height, and draw the top bar appropriately.
peter1138 <peter1138@openttd.org>
parents: 13626
diff changeset
389
16441
86fd9bcc9d2f (svn r21157) -Codechange: remove information about the text direction out of the language "list"
rubidium <rubidium@openttd.org>
parents: 16309
diff changeset
390 if (_current_text_dir == TD_LTR) {
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
391 /* Line from upper left corner to start of text */
13644
05b6dd4a2a90 (svn r18168) -Codechange: Adjust a frame's child's padding to account for text height, and draw the top bar appropriately.
peter1138 <peter1138@openttd.org>
parents: 13626
diff changeset
392 GfxFillRect(r.left, r.top + dy1, r.left + 4, r.top + dy1, c1);
05b6dd4a2a90 (svn r18168) -Codechange: Adjust a frame's child's padding to account for text height, and draw the top bar appropriately.
peter1138 <peter1138@openttd.org>
parents: 13626
diff changeset
393 GfxFillRect(r.left + 1, r.top + dy2, r.left + 4, r.top + dy2, c2);
11999
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 /* Line from end of text to upper right corner */
13644
05b6dd4a2a90 (svn r18168) -Codechange: Adjust a frame's child's padding to account for text height, and draw the top bar appropriately.
peter1138 <peter1138@openttd.org>
parents: 13626
diff changeset
396 GfxFillRect(x2, r.top + dy1, r.right - 1, r.top + dy1, c1);
05b6dd4a2a90 (svn r18168) -Codechange: Adjust a frame's child's padding to account for text height, and draw the top bar appropriately.
peter1138 <peter1138@openttd.org>
parents: 13626
diff changeset
397 GfxFillRect(x2, r.top + dy2, r.right - 2, r.top + dy2, c2);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
398 } else {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
399 /* Line from upper left corner to start of text */
13644
05b6dd4a2a90 (svn r18168) -Codechange: Adjust a frame's child's padding to account for text height, and draw the top bar appropriately.
peter1138 <peter1138@openttd.org>
parents: 13626
diff changeset
400 GfxFillRect(r.left, r.top + dy1, x2 - 2, r.top + dy1, c1);
05b6dd4a2a90 (svn r18168) -Codechange: Adjust a frame's child's padding to account for text height, and draw the top bar appropriately.
peter1138 <peter1138@openttd.org>
parents: 13626
diff changeset
401 GfxFillRect(r.left + 1, r.top + dy2, x2 - 2, r.top + dy2, c2);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
402
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
403 /* Line from end of text to upper right corner */
13644
05b6dd4a2a90 (svn r18168) -Codechange: Adjust a frame's child's padding to account for text height, and draw the top bar appropriately.
peter1138 <peter1138@openttd.org>
parents: 13626
diff changeset
404 GfxFillRect(r.right - 5, r.top + dy1, r.right - 1, r.top + dy1, c1);
05b6dd4a2a90 (svn r18168) -Codechange: Adjust a frame's child's padding to account for text height, and draw the top bar appropriately.
peter1138 <peter1138@openttd.org>
parents: 13626
diff changeset
405 GfxFillRect(r.right - 5, r.top + dy2, r.right - 2, r.top + dy2, c2);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
406 }
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 /* Line from upper left corner to bottom left corner */
13644
05b6dd4a2a90 (svn r18168) -Codechange: Adjust a frame's child's padding to account for text height, and draw the top bar appropriately.
peter1138 <peter1138@openttd.org>
parents: 13626
diff changeset
409 GfxFillRect(r.left, r.top + dy2, r.left, r.bottom - 1, c1);
05b6dd4a2a90 (svn r18168) -Codechange: Adjust a frame's child's padding to account for text height, and draw the top bar appropriately.
peter1138 <peter1138@openttd.org>
parents: 13626
diff changeset
410 GfxFillRect(r.left + 1, r.top + dy2 + 1, r.left + 1, r.bottom - 2, c2);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
411
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
412 /* Line from upper right corner to bottom right corner */
13644
05b6dd4a2a90 (svn r18168) -Codechange: Adjust a frame's child's padding to account for text height, and draw the top bar appropriately.
peter1138 <peter1138@openttd.org>
parents: 13626
diff changeset
413 GfxFillRect(r.right - 1, r.top + dy2, r.right - 1, r.bottom - 2, c1);
05b6dd4a2a90 (svn r18168) -Codechange: Adjust a frame's child's padding to account for text height, and draw the top bar appropriately.
peter1138 <peter1138@openttd.org>
parents: 13626
diff changeset
414 GfxFillRect(r.right, r.top + dy1, r.right, r.bottom - 1, c2);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
415
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
416 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
417 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
418 }
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 /**
14040
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
421 * Draw a shade box.
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
422 * @param r Rectangle of the box.
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
423 * @param colour Colour of the shade box.
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
424 * @param clicked Box is lowered.
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
425 */
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
426 static inline void DrawShadeBox(const Rect &r, Colours colour, bool clicked)
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
427 {
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
428 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
429 DrawSprite((clicked) ? SPR_WINDOW_SHADE : SPR_WINDOW_UNSHADE, PAL_NONE, r.left + WD_SHADEBOX_LEFT + clicked, r.top + WD_SHADEBOX_TOP + clicked);
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
430 }
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
431
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
432 /**
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
433 * 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
434 * @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
435 * @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
436 * @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
437 */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
438 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
439 {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
440 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
441 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
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 /**
15080
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
445 * Draw a NewGRF debug box.
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
446 * @param r Rectangle of the box.
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
447 * @param colour Colour of the debug box.
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
448 * @param clicked Box is lowered.
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
449 */
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
450 static inline void DrawDebugBox(const Rect &r, Colours colour, bool clicked)
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
451 {
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
452 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
453 DrawSprite(SPR_WINDOW_DEBUG, PAL_NONE, r.left + WD_DEBUGBOX_LEFT + clicked, r.top + WD_DEBUGBOX_TOP + clicked);
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
454 }
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
455
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
456 /**
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
457 * 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
458 * @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
459 * @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
460 * @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
461 * @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
462 */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
463 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
464 {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
465 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
466 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
467 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
468 } 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
469 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
470 }
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
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
473 /**
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
474 * 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
475 * @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
476 * @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
477 * @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
478 */
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
479 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
480 {
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
481 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
482 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_NONE);
15400
821c26b30fd9 (svn r20043) -Codechange: Introduce vertical alignment for DrawStringMultiLine().
alberth <alberth@openttd.org>
parents: 15302
diff changeset
483 DrawString(r.left + WD_CLOSEBOX_LEFT, r.right - WD_CLOSEBOX_RIGHT, r.top + WD_CLOSEBOX_TOP, str, TC_FROMSTRING, SA_HOR_CENTER);
11999
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
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
486 /**
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
487 * 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
488 * @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
489 * @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
490 * @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
491 * @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
492 */
15302
a17347e65c55 (svn r19943) -Fix [FS#3865]: Disallow moving of vehicle news window.
frosch <frosch@openttd.org>
parents: 15215
diff changeset
493 void DrawCaption(const Rect &r, Colours colour, Owner owner, StringID str)
11999
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 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
496 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
497
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
498 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
499 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
500 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
501
15400
821c26b30fd9 (svn r20043) -Codechange: Introduce vertical alignment for DrawStringMultiLine().
alberth <alberth@openttd.org>
parents: 15302
diff changeset
502 if (str != STR_NULL) DrawString(r.left + WD_CAPTIONTEXT_LEFT, r.right - WD_CAPTIONTEXT_RIGHT, r.top + WD_CAPTIONTEXT_TOP, str, TC_FROMSTRING, SA_HOR_CENTER);
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
503 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
504
13075
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
505 /**
13664
ce197674184d (svn r18188) -Codechange: s/NWID_BUTTON_DRPDOWN/NWID_BUTTON_DROPDOWN/g
rubidium <rubidium@openttd.org>
parents: 13662
diff changeset
506 * Draw a button with a dropdown (#WWT_DROPDOWN and #NWID_BUTTON_DROPDOWN).
13075
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
507 * @param r Rectangle containing the widget.
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
508 * @param colour Background colour of the widget.
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
509 * @param clicked_button The button-part is lowered.
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
510 * @param clicked_dropdown The drop-down part is lowered.
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
511 * @param str Text of the button.
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
512 *
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
513 * @note Magic constants are also used in #NWidgetLeaf::ButtonHit.
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
514 */
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
515 static inline void DrawButtonDropdown(const Rect &r, Colours colour, bool clicked_button, bool clicked_dropdown, StringID str)
11999
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
516 {
16441
86fd9bcc9d2f (svn r21157) -Codechange: remove information about the text direction out of the language "list"
rubidium <rubidium@openttd.org>
parents: 16309
diff changeset
517 if (_current_text_dir == TD_LTR) {
13075
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
518 DrawFrameRect(r.left, r.top, r.right - 12, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE);
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
519 DrawFrameRect(r.right - 11, r.top, r.right, r.bottom, colour, clicked_dropdown ? FR_LOWERED : FR_NONE);
15400
821c26b30fd9 (svn r20043) -Codechange: Introduce vertical alignment for DrawStringMultiLine().
alberth <alberth@openttd.org>
parents: 15302
diff changeset
520 DrawString(r.right - (clicked_dropdown ? 10 : 11), r.right, r.top + (clicked_dropdown ? 2 : 1), DOWNARROW, TC_BLACK, SA_HOR_CENTER);
13075
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
521 if (str != STR_NULL) DrawString(r.left + WD_DROPDOWNTEXT_LEFT + clicked_button, r.right - WD_DROPDOWNTEXT_RIGHT + clicked_button, r.top + WD_DROPDOWNTEXT_TOP + clicked_button, 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
522 } else {
13075
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
523 DrawFrameRect(r.left + 12, r.top, r.right, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE);
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
524 DrawFrameRect(r.left, r.top, r.left + 11, r.bottom, colour, clicked_dropdown ? FR_LOWERED : FR_NONE);
15400
821c26b30fd9 (svn r20043) -Codechange: Introduce vertical alignment for DrawStringMultiLine().
alberth <alberth@openttd.org>
parents: 15302
diff changeset
525 DrawString(r.left + clicked_dropdown, r.left + 11, r.top + (clicked_dropdown ? 2 : 1), DOWNARROW, TC_BLACK, SA_HOR_CENTER);
13075
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
526 if (str != STR_NULL) DrawString(r.left + WD_DROPDOWNTEXT_RIGHT + clicked_button, r.right - WD_DROPDOWNTEXT_LEFT + clicked_button, r.top + WD_DROPDOWNTEXT_TOP + clicked_button, 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
527 }
b8e87660b9fc (svn r16405) -Codechange: Move widget drawing code to functions to allow re-use.
alberth <alberth@openttd.org>
parents: 11966
diff changeset
528 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
529
8857
a75a0c683fea (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8737
diff changeset
530 /**
13075
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
531 * Draw a dropdown #WWT_DROPDOWN widget.
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
532 * @param r Rectangle containing the widget.
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
533 * @param colour Background colour of the widget.
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
534 * @param clicked The widget is lowered.
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
535 * @param str Text of the button.
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
536 */
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
537 static inline void DrawDropdown(const Rect &r, Colours colour, bool clicked, StringID str)
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
538 {
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
539 DrawButtonDropdown(r, colour, false, clicked, str);
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
540 }
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
541
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
542 /**
8857
a75a0c683fea (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium <rubidium@openttd.org>
parents: 8737
diff changeset
543 * 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
544 */
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
545 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
546 {
13570
4a7574282ac8 (svn r18092) -Codechange: remove support for the unnested widgets
rubidium <rubidium@openttd.org>
parents: 13567
diff changeset
547 this->nested_root->Draw(this);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
548
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
549 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
550 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
551 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
552 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
553
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
554 /**
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
555 * 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
556 * @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
557 * @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
558 */
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
559 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
560 {
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
561 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
562
13570
4a7574282ac8 (svn r18092) -Codechange: remove support for the unnested widgets
rubidium <rubidium@openttd.org>
parents: 13567
diff changeset
563 assert(this->nested_array != NULL);
4a7574282ac8 (svn r18092) -Codechange: remove support for the unnested widgets
rubidium <rubidium@openttd.org>
parents: 13567
diff changeset
564 const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget);
4a7574282ac8 (svn r18092) -Codechange: remove support for the unnested widgets
rubidium <rubidium@openttd.org>
parents: 13567
diff changeset
565
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
566 int offset = this->IsWidgetLowered(widget) ? 1 : 0;
16441
86fd9bcc9d2f (svn r21157) -Codechange: remove information about the text direction out of the language "list"
rubidium <rubidium@openttd.org>
parents: 16309
diff changeset
567 int base = offset + nwid->pos_x + (_current_text_dir == TD_LTR ? nwid->current_x - WD_SORTBUTTON_ARROW_WIDTH : 0);
13570
4a7574282ac8 (svn r18092) -Codechange: remove support for the unnested widgets
rubidium <rubidium@openttd.org>
parents: 13567
diff changeset
568 int top = nwid->pos_y;
4a7574282ac8 (svn r18092) -Codechange: remove support for the unnested widgets
rubidium <rubidium@openttd.org>
parents: 13567
diff changeset
569
15400
821c26b30fd9 (svn r20043) -Codechange: Introduce vertical alignment for DrawStringMultiLine().
alberth <alberth@openttd.org>
parents: 15302
diff changeset
570 DrawString(base, base + WD_SORTBUTTON_ARROW_WIDTH, top + 1 + offset, state == SBS_DOWN ? DOWNARROW : UPARROW, TC_BLACK, SA_HOR_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
571 }
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
572
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
573
11799
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
574 /**
12708
f1e888f0b9e1 (svn r17171) -Doc: Additions and corrections of various doxygen strings.
alberth <alberth@openttd.org>
parents: 12706
diff changeset
575 * @defgroup NestedWidgets Hierarchical 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
576 * 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
577 * 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
578 *
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
579 * \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
580 * 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
581 * <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
582 * <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
583 * <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
584 * </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
585 * 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
586 *
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
587 * 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
588 * <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
589 * <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
590 * 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
591 * <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
592 * 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
593 * <li> #NWidgetVertical for organizing child widgets underneath each other.
16715
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
594 * <li> #NWidgetMatrix for organizing child widgets in a matrix form.
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
595 * <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
596 * <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
597 * </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
598 * 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
599 *
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
600 * \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
601 * 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
602 * 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
603 *
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
604 * 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
605 * - 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
606 * - 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
607 *
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
608 * 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
609 * <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
610 * <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
611 * to propagate filling and resize steps upwards to the root of the tree.
13676
e9a201c03e65 (svn r18201) -Codechange (r18092): No need anymore for initializing nested widgets for Widget* arrays.
alberth <alberth@openttd.org>
parents: 13670
diff changeset
612 * <li> A top-down sweep by recursively calling NWidgetBase::AssignSizePosition() with #ST_SMALLEST to make the smallest sizes consistent over
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
613 * 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
614 * 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
615 * <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
616 * 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
617 * 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
618 * </ol>
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
619 * 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
620 *
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
621 * 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
622 * 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
623 *
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
624 * @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
625 */
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
626
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
627 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
628 * Base class constructor.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
629 * @param tp Nested widget type.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
630 */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
631 NWidgetBase::NWidgetBase(WidgetType tp) : ZeroedMemoryAllocator()
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
632 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
633 this->type = tp;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
634 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
635
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
636 /* ~NWidgetContainer() takes care of #next and #prev data members. */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
637
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
638 /**
12404
375cd4fb8ae3 (svn r16838) -Codechange: Fill Window::nested_array in SetupSmallestSize.
alberth <alberth@openttd.org>
parents: 12403
diff changeset
639 * @fn void NWidgetBase::SetupSmallestSize(Window *w, bool init_array)
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
640 * Compute smallest size needed by the widget.
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
641 *
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
642 * 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
643 * display itself properly. In addition, filling and resizing of the widget are computed.
13955
2aacd08c5871 (svn r18491) -Fix (r18482): Update doxy comments of SetupSmallestSize() as well.
alberth <alberth@openttd.org>
parents: 13954
diff changeset
644 * The function calls #Window::UpdateWidgetSize for each leaf widget and
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
645 * 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
646 *
13955
2aacd08c5871 (svn r18491) -Fix (r18482): Update doxy comments of SetupSmallestSize() as well.
alberth <alberth@openttd.org>
parents: 13954
diff changeset
647 * @param w Window owning the widget.
2aacd08c5871 (svn r18491) -Fix (r18482): Update doxy comments of SetupSmallestSize() as well.
alberth <alberth@openttd.org>
parents: 13954
diff changeset
648 * @param init_array Initialize the \c w->nested_array.
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
649 *
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
650 * @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
651 */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
652
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
653 /**
13676
e9a201c03e65 (svn r18201) -Codechange (r18092): No need anymore for initializing nested widgets for Widget* arrays.
alberth <alberth@openttd.org>
parents: 13670
diff changeset
654 * @fn void NWidgetBase::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
655 * Assign size and position to the widget.
13676
e9a201c03e65 (svn r18201) -Codechange (r18092): No need anymore for initializing nested widgets for Widget* arrays.
alberth <alberth@openttd.org>
parents: 13670
diff changeset
656 * @param sizing Type of resizing to perform.
e9a201c03e65 (svn r18201) -Codechange (r18092): No need anymore for initializing nested widgets for Widget* arrays.
alberth <alberth@openttd.org>
parents: 13670
diff changeset
657 * @param x Horizontal offset of the widget relative to the left edge of the window.
e9a201c03e65 (svn r18201) -Codechange (r18092): No need anymore for initializing nested widgets for Widget* arrays.
alberth <alberth@openttd.org>
parents: 13670
diff changeset
658 * @param y Vertical offset of the widget relative to the top edge of the window.
e9a201c03e65 (svn r18201) -Codechange (r18092): No need anymore for initializing nested widgets for Widget* arrays.
alberth <alberth@openttd.org>
parents: 13670
diff changeset
659 * @param given_width Width allocated to the widget.
e9a201c03e65 (svn r18201) -Codechange (r18092): No need anymore for initializing nested widgets for Widget* arrays.
alberth <alberth@openttd.org>
parents: 13670
diff changeset
660 * @param given_height Height allocated to the widget.
e9a201c03e65 (svn r18201) -Codechange (r18092): No need anymore for initializing nested widgets for Widget* arrays.
alberth <alberth@openttd.org>
parents: 13670
diff changeset
661 * @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
662 *
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
663 * 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
664 * 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
665 */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
666
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
667 /**
13072
75bd67594af2 (svn r17572) -Codechange: Use the Window::GetWidget() function to access nested widgets through the nested_array.
alberth <alberth@openttd.org>
parents: 13034
diff changeset
668 * @fn void FillNestedArray(NWidgetBase **array, uint length)
12583
1fd1aea7e009 (svn r17023) -Revert (r16839): FillNestedArray() was less obsolete than anticipated.
alberth <alberth@openttd.org>
parents: 12577
diff changeset
669 * Fill the Window::nested_array array with pointers to nested widgets in the tree.
1fd1aea7e009 (svn r17023) -Revert (r16839): FillNestedArray() was less obsolete than anticipated.
alberth <alberth@openttd.org>
parents: 12577
diff changeset
670 * @param array Base pointer of the array.
1fd1aea7e009 (svn r17023) -Revert (r16839): FillNestedArray() was less obsolete than anticipated.
alberth <alberth@openttd.org>
parents: 12577
diff changeset
671 * @param length Length of the array.
1fd1aea7e009 (svn r17023) -Revert (r16839): FillNestedArray() was less obsolete than anticipated.
alberth <alberth@openttd.org>
parents: 12577
diff changeset
672 */
1fd1aea7e009 (svn r17023) -Revert (r16839): FillNestedArray() was less obsolete than anticipated.
alberth <alberth@openttd.org>
parents: 12577
diff changeset
673
1fd1aea7e009 (svn r17023) -Revert (r16839): FillNestedArray() was less obsolete than anticipated.
alberth <alberth@openttd.org>
parents: 12577
diff changeset
674 /**
13956
702099b8c615 (svn r18492) -Doc: A few Doxygen reference fixes (NewsSubtype reported by Eddi), and a typo fix.
alberth <alberth@openttd.org>
parents: 13955
diff changeset
675 * @fn void NWidgetBase::Draw(const Window *w)
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
676 * 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
677 * 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
678 * @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
679 */
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
680
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
681 /**
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
682 * 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
683 * @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
684 */
13034
6eb3f749890a (svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents: 13011
diff changeset
685 void NWidgetBase::SetDirty(const Window *w) const
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
686 {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
687 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
688 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
689 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
690 }
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
691
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
692 /**
12524
b78b7e2cb29f (svn r16961) -Codechange: Moving some methods up in the class hierarchy to avoid code duplication.
alberth <alberth@openttd.org>
parents: 12516
diff changeset
693 * @fn NWidgetCore *NWidgetBase::GetWidgetFromPos(int x, int 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
694 * 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
695 * @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
696 * @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
697 * @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
698 */
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
699
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
700 /**
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
701 * 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
702 * @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
703 * @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
704 */
12524
b78b7e2cb29f (svn r16961) -Codechange: Moving some methods up in the class hierarchy to avoid code duplication.
alberth <alberth@openttd.org>
parents: 12516
diff changeset
705 NWidgetBase *NWidgetBase::GetWidgetOfType(WidgetType tp)
b78b7e2cb29f (svn r16961) -Codechange: Moving some methods up in the class hierarchy to avoid code duplication.
alberth <alberth@openttd.org>
parents: 12516
diff changeset
706 {
b78b7e2cb29f (svn r16961) -Codechange: Moving some methods up in the class hierarchy to avoid code duplication.
alberth <alberth@openttd.org>
parents: 12516
diff changeset
707 return (this->type == tp) ? this : NULL;
b78b7e2cb29f (svn r16961) -Codechange: Moving some methods up in the class hierarchy to avoid code duplication.
alberth <alberth@openttd.org>
parents: 12516
diff changeset
708 }
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
709
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
710 /**
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
711 * Constructor for resizable nested widgets.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
712 * @param tp Nested widget type.
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
713 * @param fill_x Horizontal fill step size, \c 0 means no filling is allowed.
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
714 * @param fill_y Vertical fill step size, \c 0 means no filling is allowed.
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
715 */
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
716 NWidgetResizeBase::NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y) : NWidgetBase(tp)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
717 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
718 this->fill_x = fill_x;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
719 this->fill_y = fill_y;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
720 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
721
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
722 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
723 * Set minimal size of the widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
724 * @param min_x Horizontal minimal size of the widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
725 * @param min_y Vertical minimal size of the widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
726 */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
727 void NWidgetResizeBase::SetMinimalSize(uint min_x, uint min_y)
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
728 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
729 this->min_x = min_x;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
730 this->min_y = min_y;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
731 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
732
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
733 /**
13614
01ef0374674c (svn r18138) -Codechange: Add a new widgetpart to specify the height of a widget in text lines.
peter1138 <peter1138@openttd.org>
parents: 13576
diff changeset
734 * Set minimal text lines for the widget.
01ef0374674c (svn r18138) -Codechange: Add a new widgetpart to specify the height of a widget in text lines.
peter1138 <peter1138@openttd.org>
parents: 13576
diff changeset
735 * @param min_lines Number of text lines of the widget.
01ef0374674c (svn r18138) -Codechange: Add a new widgetpart to specify the height of a widget in text lines.
peter1138 <peter1138@openttd.org>
parents: 13576
diff changeset
736 * @param spacing Extra spacing (eg WD_FRAMERECT_TOP + _BOTTOM) of the widget.
01ef0374674c (svn r18138) -Codechange: Add a new widgetpart to specify the height of a widget in text lines.
peter1138 <peter1138@openttd.org>
parents: 13576
diff changeset
737 * @param size Font size of text.
01ef0374674c (svn r18138) -Codechange: Add a new widgetpart to specify the height of a widget in text lines.
peter1138 <peter1138@openttd.org>
parents: 13576
diff changeset
738 */
01ef0374674c (svn r18138) -Codechange: Add a new widgetpart to specify the height of a widget in text lines.
peter1138 <peter1138@openttd.org>
parents: 13576
diff changeset
739 void NWidgetResizeBase::SetMinimalTextLines(uint8 min_lines, uint8 spacing, FontSize size)
01ef0374674c (svn r18138) -Codechange: Add a new widgetpart to specify the height of a widget in text lines.
peter1138 <peter1138@openttd.org>
parents: 13576
diff changeset
740 {
01ef0374674c (svn r18138) -Codechange: Add a new widgetpart to specify the height of a widget in text lines.
peter1138 <peter1138@openttd.org>
parents: 13576
diff changeset
741 this->min_y = min_lines * GetCharacterHeight(size) + spacing;
01ef0374674c (svn r18138) -Codechange: Add a new widgetpart to specify the height of a widget in text lines.
peter1138 <peter1138@openttd.org>
parents: 13576
diff changeset
742 }
01ef0374674c (svn r18138) -Codechange: Add a new widgetpart to specify the height of a widget in text lines.
peter1138 <peter1138@openttd.org>
parents: 13576
diff changeset
743
01ef0374674c (svn r18138) -Codechange: Add a new widgetpart to specify the height of a widget in text lines.
peter1138 <peter1138@openttd.org>
parents: 13576
diff changeset
744 /**
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
745 * Set the filling of the widget from initial size.
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
746 * @param fill_x Horizontal fill step size, \c 0 means no filling is allowed.
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
747 * @param fill_y Vertical fill step size, \c 0 means no filling is allowed.
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
748 */
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
749 void NWidgetResizeBase::SetFill(uint fill_x, uint fill_y)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
750 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
751 this->fill_x = fill_x;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
752 this->fill_y = fill_y;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
753 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
754
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
755 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
756 * Set resize step of the widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
757 * @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
758 * @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
759 */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
760 void NWidgetResizeBase::SetResize(uint resize_x, uint resize_y)
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
761 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
762 this->resize_x = resize_x;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
763 this->resize_y = resize_y;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
764 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
765
13676
e9a201c03e65 (svn r18201) -Codechange (r18092): No need anymore for initializing nested widgets for Widget* arrays.
alberth <alberth@openttd.org>
parents: 13670
diff changeset
766 void NWidgetResizeBase::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
767 {
15215
c68f3c67204d (svn r19844) -Fix: Move NWidgetBase::StoreSizePosition() to an include file, and use proper inline macro.
alberth <alberth@openttd.org>
parents: 15214
diff changeset
768 this->StoreSizePosition(sizing, x, y, given_width, given_height);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
769 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
770
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
771 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
772 * Initialization of a 'real' widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
773 * @param tp Type of the widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
774 * @param colour Colour of the widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
775 * @param fill_x Default horizontal filling.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
776 * @param fill_y Default vertical filling.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
777 * @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
778 * @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
779 */
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
780 NWidgetCore::NWidgetCore(WidgetType tp, Colours colour, uint fill_x, uint fill_y, uint16 widget_data, StringID tool_tip) : NWidgetResizeBase(tp, fill_x, fill_y)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
781 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
782 this->colour = colour;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
783 this->index = -1;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
784 this->widget_data = widget_data;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
785 this->tool_tip = tool_tip;
15788
0f906a2224dc (svn r20462) -Fix (r20452): Initialise scrollbar_index with -1 to indicate 'no scrollbar associated'.
frosch <frosch@openttd.org>
parents: 15787
diff changeset
786 this->scrollbar_index = -1;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
787 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
788
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
789 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
790 * 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
791 * @param index Index to use.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
792 */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
793 void NWidgetCore::SetIndex(int index)
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
794 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
795 assert(index >= 0);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
796 this->index = index;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
797 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
798
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
799 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
800 * Set data and tool tip of the nested widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
801 * @param widget_data Data to use.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
802 * @param tool_tip Tool tip string to use.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
803 */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
804 void NWidgetCore::SetDataTip(uint16 widget_data, StringID tool_tip)
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
805 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
806 this->widget_data = widget_data;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
807 this->tool_tip = tool_tip;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
808 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
809
13072
75bd67594af2 (svn r17572) -Codechange: Use the Window::GetWidget() function to access nested widgets through the nested_array.
alberth <alberth@openttd.org>
parents: 13034
diff changeset
810 void NWidgetCore::FillNestedArray(NWidgetBase **array, uint length)
12583
1fd1aea7e009 (svn r17023) -Revert (r16839): FillNestedArray() was less obsolete than anticipated.
alberth <alberth@openttd.org>
parents: 12577
diff changeset
811 {
1fd1aea7e009 (svn r17023) -Revert (r16839): FillNestedArray() was less obsolete than anticipated.
alberth <alberth@openttd.org>
parents: 12577
diff changeset
812 if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
1fd1aea7e009 (svn r17023) -Revert (r16839): FillNestedArray() was less obsolete than anticipated.
alberth <alberth@openttd.org>
parents: 12577
diff changeset
813 }
1fd1aea7e009 (svn r17023) -Revert (r16839): FillNestedArray() was less obsolete than anticipated.
alberth <alberth@openttd.org>
parents: 12577
diff changeset
814
12524
b78b7e2cb29f (svn r16961) -Codechange: Moving some methods up in the class hierarchy to avoid code duplication.
alberth <alberth@openttd.org>
parents: 12516
diff changeset
815 NWidgetCore *NWidgetCore::GetWidgetFromPos(int x, int y)
b78b7e2cb29f (svn r16961) -Codechange: Moving some methods up in the class hierarchy to avoid code duplication.
alberth <alberth@openttd.org>
parents: 12516
diff changeset
816 {
b78b7e2cb29f (svn r16961) -Codechange: Moving some methods up in the class hierarchy to avoid code duplication.
alberth <alberth@openttd.org>
parents: 12516
diff changeset
817 return (IsInsideBS(x, this->pos_x, this->current_x) && IsInsideBS(y, this->pos_y, this->current_y)) ? this : NULL;
b78b7e2cb29f (svn r16961) -Codechange: Moving some methods up in the class hierarchy to avoid code duplication.
alberth <alberth@openttd.org>
parents: 12516
diff changeset
818 }
b78b7e2cb29f (svn r16961) -Codechange: Moving some methods up in the class hierarchy to avoid code duplication.
alberth <alberth@openttd.org>
parents: 12516
diff changeset
819
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
820 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
821 * Constructor container baseclass.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
822 * @param tp Type of the container.
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 NWidgetContainer::NWidgetContainer(WidgetType tp) : NWidgetBase(tp)
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
825 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
826 this->head = NULL;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
827 this->tail = NULL;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
828 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
829
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
830 NWidgetContainer::~NWidgetContainer()
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
831 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
832 while (this->head != NULL) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
833 NWidgetBase *wid = this->head->next;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
834 delete this->head;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
835 this->head = wid;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
836 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
837 this->tail = NULL;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
838 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
839
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
840 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
841 {
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
842 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
843 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
844 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
845 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
846 }
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
847 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
848 }
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
849
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
850 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
851 * Append widget \a wid to container.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
852 * @param wid Widget to append.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
853 */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
854 void NWidgetContainer::Add(NWidgetBase *wid)
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
855 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
856 assert(wid->next == NULL && wid->prev == NULL);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
857
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
858 if (this->head == NULL) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
859 this->head = wid;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
860 this->tail = wid;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
861 } else {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
862 assert(this->tail != NULL);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
863 assert(this->tail->next == NULL);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
864
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
865 this->tail->next = wid;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
866 wid->prev = this->tail;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
867 this->tail = wid;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
868 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
869 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
870
13072
75bd67594af2 (svn r17572) -Codechange: Use the Window::GetWidget() function to access nested widgets through the nested_array.
alberth <alberth@openttd.org>
parents: 13034
diff changeset
871 void NWidgetContainer::FillNestedArray(NWidgetBase **array, uint length)
12583
1fd1aea7e009 (svn r17023) -Revert (r16839): FillNestedArray() was less obsolete than anticipated.
alberth <alberth@openttd.org>
parents: 12577
diff changeset
872 {
1fd1aea7e009 (svn r17023) -Revert (r16839): FillNestedArray() was less obsolete than anticipated.
alberth <alberth@openttd.org>
parents: 12577
diff changeset
873 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
1fd1aea7e009 (svn r17023) -Revert (r16839): FillNestedArray() was less obsolete than anticipated.
alberth <alberth@openttd.org>
parents: 12577
diff changeset
874 child_wid->FillNestedArray(array, length);
1fd1aea7e009 (svn r17023) -Revert (r16839): FillNestedArray() was less obsolete than anticipated.
alberth <alberth@openttd.org>
parents: 12577
diff changeset
875 }
1fd1aea7e009 (svn r17023) -Revert (r16839): FillNestedArray() was less obsolete than anticipated.
alberth <alberth@openttd.org>
parents: 12577
diff changeset
876 }
1fd1aea7e009 (svn r17023) -Revert (r16839): FillNestedArray() was less obsolete than anticipated.
alberth <alberth@openttd.org>
parents: 12577
diff changeset
877
11528
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
878 /**
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
879 * Widgets stacked on top of each other.
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
880 */
13565
40a13e194fd0 (svn r18087) -Codechange: remove NWID_LAYERED
rubidium <rubidium@openttd.org>
parents: 13543
diff changeset
881 NWidgetStacked::NWidgetStacked() : NWidgetContainer(NWID_SELECTION)
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
882 {
13073
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
883 this->index = -1;
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
884 }
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
885
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
886 void NWidgetStacked::SetIndex(int index)
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
887 {
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
888 this->index = index;
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
889 }
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
890
12404
375cd4fb8ae3 (svn r16838) -Codechange: Fill Window::nested_array in SetupSmallestSize.
alberth <alberth@openttd.org>
parents: 12403
diff changeset
891 void NWidgetStacked::SetupSmallestSize(Window *w, bool init_array)
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
892 {
13074
c6408d5b9f99 (svn r17574) -Fix (r17573): Insert NWID_SELECTION in nested_array when appropriate.
alberth <alberth@openttd.org>
parents: 13073
diff changeset
893 if (this->index >= 0 && init_array) { // Fill w->nested_array[]
c6408d5b9f99 (svn r17574) -Fix (r17573): Insert NWID_SELECTION in nested_array when appropriate.
alberth <alberth@openttd.org>
parents: 13073
diff changeset
894 assert(w->nested_array_size > (uint)this->index);
c6408d5b9f99 (svn r17574) -Fix (r17573): Insert NWID_SELECTION in nested_array when appropriate.
alberth <alberth@openttd.org>
parents: 13073
diff changeset
895 w->nested_array[this->index] = this;
c6408d5b9f99 (svn r17574) -Fix (r17573): Insert NWID_SELECTION in nested_array when appropriate.
alberth <alberth@openttd.org>
parents: 13073
diff changeset
896 }
c6408d5b9f99 (svn r17574) -Fix (r17573): Insert NWID_SELECTION in nested_array when appropriate.
alberth <alberth@openttd.org>
parents: 13073
diff changeset
897
13246
6ed0d462f914 (svn r17755) -Codechange: Allow for a zero-size display plane in a NWidgetStacked widget to hide its child widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
898 /* Zero size plane selected */
14063
4eb2be463cc4 (svn r18606) -Codechange: Introduce several forms of zero-size stacked display planes.
alberth <alberth@openttd.org>
parents: 14062
diff changeset
899 if (this->shown_plane >= SZSP_BEGIN) {
4eb2be463cc4 (svn r18606) -Codechange: Introduce several forms of zero-size stacked display planes.
alberth <alberth@openttd.org>
parents: 14062
diff changeset
900 Dimension size = {0, 0};
13705
8dee47e001b2 (svn r18230) -Codechange: Allow fill stepsize to be set from Window::UpdateWidgetSize().
alberth <alberth@openttd.org>
parents: 13704
diff changeset
901 Dimension padding = {0, 0};
14063
4eb2be463cc4 (svn r18606) -Codechange: Introduce several forms of zero-size stacked display planes.
alberth <alberth@openttd.org>
parents: 14062
diff changeset
902 Dimension fill = {(this->shown_plane == SZSP_HORIZONTAL), (this->shown_plane == SZSP_VERTICAL)};
4eb2be463cc4 (svn r18606) -Codechange: Introduce several forms of zero-size stacked display planes.
alberth <alberth@openttd.org>
parents: 14062
diff changeset
903 Dimension resize = {(this->shown_plane == SZSP_HORIZONTAL), (this->shown_plane == SZSP_VERTICAL)};
13339
78083f48ac84 (svn r17848) -Codechange: allow overriding (some) settings of STACKED_SELECTION_ZERO_SIZE widgets via UpdateWidgetSize
rubidium <rubidium@openttd.org>
parents: 13246
diff changeset
904 /* Here we're primarily interested in the value of resize */
14062
9103e248263f (svn r18605) -Codechange: Coding style fixes, prevent useless calls to UpdateWidgetSize().
alberth <alberth@openttd.org>
parents: 14050
diff changeset
905 if (this->index >= 0) w->UpdateWidgetSize(this->index, &size, padding, &fill, &resize);
13339
78083f48ac84 (svn r17848) -Codechange: allow overriding (some) settings of STACKED_SELECTION_ZERO_SIZE widgets via UpdateWidgetSize
rubidium <rubidium@openttd.org>
parents: 13246
diff changeset
906
78083f48ac84 (svn r17848) -Codechange: allow overriding (some) settings of STACKED_SELECTION_ZERO_SIZE widgets via UpdateWidgetSize
rubidium <rubidium@openttd.org>
parents: 13246
diff changeset
907 this->smallest_x = size.width;
78083f48ac84 (svn r17848) -Codechange: allow overriding (some) settings of STACKED_SELECTION_ZERO_SIZE widgets via UpdateWidgetSize
rubidium <rubidium@openttd.org>
parents: 13246
diff changeset
908 this->smallest_y = size.height;
13705
8dee47e001b2 (svn r18230) -Codechange: Allow fill stepsize to be set from Window::UpdateWidgetSize().
alberth <alberth@openttd.org>
parents: 13704
diff changeset
909 this->fill_x = fill.width;
8dee47e001b2 (svn r18230) -Codechange: Allow fill stepsize to be set from Window::UpdateWidgetSize().
alberth <alberth@openttd.org>
parents: 13704
diff changeset
910 this->fill_y = fill.height;
13339
78083f48ac84 (svn r17848) -Codechange: allow overriding (some) settings of STACKED_SELECTION_ZERO_SIZE widgets via UpdateWidgetSize
rubidium <rubidium@openttd.org>
parents: 13246
diff changeset
911 this->resize_x = resize.width;
78083f48ac84 (svn r17848) -Codechange: allow overriding (some) settings of STACKED_SELECTION_ZERO_SIZE widgets via UpdateWidgetSize
rubidium <rubidium@openttd.org>
parents: 13246
diff changeset
912 this->resize_y = resize.height;
13246
6ed0d462f914 (svn r17755) -Codechange: Allow for a zero-size display plane in a NWidgetStacked widget to hide its child widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
913 return;
6ed0d462f914 (svn r17755) -Codechange: Allow for a zero-size display plane in a NWidgetStacked widget to hide its child widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
914 }
6ed0d462f914 (svn r17755) -Codechange: Allow for a zero-size display plane in a NWidgetStacked widget to hide its child widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
915
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
916 /* First sweep, recurse down and compute minimal size and filling. */
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
917 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
918 this->smallest_y = 0;
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
919 this->fill_x = (this->head != NULL) ? 1 : 0;
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
920 this->fill_y = (this->head != NULL) ? 1 : 0;
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
921 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
922 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
923 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
12404
375cd4fb8ae3 (svn r16838) -Codechange: Fill Window::nested_array in SetupSmallestSize.
alberth <alberth@openttd.org>
parents: 12403
diff changeset
924 child_wid->SetupSmallestSize(w, init_array);
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
925
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
926 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
927 this->smallest_y = max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
928 this->fill_x = LeastCommonMultiple(this->fill_x, child_wid->fill_x);
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
929 this->fill_y = LeastCommonMultiple(this->fill_y, child_wid->fill_y);
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
930 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
931 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
932 }
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
933 }
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
934
13676
e9a201c03e65 (svn r18201) -Codechange (r18092): No need anymore for initializing nested widgets for Widget* arrays.
alberth <alberth@openttd.org>
parents: 13670
diff changeset
935 void NWidgetStacked::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
936 {
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
937 assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
15215
c68f3c67204d (svn r19844) -Fix: Move NWidgetBase::StoreSizePosition() to an include file, and use proper inline macro.
alberth <alberth@openttd.org>
parents: 15214
diff changeset
938 this->StoreSizePosition(sizing, x, y, given_width, given_height);
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
939
14063
4eb2be463cc4 (svn r18606) -Codechange: Introduce several forms of zero-size stacked display planes.
alberth <alberth@openttd.org>
parents: 14062
diff changeset
940 if (this->shown_plane >= SZSP_BEGIN) return;
13246
6ed0d462f914 (svn r17755) -Codechange: Allow for a zero-size display plane in a NWidgetStacked widget to hide its child widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
941
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
942 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
13685
ac56dd84488d (svn r18210) -Codechange: Child widgets always get the entire space in perpendicular direction of the container.
alberth <alberth@openttd.org>
parents: 13676
diff changeset
943 uint hor_step = (sizing == ST_SMALLEST) ? 1 : 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
944 uint child_width = ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding_left - child_wid->padding_right, hor_step);
13685
ac56dd84488d (svn r18210) -Codechange: Child widgets always get the entire space in perpendicular direction of the container.
alberth <alberth@openttd.org>
parents: 13676
diff changeset
945 uint child_pos_x = (rtl ? child_wid->padding_right : child_wid->padding_left);
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
946
13685
ac56dd84488d (svn r18210) -Codechange: Child widgets always get the entire space in perpendicular direction of the container.
alberth <alberth@openttd.org>
parents: 13676
diff changeset
947 uint vert_step = (sizing == ST_SMALLEST) ? 1 : 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
948 uint child_height = ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding_top - child_wid->padding_bottom, vert_step);
13685
ac56dd84488d (svn r18210) -Codechange: Child widgets always get the entire space in perpendicular direction of the container.
alberth <alberth@openttd.org>
parents: 13676
diff changeset
949 uint child_pos_y = child_wid->padding_top;
11966
de771cbe234d (svn r16372) -Codechange: Simplify size calculations with a few helper functions.
alberth <alberth@openttd.org>
parents: 11965
diff changeset
950
13676
e9a201c03e65 (svn r18201) -Codechange (r18092): No need anymore for initializing nested widgets for Widget* arrays.
alberth <alberth@openttd.org>
parents: 13670
diff changeset
951 child_wid->AssignSizePosition(sizing, x + child_pos_x, y + child_pos_y, child_width, child_height, rtl);
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
952 }
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
953 }
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
954
13073
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
955 void NWidgetStacked::FillNestedArray(NWidgetBase **array, uint length)
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
956 {
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
957 if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
958 NWidgetContainer::FillNestedArray(array, length);
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
959 }
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
960
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
961 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
962 {
14063
4eb2be463cc4 (svn r18606) -Codechange: Introduce several forms of zero-size stacked display planes.
alberth <alberth@openttd.org>
parents: 14062
diff changeset
963 if (this->shown_plane >= SZSP_BEGIN) return;
13246
6ed0d462f914 (svn r17755) -Codechange: Allow for a zero-size display plane in a NWidgetStacked widget to hide its child widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
964
13565
40a13e194fd0 (svn r18087) -Codechange: remove NWID_LAYERED
rubidium <rubidium@openttd.org>
parents: 13543
diff changeset
965 int plane = 0;
40a13e194fd0 (svn r18087) -Codechange: remove NWID_LAYERED
rubidium <rubidium@openttd.org>
parents: 13543
diff changeset
966 for (NWidgetBase *child_wid = this->head; child_wid != NULL; plane++, child_wid = child_wid->next) {
40a13e194fd0 (svn r18087) -Codechange: remove NWID_LAYERED
rubidium <rubidium@openttd.org>
parents: 13543
diff changeset
967 if (plane == this->shown_plane) {
40a13e194fd0 (svn r18087) -Codechange: remove NWID_LAYERED
rubidium <rubidium@openttd.org>
parents: 13543
diff changeset
968 child_wid->Draw(w);
40a13e194fd0 (svn r18087) -Codechange: remove NWID_LAYERED
rubidium <rubidium@openttd.org>
parents: 13543
diff changeset
969 return;
13073
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
970 }
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
971 }
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
972
13565
40a13e194fd0 (svn r18087) -Codechange: remove NWID_LAYERED
rubidium <rubidium@openttd.org>
parents: 13543
diff changeset
973 NOT_REACHED();
12101
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
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
976 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
977 {
14063
4eb2be463cc4 (svn r18606) -Codechange: Introduce several forms of zero-size stacked display planes.
alberth <alberth@openttd.org>
parents: 14062
diff changeset
978 if (this->shown_plane >= SZSP_BEGIN) return NULL;
13246
6ed0d462f914 (svn r17755) -Codechange: Allow for a zero-size display plane in a NWidgetStacked widget to hide its child widgets.
alberth <alberth@openttd.org>
parents: 13186
diff changeset
979
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
980 if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return NULL;
13073
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
981 int plane = 0;
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
982 for (NWidgetBase *child_wid = this->head; child_wid != NULL; plane++, child_wid = child_wid->next) {
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
983 if (plane == this->shown_plane) {
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
984 return child_wid->GetWidgetFromPos(x, y);
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
985 }
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
986 }
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 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
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
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15579
diff changeset
990 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15579
diff changeset
991 * Select which plane to show (for #NWID_SELECTION only).
13073
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
992 * @param plane Plane number to display.
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
993 */
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
994 void NWidgetStacked::SetDisplayedPlane(int plane)
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
995 {
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
996 this->shown_plane = plane;
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
997 }
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
998
12255
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
999 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
1000 {
12255
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1001 this->flags = flags;
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1002 }
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1003
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1004 /**
11528
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1005 * 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
1006 *
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1007 * @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
1008 * 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
1009 * @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
1010 * @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
1011 * 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
1012 */
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
1013 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
1014 {
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1015 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
1016 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
1017 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
1018 }
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1019
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1020 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
1021 {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1022 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
1023 child_wid->Draw(w);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1024 }
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1025 }
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1026
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
1027 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
1028 {
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
1029 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
1030
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
1031 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
1032 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
1033 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
1034 }
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
1035 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
1036 }
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
1037
11799
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
1038 /** 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
1039 NWidgetHorizontal::NWidgetHorizontal(NWidContainerFlags flags) : NWidgetPIPContainer(NWID_HORIZONTAL, flags)
11461
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 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1042
12404
375cd4fb8ae3 (svn r16838) -Codechange: Fill Window::nested_array in SetupSmallestSize.
alberth <alberth@openttd.org>
parents: 12403
diff changeset
1043 void NWidgetHorizontal::SetupSmallestSize(Window *w, bool init_array)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1044 {
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1045 this->smallest_x = 0; // Sum of minimal size of all childs.
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1046 this->smallest_y = 0; // Biggest child.
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1047 this->fill_x = 0; // smallest non-zero child widget fill step.
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1048 this->fill_y = 1; // smallest common child fill step.
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1049 this->resize_x = 0; // smallest non-zero child widget resize step.
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1050 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
1051
13707
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1052 /* 1a. Forward call, collect biggest nested array index, and longest/widest child length. */
12255
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1053 uint longest = 0; // Longest child found.
13707
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1054 uint max_vert_fill = 0; // Biggest vertical fill step.
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1055 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
12404
375cd4fb8ae3 (svn r16838) -Codechange: Fill Window::nested_array in SetupSmallestSize.
alberth <alberth@openttd.org>
parents: 12403
diff changeset
1056 child_wid->SetupSmallestSize(w, init_array);
12255
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1057 longest = max(longest, child_wid->smallest_x);
13707
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1058 max_vert_fill = max(max_vert_fill, child_wid->GetVerticalStepSize(ST_SMALLEST));
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1059 this->smallest_y = max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1060 }
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1061 /* 1b. Make the container higher if needed to accomadate all childs nicely. */
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1062 uint max_smallest = this->smallest_y + 3 * max_vert_fill; // Upper limit to computing smallest height.
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1063 uint cur_height = this->smallest_y;
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1064 while (true) {
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1065 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1066 uint step_size = child_wid->GetVerticalStepSize(ST_SMALLEST);
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1067 uint child_height = child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom;
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1068 if (step_size > 1 && child_height < cur_height) { // Small step sizes or already fitting childs are not interesting.
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1069 uint remainder = (cur_height - child_height) % step_size;
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1070 if (remainder > 0) { // Child did not fit entirely, widen the container.
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1071 cur_height += step_size - remainder;
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1072 assert(cur_height < max_smallest); // Safeguard against infinite height expansion.
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1073 /* Remaining childs will adapt to the new cur_height, thus speeding up the computation. */
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1074 }
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1075 }
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1076 }
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1077 if (this->smallest_y == cur_height) break;
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1078 this->smallest_y = cur_height; // Smallest height got changed, try again.
12255
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1079 }
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1080 /* 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
1081 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
1082 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1083 if (child_wid->fill_x == 1) child_wid->smallest_x = longest;
12255
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1084 }
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1085 }
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1086 /* 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
1087 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
1088 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
1089 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
1090 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
1091 } 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
1092 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
1093 }
bf92950ea00b (svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents: 11500
diff changeset
1094
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
1095 this->smallest_x += child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right;
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1096 if (child_wid->fill_x > 0) {
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1097 if (this->fill_x == 0 || this->fill_x > child_wid->fill_x) this->fill_x = child_wid->fill_x;
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1098 }
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1099 this->fill_y = LeastCommonMultiple(this->fill_y, child_wid->fill_y);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1100
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1101 if (child_wid->resize_x > 0) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1102 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
1103 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1104 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
1105 }
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
1106 /* 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
1107 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
1108 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1109
13676
e9a201c03e65 (svn r18201) -Codechange (r18092): No need anymore for initializing nested widgets for Widget* arrays.
alberth <alberth@openttd.org>
parents: 13670
diff changeset
1110 void NWidgetHorizontal::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1111 {
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
1112 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
1113
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
1114 uint additional_length = given_width - this->smallest_x; // Additional width given to us.
15215
c68f3c67204d (svn r19844) -Fix: Move NWidgetBase::StoreSizePosition() to an include file, and use proper inline macro.
alberth <alberth@openttd.org>
parents: 15214
diff changeset
1115 this->StoreSizePosition(sizing, x, y, given_width, given_height);
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1116
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1117 /* 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
1118 * 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
1119 * 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
1120 * 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
1121 *
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1122 * 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
1123 * 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
1124 * 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
1125 * 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
1126 */
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1127
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1128 /* 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
1129 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
1130 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
1131 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
1132 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
1133 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
1134 num_changing_childs++;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1135 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
1136 } else {
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1137 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
1138 }
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1139
13685
ac56dd84488d (svn r18210) -Codechange: Child widgets always get the entire space in perpendicular direction of the container.
alberth <alberth@openttd.org>
parents: 13676
diff changeset
1140 uint vert_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetVerticalStepSize(sizing);
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1141 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
1142 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1143
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1144 /* 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
1145 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
1146 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
1147 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
1148 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
1149 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
1150 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
1151 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
1152 num_changing_childs--;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1153 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
1154 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
1155 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
1156 continue;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1157 }
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1158 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
1159 }
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1160 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
1161 }
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1162 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
1163
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1164 /* Third loop: Compute position and call the child. */
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1165 uint position = 0; // Place to put next child relative to origin of the container.
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1166 NWidgetBase *child_wid = rtl ? this->tail : this->head;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1167 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
1168 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
1169 uint child_x = x + position + (rtl ? child_wid->padding_right : child_wid->padding_left);
13685
ac56dd84488d (svn r18210) -Codechange: Child widgets always get the entire space in perpendicular direction of the container.
alberth <alberth@openttd.org>
parents: 13676
diff changeset
1170 uint child_y = y + child_wid->padding_top;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1171
13676
e9a201c03e65 (svn r18201) -Codechange (r18092): No need anymore for initializing nested widgets for Widget* arrays.
alberth <alberth@openttd.org>
parents: 13670
diff changeset
1172 child_wid->AssignSizePosition(sizing, child_x, child_y, child_width, child_wid->current_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
1173 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
1174
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1175 child_wid = rtl ? child_wid->prev : child_wid->next;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1176 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1177 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1178
11799
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
1179 /** 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
1180 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
1181 {
d29f1358f95b (svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents: 11495
diff changeset
1182 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
1183 }
d29f1358f95b (svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents: 11495
diff changeset
1184
13676
e9a201c03e65 (svn r18201) -Codechange (r18092): No need anymore for initializing nested widgets for Widget* arrays.
alberth <alberth@openttd.org>
parents: 13670
diff changeset
1185 void NWidgetHorizontalLTR::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, 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
1186 {
13676
e9a201c03e65 (svn r18201) -Codechange (r18092): No need anymore for initializing nested widgets for Widget* arrays.
alberth <alberth@openttd.org>
parents: 13670
diff changeset
1187 NWidgetHorizontal::AssignSizePosition(sizing, x, y, given_width, given_height, 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
1188 }
d29f1358f95b (svn r15861) -Codechange: Add NWID_HORIZONTAL_LTR that forces the ordering from left-to-right.
yexo <yexo@openttd.org>
parents: 11495
diff changeset
1189
11799
3a6a820d27e2 (svn r16189) -Doc: Additions and improvement of (mainly) nested widgets/widget-parts doxygen docs.
alberth <alberth@openttd.org>
parents: 11770
diff changeset
1190 /** 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
1191 NWidgetVertical::NWidgetVertical(NWidContainerFlags flags) : NWidgetPIPContainer(NWID_VERTICAL, flags)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1192 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1193 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1194
12404
375cd4fb8ae3 (svn r16838) -Codechange: Fill Window::nested_array in SetupSmallestSize.
alberth <alberth@openttd.org>
parents: 12403
diff changeset
1195 void NWidgetVertical::SetupSmallestSize(Window *w, bool init_array)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1196 {
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1197 this->smallest_x = 0; // Biggest child.
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1198 this->smallest_y = 0; // Sum of minimal size of all childs.
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1199 this->fill_x = 1; // smallest common child fill step.
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1200 this->fill_y = 0; // smallest non-zero child widget fill step.
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1201 this->resize_x = 1; // smallest common child resize step.
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1202 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
1203
13707
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1204 /* 1a. Forward call, collect biggest nested array index, and longest/widest child length. */
12255
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1205 uint highest = 0; // Highest child found.
13707
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1206 uint max_hor_fill = 0; // Biggest horizontal fill step.
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1207 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
12404
375cd4fb8ae3 (svn r16838) -Codechange: Fill Window::nested_array in SetupSmallestSize.
alberth <alberth@openttd.org>
parents: 12403
diff changeset
1208 child_wid->SetupSmallestSize(w, init_array);
12255
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1209 highest = max(highest, child_wid->smallest_y);
13707
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1210 max_hor_fill = max(max_hor_fill, child_wid->GetHorizontalStepSize(ST_SMALLEST));
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1211 this->smallest_x = max(this->smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1212 }
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1213 /* 1b. Make the container wider if needed to accomadate all childs nicely. */
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1214 uint max_smallest = this->smallest_x + 3 * max_hor_fill; // Upper limit to computing smallest height.
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1215 uint cur_width = this->smallest_x;
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1216 while (true) {
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1217 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1218 uint step_size = child_wid->GetHorizontalStepSize(ST_SMALLEST);
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1219 uint child_width = child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right;
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1220 if (step_size > 1 && child_width < cur_width) { // Small step sizes or already fitting childs are not interesting.
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1221 uint remainder = (cur_width - child_width) % step_size;
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1222 if (remainder > 0) { // Child did not fit entirely, widen the container.
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1223 cur_width += step_size - remainder;
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1224 assert(cur_width < max_smallest); // Safeguard against infinite width expansion.
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1225 /* Remaining childs will adapt to the new cur_width, thus speeding up the computation. */
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1226 }
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1227 }
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1228 }
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1229 if (this->smallest_x == cur_width) break;
472de6714e9a (svn r18232) -Fix: Extend container widgets to accomadate multiples of filling step size.
alberth <alberth@openttd.org>
parents: 13705
diff changeset
1230 this->smallest_x = cur_width; // Smallest width got changed, try again.
12255
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1231 }
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1232 /* 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
1233 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
1234 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1235 if (child_wid->fill_y == 1) child_wid->smallest_y = highest;
12255
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1236 }
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1237 }
bbfb4d4f6bb2 (svn r16670) -Codechange: Containers with equally sized children are useful to have.
alberth <alberth@openttd.org>
parents: 12195
diff changeset
1238 /* 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
1239 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
1240 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
1241 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
1242 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
1243 } 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
1244 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
1245 }
bf92950ea00b (svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents: 11500
diff changeset
1246
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
1247 this->smallest_y += child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom;
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1248 if (child_wid->fill_y > 0) {
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1249 if (this->fill_y == 0 || this->fill_y > child_wid->fill_y) this->fill_y = child_wid->fill_y;
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1250 }
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1251 this->fill_x = LeastCommonMultiple(this->fill_x, child_wid->fill_x);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1252
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1253 if (child_wid->resize_y > 0) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1254 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
1255 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1256 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
1257 }
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
1258 /* 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
1259 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
1260 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1261
13676
e9a201c03e65 (svn r18201) -Codechange (r18092): No need anymore for initializing nested widgets for Widget* arrays.
alberth <alberth@openttd.org>
parents: 13670
diff changeset
1262 void NWidgetVertical::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1263 {
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
1264 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
1265
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
1266 int additional_length = given_height - this->smallest_y; // Additional height given to us.
15215
c68f3c67204d (svn r19844) -Fix: Move NWidgetBase::StoreSizePosition() to an include file, and use proper inline macro.
alberth <alberth@openttd.org>
parents: 15214
diff changeset
1267 this->StoreSizePosition(sizing, x, y, given_width, given_height);
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1268
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1269 /* 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
1270 * 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
1271 */
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1272
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1273 /* 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
1274 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
1275 uint biggest_stepsize = 0;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1276 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
1277 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
1278 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
1279 num_changing_childs++;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1280 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
1281 } else {
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1282 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
1283 }
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1284
13685
ac56dd84488d (svn r18210) -Codechange: Child widgets always get the entire space in perpendicular direction of the container.
alberth <alberth@openttd.org>
parents: 13676
diff changeset
1285 uint hor_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing);
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1286 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
1287 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1288
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1289 /* 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
1290 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
1291 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
1292 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
1293 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
1294 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
1295 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
1296 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
1297 num_changing_childs--;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1298 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
1299 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
1300 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
1301 continue;
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1302 }
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1303 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
1304 }
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1305 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
1306 }
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1307 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
1308
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1309 /* Third loop: Compute position and call the child. */
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1310 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
1311 for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
13685
ac56dd84488d (svn r18210) -Codechange: Child widgets always get the entire space in perpendicular direction of the container.
alberth <alberth@openttd.org>
parents: 13676
diff changeset
1312 uint child_x = x + (rtl ? child_wid->padding_right : child_wid->padding_left);
12091
f1a0762b5788 (svn r16501) -Codechange: Introduced different phases in resizing a nested widget tree.
alberth <alberth@openttd.org>
parents: 12082
diff changeset
1313 uint child_height = child_wid->current_y;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1314
13676
e9a201c03e65 (svn r18201) -Codechange (r18092): No need anymore for initializing nested widgets for Widget* arrays.
alberth <alberth@openttd.org>
parents: 13670
diff changeset
1315 child_wid->AssignSizePosition(sizing, child_x, y + position + child_wid->padding_top, child_wid->current_x, child_height, 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
1316 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
1317 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1318 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1319
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1320 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1321 * Generic spacer widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1322 * @param length Horizontal size of the spacer widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1323 * @param height Vertical size of the spacer widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1324 */
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1325 NWidgetSpacer::NWidgetSpacer(int length, int height) : NWidgetResizeBase(NWID_SPACER, 0, 0)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1326 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1327 this->SetMinimalSize(length, height);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1328 this->SetResize(0, 0);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1329 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1330
12404
375cd4fb8ae3 (svn r16838) -Codechange: Fill Window::nested_array in SetupSmallestSize.
alberth <alberth@openttd.org>
parents: 12403
diff changeset
1331 void NWidgetSpacer::SetupSmallestSize(Window *w, bool init_array)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1332 {
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
1333 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
1334 this->smallest_y = this->min_y;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1335 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1336
13072
75bd67594af2 (svn r17572) -Codechange: Use the Window::GetWidget() function to access nested widgets through the nested_array.
alberth <alberth@openttd.org>
parents: 13034
diff changeset
1337 void NWidgetSpacer::FillNestedArray(NWidgetBase **array, uint length)
12583
1fd1aea7e009 (svn r17023) -Revert (r16839): FillNestedArray() was less obsolete than anticipated.
alberth <alberth@openttd.org>
parents: 12577
diff changeset
1338 {
1fd1aea7e009 (svn r17023) -Revert (r16839): FillNestedArray() was less obsolete than anticipated.
alberth <alberth@openttd.org>
parents: 12577
diff changeset
1339 }
1fd1aea7e009 (svn r17023) -Revert (r16839): FillNestedArray() was less obsolete than anticipated.
alberth <alberth@openttd.org>
parents: 12577
diff changeset
1340
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1341 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
1342 {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1343 /* Spacer widget is never visible. */
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1344 }
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1345
13034
6eb3f749890a (svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents: 13011
diff changeset
1346 void NWidgetSpacer::SetDirty(const Window *w) const
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1347 {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1348 /* Spacer widget never need repainting. */
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1349 }
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1350
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
1351 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
1352 {
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
1353 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
1354 }
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
1355
16715
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1356 NWidgetMatrix::NWidgetMatrix() : NWidgetPIPContainer(NWID_MATRIX, NC_EQUALSIZE), index(-1), clicked(-1), count(-1)
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1357 {
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1358 }
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1359
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1360 void NWidgetMatrix::SetIndex(int index)
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1361 {
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1362 this->index = index;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1363 }
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1364
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1365 void NWidgetMatrix::SetColour(Colours colour)
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1366 {
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1367 this->colour = colour;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1368 }
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1369
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1370 /**
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1371 * Sets the clicked widget in the matrix.
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1372 * @param clicked The clicked widget.
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1373 */
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1374 void NWidgetMatrix::SetClicked(int clicked)
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1375 {
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1376 this->clicked = clicked;
17075
7ac0e0454f5f (svn r21812) -Fix (r21754): Don't try to scroll the matrix widget to position -1.
alberth <alberth@openttd.org>
parents: 17027
diff changeset
1377 if (this->clicked >= 0 && this->sb != NULL && this->widgets_x != 0) {
17017
866761010474 (svn r21754) -Codechange: Scroll the matrix widget to make a clicked entry fully visible.
alberth <alberth@openttd.org>
parents: 16746
diff changeset
1378 int vpos = (this->clicked / this->widgets_x) * this->widget_h; // Vertical position of the top.
866761010474 (svn r21754) -Codechange: Scroll the matrix widget to make a clicked entry fully visible.
alberth <alberth@openttd.org>
parents: 16746
diff changeset
1379 /* Need to scroll down -> Scroll to the bottom.
866761010474 (svn r21754) -Codechange: Scroll the matrix widget to make a clicked entry fully visible.
alberth <alberth@openttd.org>
parents: 16746
diff changeset
1380 * However, last entry has no 'this->pip_inter' underneath, and we must stay below this->sb->GetCount() */
866761010474 (svn r21754) -Codechange: Scroll the matrix widget to make a clicked entry fully visible.
alberth <alberth@openttd.org>
parents: 16746
diff changeset
1381 if (this->sb->GetPosition() < vpos) vpos += this->widget_h - this->pip_inter - 1;
866761010474 (svn r21754) -Codechange: Scroll the matrix widget to make a clicked entry fully visible.
alberth <alberth@openttd.org>
parents: 16746
diff changeset
1382 this->sb->ScrollTowards(vpos);
866761010474 (svn r21754) -Codechange: Scroll the matrix widget to make a clicked entry fully visible.
alberth <alberth@openttd.org>
parents: 16746
diff changeset
1383 }
16715
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1384 }
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1385
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1386 /**
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1387 * Set the number of elements in this matrix.
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1388 * @note Updates the number of elements/capacity of the real scrollbar.
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1389 * @param count The number of elements.
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1390 */
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1391 void NWidgetMatrix::SetCount(int count)
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1392 {
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1393 this->count = count;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1394
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1395 if (this->sb == NULL || this->widgets_x == 0) return;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1396
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1397 /* We need to get the number of pixels the matrix is high/wide.
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1398 * So, determine the number of rows/columns based on the number of
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1399 * columns/rows (one is constant/unscrollable).
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1400 * Then multiply that by the height of a widget, and add the pre
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1401 * and post spacing "offsets". */
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1402 count = CeilDiv(count, this->sb->IsVertical() ? this->widgets_x : this->widgets_y);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1403 count *= (this->sb->IsVertical() ? this->head->smallest_y : this->head->smallest_x) + this->pip_inter;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1404 count += -this->pip_inter + this->pip_pre + this->pip_post; // We counted an inter too much in the multiplication above
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1405 this->sb->SetCount(count);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1406 this->sb->SetCapacity(this->sb->IsVertical() ? this->current_y : this->current_x);
17027
96e98a584a28 (svn r21764) -Change: Make the scrollbar associated to a NWidgetMatrix scroll in steps of the matrix when using the wheel or the scrollbar-buttons.
frosch <frosch@openttd.org>
parents: 17026
diff changeset
1407 this->sb->SetStepSize(this->sb->IsVertical() ? this->widget_h : this->widget_w);
16715
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1408 }
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1409
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1410 /**
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1411 * Assign a scrollbar to this matrix.
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1412 * @param sb The scrollbar to assign to us.
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1413 */
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1414 void NWidgetMatrix::SetScrollbar(Scrollbar *sb)
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1415 {
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1416 this->sb = sb;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1417 }
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1418
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1419 void NWidgetMatrix::SetupSmallestSize(Window *w, bool init_array)
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1420 {
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1421 assert(this->head != NULL);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1422 assert(this->head->next == NULL);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1423
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1424 if (this->index >= 0 && init_array) { // Fill w->nested_array[]
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1425 assert(w->nested_array_size > (uint)this->index);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1426 w->nested_array[this->index] = this;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1427 }
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1428
16718
05dacd546a70 (svn r21451) -Fix (r21449): make sure the matrix's child widget's size is updated with the right widget index
rubidium <rubidium@openttd.org>
parents: 16715
diff changeset
1429 /* Reset the widget number. */
05dacd546a70 (svn r21451) -Fix (r21449): make sure the matrix's child widget's size is updated with the right widget index
rubidium <rubidium@openttd.org>
parents: 16715
diff changeset
1430 SB(dynamic_cast<NWidgetCore *>(this->head)->index, 16, 16, 0);
16715
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1431 this->head->SetupSmallestSize(w, init_array);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1432
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1433 Dimension padding = {this->pip_pre + this->pip_post, this->pip_pre + this->pip_post};
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1434 Dimension size = {this->head->smallest_x + padding.width, this->head->smallest_y + padding.height};
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1435 Dimension fill = {0, 0};
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1436 Dimension resize = {this->pip_inter + this->head->smallest_x, this->pip_inter + this->head->smallest_y};
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1437
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1438 if (this->index >= 0) w->UpdateWidgetSize(this->index, &size, padding, &fill, &resize);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1439
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1440 this->smallest_x = size.width;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1441 this->smallest_y = size.height;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1442 this->fill_x = fill.width;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1443 this->fill_y = fill.height;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1444 this->resize_x = resize.width;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1445 this->resize_y = resize.height;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1446 }
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1447
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1448 void NWidgetMatrix::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1449 {
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1450 assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1451
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1452 this->pos_x = x;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1453 this->pos_y = y;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1454 this->current_x = given_width;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1455 this->current_y = given_height;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1456
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1457 /* Determine the size of the widgets, and the number of visible widgets on each of the axis. */
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1458 this->widget_w = this->head->smallest_x + this->pip_inter;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1459 this->widget_h = this->head->smallest_y + this->pip_inter;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1460
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1461 /* Account for the pip_inter is between widgets, so we need to account for that when
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1462 * the division assumes pip_inter is used for all widgets. */
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1463 this->widgets_x = CeilDiv(this->current_x - this->pip_pre - this->pip_post + this->pip_inter, this->widget_w);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1464 this->widgets_y = CeilDiv(this->current_y - this->pip_pre - this->pip_post + this->pip_inter, this->widget_h);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1465
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1466 /* When resizing, update the scrollbar's count. E.g. with a vertical
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1467 * scrollbar becoming wider or narrower means the amount of rows in
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1468 * the scrollbar becomes respectively smaller or higher. */
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1469 if (sizing == ST_RESIZE) {
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1470 this->SetCount(this->count);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1471 }
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1472 }
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1473
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1474 void NWidgetMatrix::FillNestedArray(NWidgetBase **array, uint length)
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1475 {
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1476 if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1477 NWidgetContainer::FillNestedArray(array, length);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1478 }
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1479
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1480 NWidgetCore *NWidgetMatrix::GetWidgetFromPos(int x, int y)
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1481 {
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1482 /* Falls outside of the matrix widget. */
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1483 if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return NULL;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1484
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1485 int start_x, start_y, base_offs_x, base_offs_y;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1486 this->GetScrollOffsets(start_x, start_y, base_offs_x, base_offs_y);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1487
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1488 /* Swap the x offset around for RTL, so it'll behave like LTR for RTL as well. */
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1489 bool rtl = _current_text_dir == TD_RTL;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1490 if (rtl) base_offs_x -= (this->widgets_x - 1) * this->widget_w;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1491
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1492 int widget_col = (x - base_offs_x - (int)this->pip_pre - (int)this->pos_x) / this->widget_w;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1493 int widget_row = (y - base_offs_y - (int)this->pip_pre - (int)this->pos_y) / this->widget_h;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1494
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1495 if (widget_row * this->widgets_x + widget_col >= this->count) return NULL;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1496
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1497 NWidgetCore *child = dynamic_cast<NWidgetCore *>(this->head);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1498 child->AssignSizePosition(ST_RESIZE,
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1499 this->pos_x + this->pip_pre + widget_col * this->widget_w + base_offs_x,
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1500 this->pos_y + this->pip_pre + widget_row * this->widget_h + base_offs_y,
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1501 child->smallest_x, child->smallest_y, rtl);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1502
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1503 /* "Undo" the RTL swap here to get the right widget index. */
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1504 if (rtl) widget_col = this->widgets_x - widget_col - 1;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1505 SB(child->index, 16, 16, (widget_row + start_y) * this->widgets_x + widget_col + start_x);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1506
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1507 return child->GetWidgetFromPos(x, y);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1508 }
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1509
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1510 /* virtual */ void NWidgetMatrix::Draw(const Window *w)
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1511 {
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1512 /* Fill the background. */
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1513 GfxFillRect(this->pos_x, this->pos_y, this->pos_x + this->current_x - 1, this->pos_y + this->current_y - 1, _colour_gradient[this->colour & 0xF][5]);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1514
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1515 /* Set up a clipping area for the previews. */
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1516 DrawPixelInfo tmp_dpi;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1517 if (!FillDrawPixelInfo(&tmp_dpi, this->pos_x + this->pip_pre, this->pos_y + this->pip_pre, this->current_x - this->pip_pre - this->pip_post, this->current_y - this->pip_pre - this->pip_post)) return;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1518 DrawPixelInfo *old_dpi = _cur_dpi;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1519 _cur_dpi = &tmp_dpi;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1520
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1521 /* Get the appropriate offsets so we can draw the right widgets. */
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1522 NWidgetCore *child = dynamic_cast<NWidgetCore *>(this->head);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1523 bool rtl = _current_text_dir == TD_RTL;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1524 int start_x, start_y, base_offs_x, base_offs_y;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1525 this->GetScrollOffsets(start_x, start_y, base_offs_x, base_offs_y);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1526
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1527 int offs_y = base_offs_y;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1528 for (int y = start_y; y < start_y + this->widgets_y + 1; y++, offs_y += this->widget_h) {
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1529 /* Are we within bounds? */
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1530 if (offs_y + child->smallest_y <= 0) continue;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1531 if (offs_y >= (int)this->current_y) break;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1532
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1533 /* We've passed our amount of widgets. */
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1534 if (y * this->widgets_x >= this->count) break;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1535
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1536 int offs_x = base_offs_x;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1537 for (int x = start_x; x < start_x + this->widgets_x + 1; x++, offs_x += rtl ? -this->widget_w : this->widget_w) {
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1538 /* Are we within bounds? */
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1539 if (offs_x + child->smallest_x <= 0) continue;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1540 if (offs_x >= (int)this->current_x) continue;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1541
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1542 /* Do we have this many widgets? */
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1543 int sub_wid = y * this->widgets_x + x;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1544 if (sub_wid >= this->count) break;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1545
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1546 child->AssignSizePosition(ST_RESIZE, offs_x, offs_y, child->smallest_x, child->smallest_y, rtl);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1547 child->SetLowered(this->clicked == sub_wid);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1548 SB(child->index, 16, 16, sub_wid);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1549 child->Draw(w);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1550 }
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1551 }
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1552
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1553 /* Restore the clipping area. */
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1554 _cur_dpi = old_dpi;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1555 }
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1556
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1557 /**
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1558 * Get the different offsets that are influenced by scrolling.
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1559 * @param [out] start_x The start position in columns,
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1560 * @param [out] start_y The start position in rows.
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1561 * @param [out] base_offs_x The base horizontal offset in pixels.
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1562 * @param [out] base_offs_y The base vertical offset in pixels.
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1563 */
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1564 void NWidgetMatrix::GetScrollOffsets(int &start_x, int &start_y, int &base_offs_x, int &base_offs_y)
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1565 {
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1566 base_offs_x = 0;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1567 base_offs_y = 0;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1568 start_x = 0;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1569 start_y = 0;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1570 if (this->sb != NULL) {
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1571 if (this->sb->IsVertical()) {
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1572 start_y = this->sb->GetPosition() / this->widget_h;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1573 base_offs_y = -this->sb->GetPosition() + start_y * this->widget_h;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1574 if (_current_text_dir == TD_RTL) base_offs_x = this->pip_pre + this->widget_w * (this->widgets_x - 1) - this->pip_inter;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1575 } else {
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1576 start_x = this->sb->GetPosition() / this->widget_w;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1577 if (_current_text_dir == TD_RTL) {
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1578 base_offs_x = this->sb->GetCapacity() + this->sb->GetPosition() - (start_x + 1) * this->widget_w + this->pip_inter - this->pip_post - this->pip_pre;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1579 } else {
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1580 base_offs_x = -this->sb->GetPosition() + start_x * this->widget_w;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1581 }
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1582 }
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1583 }
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1584 }
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
1585
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1586 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1587 * Constructor parent nested widgets.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1588 * @param tp Type of parent widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1589 * @param colour Colour of the parent widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1590 * @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
1591 * @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
1592 * vertical container will be inserted while adding the first
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1593 * child widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1594 */
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1595 NWidgetBackground::NWidgetBackground(WidgetType tp, Colours colour, int index, NWidgetPIPContainer *child) : NWidgetCore(tp, colour, 1, 1, 0x0, STR_NULL)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1596 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1597 assert(tp == WWT_PANEL || tp == WWT_INSET || tp == WWT_FRAME);
13698
3e426534b3bf (svn r18223) -Codechange: remove the requirement of having an index for background widgets
rubidium <rubidium@openttd.org>
parents: 13687
diff changeset
1598 if (index >= 0) this->SetIndex(index);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1599 this->child = child;
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 NWidgetBackground::~NWidgetBackground()
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1603 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1604 if (this->child != NULL) delete this->child;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1605 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1606
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1607 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1608 * Add a child to the parent.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1609 * @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
1610 *
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1611 * 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
1612 * 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
1613 */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1614 void NWidgetBackground::Add(NWidgetBase *nwid)
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 if (this->child == NULL) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1617 this->child = new NWidgetVertical();
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1618 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1619 this->child->Add(nwid);
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
11528
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1622 /**
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1623 * 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
1624 *
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1625 * @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
1626 * 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
1627 * @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
1628 * @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
1629 * 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
1630 * @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
1631 */
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1632 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
1633 {
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1634 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
1635 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
1636 }
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1637 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
1638 }
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
1639
12404
375cd4fb8ae3 (svn r16838) -Codechange: Fill Window::nested_array in SetupSmallestSize.
alberth <alberth@openttd.org>
parents: 12403
diff changeset
1640 void NWidgetBackground::SetupSmallestSize(Window *w, bool init_array)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1641 {
12404
375cd4fb8ae3 (svn r16838) -Codechange: Fill Window::nested_array in SetupSmallestSize.
alberth <alberth@openttd.org>
parents: 12403
diff changeset
1642 if (init_array && this->index >= 0) {
375cd4fb8ae3 (svn r16838) -Codechange: Fill Window::nested_array in SetupSmallestSize.
alberth <alberth@openttd.org>
parents: 12403
diff changeset
1643 assert(w->nested_array_size > (uint)this->index);
375cd4fb8ae3 (svn r16838) -Codechange: Fill Window::nested_array in SetupSmallestSize.
alberth <alberth@openttd.org>
parents: 12403
diff changeset
1644 w->nested_array[this->index] = this;
375cd4fb8ae3 (svn r16838) -Codechange: Fill Window::nested_array in SetupSmallestSize.
alberth <alberth@openttd.org>
parents: 12403
diff changeset
1645 }
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1646 if (this->child != NULL) {
12404
375cd4fb8ae3 (svn r16838) -Codechange: Fill Window::nested_array in SetupSmallestSize.
alberth <alberth@openttd.org>
parents: 12403
diff changeset
1647 this->child->SetupSmallestSize(w, init_array);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1648
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
1649 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
1650 this->smallest_y = this->child->smallest_y;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1651 this->fill_x = this->child->fill_x;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1652 this->fill_y = this->child->fill_y;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1653 this->resize_x = this->child->resize_x;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1654 this->resize_y = this->child->resize_y;
13543
2896c84f76d7 (svn r18065) -Codechange/Fix: account for the text in WWT_FRAMEs when determining the minimum width
rubidium <rubidium@openttd.org>
parents: 13542
diff changeset
1655
2896c84f76d7 (svn r18065) -Codechange/Fix: account for the text in WWT_FRAMEs when determining the minimum width
rubidium <rubidium@openttd.org>
parents: 13542
diff changeset
1656 /* Account for the size of the frame's text if that exists */
2896c84f76d7 (svn r18065) -Codechange/Fix: account for the text in WWT_FRAMEs when determining the minimum width
rubidium <rubidium@openttd.org>
parents: 13542
diff changeset
1657 if (w != NULL && this->type == WWT_FRAME) {
13670
2e7ff39e2ec6 (svn r18195) -Codechange: move the child padding calculation/handling to WWT_FRAME
rubidium <rubidium@openttd.org>
parents: 13665
diff changeset
1658 this->child->padding_left = WD_FRAMETEXT_LEFT;
2e7ff39e2ec6 (svn r18195) -Codechange: move the child padding calculation/handling to WWT_FRAME
rubidium <rubidium@openttd.org>
parents: 13665
diff changeset
1659 this->child->padding_right = WD_FRAMETEXT_RIGHT;
2e7ff39e2ec6 (svn r18195) -Codechange: move the child padding calculation/handling to WWT_FRAME
rubidium <rubidium@openttd.org>
parents: 13665
diff changeset
1660 this->child->padding_top = max((int)WD_FRAMETEXT_TOP, this->widget_data != STR_NULL ? FONT_HEIGHT_NORMAL + WD_FRAMETEXT_TOP / 2 : 0);
2e7ff39e2ec6 (svn r18195) -Codechange: move the child padding calculation/handling to WWT_FRAME
rubidium <rubidium@openttd.org>
parents: 13665
diff changeset
1661 this->child->padding_bottom = WD_FRAMETEXT_BOTTOM;
2e7ff39e2ec6 (svn r18195) -Codechange: move the child padding calculation/handling to WWT_FRAME
rubidium <rubidium@openttd.org>
parents: 13665
diff changeset
1662
2e7ff39e2ec6 (svn r18195) -Codechange: move the child padding calculation/handling to WWT_FRAME
rubidium <rubidium@openttd.org>
parents: 13665
diff changeset
1663 this->smallest_x += this->child->padding_left + this->child->padding_right;
2e7ff39e2ec6 (svn r18195) -Codechange: move the child padding calculation/handling to WWT_FRAME
rubidium <rubidium@openttd.org>
parents: 13665
diff changeset
1664 this->smallest_y += this->child->padding_top + this->child->padding_bottom;
2e7ff39e2ec6 (svn r18195) -Codechange: move the child padding calculation/handling to WWT_FRAME
rubidium <rubidium@openttd.org>
parents: 13665
diff changeset
1665
13543
2896c84f76d7 (svn r18065) -Codechange/Fix: account for the text in WWT_FRAMEs when determining the minimum width
rubidium <rubidium@openttd.org>
parents: 13542
diff changeset
1666 if (this->index >= 0) w->SetStringParameters(this->index);
2896c84f76d7 (svn r18065) -Codechange/Fix: account for the text in WWT_FRAMEs when determining the minimum width
rubidium <rubidium@openttd.org>
parents: 13542
diff changeset
1667 this->smallest_x = max(this->smallest_x, GetStringBoundingBox(this->widget_data).width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT);
2896c84f76d7 (svn r18065) -Codechange/Fix: account for the text in WWT_FRAMEs when determining the minimum width
rubidium <rubidium@openttd.org>
parents: 13542
diff changeset
1668 }
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
1669 } 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
1670 Dimension d = {this->min_x, this->min_y};
13705
8dee47e001b2 (svn r18230) -Codechange: Allow fill stepsize to be set from Window::UpdateWidgetSize().
alberth <alberth@openttd.org>
parents: 13704
diff changeset
1671 Dimension fill = {this->fill_x, this->fill_y};
12437
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
1672 Dimension resize = {this->resize_x, this->resize_y};
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
1673 if (w != NULL) { // A non-NULL window pointer acts as switch to turn dynamic widget size on.
12516
49534d3a6b57 (svn r16953) -Codechange: Use SetStringParameters() for simple parameterized strings.
alberth <alberth@openttd.org>
parents: 12493
diff changeset
1674 if (this->type == WWT_FRAME || this->type == WWT_INSET) {
49534d3a6b57 (svn r16953) -Codechange: Use SetStringParameters() for simple parameterized strings.
alberth <alberth@openttd.org>
parents: 12493
diff changeset
1675 if (this->index >= 0) w->SetStringParameters(this->index);
13543
2896c84f76d7 (svn r18065) -Codechange/Fix: account for the text in WWT_FRAMEs when determining the minimum width
rubidium <rubidium@openttd.org>
parents: 13542
diff changeset
1676 Dimension background = GetStringBoundingBox(this->widget_data);
2896c84f76d7 (svn r18065) -Codechange/Fix: account for the text in WWT_FRAMEs when determining the minimum width
rubidium <rubidium@openttd.org>
parents: 13542
diff changeset
1677 background.width += (this->type == WWT_FRAME) ? (WD_FRAMETEXT_LEFT + WD_FRAMERECT_RIGHT) : (WD_INSET_LEFT + WD_INSET_RIGHT);
2896c84f76d7 (svn r18065) -Codechange/Fix: account for the text in WWT_FRAMEs when determining the minimum width
rubidium <rubidium@openttd.org>
parents: 13542
diff changeset
1678 d = maxdim(d, background);
12516
49534d3a6b57 (svn r16953) -Codechange: Use SetStringParameters() for simple parameterized strings.
alberth <alberth@openttd.org>
parents: 12493
diff changeset
1679 }
12437
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
1680 if (this->index >= 0) {
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
1681 static const Dimension padding = {0, 0};
13705
8dee47e001b2 (svn r18230) -Codechange: Allow fill stepsize to be set from Window::UpdateWidgetSize().
alberth <alberth@openttd.org>
parents: 13704
diff changeset
1682 w->UpdateWidgetSize(this->index, &d, padding, &fill, &resize);
12437
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
1683 }
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
1684 }
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
1685 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
1686 this->smallest_y = d.height;
13705
8dee47e001b2 (svn r18230) -Codechange: Allow fill stepsize to be set from Window::UpdateWidgetSize().
alberth <alberth@openttd.org>
parents: 13704
diff changeset
1687 this->fill_x = fill.width;
8dee47e001b2 (svn r18230) -Codechange: Allow fill stepsize to be set from Window::UpdateWidgetSize().
alberth <alberth@openttd.org>
parents: 13704
diff changeset
1688 this->fill_y = fill.height;
12437
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
1689 this->resize_x = resize.width;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
1690 this->resize_y = resize.height;
11461
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 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1693
13676
e9a201c03e65 (svn r18201) -Codechange (r18092): No need anymore for initializing nested widgets for Widget* arrays.
alberth <alberth@openttd.org>
parents: 13670
diff changeset
1694 void NWidgetBackground::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1695 {
15215
c68f3c67204d (svn r19844) -Fix: Move NWidgetBase::StoreSizePosition() to an include file, and use proper inline macro.
alberth <alberth@openttd.org>
parents: 15214
diff changeset
1696 this->StoreSizePosition(sizing, x, y, given_width, given_height);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1697
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
1698 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
1699 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
1700 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
1701 uint height = given_height - this->child->padding_top - this->child->padding_bottom;
13676
e9a201c03e65 (svn r18201) -Codechange (r18092): No need anymore for initializing nested widgets for Widget* arrays.
alberth <alberth@openttd.org>
parents: 13670
diff changeset
1702 this->child->AssignSizePosition(sizing, x + x_offset, y + this->child->padding_top, width, height, 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
1703 }
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1704 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1705
13072
75bd67594af2 (svn r17572) -Codechange: Use the Window::GetWidget() function to access nested widgets through the nested_array.
alberth <alberth@openttd.org>
parents: 13034
diff changeset
1706 void NWidgetBackground::FillNestedArray(NWidgetBase **array, uint length)
12583
1fd1aea7e009 (svn r17023) -Revert (r16839): FillNestedArray() was less obsolete than anticipated.
alberth <alberth@openttd.org>
parents: 12577
diff changeset
1707 {
1fd1aea7e009 (svn r17023) -Revert (r16839): FillNestedArray() was less obsolete than anticipated.
alberth <alberth@openttd.org>
parents: 12577
diff changeset
1708 if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
1fd1aea7e009 (svn r17023) -Revert (r16839): FillNestedArray() was less obsolete than anticipated.
alberth <alberth@openttd.org>
parents: 12577
diff changeset
1709 if (this->child != NULL) this->child->FillNestedArray(array, length);
1fd1aea7e009 (svn r17023) -Revert (r16839): FillNestedArray() was less obsolete than anticipated.
alberth <alberth@openttd.org>
parents: 12577
diff changeset
1710 }
1fd1aea7e009 (svn r17023) -Revert (r16839): FillNestedArray() was less obsolete than anticipated.
alberth <alberth@openttd.org>
parents: 12577
diff changeset
1711
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1712 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
1713 {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1714 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
1715
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1716 Rect r;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1717 r.left = this->pos_x;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1718 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
1719 r.top = this->pos_y;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1720 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
1721
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1722 const DrawPixelInfo *dpi = _cur_dpi;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1723 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
1724
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1725 switch (this->type) {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1726 case WWT_PANEL:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1727 assert(this->widget_data == 0);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1728 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
1729 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1730
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1731 case WWT_FRAME:
12516
49534d3a6b57 (svn r16953) -Codechange: Use SetStringParameters() for simple parameterized strings.
alberth <alberth@openttd.org>
parents: 12493
diff changeset
1732 if (this->index >= 0) w->SetStringParameters(this->index);
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1733 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
1734 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1735
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1736 case WWT_INSET:
12516
49534d3a6b57 (svn r16953) -Codechange: Use SetStringParameters() for simple parameterized strings.
alberth <alberth@openttd.org>
parents: 12493
diff changeset
1737 if (this->index >= 0) w->SetStringParameters(this->index);
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1738 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
1739 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1740
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1741 default:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1742 NOT_REACHED();
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1743 }
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1744
12896
04374f6dcdc8 (svn r17388) -Codechange: Paint the background of background widgets before painting its children.
alberth <alberth@openttd.org>
parents: 12884
diff changeset
1745 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
1746 if (this->child != NULL) this->child->Draw(w);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1747
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1748 if (this->IsDisabled()) {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1749 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
1750 }
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1751 }
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
1752
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
1753 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
1754 {
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
1755 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
1756 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
1757 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
1758 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
1759 }
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
1760 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
1761 }
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
1762
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
1763 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
1764 {
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
1765 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
1766 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
1767 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
1768 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
1769 }
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
1770
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1771 NWidgetViewport::NWidgetViewport(int index) : NWidgetCore(NWID_VIEWPORT, INVALID_COLOUR, 1, 1, 0x0, STR_NULL)
12526
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1772 {
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1773 this->SetIndex(index);
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1774 }
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1775
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1776 void NWidgetViewport::SetupSmallestSize(Window *w, bool init_array)
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1777 {
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1778 if (init_array && this->index >= 0) {
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1779 assert(w->nested_array_size > (uint)this->index);
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1780 w->nested_array[this->index] = this;
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1781 }
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1782 this->smallest_x = this->min_x;
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1783 this->smallest_y = this->min_y;
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1784 }
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1785
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1786 void NWidgetViewport::Draw(const Window *w)
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1787 {
12897
323d905aa7b9 (svn r17389) -Codechange: Add support for shaded viewports.
alberth <alberth@openttd.org>
parents: 12896
diff changeset
1788 if (this->disp_flags & ND_NO_TRANSPARENCY) {
323d905aa7b9 (svn r17389) -Codechange: Add support for shaded viewports.
alberth <alberth@openttd.org>
parents: 12896
diff changeset
1789 TransparencyOptionBits to_backup = _transparency_opt;
16746
f67def58a51c (svn r21479) -Fix (r9563): Keep transparency for textual stuff in newspaper.
frosch <frosch@openttd.org>
parents: 16718
diff changeset
1790 _transparency_opt &= (1 << TO_SIGNS) | (1 << TO_LOADING); // Disable all transparency, except textual stuff
12897
323d905aa7b9 (svn r17389) -Codechange: Add support for shaded viewports.
alberth <alberth@openttd.org>
parents: 12896
diff changeset
1791 w->DrawViewport();
323d905aa7b9 (svn r17389) -Codechange: Add support for shaded viewports.
alberth <alberth@openttd.org>
parents: 12896
diff changeset
1792 _transparency_opt = to_backup;
323d905aa7b9 (svn r17389) -Codechange: Add support for shaded viewports.
alberth <alberth@openttd.org>
parents: 12896
diff changeset
1793 } else {
323d905aa7b9 (svn r17389) -Codechange: Add support for shaded viewports.
alberth <alberth@openttd.org>
parents: 12896
diff changeset
1794 w->DrawViewport();
323d905aa7b9 (svn r17389) -Codechange: Add support for shaded viewports.
alberth <alberth@openttd.org>
parents: 12896
diff changeset
1795 }
323d905aa7b9 (svn r17389) -Codechange: Add support for shaded viewports.
alberth <alberth@openttd.org>
parents: 12896
diff changeset
1796
323d905aa7b9 (svn r17389) -Codechange: Add support for shaded viewports.
alberth <alberth@openttd.org>
parents: 12896
diff changeset
1797 /* Optionally shade the viewport. */
323d905aa7b9 (svn r17389) -Codechange: Add support for shaded viewports.
alberth <alberth@openttd.org>
parents: 12896
diff changeset
1798 if (this->disp_flags & (ND_SHADE_GREY | ND_SHADE_DIMMED)) {
323d905aa7b9 (svn r17389) -Codechange: Add support for shaded viewports.
alberth <alberth@openttd.org>
parents: 12896
diff changeset
1799 GfxFillRect(this->pos_x, this->pos_y, this->pos_x + this->current_x - 1, this->pos_y + this->current_y - 1,
323d905aa7b9 (svn r17389) -Codechange: Add support for shaded viewports.
alberth <alberth@openttd.org>
parents: 12896
diff changeset
1800 (this->disp_flags & ND_SHADE_DIMMED) ? PALETTE_TO_TRANSPARENT : PALETTE_TO_STRUCT_GREY, FILLRECT_RECOLOUR);
323d905aa7b9 (svn r17389) -Codechange: Add support for shaded viewports.
alberth <alberth@openttd.org>
parents: 12896
diff changeset
1801 }
12526
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1802 }
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1803
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1804 /**
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1805 * Initialize the viewport of the window.
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1806 * @param w Window owning the viewport.
16309
19dba04d7fc5 (svn r21017) -Doc: Small fixes (by Krille).
alberth <alberth@openttd.org>
parents: 16221
diff changeset
1807 * @param follow_flags Type of viewport, see #InitializeWindowViewport().
12526
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1808 * @param zoom Zoom level.
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1809 */
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1810 void NWidgetViewport::InitializeViewport(Window *w, uint32 follow_flags, ZoomLevel zoom)
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1811 {
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1812 InitializeWindowViewport(w, this->pos_x, this->pos_y, this->current_x, this->current_y, follow_flags, zoom);
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1813 }
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1814
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1815 /**
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1816 * Update the position and size of the viewport (after eg a resize).
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1817 * @param w Window owning the viewport.
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1818 */
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1819 void NWidgetViewport::UpdateViewportCoordinates(Window *w)
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1820 {
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1821 ViewPort *vp = w->viewport;
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1822 if (vp != NULL) {
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1823 vp->left = w->left + this->pos_x;
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1824 vp->top = w->top + this->pos_y;
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1825 vp->width = this->current_x;
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1826 vp->height = this->current_y;
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1827
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1828 vp->virtual_width = ScaleByZoom(vp->width, vp->zoom);
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1829 vp->virtual_height = ScaleByZoom(vp->height, vp->zoom);
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1830 }
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1831 }
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
1832
15782
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1833 /**
15784
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1834 * Compute the row of a scrolled widget that a user clicked in.
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1835 * @param clickpos Vertical position of the mouse click (without taking scrolling into account).
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1836 * @param widget Widget number of the widget clicked in.
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1837 * @param padding Amount of empty space between the widget edge and the top of the first row. Default value is \c 0.
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1838 * @param line_height Height of a single row. A negative value means using the vertical resize step of the widget.
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1839 * @return Row number clicked at. If clicked at a wrong position, #INT_MAX is returned.
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1840 */
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1841 int Scrollbar::GetScrolledRowFromWidget(int clickpos, const Window * const w, int widget, int padding, int line_height) const
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1842 {
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1843 uint pos = w->GetRowFromWidget(clickpos, widget, padding, line_height);
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1844 if (pos != INT_MAX) pos += this->GetPosition();
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1845 return (pos >= this->GetCount()) ? INT_MAX : pos;
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1846 }
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1847
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1848 /**
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1849 * Set capacity of visible elements from the size and resize properties of a widget.
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1850 * @param w Window.
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1851 * @param widget Widget with size and resize properties.
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1852 * @param padding Padding to subtract from the size.
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1853 * @note Updates the position if needed.
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1854 */
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1855 void Scrollbar::SetCapacityFromWidget(Window *w, int widget, int padding)
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1856 {
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1857 NWidgetBase *nwid = w->GetWidget<NWidgetBase>(widget);
16714
fdb38185fbea (svn r21447) -Add: accessor function to get the direction of a scrollbar
rubidium <rubidium@openttd.org>
parents: 16441
diff changeset
1858 if (this->IsVertical()) {
15784
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1859 this->SetCapacity(((int)nwid->current_y - padding) / (int)nwid->resize_y);
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1860 } else {
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1861 this->SetCapacity(((int)nwid->current_x - padding) / (int)nwid->resize_x);
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1862 }
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1863 }
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1864
93083c350208 (svn r20458) -Codechange: Move Scrollbar from window.cpp to widget.cpp
frosch <frosch@openttd.org>
parents: 15783
diff changeset
1865 /**
15782
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1866 * Scrollbar widget.
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1867 * @param tp Scrollbar type. (horizontal/vertical)
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1868 * @param colour Colour of the scrollbar.
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1869 * @param index Index in the widget array used by the window system.
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1870 */
15787
6c4bec3b8401 (svn r20461) -Codechange: Replace WWT_HSCROLLBAR, WWT_SCROLLBAR and WWT_SCROLL2BAR with NWID_HSCROLLBAR and NWID_VSCROLLBAR.
frosch <frosch@openttd.org>
parents: 15786
diff changeset
1871 NWidgetScrollbar::NWidgetScrollbar(WidgetType tp, Colours colour, int index) : NWidgetCore(tp, colour, 1, 1, 0x0, STR_NULL), Scrollbar(tp != NWID_HSCROLLBAR)
15782
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1872 {
15787
6c4bec3b8401 (svn r20461) -Codechange: Replace WWT_HSCROLLBAR, WWT_SCROLLBAR and WWT_SCROLL2BAR with NWID_HSCROLLBAR and NWID_VSCROLLBAR.
frosch <frosch@openttd.org>
parents: 15786
diff changeset
1873 assert(tp == NWID_HSCROLLBAR || tp == NWID_VSCROLLBAR);
15782
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1874 this->SetIndex(index);
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1875
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1876 switch (this->type) {
15787
6c4bec3b8401 (svn r20461) -Codechange: Replace WWT_HSCROLLBAR, WWT_SCROLLBAR and WWT_SCROLL2BAR with NWID_HSCROLLBAR and NWID_VSCROLLBAR.
frosch <frosch@openttd.org>
parents: 15786
diff changeset
1877 case NWID_HSCROLLBAR:
15903
7585966382b1 (svn r20587) -Codechange (r20456)[FS#4035]: Revert to scrollbars without minimal size to simplify window setup.
frosch <frosch@openttd.org>
parents: 15894
diff changeset
1878 this->SetMinimalSize(0, WD_HSCROLLBAR_HEIGHT);
15782
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1879 this->SetResize(1, 0);
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1880 this->SetFill(1, 0);
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1881 this->SetDataTip(0x0, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1882 break;
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1883
15787
6c4bec3b8401 (svn r20461) -Codechange: Replace WWT_HSCROLLBAR, WWT_SCROLLBAR and WWT_SCROLL2BAR with NWID_HSCROLLBAR and NWID_VSCROLLBAR.
frosch <frosch@openttd.org>
parents: 15786
diff changeset
1884 case NWID_VSCROLLBAR:
15903
7585966382b1 (svn r20587) -Codechange (r20456)[FS#4035]: Revert to scrollbars without minimal size to simplify window setup.
frosch <frosch@openttd.org>
parents: 15894
diff changeset
1885 this->SetMinimalSize(WD_VSCROLLBAR_WIDTH, 0);
15782
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1886 this->SetResize(0, 1);
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1887 this->SetFill(0, 1);
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1888 this->SetDataTip(0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST);
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1889 break;
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1890
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1891 default: NOT_REACHED();
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1892 }
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1893 }
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1894
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1895 void NWidgetScrollbar::SetupSmallestSize(Window *w, bool init_array)
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1896 {
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1897 if (init_array && this->index >= 0) {
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1898 assert(w->nested_array_size > (uint)this->index);
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1899 w->nested_array[this->index] = this;
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1900 }
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1901 this->smallest_x = this->min_x;
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1902 this->smallest_y = this->min_y;
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1903 }
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1904
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1905 void NWidgetScrollbar::Draw(const Window *w)
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1906 {
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1907 if (this->current_x == 0 || this->current_y == 0) return;
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1908
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1909 Rect r;
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1910 r.left = this->pos_x;
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1911 r.right = this->pos_x + this->current_x - 1;
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1912 r.top = this->pos_y;
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1913 r.bottom = this->pos_y + this->current_y - 1;
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1914
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1915 const DrawPixelInfo *dpi = _cur_dpi;
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1916 if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top) return;
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1917
15786
04cd1d957b49 (svn r20460) -Codechange: Remove WF_SCROLL window flags and store the state directly in the scrollbar widget instead.
frosch <frosch@openttd.org>
parents: 15785
diff changeset
1918 bool up_lowered = HasBit(this->disp_flags, NDB_SCROLLBAR_UP);
04cd1d957b49 (svn r20460) -Codechange: Remove WF_SCROLL window flags and store the state directly in the scrollbar widget instead.
frosch <frosch@openttd.org>
parents: 15785
diff changeset
1919 bool down_lowered = HasBit(this->disp_flags, NDB_SCROLLBAR_DOWN);
16221
4f317dcb219a (svn r20922) -Fix [FS#4071]: accidentally moving the mouse of the scrollbar arrows while pressing it clicks the button next to the arrow
rubidium <rubidium@openttd.org>
parents: 15903
diff changeset
1920 bool middle_lowered = !(this->disp_flags & ND_SCROLLBAR_BTN) && w->scrolling_scrollbar == this->index;
15782
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1921
15787
6c4bec3b8401 (svn r20461) -Codechange: Replace WWT_HSCROLLBAR, WWT_SCROLLBAR and WWT_SCROLL2BAR with NWID_HSCROLLBAR and NWID_VSCROLLBAR.
frosch <frosch@openttd.org>
parents: 15786
diff changeset
1922 if (this->type == NWID_HSCROLLBAR) {
15786
04cd1d957b49 (svn r20460) -Codechange: Remove WF_SCROLL window flags and store the state directly in the scrollbar widget instead.
frosch <frosch@openttd.org>
parents: 15785
diff changeset
1923 DrawHorizontalScrollbar(r, this->colour, up_lowered, middle_lowered, down_lowered, this);
04cd1d957b49 (svn r20460) -Codechange: Remove WF_SCROLL window flags and store the state directly in the scrollbar widget instead.
frosch <frosch@openttd.org>
parents: 15785
diff changeset
1924 } else {
04cd1d957b49 (svn r20460) -Codechange: Remove WF_SCROLL window flags and store the state directly in the scrollbar widget instead.
frosch <frosch@openttd.org>
parents: 15785
diff changeset
1925 DrawVerticalScrollbar(r, this->colour, up_lowered, middle_lowered, down_lowered, this);
15782
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1926 }
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1927
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1928 if (this->IsDisabled()) {
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1929 GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, _colour_gradient[this->colour & 0xF][2], FILLRECT_CHECKER);
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1930 }
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1931 }
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
1932
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
1933 /** 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
1934 /* 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
1935 {
14040
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
1936 shadebox_dimension.width = shadebox_dimension.height = 0;
15080
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
1937 debugbox_dimension.width = debugbox_dimension.height = 0;
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
1938 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
1939 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
1940 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
1941 }
62259c3dc887 (svn r16798) -Fix [FS#3016]: Added several new widget distances for better widget size computations.
alberth <alberth@openttd.org>
parents: 12371
diff changeset
1942
14040
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
1943 Dimension NWidgetLeaf::shadebox_dimension = {0, 0};
15080
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
1944 Dimension NWidgetLeaf::debugbox_dimension = {0, 0};
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
1945 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
1946 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
1947 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
1948
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1949 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1950 * 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
1951 * @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
1952 * @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
1953 * @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
1954 * @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
1955 * @param tip Tooltip of the widget.
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1956 */
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1957 NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint16 data, StringID tip) : NWidgetCore(tp, colour, 1, 1, data, tip)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1958 {
15080
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
1959 assert(index >= 0 || tp == WWT_LABEL || tp == WWT_TEXT || tp == WWT_CAPTION || tp == WWT_RESIZEBOX || tp == WWT_SHADEBOX || tp == WWT_DEBUGBOX || tp == WWT_STICKYBOX || tp == WWT_CLOSEBOX);
13742
a0aa80f5d2d2 (svn r18267) -Codechange: make the music window big font aware
rubidium <rubidium@openttd.org>
parents: 13707
diff changeset
1960 if (index >= 0) this->SetIndex(index);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1961 this->SetMinimalSize(0, 0);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1962 this->SetResize(0, 0);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1963
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1964 switch (tp) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1965 case WWT_EMPTY:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1966 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1967
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1968 case WWT_PUSHBTN:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1969 case WWT_IMGBTN:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1970 case WWT_PUSHIMGBTN:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1971 case WWT_IMGBTN_2:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1972 case WWT_TEXTBTN:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1973 case WWT_PUSHTXTBTN:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1974 case WWT_TEXTBTN_2:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1975 case WWT_LABEL:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1976 case WWT_TEXT:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1977 case WWT_MATRIX:
13664
ce197674184d (svn r18188) -Codechange: s/NWID_BUTTON_DRPDOWN/NWID_BUTTON_DROPDOWN/g
rubidium <rubidium@openttd.org>
parents: 13662
diff changeset
1978 case NWID_BUTTON_DROPDOWN:
15795
c9cf5fe6d6a1 (svn r20470) -Codechange: Make arrow buttons lower and raise like other buttons when clicked.
frosch <frosch@openttd.org>
parents: 15788
diff changeset
1979 case WWT_ARROWBTN:
c9cf5fe6d6a1 (svn r20470) -Codechange: Make arrow buttons lower and raise like other buttons when clicked.
frosch <frosch@openttd.org>
parents: 15788
diff changeset
1980 case WWT_PUSHARROWBTN:
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1981 this->SetFill(0, 0);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1982 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1983
15727
e7ce9e72e50f (svn r20394) -Fix [FS#4010]: make the default minimum width for editboxes 10 pixels
yexo <yexo@openttd.org>
parents: 15620
diff changeset
1984 case WWT_EDITBOX:
e7ce9e72e50f (svn r20394) -Fix [FS#4010]: make the default minimum width for editboxes 10 pixels
yexo <yexo@openttd.org>
parents: 15620
diff changeset
1985 this->SetMinimalSize(10, 0);
e7ce9e72e50f (svn r20394) -Fix [FS#4010]: make the default minimum width for editboxes 10 pixels
yexo <yexo@openttd.org>
parents: 15620
diff changeset
1986 this->SetFill(0, 0);
e7ce9e72e50f (svn r20394) -Fix [FS#4010]: make the default minimum width for editboxes 10 pixels
yexo <yexo@openttd.org>
parents: 15620
diff changeset
1987 break;
e7ce9e72e50f (svn r20394) -Fix [FS#4010]: make the default minimum width for editboxes 10 pixels
yexo <yexo@openttd.org>
parents: 15620
diff changeset
1988
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1989 case WWT_CAPTION:
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1990 this->SetFill(1, 0);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1991 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
1992 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
1993 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
1994 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1995
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
1996 case WWT_STICKYBOX:
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
1997 this->SetFill(0, 0);
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
1998 this->SetMinimalSize(WD_STICKYBOX_WIDTH, 14);
12632
e41943276802 (svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents: 12583
diff changeset
1999 this->SetDataTip(STR_NULL, STR_TOOLTIP_STICKY);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2000 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2001
14040
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
2002 case WWT_SHADEBOX:
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
2003 this->SetFill(0, 0);
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
2004 this->SetMinimalSize(WD_SHADEBOX_TOP, 14);
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
2005 this->SetDataTip(STR_NULL, STR_TOOLTIP_SHADE);
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
2006 break;
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
2007
15080
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2008 case WWT_DEBUGBOX:
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2009 this->SetFill(0, 0);
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2010 this->SetMinimalSize(WD_DEBUGBOX_TOP, 14);
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2011 this->SetDataTip(STR_NULL, STR_TOOLTIP_DEBUG);
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2012 break;
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2013
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2014 case WWT_RESIZEBOX:
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
2015 this->SetFill(0, 0);
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
2016 this->SetMinimalSize(WD_RESIZEBOX_WIDTH, 12);
12632
e41943276802 (svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents: 12583
diff changeset
2017 this->SetDataTip(STR_NULL, STR_TOOLTIP_RESIZE);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2018 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2019
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2020 case WWT_CLOSEBOX:
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
2021 this->SetFill(0, 0);
12195
ee5c5c8f0557 (svn r16609) -Codechange: Introduction of widget sizes and offsets used while drawing.
alberth <alberth@openttd.org>
parents: 12159
diff changeset
2022 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
2023 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
2024 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2025
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2026 case WWT_DROPDOWN:
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
2027 this->SetFill(0, 0);
12195
ee5c5c8f0557 (svn r16609) -Codechange: Introduction of widget sizes and offsets used while drawing.
alberth <alberth@openttd.org>
parents: 12159
diff changeset
2028 this->min_y = WD_DROPDOWN_HEIGHT;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2029 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2030
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2031 default:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2032 NOT_REACHED();
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2033 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2034 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2035
12404
375cd4fb8ae3 (svn r16838) -Codechange: Fill Window::nested_array in SetupSmallestSize.
alberth <alberth@openttd.org>
parents: 12403
diff changeset
2036 void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array)
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
2037 {
12437
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2038 if (this->index >= 0 && init_array) { // Fill w->nested_array[]
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2039 assert(w->nested_array_size > (uint)this->index);
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2040 w->nested_array[this->index] = this;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2041 }
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
2042
12437
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2043 Dimension size = {this->min_x, this->min_y};
13705
8dee47e001b2 (svn r18230) -Codechange: Allow fill stepsize to be set from Window::UpdateWidgetSize().
alberth <alberth@openttd.org>
parents: 13704
diff changeset
2044 Dimension fill = {this->fill_x, this->fill_y};
12437
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2045 Dimension resize = {this->resize_x, this->resize_y};
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2046 /* Get padding, and update size with the real content size if appropriate. */
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2047 const Dimension *padding = NULL;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2048 switch (this->type) {
15782
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
2049 case WWT_EMPTY: {
12437
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2050 static const Dimension extra = {0, 0};
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2051 padding = &extra;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2052 break;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2053 }
12577
7d27f0e5a0cd (svn r17017) -Fix (r17008): Setup padding for WWT_MATRIX.
alberth <alberth@openttd.org>
parents: 12526
diff changeset
2054 case WWT_MATRIX: {
7d27f0e5a0cd (svn r17017) -Fix (r17008): Setup padding for WWT_MATRIX.
alberth <alberth@openttd.org>
parents: 12526
diff changeset
2055 static const Dimension extra = {WD_MATRIX_LEFT + WD_MATRIX_RIGHT, WD_MATRIX_TOP + WD_MATRIX_BOTTOM};
7d27f0e5a0cd (svn r17017) -Fix (r17008): Setup padding for WWT_MATRIX.
alberth <alberth@openttd.org>
parents: 12526
diff changeset
2056 padding = &extra;
7d27f0e5a0cd (svn r17017) -Fix (r17008): Setup padding for WWT_MATRIX.
alberth <alberth@openttd.org>
parents: 12526
diff changeset
2057 break;
7d27f0e5a0cd (svn r17017) -Fix (r17008): Setup padding for WWT_MATRIX.
alberth <alberth@openttd.org>
parents: 12526
diff changeset
2058 }
14040
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
2059 case WWT_SHADEBOX: {
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
2060 static const Dimension extra = {WD_SHADEBOX_LEFT + WD_SHADEBOX_RIGHT, WD_SHADEBOX_TOP + WD_SHADEBOX_BOTTOM};
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
2061 padding = &extra;
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
2062 if (NWidgetLeaf::shadebox_dimension.width == 0) {
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
2063 NWidgetLeaf::shadebox_dimension = maxdim(GetSpriteSize(SPR_WINDOW_SHADE), GetSpriteSize(SPR_WINDOW_UNSHADE));
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
2064 NWidgetLeaf::shadebox_dimension.width += extra.width;
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
2065 NWidgetLeaf::shadebox_dimension.height += extra.height;
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
2066 }
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
2067 size = maxdim(size, NWidgetLeaf::shadebox_dimension);
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
2068 break;
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
2069 }
15080
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2070 case WWT_DEBUGBOX:
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2071 if (_settings_client.gui.newgrf_developer_tools && w->IsNewGRFInspectable()) {
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2072 static const Dimension extra = {WD_DEBUGBOX_LEFT + WD_DEBUGBOX_RIGHT, WD_DEBUGBOX_TOP + WD_DEBUGBOX_BOTTOM};
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2073 padding = &extra;
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2074 if (NWidgetLeaf::debugbox_dimension.width == 0) {
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2075 NWidgetLeaf::debugbox_dimension = GetSpriteSize(SPR_WINDOW_DEBUG);
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2076 NWidgetLeaf::debugbox_dimension.width += extra.width;
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2077 NWidgetLeaf::debugbox_dimension.height += extra.height;
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2078 }
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2079 size = maxdim(size, NWidgetLeaf::debugbox_dimension);
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2080 } else {
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2081 /* If the setting is disabled we don't want to see it! */
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2082 size.width = 0;
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2083 fill.width = 0;
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2084 resize.width = 0;
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2085 }
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2086 break;
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2087
12437
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2088 case WWT_STICKYBOX: {
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2089 static const Dimension extra = {WD_STICKYBOX_LEFT + WD_STICKYBOX_RIGHT, WD_STICKYBOX_TOP + WD_STICKYBOX_BOTTOM};
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2090 padding = &extra;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2091 if (NWidgetLeaf::stickybox_dimension.width == 0) {
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2092 NWidgetLeaf::stickybox_dimension = maxdim(GetSpriteSize(SPR_PIN_UP), GetSpriteSize(SPR_PIN_DOWN));
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2093 NWidgetLeaf::stickybox_dimension.width += extra.width;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2094 NWidgetLeaf::stickybox_dimension.height += extra.height;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2095 }
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2096 size = maxdim(size, NWidgetLeaf::stickybox_dimension);
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2097 break;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2098 }
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2099 case WWT_RESIZEBOX: {
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2100 static const Dimension extra = {WD_RESIZEBOX_LEFT + WD_RESIZEBOX_RIGHT, WD_RESIZEBOX_TOP + WD_RESIZEBOX_BOTTOM};
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2101 padding = &extra;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2102 if (NWidgetLeaf::resizebox_dimension.width == 0) {
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2103 NWidgetLeaf::resizebox_dimension = maxdim(GetSpriteSize(SPR_WINDOW_RESIZE_LEFT), GetSpriteSize(SPR_WINDOW_RESIZE_RIGHT));
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2104 NWidgetLeaf::resizebox_dimension.width += extra.width;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2105 NWidgetLeaf::resizebox_dimension.height += extra.height;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2106 }
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2107 size = maxdim(size, NWidgetLeaf::resizebox_dimension);
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2108 break;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2109 }
13576
7d9d6446b83f (svn r18099) -Codechange: scale the edit boxes to the fontsize
rubidium <rubidium@openttd.org>
parents: 13570
diff changeset
2110 case WWT_EDITBOX:
7d9d6446b83f (svn r18099) -Codechange: scale the edit boxes to the fontsize
rubidium <rubidium@openttd.org>
parents: 13570
diff changeset
2111 size.height = max(size.height, GetStringBoundingBox("_").height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
15579
5f128be91f59 (svn r20239) -Doc: Give a common name to all fall throughs (FALL THROUGH).
terkhen <terkhen@openttd.org>
parents: 15400
diff changeset
2112 /* FALL THROUGH */
13576
7d9d6446b83f (svn r18099) -Codechange: scale the edit boxes to the fontsize
rubidium <rubidium@openttd.org>
parents: 13570
diff changeset
2113 case WWT_PUSHBTN: {
12437
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2114 static const Dimension extra = {WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM};
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2115 padding = &extra;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2116 break;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2117 }
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2118 case WWT_IMGBTN:
13514
b70924cfd627 (svn r18033) -Codechange: make the padding for IMGBTN_2 the same as for IMGBTN; the image doesn't move, so the extra space at the right and bottom aren't needed
rubidium <rubidium@openttd.org>
parents: 13509
diff changeset
2119 case WWT_IMGBTN_2:
12437
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2120 case WWT_PUSHIMGBTN: {
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2121 static const Dimension extra = {WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT, WD_IMGBTN_TOP + WD_IMGBTN_BOTTOM};
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2122 padding = &extra;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2123 Dimension d2 = GetSpriteSize(this->widget_data);
13514
b70924cfd627 (svn r18033) -Codechange: make the padding for IMGBTN_2 the same as for IMGBTN; the image doesn't move, so the extra space at the right and bottom aren't needed
rubidium <rubidium@openttd.org>
parents: 13509
diff changeset
2124 if (this->type == WWT_IMGBTN_2) d2 = maxdim(d2, GetSpriteSize(this->widget_data + 1));
12437
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2125 d2.width += extra.width;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2126 d2.height += extra.height;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2127 size = maxdim(size, d2);
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2128 break;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2129 }
15795
c9cf5fe6d6a1 (svn r20470) -Codechange: Make arrow buttons lower and raise like other buttons when clicked.
frosch <frosch@openttd.org>
parents: 15788
diff changeset
2130 case WWT_ARROWBTN:
c9cf5fe6d6a1 (svn r20470) -Codechange: Make arrow buttons lower and raise like other buttons when clicked.
frosch <frosch@openttd.org>
parents: 15788
diff changeset
2131 case WWT_PUSHARROWBTN: {
13662
6182cd79cc26 (svn r18186) -Add: a widgets for left/right arrows with the ability to turn themselves around when a RTL language is loaded
rubidium <rubidium@openttd.org>
parents: 13644
diff changeset
2132 static const Dimension extra = {WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT, WD_IMGBTN_TOP + WD_IMGBTN_BOTTOM};
6182cd79cc26 (svn r18186) -Add: a widgets for left/right arrows with the ability to turn themselves around when a RTL language is loaded
rubidium <rubidium@openttd.org>
parents: 13644
diff changeset
2133 padding = &extra;
6182cd79cc26 (svn r18186) -Add: a widgets for left/right arrows with the ability to turn themselves around when a RTL language is loaded
rubidium <rubidium@openttd.org>
parents: 13644
diff changeset
2134 Dimension d2 = maxdim(GetSpriteSize(SPR_ARROW_LEFT), GetSpriteSize(SPR_ARROW_RIGHT));
6182cd79cc26 (svn r18186) -Add: a widgets for left/right arrows with the ability to turn themselves around when a RTL language is loaded
rubidium <rubidium@openttd.org>
parents: 13644
diff changeset
2135 d2.width += extra.width;
6182cd79cc26 (svn r18186) -Add: a widgets for left/right arrows with the ability to turn themselves around when a RTL language is loaded
rubidium <rubidium@openttd.org>
parents: 13644
diff changeset
2136 d2.height += extra.height;
6182cd79cc26 (svn r18186) -Add: a widgets for left/right arrows with the ability to turn themselves around when a RTL language is loaded
rubidium <rubidium@openttd.org>
parents: 13644
diff changeset
2137 size = maxdim(size, d2);
6182cd79cc26 (svn r18186) -Add: a widgets for left/right arrows with the ability to turn themselves around when a RTL language is loaded
rubidium <rubidium@openttd.org>
parents: 13644
diff changeset
2138 break;
6182cd79cc26 (svn r18186) -Add: a widgets for left/right arrows with the ability to turn themselves around when a RTL language is loaded
rubidium <rubidium@openttd.org>
parents: 13644
diff changeset
2139 }
6182cd79cc26 (svn r18186) -Add: a widgets for left/right arrows with the ability to turn themselves around when a RTL language is loaded
rubidium <rubidium@openttd.org>
parents: 13644
diff changeset
2140
12437
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2141 case WWT_CLOSEBOX: {
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2142 static const Dimension extra = {WD_CLOSEBOX_LEFT + WD_CLOSEBOX_RIGHT, WD_CLOSEBOX_TOP + WD_CLOSEBOX_BOTTOM};
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2143 padding = &extra;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2144 if (NWidgetLeaf::closebox_dimension.width == 0) {
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2145 NWidgetLeaf::closebox_dimension = maxdim(GetStringBoundingBox(STR_BLACK_CROSS), GetStringBoundingBox(STR_SILVER_CROSS));
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2146 NWidgetLeaf::closebox_dimension.width += extra.width;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2147 NWidgetLeaf::closebox_dimension.height += extra.height;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2148 }
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2149 size = maxdim(size, NWidgetLeaf::closebox_dimension);
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2150 break;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2151 }
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2152 case WWT_TEXTBTN:
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2153 case WWT_PUSHTXTBTN:
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2154 case WWT_TEXTBTN_2: {
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2155 static const Dimension extra = {WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM};
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2156 padding = &extra;
12516
49534d3a6b57 (svn r16953) -Codechange: Use SetStringParameters() for simple parameterized strings.
alberth <alberth@openttd.org>
parents: 12493
diff changeset
2157 if (this->index >= 0) w->SetStringParameters(this->index);
12437
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2158 Dimension d2 = GetStringBoundingBox(this->widget_data);
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2159 d2.width += extra.width;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2160 d2.height += extra.height;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2161 size = maxdim(size, d2);
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2162 break;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2163 }
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2164 case WWT_LABEL:
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2165 case WWT_TEXT: {
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2166 static const Dimension extra = {0, 0};
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2167 padding = &extra;
12516
49534d3a6b57 (svn r16953) -Codechange: Use SetStringParameters() for simple parameterized strings.
alberth <alberth@openttd.org>
parents: 12493
diff changeset
2168 if (this->index >= 0) w->SetStringParameters(this->index);
12437
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2169 size = maxdim(size, GetStringBoundingBox(this->widget_data));
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2170 break;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2171 }
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2172 case WWT_CAPTION: {
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2173 static const Dimension extra = {WD_CAPTIONTEXT_LEFT + WD_CAPTIONTEXT_RIGHT, WD_CAPTIONTEXT_TOP + WD_CAPTIONTEXT_BOTTOM};
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2174 padding = &extra;
12516
49534d3a6b57 (svn r16953) -Codechange: Use SetStringParameters() for simple parameterized strings.
alberth <alberth@openttd.org>
parents: 12493
diff changeset
2175 if (this->index >= 0) w->SetStringParameters(this->index);
12437
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2176 Dimension d2 = GetStringBoundingBox(this->widget_data);
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2177 d2.width += extra.width;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2178 d2.height += extra.height;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2179 size = maxdim(size, d2);
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2180 break;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2181 }
13075
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
2182 case WWT_DROPDOWN:
13664
ce197674184d (svn r18188) -Codechange: s/NWID_BUTTON_DRPDOWN/NWID_BUTTON_DROPDOWN/g
rubidium <rubidium@openttd.org>
parents: 13662
diff changeset
2183 case NWID_BUTTON_DROPDOWN: {
12437
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2184 static const Dimension extra = {WD_DROPDOWNTEXT_LEFT + WD_DROPDOWNTEXT_RIGHT, WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM};
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2185 padding = &extra;
12516
49534d3a6b57 (svn r16953) -Codechange: Use SetStringParameters() for simple parameterized strings.
alberth <alberth@openttd.org>
parents: 12493
diff changeset
2186 if (this->index >= 0) w->SetStringParameters(this->index);
12437
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2187 Dimension d2 = GetStringBoundingBox(this->widget_data);
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2188 d2.width += extra.width;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2189 d2.height += extra.height;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2190 size = maxdim(size, d2);
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2191 break;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2192 }
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2193 default:
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2194 NOT_REACHED();
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2195 }
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
2196
13705
8dee47e001b2 (svn r18230) -Codechange: Allow fill stepsize to be set from Window::UpdateWidgetSize().
alberth <alberth@openttd.org>
parents: 13704
diff changeset
2197 if (this->index >= 0) w->UpdateWidgetSize(this->index, &size, *padding, &fill, &resize);
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
2198
12437
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2199 this->smallest_x = size.width;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2200 this->smallest_y = size.height;
13705
8dee47e001b2 (svn r18230) -Codechange: Allow fill stepsize to be set from Window::UpdateWidgetSize().
alberth <alberth@openttd.org>
parents: 13704
diff changeset
2201 this->fill_x = fill.width;
8dee47e001b2 (svn r18230) -Codechange: Allow fill stepsize to be set from Window::UpdateWidgetSize().
alberth <alberth@openttd.org>
parents: 13704
diff changeset
2202 this->fill_y = fill.height;
12437
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2203 this->resize_x = resize.width;
971748cbbe8f (svn r16871) -Codechange: Generalize GetWidgetContentSize to UpdateWidgetSize for better control over widget size and resize steps.
alberth <alberth@openttd.org>
parents: 12411
diff changeset
2204 this->resize_y = resize.height;
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
2205 }
5ae30511f96c (svn r16740) -Codechange: Self-sizing widgets in intro screen, town directory, and found town windows.
alberth <alberth@openttd.org>
parents: 12310
diff changeset
2206
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2207 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
2208 {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2209 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
2210
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2211 Rect r;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2212 r.left = this->pos_x;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2213 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
2214 r.top = this->pos_y;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2215 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
2216
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2217 const DrawPixelInfo *dpi = _cur_dpi;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2218 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
2219
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2220 bool clicked = this->IsLowered();
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2221 switch (this->type) {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2222 case WWT_EMPTY:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2223 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2224
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2225 case WWT_PUSHBTN:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2226 assert(this->widget_data == 0);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2227 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
2228 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2229
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2230 case WWT_IMGBTN:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2231 case WWT_PUSHIMGBTN:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2232 case WWT_IMGBTN_2:
12408
a1c0de97cd50 (svn r16842) -Cleanup: add some spaces around a few operators
rubidium <rubidium@openttd.org>
parents: 12405
diff changeset
2233 DrawImageButtons(r, this->type, this->colour, clicked, this->widget_data);
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2234 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2235
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2236 case WWT_TEXTBTN:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2237 case WWT_PUSHTXTBTN:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2238 case WWT_TEXTBTN_2:
12516
49534d3a6b57 (svn r16953) -Codechange: Use SetStringParameters() for simple parameterized strings.
alberth <alberth@openttd.org>
parents: 12493
diff changeset
2239 if (this->index >= 0) w->SetStringParameters(this->index);
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2240 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
2241 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
2242 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2243
15795
c9cf5fe6d6a1 (svn r20470) -Codechange: Make arrow buttons lower and raise like other buttons when clicked.
frosch <frosch@openttd.org>
parents: 15788
diff changeset
2244 case WWT_ARROWBTN:
c9cf5fe6d6a1 (svn r20470) -Codechange: Make arrow buttons lower and raise like other buttons when clicked.
frosch <frosch@openttd.org>
parents: 15788
diff changeset
2245 case WWT_PUSHARROWBTN: {
13662
6182cd79cc26 (svn r18186) -Add: a widgets for left/right arrows with the ability to turn themselves around when a RTL language is loaded
rubidium <rubidium@openttd.org>
parents: 13644
diff changeset
2246 SpriteID sprite;
6182cd79cc26 (svn r18186) -Add: a widgets for left/right arrows with the ability to turn themselves around when a RTL language is loaded
rubidium <rubidium@openttd.org>
parents: 13644
diff changeset
2247 switch (this->widget_data) {
16441
86fd9bcc9d2f (svn r21157) -Codechange: remove information about the text direction out of the language "list"
rubidium <rubidium@openttd.org>
parents: 16309
diff changeset
2248 case AWV_DECREASE: sprite = _current_text_dir != TD_RTL ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT; break;
86fd9bcc9d2f (svn r21157) -Codechange: remove information about the text direction out of the language "list"
rubidium <rubidium@openttd.org>
parents: 16309
diff changeset
2249 case AWV_INCREASE: sprite = _current_text_dir == TD_RTL ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT; break;
13662
6182cd79cc26 (svn r18186) -Add: a widgets for left/right arrows with the ability to turn themselves around when a RTL language is loaded
rubidium <rubidium@openttd.org>
parents: 13644
diff changeset
2250 case AWV_LEFT: sprite = SPR_ARROW_LEFT; break;
6182cd79cc26 (svn r18186) -Add: a widgets for left/right arrows with the ability to turn themselves around when a RTL language is loaded
rubidium <rubidium@openttd.org>
parents: 13644
diff changeset
2251 case AWV_RIGHT: sprite = SPR_ARROW_RIGHT; break;
6182cd79cc26 (svn r18186) -Add: a widgets for left/right arrows with the ability to turn themselves around when a RTL language is loaded
rubidium <rubidium@openttd.org>
parents: 13644
diff changeset
2252 default: NOT_REACHED();
6182cd79cc26 (svn r18186) -Add: a widgets for left/right arrows with the ability to turn themselves around when a RTL language is loaded
rubidium <rubidium@openttd.org>
parents: 13644
diff changeset
2253 }
6182cd79cc26 (svn r18186) -Add: a widgets for left/right arrows with the ability to turn themselves around when a RTL language is loaded
rubidium <rubidium@openttd.org>
parents: 13644
diff changeset
2254 DrawImageButtons(r, WWT_PUSHIMGBTN, this->colour, clicked, sprite);
6182cd79cc26 (svn r18186) -Add: a widgets for left/right arrows with the ability to turn themselves around when a RTL language is loaded
rubidium <rubidium@openttd.org>
parents: 13644
diff changeset
2255 }
6182cd79cc26 (svn r18186) -Add: a widgets for left/right arrows with the ability to turn themselves around when a RTL language is loaded
rubidium <rubidium@openttd.org>
parents: 13644
diff changeset
2256
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2257 case WWT_LABEL:
12516
49534d3a6b57 (svn r16953) -Codechange: Use SetStringParameters() for simple parameterized strings.
alberth <alberth@openttd.org>
parents: 12493
diff changeset
2258 if (this->index >= 0) w->SetStringParameters(this->index);
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2259 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
2260 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2261
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2262 case WWT_TEXT:
12516
49534d3a6b57 (svn r16953) -Codechange: Use SetStringParameters() for simple parameterized strings.
alberth <alberth@openttd.org>
parents: 12493
diff changeset
2263 if (this->index >= 0) w->SetStringParameters(this->index);
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2264 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
2265 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2266
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2267 case WWT_MATRIX:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2268 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
2269 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2270
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2271 case WWT_EDITBOX:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2272 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
2273 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2274
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2275 case WWT_CAPTION:
12516
49534d3a6b57 (svn r16953) -Codechange: Use SetStringParameters() for simple parameterized strings.
alberth <alberth@openttd.org>
parents: 12493
diff changeset
2276 if (this->index >= 0) w->SetStringParameters(this->index);
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2277 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
2278 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2279
14040
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
2280 case WWT_SHADEBOX:
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
2281 assert(this->widget_data == 0);
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
2282 DrawShadeBox(r, this->colour, w->IsShaded());
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
2283 break;
869eedf8fbc5 (svn r18583) -Codechange: Add WWT_SHADEBOX widget and its functions (heavily based on code by erikjanp).
alberth <alberth@openttd.org>
parents: 13956
diff changeset
2284
15080
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2285 case WWT_DEBUGBOX:
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2286 DrawDebugBox(r, this->colour, clicked);
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2287 break;
5eeefe395a96 (svn r19706) -Add: support for the (NewGRF) debug box
rubidium <rubidium@openttd.org>
parents: 14258
diff changeset
2288
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2289 case WWT_STICKYBOX:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2290 assert(this->widget_data == 0);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2291 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
2292 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2293
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2294 case WWT_RESIZEBOX:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2295 assert(this->widget_data == 0);
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2296 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
2297 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2298
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2299 case WWT_CLOSEBOX:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2300 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
2301 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2302
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2303 case WWT_DROPDOWN:
12516
49534d3a6b57 (svn r16953) -Codechange: Use SetStringParameters() for simple parameterized strings.
alberth <alberth@openttd.org>
parents: 12493
diff changeset
2304 if (this->index >= 0) w->SetStringParameters(this->index);
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2305 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
2306 break;
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2307
13664
ce197674184d (svn r18188) -Codechange: s/NWID_BUTTON_DRPDOWN/NWID_BUTTON_DROPDOWN/g
rubidium <rubidium@openttd.org>
parents: 13662
diff changeset
2308 case NWID_BUTTON_DROPDOWN:
13075
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
2309 if (this->index >= 0) w->SetStringParameters(this->index);
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
2310 DrawButtonDropdown(r, this->colour, clicked, (this->disp_flags & ND_DROPDOWN_ACTIVE) != 0, this->widget_data);
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
2311 break;
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
2312
12101
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2313 default:
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2314 NOT_REACHED();
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2315 }
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
2316 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
2317
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2318 if (this->IsDisabled()) {
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2319 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
2320 }
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2321 }
dc6c0caea002 (svn r16514) -Codechange: Add widget flags, and drawing and invalidating.
alberth <alberth@openttd.org>
parents: 12100
diff changeset
2322
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2323 /**
13664
ce197674184d (svn r18188) -Codechange: s/NWID_BUTTON_DRPDOWN/NWID_BUTTON_DROPDOWN/g
rubidium <rubidium@openttd.org>
parents: 13662
diff changeset
2324 * For a #NWID_BUTTON_DROPDOWN, test whether \a pt refers to the button or to the drop-down.
13075
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
2325 * @param pt Point in the widget.
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
2326 * @return The point refers to the button.
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
2327 *
13079
090bac35e7e4 (svn r17579) -Fix: remove doxygen docs for removed parameters, or change @param to @tparam if necessary
rubidium <rubidium@openttd.org>
parents: 13075
diff changeset
2328 * @note The magic constants are also used at #DrawButtonDropdown.
13075
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
2329 */
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
2330 bool NWidgetLeaf::ButtonHit(const Point &pt)
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
2331 {
16441
86fd9bcc9d2f (svn r21157) -Codechange: remove information about the text direction out of the language "list"
rubidium <rubidium@openttd.org>
parents: 16309
diff changeset
2332 if (_current_text_dir == TD_LTR) {
13075
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
2333 int button_width = this->pos_x + this->current_x - 12;
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
2334 return pt.x < button_width;
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
2335 } else {
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
2336 int button_left = this->pos_x + 12;
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
2337 return pt.x >= button_left;
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
2338 }
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
2339 }
0a2c74e86245 (svn r17575) -Codechange: Adding a new combined button+dropdown widget.
alberth <alberth@openttd.org>
parents: 13074
diff changeset
2340
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2341 /* == Conversion code from NWidgetPart array to NWidgetBase* tree == */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2342
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2343 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2344 * 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
2345 *
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2346 * 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
2347 * settings that follow it, until encountering a #EndContainer, another
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2348 * #NWidget, or the end of the parts array.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2349 *
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2350 * @param parts Array with parts of the nested widget.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2351 * @param count Length of the \a parts array.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2352 * @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
2353 * @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
2354 * @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
2355 * @return Number of widget part elements used to compose the widget.
13954
79b889a3a0cd (svn r18490) -Doc: Fixed syntax of a few doxygen pre and post coditions.
alberth <alberth@openttd.org>
parents: 13946
diff changeset
2356 * @pre \c biggest_index != NULL.
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2357 */
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12373
diff changeset
2358 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
2359 {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2360 int num_used = 0;
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 *dest = NULL;
11750
924e26095f16 (svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
2363 *fill_dest = false;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2364
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2365 while (count > num_used) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2366 switch (parts->type) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2367 case NWID_SPACER:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2368 if (*dest != NULL) return num_used;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2369 *dest = new NWidgetSpacer(0, 0);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2370 break;
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 NWID_HORIZONTAL:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2373 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
2374 *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
2375 *fill_dest = true;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2376 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2377
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
2378 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
2379 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
2380 *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
2381 *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
2382 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
2383
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2384 case WWT_PANEL:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2385 case WWT_INSET:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2386 case WWT_FRAME:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2387 if (*dest != NULL) return num_used;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2388 *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
2389 *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
2390 *fill_dest = true;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2391 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2392
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2393 case NWID_VERTICAL:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2394 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
2395 *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
2396 *fill_dest = true;
924e26095f16 (svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
2397 break;
924e26095f16 (svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
2398
16715
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
2399 case NWID_MATRIX: {
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
2400 if (*dest != NULL) return num_used;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
2401 NWidgetMatrix *nwm = new NWidgetMatrix();
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
2402 *dest = nwm;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
2403 *fill_dest = true;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
2404 nwm->SetIndex(parts->u.widget.index);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
2405 nwm->SetColour(parts->u.widget.colour);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
2406 *biggest_index = max(*biggest_index, (int)parts->u.widget.index);
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
2407 break;
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
2408 }
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
2409
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12373
diff changeset
2410 case WPT_FUNCTION: {
11750
924e26095f16 (svn r16140) -Codechange: Call a function while contructing a widget tree.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
2411 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
2412 /* 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
2413 int biggest = -1;
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12373
diff changeset
2414 *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
2415 *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
2416 *fill_dest = false;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2417 break;
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12373
diff changeset
2418 }
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2419
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2420 case WPT_RESIZE: {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2421 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2422 if (nwrb != NULL) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2423 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
2424 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
2425 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2426 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2427 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2428
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2429 case WPT_MINSIZE: {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2430 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2431 if (nwrb != NULL) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2432 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
2433 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
2434 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2435 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2436 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2437
13614
01ef0374674c (svn r18138) -Codechange: Add a new widgetpart to specify the height of a widget in text lines.
peter1138 <peter1138@openttd.org>
parents: 13576
diff changeset
2438 case WPT_MINTEXTLINES: {
01ef0374674c (svn r18138) -Codechange: Add a new widgetpart to specify the height of a widget in text lines.
peter1138 <peter1138@openttd.org>
parents: 13576
diff changeset
2439 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
01ef0374674c (svn r18138) -Codechange: Add a new widgetpart to specify the height of a widget in text lines.
peter1138 <peter1138@openttd.org>
parents: 13576
diff changeset
2440 if (nwrb != NULL) {
01ef0374674c (svn r18138) -Codechange: Add a new widgetpart to specify the height of a widget in text lines.
peter1138 <peter1138@openttd.org>
parents: 13576
diff changeset
2441 assert(parts->u.text_lines.size >= FS_BEGIN && parts->u.text_lines.size < FS_END);
01ef0374674c (svn r18138) -Codechange: Add a new widgetpart to specify the height of a widget in text lines.
peter1138 <peter1138@openttd.org>
parents: 13576
diff changeset
2442 nwrb->SetMinimalTextLines(parts->u.text_lines.lines, parts->u.text_lines.spacing, parts->u.text_lines.size);
01ef0374674c (svn r18138) -Codechange: Add a new widgetpart to specify the height of a widget in text lines.
peter1138 <peter1138@openttd.org>
parents: 13576
diff changeset
2443 }
01ef0374674c (svn r18138) -Codechange: Add a new widgetpart to specify the height of a widget in text lines.
peter1138 <peter1138@openttd.org>
parents: 13576
diff changeset
2444 break;
01ef0374674c (svn r18138) -Codechange: Add a new widgetpart to specify the height of a widget in text lines.
peter1138 <peter1138@openttd.org>
parents: 13576
diff changeset
2445 }
01ef0374674c (svn r18138) -Codechange: Add a new widgetpart to specify the height of a widget in text lines.
peter1138 <peter1138@openttd.org>
parents: 13576
diff changeset
2446
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2447 case WPT_FILL: {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2448 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13698
diff changeset
2449 if (nwrb != NULL) nwrb->SetFill(parts->u.xy.x, parts->u.xy.y);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2450 break;
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
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2453 case WPT_DATATIP: {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2454 NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2455 if (nwc != NULL) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2456 nwc->widget_data = parts->u.data_tip.data;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2457 nwc->tool_tip = parts->u.data_tip.tooltip;
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 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2460 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2461
11811
b32bfec54ff8 (svn r16201) -Codechange: Add NWidgetBase::SetPadding method.
alberth <alberth@openttd.org>
parents: 11800
diff changeset
2462 case WPT_PADDING:
b32bfec54ff8 (svn r16201) -Codechange: Add NWidgetBase::SetPadding method.
alberth <alberth@openttd.org>
parents: 11800
diff changeset
2463 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
2464 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
2465
bf92950ea00b (svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents: 11500
diff changeset
2466 case WPT_PIPSPACE: {
11800
3ab4d2cd4ea5 (svn r16190) -Codechange: Allow stacking of nested widgets.
alberth <alberth@openttd.org>
parents: 11799
diff changeset
2467 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
2468 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
2469
2ee677c87220 (svn r15889) -Codechange: Add pre/inter/post space to nested background widgets
alberth <alberth@openttd.org>
parents: 11511
diff changeset
2470 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
2471 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
2472 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
2473 }
bf92950ea00b (svn r15872) -Codechange: add paddings for widgets, this makes writing new widget arrays less cumbersome.
yexo <yexo@openttd.org>
parents: 11500
diff changeset
2474
15778
4f4c3160cca8 (svn r20452) -Codechange: Remove NWidgetCore::FindScrollbar() and associate scrollbar explicitly using a NWidgetPart via SetScrollbar().
frosch <frosch@openttd.org>
parents: 15727
diff changeset
2475 case WPT_SCROLLBAR: {
4f4c3160cca8 (svn r20452) -Codechange: Remove NWidgetCore::FindScrollbar() and associate scrollbar explicitly using a NWidgetPart via SetScrollbar().
frosch <frosch@openttd.org>
parents: 15727
diff changeset
2476 NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest);
4f4c3160cca8 (svn r20452) -Codechange: Remove NWidgetCore::FindScrollbar() and associate scrollbar explicitly using a NWidgetPart via SetScrollbar().
frosch <frosch@openttd.org>
parents: 15727
diff changeset
2477 if (nwc != NULL) {
4f4c3160cca8 (svn r20452) -Codechange: Remove NWidgetCore::FindScrollbar() and associate scrollbar explicitly using a NWidgetPart via SetScrollbar().
frosch <frosch@openttd.org>
parents: 15727
diff changeset
2478 nwc->scrollbar_index = parts->u.widget.index;
4f4c3160cca8 (svn r20452) -Codechange: Remove NWidgetCore::FindScrollbar() and associate scrollbar explicitly using a NWidgetPart via SetScrollbar().
frosch <frosch@openttd.org>
parents: 15727
diff changeset
2479 }
4f4c3160cca8 (svn r20452) -Codechange: Remove NWidgetCore::FindScrollbar() and associate scrollbar explicitly using a NWidgetPart via SetScrollbar().
frosch <frosch@openttd.org>
parents: 15727
diff changeset
2480 break;
4f4c3160cca8 (svn r20452) -Codechange: Remove NWidgetCore::FindScrollbar() and associate scrollbar explicitly using a NWidgetPart via SetScrollbar().
frosch <frosch@openttd.org>
parents: 15727
diff changeset
2481 }
4f4c3160cca8 (svn r20452) -Codechange: Remove NWidgetCore::FindScrollbar() and associate scrollbar explicitly using a NWidgetPart via SetScrollbar().
frosch <frosch@openttd.org>
parents: 15727
diff changeset
2482
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2483 case WPT_ENDCONTAINER:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2484 return num_used;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2485
12526
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
2486 case NWID_VIEWPORT:
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
2487 if (*dest != NULL) return num_used;
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
2488 *dest = new NWidgetViewport(parts->u.widget.index);
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
2489 *biggest_index = max(*biggest_index, (int)parts->u.widget.index);
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
2490 break;
3d39b4181f66 (svn r16963) -Codechange: Added NWidgetViewport widget.
alberth <alberth@openttd.org>
parents: 12524
diff changeset
2491
15787
6c4bec3b8401 (svn r20461) -Codechange: Replace WWT_HSCROLLBAR, WWT_SCROLLBAR and WWT_SCROLL2BAR with NWID_HSCROLLBAR and NWID_VSCROLLBAR.
frosch <frosch@openttd.org>
parents: 15786
diff changeset
2492 case NWID_HSCROLLBAR:
6c4bec3b8401 (svn r20461) -Codechange: Replace WWT_HSCROLLBAR, WWT_SCROLLBAR and WWT_SCROLL2BAR with NWID_HSCROLLBAR and NWID_VSCROLLBAR.
frosch <frosch@openttd.org>
parents: 15786
diff changeset
2493 case NWID_VSCROLLBAR:
15782
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
2494 if (*dest != NULL) return num_used;
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
2495 *dest = new NWidgetScrollbar(parts->type, parts->u.widget.colour, parts->u.widget.index);
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
2496 *biggest_index = max(*biggest_index, (int)parts->u.widget.index);
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
2497 break;
ae6efcfbfe64 (svn r20456) -Codechange: Add separate nested widget class for scrollbars.
frosch <frosch@openttd.org>
parents: 15779
diff changeset
2498
13073
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
2499 case NWID_SELECTION: {
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
2500 if (*dest != NULL) return num_used;
13565
40a13e194fd0 (svn r18087) -Codechange: remove NWID_LAYERED
rubidium <rubidium@openttd.org>
parents: 13543
diff changeset
2501 NWidgetStacked *nws = new NWidgetStacked();
13073
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
2502 *dest = nws;
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
2503 *fill_dest = true;
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
2504 nws->SetIndex(parts->u.widget.index);
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
2505 *biggest_index = max(*biggest_index, (int)parts->u.widget.index);
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
2506 break;
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
2507 }
013c3a75e449 (svn r17573) -Codechange: NWID_SELECTION containers have a selected widget-plane, and optionally an index in the nested_array.
alberth <alberth@openttd.org>
parents: 13072
diff changeset
2508
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2509 default:
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2510 if (*dest != NULL) return num_used;
15795
c9cf5fe6d6a1 (svn r20470) -Codechange: Make arrow buttons lower and raise like other buttons when clicked.
frosch <frosch@openttd.org>
parents: 15788
diff changeset
2511 assert((parts->type & WWT_MASK) < WWT_LAST || parts->type == NWID_BUTTON_DROPDOWN);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2512 *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
2513 *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
2514 break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2515 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2516 num_used++;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2517 parts++;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2518 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2519
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2520 return num_used;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2521 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2522
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2523 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2524 * 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
2525 * @param parts Array with parts of the nested widgets.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2526 * @param count Length of the \a parts array.
14041
b231a976136b (svn r18584) -Codechange: Generalize MakeWidgetTree to read only one widget (recursively).
alberth <alberth@openttd.org>
parents: 14040
diff changeset
2527 * @param parent Pointer or container to use for storing the child widgets (*parent == NULL or *parent == container or background widget).
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12373
diff changeset
2528 * @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
2529 * @return Number of widget part elements used to fill the container.
13954
79b889a3a0cd (svn r18490) -Doc: Fixed syntax of a few doxygen pre and post coditions.
alberth <alberth@openttd.org>
parents: 13946
diff changeset
2530 * @post \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
2531 */
14041
b231a976136b (svn r18584) -Codechange: Generalize MakeWidgetTree to read only one widget (recursively).
alberth <alberth@openttd.org>
parents: 14040
diff changeset
2532 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
2533 {
14041
b231a976136b (svn r18584) -Codechange: Generalize MakeWidgetTree to read only one widget (recursively).
alberth <alberth@openttd.org>
parents: 14040
diff changeset
2534 /* If *parent == NULL, only the first widget is read and returned. Otherwise, *parent must point to either
b231a976136b (svn r18584) -Codechange: Generalize MakeWidgetTree to read only one widget (recursively).
alberth <alberth@openttd.org>
parents: 14040
diff changeset
2535 * a #NWidgetContainer or a #NWidgetBackground object, and parts are added as much as possible. */
b231a976136b (svn r18584) -Codechange: Generalize MakeWidgetTree to read only one widget (recursively).
alberth <alberth@openttd.org>
parents: 14040
diff changeset
2536 NWidgetContainer *nwid_cont = dynamic_cast<NWidgetContainer *>(*parent);
b231a976136b (svn r18584) -Codechange: Generalize MakeWidgetTree to read only one widget (recursively).
alberth <alberth@openttd.org>
parents: 14040
diff changeset
2537 NWidgetBackground *nwid_parent = dynamic_cast<NWidgetBackground *>(*parent);
b231a976136b (svn r18584) -Codechange: Generalize MakeWidgetTree to read only one widget (recursively).
alberth <alberth@openttd.org>
parents: 14040
diff changeset
2538 assert(*parent == NULL || (nwid_cont != NULL && nwid_parent == NULL) || (nwid_cont == NULL && nwid_parent != NULL));
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2539
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2540 int total_used = 0;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2541 while (true) {
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2542 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
2543 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
2544 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
2545 parts += num_used;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2546 total_used += num_used;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2547
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2548 /* Break out of loop when end reached */
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2549 if (sub_widget == NULL) break;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2550
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2551 /* 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
2552 WidgetType tp = sub_widget->type;
16715
ad3cf41d5861 (svn r21448) -Add: generic widget for creating a scrollable (one direction) and resizable (both directions) area with same sized widgets
rubidium <rubidium@openttd.org>
parents: 16714
diff changeset
2553 if (fill_sub && (tp == NWID_HORIZONTAL || tp == NWID_HORIZONTAL_LTR || tp == NWID_VERTICAL || tp == NWID_MATRIX
13565
40a13e194fd0 (svn r18087) -Codechange: remove NWID_LAYERED
rubidium <rubidium@openttd.org>
parents: 13543
diff changeset
2554 || tp == WWT_PANEL || tp == WWT_FRAME || tp == WWT_INSET || tp == NWID_SELECTION)) {
14041
b231a976136b (svn r18584) -Codechange: Generalize MakeWidgetTree to read only one widget (recursively).
alberth <alberth@openttd.org>
parents: 14040
diff changeset
2555 NWidgetBase *sub_ptr = sub_widget;
b231a976136b (svn r18584) -Codechange: Generalize MakeWidgetTree to read only one widget (recursively).
alberth <alberth@openttd.org>
parents: 14040
diff changeset
2556 int num_used = MakeWidgetTree(parts, count - total_used, &sub_ptr, biggest_index);
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2557 parts += num_used;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2558 total_used += num_used;
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2559 }
14041
b231a976136b (svn r18584) -Codechange: Generalize MakeWidgetTree to read only one widget (recursively).
alberth <alberth@openttd.org>
parents: 14040
diff changeset
2560
b231a976136b (svn r18584) -Codechange: Generalize MakeWidgetTree to read only one widget (recursively).
alberth <alberth@openttd.org>
parents: 14040
diff changeset
2561 /* Add sub_widget to parent container if available, otherwise return the widget to the caller. */
b231a976136b (svn r18584) -Codechange: Generalize MakeWidgetTree to read only one widget (recursively).
alberth <alberth@openttd.org>
parents: 14040
diff changeset
2562 if (nwid_cont) nwid_cont->Add(sub_widget);
b231a976136b (svn r18584) -Codechange: Generalize MakeWidgetTree to read only one widget (recursively).
alberth <alberth@openttd.org>
parents: 14040
diff changeset
2563 if (nwid_parent) nwid_parent->Add(sub_widget);
b231a976136b (svn r18584) -Codechange: Generalize MakeWidgetTree to read only one widget (recursively).
alberth <alberth@openttd.org>
parents: 14040
diff changeset
2564 if (!nwid_cont && !nwid_parent) {
b231a976136b (svn r18584) -Codechange: Generalize MakeWidgetTree to read only one widget (recursively).
alberth <alberth@openttd.org>
parents: 14040
diff changeset
2565 *parent = sub_widget;
b231a976136b (svn r18584) -Codechange: Generalize MakeWidgetTree to read only one widget (recursively).
alberth <alberth@openttd.org>
parents: 14040
diff changeset
2566 return total_used;
b231a976136b (svn r18584) -Codechange: Generalize MakeWidgetTree to read only one widget (recursively).
alberth <alberth@openttd.org>
parents: 14040
diff changeset
2567 }
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2568 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2569
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2570 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
2571
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2572 assert(total_used < count);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2573 assert(parts->type == WPT_ENDCONTAINER);
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2574 return total_used + 1; // *parts is also 'used'
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2575 }
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2576
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2577 /**
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2578 * 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
2579 * @param parts Array with parts of the widgets.
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2580 * @param count Length of the \a parts array.
12404
375cd4fb8ae3 (svn r16838) -Codechange: Fill Window::nested_array in SetupSmallestSize.
alberth <alberth@openttd.org>
parents: 12403
diff changeset
2581 * @param biggest_index Pointer to biggest nested widget index collected in the tree.
13469
3783590f0d39 (svn r17984) -Codechange: make it possible to use MakeNWidgets using a custom container widget.
rubidium <rubidium@openttd.org>
parents: 13394
diff changeset
2582 * @param container Container to add the nested widgets to. In case it is NULL a vertical container is used.
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2583 * @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
2584 * @ingroup NestedWidgetParts
13469
3783590f0d39 (svn r17984) -Codechange: make it possible to use MakeNWidgets using a custom container widget.
rubidium <rubidium@openttd.org>
parents: 13394
diff changeset
2585 * @pre \c biggest_index != NULL
3783590f0d39 (svn r17984) -Codechange: make it possible to use MakeNWidgets using a custom container widget.
rubidium <rubidium@openttd.org>
parents: 13394
diff changeset
2586 * @post \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
2587 */
13469
3783590f0d39 (svn r17984) -Codechange: make it possible to use MakeNWidgets using a custom container widget.
rubidium <rubidium@openttd.org>
parents: 13394
diff changeset
2588 NWidgetContainer *MakeNWidgets(const NWidgetPart *parts, int count, int *biggest_index, NWidgetContainer *container)
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2589 {
12404
375cd4fb8ae3 (svn r16838) -Codechange: Fill Window::nested_array in SetupSmallestSize.
alberth <alberth@openttd.org>
parents: 12403
diff changeset
2590 *biggest_index = -1;
13469
3783590f0d39 (svn r17984) -Codechange: make it possible to use MakeNWidgets using a custom container widget.
rubidium <rubidium@openttd.org>
parents: 13394
diff changeset
2591 if (container == NULL) container = new NWidgetVertical();
14041
b231a976136b (svn r18584) -Codechange: Generalize MakeWidgetTree to read only one widget (recursively).
alberth <alberth@openttd.org>
parents: 14040
diff changeset
2592 NWidgetBase *cont_ptr = container;
b231a976136b (svn r18584) -Codechange: Generalize MakeWidgetTree to read only one widget (recursively).
alberth <alberth@openttd.org>
parents: 14040
diff changeset
2593 MakeWidgetTree(parts, count, &cont_ptr, biggest_index);
13469
3783590f0d39 (svn r17984) -Codechange: make it possible to use MakeNWidgets using a custom container widget.
rubidium <rubidium@openttd.org>
parents: 13394
diff changeset
2594 return container;
11461
0ec1833138f7 (svn r15819) -Add: Nested widgets framework
alberth <alberth@openttd.org>
parents: 11454
diff changeset
2595 }
14044
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2596
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15579
diff changeset
2597 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15579
diff changeset
2598 * Make a nested widget tree for a window from a parts array. Besides loading, it inserts a shading selection widget
14044
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2599 * between the title bar and the window body if the first widget in the parts array looks like a title bar (it is a horizontal
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2600 * container with a caption widget) and has a shade box widget.
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2601 * @param parts Array with parts of the widgets.
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2602 * @param count Length of the \a parts array.
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2603 * @param biggest_index Pointer to biggest nested widget index collected in the tree.
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2604 * @param [out] shade_select Pointer to the inserted shade selection widget (\c NULL if not unserted).
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2605 * @return Root of the nested widget tree, a vertical container containing the entire GUI.
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2606 * @ingroup NestedWidgetParts
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2607 * @pre \c biggest_index != NULL
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2608 * @post \c *biggest_index contains the largest widget index of the tree and \c -1 if no index is used.
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2609 */
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2610 NWidgetContainer *MakeWindowNWidgetTree(const NWidgetPart *parts, int count, int *biggest_index, NWidgetStacked **shade_select)
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2611 {
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2612 *biggest_index = -1;
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2613
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2614 /* Read the first widget recursively from the array. */
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2615 NWidgetBase *nwid = NULL;
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2616 int num_used = MakeWidgetTree(parts, count, &nwid, biggest_index);
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2617 assert(nwid != NULL);
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2618 parts += num_used;
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2619 count -= num_used;
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2620
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2621 NWidgetContainer *root = new NWidgetVertical;
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2622 root->Add(nwid);
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2623 if (count == 0) { // There is no body at all.
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2624 *shade_select = NULL;
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2625 return root;
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2626 }
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2627
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2628 /* If the first widget looks like a titlebar, treat it as such.
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2629 * If it has a shading box, silently add a shade selection widget in the tree. */
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2630 NWidgetHorizontal *hor_cont = dynamic_cast<NWidgetHorizontal *>(nwid);
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2631 NWidgetContainer *body;
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2632 if (hor_cont != NULL && hor_cont->GetWidgetOfType(WWT_CAPTION) != NULL && hor_cont->GetWidgetOfType(WWT_SHADEBOX) != NULL) {
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2633 *shade_select = new NWidgetStacked;
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2634 root->Add(*shade_select);
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2635 body = new NWidgetVertical;
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2636 (*shade_select)->Add(body);
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2637 } else {
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2638 *shade_select = NULL;
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2639 body = root;
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2640 }
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2641
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2642 /* Load the remaining parts into 'body'. */
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2643 int biggest2 = -1;
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2644 MakeNWidgets(parts, count, &biggest2, body);
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2645
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2646 *biggest_index = max(*biggest_index, biggest2);
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2647 return root;
7e5f2232c5d3 (svn r18587) -Codechange: Insert a shade selection widget in the widget tree when the window starts with a title bar with a shade box.
alberth <alberth@openttd.org>
parents: 14041
diff changeset
2648 }
15876
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2649
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2650 /**
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2651 * Make a number of rows with button-like graphics, for enabling/disabling each company.
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2652 * @param biggest_index Storage for collecting the biggest index used in the returned tree.
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2653 * @param widget_first The first widget index to use.
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2654 * @param widget_last The last widget index to use.
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2655 * @param max_length Maximal number of company buttons in one row.
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2656 * @param button_tooltip The tooltip-string of every button.
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2657 * @return Panel with rows of company buttons.
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2658 * @post \c *biggest_index contains the largest used index in the tree.
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2659 */
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2660 NWidgetBase *MakeCompanyButtonRows(int *biggest_index, int widget_first, int widget_last, int max_length, StringID button_tooltip)
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2661 {
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2662 NWidgetVertical *vert = NULL; // Storage for all rows.
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2663 NWidgetHorizontal *hor = NULL; // Storage for buttons in one row.
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2664 int hor_length = 0;
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2665
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2666 Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON);
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2667 sprite_size.width += WD_MATRIX_LEFT + WD_MATRIX_RIGHT;
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2668 sprite_size.height += WD_MATRIX_TOP + WD_MATRIX_BOTTOM + 1; // 1 for the 'offset' of being pressed
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2669
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2670 for (int widnum = widget_first; widnum <= widget_last; widnum++) {
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2671 /* Ensure there is room in 'hor' for another button. */
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2672 if (hor_length == max_length) {
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2673 if (vert == NULL) vert = new NWidgetVertical();
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2674 vert->Add(hor);
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2675 hor = NULL;
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2676 hor_length = 0;
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2677 }
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2678 if (hor == NULL) {
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2679 hor = new NWidgetHorizontal();
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2680 hor_length = 0;
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2681 }
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2682
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2683 NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, widnum);
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2684 panel->SetMinimalSize(sprite_size.width, sprite_size.height);
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2685 panel->SetFill(1, 0);
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2686 panel->SetResize(1, 0);
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2687 panel->SetDataTip(0x0, button_tooltip);
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2688 hor->Add(panel);
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2689 hor_length++;
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2690 }
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2691 *biggest_index = widget_last;
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2692 if (vert == NULL) return hor; // All buttons fit in a single row.
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2693
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2694 if (hor_length > 0 && hor_length < max_length) {
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2695 /* Last row is partial, add a spacer at the end to force all buttons to the left. */
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2696 NWidgetSpacer *spc = new NWidgetSpacer(sprite_size.width, sprite_size.height);
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2697 spc->SetFill(1, 0);
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2698 spc->SetResize(1, 0);
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2699 hor->Add(spc);
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2700 }
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2701 if (hor != NULL) vert->Add(hor);
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2702 return vert;
625f70985d01 (svn r20558) -Codechange: use one generic function to create a list of company buttons
yexo <yexo@openttd.org>
parents: 15795
diff changeset
2703 }