1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/* $Id$ */
/** @file widget_type.h Definitions about widgets. */
#ifndef WIDGET_TYPE_H
#define WIDGET_TYPE_H
#include "core/bitmath_func.hpp"
#include "strings_type.h"
#include "gfx_type.h"
/* How the resize system works:
First, you need to add a WWT_RESIZEBOX to the widgets, and you need
to add the flag WDF_RESIZABLE to the window. Now the window is ready
to resize itself.
As you may have noticed, all widgets have a RESIZE_XXX in their line.
This lines controls how the widgets behave on resize. RESIZE_NONE means
it doesn't do anything. Any other option let's one of the borders
move with the changed width/height. So if a widget has
RESIZE_RIGHT, and the window is made 5 pixels wider by the user,
the right of the window will also be made 5 pixels wider.
Now, what if you want to clamp a widget to the bottom? Give it the flag
RESIZE_TB. This is RESIZE_TOP + RESIZE_BOTTOM. Now if the window gets
5 pixels bigger, both the top and bottom gets 5 bigger, so the whole
widgets moves downwards without resizing, and appears to be clamped
to the bottom. Nice aint it?
You should know one more thing about this system. Most windows can't
handle an increase of 1 pixel. So there is a step function, which
let the windowsize only be changed by X pixels. You configure this
after making the window, like this:
w->resize.step_height = 10;
Now the window will only change in height in steps of 10.
You can also give a minimum width and height. The default value is
the default height/width of the window itself. You can change this
AFTER window - creation, with:
w->resize.width or w->resize.height.
That was all.. good luck, and enjoy :) -- TrueLight */
enum DisplayFlags {
RESIZE_NONE = 0, ///< no resize required
RESIZE_LEFT = 1, ///< left resize flag
RESIZE_RIGHT = 2, ///< rigth resize flag
RESIZE_TOP = 4, ///< top resize flag
RESIZE_BOTTOM = 8, ///< bottom resize flag
RESIZE_LR = RESIZE_LEFT | RESIZE_RIGHT, ///< combination of left and right resize flags
RESIZE_RB = RESIZE_RIGHT | RESIZE_BOTTOM, ///< combination of right and bottom resize flags
RESIZE_TB = RESIZE_TOP | RESIZE_BOTTOM, ///< combination of top and bottom resize flags
RESIZE_LRB = RESIZE_LEFT | RESIZE_RIGHT | RESIZE_BOTTOM, ///< combination of left, right and bottom resize flags
RESIZE_LRTB = RESIZE_LEFT | RESIZE_RIGHT | RESIZE_TOP | RESIZE_BOTTOM, ///< combination of all resize flags
RESIZE_RTB = RESIZE_RIGHT | RESIZE_TOP | RESIZE_BOTTOM, ///< combination of right, top and bottom resize flag
/* The following flags are used by the system to specify what is disabled, hidden, or clicked
* They are used in the same place as the above RESIZE_x flags, Widget visual_flags.
* These states are used in exceptions. If nothing is specified, they will indicate
* Enabled, visible or unclicked widgets*/
WIDG_DISABLED = 4, ///< widget is greyed out, not available
WIDG_HIDDEN = 5, ///< widget is made invisible
WIDG_LOWERED = 6, ///< widget is paint lowered, a pressed button in fact
};
DECLARE_ENUM_AS_BIT_SET(DisplayFlags);
enum {
WIDGET_LIST_END = -1, ///< indicate the end of widgets' list for vararg functions
};
/**
* Window widget types
*/
enum WidgetType {
WWT_EMPTY, ///< Empty widget, place holder to reserve space in widget array
WWT_PANEL, ///< Simple depressed panel
WWT_INSET, ///< Pressed (inset) panel, most commonly used as combo box _text_ area
WWT_IMGBTN, ///< Button with image
WWT_IMGBTN_2, ///< Button with diff image when clicked
WWT_TEXTBTN, ///< Button with text
WWT_TEXTBTN_2, ///< Button with diff text when clicked
WWT_LABEL, ///< Centered label
WWT_TEXT, ///< Pure simple text
WWT_MATRIX, ///< List of items underneath each other
WWT_SCROLLBAR, ///< Vertical scrollbar
WWT_FRAME, ///< Frame
WWT_CAPTION, ///< Window caption (window title between closebox and stickybox)
WWT_HSCROLLBAR, ///< Horizontal scrollbar
WWT_STICKYBOX, ///< Sticky box (normally at top-right of a window)
WWT_SCROLL2BAR, ///< 2nd vertical scrollbar
WWT_RESIZEBOX, ///< Resize box (normally at bottom-right of a window)
WWT_CLOSEBOX, ///< Close box (at top-left of a window)
WWT_DROPDOWN, ///< Raised drop down list (regular)
WWT_DROPDOWNIN, ///< Inset drop down list (used on game options only)
WWT_EDITBOX, ///< a textbox for typing
WWT_LAST, ///< Last Item. use WIDGETS_END to fill up padding!!
WWT_MASK = 0x1F,
WWB_PUSHBUTTON = 1 << 5,
WWB_MASK = 0xE0,
WWT_PUSHBTN = WWT_PANEL | WWB_PUSHBUTTON,
WWT_PUSHTXTBTN = WWT_TEXTBTN | WWB_PUSHBUTTON,
WWT_PUSHIMGBTN = WWT_IMGBTN | WWB_PUSHBUTTON,
};
/** Marker for the "end of widgets" in a Window(Desc) widget table. */
#define WIDGETS_END WWT_LAST, RESIZE_NONE, INVALID_COLOUR, 0, 0, 0, 0, 0, STR_NULL
/**
* Window widget data structure
*/
struct Widget {
WidgetType type; ///< Widget type
DisplayFlags display_flags; ///< Resize direction, alignment, etc. during resizing
Colours colour; ///< Widget colour, see docs/ottd-colourtext-palette.png
int16 left; ///< The left edge of the widget
int16 right; ///< The right edge of the widget
int16 top; ///< The top edge of the widget
int16 bottom; ///< The bottom edge of the widget
uint16 data; ///< The String/Image or special code (list-matrixes) of a widget
StringID tooltips; ///< Tooltips that are shown when rightclicking on a widget
};
#endif /* WIDGET_TYPE_H */
|