-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
ui_main.h
363 lines (300 loc) · 11.3 KB
/
ui_main.h
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
/**\file ui_main.h
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2011 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2005-2011 Daniel Swanson <danij@dengine.net>
*
* This program 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; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/**
* Graphical User Interface.
*/
#ifndef LIBDENG_UI_MAIN_H
#define LIBDENG_UI_MAIN_H
#define IS_ACTKEY(x) (x == ' ' || x == DDKEY_RETURN)
typedef enum {
UI_NONE,
UI_TEXT,
UI_BOX,
UI_FOCUSBOX, /// Can receive focus.
UI_BUTTON,
UI_BUTTON2, /// Staydown/2-state button.
UI_BUTTON2EX, /// Staydown/2-state with additional data.
UI_EDIT,
UI_LIST,
UI_SLIDER,
UI_META /// Special: affects all objects up to the next meta.
} ui_obtype_e;
/// Standard dimensions.
#define UI_WIDTH (1000.0f)
#define UI_HEIGHT (1000.0f)
#define UI_BORDER (UI_WIDTH/120) /// All borders are this wide.
#define UI_SHADOW_OFFSET (MIN_OF(3, UI_WIDTH/320))
#define UI_SHADOW_STRENGTH (.6f)
#define UI_BUTTON_BORDER (UI_BORDER)
#define UI_BAR_WDH (UI_BORDER * 3)
#define UI_BAR_BORDER (UI_BORDER / 2)
#define UI_BAR_BUTTON_BORDER (3 * UI_BAR_BORDER / 2)
#define UI_MAX_COLUMNS 10 /// Maximum columns for list box.
/// Object flags.
#define UIF_HIDDEN 0x1
#define UIF_DISABLED 0x2 /// Can't be interacted with.
#define UIF_PAUSED 0x4 /// Ticker not called.
#define UIF_CLICKED 0x8
#define UIF_ACTIVE 0x10 /// Object active.
#define UIF_FOCUS 0x20 /// Has focus.
#define UIF_NO_FOCUS 0x40 /// Can't receive focus.
#define UIF_DEFAULT 0x80 /// Has focus by default.
#define UIF_LEFT_ALIGN 0x100
#define UIF_FADE_AWAY 0x200 /// Fade UI away while the control is active.
#define UIF_NEVER_FADE 0x400
#define UIF_ID0 0x10000000
#define UIF_ID1 0x20000000
#define UIF_ID2 0x40000000
#define UIF_ID3 0x80000000
/// Special group: no group.
#define UIG_NONE -1
/**
* Flag group modes (for UI_FlagGroup).
*/
enum {
UIFG_CLEAR,
UIFG_SET,
UIFG_XOR
};
/**
* Button arrows.
*/
enum {
UIBA_NONE,
UIBA_UP,
UIBA_DOWN,
UIBA_LEFT,
UIBA_RIGHT
};
typedef struct {
float red, green, blue;
} ui_color_t;
typedef struct ui_object_s {
ui_obtype_e type; /// Type of the object.
int group;
int flags;
int relx, rely, relw, relh; /// Relative placement.
char text[256]; /// Used in various ways.
void (*drawer) (struct ui_object_s*);
int (*responder) (struct ui_object_s*, ddevent_t*);
void (*ticker) (struct ui_object_s*);
void (*action) (struct ui_object_s*);
void* data; /// Pointer to extra data.
int data2; /// Extra numerical data.
int timer;
int x, y, w, h; /// Position and dimensions, auto-inited.
} ui_object_t;
/**
* UI Pages consist of one or more controls.
*/
typedef struct ui_page_s {
struct ui_page_flags_s {
char showBackground:1; /// Draw the background?
} flags;
/// List of objects, UI_NONE terminates.
ui_object_t* _objects;
/// Index of the focus object.
int focus;
/// Index of the capture object.
int capture;
void (*drawer) (struct ui_page_s*);
void (*ticker) (struct ui_page_s*);
int (*responder) (struct ui_page_s*, ddevent_t*);
/// Pointer to the previous page, if any.
struct ui_page_s* previous;
uint _timer;
/// Object count, no need to initialize.
uint count;
} ui_page_t;
typedef struct {
void* data;
const char* yes;
const char* no;
} uidata_button_t;
typedef struct {
char* ptr; /// Text to modify.
int maxlen; /// Maximum allowed length.
void* data;
uint cp; /// Cursor position.
} uidata_edit_t;
typedef struct {
char text[256];
int data;
int data2;
} uidata_listitem_t;
typedef struct {
void* items;
int count; /// Number of items.
void* data;
int selection; /// Selected item (-1 if none).
int first; /// First visible item.
int itemhgt; /// Height of each item (0 = fonthgt).
int numvis; /// Number of visible items (updated at SetPage).
byte button[3]; /// Button states (0=normal, 1=down).
int column[UI_MAX_COLUMNS]; /// Column offsets (real coords).
} uidata_list_t;
typedef struct {
float min, max;
float value;
float step; /// Button step.
boolean floatmode; /// Otherwise only integers are allowed.
void* data;
char* zerotext;
byte button[3]; /// Button states (0=normal, 1=down).
} uidata_slider_t;
void UI_Register(void);
/// Called when entering a UI page.
void UI_PageInit(boolean halttime, boolean tckui, boolean tckframe, boolean drwgame, boolean noescape);
/// Called upon exiting a ui page.
void UI_End(void);
/// @return @c true, if the UI is currently active.
boolean UI_IsActive(void);
/// @return Ptr to the current UI page if active.
ui_page_t* UI_CurrentPage(void);
/**
* Set the alpha level of the entire UI. Alpha levels below one automatically
* show the game view in addition to the UI.
*
* @param alpha Alpha level to set the UI too (0...1)
*/
void UI_SetAlpha(float alpha);
/// @return Current alpha level of the UI.
float UI_Alpha(void);
/// @param id Id number of the color to return e.g. "UIC_TEXT".
ui_color_t* UI_Color(uint id);
/// @return Height of the current UI font.
int UI_FontHeight(void);
void UI_LoadTextures(void);
void UI_ClearTextures(void);
/// Initializes UI page data prior to use.
void UI_InitPage(ui_page_t* page, ui_object_t* objects);
/// Change and prepare the active page.
void UI_SetPage(ui_page_t* page);
/// Directs events through the ui and current page if active.
int UI_Responder(ddevent_t* ev);
void UI_Ticker(timespan_t time);
/// Draws the current ui page if active.
void UI_Drawer(void);
int UI_CountObjects(ui_object_t* list);
void UI_FlagGroup(ui_object_t* list, int group, int flags, int set);
/// All the specified flags must be set.
ui_object_t* UI_FindObject(ui_object_t* list, int group, int flags);
/// @param ob Must be on the current page! It can't be NULL.
void UI_Focus(ui_object_t* ob);
/// Set focus to the object under the mouse cursor.
void UI_MouseFocus(void);
/// Set focus to the object that should get focus by default.
void UI_DefaultFocus(ui_page_t* page);
/// @param ob If @c NULL,, capture is ended. Must be on the current page!
void UI_Capture(ui_object_t* ob);
/**
* Default callbacks.
*/
int UIPage_Responder(ui_page_t* page, ddevent_t* ev);
/// Call the ticker routine for each object.
void UIPage_Ticker(ui_page_t* page);
/// Draws the ui including all objects on the current page.
void UIPage_Drawer(ui_page_t* page);
void UIFrame_Drawer(ui_object_t* ob);
void UIText_Drawer(ui_object_t* ob);
void UIText_BrightDrawer(ui_object_t* ob);
int UIButton_Responder(ui_object_t* ob, ddevent_t* ev);
void UIButton_Drawer(ui_object_t* ob);
int UIEdit_Responder(ui_object_t* ob, ddevent_t* ev);
void UIEdit_Drawer(ui_object_t* ob);
int UIList_Responder(ui_object_t* ob, ddevent_t* ev);
void UIList_Ticker(ui_object_t* ob);
void UIList_Drawer(ui_object_t* ob);
int UISlider_Responder(ui_object_t* ob, ddevent_t* ev);
void UISlider_Ticker(ui_object_t* ob);
void UISlider_Drawer(ui_object_t* ob);
/**
* Helpers.
*/
/// Width of the available page area, in pixels.
int UI_AvailableWidth(void);
/// Height of the available page area, in pixels.
int UI_AvailableHeight(void);
/// Coordinate space conversion: relative to screen space.
int UI_ScreenX(int relx);
int UI_ScreenY(int rely);
int UI_ScreenW(int relw);
int UI_ScreenH(int relh);
void UI_InitColumns(ui_object_t* ob);
int UI_MouseInsideBox(int x, int y, int w, int h);
/// @return @c true, if the mouse is inside the object.
int UI_MouseInside(ui_object_t* ob);
/// @return @c true, if the mouse hasn't been moved for a while.
int UI_MouseResting(ui_page_t* page);
int UI_ListFindItem(ui_object_t* ob, int data_value);
void UI_DrawLogo(int x, int y, int w, int h);
/**
* Background with the "The Doomsday Engine" text superimposed.
*
* @param x X coordinate (left) to draw the background.
* @param y Y coordinate (top) to draw the background.
* @param w Width (from left) to draw the background.
* @param h Height (from top) to draw the background.
* @param alpha Alpha level to use when drawing the background.
*/
void UI_DrawDDBackground(float x, float y, float w, float h,float alpha);
/**
* Draw the mouse cursor at the given x, y co-ordinates.
*
* @param x X screen-space coordinate.
* @param y Y screen-space coordinate.
* @param w Width of the cursor in pixels.
* @param h Height of the cursor in pixels.
*/
void UI_DrawMouse(int x, int y, int w, int h);
void UI_DrawTitle(ui_page_t* page);
void UI_DrawTitleEx(char* text, int height, float alpha);
void UI_MixColors(ui_color_t* a, ui_color_t* b, ui_color_t* dest, float amount);
void UI_SetColorA(ui_color_t* color, float alpha);
void UI_SetColor(ui_color_t* color);
void UI_Line(int x1, int y1, int x2, int y2, ui_color_t* start, ui_color_t* end, float startAlpha, float endAlpha);
void UI_Shade(int x, int y, int w, int h, int border, ui_color_t* main, ui_color_t* secondary, float alpha, float bottom_alpha);
void UI_Gradient(int x, int y, int w, int h, ui_color_t* top, ui_color_t* bottom, float topAlpha, float bottomAlpha);
void UI_GradientEx(int x, int y, int w, int h, int border, ui_color_t* top, ui_color_t* bottom, float topAlpha, float bottomAlpha);
void UI_HorizGradient(int x, int y, int w, int h, ui_color_t* left, ui_color_t* right, float leftAlpha, float rightAlpha);
void UI_DrawRect(int x, int y, int w, int h, int brd, ui_color_t* color, float alpha);
void UI_DrawRectEx(int x, int y, int w, int h, int brd, boolean filled, ui_color_t* top, ui_color_t* bottom, float alpha, float bottomAlpha);
void UI_DrawTriangle(int x, int y, int radius, ui_color_t* hi, ui_color_t* med, ui_color_t* low, float alpha);
/**
* A horizontal triangle, pointing left or right. Positive radius
* means left.
*/
void UI_DrawHorizTriangle(int x, int y, int radius, ui_color_t* hi, ui_color_t* med, ui_color_t *low, float alpha);
void UI_DrawButton(int x, int y, int w, int h, int brd, float alpha, ui_color_t* background, boolean down, boolean disabled, int arrow);
/// Draw shadowed text.
void UI_TextOutEx(const char* text, int x, int y, ui_color_t* color, float alpha);
void UI_TextOutEx2(const char* text, int x, int y, ui_color_t* color, float alpha, short flags);
int UI_TextOutWrap(const char* text, int x, int y, int w, int h);
/**
* Draw line-wrapped text inside a box. Returns the Y coordinate of the
* last word.
*/
int UI_TextOutWrapEx(const char* text, int x, int y, int w, int h, ui_color_t* color, float alpha);
void UI_DrawHelpBox(int x, int y, int w, int h, float alpha, char* text);
#endif /* LIBDENG_UI_MAIN_H */