naev 0.10.4
Macros | Functions | Variables
toolkit.c File Reference

Handles windows and widgets. More...

#include "toolkit.h"
#include "conf.h"
#include "dialogue.h"
#include "input.h"
#include "log.h"
#include "opengl.h"
#include "pause.h"
#include "nmath.h"
#include "tk/toolkit_priv.h"

Go to the source code of this file.

Macros

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

Functions

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

Variables

static unsigned int genwid = 0
 
static int toolkit_delayCounter = 0
 
static const double WINDOW_FADEIN_TIME = 0.05
 
static const double WINDOW_FADEOUT_TIME = 0.05
 
static Window * windows = NULL
 
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 26 of file toolkit.c.

◆ INPUT_FREQ

#define INPUT_FREQ   conf.repeat_freq

Interval between repetition.

Definition at line 27 of file toolkit.c.

◆ MIN_WINDOWS

#define MIN_WINDOWS   3

Minimum windows to prealloc.

Definition at line 39 of file toolkit.c.

Function Documentation

◆ toolkit_clearKey()

void toolkit_clearKey ( void  )

Clears the registered keys.

Definition at line 2032 of file toolkit.c.

◆ toolkit_closeAll()

void toolkit_closeAll ( void  )

Closes all open toolkit windows.

Definition at line 1019 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 2389 of file toolkit.c.

◆ toolkit_delay()

void toolkit_delay ( void  )

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

Definition at line 107 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 1426 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 1290 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 1213 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 1340 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 1574 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 1388 of file toolkit.c.

◆ toolkit_exit()

void toolkit_exit ( void  )

Exits the toolkit.

Definition at line 2651 of file toolkit.c.

◆ toolkit_expose()

static 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 2243 of file toolkit.c.

◆ toolkit_focusClear()

void toolkit_focusClear ( Window *  wdw)

Clears the window focus.

Definition at line 2267 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 2281 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 2374 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 2419 of file toolkit.c.

◆ toolkit_getFocus()

static Widget * toolkit_getFocus ( Window *  wdw)
static

Gets the focused widget in a window.

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

Definition at line 2436 of file toolkit.c.

◆ toolkit_init()

int toolkit_init ( void  )

Initializes the toolkit.

Returns
0 on success.

Definition at line 2633 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 1674 of file toolkit.c.

◆ toolkit_inputTranslateCoords()

