naev 0.12.5
toolkit.c File Reference

Handles windows and widgets. More...

#include "toolkit.h"
#include "dialogue.h"
#include "input.h"
#include "log.h"
#include "ntracing.h"
#include "opengl.h"
#include "pause.h"
#include "tk/toolkit_priv.h"
Include dependency graph for toolkit.c:

Go to the source code of this file.

Macros

#define INPUT_DELAY   conf.repeat_delay
#define INPUT_FREQ   conf.repeat_freq
#define MIN_WINDOWS   4

Functions

static int toolkit_mouseEvent (Window *w, SDL_Event *event)
 Handles the mouse events.
static int toolkit_mouseEventWidget (Window *w, Widget *wgt, SDL_Event *event, int x, int y, int rx, int ry)
 Handle widget mouse input.
static int toolkit_keyEvent (Window *wdw, SDL_Event *event)
 Handles keyboard events.
static int toolkit_textEvent (Window *wdw, SDL_Event *event)
static int toolkit_isFocusable (const Widget *wgt)
 Checks to see if a widget is focusable.
static void toolkit_expose (Window *wdw, int expose)
 Exposes or hides a window and notifies its widgets.
static void window_renderBorder (const Window *w)
 Renders a window border.
static void widget_kill (Widget *wgt)
 Destroy a widget really.
static void window_cleanup (Window *wdw)
 Cleans up the window, should be done before window_remove.
static void window_remove (Window *wdw)
 Frees up a window. Make sure to clean up the window first.
static void toolkit_purgeDead (void)
 Purges the dead windows.
int toolkit_isOpen (void)
 Checks to see if the toolkit is open.
void toolkit_delay (void)
 Delays the toolkit purge by an iteration, useful for dialogues.
void toolkit_setPos (const Window *wdw, Widget *wgt, int x, int y)
 Sets the internal widget position.
void toolkit_setWindowPos (Window *wdw, int x, int y)
 Moves a window to the specified coordinates.
void window_move (unsigned int wid, int x, int y)
 Moves a window to the specified coordinates.
void window_resize (unsigned int wid, int w, int h)
 Resizes the window.
Widget * window_newWidget (Window *w, const char *name)
 Allocates room for a new widget.
Window * window_wget (unsigned int wid)
 Gets a Window by ID.
Window * window_wgetW (unsigned int wid)
 Gets a Window by ID, without warning.
Window * window_wgetNameW (const char *name)
 Gets a Window by name, without warning.
Widget * window_getwgt (unsigned int wid, const char *name)
 Gets a widget from window id and widgetname.
void window_dimWindow (unsigned int wid, int *w, int *h)
 Gets the dimensions of a window.
void window_posWindow (unsigned int wid, int *x, int *y)
 Gets the dimensions of a window.
void window_dimWidget (unsigned int wid, const char *name, int *w, int *h)
 Gets the dimensions of a widget.
void window_posWidget (unsigned int wid, const char *name, int *x, int *y)
 Gets a widget's position.
void window_moveWidget (unsigned int wid, const char *name, int x, int y)
 Moves a widget.
void window_resizeWidget (unsigned int wid, const char *name, int w, int h)
 Resizes a widget.
void window_canFocusWidget (unsigned int wid, const char *name, int canfocus)
 Allows or disallows focusing a widget.
int window_isTop (unsigned int wid)
 Checks to see if a window is at the top.
int widget_isCovered (unsigned int wid, const char *name, int x, int y)
 Checks to see if a widget is covered or not.
int window_exists (const char *wdwname)
 Checks to see if a window exists.
int window_existsID (unsigned int wid)
 Checks to see if a window with a certain ID exists.
int window_setDisplayname (unsigned int wid, const char *displayname)
 Sets the displayname of a window.
void window_setDynamic (unsigned int wid, int dynamic)
 Sets a window as dynamic, so that it is drawn every frame completely.
unsigned int window_get (const char *wdwname)
 Gets the ID of a window.
unsigned int window_create (const char *name, const char *displayname, const int x, const int y, const int w, const int h)
 Creates a window.
unsigned int window_createFlags (const char *name, const char *displayname, const int x, const int y, const int w, const int h, unsigned int flags)
 Creates a window.
void window_setParent (unsigned int wid, unsigned int parent)
 Sets a window as a window's parent.
unsigned int window_getParent (unsigned int wid)
 Gets the window's parent.
void window_onClose (unsigned int wid, void(*fptr)(unsigned int, const char *))
 Sets the default close function of the window.
void window_setAccept (unsigned int wid, void(*accept)(unsigned int, const char *))
 Sets the default accept function of the window.
void window_setCancel (unsigned int wid, void(*cancel)(unsigned int, const char *))
 Sets the default cancel function of the window.
