Atrinik Client  4.0
Functions
list.c File Reference
#include <global.h>
#include <toolkit/string.h>

Go to the source code of this file.

Functions

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)
 
void list_set_parent (list_struct *list, int px, int py)
 
list_structlist_create (uint32_t max_rows, uint32_t cols, int spacing)
 
void list_add (list_struct *list, uint32_t row, uint32_t col, const char *str)
 
void list_remove_row (list_struct *list, uint32_t row)
 
void list_set_column (list_struct *list, uint32_t col, int width, int spacing, const char *name, int centered)
 
void list_set_font (list_struct *list, font_struct *font)
 
void list_scrollbar_enable (list_struct *list)
 
int list_need_redraw (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_scroll (list_struct *list, int up, int scroll)
 
int list_handle_keyboard (list_struct *list, SDL_Event *event)
 
int list_handle_mouse (list_struct *list, SDL_Event *event)
 
int list_mouse_get_pos (list_struct *list, int mx, int my, uint32_t *row, uint32_t *col)
 
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_t col)
 
const char * list_get_selected (list_struct *list, uint32_t col)
 

Detailed Description

Generic lists implementation.

Author
Alex Tokar

Definition in file list.c.

Function Documentation

void list_add ( list_struct list,
uint32_t  row,
uint32_t  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 163 of file list.c.

void list_clear ( list_struct list)

Clear and free list's entries.

Parameters
listList.

Definition at line 486 of file list.c.

void list_clear_rows ( list_struct list)

Clear the list's rows.

Parameters
listThe list.

Definition at line 457 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 819 of file list.c.

list_struct* list_create ( uint32_t  max_rows,
uint32_t  cols,
int  spacing 
)

Create new list.

Parameters
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 113 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 40 of file list.c.

const char* list_get_selected ( list_struct list,
uint32_t  col 
)

Acquire text at the specified column of the currently selected row.

Parameters
listList.
colColumn to get text at.
Returns
Pointer to column's text, NULL if there is no row selected.

Definition at line 879 of file list.c.

int list_handle_keyboard ( list_struct list,
SDL_Event *  event 
)

Handle keyboard event for the specified list.

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

Definition at line 622 of file list.c.

int list_handle_mouse ( list_struct list,
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.
eventEvent.
Returns
1 if the event was handled, 0 otherwise.

Definition at line 698 of file list.c.

int list_need_redraw ( list_struct list)

Check whether the list needs redrawing.

Parameters
listList to check.
Returns
1 if the list needs redrawing, 0 otherwise.

Definition at line 315 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 501 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 522 of file list.c.

void list_remove_row ( list_struct list,
uint32_t  row 
)

Remove row from a list.

Parameters
listList.
rowRow ID to remove.

Definition at line 198 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 82 of file list.c.

void list_scroll ( list_struct list,
int  up,
int  scroll 
)

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 564 of file list.c.

void list_scrollbar_enable ( list_struct list)

Enable scrollbar.

Parameters
listList to enable scrollbar on.

Definition at line 302 of file list.c.

void list_set_column ( list_struct list,
uint32_t  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 242 of file list.c.

void list_set_font ( list_struct list,
font_struct font 
)

Change list's font.

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

Definition at line 284 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 96 of file list.c.

int list_set_selected ( list_struct list,
const char *  str,
uint32_t  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 855 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 337 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 832 of file list.c.