Browse code

Initial commit

Dario Rodriguez authored on 26/01/2025 11:50:16
Showing 11 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,8 @@
1
+*.o
2
+.*.reu
3
+external/raylib
4
+toolchain-zig-dl
5
+toolchain-zig
6
+roboto_regular.c
7
+roboto_regular.h
8
+test.c
0 9
new file mode 100644
... ...
@@ -0,0 +1,22 @@
1
+CC=gcc
2
+CFLAGS=-g -Wall
3
+LDFLAGS=
4
+
5
+all: imgmover imgmover.exe
6
+
7
+imgmover: imgmover.c roboto_regular.c
8
+	$(CC) $(CFLAGS) -Iexternal/raylib/include/ imgmover.c external/raylib/libraylib.a -lm $(LDFLAGS) -o imgmover
9
+
10
+imgmover.exe: imgmover.c roboto_regular.c
11
+	sh -c "if [ ! -e test-icon_256x256.png ] ; then	convert -size 256x256 xc:white test-icon_256x256.png ; fi"
12
+	toolchain-zig/compile.sh imgmover.c -c -o imgmover-windows.o
13
+	toolchain-zig/link.sh -icon test-icon_256x256.png imgmover.exe imgmover-windows.o toolchain-zig/windows-msys2-mingw/lib/libraylib.a
14
+
15
+roboto_regular.c: ttf2h.sh fonts/Roboto-Regular.ttf
16
+	./ttf2h.sh fonts/Roboto-Regular.ttf
17
+
18
+roboto_regular.h: roboto_regular.c
19
+
20
+clean:
21
+	rm -f imgmover-windows.o imgmover imgmover.exe
22
+
0 23
new file mode 100644
... ...
@@ -0,0 +1 @@
1
+imgmover is a program to make moving/classifying images in directories easier
0 2
new file mode 100755
... ...
@@ -0,0 +1,2 @@
1
+#!/bin/bash
2
+gcc -Iexternal/raylib/include/ test.c external/raylib/libraylib.a -lm -o test
0 3
new file mode 100755
... ...
@@ -0,0 +1,6 @@
1
+#!/bin/bash
2
+if [ ! -e test-icon_256x256.png ] ; then
3
+	convert -size 256x256 xc:white test-icon_256x256.png
4
+fi
5
+toolchain-zig/compile.sh test.c -c -o test-windows.o
6
+toolchain-zig/link.sh -icon test-icon_256x256.png test.exe test-windows.o toolchain-zig/windows-msys2-mingw/lib/libraylib.a
0 7
new file mode 100755
... ...
@@ -0,0 +1,12 @@
1
+#!/bin/bash
2
+if [ -e raylib ] ; then
3
+	echo "ERROR: raylib directory already exists"
4
+	exit 1
5
+fi
6
+#sudo apt install build-essential git
7
+#sudo apt install libasound2-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev libglu1-mesa-dev libxcursor-dev libxinerama-dev libwayland-dev libxkbcommon-dev
8
+mkdir raylib
9
+cd raylib
10
+git clone --depth 1 https://github.com/raysan5/raylib.git raylib
11
+cd raylib/src/
12
+make PLATFORM=PLATFORM_DESKTOP && cd ../.. && cp ./raylib/src/libraylib.a . && mkdir include && ( cd raylib/src/ && tar -cf - *.h $(find external -name "*.h" ) ) | (cd include && tar -xf -) && echo "raylib was setup correctly."
0 13
new file mode 100644
1 14
Binary files /dev/null and b/fonts/Roboto-Regular.ttf differ
2 15
new file mode 100644
... ...
@@ -0,0 +1,485 @@
1
+/*
2
+ * imgmover.c
3
+ *
4
+ * Simple C application using raylib to move images between directories.
5
+ *
6
+ * History:
7
+ *      20250119 Creation. Menu bar.
8
+ *      20250123 Load font.
9
+ *
10
+ * Author: Dario Rodriguez dario@darionomono.com
11
+ * (c) Dario Rodriguez 2025
12
+ * This program is licensed under the terms of GNU GPL v2.1+
13
+ */
14
+
15
+#include <stdio.h>
16
+#include <stdlib.h>
17
+#include <unistd.h>
18
+#include <string.h>
19
+
20
+#include "raylib.h"
21
+#include "roboto_regular.c"
22
+
23
+#define DEFAULTWIDTH 1280
24
+#define DEFAULTHEIGHT 768
25
+
26
+#ifndef FILLXY
27
+#define FILLXY(xywh,valx,valy) (xywh).x=(valx),(xywh).y=(valy)
28
+#endif
29
+
30
+#ifndef FILLWH
31
+#define FILLWH(xywh,valw,valh) (xywh).w=(valw),(xywh).h=(valh)
32
+#endif
33
+
34
+#ifndef FILLXYWH
35
+#define FILLXYWH(xywh,valx,valy,valw,valh) (xywh).x=(valx),(xywh).y=(valy),(xywh).w=(valw),(xywh).h=(valh)
36
+#endif
37
+
38
+#ifndef UNROLLXYWH
39
+#define UNROLLXYWH(xywh) (xywh).x,(xywh).y,(xywh).w,(xywh).h
40
+#endif
41
+
42
+typedef struct xywh_t {
43
+        int x;
44
+        int y;
45
+        int w;
46
+        int h;
47
+} xywh_t;
48
+
49
+typedef struct menudata_t {
50
+        char *title;
51
+        xywh_t xywh;
52
+        int sizeoptions;
53
+        char **options;
54
+        xywh_t optionsxywh;
55
+        int flag_open;
56
+        int flag_stickyopen;
57
+        int currentoption;
58
+} menudata_t;
59
+
60
+typedef struct dirdata_t {
61
+        int height;
62
+        char *dirname;
63
+} dirdata_t;
64
+
65
+typedef struct im_t {
66
+        int w;
67
+        int h;
68
+        int sizemenudata;
69
+        menudata_t **menudata;
70
+        int sizedirdata;
71
+        dirdata_t **dirdata;
72
+        int currentdirdata;
73
+        int leftscrollpos;
74
+        int rightscrollpos;
75
+        Font font;
76
+        int font_height;
77
+} im_t;
78
+
79
+im_t *im_init(char *menus);
80
+void im_free(im_t *im);
81
+
82
+int imdraw_menus(im_t *im);
83
+
84
+int imutil_menu_count(char *menus);
85
+char *imutil_menu_get(char *menus, int targetn, int *len);
86
+int imutil_submenu_count(char *menus);
87
+char *imutil_submenu_get(char *menus, int targetn, int *len);
88
+char *imutil_strduplen(char *str, int len);
89
+int is_imutil_insidexywh(Vector2 pos, xywh_t *xywh);
90
+int menudata_pos2option(menudata_t *menudata, Vector2 pos);
91
+int *getcodepoints(int *sizecodepoints);
92
+
93
+int
94
+main(int argc, char *argv[])
95
+{
96
+        im_t *im;
97
+        Vector2 mousepos;
98
+        int flag_ignorelmb;
99
+        int i,j;
100
+        int lmbpressed,lmbreleased,lmbdown;
101
+        int flag_outsideall;
102
+        if((im=im_init("Fichero\nAjustes\nSalir\n\nEditar\nNuevo directorio\n\nAyuda\nInformación sobre el programa\n\n"))==NULL) {
103
+                return(1);
104
+        }
105
+        flag_ignorelmb=0;
106
+        while(!WindowShouldClose()) {
107
+                mousepos=GetMousePosition();
108
+                lmbpressed=IsMouseButtonPressed(0);
109
+                lmbreleased=IsMouseButtonReleased(0);
110
+                lmbdown=IsMouseButtonDown(0);
111
+                /* check if we have to open a menu */
112
+                flag_outsideall=1;
113
+                for(i=0;i<im->sizemenudata;i++) {
114
+                        int insidetitle,currentoption;
115
+                        insidetitle=is_imutil_insidexywh(mousepos,&(im->menudata[i]->xywh));
116
+                        currentoption=menudata_pos2option(im->menudata[i],mousepos);
117
+                        flag_outsideall=(currentoption!=-1)?0:flag_outsideall;
118
+                        if(lmbreleased && insidetitle) {
119
+                                for(j=0;j<im->sizemenudata;j++) {
120
+                                        im->menudata[j]->flag_stickyopen=(j==i)?1:0;
121
+                                        im->menudata[j]->flag_open=0;
122
+                                        im->menudata[j]->currentoption=-1;
123
+                                }
124
+                        } else if((lmbpressed || lmbdown) && insidetitle) {
125
+                                for(j=0;j<im->sizemenudata;j++) {
126
+                                        im->menudata[j]->flag_open=(j==i)?1:0;
127
+                                        im->menudata[j]->flag_stickyopen=0;
128
+                                        im->menudata[j]->currentoption=-1;
129
+                                }
130
+                        } else if(lmbdown && currentoption!=-1) {
131
+                                for(j=0;j<im->sizemenudata;j++) {
132
+                                        im->menudata[j]->flag_open=(j==i)?im->menudata[i]->flag_open:0;
133
+                                        im->menudata[j]->flag_stickyopen=(j==i)?im->menudata[i]->flag_stickyopen:0;
134
+                                        im->menudata[j]->currentoption=(j==i)?currentoption:-1;
135
+                                }
136
+                        } else if(lmbreleased && currentoption!=-1) {
137
+                                for(j=0;j<im->sizemenudata;j++) {
138
+                                        im->menudata[j]->flag_open=0;
139
+                                        im->menudata[j]->flag_stickyopen=0;
140
+                                        im->menudata[j]->currentoption=-1;
141
+                                }
142
+#if 1
143
+fprintf(stderr,"SELECTED: \"%s\"->\"%s\"\n",im->menudata[i]->title,im->menudata[i]->options[currentoption]);
144
+#endif
145
+                        } else if(lmbdown==0) {
146
+                                im->menudata[i]->flag_open=0;
147
+                                im->menudata[i]->flag_stickyopen=0;
148
+                                im->menudata[i]->flag_open=0;
149
+                        }
150
+                }
151
+                if(flag_outsideall) {
152
+                        for(j=0;j<im->sizemenudata;j++) {
153
+                                im->menudata[j]->currentoption=-1;
154
+                        }
155
+                }
156
+                BeginDrawing();
157
+                ClearBackground(RAYWHITE);
158
+                imdraw_menus(im);
159
+                EndDrawing();
160
+        }
161
+        CloseWindow();
162
+        im_free(im),im=NULL;
163
+        return(0);
164
+}
165
+
166
+im_t *
167
+im_init(char *menus)
168
+{
169
+        im_t *im;
170
+        int i,j;
171
+        char *str,*substr;
172
+        int len,sublen;
173
+        menudata_t *menudata;
174
+        if(menus==NULL)
175
+                return(NULL); /* sanity check failed */
176
+        if((im=calloc(1,sizeof(im_t)))==NULL
177
+          || (im->sizemenudata=imutil_menu_count(menus))<=0
178
+          || (im->menudata=calloc(im->sizemenudata,sizeof(menudata_t)))==NULL
179
+        ) {
180
+                im_free(im),im=NULL;
181
+                return(NULL); /* insuf. mem. */
182
+        }
183
+        /* init menus */
184
+        for(i=0;i<im->sizemenudata;i++) {
185
+                if((menudata=im->menudata[i]=calloc(1,sizeof(menudata_t)))==NULL
186
+                  || (str=imutil_menu_get(menus,i,&len))==NULL
187
+                  || (menudata->title=imutil_strduplen(str,len))==NULL
188
+                  || (menudata->sizeoptions=imutil_submenu_count(str))<=0
189
+                  || (menudata->options=calloc(menudata->sizeoptions,sizeof(char *)))==NULL
190
+                ) {
191
+                        im_free(im),im=NULL;
192
+                        return(NULL); /* insuf. mem. */
193
+                }
194
+                for(j=0;j<menudata->sizeoptions;j++) {
195
+                        if((substr=imutil_submenu_get(str,j,&sublen))==NULL
196
+                          || (menudata->options[j]=imutil_strduplen(substr,sublen))==NULL
197
+                        ) {
198
+                                im_free(im),im=NULL;
199
+                                return(NULL); /* insuf. mem. */
200
+                        }
201
+                }
202
+        }
203
+        /* init window */
204
+        SetTraceLogLevel(LOG_ERROR);
205
+        InitWindow((im->w=DEFAULTWIDTH),(im->h=DEFAULTHEIGHT),"Image Mover");
206
+        SetTargetFPS(30);
207
+        /* init font */
208
+        {
209
+                int sizecodepoints;
210
+                int *codepoints;
211
+                im->font_height=18;
212
+                codepoints=getcodepoints(&sizecodepoints);
213
+                im->font=LoadFontFromMemory(".ttf",(const unsigned char *)roboto_regular,sizeof(roboto_regular)-1,im->font_height,codepoints,sizecodepoints);
214
+        }
215
+#if 0
216
+        /* test imutil_menu_xxx */
217
+        int n,m,l,ml,len,mlen;
218
+        char *ptr,*mptr;
219
+        for(n=0,l=imutil_menu_count(menus);n<l;n++) {
220
+                ptr=imutil_menu_get(menus,n,&len);
221
+                fprintf(stderr,"menu[%i]:\"",n);
222
+                fwrite(ptr,1,len,stderr);
223
+                fprintf(stderr,"\"->");
224
+                for(m=0,ml=imutil_submenu_count(ptr);m<ml;m++) {
225
+                        mptr=imutil_submenu_get(ptr,m,&mlen);
226
+                        fprintf(stderr,"|\"");
227
+                        fwrite(mptr,1,mlen,stderr);
228
+                        fprintf(stderr,"\"");
229
+                }
230
+                fprintf(stderr,"\n");
231
+        }
232
+#endif
233
+#if 0
234
+        /* test menudata */
235
+        for(i=0;i<im->sizemenudata;i++) {
236
+                fprintf(stderr,"menu[%i]:\"%s\"->",i,im->menudata[i]->title);
237
+                for(j=0;j<im->menudata[i]->sizeoptions;j++)
238
+                        fprintf(stderr,"|\"%s\"",im->menudata[i]->options[j]);
239
+                fprintf(stderr,"\n");
240
+        }
241
+#endif
242
+        return(im);
243
+}
244
+
245
+void
246
+im_free(im_t *im)
247
+{
248
+        int i,j;
249
+        if(im==NULL)
250
+                return;
251
+        if(im->menudata!=NULL) {
252
+                menudata_t *menudata;
253
+                for(i=0;i<im->sizemenudata;i++) {
254
+                        if((menudata=im->menudata[i])==NULL)
255
+                                continue;
256
+                        if(menudata->title!=NULL)
257
+                                free(menudata->title),menudata->title=NULL;
258
+                        if(menudata->options!=NULL) {
259
+                                for(j=0;j<menudata->sizeoptions;j++) {
260
+                                        if(menudata->options[j]!=NULL)
261
+                                                free(menudata->options[j]),menudata->options[j]=NULL;
262
+                                }
263
+                                free(menudata->options),menudata->options=NULL,menudata->sizeoptions=0;
264
+                        }
265
+                        free(im->menudata[i]),im->menudata[i]=NULL,menudata=NULL;
266
+                }
267
+                free(im->menudata),im->menudata=NULL,im->sizemenudata=0;
268
+        }
269
+        if(im->dirdata!=NULL) {
270
+                dirdata_t *dirdata;
271
+                for(i=0;i<im->sizedirdata;i++) {
272
+                        if((dirdata=im->dirdata[i])==NULL)
273
+                                continue;
274
+                        if(dirdata->dirname!=NULL)
275
+                                free(dirdata->dirname),dirdata->dirname=NULL;
276
+                }
277
+                free(im->dirdata),im->dirdata=NULL,im->sizedirdata=0;
278
+        }
279
+        free(im),im=NULL;
280
+        return;
281
+}
282
+
283
+int
284
+imdraw_menus(im_t *im)
285
+{
286
+        int i,j,k,x;
287
+        menudata_t *menudata;
288
+        DrawRectangle(0,0,im->w, im->font_height+im->font_height/2, (Color){ 235, 235, 235, 235 } );
289
+        for(i=0,x=0;i<im->sizemenudata;i++) {
290
+                Vector2 v2;
291
+                menudata=im->menudata[i];
292
+                v2=MeasureTextEx(im->font,menudata->title,im->font_height,0);
293
+                FILLXYWH(menudata->xywh,x,0,((int)v2.x)+im->font_height,im->font_height+im->font_height/2);
294
+                v2.x=(float) (menudata->xywh.x+im->font_height/2);
295
+                v2.y=(float) (menudata->xywh.y+im->font_height/4);
296
+                DrawTextEx(im->font
297
+                  ,menudata->title
298
+                  ,v2
299
+                  ,im->font_height
300
+                  ,0
301
+                  ,(Color){ 45, 45, 45, 255 }
302
+                );
303
+                if(menudata->flag_open || menudata->flag_stickyopen) {
304
+                        int underline_height=3;
305
+                        int maxw;
306
+                        DrawRectangle(menudata->xywh.x,menudata->xywh.y+menudata->xywh.h-underline_height,menudata->xywh.w,underline_height, (Color){ 53,132,228,255 } );
307
+                        for(j=0,maxw=0;j<menudata->sizeoptions;j++) {
308
+                                v2=MeasureTextEx(im->font,menudata->options[j],im->font_height,0);
309
+                                maxw=(((int)(v2.x))>maxw)?((int)(v2.x)):maxw;
310
+                        }
311
+                        maxw=(maxw<(menudata->xywh.w+im->font_height))?(menudata->xywh.w+im->font_height):maxw;
312
+                        maxw+=im->font_height;
313
+                        FILLXYWH(menudata->optionsxywh,menudata->xywh.x+1,menudata->xywh.y+menudata->xywh.h+2,maxw,(im->font_height+im->font_height/2)*menudata->sizeoptions);
314
+                        DrawLine(menudata->optionsxywh.x-1,menudata->optionsxywh.y-2,menudata->optionsxywh.x+menudata->optionsxywh.w+2,menudata->optionsxywh.y-2,(Color){ 255,255,255,255 } );
315
+                        DrawLine(menudata->optionsxywh.x-1,menudata->optionsxywh.y,menudata->optionsxywh.x-1,menudata->optionsxywh.y+menudata->optionsxywh.h+1,(Color){ 255,255,255,255 } );
316
+                        DrawLine(menudata->optionsxywh.x+menudata->optionsxywh.w+2,menudata->optionsxywh.y,menudata->optionsxywh.x+menudata->optionsxywh.w+2,menudata->optionsxywh.y+menudata->optionsxywh.h+1,(Color){ 192,192,192,255 } );
317
+                        DrawLine(menudata->optionsxywh.x-1,menudata->optionsxywh.y+menudata->optionsxywh.h+1,menudata->optionsxywh.x+menudata->optionsxywh.w+2,menudata->optionsxywh.y+menudata->optionsxywh.h+1,(Color){ 192,192,192,255 } );
318
+                        DrawRectangle(menudata->optionsxywh.x,menudata->optionsxywh.y,menudata->optionsxywh.w,menudata->optionsxywh.h,(Color){ 235, 235, 235, 235 });
319
+                        for(k=0;k<menudata->sizeoptions;k++) {
320
+                                Color c;
321
+                                c=(k==menudata->currentoption)?((Color){ 255,255,255,255 }):((Color){ 45, 45, 45, 255 });
322
+                                if(k==menudata->currentoption)
323
+                                        DrawRectangle(menudata->optionsxywh.x+1,menudata->optionsxywh.y+(im->font_height+(im->font_height/2))*k,menudata->optionsxywh.w-2,im->font_height+im->font_height/2,(Color){ 53,132,228,255 });
324
+                                v2.x=(float) (menudata->optionsxywh.x+im->font_height/2);
325
+                                v2.y=(float) (menudata->optionsxywh.y+(im->font_height/4)+(im->font_height+(im->font_height/2))*k);
326
+                                DrawTextEx(im->font
327
+                                  ,menudata->options[k]
328
+                                  ,v2
329
+                                  ,im->font_height
330
+                                  ,0
331
+                                  ,c
332
+                                );
333
+                        }
334
+                } else {
335
+                        FILLXYWH(menudata->optionsxywh,0,0,0,0);
336
+                }
337
+                x=menudata->xywh.x+menudata->xywh.w;
338
+        }
339
+#warning TODO
340
+        return(0);
341
+}
342
+
343
+int
344
+imutil_menu_count(char *menus)
345
+{
346
+        int n;
347
+        char *ptr,*next;
348
+        if(menus==NULL)
349
+                return(0); /* sanity check error */
350
+        for(ptr=menus,n=0;(next=strchr(ptr,'\n'))!=NULL;ptr=next+1) {
351
+                if(next[1]=='\n') {
352
+                        next++;
353
+                        n++;
354
+                }
355
+        }
356
+        return(n);
357
+}
358
+
359
+char *
360
+imutil_menu_get(char *menus, int targetn, int *len)
361
+{
362
+        int n;
363
+        char *ptr,*next,*end;
364
+        int is_title;
365
+        if(len!=NULL)
366
+                *len=0;
367
+        if(menus==NULL || targetn<0)
368
+                return(NULL); /* sanity check error */
369
+        end=menus+strlen(menus);
370
+        for(ptr=menus,is_title=1,n=0;(next=strchr(ptr,'\n'))!=NULL;ptr=next+1) {
371
+                if(targetn==n && is_title==1) {
372
+                        if(len!=NULL)
373
+                                *len=next-ptr;
374
+                        return(ptr); /* found, return start of menu string */
375
+                }
376
+                is_title=0;
377
+                if(next[1]=='\n') {
378
+                        n++;
379
+                        next++;
380
+                        is_title=1;
381
+                }
382
+        }
383
+        return(end); /* not found, return end of menus */
384
+}
385
+
386
+int
387
+imutil_submenu_count(char *menus)
388
+{
389
+        int subn;
390
+        char *ptr,*next;
391
+        if(menus==NULL)
392
+                return(0); /* sanity check error */
393
+        next=strchr(menus,'\n');
394
+        if(next==NULL)
395
+                return(0); /* no title */
396
+        for(subn=0,ptr=next+1;(next=strchr(ptr,'\n'))!=NULL;ptr=next+1) {
397
+                subn++;
398
+                if(next[1]=='\n')
399
+                        break;
400
+        }
401
+        return(subn);
402
+}
403
+
404
+char *
405
+imutil_submenu_get(char *menus, int targetsubn, int *len)
406
+{
407
+        char *ptr,*next,*end;
408
+        int subn;
409
+        if(len!=NULL)
410
+                *len=0;
411
+        if(menus==NULL || targetsubn<0)
412
+                return(NULL); /* sanity check error */
413
+        end=menus+strlen(menus);
414
+        next=strchr(menus,'\n');
415
+        if(next==NULL)
416
+                return(end); /* no title */
417
+        for(ptr=next+1,subn=0;(next=strchr(ptr,'\n'))!=NULL;ptr=next+1,subn++) {
418
+                if(targetsubn==subn) {
419
+                        if(len!=NULL)
420
+                                *len=next-ptr;
421
+                        return(ptr);
422
+                }
423
+                if(next[1]=='\n')
424
+                        break; /* "\n\n" marks the end of submenus */
425
+        }
426
+        return(end);
427
+}
428
+
429
+char *
430
+imutil_strduplen(char *str, int len)
431
+{
432
+        char *res;
433
+        if(len<0 || (str==NULL && len!=0))
434
+                return(NULL);
435
+        if((res=malloc(len+1))==NULL)
436
+                return(NULL);
437
+        memcpy(res,str,len);
438
+        res[len]='\0';
439
+        return(res);
440
+}
441
+
442
+int
443
+is_imutil_insidexywh(Vector2 pos, xywh_t *xywh)
444
+{
445
+        if(xywh==NULL)
446
+                return(0); /* sanity check error */
447
+        if(pos.x>=(float)(xywh->x)
448
+          && pos.x<=(float)(xywh->x+xywh->w)
449
+          && pos.y>=(float)(xywh->y)
450
+          && pos.y<=(float)(xywh->y+xywh->h)
451
+        ) {
452
+                return(1);
453
+        }
454
+        return(0);
455
+}
456
+
457
+int
458
+menudata_pos2option(menudata_t *menudata, Vector2 pos)
459
+{
460
+        int n,h;
461
+        if(menudata==NULL
462
+          || (menudata->flag_open==0 && menudata->flag_stickyopen==0)
463
+          || is_imutil_insidexywh(pos, &(menudata->optionsxywh))==0
464
+        ) {
465
+                return(-1);
466
+        }
467
+        h=(menudata->sizeoptions==0)?0:menudata->optionsxywh.h/menudata->sizeoptions;
468
+        n=(((int)pos.y)-menudata->optionsxywh.y)/h;
469
+        return(n);
470
+}
471
+
472
+int *
473
+getcodepoints(int *sizecodepoints)
474
+{
475
+        static int codepoints[]={
476
+/* Basic Latin */
477
+32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
478
+/* Latin-1 Supplement */
479
+160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,
480
+};
481
+        if(sizecodepoints!=NULL)
482
+                *sizecodepoints=(int) (sizeof(codepoints)/sizeof(codepoints[0]));
483
+        return(codepoints);
484
+}
485
+
0 486
new file mode 100755
... ...
@@ -0,0 +1,200 @@
1
+#!/bin/bash
2
+zigbuild=zig-linux-x86_64-0.11.0-dev.514+4be1bb4aa.tar.xz
3
+zigversion=$(echo $zigbuild | cut -d '-' -f 4)
4
+if [ -e toolchain-zig ] ; then
5
+        echo "ERROR: A toolchain-zig directory already exists, aborting install"
6
+        exit 1
7
+fi
8
+parentdir=$(pwd)
9
+mkdir -p toolchain-zig toolchain-zig-dl
10
+cd toolchain-zig
11
+
12
+# Zig install
13
+if [ ! -e ../toolchain-zig-dl/$zigbuild ] ; then
14
+        (cd ../toolchain-zig-dl && wget https://ziglang.org/builds/$zigbuild)
15
+fi
16
+xz -dc <../toolchain-zig-dl/$zigbuild | tar -xvf -
17
+ln -s ${zigbuild/.tar.xz/} zig-$zigversion
18
+cat > env.sh  <<'EOF'
19
+#!/bin/bash
20
+echo "Reminder: this script has to be used with source (.) instead of exec"
21
+EOF
22
+echo "export PATH=\$PATH:$parentdir/toolchain-zig/zig-$zigversion" >> env.sh
23
+chmod 755 env.sh
24
+# Convenience scripts
25
+cat > compile.sh  <<EOF
26
+#!/bin/bash
27
+if [ "m\$2" = "m--help" ] ; then
28
+        echo "Syntax: \$0 source.c -c -o result.o [flags]"
29
+        exit 1
30
+fi
31
+. "$parentdir/toolchain-zig/env.sh" >/dev/null
32
+exec zig cc "-I$parentdir/toolchain-zig/windows-msys2-mingw/include/" "-I$parentdir/toolchain-zig/windows-msys2-mingw/include/w32api/" "-I$parentdir/toolchain-zig/windows-msys2-mingw/include/SDL2" "-I$parentdir/toolchain-zig/windows-msys2-mingw/include/SDL" "\$@" -target x86_64-windows-gnu
33
+EOF
34
+chmod 755 compile.sh
35
+cat > compile-cpp.sh  <<EOF
36
+#!/bin/bash
37
+if [ "m$2" = "m--help" ] ; then
38
+        echo "Syntax: $0 source.cpp -c -o result.o [flags]"
39
+        exit 1
40
+fi
41
+. "$parentdir/toolchain-zig/env.sh" >/dev/null
42
+exec zig c++ "-I$parentdir/toolchain-zig/windows-msys2-mingw/include/" "-I$parentdir/toolchain-zig/windows-msys2-mingw/include/w32api/" "-I$parentdir/toolchain-zig/windows-msys2-mingw/include/SDL2" "-I$parentdir/toolchain-zig/windows-msys2-mingw/include/SDL" "\$@" -target x86_64-windows-gnu
43
+EOF
44
+chmod 755 compile-cpp.sh
45
+
46
+cat > link.sh  <<EOF
47
+#!/bin/bash
48
+tmpicon=0
49
+if [ "m\$1" = "m-icon" ] ; then
50
+        shift
51
+        icon="\$1"
52
+        shift
53
+else
54
+        tmpicon=1
55
+        icon=\$(mktemp -p . --suffix=.png)
56
+        convert -size 256x256 xc:white \$icon
57
+fi
58
+if [ "\${icon/.png/}" = "\$icon" ] || [ "\${1/.exe/}" = "\$1" ] || [ ! -e "\$2" ] ; then
59
+        echo "Syntax: \$0 [-icon myicon.png] result.exe source1.o [source2.o [...]"
60
+        if [ \$tmpicon -eq 1 ] ; then rm "\$icon" ; fi
61
+        exit 1
62
+fi
63
+. "$parentdir/toolchain-zig/env.sh" >/dev/null
64
+name="\${1/.exe/}"
65
+shift
66
+convert "\$icon" "\${icon/.png/-buildiconobject.ico}" && \
67
+ echo "1 ICON \"\${icon/.png/-buildiconobject.ico}\"" > "\${icon/.png/-buildiconobject.rc}" && \
68
+ x86_64-w64-mingw32-windres --preprocessor /usr/bin/cpp "\${icon/.png/-buildiconobject.rc}" "\${icon/.png/-buildiconobject.o}" && \
69
+ zig build-exe --subsystem windows "\$@" \${icon/.png/-buildiconobject.o} -L$parentdir/toolchain-zig/windows-msys2-mingw/lib/ -L$parentdir/toolchain-zig/windows-msys2-mingw/lib/w32api -lgdi32 -lwinmm -lsetupapi -lmincore -lwindowsapp -limm32 -lversion -lgraphite2 -lpng -lbrotlidec -lbrotlicommon -lharfbuzz -lstdc++ -lbz2 -lz --name \$name -target x86_64-windows-gnu && if [ -e "\${name}.lib" ] ; then rm "\${name}.lib" ; fi ; rm "\${name}.pdb"
70
+res=\$?
71
+rm "\${icon/.png/-buildiconobject.ico}" "\${icon/.png/-buildiconobject.rc}" "\${icon/.png/-buildiconobject.o}"
72
+if [ \$tmpicon -eq 1 ] ; then rm "\$icon" ; fi
73
+exit \$res
74
+EOF
75
+chmod 755 link.sh
76
+# msys2 install
77
+mkdir -p windows-msys2-mingw
78
+cat > deps.txt <<'EOF'
79
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-aom-3.5.0-1-any.pkg.tar.zst
80
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-brotli-1.0.9-5-any.pkg.tar.zst
81
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-bzip2-1.0.8-2-any.pkg.tar.zst
82
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-ca-certificates-20211016-3-any.pkg.tar.zst
83
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-dav1d-1.0.0-1-any.pkg.tar.zst
84
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-expat-2.5.0-1-any.pkg.tar.zst
85
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-flac-1.4.2-1-any.pkg.tar.zst
86
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-fluidsynth-2.3.0-1-any.pkg.tar.zst
87
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-gcc-libs-12.2.0-6-any.pkg.tar.zst
88
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-gettext-0.21-3-any.pkg.tar.zst
89
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-giflib-5.2.1-3-any.pkg.tar.zst
90
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-glib2-2.74.3-1-any.pkg.tar.zst
91
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-gmp-6.2.1-3-any.pkg.tar.zst
92
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-graphite2-1.3.14-2-any.pkg.tar.zst
93
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-harfbuzz-5.3.1-2-any.pkg.tar.zst
94
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-highway-1.0.2-1-any.pkg.tar.zst
95
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-imath-3.1.6-1-any.pkg.tar.zst
96
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-jbigkit-2.1-4-any.pkg.tar.xz
97
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-lcms2-2.14-1-any.pkg.tar.zst
98
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-lerc-4.0.0-1-any.pkg.tar.zst
99
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-libavif-0.11.1-3-any.pkg.tar.zst
100
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-libdeflate-1.15-1-any.pkg.tar.zst
101
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-libffi-3.4.4-1-any.pkg.tar.zst
102
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-libiconv-1.17-1-any.pkg.tar.zst
103
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-libjpeg-turbo-2.1.4-1-any.pkg.tar.zst
104
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-libjxl-0.7.0-2-any.pkg.tar.zst
105
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-libmodplug-0.8.9.0-4-any.pkg.tar.zst
106
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-libogg-1.3.5-1-any.pkg.tar.zst
107
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-libpng-1.6.39-1-any.pkg.tar.zst
108
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-libsndfile-1.1.0-3-any.pkg.tar.zst
109
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-libsystre-1.0.1-4-any.pkg.tar.xz
110
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-libtasn1-4.19.0-1-any.pkg.tar.zst
111
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-libtiff-4.4.0-6-any.pkg.tar.zst
112
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-libtre-git-r128.6fb7206-2-any.pkg.tar.xz
113
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-libvorbis-1.3.7-1-any.pkg.tar.zst
114
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-libwebp-1.2.4-2-any.pkg.tar.zst
115
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-libwinpthread-git-10.0.0.r157.gd295924f0-1-any.pkg.tar.zst
116
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-libyuv-1844.r2374.f9fda6e7-1-any.pkg.tar.zst
117
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-mpc-1.2.1-1-any.pkg.tar.zst
118
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-mpdecimal-2.5.1-1-any.pkg.tar.zst
119
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-mpfr-4.1.0.p13-1-any.pkg.tar.zst
120
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-mpg123-1.31.1-1-any.pkg.tar.zst
121
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-ncurses-6.3-6-any.pkg.tar.zst
122
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-openexr-3.1.5-2-any.pkg.tar.zst
123
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-openssl-1.1.1.s-1-any.pkg.tar.zst
124
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-opus-1.3.1-5-any.pkg.tar.zst
125
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-opusfile-0.12-2-any.pkg.tar.zst
126
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-p11-kit-0.24.1-3-any.pkg.tar.zst
127
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-pcre2-10.40-1-any.pkg.tar.zst
128
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-portaudio-1~19.7.0-4-any.pkg.tar.zst
129
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-python-3.10.8-2-any.pkg.tar.zst
130
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-rav1e-0.6.1-1-any.pkg.tar.zst
131
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-SDL2-2.26.0-1-any.pkg.tar.zst
132
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-SDL2_image-2.6.2-3-any.pkg.tar.zst
133
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-SDL2_mixer-2.6.2-1-any.pkg.tar.zst
134
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-SDL2_ttf-2.20.1-1-any.pkg.tar.zst
135
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-sqlite3-3.40.0-1-any.pkg.tar.zst
136
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-svt-av1-1.3.0-1-any.pkg.tar.zst
137
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-tcl-8.6.12-1-any.pkg.tar.zst
138
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-tzdata-2022g-1-any.pkg.tar.zst
139
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-vulkan-headers-1.3.236-1-any.pkg.tar.zst
140
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-vulkan-loader-1.3.236-1-any.pkg.tar.zst
141
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-wineditline-2.205-3-any.pkg.tar.xz
142
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-xz-5.2.9-1-any.pkg.tar.zst
143
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-zlib-1.2.13-2-any.pkg.tar.zst
144
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-zstd-1.5.2-2-any.pkg.tar.zst
145
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-winpthreads-git-12.0.0.r351.gcdf6b16b8-1-any.pkg.tar.zst
146
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-cmake-3.30.5-1-any.pkg.tar.zst
147
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-ninja-1.12.1-1-any.pkg.tar.zst
148
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-pkg-config-0.29.2-6-any.pkg.tar.zst
149
+https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-raylib-5.0-1-any.pkg.tar.zst
150
+https://mirror.msys2.org/msys/x86_64/msys2-w32api-headers-10.0.0.r16.g49a56d453-1-x86_64.pkg.tar.zst
151
+https://mirror.msys2.org/msys/x86_64/msys2-w32api-runtime-10.0.0.r16.g49a56d453-1-x86_64.pkg.tar.zst
152
+https://mirror.msys2.org/msys/x86_64/perl-5.38.2-2-x86_64.pkg.tar.zst
153
+EOF
154
+for i in  $(cat deps.txt) ; do
155
+        if [ ! -e ../toolchain-zig-dl/$(basename $i) ] ; then
156
+                (cd ../toolchain-zig-dl && wget $i )
157
+        fi
158
+done
159
+for i in $(cd ../toolchain-zig-dl && find . -maxdepth 1 -name "*.zst") ; do 
160
+         ( mkdir -p t ; cd t ; cat ../../toolchain-zig-dl/$i | zstd -dc | tar -xvf - ; find . -maxdepth 1 -type d  -print | grep -v "^\.\$" | while read l ; do
161
+          (cd $l && tar -cf - . | (cd $parentdir/toolchain-zig/windows-msys2-mingw && tar -xvf - ) ) ; done ) ; rm -rf t ; done
162
+for i in $(cd ../toolchain-zig-dl && find . -maxdepth 1 -name "*.xz") ; do 
163
+         ( mkdir -p t ; cd t ; cat ../../toolchain-zig-dl/$i | xz -dc | tar -xvf - ; find . -maxdepth 1 -type d  -print | grep -v "^\.\$" | while read l ; do
164
+         (cd $l && tar -cf - . | (cd $parentdir/toolchain-zig/windows-msys2-mingw && tar -xvf - ) ) ; done ) ; rm -rf t ; done
165
+cat > add-zst.sh <<'EOF'
166
+#!/bin/bash
167
+if [ "m$1" == "m" ] || [ "m$1" == "m--help" ] || [ ! -f "$1" ] ; then
168
+        echo "Syntax: $0 filename.pkg.tar.zst"
169
+        exit 0
170
+fi
171
+i="$1"
172
+( mkdir -p t ; cd t ; cat ../$i | zstd -dc | tar -xvf - ; find . -maxdepth 1 -type d  -print | grep -v "^\.\$" | while read l ; do
173
+EOF
174
+echo " (cd \$l && tar -cf - . | (cd $parentdir/toolchain-zig/windows-msys2-mingw && tar -xvf - ) ) ; done ) ; rm -rf t " >> add-zst.sh
175
+cat > add-xz.sh <<'EOF'
176
+#!/bin/bash
177
+if [ "m$1" == "m" ] || [ "m$1" == "m--help" ] || [ ! -f "$1" ] ; then
178
+        echo "Syntax: $0 filename.pkg.tar.xz"
179
+        exit 0
180
+fi
181
+i="$1"
182
+( mkdir -p t ; cd t ; cat ../$i | xz -dc | tar -xvf - ; find . -maxdepth 1 -type d  -print | grep -v "^\.\$" | while read l ; do
183
+EOF
184
+echo " (cd $l && tar -cf - . | (cd $parentdir/toolchain-zig/windows-msys2-mingw && tar -xvf - ) ) ; done ) ; rm -rf t " >> add-xz.sh
185
+chmod a+x add-xz.sh add-zst.sh
186
+cd ..
187
+# Check for windres
188
+if ! which x86_64-w64-mingw32-windres >/dev/null 2>/dev/null; then
189
+        echo "Please, install windres manually using your distribution, i.e.:" >> tooldchain-zig/error.log
190
+        echo "sudo apt-get install binutils-mingw-w64-x86-64" >> tooldchain-zig/error.log
191
+fi
192
+if ! which convert >/dev/null 2>/dev/null; then
193
+        echo "Please, install imagemagick manually using your distribution, i.e.:" >> tooldchain-zig/error.log
194
+        echo "sudo apt-get install imagemagick" >> tooldchain-zig/error.log
195
+fi
196
+# Success message
197
+echo ""
198
+echo "Installation complete."
199
+echo "To use the zig toolchain, first include env.sh with \". toolchain-zig/env.sh\""
200
+echo "( alternative: use toolchain-zig/compile.sh and toolchain-zig/link.sh )"
0 201
new file mode 100644
1 202
Binary files /dev/null and b/test-icon_256x256.png differ
2 203
new file mode 100755
... ...
@@ -0,0 +1,6 @@
1
+#!/bin/bash
2
+name=$(basename $1 | sed 's/\.ttf$//g' | tr -- '-A-Z.' '_a-z_')
3
+sizename=$( echo SIZE_${name} | tr a-z A-Z )
4
+sizeval=$( wc -c "$1" | expand | sed "s/^ *//g" | cut -d ' '  -f 1)
5
+( echo "extern const char *${name};" ; echo "#define $sizename $sizeval" ) > ${name}.h
6
+( echo "const char *${name}={\"\\" ; hexdump -v -C "$1" | expand | sed "s/  */ /g" | cut -d '|' -f 1 | grep " [^ ]" | cut -d ' ' -f 2- | sed "s/^/ /;s/ *\$//g" | sed "s/ /\\\x/g" | sed "s/\$/\\\/g" ; echo "\"};" ) > ${name}.c