void window_setOnFocus (unsigned int wid, void(*focus)(unsigned int))
 Sets the focus function of the window.
void window_setData (unsigned int wid, void *data)
 Sets custom data for a window.
void * window_getData (unsigned int wid)
 Gets the custom data of a window.
void window_setBorder (unsigned int wid, int enable)
 Sets or removes the border of a window.
void window_handleKeys (unsigned int wid, int(*keyhandler)(unsigned int, SDL_Keycode, SDL_Keymod, int))
 Sets the key handler for the window.
void window_handleEvents (unsigned int wid, int(*eventhandler)(unsigned int, SDL_Event *))
 Sets the event handler for the window.
void widget_cleanup (Widget *widget)
 Destroys a widget.
void widget_setStatus (Widget *wgt, WidgetStatus sts)
void toolkit_closeAll (void)
 Closes all open toolkit windows.
void window_close (unsigned int wid, const char *str)
 Helper function to automatically close the window calling it.
void window_destroy (unsigned int wid)
 Kills the window.
void window_kill (Window *wdw)
 Kills the window (and children).
int widget_exists (unsigned int wid, const char *wgtname)
 Checks to see if a widget exists.
void window_destroyWidget (unsigned int wid, const char *wgtname)
 Destroys a widget in a window.
void window_clearWidgets (unsigned int wid)
void toolkit_drawOutlineThick (int x, int y, int w, int h, int b, int thick, const glColour *c, const glColour *lc)
 Draws an outline.
void toolkit_drawOutline (int x, int y, int w, int h, int b, const glColour *c, const glColour *lc)
 Draws an outline.
void toolkit_drawRect (int x, int y, int w, int h, const glColour *c, const glColour *lc)
 Draws a rectangle.
void toolkit_drawTriangle (int x1, int y1, int x2, int y2, int x3, int y3, const glColour *c)
 Draws a rectangle.
void toolkit_drawAltText (int bx, int by, const char *alt)
 Draws an alt text.
void window_render (Window *w, int top)
 Renders a window.
void window_renderDynamic (Window *w)
 Renders the dynamic components of a window.
void window_renderOverlay (Window *w)
 Renders the window overlays.
void toolkit_drawScrollbar (int x, int y, int w, int h, double pos)
 Draws a scrollbar.
void toolkit_render (double dt)
 Renders the windows.
void toolkit_rerender (void)
 Marks the toolkit for needing a full rerender.
int toolkit_input (SDL_Event *event)
 Toolkit input handled here.
int toolkit_inputWindow (Window *wdw, SDL_Event *event, int purge)
 Toolkit window input is handled here.
Uint32 toolkit_inputTranslateCoords (const Window *w, SDL_Event *event, int *x, int *y, int *rx, int *ry)
 Translates the mouse coordinates.
static int toolkit_mouseEventSingle (Window *w, SDL_Event *event, Widget *wgt, int x, int y, int rx, int ry)
static int toolkit_mouseEventReverse (Window *w, SDL_Event *event, Widget *wgt, int x, int y, int rx, int ry)
static SDL_Keymod toolkit_mapMod (SDL_Keycode key)
 Maps modifier keysyms (ctrl, alt, shift) to SDL_Keymods.
static void toolkit_regKey (SDL_Keycode key)
 Registers a key as down (for key repetition).
static void toolkit_unregKey (SDL_Keycode key)
 Unregisters a key.
void toolkit_clearKey (void)
 Clears the registered keys.
void toolkit_update (void)
 Updates the toolkit input for repeating keys.
void toolkit_focusClear (Window *wdw)
 Clears the window focus.
void toolkit_focusSanitize (Window *wdw)
 Sanitizes the focus of a window.
void toolkit_nextFocus (Window *wdw)
 Focus next widget.
void toolkit_prevFocus (Window *wdw)
 Focus previous widget.
void toolkit_focusWidget (Window *wdw, Widget *wgt)
 Focuses a widget in a window. No-op if it's not focusable or already focused.
void toolkit_defocusWidget (Window *wdw, Widget *wgt)
 Defocuses the focused widget in a window. No-op if it's not (de)focusable or already defocused, else voids the window's focus.
Window * toolkit_getActiveWindow (void)
 Gets the active window in the toolkit.
Widget * toolkit_getFocus (Window *wdw)
 Gets the focused widget in a window.
void window_setFocus (unsigned int wid, const char *wgtname)
 Sets the focused widget in a window.
char * window_getFocus (unsigned int wid)
 Gets the focused widget in a window (does strdup!!).
void window_raise (unsigned int wid)
 Raises a window (causes all other windows to appear below it).
