Atrinik Client 2.5
Functions | Variables
toolkit/widget.c File Reference
#include <global.h>

Go to the source code of this file.

Functions

static int load_interface_file (char *filename)
static void process_widget (widgetdata *widget)
static void init_widgets_fromDefault ()
void init_widgets_fromCurrent ()
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 init_widgets ()
void kill_widgets ()
void reset_widget (const char *name)
static void widget_ensure_onscreen (widgetdata *widget)
void widgets_ensure_onscreen ()
void kill_widget_tree (widgetdata *widget)
widgetdatacreate_widget (int widget_id)
void remove_widget (widgetdata *widget)
void detach_widget (widgetdata *widget)
void save_interface_file ()
void save_interface_file_rec (widgetdata *widget, FILE *stream)
int widget_event_mousedn (int x, int y, SDL_Event *event)
int widget_event_mouseup (int x, int y, SDL_Event *event)
int widget_event_mousemv (int x, int y, SDL_Event *event)
int widget_event_start_move (widgetdata *widget, int x, int y)
int widget_event_respond (int x, int y)
int widget_event_override ()
widgetdataget_widget_owner (int x, int y, widgetdata *start, widgetdata *end)
widgetdataget_widget_owner_rec (int x, int y, widgetdata *widget, widgetdata *end)
static void process_widget_background (widgetdata *widget)
void process_widgets ()
void process_widgets_rec (widgetdata *widget)
void SetPriorityWidget (widgetdata *node)
void SetPriorityWidget_reverse (widgetdata *node)
void insert_widget_in_container (widgetdata *widget_container, widgetdata *widget)
widgetdataget_outermost_container (widgetdata *widget)
widgetdatawidget_find_by_surface (SDL_Surface *surface)
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 (char *text, int font, const char *color)
widgetdataadd_bitmap (int bitmap_id)
widgetdatacreate_menu (int x, int y, widgetdata *owner)
void add_menuitem (widgetdata *menu, char *text, void(*menu_func_ptr)(widgetdata *, int, int), int menu_type, int val)
void add_separator (widgetdata *widget)
void menu_finalize (widgetdata *widget)
void widget_redraw_all (int widget_type_id)
void menu_move_widget (widgetdata *widget, int x, int y)
void menu_create_widget (widgetdata *widget, int x, int y)
void menu_remove_widget (widgetdata *widget, int x, int y)
void menu_detach_widget (widgetdata *widget, int x, int y)
void menu_set_say_filter (widgetdata *widget, int x, int y)
void menu_set_shout_filter (widgetdata *widget, int x, int y)
void menu_set_gsay_filter (widgetdata *widget, int x, int y)
void menu_set_tell_filter (widgetdata *widget, int x, int y)
void menu_set_channel_filter (widgetdata *widget, int x, int y)
void submenu_chatwindow_filters (widgetdata *widget, int x, int y)
void menu_inv_filter_all ()
void menu_inv_filter_applied ()
void menu_inv_filter_containers ()
void menu_inv_filter_magical ()
void menu_inv_filter_cursed ()
void menu_inv_filter_unidentified ()
void menu_inv_filter_locked ()
void menu_inv_filter_unapplied ()

Variables

static widgetdata def_widget [TOTAL_SUBWIDGETS]
static const widgetdata con_widget [TOTAL_SUBWIDGETS]
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

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().

Definition in file widget.c.


Function Documentation

widgetdata* add_bitmap ( int  bitmap_id)

Creates a bitmap.

Definition at line 2650 of file widget.c.

