Browse code

Add android target support

Dario Rodriguez authored on 16/03/2025 11:18:47
Showing 1 changed files
... ...
@@ -24,6 +24,7 @@
24 24
  *               Fix thumb aspect ratio.
25 25
  *      20250311 Fix bug because of stray CloseWindow() call.
26 26
  *               Add show using all window with right button.
27
+ *      20250316 Add android target support.
27 28
  *
28 29
  * Author: Dario Rodriguez dario@darionomono.com
29 30
  * (c) Dario Rodriguez 2025
... ...
@@ -41,23 +42,40 @@
41 42
 #include "raylib.h"
42 43
 #include "roboto_regular.c"
43 44
 
44
-#define DEFAULTWIDTH 1280
45
-#define DEFAULTHEIGHT 768
46
-
47 45
 #define UTF8DOWNARROW "\xe2\x86\x86" /* U+2186 in UTF-8 */
48 46
 
47
+#define SIMANDROID
48
+
49
+#if defined(ANDROID) || defined(SIMANDROID)
50
+#define ROOTDIR "/sdcard/"
51
+#define DEFAULTWIDTH 2400
52
+#define DEFAULTHEIGHT 1080
53
+#define LEFTSIZE 1600
54
+#define DEFAULTDIRDATAHEIGHT 520
55
+#define DEFAULTDIRDATATRIANGLEW 100
56
+#define LEFTIMAGESIDELEN 326
57
+#define FONTSIZE 64
58
+#define FONTBIGSIZE 96
59
+#define FONTHUGESIZE 128
60
+#else
61
+#define ROOTDIR "/var/www/default/animeshot/"
62
+#define DEFAULTWIDTH 1280
63
+#define DEFAULTHEIGHT 768
49 64
 #define LEFTSIZE 720
50 65
 #define DEFAULTDIRDATAHEIGHT 150
51 66
 #define DEFAULTDIRDATATRIANGLEW 35
52 67
 #define LEFTIMAGESIDELEN 125
53
-
54 68
 #define FONTSIZE 18
55 69
 #define FONTBIGSIZE 32
56 70
 #define FONTHUGESIZE 48
71
+#endif
57 72
 
58
-#define WHEELSTEP LEFTIMAGESIDELEN
59
-
73
+#if defined(SIMANDROID)
74
+#undef ROOTDIR
60 75
 #define ROOTDIR "/var/www/default/animeshot/"
76
+#endif
77
+
78
+#define WHEELSTEP LEFTIMAGESIDELEN
61 79
 
62 80
 #define SEP "/"
63 81
 
... ...
@@ -85,7 +103,7 @@
85 103
 #define UNROLLWHXY(xywh) (xywh).w,(xywh).h,(xywh).x,(xywh).y
86 104
 #endif
87 105
 
88
-#ifndef __linux__
106
+#if !defined(__linux__) && !defined(ANDROID)
89 107
 /* the old raylib used in the windows build lacks this function */
90 108
 bool IsImageValid(Image image)