void window_lower (unsigned int wid)
 Lowers a window (causes all other windows to appear above it).
void toolkit_resize (void)
 Repositions windows and their children if resolution changes.
int toolkit_init (void)
 Initializes the toolkit.
void toolkit_exit (void)
 Exits the toolkit.

Variables

static unsigned int genwid = 0
static int toolkit_needsRender
static int toolkit_delayCounter
static Window * windows
static SDL_Keycode input_key = 0
static SDL_Keymod input_mod = 0
const glColour * toolkit_colLight = &cGrey50
const glColour * toolkit_col = &cGrey20
const glColour * toolkit_colDark = &cGrey5
const glColour * tab_active = &cGrey20
const glColour * tab_activeB = &cGrey10
const glColour * tab_inactive = &cGrey15
const glColour * tab_inactiveB = &cGrey10
const glColour * tab_background = &cBlack
static gl_vbo * toolkit_vbo
static GLsizei toolkit_vboColourOffset

Detailed Description

Handles windows and widgets.

Definition in file toolkit.c.

Macro Definition Documentation

◆ INPUT_DELAY

#define INPUT_DELAY   conf.repeat_delay

Delay before starting to repeat.

Definition at line 23 of file toolkit.c.

◆ INPUT_FREQ

#define INPUT_FREQ   conf.repeat_freq

Interval between repetition.

Definition at line 24 of file toolkit.c.

◆ MIN_WINDOWS

#define MIN_WINDOWS   4

Minimum windows to prealloc.

Definition at line 36 of file toolkit.c.

Function Documentation

◆ toolkit_clearKey()

void toolkit_clearKey ( void )

Clears the registered keys.

Definition at line 2051 of file toolkit.c.

◆ toolkit_closeAll()

void toolkit_closeAll ( void )

Closes all open toolkit windows.

Definition at line 1016 of file toolkit.c.

◆ toolkit_defocusWidget()

void toolkit_defocusWidget ( Window * wdw,
Widget * wgt )

Defocuses the focused widget in a window. No-op if it's not (de)focusable or already defocused, else voids the window's focus.

Definition at line 2415 of file toolkit.c.

◆ toolkit_delay()

void toolkit_delay ( void )

Delays the toolkit purge by an iteration, useful for dialogues.

Definition at line 105 of file toolkit.c.

◆ toolkit_drawAltText()

void toolkit_drawAltText ( int bx,
int by,
const char * alt )

Draws an alt text.

Parameters
bxX position to draw at.
byY position to draw at.
altText to draw.

Definition at line 1460 of file toolkit.c.

◆ toolkit_drawOutline()

void toolkit_drawOutline ( int x,
int y,
int w,
int h,
int b,
const glColour * c,
const glColour * lc )

Draws an outline.

If lc is NULL, colour will be flat.

Parameters
xX position to draw at.
yY position to draw at.
wWidth.
hHeight.
bBorder width.
cColour.
lcLight colour.

Definition at line 1318 of file toolkit.c.

◆ toolkit_drawOutlineThick()

void toolkit_drawOutlineThick ( int x,
int y,
int w,
int h,
int b,
int thick,
const glColour * c,
const glColour * lc )

Draws an outline.

If lc is NULL, colour will be flat.

Parameters
xX position to draw at.
yY position to draw at.
wWidth.
hHeight.
bBorder width.
thickThickness of the border.
cColour.
lcLight colour.

Definition at line 1239 of file toolkit.c.

◆ toolkit_drawRect()

void toolkit_drawRect ( int x,
int y,
int w,
int h,
const glColour * c,
const glColour * lc )

Draws a rectangle.

If lc is NULL, colour will be flat.

Parameters
xX position to draw at.
yY position to draw at.
wWidth.
hHeight.
cColour.
lcLight colour.

Definition at line 1370 of file toolkit.c.

◆ toolkit_drawScrollbar()

void toolkit_drawScrollbar ( int x,
int y,
int w,
int h,
double pos )

Draws a scrollbar.

Parameters
xX position of scrollbar.
yY position of scrollbar.
wWidth of the scrollbar.
hHeight of the scrollbar.
posPosition at [0:1].

Definition at line 1609 of file toolkit.c.

◆ toolkit_drawTriangle()

void toolkit_drawTriangle ( int x1,
int y1,
int x2,
int y2,
int x3,
int y3,
const glColour * c )

Draws a rectangle.

Parameters
x1X position of corner 1.
y1Y position to corner 1.
x2X position of corner 2.
y2Y position to corner 2.
x3X position of corner 3.
y3Y position to corner 3.
cColour.

Definition at line 1420 of file toolkit.c.

◆ toolkit_exit()

void toolkit_exit ( void )

Exits the toolkit.