widgetdata* add_label ( char *  text,
int  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 2630 of file widget.c.

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

Adds a menuitem to a menu.

Definition at line 2689 of file widget.c.

void add_separator ( widgetdata widget)

Placeholder for menu separators.

Definition at line 2754 of file widget.c.

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

Initializes a menu widget.

Definition at line 2667 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 665 of file widget.c.

widgetdata* create_widget_object ( int  widget_subtype_id)

Wrapper function to handle the creation of a widget.

Definition at line 179 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 847 of file widget.c.

widgetdata* get_outermost_container ( widgetdata widget)

Get the outermost container the widget is inside.

Definition at line 2387 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 1845 of file widget.c.

void init_widgets ( )

Wrapper function to initiate one of each widget.

Definition at line 527 of file widget.c.

void init_widgets_fromCurrent ( )

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

Definition at line 156 of file widget.c.

static void init_widgets_fromDefault ( ) [static]

Load the defaults and initialize the priority list. Create the interface file, if it doesn't exist

Definition at line 133 of file widget.c.

void kill_widget_tree ( widgetdata widget)

Recursive function to nuke the entire widget tree.

Definition at line 637 of file widget.c.

void kill_widgets ( )

Deinitialize all widgets, and free their SDL surfaces.

Definition at line 556 of file widget.c.

static int load_interface_file ( char *  filename) [static]

Load the widgets interface from a file.

Parameters:
filenameThe interface filename.
Returns:
1 on success, 0 on failure.

Definition at line 961 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.

Parameters:
widgetThe menu to finalize.

Definition at line 2765 of file widget.c.

static void process_widget ( widgetdata widget) [static]

Function list for each widget. Calls the widget with the process type.

Parameters:
nIDThe widget ID.

Definition at line 1923 of file widget.c.

static void process_widget_background ( widgetdata widget) [static]

Process background tasks of a widget; called even if the widget is not currently visible.

Parameters:
widgetThe widget.

Definition at line 2038 of file widget.c.

void process_widgets ( )

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 2055 of file widget.c.

void process_widgets_rec ( 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 2070 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 733 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 509 of file widget.c.

void remove_widget_object ( widgetdata widget)

Wrapper function to handle the obliteration of a widget.

Definition at line 373 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 388 of file widget.c.

void reset_widget ( const char *  name)

Resets widget's coordinates from default.

Parameters:
nameWidget name to reset. If NULL, will reset all.

Definition at line 573 of file widget.c.

void save_interface_file ( )

Save the widgets interface to a file.

Definition at line 1158 of file widget.c.

void save_interface_file_rec ( widgetdata widget,
FILE *  stream 
)

The recursive part of save_interface_file(). NEVER call this explicitly, use save_interface_file() in order to use this safely.

Definition at line 1181 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 2103 of file widget.c.

void SetPriorityWidget_reverse ( widgetdata node)

Like SetPriorityWidget(), but in reverse.

Parameters:
nodeThe widget.

Definition at line 2216 of file widget.c.

static void widget_ensure_onscreen ( widgetdata widget) [static]

Ensures a single widget is on-screen.

Parameters:
widgetThe widget.

Definition at line 599 of file widget.c.

int widget_event_mousedn ( int  x,
int  y,
SDL_Event *  event 
)

Mouse is down. Check for owner of the mouse focus. Setup widget dragging, if enabled

Parameters:
xMouse X position.
yMouse Y position.
eventSDL event type.
Returns:
1 if this is a widget and we're handling the mouse, 0 otherwise.

Definition at line 1238 of file widget.c.

int widget_event_mousemv ( int  x,
int  y,
SDL_Event *  event 
)

Mouse was moved. Check for owner of mouse focus. Drag the widget, if active.

Parameters:
xMouse X position.
yMouse Y position.
eventSDL event type.
Returns:
1 if this is a widget and we're handling the mouse, 0 otherwise.

Definition at line 1514 of file widget.c.

int widget_event_mouseup ( int  x,
int  y,
SDL_Event *  event 
)

Mouse is up. Check for owner of mouse focus. Stop dragging the widget, if active.

Parameters:
xMouse X position.
yMouse Y position.
eventSDL event type.
Returns:
1 if this is a widget and we're handling the mouse, 0 otherwise.

Definition at line 1421 of file widget.c.

int widget_event_override ( )

Priority override function, we have to have that here for resizing...

Definition at line 1839 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 1817 of file widget.c.

int widget_event_start_move ( widgetdata widget,
int  x,
int  y 
)

Handles the initiation of widget dragging.

Definition at line 1780 of file widget.c.

widgetdata* widget_find_by_surface ( SDL_Surface *  surface)

Find a widget by its surface.

Parameters:
surfaceThe surface to look for.
Returns:
First widget with the passed surface, NULL if there isn't any such widget.

Definition at line 2412 of file widget.c.

void widget_redraw_all ( int  widget_type_id)

Redraws all widgets of a particular type.

Definition at line 2802 of file widget.c.

void widgets_ensure_onscreen ( )

Ensures all widgets are on-screen.

Definition at line 626 of file widget.c.


Variable Documentation

const widgetdata con_widget[TOTAL_SUBWIDGETS] [static]

Default data list of all widgets.

Definition at line 51 of file widget.c.

widgetdata* cur_widget[TOTAL_SUBWIDGETS]

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 102 of file widget.c.

widgetdata def_widget[TOTAL_SUBWIDGETS] [static]

Current (default) data list of all widgets.

Definition at line 44 of file widget.c.

int IsMouseExclusive = 0 [static]

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 128 of file widget.c.

Initial value:
{
    0, NULL, 0, 0
}

This is used when moving a widget with the mouse.

Definition at line 114 of file widget.c.

Initial value:
{
    0, NULL
}

This is used when resizing a widget with the mouse.

Definition at line 120 of file widget.c.

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

Definition at line 96 of file widget.c.

The root node at the top of the tree.

Definition at line 94 of file widget.c.

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 108 of file widget.c.