91 109
 {
... ...
@@ -235,10 +253,11 @@ int imutil_submenu_count(char *menus);
235 253
 char *imutil_submenu_get(char *menus, int targetn, int *len);
236 254
 char *imutil_strduplen(char *str, int len);
237 255
 int is_imutil_insidexywh(Vector2 pos, xywh_t *xywh, int margin);
238
-int im_util_aspectmaximize(int w, int h, int maxw, int maxh, int *neww, int *newh);
256
+int imutil_aspectmaximize(int w, int h, int maxw, int maxh, int *neww, int *newh);
239 257
 int menudata_pos2option(menudata_t *menudata, Vector2 pos);
240 258
 int *getcodepoints(int *sizecodepoints);
241 259
 int is_imagefilename(char *filename);
260
+Image imutil_loadimage(const char *filename);
242 261
 
243 262
 int
244 263
 main(int argc, char *argv[])
... ...
@@ -935,7 +954,7 @@ DrawRectangle(UNROLLXYWH(body->backxywh),((Color){ 0,255,0,255 })); /* hit zone
935 954
                                                 char fullpath[2048];
936 955
                                                 snprintf(fullpath,sizeof(fullpath),"%s/%s/%s",body->rootdir,dirdata->dirname,elem->name+1);
937 956
                                                 fullpath[sizeof(fullpath)-1]='\0';
938
-                                                im=LoadImage(fullpath);
957
+                                                im=imutil_loadimage(fullpath);
939 958
                                                 if(IsImageValid(im)) {
940 959
                                                         int neww,newh;
941 960
                                                         Image im2,impixel;
... ...
@@ -945,7 +964,7 @@ fprintf(stderr,"Loaded %s\n",fullpath);
945 964
 int oldw=im.width,oldh=im.height;
946 965
 #endif
947 966
                                                         im2=GenImageColor(sidelen,sidelen,(Color){0,0,0,255});
948
-                                                        im_util_aspectmaximize(im.width,im.height,sidelen,sidelen,&neww,&newh);
967
+                                                        imutil_aspectmaximize(im.width,im.height,sidelen,sidelen,&neww,&newh);
949 968
                                                         ImageResize(&im,neww,newh);
950 969
                                                         impixel=ImageCopy(im);
951 970
                                                         ImageResize(&impixel,1,1);
... ...
@@ -1079,9 +1098,9 @@ texture_load(texture_t *texture, char *fullpath, int maxw, int maxh)
1079 1098
                 texture->has_failedload=0;
1080 1099
         }
1081 1100
         texture->currentpath[0]='\0';
1082
-        im=LoadImage(fullpath);
1101
+        im=imutil_loadimage(fullpath);
1083 1102
         if(IsImageValid(im)) {
1084
-                im_util_aspectmaximize(im.width,im.height,maxw,maxh,&neww,&newh);
1103
+                imutil_aspectmaximize(im.width,im.height,maxw,maxh,&neww,&newh);
1085 1104
                 ImageResize(&im,neww,newh);
1086 1105
                 texture->texture=LoadTextureFromImage(im);
1087 1106
                 UnloadImage(im);
... ...
@@ -1239,7 +1258,7 @@ is_imutil_insidexywh(Vector2 pos, xywh_t *xywh, int margin)
1239 1258
 }
1240 1259
 
1241 1260
 int
1242
-im_util_aspectmaximize(int w, int h, int maxw, int maxh, int *neww, int *newh)
1261
+imutil_aspectmaximize(int w, int h, int maxw, int maxh, int *neww, int *newh)
1243 1262
 {
1244 1263
         if(neww==NULL || newh==NULL || w==0 || h==0 || maxw==0 || maxh==0)
1245 1264
                 return(-1);
... ...
@@ -1529,3 +1548,39 @@ is_imagefilename(char *filename)
1529 1548
         return(0); /* not in the knownext list */
1530 1549
 }
1531 1550
 
1551
+#ifdef ANDROID
1552
+Image
1553
+imutil_loadimage(const char *filename)
1554
+{
1555
+        unsigned char *filedata=NULL;
1556
+        FILE *f=NULL;
1557
+        struct stat st;
1558
+        Image img;
1559
+        char *ext;
1560
+        if((f=fopen(filename,"r"))==NULL
1561
+          || fstat(fileno(f),&st)!=0
1562
+          || st.st_size<=0
1563
+          || (filedata=(unsigned char *)malloc(st.st_size))==NULL
1564
+          || fread(filedata,1,st.st_size,f)!=st.st_size
1565
+        ) {
1566
+                if(f!=NULL)
1567
+                        fclose(f),f=NULL;
1568
+                if(filedata!=NULL)
1569
+                        free(filedata),filedata=NULL;
1570
+                return((Image){0});
1571
+        }
1572
+        fclose(f);
1573
+        ext=strchr(filename,'.');
1574
+        ext=(ext==NULL)?filename+strlen(filename):ext;
1575
+        img=LoadImageFromMemory(ext,filedata,st.st_size);
1576
+        free(filedata),filedata=NULL;
1577
+        return(img);
1578
+}
1579
+#else
1580
+Image
1581
+imutil_loadimage(const char *filename)
1582
+{
1583
+        return(LoadImage(filename));
1584
+}
1585
+#endif
1586
+