Definition at line 2682 of file toolkit.c.

◆ toolkit_expose()

void toolkit_expose ( Window * wdw,
int expose )
static

Exposes or hides a window and notifies its widgets.

Parameters
wdwWindow to change exposure of.
exposeWhether exposing or hiding.

Definition at line 2266 of file toolkit.c.

◆ toolkit_focusClear()

void toolkit_focusClear ( Window * wdw)

Clears the window focus.

Definition at line 2290 of file toolkit.c.

◆ toolkit_focusSanitize()

void toolkit_focusSanitize ( Window * wdw)

Sanitizes the focus of a window.

Makes sure the window has a focusable widget focused.

Definition at line 2304 of file toolkit.c.

◆ toolkit_focusWidget()

void toolkit_focusWidget ( Window * wdw,
Widget * wgt )

Focuses a widget in a window. No-op if it's not focusable or already focused.

Definition at line 2398 of file toolkit.c.

◆ toolkit_getActiveWindow()

Window * toolkit_getActiveWindow ( void )

Gets the active window in the toolkit.

Returns
The active window in the toolkit.

Definition at line 2447 of file toolkit.c.

◆ toolkit_getFocus()

Widget * toolkit_getFocus ( Window * wdw)

Gets the focused widget in a window.

Parameters
wdwThe window to get the focused widget from.
Returns
The focused widget.

Definition at line 2464 of file toolkit.c.

◆ toolkit_init()

int toolkit_init ( void )

Initializes the toolkit.

Returns
0 on success.

Definition at line 2664 of file toolkit.c.

◆ toolkit_input()

int toolkit_input ( SDL_Event * event)

Toolkit input handled here.

Parameters
eventEvent to handle.
Returns
1 if input was used, 0 if it wasn't.

Definition at line 1686 of file toolkit.c.

◆ toolkit_inputTranslateCoords()

Uint32 toolkit_inputTranslateCoords ( const Window * w,
SDL_Event * event,
int * x,
int * y,
int * rx,
int * ry )

Translates the mouse coordinates.

Parameters
wWindow to translate coords for.
eventEvent to translate coords.
[out]xResulting X coord in window space.
[out]yResulting Y coord in window space.
[out]rxRelative X movement (only valid for motion).
[out]ryRelative Y movement (only valid for motion).
Returns
The type of the event.

Definition at line 1776 of file toolkit.c.

◆ toolkit_inputWindow()

int toolkit_inputWindow ( Window * wdw,
SDL_Event * event,
int purge )

Toolkit window input is handled here.

Definition at line 1700 of file toolkit.c.

◆ toolkit_isFocusable()

int toolkit_isFocusable ( const Widget * wgt)
static

Checks to see if a widget is focusable.

Parameters
wgtWidget to check if is focusable.
Returns
1 if it's focusable, 0 if it isn't.

Definition at line 2434 of file toolkit.c.

◆ toolkit_isOpen()

int toolkit_isOpen ( void )

Checks to see if the toolkit is open.

Returns
1 if the toolkit is open.

Definition at line 93 of file toolkit.c.

◆ toolkit_keyEvent()

int toolkit_keyEvent ( Window * wdw,
SDL_Event * event )
static

Handles keyboard events.

Parameters
wdwWindow receiving the key event.
eventKeyboard event to handle.
Returns
1 if the event is used, 0 if it isn't.

Definition at line 2062 of file toolkit.c.

◆ toolkit_mapMod()

SDL_Keymod toolkit_mapMod ( SDL_Keycode key)
static

Maps modifier keysyms (ctrl, alt, shift) to SDL_Keymods.

Parameters
keyKey to convert.
Returns
The SDL_Keymod corresponding to the key, or 0 if none correspond.

Definition at line 1991 of file toolkit.c.

◆ toolkit_mouseEvent()

int toolkit_mouseEvent ( Window * w,
SDL_Event * event )
static

Handles the mouse events.

Parameters
wWindow receiving the mouse event.
eventMouse event to handle.

Definition at line 1839 of file toolkit.c.

◆ toolkit_mouseEventReverse()

int toolkit_mouseEventReverse ( Window * w,
SDL_Event * event,
Widget * wgt,
int x,
int y,
int rx,
int ry )
static

Definition at line 1822 of file toolkit.c.

◆ toolkit_mouseEventSingle()

int toolkit_mouseEventSingle ( Window * w,
SDL_Event * event,
Widget * wgt,
int x,
int y,
int rx,
int ry )
static

Definition at line 1809 of file toolkit.c.

◆ toolkit_mouseEventWidget()

int toolkit_mouseEventWidget ( Window * w,
Widget * wgt,
SDL_Event * event,
int x,
int y,
int rx,
int ry )
static

