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

Go to the source code of this file.

Functions

static int list_handle_key (list_struct *list, SDLKey key)
static void list_draw_frame (list_struct *list)
static void list_row_color (list_struct *list, int row, SDL_Rect box)
static void list_row_highlight (list_struct *list, SDL_Rect box)
static void list_row_selected (list_struct *list, SDL_Rect box)
list_structlist_get_focused ()
void list_set_focus (list_struct *list)
void list_set_parent (list_struct *list, int px, int py)
list_structlist_create (uint32 id, uint32 max_rows, uint32 cols, int spacing)
void list_add (list_struct *list, uint32 row, uint32 col, const char *str)
void list_remove_row (list_struct *list, uint32 row)
void list_set_column (list_struct *list, uint32 col, int width, int spacing, const char *name, int centered)
void list_set_font (list_struct *list, int font)
void list_scrollbar_enable (list_struct *list)
static int list_scrollbar_get_size (list_struct *list, SDL_Rect *box)
static int list_slider_get_size (list_struct *list, SDL_Rect *box)
static void list_scrollbar_render (list_struct *list)
void list_show (list_struct *list, int x, int y)
void list_clear_rows (list_struct *list)
void list_clear (list_struct *list)
void list_offsets_ensure (list_struct *list)
void list_remove (list_struct *list)
void list_remove_all ()
static void list_scroll (list_struct *list, int up, int scroll)
int list_handle_keyboard (list_struct *list, SDL_KeyboardEvent *event)
int lists_handle_keyboard (SDL_KeyboardEvent *event)
int list_handle_mouse (list_struct *list, int mx, int my, SDL_Event *event)
int lists_handle_mouse (int mx, int my, SDL_Event *event)
list_structlist_exists (uint32 id)
static int list_compare_alpha (const void *a, const void *b)
void list_sort (list_struct *list, int type)
int list_set_selected (list_struct *list, const char *str, uint32 col)

Variables

static list_structlist_head = NULL
static list_structlist_tail = NULL
static int old_scrollbar_pos = 0

Detailed Description

Generic lists implementation.

Definition in file list.c.


Function Documentation

void list_add ( list_struct list,
uint32  row,
uint32  col,
const char *  str 
)

Add text to list.

Parameters:
listList to add to.
rowRow ID to add to. If it doesn't exist yet, it will be allocated.
colColumn ID.
strText to add.

Definition at line 228 of file list.c.

void list_clear ( list_struct list)

Clear and free list's entries.

Parameters:
listList.

Definition at line 636 of file list.c.

void list_clear_rows ( list_struct list)

Clear the list's rows.

Parameters:
listThe list.

Definition at line 605 of file list.c.

static int list_compare_alpha ( const void *  a,
const void *  b 
) [static]

Used for alphabetical sorting in list_sort().

Parameters:
aWhat to compare.
bWhat to compare against.
Returns:
Return value of strcmp() against the two entries.

Definition at line 1145 of file list.c.

list_struct* list_create ( uint32  id,
uint32  max_rows,
uint32  cols,
int  spacing 
)

Create new list.

Parameters:
idID of the list, one of List IDs.
max_rowsMaximum number of visible rows to show.
colsHow many columns per row.
spacingSpacing between column names and the actual rows start.
Returns:
The created list.

Definition at line 165 of file list.c.

static void list_draw_frame ( list_struct list) [static]

Draw a frame in which the rows will be drawn.

Parameters:
listList to draw the frame for.

Definition at line 44 of file list.c.

list_struct* list_exists ( uint32  id)

Utility function: checks if list with the specified ID already exists.

Parameters:
idList ID. One of List IDs.
Returns:
Pointer to the list if it exists, NULL otherwise.

Definition at line 1125 of file list.c.

list_struct* list_get_focused ( )

Get the currently focused list.

If there is no focused list but there is at least one visible list, will set the first list as the focused list.

Returns:
Focused list, or NULL if there are no visible lists at all.

Definition at line 90 of file list.c.

static int list_handle_key ( list_struct list,
SDLKey  key 
) [static]

Handle one key press.

Parameters:
listList to do the keypress for.
keyThe key.
Returns:
1 to allow key repeating, 0 otherwise.

Definition at line 804 of file list.c.

int list_handle_keyboard ( list_struct list,
SDL_KeyboardEvent *  event 
)

Handle keyboard event for the specified list.

Parameters:
listList.
eventThe keyboard event.
Returns:
1 if we handled the event, 0 otherwise.

Definition at line 870 of file list.c.

int list_handle_mouse ( list_struct list,
int  mx,
int  my,
SDL_Event *  event 
)

Handle mouse events for one list. Checking whether the mouse is over the list should have been done before calling this.

Parameters:
listThe list.
mxMouse X.
myMouse Y.
eventEvent.
Returns:
1 if the event was handled, 0 otherwise.

Definition at line 961 of file list.c.

void list_offsets_ensure ( list_struct list)

Ensure the list's offsets are in a valid range. The offsets could be invalid due to a row removal, for example.