Uint32 toolkit_inputTranslateCoords ( 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 1757 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 1688 of file toolkit.c.

◆ toolkit_isFocusable()

static int toolkit_isFocusable ( 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 2406 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 95 of file toolkit.c.

◆ toolkit_keyEvent()

static 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 2043 of file toolkit.c.

◆ toolkit_mapMod()

static 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 1969 of file toolkit.c.

◆ toolkit_mouseEvent()

static 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 1823 of file toolkit.c.

◆ toolkit_mouseEventReverse()

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

Definition at line 1806 of file toolkit.c.

◆ toolkit_mouseEventSingle()

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

Definition at line 1792 of file toolkit.c.

◆ toolkit_mouseEventWidget()

static 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 1847 of file toolkit.c.

◆ toolkit_nextFocus()

void toolkit_nextFocus ( Window *  wdw)

Focus next widget.

Definition at line 2309 of file toolkit.c.

◆ toolkit_prevFocus()

void toolkit_prevFocus ( Window *  wdw)

Focus previous widget.

Definition at line 2339 of file toolkit.c.

◆ toolkit_purgeDead()

static void toolkit_purgeDead ( void  )
static

Purges the dead windows.

Definition at line 2156 of file toolkit.c.

◆ toolkit_regKey()

static void toolkit_regKey ( SDL_Keycode  key)
static

Registers a key as down (for key repetition).

Parameters
keyKey to register as down.

Definition at line 1994 of file toolkit.c.

◆ toolkit_render()

void toolkit_render ( double  dt)

Renders the windows.

Definition at line 1590 of file toolkit.c.

◆ toolkit_reposition()

void toolkit_reposition ( void  )

Repositions windows and their children if resolution changes.

Definition at line 2582 of file toolkit.c.

◆ toolkit_setPos()

void toolkit_setPos ( 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 120 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 142 of file toolkit.c.

◆ toolkit_textEvent()

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

Definition at line 2131 of file toolkit.c.

◆ toolkit_unregKey()

static void toolkit_unregKey ( SDL_Keycode  key)
static

Unregisters a key.

Parameters
keyKey to unregister.

Definition at line 2015 of file toolkit.c.

◆ toolkit_update()

void toolkit_update ( void  )

Updates the toolkit input for repeating keys.

Definition at line 2218 of file toolkit.c.

◆ widget_cleanup()

void widget_cleanup ( Widget *  widget)

Destroys a widget.

Parameters
widgetWidget to destroy.

Definition at line 1006 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 1139 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 568 of file toolkit.c.

◆ widget_kill()

static void widget_kill ( Widget *  wgt)
static

Destroy a widget really.

Definition at line 1192 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 523 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 1031 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 696 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 714 of file toolkit.c.

◆ window_destroy()

void window_destroy ( unsigned int  wid)

Kills the window.

Parameters
widID of window to destroy.

Definition at line 1042 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 1162 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 416 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 371 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 598 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 614 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 671 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 934 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 2486 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 820 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 346 of file toolkit.c.

◆ window_handleEvents()

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

Sets the event handler for the window.

This function is called every time the window receives input.

Definition at line 989 of file toolkit.c.

◆ window_handleKeys()

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

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 972 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 551 of file toolkit.c.

◆ window_kill()

void window_kill ( Window *  wdw)

Kills the window (and children).

Parameters
wdwWindow to kill.

Definition at line 1090 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 2548 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 180 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 467 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 227 of file toolkit.c.

◆ window_onCleanup()

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

Sets the cleanup function of the window.

Parameters
widWindow to set cleanup function of.
fptrFunction to trigger when window is freed. Parameter is the window id and name.

Definition at line 858 of file toolkit.c.

◆ window_onClose()

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

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 840 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 442 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 393 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 2506 of file toolkit.c.

◆ window_remove()

static void window_remove ( Window *  wdw)
static

Frees up a window.

Parameters
wdwWindow to remove.

Definition at line 1103 of file toolkit.c.

◆ window_render()

void window_render ( Window *  w)

Renders a window.

Parameters
wWindow to render.

Definition at line 1505 of file toolkit.c.

◆ window_renderBorder()

static void window_renderBorder ( Window *  w)
static

Renders a window border.

Parameters
wWindow to render

Definition at line 1467 of file toolkit.c.

◆ window_renderOverlay()

void window_renderOverlay ( Window *  w)

Renders the window overlays.

Parameters
wWindow to render overlays of.

Definition at line 1545 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 197 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 495 of file toolkit.c.

◆ window_setAccept()

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

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 879 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 953 of file toolkit.c.

◆ window_setCancel()

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

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 900 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 917 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 631 of file toolkit.c.

◆ window_setFade()

void window_setFade ( unsigned int  wid,
const SimpleShader *  shd,
double  length 
)

Sets the fade-in behaviour of a window.

Definition at line 646 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 2460 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 803 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 299 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 331 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 317 of file toolkit.c.

Variable Documentation

◆ genwid

unsigned int genwid = 0
static

Generates unique window ids, > 0

Definition at line 29 of file toolkit.c.

◆ input_key

SDL_Keycode input_key = 0
static

Current pressed key.

Definition at line 45 of file toolkit.c.

◆ input_mod

SDL_Keymod input_mod = 0
static

Current pressed modifier.

Definition at line 46 of file toolkit.c.

◆ tab_active

const glColour* tab_active = &cGrey20

Light outline colour.

Definition at line 58 of file toolkit.c.

◆ tab_activeB

const glColour* tab_activeB = &cGrey10

Light outline colour.

Definition at line 59 of file toolkit.c.

◆ tab_background

const glColour* tab_background = &cBlack

Dark outline colour.

Definition at line 62 of file toolkit.c.

◆ tab_inactive

const glColour* tab_inactive = &cGrey15

Normal outline colour.

Definition at line 60 of file toolkit.c.

◆ tab_inactiveB

const glColour* tab_inactiveB = &cGrey10

Normal outline colour.

Definition at line 61 of file toolkit.c.

◆ toolkit_col

const glColour* toolkit_col = &cGrey20

Normal outline colour.

Definition at line 52 of file toolkit.c.

◆ toolkit_colDark

const glColour* toolkit_colDark = &cGrey5

Dark outline colour.

Definition at line 53 of file toolkit.c.

◆ toolkit_colLight

const glColour* toolkit_colLight = &cGrey50

Light outline colour.

Definition at line 51 of file toolkit.c.

◆ toolkit_delayCounter

int toolkit_delayCounter = 0
static

Horrible hack around secondary loop.

Definition at line 31 of file toolkit.c.

◆ toolkit_vbo

gl_vbo* toolkit_vbo
static

Toolkit VBO.

Definition at line 67 of file toolkit.c.

◆ toolkit_vboColourOffset

GLsizei toolkit_vboColourOffset
static

Colour offset.

Definition at line 68 of file toolkit.c.

◆ WINDOW_FADEIN_TIME

const double WINDOW_FADEIN_TIME = 0.05
static

Time it takes to fade in for a window.

Definition at line 33 of file toolkit.c.

◆ WINDOW_FADEOUT_TIME

const double WINDOW_FADEOUT_TIME = 0.05
static

Time it takes to fade out for a window.

Definition at line 34 of file toolkit.c.

◆ windows

Window* windows = NULL
static

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

Definition at line 40 of file toolkit.c.