Handle widget mouse input.

Parameters
wWindow to which widget belongs.
wgtWidget receiving event.
eventEvent received by the window.
xX coordinate in window space.
yY coordinate in window space.
rxRelative X movement (only valid for motion).
ryRelative Y movement (only valid for motion).

Definition at line 1863 of file toolkit.c.

◆ toolkit_nextFocus()

void toolkit_nextFocus ( Window * wdw)

Focus next widget.

Definition at line 2332 of file toolkit.c.

◆ toolkit_prevFocus()

void toolkit_prevFocus ( Window * wdw)

Focus previous widget.

Definition at line 2362 of file toolkit.c.

◆ toolkit_purgeDead()

void toolkit_purgeDead ( void )
static

Purges the dead windows.

Definition at line 2178 of file toolkit.c.

◆ toolkit_regKey()

void toolkit_regKey ( SDL_Keycode key)
static

Registers a key as down (for key repetition).

Parameters
keyKey to register as down.

Definition at line 2016 of file toolkit.c.

◆ toolkit_render()

void toolkit_render ( double dt)

Renders the windows.

Definition at line 1625 of file toolkit.c.

◆ toolkit_rerender()

void toolkit_rerender ( void )

Marks the toolkit for needing a full rerender.

Definition at line 1675 of file toolkit.c.

◆ toolkit_resize()

void toolkit_resize ( void )

Repositions windows and their children if resolution changes.

Definition at line 2612 of file toolkit.c.

◆ toolkit_setPos()

void toolkit_setPos ( const Window * wdw,
Widget * wgt,
int x,
int y )

Sets the internal widget position.

Parameters
wdwWindow to which the widget belongs.
wgtWidget to set position of.
xX position to use.
yY position to use.

Definition at line 118 of file toolkit.c.

◆ toolkit_setWindowPos()

void toolkit_setWindowPos ( Window * wdw,
int x,
int y )

Moves a window to the specified coordinates.

Parameters
wdwWindow to move.
xX position.
yY position.

Definition at line 140 of file toolkit.c.

◆ toolkit_textEvent()

int toolkit_textEvent ( Window * wdw,
SDL_Event * event )
static

Definition at line 2154 of file toolkit.c.

◆ toolkit_unregKey()

void toolkit_unregKey ( SDL_Keycode key)
static

Unregisters a key.

Parameters
keyKey to unregister.

Definition at line 2035 of file toolkit.c.

◆ toolkit_update()

void toolkit_update ( void )

Updates the toolkit input for repeating keys.

Definition at line 2241 of file toolkit.c.

◆ widget_cleanup()

void widget_cleanup ( Widget * widget)

Destroys a widget.

Parameters
widgetWidget to destroy.

Definition at line 996 of file toolkit.c.

◆ widget_exists()

int widget_exists ( unsigned int wid,
const char * wgtname )

Checks to see if a widget exists.

Parameters
widWindow to check widget in.
wgtnameName of the widget to check;
Returns
1 if the widget exists.

Definition at line 1144 of file toolkit.c.

◆ widget_isCovered()

int widget_isCovered ( unsigned int wid,
const char * name,
int x,
int y )

Checks to see if a widget is covered or not.

Definition at line 561 of file toolkit.c.

◆ widget_kill()

void widget_kill ( Widget * wgt)
static

Destroy a widget really.

Definition at line 1218 of file toolkit.c.

◆ widget_setStatus()

void widget_setStatus ( Widget * wgt,
WidgetStatus sts )

Definition at line 1006 of file toolkit.c.

◆ window_canFocusWidget()

void window_canFocusWidget ( unsigned int wid,
const char * name,
int canfocus )

Allows or disallows focusing a widget.

Parameters
widID of the window to get widget from.
nameName of the widget to resize
canfocusWhether or not the widget should be able to be focused.

Definition at line 517 of file toolkit.c.

◆ window_cleanup()

void window_cleanup ( Window * wdw)
static

Cleans up the window, should be done before window_remove.

Parameters
wdwWindow to clean up.
See also
window_remove

Definition at line 1104 of file toolkit.c.

◆ window_clearWidgets()

void window_clearWidgets ( unsigned int wid)

Definition at line 1195 of file toolkit.c.

◆ window_close()

void window_close ( unsigned int wid,
const char * str )

Helper function to automatically close the window calling it.

Parameters
widWindow to close.
strUnused.

Definition at line 1028 of file toolkit.c.

◆ window_create()

unsigned int window_create ( const char * name,
const char * displayname,
const int x,
const int y,
const int w,
const int h )

Creates a window.

