LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024-2025 ETMSoftware
lg_ui.h
1 /*
2  * LibGame - Copyright (C) Emmanuel Thomas-Maurin 2011-2025
3  * All rights reserved
4  */
5 
6 #ifndef LG_UI_H
7 #define LG_UI_H
8 
9 #ifndef ANDROID_V
10 # define FLUSH_KEYB_OR_TOUCHSCREEN_BUF {lg_flush_keyb_buf();}
11 #else
12 # define FLUSH_KEYB_OR_TOUCHSCREEN_BUF {lg_flush_touchscreen_buf();}
13 #endif
14 
15 #ifndef ANDROID_V
16 # define WAIT_FOR_PRESS_OR_TOUCH {lg_wait_for_any_key_pressed();}
17 #else
18 # define WAIT_FOR_PRESS_OR_TOUCH {lg_wait_for_finger_down(NULL, NULL);}
19 #endif
20 
21 #define FUNC_KEYS_REPEAT_DELAY 200 /* In ms */
22 
23 /*
24  * Check this out:
25  * Android touch screen
26  * typedef enum {
27  * LG_FINGER_DOWN_NO_LOC = 0,
28  * LG_FINGER_DOWN_LEFT = 1,
29  * LG_FINGER_DOWN_H_CENTER = 2,
30  * LG_FINGER_DOWN_RIGHT = 4,
31  * LG_FINGER_DOWN_BOTTOM = 8,
32  * LG_FINGER_DOWN_V_CENTER = 16,
33  * LG_FINGER_DOWN_TOP = 32
34  * } lg_finger_down_loc;
35  *
36  *\code
37  * L C R
38  * -------------------
39  * T | | | |
40  * -------------------
41  * C | | | |
42  * -------------------
43  * B | | | |
44  * -------------------
45  *
46  * TZ_LEFT
47  * TZ_H_CENTER
48  * TZ_RIGHT
49  * TZ_BOTTOM
50  * TZ_V_CENTER
51  * TZ_TOP
52  *\endcode
53  */
54 
55 typedef struct {
56  /* Linux */
57  uint8_t arrow_keys_state; /* LEFT, RIGHT, UP, DOWN */
58  zboolean kmod_ctrl;
59  zboolean kmod_shift;
60  zboolean kmod_alt;
61  uint32_t last_pressed_key;
62  /* Android */
63  lg_finger_down_loc finger_down_loc; /* Logical OR of values */
64  float x;
65  float y;
66  /* Cam/object motions and rotations = -1, 0, 1 (but slow_motion) */
67  int move_forward;
68  int move_up; /* Y transl - not an aircraft motion */
69  int cam_truck; /* X transl - not an aircraft motion */
70  /* Yaw/Pitch/Roll = -1, 0, 1 */ /* Aircraft/flight simulator standard order */
71  int yaw; /* Or pan */
72  int pitch; /* Or tilt */
73  int roll;
74  //
75  // -> need yaw/pitch/roll quats ?
76  //
77  /* Orbit cam */
78  int h_orbit;
79  int v_orbit;
80  /* Mouse inputs */
81  zboolean left_click;
82  zboolean right_click;
83  int dx;
84  int dy;
85  int dz_wheel; /* Mouse wheel also set move_forward */
86  /* Appply for keyboard and mouse */
87  zboolean slow_motion; /* Set by <F2> ? */
89 
90 /*
91  * TZ/tz means Touch Zone (not Time Zone)
92  */
93 typedef enum {
94  TZ_LEFT,
95  TZ_H_CENTER,
96  TZ_RIGHT,
97  TZ_BOTTOM,
98  TZ_V_CENTER,
99  TZ_TOP
100 } lg_touch_zone;
101 
102 typedef struct {
103  LG_Window win;
104  LG_Color_u color;
105  Rec2Di area;
107 
108 #define TZW_ARROW_POINTS_NUM 7
109 
110 typedef enum {
111  TZW_RECTANGLE,
112  TZW_RECT_CORNERS,
113  TZW_ARROW_UP,
114  TZW_ARROW_DOWN,
115  TZW_ARROW_LEFT,
116  TZW_ARROW_RIGHT,
117  TZW_DOUBLE_ARROW_HORIZ,
118  TZW_DOUBLE_ARROW_VERT,
119 } lg_tzw_type;
120 
121 uint32_t lg_get_user_input(LG_InputState *, Rec2Di *[]);
122 
123 LG_TouchZoneWindow *lg_tzwin_new(const char *, LG_Color_u, int, int, TTF_Font *);
124 
125 void lg_tzwin_show(LG_TouchZoneWindow *, lg_tzw_type);
126 
128 
130 
132 
133 void lg_draw_arrow(Rec2Di r, LG_Color_u c, lg_tzw_type);
134 
135 void lg_rectangle_to_arrow(Rec2Di, lg_tzw_type, Point2Di *[]);
136 
137 void lg_set_func_keys_repeat_delay(uint32_t);
138 
139 #endif /* LG_UI_H */
lg_draw_arrow
void lg_draw_arrow(Rec2Di r, LG_Color_u c, lg_tzw_type type)
Definition: lg_ui.c:389
lg_tzwin_show
void lg_tzwin_show(LG_TouchZoneWindow *tzwin, lg_tzw_type type)
Definition: lg_ui.c:284
lg_rectangle_to_arrow
void lg_rectangle_to_arrow(Rec2Di r, lg_tzw_type arrow_type, Point2Di *p[])
Definition: lg_ui.c:413
lg_draw_rect_corners
void lg_draw_rect_corners(Rec2Di r, LG_Color_u c, int len)
Definition: lg_ui.c:359
LG_InputState
Definition: lg_ui.h:55
Point2Di
Definition: lg_gr_func.h:15
lg_tzwin_new
LG_TouchZoneWindow * lg_tzwin_new(const char *str, LG_Color_u text_color, int x_loc, int y_loc, TTF_Font *f)
Definition: lg_ui.c:220
lg_set_func_keys_repeat_delay
void lg_set_func_keys_repeat_delay(uint32_t delay)
Definition: lg_ui.c:534
LG_Color_u
Definition: lg_vertex.h:111
lg_tzwin_get_rect
Rec2Di lg_tzwin_get_rect(LG_TouchZoneWindow *tzwin)
Definition: lg_ui.c:342
lg_get_user_input
uint32_t lg_get_user_input(LG_InputState *in, Rec2Di **r)
Definition: lg_ui.c:62
LG_Window
Definition: lg_wins.h:47
lg_tzwin_free
void lg_tzwin_free(LG_TouchZoneWindow *tzwin)
Definition: lg_ui.c:329
LG_TouchZoneWindow
Definition: lg_ui.h:102
Rec2Di
Definition: lg_gr_func.h:49