LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024 ETMSoftware
lg_ui.c File Reference

Functions

LG_TouchZoneWindowlg_tzwin_new (const char *str, LG_Color_u text_color, int x_loc, int y_loc)
 
void lg_tzwin_show (LG_TouchZoneWindow *tzwin, lg_tzw_type type)
 
void lg_tzwin_free (LG_TouchZoneWindow *tzwin)
 
Rec2Di lg_tzwin_get_rect (LG_TouchZoneWindow *tzwin)
 
void lg_draw_rect_corners (Rec2Di r, LG_Color_u c, int len)
 
void lg_draw_arrow (Rec2Di r, LG_Color_u c, lg_tzw_type type)
 
void lg_rectangle_to_arrow (Rec2Di r, lg_tzw_type arrow_type, Point2Di *p[])
 
void lg_set_func_keys_repeat_delay (uint32_t delay)
 
uint32_t lg_get_user_input (LG_InputState *in, Rec2Di **r)
 

Detailed Description

 === User Interface things ===

 Get all user input from keyboard, mouse, touchscreen
 Then try to make something coherent out of all that

Function Documentation

◆ lg_tzwin_new()

LG_TouchZoneWindow* lg_tzwin_new ( const char *  str,
LG_Color_u  text_color,
int  x_loc,
int  y_loc 
)

Create a new LG_TouchZoneWindow

=== Set touch_zone area ===

Parameters
strA string
text_colorA LG_Color_u
xOne of TZ_LEFT, TZ_RIGHT
yOne of TZ_BOTTOM, TZ_TOP
Returns
Addr of a new LG_TouchZoneWindow or NULL on error

◆ lg_tzwin_show()

void lg_tzwin_show ( LG_TouchZoneWindow tzwin,
lg_tzw_type  type 
)

Show a LG_TouchZoneWindow

Parameters
tzwinA pointer to a LG_TouchZoneWindow
typeA lg_tzw_type value

◆ lg_tzwin_free()

void lg_tzwin_free ( LG_TouchZoneWindow tzwin)

Free a LG_TouchZoneWindow

Parameters
tzwinA pointer to a LG_TouchZoneWindow

◆ lg_tzwin_get_rect()

Rec2Di lg_tzwin_get_rect ( LG_TouchZoneWindow tzwin)

Get the Rec2Di from a LG_TouchZoneWindow

Parameters
tzwinA pointer to a LG_TouchZoneWindow
Returns
tzwin->area (a Rec2Di)

◆ lg_draw_rect_corners()

void lg_draw_rect_corners ( Rec2Di  r,
LG_Color_u  c,
int  len 
)

Draw corners of a rect

Parameters
rA Rec2Di
cA LG_Color_u
lenLength of corner lines

◆ lg_draw_arrow()

void lg_draw_arrow ( Rec2Di  r,
LG_Color_u  c,
lg_tzw_type  type 
)

Draw an arrow

Parameters
rA Rec2Di
cA LG_Color_u
typeA lg_tzw_type value

◆ lg_rectangle_to_arrow()

void lg_rectangle_to_arrow ( Rec2Di  r,
lg_tzw_type  arrow_type,
Point2Di p[] 
)

Determine the points to draw a lg_tzw_type arrow (with TZW_ARROW_POINTS_NUM points) inside a rectangle

-> up/down/left/right_arrow

Parameters
rA Rec2Di
arrow_typeOne of TZW_RECTANGLE, TZW_RECT_CORNERS, TZW_ARROW_UP, TZW_ARROW_DOWN, TZW_ARROW_LEFT, TZW_ARROW_RIGHT, TZW_DOUBLE_ARROW_HORIZ, TZW_DOUBLE_ARROW_VERT
pAn array of Point2Di pointers

◆ lg_set_func_keys_repeat_delay()

void lg_set_func_keys_repeat_delay ( uint32_t  delay)

Set func keys repeat delay

Parameters
delayDelay in ms

◆ lg_get_user_input()

uint32_t lg_get_user_input ( LG_InputState in,
Rec2Di **  r 
)

Get user input (from keyboard, mouse, touchscreen) in LG_InputState and return in->last_pressed_key (SDLK_*)

Use lg_enable_mouse() / lg_disable_mouse() to read/ignore mouse inputs

Delay for func keys (<F1> -> <F12>) is set to FUNC_KEYS_REPEAT_DELAY, can be overridden with lg_set_func_keys_repeat_delay()

On Android, returned value > 0 means requiring action associated with index + 1 of LG_TouchZoneWindow.area array

=== VARO: order of area matters, ie it goes from left to right ===

Reset last_pressed_key if finger up is detected

Parameters
inA pointer to a LG_InputState
rA pointer to an array of pointers to Rec2Di
Returns
in->last_pressed_key