Parameters
nameWindow name to use internally - should be unique.
displaynameTitle displayed on the window.
xX position of the window (-1 centers).
yY position of the window (-1 centers).
wWidth of the window (-1 fullscreen).
hHeight of the window (-1 fullscreen).
Returns
Newly created window's ID.

Definition at line 688 of file toolkit.c.

◆ window_createFlags()

unsigned int window_createFlags ( const char * name,
const char * displayname,
const int x,
const int y,
const int w,
const int h,
unsigned int flags )

Creates a window.

Parameters
nameWindow name to use internally - should be unique.
displaynameTitle displayed on the window.
xX position of the window (-1 centers).
yY position of the window (-1 centers).
wWidth of the window (-1 fullscreen).
hHeight of the window (-1 fullscreen).
flagsInitial flags to set.
Returns
Newly created window's ID.

Definition at line 706 of file toolkit.c.

◆ window_destroy()

void window_destroy ( unsigned int wid)

Kills the window.

Parameters
widID of window to destroy.

Definition at line 1039 of file toolkit.c.

◆ window_destroyWidget()

void window_destroyWidget ( unsigned int wid,
const char * wgtname )

Destroys a widget in a window.

Parameters
widWindow to destroy widget in.
wgtnameName of the widget to destroy.

Definition at line 1167 of file toolkit.c.

◆ window_dimWidget()

void window_dimWidget ( unsigned int wid,
const char * name,
int * w,
int * h )

Gets the dimensions of a widget.

Parameters
widID of the window that contains the widget.
nameName of the widget to get dimensions of.
[out]wWidth of the widget or -1 on error.
[out]hHeight of the widget or -1 on error.

Definition at line 415 of file toolkit.c.

◆ window_dimWindow()

void window_dimWindow ( unsigned int wid,
int * w,
int * h )

Gets the dimensions of a window.

Parameters
widID of the window to get dimension of.
[out]wWidth of the window or -1 on error.
[out]hHeight of the window or -1 on error.

Definition at line 370 of file toolkit.c.

◆ window_exists()

int window_exists ( const char * wdwname)

Checks to see if a window exists.

Parameters
wdwnameName of the window to check.
Returns
1 if it exists, 0 if it doesn't.

Definition at line 591 of file toolkit.c.

◆ window_existsID()

int window_existsID ( unsigned int wid)

Checks to see if a window with a certain ID exists.

Parameters
widID of the window to check.
Returns
1 if it exists, 0 if it doesn't.

Definition at line 608 of file toolkit.c.

◆ window_get()

unsigned int window_get ( const char * wdwname)

Gets the ID of a window.

Note
Gets the top window matching the ID first.
Parameters
wdwnameName of the window to get ID of.
Returns
ID of the window.

Definition at line 662 of file toolkit.c.

◆ window_getData()

void * window_getData ( unsigned int wid)

Gets the custom data of a window.

Parameters
widWindow to get custom data of.
Returns
The custom data or NULL if not applicable.

Definition at line 923 of file toolkit.c.

◆ window_getFocus()

char * window_getFocus ( unsigned int wid)

Gets the focused widget in a window (does strdup!!).

Parameters
widID of the window to get widget from.
Returns
The focused widget's name (strdup()ed string or NULL).

Definition at line 2514 of file toolkit.c.

◆ window_getParent()

unsigned int window_getParent ( unsigned int wid)

Gets the window's parent.

Parameters
widWindow to get parent of.
Returns
Parent of the window or 0 on error.

Definition at line 804 of file toolkit.c.

◆ window_getwgt()

Widget * window_getwgt ( unsigned int wid,
const char * name )

Gets a widget from window id and widgetname.

Parameters
widID of the window to get widget from.
nameName of the widget to get.
Returns
Widget matching name in the window.

Definition at line 345 of file toolkit.c.

◆ window_handleEvents()

void window_handleEvents ( unsigned int wid,
int(* eventhandler )(unsigned int, SDL_Event *) )

Sets the event handler for the window.

This function is called every time the window receives input.

Definition at line 979 of file toolkit.c.

◆ window_handleKeys()

void window_handleKeys ( unsigned int wid,
int(* keyhandler )(unsigned int, SDL_Keycode, SDL_Keymod, int) )

Sets the key handler for the window.

This function is only called if neither the active widget nor the window itself grabs the input.

Definition at line 961 of file toolkit.c.

◆ window_isTop()

int window_isTop ( unsigned int wid)

Checks to see if a window is at the top.

Parameters
widindow ID to see if is top.

Definition at line 544 of file toolkit.c.

◆ window_kill()

void window_kill ( Window * wdw)

Kills the window (and children).

Parameters
wdwWindow to kill.

Definition at line 1088 of file toolkit.c.

◆ window_lower()

void window_lower ( unsigned int wid)