Parameters:
listList to ensure for.

Definition at line 649 of file list.c.

void list_remove ( list_struct list)

Remove the specified list from the linked list of visible lists and deinitialize it.

Parameters:
listList to remove.

Definition at line 670 of file list.c.

void list_remove_all ( )

Remove all visible lists.

Definition at line 725 of file list.c.

void list_remove_row ( list_struct list,
uint32  row 
)

Remove row from a list.

Parameters:
listList.
rowRow ID to remove.

Definition at line 264 of file list.c.

static void list_row_color ( list_struct list,
int  row,
SDL_Rect  box 
) [static]

Colorize a row.

Parameters:
listList.
rowRow number, 0-[max visible rows].
boxContains base x/y/width/height information to use.

Definition at line 54 of file list.c.

static void list_row_highlight ( list_struct list,
SDL_Rect  box 
) [static]

Highlight a row (due to mouse being over it).

Parameters:
listList.
boxContains base x/y/width/height information to use.

Definition at line 70 of file list.c.

static void list_row_selected ( list_struct list,
SDL_Rect  box 
) [static]

Color a selected row.

Parameters:
listList.
boxContains base x/y/width/height information to use.

Definition at line 79 of file list.c.

static void list_scroll ( list_struct list,
int  up,
int  scroll 
) [static]

Scroll the list in the specified direction by the specified amount.

Parameters:
listList to scroll.
upIf 1, scroll the list upwards, otherwise downwards.
scrollAmount to scroll by.

Definition at line 739 of file list.c.

void list_scrollbar_enable ( list_struct list)

Enable scrollbar.

Parameters:
listList to enable scrollbar on.

Definition at line 356 of file list.c.

static int list_scrollbar_get_size ( list_struct list,
SDL_Rect *  box 
) [static]

Get scrollbar's size.

Parameters:
listList.
boxWhere to store the size of the scrollbar.
Returns:
1 on success, 0 on failure (no scrollbar active).

Definition at line 366 of file list.c.

static void list_scrollbar_render ( list_struct list) [static]

Render scrollbar for a list.

Parameters:
listThe list.

Definition at line 434 of file list.c.

void list_set_column ( list_struct list,
uint32  col,
int  width,
int  spacing,
const char *  name,
int  centered 
)

Set options for one column.

Parameters:
listList.
colColumn ID.
widthThe column's ID. -1 to leave default (0).
spacingSpacing between columns. -1 to leave default (0).
nameName of the column. NULL to leave default (no name shown).
centeredWhether to center the drawn name/text in the column. -1 to leave default (not centered).

Definition at line 303 of file list.c.

void list_set_focus ( list_struct list)

Set currently focused list.

Parameters:
listList to focus.

Definition at line 125 of file list.c.

void list_set_font ( list_struct list,
int  font 
)

Change list's font.

Parameters:
listWhich list to change font for.
fontFont to use.

Definition at line 348 of file list.c.

void list_set_parent ( list_struct list,
int  px,
int  py 
)

Update list's parent X/Y coordinates.

Parameters:
listThe list.
pxParent X.
pyParent Y.

Definition at line 152 of file list.c.

int list_set_selected ( list_struct list,
const char *  str,
uint32  col 
)

Set the selected row based on column's text.

Parameters:
listThe list.
strText to search for in all the rows.
colThe column to check value of in each row.
Returns:
1 if new selected row was set, 0 otherwise.

Definition at line 1175 of file list.c.

void list_show ( list_struct list,
int  x,
int  y 
)

Show one list.

Parameters:
listList to show.
xX position.
yY position.

Definition at line 468 of file list.c.

static int list_slider_get_size ( list_struct list,
SDL_Rect *  box 
) [static]

Get slider's size.

Parameters:
listList.
boxWhere to store the size of the slider.
Returns:
1 on success, 0 on failure (no scrollbar active, so no slider either).

Definition at line 394 of file list.c.

void list_sort ( list_struct list,
int  type 
)

Sort a list's entries.

Parameters:
listList to sort.
typeHow to sort, one of List sort types.
Note:
Sorting is done by looking at the first column of each row.

Definition at line 1155 of file list.c.

int lists_handle_keyboard ( SDL_KeyboardEvent *  event)

Handle keyboard event.

Parameters:
eventEvent.
Returns:
1 if we handled the event, 0 otherwise.

Definition at line 935 of file list.c.

int lists_handle_mouse ( int  mx,
int  my,
SDL_Event *  event 
)

Handle mouse events such as mouse motion and mouse click.

Parameters:
mxMouse X.
myMouse Y.
eventThe event.
Returns:
1 if we handled the event (mouse was inside the list), 0 otherwise.

Definition at line 1106 of file list.c.


Variable Documentation

list_struct* list_head = NULL [static]

Start of the visible lists.

Definition at line 33 of file list.c.

list_struct* list_tail = NULL [static]

End of the visible lists.

Definition at line 35 of file list.c.

int old_scrollbar_pos = 0 [static]

Used to store scrollbar position.

Definition at line 37 of file list.c.