Atrinik Client  4.0
widget.h
Go to the documentation of this file.
1 /*************************************************************************
2  * Atrinik, a Multiplayer Online Role Playing Game *
3  * *
4  * Copyright (C) 2009-2014 Alex Tokar and Atrinik Development Team *
5  * *
6  * Fork from Crossfire (Multiplayer game for X-windows). *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
21  * *
22  * The author can be reached at admin@atrinik.org *
23  ************************************************************************/
24 
30 #ifndef WIDGET_H
31 #define WIDGET_H
32 
33 /* If you want (a LOT of) debug info about widgets, uncomment this */
34 /*#define DEBUG_WIDGET*/
35 
37 typedef struct widgetdata {
39  char *name;
40 
42  char *id;
43 
45  char bg[32];
46 
48  int x;
49 
51  int y;
52 
54  int w;
55 
57  int h;
58 
60  int zoom_x;
61 
63  int zoom_y;
64 
66  uint8_t moveable;
67 
69  uint8_t show;
70 
72  uint8_t redraw;
73 
75  uint8_t unique;
76 
78  uint8_t required;
79 
83  uint8_t save;
84 
86  struct widgetdata *next;
87 
89  struct widgetdata *prev;
90 
92  struct widgetdata *inv;
93 
96 
98  struct widgetdata *env;
99 
102 
105 
107  void *subwidget;
108 
110  SDL_Surface *surface;
111 
114 
115  int texture_type;
116 
118  int type;
119 
122  int sub_type;
123 
124  uint8_t resizeable;
125 
126  int min_w;
127 
128  int min_h;
129 
130  int resize_flags;
131 
132  int disable_snapping;
133 
134  uint32_t showed_ticks;
135 
140  int hidden;
141 
142  double zoom;
143 
144  void (*draw_func)(struct widgetdata *widget);
145 
146  void (*background_func)(struct widgetdata *widget, int draw);
147 
148  int (*event_func)(struct widgetdata *widget, SDL_Event *event);
149 
150  void (*deinit_func)(struct widgetdata *widget);
151 
152  int (*load_func)(struct widgetdata *widget, const char *keyword, const char *parameter);
153 
154  void (*save_func)(struct widgetdata *widget, FILE *fp, const char *padding);
155 
156  int (*menu_handle_func)(struct widgetdata *widget, SDL_Event *event);
157 
158  void (*padding_func)(struct widgetdata *widget, int *x, int *y);
159 } widgetdata;
160 
163 typedef struct _widget_container {
167 
171 
175 
179 
183 
184  /* these are the top two values of the widgets inside stored here for fast
185  * movement and resizing.
186  * the values are in relation to each border of the container. if a widget's
187  * relative co-ordinate
188  * was equal to one of these values before movement/resizing and then dips
189  * below the second top
190  * value, the client will scan the immediate children of the container to
191  * find out what the new
192  * second top value is after the movement/resizing is complete. this means
193  * it doesn't have to keep
194  * scanning the children for the new highest size during the movement */
195  int x_left_buf1;
196  int x_left_buf2;
197  int x_right_buf1;
198  int x_right_buf2;
199  int y_top_buf1;
200  int y_top_buf2;
201  int y_bottom_buf1;
202  int y_bottom_buf2;
203 
204  /* Used for custom attributes of a container. */
205  void *subcontainer;
207 
208 typedef struct _widget_label {
210  char *text;
211 
214 
216  const char *color;
217 } _widget_label;
218 
219 typedef struct _widget_texture {
223 
224 typedef struct widget_input_struct {
225  text_input_struct text_input;
226 
227  text_input_history_struct *text_input_history;
228 
229  char title_text[MAX_BUF];
230 
231  char prepend_text[MAX_BUF];
233 
236 typedef struct _widget_container_strip {
239 
242 
244  int size;
245 
249 
252 typedef struct _menu {
256 
259 } _menu;
260 
268 typedef struct _menuitem {
271  void (*menu_func_ptr)(widgetdata *, widgetdata *, SDL_Event *event);
272 
275 
276  int val;
277 } _menuitem;
278 
280 enum _MEvent {
281  MOUSE_UP = 1,
282  MOUSE_DOWN,
283  MOUSE_MOVE
284 };
285 
287 typedef enum WidgetID {
288  MAP_ID,
289  STAT_ID,
290  MENU_B_ID,
291  QUICKSLOT_ID,
292  CHATWIN_ID,
293  PDOLL_ID,
294  PLAYER_INFO_ID,
295  MAPNAME_ID,
296  INPUT_ID,
297  FPS_ID,
298  MPLAYER_ID,
299  SPELLS_ID,
300  SKILLS_ID,
301  PARTY_ID,
302  NOTIFICATION_ID,
303  CONTAINER_ID,
304  LABEL_ID,
305  TEXTURE_ID,
306  BUDDY_ID,
307  ACTIVE_EFFECTS_ID,
308  PROTECTIONS_ID,
309  MINIMAP_ID,
310  TARGET_ID,
311  INVENTORY_ID,
312  NETWORK_GRAPH_ID,
313 
316 } WidgetID;
317 
319 enum {
322  MENU_ID,
323  MENUITEM_ID,
324 
327 };
328 
330 enum {
331  RESIZE_LEFT = 1,
332  RESIZE_TOP = 2,
333  RESIZE_RIGHT = 4,
334  RESIZE_BOTTOM = 8,
335  RESIZE_TOPLEFT = RESIZE_TOP | RESIZE_LEFT,
336  RESIZE_TOPRIGHT = RESIZE_TOP | RESIZE_RIGHT,
337  RESIZE_BOTTOMRIGHT = RESIZE_BOTTOM | RESIZE_RIGHT,
338  RESIZE_BOTTOMLEFT = RESIZE_BOTTOM | RESIZE_LEFT
339 };
340 
342 enum {
343  MENU_NORMAL,
344  MENU_SUBMENU,
345  MENU_CHECKBOX,
346  MENU_RADIO
347 };
348 
349 enum {
350  WIDGET_TEXTURE_TYPE_NONE,
351  WIDGET_TEXTURE_TYPE_NORMAL,
352  WIDGET_TEXTURE_TYPE_EMPTY,
353 
354  WIDGET_TEXTURE_TYPE_NUM
355 };
356 
358 typedef struct widgetevent {
361 
363  int x;
364 
366  int y;
367 } widgetevent;
368 
370 typedef struct widgetmove {
372  int active;
373 
376 
378  int xOffset;
379 
381  int yOffset;
382 } widgetmove;
383 
385 typedef struct widgetresize {
387  int active;
388 
391 
392  int xoff;
393 
394  int yoff;
395 } widgetresize;
396 
398 #define WIDGET_REDRAW(__tmp) __tmp->redraw = 1;
399 
400 #define WIDGET_SHOW(_widget) widget_show(_widget, 1);
401 #define WIDGET_SHOW_TOGGLE(_widget) widget_show(_widget, !(_widget)->show);
402 #define WIDGET_SHOW_TOGGLE_ALL(__id) widget_show_toggle_all(__id);
403 #define WIDGET_SHOW_CHANGE(_id, _state) \
404  do { \
405  bool _state_ = _state != 0; \
406  for (widgetdata *_widget_ = cur_widget[_id]; _widget_ != NULL; \
407  _widget_ = _widget_->type_next) { \
408  widget_show(_widget_, _state_); \
409  } \
410  } while (0)
411 
412 /* Macro to redraw all widgets of a particular type. Don't use this often. */
413 #define WIDGET_REDRAW_ALL(__id) widget_redraw_all(__id);
414 
417 #define TEXTWIN(__textwin) ((textwin_struct *) ((__textwin)->subwidget))
418 #define WIDGET_INPUT(_widget) ((widget_input_struct *) (_widget)->subwidget)
419 #define CONTAINER(__widget_container) (_widget_container *) (__widget_container->subwidget)
420 #define LABEL(__widget_label) (_widget_label *) (__widget_label->subwidget)
421 #define WIDGET_TEXTURE(__widget_texture) (_widget_texture *) (__widget_texture->subwidget)
422 #define CONTAINER_STRIP(__widget_container_strip) \
423  (_widget_container_strip *) ( ((_widget_container *) (__widget_container_strip->subwidget))->subcontainer)
424 #define MENU(__menu) \
425  ((_menu *) ( (( ((_widget_container_strip *) ((_widget_container *) (__menu->subwidget))->subcontainer))->subcontainer_strip)))
426 #define MENUITEM(__menuitem) \
427  (_menuitem *) ( (( ((_widget_container_strip *) ((_widget_container *) (__menuitem->subwidget))->subcontainer))->subcontainer_strip))
428 #define INVENTORY(_widget) ((inventory_struct *) ((_widget)->subwidget))
429 
430 #define WIDGET_BORDER_SIZE 1
431 
432 #endif
widgetdata * submenu
Definition: widget.h:255
struct _menuitem _menuitem
int type
Definition: widget.h:118
int outer_padding_left
Definition: widget.h:178
int outer_padding_top
Definition: widget.h:170
struct _widget_container_strip _widget_container_strip
struct widgetdata * env
Definition: widget.h:98
struct widgetresize widgetresize
void * subwidget
Definition: widget.h:107
struct widgetdata * prev
Definition: widget.h:89
struct _widget_container _widget_container
SDL_Surface * surface
Definition: widget.h:110
int sub_type
Definition: widget.h:122
_MEvent
Definition: widget.h:280
char * name
Definition: widget.h:39
double zoom
Zoom factor of the widget.
Definition: widget.h:142
struct widgetevent widgetevent
struct widgetdata * type_next
Definition: widget.h:101
int active
Definition: widget.h:372
struct widgetdata * next
Definition: widget.h:86
int hidden
Definition: widget.h:140
font_struct * font
Definition: widget.h:213
struct widgetdata * inv
Definition: widget.h:92
struct _menu _menu
char * id
Definition: widget.h:42
struct widgetdata widgetdata
uint8_t unique
Definition: widget.h:75
texture_struct * texture
Definition: widget.h:113
widgetdata * owner
Definition: widget.h:390
int menu_type
Definition: widget.h:274
uint8_t show
Definition: widget.h:69
char bg[32]
Definition: widget.h:45
Definition: widget.h:252
struct widgetmove widgetmove
void * subcontainer_strip
Definition: widget.h:247
uint8_t required
Definition: widget.h:78
uint8_t save
Definition: widget.h:83
int xOffset
Definition: widget.h:378
uint8_t redraw
Definition: widget.h:72
uint8_t moveable
Definition: widget.h:66
int zoom_x
Definition: widget.h:60
int x
Definition: widget.h:48
widgetdata * owner
Definition: widget.h:258
int active
Definition: widget.h:387
void(* menu_func_ptr)(widgetdata *, widgetdata *, SDL_Event *event)
Definition: widget.h:271
widgetdata * owner
Definition: widget.h:375
int yOffset
Definition: widget.h:381
int w
Definition: widget.h:54
int h
Definition: widget.h:57
WidgetID
Definition: widget.h:287
int zoom_y
Definition: widget.h:63
widgetdata * owner
Definition: widget.h:360
const char * color
Definition: widget.h:216
struct widgetdata * type_prev
Definition: widget.h:104
int outer_padding_bottom
Definition: widget.h:174
int outer_padding_right
Definition: widget.h:182
struct widgetdata * inv_rev
Definition: widget.h:95
texture_struct * texture
Definition: widget.h:221
int y
Definition: widget.h:51
char * text
Definition: widget.h:210