Lowers a window (causes all other windows to appear above it).

Parameters
widWindow to lower.

Definition at line 2577 of file toolkit.c.

◆ window_move()

void window_move ( unsigned int wid,
int x,
int y )

Moves a window to the specified coordinates.

Parameters
widID of the window to move.
xX position.
yY position.

Definition at line 176 of file toolkit.c.

◆ window_moveWidget()

void window_moveWidget ( unsigned int wid,
const char * name,
int x,
int y )

Moves a widget.

Parameters
widID of the window to get widget from.
nameName of the widget to set position to.
xNew X position to set widget to.
yNew Y position to set widget to.

Definition at line 463 of file toolkit.c.

◆ window_newWidget()

Widget * window_newWidget ( Window * w,
const char * name )

Allocates room for a new widget.

Parameters
wWindow to create widget in.
nameName of the widget to create.
Returns
Newly allocated widget.

Definition at line 223 of file toolkit.c.

◆ window_onClose()

void window_onClose ( unsigned int wid,
void(* fptr )(unsigned int, const char *) )

Sets the default close function of the window.

This function is called when the window is closed.

Parameters
widWindow to set close function of.
fptrFunction to trigger when window is closed, parameter is window id and name.

Definition at line 824 of file toolkit.c.

◆ window_posWidget()

void window_posWidget ( unsigned int wid,
const char * name,
int * x,
int * y )

Gets a widget's position.

Parameters
widID of the window to get widget from.
nameName of the widget to get position of.
[out]xX position of the widget.
[out]yY position of the widget.

Definition at line 441 of file toolkit.c.

◆ window_posWindow()

void window_posWindow ( unsigned int wid,
int * x,
int * y )

Gets the dimensions of a window.

Parameters
widID of the window to get dimension of.
[out]xX position of the window or -1 on error.
[out]yY position of the window or -1 on error.

Definition at line 392 of file toolkit.c.

◆ window_raise()

void window_raise ( unsigned int wid)

Raises a window (causes all other windows to appear below it).

Parameters
widWindow to raise.

Definition at line 2534 of file toolkit.c.

◆ window_remove()

void window_remove ( Window * wdw)
static

Frees up a window. Make sure to clean up the window first.

Parameters
wdwWindow to remove.
See also
window_cleanup

Definition at line 1118 of file toolkit.c.

◆ window_render()

void window_render ( Window * w,
int top )

Renders a window.

Parameters
wWindow to render.
topWhether or not the window is at the top.

Definition at line 1538 of file toolkit.c.

◆ window_renderBorder()

void window_renderBorder ( const Window * w)
static

Renders a window border.

Parameters
wWindow to render

Definition at line 1502 of file toolkit.c.

◆ window_renderDynamic()

void window_renderDynamic ( Window * w)

Renders the dynamic components of a window.

Definition at line 1571 of file toolkit.c.

◆ window_renderOverlay()

void window_renderOverlay ( Window * w)

Renders the window overlays.

Parameters
wWindow to render overlays of.

Definition at line 1592 of file toolkit.c.

◆ window_resize()

void window_resize ( unsigned int wid,
int w,
int h )

Resizes the window.

Parameters
widWindow ID.
wWidth to change to (or fullscreen if -1).
hHeight to change to (or fullscreen if -1).

Definition at line 193 of file toolkit.c.

◆ window_resizeWidget()

void window_resizeWidget ( unsigned int wid,
const char * name,
int w,
int h )

Resizes a widget.

Parameters
widID of the window to get widget from.
nameName of the widget to resize
wNew width.
hNew height.

Definition at line 490 of file toolkit.c.

◆ window_setAccept()

void window_setAccept ( unsigned int wid,
void(* accept )(unsigned int, const char *) )

Sets the default accept function of the window.

This function is called whenever 'enter' is pressed and the current widget does not catch it. NULL disables the accept function.

Parameters
widID of the window to set the accept function.
acceptFunction to trigger when window is "accepted". Parameter passed is window name.

Definition at line 846 of file toolkit.c.

◆ window_setBorder()

void window_setBorder ( unsigned int wid,
int enable )

Sets or removes the border of a window.

Default is enabled.

Parameters
widID of the window to enable/disable border.
enableWhether or not to enable rendering of the border.

Definition at line 942 of file toolkit.c.

◆ window_setCancel()

void window_setCancel ( unsigned int wid,
void(* cancel )(unsigned int, const char *) )

Sets the default cancel function of the window.

This function is called whenever 'escape' is hit and the current widget does not catch it. NULL disables the cancel function.

Parameters
widID of the window to set cancel function.
cancelFunction to trigger when window is "cancelled". Parameter passed is window name.

Definition at line 868 of file toolkit.c.

