LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024-2025 ETMSoftware
lg_gr_func.h
1 /*
2  * LibGame - Copyright (C) Emmanuel Thomas-Maurin 2011-2025
3  * All rights reserved
4  */
5 
6 #ifndef LG_GR_FUNC_H
7 #define LG_GR_FUNC_H
8 
9 /*
10  * === A few 2D structs and graphical funcs ===
11  *
12  * Plus colors funcs
13  */
14 
15 typedef struct {
16  int32_t x;
17  int32_t y;
18 } Point2Di;
19 
20 typedef struct {
21  float x;
22  float y;
23 } Point2Df;
24 
25 typedef struct {
26  int32_t x1;
27  int32_t y1;
28  int32_t x2;
29  int32_t y2;
30 } Line2Di;
31 
32 typedef struct {
33  float x1;
34  float y1;
35  float x2;
36  float y2;
37 } Line2Df;
38 
39 /*
40  * Rec = rectangle (floats) with OpenGL coords sys orientation
41  * ^
42  * |
43  * x,y+h |--------
44  * | |
45  * | |
46  * ------------->
47  * x,y x+w,y
48  */
49 typedef struct {
50  int32_t x;
51  int32_t y;
52  int32_t w;
53  int32_t h;
54 } Rec2Di;
55 
56 typedef struct {
57  float x;
58  float y;
59  float w;
60  float h;
61 } Rec2Df;
62 
63 void lg_draw_line(int32_t, int32_t, int32_t, int32_t, LG_Color_u);
64 
66 
67 void lg_fill_rect(Rec2Di r, LG_Color_u c);
68 
70 
71 zboolean lg_clip_rect(Rec2Di, Rec2Di, Rec2Di *);
72 
73 zboolean lg_recs_overlap(Rec2Df *, Rec2Df *);
74 
75 void lg_copy_rect(Rec2Di, Rec2Di *);
76 
77 void lg_rec_i_copy(Rec2Di *, Rec2Di);
78 
79 void lg_rec_f_copy(Rec2Df *, Rec2Df);
80 
81 Rec2Di lg_rec_i(int, int, int, int);
82 
83 Rec2Df lg_rec_f(float, float, float, float);
84 
86 
88 
89 Point2Di lg_point2d_i(int32_t, int32_t);
90 
91 Point2Df lg_point2d_f(float, float);
92 
94 
96 
97 void gl_coords_from_screen_coords(float *, float *, int, int, int, int);
98 
99 void logical_coords_from_viewport_coords(int *, int *, int, int);
100 
102 
103 void logical_coords_from_touchscreen_coords(int *, int *, float, float);
104 
105 void lg_set_touchscreen_coords_margins(float, float);
106 
108 
109 uint32_t lg_point2df_is_inside_rec2df_from_array(Point2Df, Rec2Df **, uint32_t);
110 
111 int32_t sdl_to_gl_int_x(int32_t);
112 
113 int32_t sdl_to_gl_int_y(int32_t);
114 
115 float sdl_to_gl_float_x(int32_t);
116 
117 float sdl_to_gl_float_y(int32_t);
118 
119 #if 0
120 // That's horrifying -> substitute
121 lg_get_lg_color_u_from_str() -> color_u_from_str()
122 
123 lg_color_u_from_sdl_color() -> color_u_from_sdl_color()
124 
125 lg_set_lg_color_u_from_str() -> set_color_u_from_str()
126 
127 lg_get_color_str_from_color_index() -> color_str_from_color_index()
128 
129 lg_get_sdl_color_from_str() -> sdl_color_from_str()
130 
131 lg_sdl_color_from_lg_color_u() -> sdl_color_from_color_u()
132 
133 lg_set_sdl_color_from_str() -> set_sdl_color_from_str()
134 #endif
135 
137 
139 
140 SDL_Color *lg_set_sdl_color_from_str(SDL_Color *, const char *);
141 
142 SDL_Color lg_get_sdl_color_from_str(const char *);
143 
145 
147 
148 int lg_get_n_color_str();
149 
151 
152 void v_flip_sdl_surf(SDL_Surface *);
153 
154 #endif /* LG_GR_FUNC_H */
sdl_to_gl_int_x
int32_t sdl_to_gl_int_x(int32_t x)
Definition: lg_gr_func.c:548
lg_point2d_f
Point2Df lg_point2d_f(float x, float y)
Definition: lg_gr_func.c:364
lg_rec_f_center
Point2Df lg_rec_f_center(Rec2Df r)
Definition: lg_gr_func.c:388
Rec2Df
Definition: lg_gr_func.h:56
Point2Df
Definition: lg_gr_func.h:20
logical_coords_from_touchscreen_coords
void logical_coords_from_touchscreen_coords(int *x2, int *y2, float x1, float y1)
Definition: lg_gr_func.c:467
sdl_to_gl_int_y
int32_t sdl_to_gl_int_y(int32_t y)
Definition: lg_gr_func.c:559
lg_rec_f_copy
void lg_rec_f_copy(Rec2Df *dest, Rec2Df src)
Definition: lg_gr_func.c:264
lg_get_lg_color_u_from_str
LG_Color_u lg_get_lg_color_u_from_str(const char *str)
Definition: lg_gr_func.c:686
lg_sdl_color_from_lg_color_u
SDL_Color lg_sdl_color_from_lg_color_u(LG_Color_u c)
Definition: lg_gr_func.c:635
Point2Di
Definition: lg_gr_func.h:15
lg_point2d_i
Point2Di lg_point2d_i(int32_t x, int32_t y)
Definition: lg_gr_func.c:352
lg_get_sdl_color_from_str
SDL_Color lg_get_sdl_color_from_str(const char *str)
Definition: lg_gr_func.c:666
Line2Df
Definition: lg_gr_func.h:32
lg_recs_overlap
zboolean lg_recs_overlap(Rec2Df *r1, Rec2Df *r2)
Definition: lg_gr_func.c:219
lg_get_color_str_from_color_index
const char * lg_get_color_str_from_color_index(int i)
Definition: lg_gr_func.c:706
lg_clear_rect
void lg_clear_rect(Rec2Di r, LG_Color_u c)
Definition: lg_gr_func.c:116
lg_draw_rect
void lg_draw_rect(Rec2Di r, LG_Color_u c)
Definition: lg_gr_func.c:46
lg_set_touchscreen_coords_margins
void lg_set_touchscreen_coords_margins(float left, float top)
Definition: lg_gr_func.c:488
lg_rec_i_from_rec_f
Rec2Di lg_rec_i_from_rec_f(Rec2Df r)
Definition: lg_gr_func.c:333
logical_coords_from_viewport_coords
void logical_coords_from_viewport_coords(int *x2, int *y2, int x1, int y1)
Definition: lg_gr_func.c:428
lg_set_lg_color_u_from_str
LG_Color_u * lg_set_lg_color_u_from_str(LG_Color_u *c, const char *str)
Definition: lg_gr_func.c:677
lg_rec_i
Rec2Di lg_rec_i(int x, int y, int w, int h)
Definition: lg_gr_func.c:281
lg_color_u_from_sdl_color
LG_Color_u lg_color_u_from_sdl_color(SDL_Color c)
Definition: lg_gr_func.c:624
lg_fill_rect
void lg_fill_rect(Rec2Di r, LG_Color_u c)
Definition: lg_gr_func.c:89
lg_rec_i_center
Point2Di lg_rec_i_center(Rec2Di r)
Definition: lg_gr_func.c:377
lg_draw_line
void lg_draw_line(int32_t x1, int32_t y1, int32_t x2, int32_t y2, LG_Color_u c)
Definition: lg_gr_func.c:30
lg_rec_f
Rec2Df lg_rec_f(float x, float y, float w, float h)
Definition: lg_gr_func.c:302
LG_Color_u
Definition: lg_vertex.h:111
Line2Di
Definition: lg_gr_func.h:25
sdl_to_gl_float_y
float sdl_to_gl_float_y(int32_t y)
Definition: lg_gr_func.c:588
sdl_to_gl_float_x
float sdl_to_gl_float_x(int32_t x)
Definition: lg_gr_func.c:574
v_flip_sdl_surf
void v_flip_sdl_surf(SDL_Surface *surf)
Definition: lg_gr_func.c:729
lg_copy_rect
void lg_copy_rect(Rec2Di src, Rec2Di *dest)
Definition: lg_gr_func.c:236
logical_coords_from_viewport_coords_btaskbar_adjustment
void logical_coords_from_viewport_coords_btaskbar_adjustment(int bth_adj)
Definition: lg_gr_func.c:446
lg_rec_f_from_rec_i
Rec2Df lg_rec_f_from_rec_i(Rec2Di r)
Definition: lg_gr_func.c:320
lg_clip_rect
zboolean lg_clip_rect(Rec2Di clip, Rec2Di rect, Rec2Di *clipped_rect)
Definition: lg_gr_func.c:163
lg_rec_i_copy
void lg_rec_i_copy(Rec2Di *dest, Rec2Di src)
Definition: lg_gr_func.c:250
gl_coords_from_screen_coords
void gl_coords_from_screen_coords(float *x2, float *y2, int x1, int y1, int viewport_w, int viewport_h)
Definition: lg_gr_func.c:406
lg_set_sdl_color_from_str
SDL_Color * lg_set_sdl_color_from_str(SDL_Color *c, const char *str)
Definition: lg_gr_func.c:643
lg_point2di_is_inside_rec2di_from_array
uint32_t lg_point2di_is_inside_rec2di_from_array(Point2Di p, Rec2Di **r, uint32_t n_rect_max)
Definition: lg_gr_func.c:504
Rec2Di
Definition: lg_gr_func.h:49
lg_get_n_color_str
int lg_get_n_color_str()
Definition: lg_gr_func.c:695