Atrinik Client  4.0
Macros | Functions | Variables
widget.c File Reference
#include <global.h>
#include <toolkit/string.h>
#include <network_graph.h>
#include <toolkit/path.h>

Go to the source code of this file.


#define WIDGET_RESIZE_CHECK(coord, upper_adj, lower_adj)


int widget_id_from_name (const char *name)
static int widget_load (const char *path, uint8_t defaults, widgetdata *widgets[])
void toolkit_widget_init (void)
static int widget_menu_handle (widgetdata *widget, SDL_Event *event)
void menu_container_move (widgetdata *widget, widgetdata *menuitem, SDL_Event *event)
void menu_container_detach (widgetdata *widget, widgetdata *menuitem, SDL_Event *event)
void menu_container_attach (widgetdata *widget, widgetdata *menuitem, SDL_Event *event)
void menu_container_background_change (widgetdata *widget, widgetdata *menuitem, SDL_Event *event)
void menu_container_background (widgetdata *widget, widgetdata *menuitem, SDL_Event *event)
static void menu_container (widgetdata *widget, widgetdata *menuitem, SDL_Event *event)
void widget_menu_standard_items (widgetdata *widget, widgetdata *menu)
static void widget_texture_create (widgetdata *widget)
widgetdatacreate_widget_object (int widget_subtype_id)
void remove_widget_object (widgetdata *widget)
void remove_widget_object_intern (widgetdata *widget)
void remove_widget_inv (widgetdata *widget)
void kill_widgets (void)
void widgets_reset (void)
int widget_x (const widgetdata *widget)
int widget_y (const widgetdata *widget)
int widget_w (const widgetdata *widget)
int widget_h (const widgetdata *widget)
bool widget_set_zoom (widgetdata *widget, double zoom)
static bool widget_is_ellipse (widgetdata *widget)
static bool widget_mouse_over (widgetdata *widget, int x, int y)
static void widget_ensure_onscreen (widgetdata *widget)
void widgets_ensure_onscreen (void)
void kill_widget_tree (widgetdata *widget)
widgetdatacreate_widget (int widget_id)
void remove_widget (widgetdata *widget)
void detach_widget (widgetdata *widget)
static void widget_save_rec (FILE *fp, widgetdata *widget, int depth)
static void widget_save (void)
void toolkit_widget_deinit (void)
int widgets_event (SDL_Event *event)
int widget_event_start_move (widgetdata *widget)
int widget_event_move_stop (int x, int y)
int widget_event_respond (int x, int y)
widgetdataget_widget_owner (int x, int y, widgetdata *start, widgetdata *end)
widgetdataget_widget_owner_rec (int x, int y, widgetdata *widget, widgetdata *end)
static int widgets_need_redraw_rec (widgetdata *widget)
int widgets_need_redraw (void)
static void process_widgets_rec (int draw, widgetdata *widget)
void process_widgets (int draw)
void SetPriorityWidget (widgetdata *node)
void SetPriorityWidget_reverse (widgetdata *node)
void insert_widget_in_container (widgetdata *widget_container, widgetdata *widget, int absolute)
widgetdataget_outermost_container (widgetdata *widget)
widgetdataget_innermost_container (widgetdata *widget)
widgetdatawidget_find (widgetdata *where, int type, const char *id, SDL_Surface *surface)
widgetdatawidget_find_create_id (int type, const char *id)
static void widget_switch_focus_do (widgetdata *widget, int type, const char *id)
void widget_switch_focus (int type, const char *id)
void move_widget (widgetdata *widget, int x, int y)
void move_widget_rec (widgetdata *widget, int x, int y)
void resize_widget (widgetdata *widget, int side, int offset)
void resize_widget_rec (widgetdata *widget, int x, int width, int y, int height)
widgetdataadd_label (const char *text, font_struct *font, const char *color)
widgetdataadd_texture (const char *texture)
widgetdatacreate_menu (int x, int y, widgetdata *owner)
void add_menuitem (widgetdata *menu, const char *text, void(*menu_func_ptr)(widgetdata *, widgetdata *, SDL_Event *event), int menu_type, int val)
void add_separator (widgetdata *widget)
void menu_finalize (widgetdata *widget)
void widget_redraw_all (int widget_type_id)
void widget_redraw_type_id (int type, const char *id)
void widget_show (widgetdata *widget, int show)
void widget_show_toggle_all (int type_id)
void menu_move_widget (widgetdata *widget, widgetdata *menuitem, SDL_Event *event)
void menu_create_widget (widgetdata *widget, widgetdata *menuitem, SDL_Event *event)
void menu_remove_widget (widgetdata *widget, widgetdata *menuitem, SDL_Event *event)
void menu_detach_widget (widgetdata *widget, widgetdata *menuitem, SDL_Event *event)
void menu_inventory_submenu_quickslots (widgetdata *widget, widgetdata *menuitem, SDL_Event *event)
void widget_render_enable_debug (void)


