![]() |
LibGame
v0.4.0
The LG Game Engine - Copyright (C) 2024-2025 ETMSoftware
|
=== User Interface things === Get all user input from keyboard, mouse, touchscreen Then try to make something coherent out of all that === Clickable/tappable areas helper macros for x and y === (in lg_touchscreen.h) typedef enum { LG_FINGER_DOWN_NO_LOC = 0, LG_FINGER_DOWN_LEFT = 1, LG_FINGER_DOWN_H_CENTER = 2, LG_FINGER_DOWN_RIGHT = 4, LG_FINGER_DOWN_BOTTOM = 8, LG_FINGER_DOWN_V_CENTER = 16, LG_FINGER_DOWN_TOP = 32 } lg_finger_down_loc; (below in this file) L C R ------------------- T | | | | ------------------- C | | | | ------------------- B | | | | ------------------- TZ_LEFT TZ_H_CENTER TZ_RIGHT TZ_BOTTOM TZ_V_CENTER TZ_TOP === Flight simulator/aircraft specific stuff === yaw + pitch + roll = attitude (Yaw/Pitch/Roll = standard order) Other namings: yaw = heading, pan / pitch = elevation, tilt / roll = bank From: https://www1.grc.nasa.gov/beginners-guide-to-aeronautics/airplane-parts-function/ Flight controls: ========================================================================= yoke (left/right) -> ailerons -> roll yoke (forward/backward) -> elevators (on horiz stabilizer) -> pitch rudder pedals -> rudder (on vert stabilizer) -> yaw thrust lever(s) -> thrust flaps -> increase lift air brakes =========================================================================
const char** lg_camcontrols_keys_str | ( | ) |
Return an array of 9 help strings for cam controls keys
uint32_t lg_get_user_input | ( | LG_InputState * | in, |
LG_TZW_Array * | tzw_array | ||
) |
Get user input (from keyboard, mouse, touchscreen) in LG_InputState and return in->last_pressed_key (SDLK_*) or LPK_MOUSE_CLICK_ACTIVITY + in->tzw_i in case of mouse left/right click
=== This is the func you should use to get user input inside the game main loop ===
Keyboard controls on Linux:
Keys which can be returned by lg_get_user_input() are so far: <enter>, <esc>, <space>, <F1> -> <F12>, <x>, <y>, <z> (see lg_get_special_keys_state())
Delay for <enter>, <esc>, plus <F1> -> <F12> is set to SPECIAL_KEYS_REPEAT_DELAY, can be overridden with lg_set_special_keys_repeat_delay()
Use lg_enable_mouse() / lg_disable_mouse() to read/ignore mouse inputs
On Android, returned value > 0 means requiring action associated with index + 1 of LG_TouchZoneWindow.area array
-> Now set in->tzw_i to index + 1 on both platforms
=== VARO: order of areas matters, ie it goes from left to right ===
Reset last_pressed_key if finger up is detected
NOTE: on Linux, if <up>/<down> with <ctrl><alt> or <ctrl><shift><alt> do nothing, they may have been hijacked by gnome keybindings - check out with dconf: /org/gnome/desktop/wm/keybindings/*
in | A pointer to a LG_InputState |
tzw_array | A pointer to a LG_TZW_Array |
LG_TouchZoneWindow* lg_tzwin_new | ( | const char * | str, |
zboolean | no_margin, | ||
LG_Color_u | text_color, | ||
int | x_loc, | ||
int | y_loc, | ||
TTF_Font * | f | ||
) |
Create a new LG_TouchZoneWindow
A LG_TouchZoneWindow is a window that is 'clickable' (on Linux) or 'tappable' (on Android) and is rendered in immediate-mode, ie upadated and shown for every frame
=== Set touch_zone area ===
str | A string |
no_margin | |
text_color | A LG_Color_u |
x | You may also use one of TZ_LEFT, TZ_H_CENTER, TZ_RIGHT |
y | You may also use one of TZ_BOTTOM, TZ_V_CENTER, TZ_TOP |
f | A TTF_Font |
void lg_tzwin_show | ( | LG_TouchZoneWindow * | tzwin, |
lg_tzw_type | type | ||
) |
Show a LG_TouchZoneWindow
tzwin | A pointer to a LG_TouchZoneWindow |
type | A lg_tzw_type value |
void lg_tzwin_free | ( | LG_TouchZoneWindow * | tzwin | ) |
Free a LG_TouchZoneWindow
tzwin | A pointer to a LG_TouchZoneWindow |
Rec2Di lg_tzwin_get_area | ( | LG_TouchZoneWindow * | tzwin | ) |
Get area (Rec2Di) from a LG_TouchZoneWindow
tzwin | A pointer to a LG_TouchZoneWindow |
void lg_draw_rect_corners | ( | Rec2Di | r, |
LG_Color_u | c, | ||
int | len | ||
) |
Draw corners of a rect
r | A Rec2Di |
c | A LG_Color_u |
len | Length of corner lines |
void lg_draw_arrow | ( | Rec2Di | r, |
LG_Color_u | c, | ||
lg_tzw_type | type | ||
) |
Draw an arrow
r | A Rec2Di, containing the arrow |
c | A LG_Color_u |
type | One of TZW_ARROW_UP, TZW_ARROW_DOWN, TZW_ARROW_LEFT, TZW_ARROW_RIGHT, TZW_DOUBLE_ARROW_HORIZ, TZW_DOUBLE_ARROW_VERT |
Determine the points to draw a lg_tzw_type arrow (with TZW_ARROW_POINTS_NUM points) inside a rectangle
-> up/down/left/right_arrow
r | A Rec2Di |
arrow_type | A lg_tzw_type value (see lg_draw_arrow() above) |
p | An array of Point2Di pointers |
void lg_draw_triangle | ( | Rec2Di | r, |
LG_Color_u | c, | ||
lg_tzw_type | type | ||
) |
Draw a triangle pointing to left, right, up, down
r | A Rec2Di, containg the triangle |
c | A LG_Color_u |
type | One of TZW_TRIANGLE_LEFT, TZW_TRIANGLE_RIGHT, TZW_TRIANGLE_UP, TZW_TRIANGLE_DOWN |
void lg_set_special_keys_repeat_delay | ( | uint32_t | delay | ) |
Set func keys repeat delay
delay | Delay in ms |
LG_TZW_Array* lg_tzw_array_new | ( | ) |
Create a new LG_TZW_Array and initialize it
(TZW and TZ win are shorts for LG_TouchZoneWindow)
The purpose of this struct is to keep an array of changeable TZ wins to show at each frame and to know which one was 'activated' (clicked or tapped)
After that, when adding/removing TZ wins, order matters, ie it goes from left to right
When a TZ win area is clicked/tapped, LG_InputState->tzw_i is set to index + 1
Use in->tzw_i to decide which action to take, knowing that:
This API seems a bit complicated at first, but to get a better sense of how it works, make sure to check out the code in scene_editor/main_loop.c, where it is used extensively
zboolean lg_tzwin_add_to_array | ( | LG_TZW_Array * | tzw_array, |
LG_TouchZoneWindow * | tzwin | ||
) |
Add a TZ win at first NULL element found
tzw_array | Pointer to a LG_TZW_Array |
tzwin | Pointer to a LG_TouchZoneWindow |
LG_TZRec_Array lg_rec2di_array_from_tzw_array | ( | LG_TZW_Array * | tzw_array | ) |
Create and return a LG_TZRec_Array from a LG_TZW_Array
tzw_array | Pointer to a LG_TZW_Array |
void lg_tzw_array_free_all_tzwin | ( | LG_TZW_Array * | tzw_array | ) |
Free all TZ win from a TZ win array
tzw_array | Pointer to a LG_TZW_Array |
void lg_tzw_array_free_all_tzwin_after | ( | LG_TZW_Array * | tzw_array, |
uint32_t | next_index | ||
) |
Free all TZ win after next_index from a TZ win array
tzw_array | Pointer to a LG_TZW_Array |
next_index |
void lg_tzw_array_free | ( | LG_TZW_Array * | tzw_array | ) |
Free a TZ win array
tzw_array | Pointer to a LG_TZW_Array |
void lg_flush_in_clicks | ( | LG_InputState * | in | ) |
Flush mouse clicks and reset associated states in LG_InputState
in | Pointer to LG_InputState |
void lg_input_state_info | ( | LG_InputState * | in | ) |
Take a snapshot of user input state
in | LG_InputState |