LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024 ETMSoftware
lg_ui.h
1 /*
2  * LibGame - Copyright (C) Emmanuel Thomas-Maurin 2011-2024
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 = -1, 0, 1 (but slow_motion) */
67  int move_forward;
68  int move_up; /* Not an aircraft motion */
69  int cam_truck; /* Not an aircraft motion */
70  int slow_motion;
71  /* Yaw/Pitch/Roll = -1, 0, 1 */ /* Aircraft/flight simulator standard order */
72  int yaw;
73  int pitch;
74  int roll;
75  /* Mouse inputs */
76  zboolean left_click;
77  zboolean right_click;
78  int dx;
79  int dy;
80  int dz_wheel; /* Mouse wheel also set move_forward */
82 
83 /*
84  * TZ/tz means Touch Zone (not Time Zone)
85  */
86 typedef enum {
87  TZ_LEFT,
88  TZ_H_CENTER,
89  TZ_RIGHT,
90  TZ_BOTTOM,
91  TZ_V_CENTER,
92  TZ_TOP
93 } lg_touch_zone;
94 
95 typedef struct {
96  LG_Window win;
97  LG_Color_u color;
98  Rec2Di area;
100 
101 #define TZW_ARROW_POINTS_NUM 7
102 
103 typedef enum {
104  TZW_RECTANGLE,
105  TZW_RECT_CORNERS,
106  TZW_ARROW_UP,
107  TZW_ARROW_DOWN,
108  TZW_ARROW_LEFT,
109  TZW_ARROW_RIGHT,
110  TZW_DOUBLE_ARROW_HORIZ,
111  TZW_DOUBLE_ARROW_VERT,
112 } lg_tzw_type;
113 
114 LG_TouchZoneWindow *lg_tzwin_new(const char *, LG_Color_u, int, int);
115 
116 void lg_tzwin_show(LG_TouchZoneWindow *, lg_tzw_type);
117 
119 
121 
123 
124 void lg_draw_arrow(Rec2Di r, LG_Color_u c, lg_tzw_type);
125 
126 void lg_rectangle_to_arrow(Rec2Di, lg_tzw_type, Point2Di *[]);
127 
128 void lg_set_func_keys_repeat_delay(uint32_t);
129 
130 uint32_t lg_get_user_input(LG_InputState *, Rec2Di *[]);
131 
132 #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:201
lg_tzwin_show
void lg_tzwin_show(LG_TouchZoneWindow *tzwin, lg_tzw_type type)
Definition: lg_ui.c:96
lg_rectangle_to_arrow
void lg_rectangle_to_arrow(Rec2Di r, lg_tzw_type arrow_type, Point2Di *p[])
Definition: lg_ui.c:225
lg_draw_rect_corners
void lg_draw_rect_corners(Rec2Di r, LG_Color_u c, int len)
Definition: lg_ui.c:171
LG_InputState
Definition: lg_ui.h:55
Point2Di
Definition: lg_gr_func.h:13
lg_set_func_keys_repeat_delay
void lg_set_func_keys_repeat_delay(uint32_t delay)
Definition: lg_ui.c:348
LG_Color_u
Definition: lg_vertex.h:91
lg_tzwin_new
LG_TouchZoneWindow * lg_tzwin_new(const char *str, LG_Color_u text_color, int x_loc, int y_loc)
Definition: lg_ui.c:32
lg_tzwin_get_rect
Rec2Di lg_tzwin_get_rect(LG_TouchZoneWindow *tzwin)
Definition: lg_ui.c:154
lg_get_user_input
uint32_t lg_get_user_input(LG_InputState *in, Rec2Di **r)
Definition: lg_ui.c:371
LG_Window
Definition: lg_wins.h:47
lg_tzwin_free
void lg_tzwin_free(LG_TouchZoneWindow *tzwin)
Definition: lg_ui.c:141
LG_TouchZoneWindow
Definition: lg_ui.h:95
Rec2Di
Definition: lg_gr_func.h:47