1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,159 @@ |
1 |
+/* |
|
2 |
+ * rayui.h |
|
3 |
+ * |
|
4 |
+ * Collections of functions to aid creating GUIs using raylib |
|
5 |
+ * |
|
6 |
+ * HEADER FILE |
|
7 |
+ * |
|
8 |
+ * History: |
|
9 |
+ * 20250902 Creation from imgmover prototype. |
|
10 |
+ * |
|
11 |
+ * Author: Dario Rodriguez dario@darionomono.com |
|
12 |
+ * (c) Dario Rodriguez 2025 |
|
13 |
+ * This program is licensed under the terms of GNU GPL v2.1+ |
|
14 |
+ */ |
|
15 |
+ |
|
16 |
+ |
|
17 |
+#ifndef RAYUI_H |
|
18 |
+#define RAYUI_H |
|
19 |
+ |
|
20 |
+#include "raylib.h" |
|
21 |
+ |
|
22 |
+#ifndef FILLXY |
|
23 |
+#define FILLXY(whxy,valx,valy) (whxy).x=(valx),(whxy).y=(valy) |
|
24 |
+#endif |
|
25 |
+ |
|
26 |
+#ifndef FILLWH |
|
27 |
+#define FILLWH(whxy,valw,valh) (whxy).w=(valw),(whxy).h=(valh) |
|
28 |
+#endif |
|
29 |
+ |
|
30 |
+#ifndef FILLWHXY |
|
31 |
+#define FILLWHXY(whxy,valw,valh,valx,valy) (whxy).w=(valw),(whxy).h=(valh),(whxy).x=(valx),(whxy).y=(valy) |
|
32 |
+#endif |
|
33 |
+ |
|
34 |
+#ifndef UNROLLWHXY |
|
35 |
+#define UNROLLWHXY(whxy) (whxy).w,(whxy).h,(whxy).x,(whxy).y |
|
36 |
+#endif |
|
37 |
+ |
|
38 |
+#ifndef RD |
|
39 |
+#define RD 0 |
|
40 |
+#endif |
|
41 |
+ |
|
42 |
+#ifndef WR |
|
43 |
+#define WR 1 |
|
44 |
+#endif |
|
45 |
+ |
|
46 |
+#define MAXSCROLLABLERECT 8 |
|
47 |
+#define SIZESCROLLABLERECTID 16 |
|
48 |
+ |
|
49 |
+typedef struct whxy_t { |
|
50 |
+ int w; |
|
51 |
+ int h; |
|
52 |
+ int x; |
|
53 |
+ int y; |
|
54 |
+} whxy_t; |
|
55 |
+ |
|
56 |
+typedef struct font_t { |
|
57 |
+ Font font; |
|
58 |
+ int height; |
|
59 |
+} font_t; |
|
60 |
+ |
|
61 |
+typedef struct menudata_t { |
|
62 |
+ char *title; |
|
63 |
+ whxy_t whxy; |
|
64 |
+ int sizeoptions; |
|
65 |
+ char **options; |
|
66 |
+ whxy_t optionswhxy; |
|
67 |
+ int flag_open; |
|
68 |
+ int flag_stickyopen; |
|
69 |
+ int currentoption; |
|
70 |
+} menudata_t; |
|
71 |
+ |
|
72 |
+typedef struct menubar_t { |
|
73 |
+ int height; |
|
74 |
+ int sizemenudata; |
|
75 |
+ menudata_t **menudata; |
|
76 |
+ font_t *ptrfont; |
|
77 |
+} menubar_t; |
|
78 |
+ |
|
79 |
+typedef struct rayui_t { |
|
80 |
+ int w; |
|
81 |
+ int h; |
|
82 |
+ int windowinit; |
|
83 |
+ menubar_t *menubar; |
|
84 |
+ const unsigned char *defaultfontdata; |
|
85 |
+ int sizedefaultfontdata; |
|
86 |
+ font_t *font; |
|
87 |
+ font_t *fontbig; |
|
88 |
+ font_t *fonthuge; |
|
89 |
+ struct timeval deadline; |
|
90 |
+ int targetfps; |
|
91 |
+} rayui_t; |
|
92 |
+ |
|
93 |
+typedef struct scrollrect_t { |
|
94 |
+ whxy_t whxy; |
|
95 |
+ char id[SIZESCROLLABLERECTID]; |
|
96 |
+ int scrollpos; |
|
97 |
+ int (*tryselect)(void *, Vector2); |
|
98 |
+ void *userptr; |
|
99 |
+ int scrollthreshold; |
|
100 |
+} scrollrect_t; |
|
101 |
+ |
|
102 |
+typedef struct mousedata_t { |
|
103 |
+ Vector2 oldmousepos; |
|
104 |
+ Vector2 mousepos; |
|
105 |
+ Vector2 wheel; |
|
106 |
+ int lmbpressed; |
|
107 |
+ int lmbreleased; |
|
108 |
+ int oldlmbdown; |
|
109 |
+ int lmbdown; |
|
110 |
+ int oldrmbdown; |
|
111 |
+ int rmbdown; |
|
112 |
+ int click_avail; |
|
113 |
+ int has_mousechanges; |
|
114 |
+ int needs_nextredraw; |
|
115 |
+ int is_scrolling; |
|
116 |
+ char scrollingid[SIZESCROLLABLERECTID]; |
|
117 |
+ int scrollspeed; |
|
118 |
+ long long scrollstart; |
|
119 |
+ long long scrolllast; |
|
120 |
+ Vector2 scrollstartpos; |
|
121 |
+ int scrollposstart; |
|
122 |
+ int scrollpos; |
|
123 |
+ int usedscrollablerect; |
|
124 |
+ scrollrect_t scrollablerect[MAXSCROLLABLERECT]; |
|
125 |
+} mousedata_t; |
|
126 |
+ |
|
127 |
+rayui_t *rayui_init(int w, int h, char *title, char *menus); |
|
128 |
+void rayui_free(rayui_t *rayui); |
|
129 |
+ |
|
130 |
+int rayui_scrollablerectreset(rayui_t *rayui, mousedata_t *mousedata); |
|
131 |
+int rayui_scrollablerectadd(rayui_t *rayui, mousedata_t *mousedata,whxy_t *rect, char *id, int scrollpos, int (*tryselect)(void *userptr, Vector2 mousepos),void *userptr, int scrollthreshold); |
|
132 |
+int rayui_getmousedata(rayui_t *rayui, mousedata_t *mousedata); |
|
133 |
+int is_rayui_scrolling(rayui_t *rayui, mousedata_t *mousedata,char *id, int *newscrollpos); /* newscrollpos is filled if it returns true */ |
|
134 |
+ |
|
135 |
+menubar_t *rayuimenubar_init(char *menus, font_t *font); |
|
136 |
+void rayuimenubar_free(menubar_t *menubar); |
|
137 |
+int rayuimenubar_mouse(menubar_t *menubar, Vector2 mousepos, int lmbpressed, int lmbreleased, int lmbdown, int *click_avail, char **sel_menu, char **sel_submenu); |
|
138 |
+int rayuimenubar_draw(menubar_t *menubar, int windowwidth, int windowheight, int *needs_nextredraw); |
|
139 |
+ |
|
140 |
+void rayui_settargetfps(rayui_t *rayui, int newfps); |
|
141 |
+int has_rayui_timeleft(rayui_t *rayui); |
|
142 |
+void rayui_timereset(rayui_t *rayui); |
|
143 |
+long long global_currentmilliseconds(void); |
|
144 |
+ |
|
145 |
+font_t *rayuifont_init(int size); |
|
146 |
+void rayuifont_free(font_t *font); |
|
147 |
+ |
|
148 |
+#ifndef __GNUC__ |
|
149 |
+void global_messagebox(char *format, ...); |
|
150 |
+#else |
|
151 |
+ void global_messagebox(char *format, ...) __attribute__ ((format (printf,1,2))); |
|
152 |
+#endif |
|
153 |
+Image global_loadimage(const char *filename); |
|
154 |
+ |
|
155 |
+int is_global_insidewhxy(Vector2 pos, whxy_t *whxy, int margin); |
|
156 |
+ |
|
157 |
+ |
|
158 |
+ |
|
159 |
+#endif |