◆ window_setData()

void window_setData ( unsigned int wid,
void * data )

Sets custom data for a window.

Parameters
widWindow to set custom data of.
dataData to set.

Definition at line 906 of file toolkit.c.

◆ window_setDisplayname()

int window_setDisplayname ( unsigned int wid,
const char * displayname )

Sets the displayname of a window.

Parameters
widID of the window.
displaynameDisplay name to set to.
Returns
0 on success.

Definition at line 625 of file toolkit.c.

◆ window_setDynamic()

void window_setDynamic ( unsigned int wid,
int dynamic )

Sets a window as dynamic, so that it is drawn every frame completely.

Parameters
widID of the window.
dynamicWhether or not to set as dynamic.

Definition at line 643 of file toolkit.c.

◆ window_setFocus()

void window_setFocus ( unsigned int wid,
const char * wgtname )

Sets the focused widget in a window.

Parameters
widID of the window to get widget from.
wgtnameName of the widget to set focus to, or NULL to clear the focus.

Definition at line 2488 of file toolkit.c.

◆ window_setOnFocus()

void window_setOnFocus ( unsigned int wid,
void(* focus )(unsigned int) )

Sets the focus function of the window.

This function is called whenever the window is focused or unfocused.

Parameters
widID of the window to set cancel function.
focusFunction to trigger when window focus status changes. Parameter passed is window name.

Definition at line 889 of file toolkit.c.

◆ window_setParent()

void window_setParent ( unsigned int wid,
unsigned int parent )

Sets a window as a window's parent.

When a window's parent closes, it closes the window also.

Parameters
widWindow to set as child.
parentWindow to set as parent.

Definition at line 787 of file toolkit.c.

◆ window_wget()

Window * window_wget ( unsigned int wid)

Gets a Window by ID.

Parameters
widID of the window to get.
Returns
Window matching wid.

Definition at line 298 of file toolkit.c.

◆ window_wgetNameW()

Window * window_wgetNameW ( const char * name)

Gets a Window by name, without warning.

Parameters
nameName of the window to get.
Returns
Window matching wid.

Definition at line 330 of file toolkit.c.

◆ window_wgetW()

Window * window_wgetW ( unsigned int wid)

Gets a Window by ID, without warning.

Parameters
widID of the window to get.
Returns
Window matching wid.

Definition at line 316 of file toolkit.c.

Variable Documentation

◆ genwid

unsigned int genwid = 0
static

Generates unique window ids, > 0

Definition at line 26 of file toolkit.c.

◆ input_key

SDL_Keycode input_key = 0
static

Current pressed key.

Definition at line 43 of file toolkit.c.

◆ input_mod

SDL_Keymod input_mod = 0
static

Current pressed modifier.

Definition at line 44 of file toolkit.c.

◆ tab_active

const glColour* tab_active = &cGrey20

Light outline colour.

Definition at line 56 of file toolkit.c.

◆ tab_activeB

const glColour* tab_activeB = &cGrey10

Light outline colour.

Definition at line 57 of file toolkit.c.

◆ tab_background

const glColour* tab_background = &cBlack

Dark outline colour.

Definition at line 60 of file toolkit.c.

◆ tab_inactive

const glColour* tab_inactive = &cGrey15

Normal outline colour.

Definition at line 58 of file toolkit.c.

◆ tab_inactiveB

const glColour* tab_inactiveB = &cGrey10

Normal outline colour.

Definition at line 59 of file toolkit.c.

◆ toolkit_col

const glColour* toolkit_col = &cGrey20

Normal outline colour.

Definition at line 50 of file toolkit.c.

◆ toolkit_colDark

const glColour* toolkit_colDark = &cGrey5

Dark outline colour.

Definition at line 51 of file toolkit.c.

◆ toolkit_colLight

const glColour* toolkit_colLight = &cGrey50

Light outline colour.

Definition at line 49 of file toolkit.c.

◆ toolkit_delayCounter

int toolkit_delayCounter
static
Initial value:
=
0

Horrible hack around secondary loop.

Definition at line 30 of file toolkit.c.

◆ toolkit_needsRender

int toolkit_needsRender
static
Initial value:
=
1

Whether or not toolkit needs a render.

Definition at line 28 of file toolkit.c.

◆ toolkit_vbo

gl_vbo* toolkit_vbo
static

Toolkit VBO.

Definition at line 65 of file toolkit.c.

◆ toolkit_vboColourOffset

GLsizei toolkit_vboColourOffset
static

Colour offset.

Definition at line 66 of file toolkit.c.

◆ windows

Window* windows
static
Initial value:
=
NULL

Window linked list, not to be confused with MS windows.

Definition at line 37 of file toolkit.c.