Freeciv-3.2
Loading...
Searching...
No Matches
widget.h
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14/**********************************************************************
15 widget.h - description
16 -------------------
17 begin : June 30 2002
18 copyright : (C) 2002 by Rafał Bursig
19 email : Rafał Bursig <bursig@poczta.fm>
20**********************************************************************/
21
22#ifndef FC__WIDGET_H
23#define FC__WIDGET_H
24
25/* utility */
26#include "fc_types.h"
27
28/* gui-sdl2 */
29#include "gui_main.h"
30#include "gui_string.h"
31
32#ifdef SMALL_SCREEN
33#define WINDOW_TITLE_HEIGHT 10
34#else
35#define WINDOW_TITLE_HEIGHT 20
36#endif
37
38#define MAX_ID 0xFFFF
39
40/* Widget Types */
41enum widget_type { /* allow 64 widgets type */
42 WT_BUTTON = 4, /* Button with Text (not use !!!)
43 ( can be transparent ) */
44 WT_I_BUTTON = 8, /* Button with TEXT and ICON
45 ( static; can't be transp. ) */
46 WT_TI_BUTTON = 12, /* Button with TEXT and ICON
47 (themed; can't be transp. ) */
48 WT_EDIT = 16, /* edit field */
49 WT_ICON = 20, /* flat Button from 4 - state icon */
50 WT_VSCROLLBAR = 24, /* bugy */
51 WT_HSCROLLBAR = 28, /* bugy */
53 WT_T_LABEL = 36, /* text label with theme background */
54 WT_I_LABEL = 40, /* text label with icon */
55 WT_TI_LABEL = 44, /* text label with icon and theme background.
56 NOTE: Not DEFINED- don't use
57 ( can't be transp. ) */
58 WT_CHECKBOX = 48, /* checkbox. */
59 WT_TCHECKBOX = 52, /* text label with checkbox. */
60 WT_ICON2 = 56, /* flat Button from 1 - state icon */
62 WT_COMBO = 64
63};
64
65/* Widget FLAGS -> allowed 20 flags */
66/* default: ICON_CENTER_Y, ICON_ON_LEFT */
68 WF_HIDDEN = (1<<10),
69 /* widget->gfx may be freed together with the widget */
70 WF_FREE_GFX = (1<<11),
71 /* widget->theme may be freed together with the widget*/
72 WF_FREE_THEME = (1<<12),
73 /* widget->theme2 may be freed together with the widget*/
74 WF_FREE_THEME2 = (1<<13),
75 /* widget->string may be freed together with the widget*/
76 WF_FREE_STRING = (1<<14),
77 /* widget->data may be freed together with the widget*/
78 WF_FREE_DATA = (1<<15),
79 /* widget->private_data may be freed together with the widget*/
83 WF_ICON_CENTER = (1<<19),
90 WF_PASSWD_EDIT = (1<<26),
91 WF_EDIT_LOOP = (1<<27)
92};
93
94/* Widget states */
101
102struct container {
103 int id0;
104 int id1;
105 int value;
106};
107
108struct small_dialog;
109struct advanced_dialog;
110struct checkbox;
111
112struct widget {
113 struct widget *next;
114 struct widget *prev;
115
116 struct gui_layer *dst; /* destination buffer layer */
117
119 SDL_Surface *theme2; /* Icon or theme2 */
120 SDL_Surface *gfx; /* saved background */
122 utf8_str *info_label; /* optional info label. */
123
124 /* data/information/transport pointers */
125 union {
126 const struct strvec *vector;
128 struct city *city;
129 struct unit *unit;
130 struct player *player;
131 struct tile *tile;
132 struct widget *widget;
133 void *ptr;
135
136 union {
137 struct checkbox *cbox;
140 void *ptr;
142
143 Uint32 state_types_flags; /* "packed" widget info */
144
145 SDL_Rect size; /* size.w and size.h are the size of widget
146 size.x and size.y are the draw positions
147 (relative to dst) */
148
149 SDL_Rect area; /* position (relative to dst) and size of the
150 area the widget resides in (or, for
151 WT_WINDOW, the client area inside it) */
152
153 SDL_Keycode key; /* key aliased with this widget */
154 Uint16 mod; /* SHIFT, CTRL, ALT, etc */
155 Uint16 id; /* id in widget list */
156
157 int (*action) (struct widget *); /* default callback action */
158
159 void (*set_area) (struct widget *pwidget, SDL_Rect area);
160 void (*set_position) (struct widget *pwidget, int x, int y);
161 void (*resize) (struct widget *pwidget, int w, int h);
162 void (*draw_frame) (struct widget *pwidget);
163 int (*redraw) (struct widget *pwidget);
164 void (*mark_dirty) (struct widget *pwidget);
165 void (*flush) (struct widget *pwidget);
166 void (*undraw) (struct widget *pwidget);
167 void (*select) (struct widget *pwidget);
168 void (*unselect) (struct widget *pwidget);
169 void (*press) (struct widget *pwidget);
170 void (*destroy) (struct widget *pwidget);
171};
172
173/* Struct of basic window group dialog ( without scrollbar ) */
176 struct widget *end_widget_list; /* window */
177};
178
179/* Struct of advanced window group dialog ( with scrollbar ) */
189
194
195void add_to_gui_list(Uint16 id, struct widget *gui);
197void widget_add_as_prev(struct widget *new_widget, struct widget *add_dock);
198
201
202void del_gui_list(struct widget *gui_list);
203void del_main_list(void);
204
205struct widget *find_next_widget_at_pos(struct widget *start_widget, int x, int y);
207
209 Uint16 id,
210 enum scan_direction direction);
211
213
214#define set_action(id, action_callback) \
215 get_widget_pointer_from_main_list(id)->action = action_callback
216
217#define set_key(id, keyb) \
218 get_widget_pointer_from_main_list(id)->key = keyb
219
220#define set_mod(id, mod) \
221 get_widget_pointer_from_main_list(id)->mod = mod
222
223#define enable(id) \
224do { \
225 struct widget *____gui = get_widget_pointer_from_main_list(id); \
226 set_wstate(____gui, FC_WS_NORMAL); \
227} while (FALSE)
228
229#define disable(id) \
230do { \
231 struct widget *____gui = get_widget_pointer_from_main_list(id); \
232 set_wstate(____gui , FC_WS_DISABLED); \
233} while (FALSE)
234
235#define show(id) \
236 clear_wflag( get_widget_pointer_from_main_list(id), WF_HIDDEN)
237
238#define hide(id) \
239 set_wflag(get_widget_pointer_from_main_list(id), WF_HIDDEN)
240
241void widget_selected_action(struct widget *pwidget);
242Uint16 widget_pressed_action(struct widget *pwidget);
243
244void unselect_widget_action(void);
245
246#define draw_widget_info_label() redraw_widget_info_label(NULL);
248
249/* Widget */
250void set_wstate(struct widget *pwidget, enum widget_state state);
251enum widget_state get_wstate(const struct widget *pwidget);
252
253void set_wtype(struct widget *pwidget, enum widget_type type);
254enum widget_type get_wtype(const struct widget *pwidget);
255
256void set_wflag(struct widget *pwidget, enum widget_flag flag);
257void clear_wflag(struct widget *pwidget, enum widget_flag flag);
258
259enum widget_flag get_wflags(const struct widget *pwidget);
260
261static inline void widget_set_area(struct widget *pwidget, SDL_Rect area)
262{
263 pwidget->set_area(pwidget, area);
264}
265
266static inline void widget_set_position(struct widget *pwidget, int x, int y)
267{
268 pwidget->set_position(pwidget, x, y);
269}
270
271static inline void widget_resize(struct widget *pwidget, int w, int h)
272{
273 pwidget->resize(pwidget, w, h);
274}
275
276static inline int widget_redraw(struct widget *pwidget)
277{
278 return pwidget->redraw(pwidget);
279}
280
281static inline void widget_draw_frame(struct widget *pwidget)
282{
283 pwidget->draw_frame(pwidget);
284}
285
286static inline void widget_mark_dirty(struct widget *pwidget)
287{
288 pwidget->mark_dirty(pwidget);
289}
290
291static inline void widget_flush(struct widget *pwidget)
292{
293 pwidget->flush(pwidget);
294}
295
296static inline void widget_undraw(struct widget *pwidget)
297{
298 pwidget->undraw(pwidget);
299}
300
301void widget_free(struct widget **gui);
302
303void refresh_widget_background(struct widget *pwidget);
304
305#define FREEWIDGET(pwidget) \
306do { \
307 widget_free(&pwidget); \
308} while (FALSE)
309
310#define draw_frame_inside_widget_on_surface(pwidget , pdest) \
311do { \
312 draw_frame(pdest, pwidget->size.x, pwidget->size.y, pwidget->size.w, pwidget->size.h); \
313} while (FALSE);
314
315#define draw_frame_inside_widget(pwidget) \
316 draw_frame_inside_widget_on_surface(pwidget , pwidget->dst->surface)
317
318#define draw_frame_around_widget_on_surface(pwidget , pdest) \
319do { \
320 draw_frame(pdest, pwidget->size.x - ptheme->FR_Left->w, pwidget->size.y - ptheme->FR_Top->h, \
321 pwidget->size.w + ptheme->FR_Left->w + ptheme->FR_Right->w,\
322 pwidget->size.h + ptheme->FR_Top->h + ptheme->FR_Bottom->h); \
323} while (FALSE);
324
325#define draw_frame_around_widget(pwidget) \
326 draw_frame_around_widget_on_surface(pwidget, pwidget->dst->surface)
327
328/* Group */
330 const struct widget *end_group_widget_list,
331 int add_to_update);
332
335
337 const struct widget *end_group_widget_list,
343
345 struct widget *end_group_widget_list, enum widget_state state);
346
349
352
355 SDL_Rect area);
356
357/* Window Group */
360
361bool select_window_group_dialog(struct widget *begin_widget_list,
362 struct widget *pwindow);
365void move_window_group(struct widget *begin_widget_list, struct widget *pwindow);
366
368 Sint16 start_x, Sint16 start_y,
369 Uint16 w, Uint16 h,
370 struct widget *begin, struct widget *end);
371
372#define del_widget_from_gui_list(__gui) \
373do { \
374 del_widget_pointer_from_gui_list(__gui); \
375 FREEWIDGET(__gui); \
376} while (FALSE)
377
378#define del_ID_from_gui_list(id) \
379do { \
380 struct widget *___ptmp = get_widget_pointer_from_main_list(id); \
381 del_widget_pointer_from_gui_list(___ptmp); \
382 FREEWIDGET(___ptmp); \
383} while (FALSE)
384
385#define move_ID_to_front_of_gui_list(id) \
386 move_widget_to_front_of_gui_list( \
387 get_widget_pointer_from_main_list(id))
388
389#define del_group(begin_group_widget_list, end_group_widget_list) \
390do { \
391 del_group_of_widgets_from_gui_list(begin_group_widget_list, \
392 end_group_widget_list); \
393 begin_group_widget_list = NULL; \
394 end_group_widget_list = NULL; \
395} while (FALSE)
396
397#define enable_group(begin_group_widget_list, end_group_widget_list) \
398 set_group_state(begin_group_widget_list, \
399 end_group_widget_list, FC_WS_NORMAL)
400
401#define disable_group(begin_group_widget_list, end_group_widget_list) \
402 set_group_state(begin_group_widget_list, end_group_widget_list, \
403 FC_WS_DISABLED)
404
405/* Advanced Dialog */
407 struct widget *new_widget,
408 struct widget *add_dock, bool dir,
409 Sint16 start_x, Sint16 start_y)
410 fc__attribute((nonnull (2)));
411
413 struct widget *pwidget)
414 fc__attribute((nonnull (2)));
415
416/* Misc */
420 Uint16 w, Uint16 h);
421
422#include "widget_button.h"
423#include "widget_checkbox.h"
424#include "widget_combo.h"
425#include "widget_edit.h"
426#include "widget_icon.h"
427#include "widget_label.h"
428#include "widget_scrollbar.h"
429#include "widget_window.h"
430
431#endif /* FC__WIDGET_H */
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
char * incite_cost
Definition comments.c:75
GType type
Definition repodlgs.c:1313
static void widget_set_position(struct widget *pwidget, int x, int y)
Definition widget.h:266
struct widget * find_next_widget_for_key(struct widget *start_widget, SDL_Keysym key)
Definition widget.c:252
void del_widget_pointer_from_gui_list(struct widget *gui)
Definition widget.c:622
void set_new_group_start_pos(const struct widget *begin_group_widget_list, const struct widget *end_group_widget_list, Sint16 Xrel, Sint16 Yrel)
Definition widget.c:774
Uint16 widget_pressed_action(struct widget *pwidget)
Definition widget.c:296
void set_group_state(struct widget *begin_group_widget_list, struct widget *end_group_widget_list, enum widget_state state)
Definition widget.c:898
void move_group_to_front_of_gui_list(struct widget *begin_group_widget_list, struct widget *end_group_widget_list)
Definition widget.c:812
widget_state
Definition widget.h:95
@ FC_WS_DISABLED
Definition widget.h:99
@ FC_WS_NORMAL
Definition widget.h:96
@ FC_WS_PRESSED
Definition widget.h:98
@ FC_WS_SELECTED
Definition widget.h:97
void clear_wflag(struct widget *pwidget, enum widget_flag flag)
Definition widget_core.c:62
void add_to_gui_list(Uint16 id, struct widget *gui)
Definition widget.c:586
bool add_widget_to_vertical_scroll_widget_list(struct advanced_dialog *dlg, struct widget *new_widget, struct widget *add_dock, bool dir, Sint16 start_x, Sint16 start_y) fc__attribute((nonnull(2)))
void widget_selected_action(struct widget *pwidget)
Definition widget.c:443
struct widget * get_widget_pointer_from_main_list(Uint16 id)
Definition widget.c:578
scan_direction
Definition widget.h:190
@ SCAN_BACKWARD
Definition widget.h:192
@ SCAN_FORWARD
Definition widget.h:191
void widget_free(struct widget **gui)
Definition widget_core.c:94
void del_group_of_widgets_from_gui_list(struct widget *begin_group_widget_list, struct widget *end_group_widget_list)
Definition widget.c:863
bool del_widget_from_vertical_scroll_widget_list(struct advanced_dialog *dlg, struct widget *pwidget) fc__attribute((nonnull(2)))
static void widget_draw_frame(struct widget *pwidget)
Definition widget.h:281
bool move_window_group_dialog(struct widget *begin_group_widget_list, struct widget *end_group_widget_list)
Definition widget.c:1016
struct widget * find_next_widget_at_pos(struct widget *start_widget, int x, int y)
Definition widget.c:222
static void widget_mark_dirty(struct widget *pwidget)
Definition widget.h:286
static void widget_flush(struct widget *pwidget)
Definition widget.h:291
void refresh_widget_background(struct widget *pwidget)
Definition widget.c:1151
void del_gui_list(struct widget *gui_list)
Definition widget.c:699
void redraw_widget_info_label(SDL_Rect *area)
Definition widget.c:467
enum widget_flag get_wflags(const struct widget *pwidget)
Definition widget_core.c:86
void draw_frame(SDL_Surface *pdest, Sint16 start_x, Sint16 start_y, Uint16 w, Uint16 h)
Definition widget.c:1114
void set_wstate(struct widget *pwidget, enum widget_state state)
Definition widget_core.c:36
void show_group(struct widget *begin_group_widget_list, struct widget *end_group_widget_list)
Definition widget.c:934
void unselect_widget_action(void)
Definition widget.c:418
enum widget_state get_wstate(const struct widget *pwidget)
Definition widget_core.c:70
void hide_group(struct widget *begin_group_widget_list, struct widget *end_group_widget_list)
Definition widget.c:915
static void widget_undraw(struct widget *pwidget)
Definition widget.h:296
widget_flag
Definition widget.h:67
@ WF_FREE_GFX
Definition widget.h:70
@ WF_EDIT_LOOP
Definition widget.h:91
@ WF_ICON_CENTER
Definition widget.h:83
@ WF_PASSWD_EDIT
Definition widget.h:90
@ WF_WIDGET_HAS_INFO_LABEL
Definition widget.h:88
@ WF_DRAW_FRAME_AROUND_WIDGET
Definition widget.h:86
@ WF_ICON_ABOVE_TEXT
Definition widget.h:81
@ WF_FREE_DATA
Definition widget.h:78
@ WF_ICON_CENTER_RIGHT
Definition widget.h:84
@ WF_FREE_PRIVATE_DATA
Definition widget.h:80
@ WF_FREE_THEME2
Definition widget.h:74
@ WF_FREE_STRING
Definition widget.h:76
@ WF_SELECT_WITHOUT_BAR
Definition widget.h:89
@ WF_RESTORE_BACKGROUND
Definition widget.h:85
@ WF_HIDDEN
Definition widget.h:68
@ WF_FREE_THEME
Definition widget.h:72
@ WF_DRAW_TEXT_LABEL_WITH_SPACE
Definition widget.h:87
@ WF_ICON_UNDER_TEXT
Definition widget.h:82
bool is_this_widget_first_on_list(struct widget *gui)
Definition widget.c:657
struct widget * get_widget_pointer_from_id(const struct widget *gui_list, Uint16 id, enum scan_direction direction)
Definition widget.c:552
void widget_add_as_prev(struct widget *new_widget, struct widget *add_dock)
Definition widget.c:602
static int widget_redraw(struct widget *pwidget)
Definition widget.h:276
static void widget_resize(struct widget *pwidget, int w, int h)
Definition widget.h:271
void undraw_group(struct widget *begin_group_widget_list, struct widget *end_group_widget_list)
Definition widget.c:754
void del_main_list(void)
Definition widget.c:691
SDL_Surface * create_bcgnd_surf(SDL_Surface *ptheme, enum widget_state state, Uint16 width, Uint16 height)
Definition widget.c:78
bool select_window_group_dialog(struct widget *begin_widget_list, struct widget *pwindow)
Definition widget.c:998
void group_set_area(struct widget *begin_group_widget_list, struct widget *end_group_widget_list, SDL_Rect area)
Definition widget.c:953
int setup_vertical_widgets_position(int step, Sint16 start_x, Sint16 start_y, Uint16 w, Uint16 h, struct widget *begin, struct widget *end)
Definition widget.c:1051
void set_wtype(struct widget *pwidget, enum widget_type type)
Definition widget_core.c:45
static void widget_set_area(struct widget *pwidget, SDL_Rect area)
Definition widget.h:261
enum widget_type get_wtype(const struct widget *pwidget)
Definition widget_core.c:78
void move_widget_to_front_of_gui_list(struct widget *gui)
Definition widget.c:667
Uint16 redraw_group(const struct widget *begin_group_widget_list, const struct widget *end_group_widget_list, int add_to_update)
Definition widget.c:720
void set_wflag(struct widget *pwidget, enum widget_flag flag)
Definition widget_core.c:54
void popdown_window_group_dialog(struct widget *begin_group_widget_list, struct widget *end_group_widget_list)
Definition widget.c:983
widget_type
Definition widget.h:41
@ WT_TI_BUTTON
Definition widget.h:46
@ WT_VSCROLLBAR
Definition widget.h:50
@ WT_T2_LABEL
Definition widget.h:61
@ WT_WINDOW
Definition widget.h:52
@ WT_TI_LABEL
Definition widget.h:55
@ WT_EDIT
Definition widget.h:48
@ WT_HSCROLLBAR
Definition widget.h:51
@ WT_TCHECKBOX
Definition widget.h:59
@ WT_T_LABEL
Definition widget.h:53
@ WT_COMBO
Definition widget.h:62
@ WT_CHECKBOX
Definition widget.h:58
@ WT_BUTTON
Definition widget.h:42
@ WT_I_BUTTON
Definition widget.h:44
@ WT_ICON2
Definition widget.h:60
@ WT_I_LABEL
Definition widget.h:54
@ WT_ICON
Definition widget.h:49
void move_window_group(struct widget *begin_widget_list, struct widget *pwindow)
Definition widget.c:1039
static mpgui * gui
Definition mpgui_qt.cpp:52
int step
Definition specpq.h:92
struct sprite int int y
Definition sprite_g.h:31
struct sprite int x
Definition sprite_g.h:31
struct widget * begin_active_widget_list
Definition widget.h:184
struct widget * end_widget_list
Definition widget.h:182
struct widget * end_active_widget_list
Definition widget.h:185
struct widget * active_widget_list
Definition widget.h:186
struct scroll_bar * scroll
Definition widget.h:187
struct widget * begin_widget_list
Definition widget.h:181
Definition city.h:320
int id1
Definition widget.h:104
int id0
Definition widget.h:103
int value
Definition widget.h:105
struct widget * begin_widget_list
Definition widget.h:175
struct widget * end_widget_list
Definition widget.h:176
Definition tile.h:50
Definition unit.h:138
void * ptr
Definition widget.h:133
void(* unselect)(struct widget *pwidget)
Definition widget.h:168
union widget::@194 data
SDL_Keycode key
Definition widget.h:153
struct checkbox * cbox
Definition widget.h:137
void(* set_area)(struct widget *pwidget, SDL_Rect area)
Definition widget.h:159
void(* draw_frame)(struct widget *pwidget)
Definition widget.h:162
void(* set_position)(struct widget *pwidget, int x, int y)
Definition widget.h:160
SDL_Surface * theme
Definition widget.h:118
struct widget * widget
Definition widget.h:132
void(* press)(struct widget *pwidget)
Definition widget.h:169
struct tile * tile
Definition widget.h:131
void(* resize)(struct widget *pwidget, int w, int h)
Definition widget.h:161
struct player * player
Definition widget.h:130
SDL_Surface * theme2
Definition widget.h:119
void(* flush)(struct widget *pwidget)
Definition widget.h:165
struct widget * prev
Definition widget.h:114
int(* redraw)(struct widget *pwidget)
Definition widget.h:163
struct small_dialog * small_dlg
Definition widget.h:138
struct unit * unit
Definition widget.h:129
struct gui_layer * dst
Definition widget.h:116
struct city * city
Definition widget.h:128
struct container * cont
Definition widget.h:127
Uint16 mod
Definition widget.h:154
void(* mark_dirty)(struct widget *pwidget)
Definition widget.h:164
struct advanced_dialog * adv_dlg
Definition widget.h:139
utf8_str * string_utf8
Definition widget.h:121
const struct strvec * vector
Definition widget.h:126
Uint32 state_types_flags
Definition widget.h:143
union widget::@195 private_data
SDL_Rect area
Definition widget.h:149
void(* undraw)(struct widget *pwidget)
Definition widget.h:166
SDL_Surface * gfx
Definition widget.h:120
struct widget * next
Definition widget.h:113
void(* destroy)(struct widget *pwidget)
Definition widget.h:170
utf8_str * info_label
Definition widget.h:122
void(* select)(struct widget *pwidget)
Definition widget.h:167
Uint16 id
Definition widget.h:155
SDL_Rect size
Definition widget.h:145
#define fc__attribute(x)
Definition support.h:99