static widgetdata def_widget [TOTAL_SUBWIDGETS]
static const char *const widget_names [TOTAL_SUBWIDGETS]
static void(* widget_initializers [TOTAL_SUBWIDGETS])(widgetdata *)
static widgetdatawidget_list_head
static widgetdatawidget_list_foot
widgetdatacur_widget [TOTAL_SUBWIDGETS]
static widgetdatatype_list_foot [TOTAL_SUBWIDGETS]
widgetevent widget_mouse_event
static widgetmove widget_event_move
static widgetresize widget_event_resize
static int IsMouseExclusive = 0
static int widget_render_debug = 0

Detailed Description

This file controls all the widget related functions, movement of the widgets, initialization, etc.

To add a new widget:

  1. Add an entry (same index in both cases) to ::con_widget and WidgetID.
  2. If applicable, add extended attributes in its own struct, and add handler code for its initialization in create_widget_object().
  3. If applicable, add handler code for widget movement in widget_event_mousedn().
  4. If applicable, add handler code to get_widget_owner().
  5. Add handler function to process_widget().
Alex Tokar
Daniel Liptrot

Definition in file widget.c.

Macro Definition Documentation

#define WIDGET_RESIZE_CHECK (   coord,
(event->motion.coord >= widget_##coord(widget) + (upper_adj) && \
event->motion.coord <= widget_##coord(widget) + (lower_adj))

Function Documentation

widgetdata* add_label ( const char *  text,
font_struct font,
const char *  color 

Creates a label with the given text, font and colour, and sets the size of the widget to the correct boundaries.

Definition at line 2387 of file widget.c.

void add_menuitem ( widgetdata menu,
const char *  text,
void(*)(widgetdata *, widgetdata *, SDL_Event *event)  menu_func_ptr,
int  menu_type,
int  val 

Adds a menuitem to a menu.

Definition at line 2451 of file widget.c.

void add_separator ( widgetdata widget)

Placeholder for menu separators.

Definition at line 2511 of file widget.c.

widgetdata* add_texture ( const char *  texture)

Creates a texture.

Definition at line 2410 of file widget.c.

widgetdata* create_menu ( int  x,
int  y,
widgetdata owner 

Initializes a menu widget.

Definition at line 2428 of file widget.c.

widgetdata* create_widget ( int  widget_id)

Creates a new widget object with a unique ID and inserts it at the root of the widget tree. This should always be the first function called by create_widget_object() in order to get the pointer to the new node so we can link it to other new nodes that depend on it.

Definition at line 845 of file widget.c.

widgetdata* create_widget_object ( int  widget_subtype_id)

Wrapper function to handle the creation of a widget.

Definition at line 414 of file widget.c.

void detach_widget ( widgetdata widget)

Removes the widget from the container it is inside and moves it to the top of the priority tree.

Definition at line 995 of file widget.c.

widgetdata* get_outermost_container ( widgetdata widget)

Get the outermost container the widget is inside.

Definition at line 2047 of file widget.c.

widgetdata* get_widget_owner ( int  x,
int  y,
widgetdata start,
widgetdata end 

Find the widget with mouse focus on a mouse-hit-test basis.

Definition at line 1563 of file widget.c.

void kill_widget_tree ( widgetdata widget)

Recursive function to nuke the entire widget tree.

Definition at line 814 of file widget.c.

void kill_widgets ( void  )

Deinitialize all widgets, and free their SDL surfaces.

Definition at line 573 of file widget.c.

void menu_finalize ( widgetdata widget)

Finalizes menu creation.

Makes sure the menu does not go over the screen size by adding x/y, using standard GUI behavior.

widgetThe menu to finalize.

Definition at line 2524 of file widget.c.

void process_widgets ( int  draw)

Traverse through all the widgets and call the corresponding handlers. This is now a wrapper function just to make the sanity checks before continuing with the actual handling.

Definition at line 1770 of file widget.c.

static void process_widgets_rec ( int  draw,
widgetdata widget 

The priority list is a binary tree, so we walk the tree by using loops and recursions. We actually only need to recurse for every child node. When we traverse the siblings, we can just do a simple loop. This makes it as fast as a linear linked list if there are no child nodes.

Definition at line 1673 of file widget.c.

void remove_widget ( widgetdata widget)

Removes the pointer passed to it from anywhere in the linked list and reconnects the adjacent nodes to each other.

Definition at line 899 of file widget.c.

void remove_widget_inv ( widgetdata widget)

Deletes the entire inventory of a widget, child nodes first. This should be the fastest way. Any widgets that can't be deleted should end up on the top level. This function is already automatically handled with the delete_inv flag, so it shouldn't be called explicitly apart from in remove_widget_object_intern().

Definition at line 553 of file widget.c.

void remove_widget_object ( widgetdata widget)

Wrapper function to handle the obliteration of a widget.

Definition at line 460 of file widget.c.

void remove_widget_object_intern ( widgetdata widget)

Wrapper function to handle the annihilation of a widget, including possibly killing the linked list altogether. Please do not use, this should only be explicitly called by kill_widget_tree() and remove_widget_object(). Use remove_widget_object() for everything else.

Definition at line 478 of file widget.c.

void SetPriorityWidget ( widgetdata node)

A recursive function to bring a widget to the front of the priority list. This makes the widget get displayed last so that they appear on top, and handle events first. In order to do this, we need to recurse backwards up the tree to the top node, and then work our way back down again, bringing each node in front of its siblings.

Definition at line 1788 of file widget.c.

void SetPriorityWidget_reverse ( widgetdata node)

Like SetPriorityWidget(), but in reverse.

nodeThe widget.

Definition at line 1902 of file widget.c.

void toolkit_widget_init ( void  )

Try to load the main interface file and initialize the priority list On failure, initialize the widgets with init_widgets_fromDefault()

Definition at line 243 of file widget.c.

static void widget_ensure_onscreen ( widgetdata widget)

Ensures a single widget is on-screen.

widgetThe widget.

Definition at line 766 of file widget.c.

int widget_event_respond ( int  x,
int  y 

Updates the widget mouse event struct in order to respond to an event.

Definition at line 1546 of file widget.c.

int widget_event_start_move ( widgetdata widget)

Handles the initiation of widget dragging.

Definition at line 1484 of file widget.c.

widgetdata* widget_find ( widgetdata where,
int  type,
const char *  id,
SDL_Surface *  surface 

Find the first widget in the priority list.

whereWhere to look for.
typeWidget type to look for. -1 for any type.
idIdentifier to look for. NULL for any identifier.
surfaceSurface to look for. NULL for any surface.
Widget if found, NULL otherwise.

Definition at line 2091 of file widget.c.

int widget_h ( const widgetdata widget)

Acquire the specified widget's height.


Definition at line 665 of file widget.c.

static bool widget_is_ellipse ( widgetdata widget)

Determine if the widget is an ellipse.

Whether the widget is an ellipse.

Definition at line 708 of file widget.c.

static int widget_menu_handle ( widgetdata widget,
SDL_Event *  event 

Definition at line 283 of file widget.c.

static bool widget_mouse_over ( widgetdata widget,
int  x,
int  y 

Determine whether the specified coordinates are over the widget.

xX coordinate.
yY coordinate.
Whether the coordinates are over the widget.

Definition at line 732 of file widget.c.

void widget_redraw_all ( int  widget_type_id)

Redraws all widgets of a particular type.

Definition at line 2555 of file widget.c.

void widget_render_enable_debug ( void  )

Enable widget rendering debugging.

Definition at line 2660 of file widget.c.

bool widget_set_zoom ( widgetdata widget,
double  zoom 

Set the widget's zoom value.

zoomNew zoom value.
Whether the widget's zoom value changed.

Definition at line 681 of file widget.c.

void widget_show ( widgetdata widget,
int  show 

Sets visibility of the specified widget.

widgetWidget to show.
show1 to show the widget, 0 to hide it.

Definition at line 2582 of file widget.c.

void widget_show_toggle_all ( int  type_id)

Toggles visibility of all widgets of a particular type.

type_idThe type.

Definition at line 2617 of file widget.c.

void widget_switch_focus ( int  type,
const char *  id 

Switches focus to the backmost widget of the given type and UID.

typeWidget type.
idUID. Can be NULL.

Definition at line 2165 of file widget.c.

static void widget_switch_focus_do ( widgetdata widget,
int  type,
const char *  id 

Actually switches focus to the backmost widget; used by widget_switch_focus().

widgetWhere to start.
typeWidget type.
idUID. Can be NULL.

Definition at line 2140 of file widget.c.

int widget_w ( const widgetdata widget)

Acquire the specified widget's width.


Definition at line 651 of file widget.c.

int widget_x ( const widgetdata widget)

Acquire the specified widget's X coordinate.

X coordinate.

Definition at line 615 of file widget.c.

int widget_y ( const widgetdata widget)

Acquire the specified widget's Y coordinate.

Y coordinate.

Definition at line 633 of file widget.c.

void widgets_ensure_onscreen ( void  )

Ensures all widgets are on-screen.

Definition at line 804 of file widget.c.

int widgets_event ( SDL_Event *  event)

Make widgets try to handle an event.

eventEvent to handle.
1 if the event was handled, 0 otherwise.

Definition at line 1205 of file widget.c.

int widgets_need_redraw ( void  )

Check if any widget need redrawing.

1 if any widget needs redrawing, 0 otherwise.

Definition at line 1661 of file widget.c.

static int widgets_need_redraw_rec ( widgetdata widget)

Used by widgets_need_redraw() to check if any widget needs redrawing.

1 if any widget needs redrawing, 0 otherwise.

Definition at line 1638 of file widget.c.

void widgets_reset ( void  )

Resets all the widgets, and the user's widget configuration as well.

Definition at line 590 of file widget.c.

Variable Documentation

The head and foot node for each widget type. The nodes in this linked list do not change until a node is deleted.

Definition at line 75 of file widget.c.

int IsMouseExclusive = 0

A way to steal the mouse, and to prevent widgets from using mouse events Example: Prevents widgets from using mouse events during dragging procedure

Definition at line 101 of file widget.c.

widgetmove widget_event_move
Initial value:
= {
0, NULL, 0, 0

This is used when moving a widget with the mouse.

Definition at line 87 of file widget.c.

widgetresize widget_event_resize
Initial value:
= {
0, NULL, 0, 0

This is used when resizing a widget with the mouse.

Definition at line 92 of file widget.c.

widgetdata* widget_list_foot

The last sibling on the top level of the tree (the far right).

Definition at line 68 of file widget.c.

widgetdata* widget_list_head

The root node at the top of the tree.

Definition at line 66 of file widget.c.

widgetevent widget_mouse_event
Initial value:
= {
NULL, 0, 0

Determines which widget has mouse focus This value is determined in the mouse routines for the widgets

Definition at line 82 of file widget.c.

const char* const widget_names[TOTAL_SUBWIDGETS]
Initial value:
= {
"map", "stat", "menu_buttons", "quickslots", "textwin", "playerdoll",
"playerinfo", "mapname", "input", "fps", "mplayer", "spells", "skills",
"party", "notification", "container", "label", "texture", "buddy",
"active_effects", "protections", "minimap", "target", "inventory",
"container_strip", "menu", "menuitem"

Definition at line 50 of file widget.c.

int widget_render_debug = 0

Whether widget rendering debugging is turned on or off.

Definition at line 106 of file widget.c.