/
gallery.c
503 lines (418 loc) · 11.4 KB
/
gallery.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
#include "homeMenu.h"
#include "clock.h"
#include "gallery.h"
#include "appDrawer.h"
#include "settingsMenu.h"
#include "screenshot.h"
#include "lockScreen.h"
#include "recentsMenu.h"
#include "powerMenu.h"
#include "fileManager.h"
#include "include/utils.h"
void galleryUp()
{
current--; // Subtract a value from current so the ">" goes up
if ((current <= curScroll-1) && (curScroll > 1)) {
curScroll--; // To do with how it scrolls
}
}
void galleryDown()
{
if (folderIcons[current+1].active) current++; // Add a value onto current so the ">" goes down
if (current >= (MAX_GALLERY_DISPLAY+curScroll)) {
curScroll++; // To do with how it scrolls
}
}
void galleryUpx5()
{
current -= 5; // Subtract a value from current so the ">" goes up
if ((current <= curScroll-1) && (curScroll > 1)) {
curScroll -= 5; // To do with how it scrolls
}
}
void galleryDownx5()
{
if (folderIcons[current+1].active) current += 5; // Add a value onto current so the ">" goes down
if (current >= (MAX_DISPLAY+curScroll)) {
curScroll += 5; // To do with how it scrolls
}
}
void galleryDisplay()
{
oslDrawImageXY(gallerybg, 0, 0);
oslDrawImageXY(gallerySelection,15,(current - curScroll)*56+GALLERY_CURR_DISPLAY_Y);
oslDrawStringf(25,25,"Album");
battery(370,2,1);
digitaltime(420,4,0,hrTime);
// Displays the directories, while also incorporating the scrolling
for(i=curScroll;i<MAX_GALLERY_DISPLAY+curScroll;i++)
{
// Handles the cursor and the display to not move past the MAX_GALLERY_DISPLAY.
// For moving down
//if ((folderIcons[i].active == 0) && (current >= i-1)) {
if ((folderIcons[i].active == 0) && (current >= i-1))
{
current = i-1;
break;
}
// For moving up
if (current <= curScroll-1)
{
current = curScroll-1;
break;
}
oslDrawImageXY(galleryThumbnail,20,(i - curScroll)*56+THUMBNAIL_DISPLAY_Y);
// If the currently selected item is active, then display the name
if (folderIcons[i].active == 1)
{
oslIntraFontSetStyle(Roboto, fontSize, WHITE, 0, 0);
oslDrawStringf(GALLERY_DISPLAY_X, (i - curScroll)*55+GALLERY_DISPLAY_Y, "%.52s", folderIcons[i].name); // change the X & Y value accordingly if you want to move it (for Y, just change the +10)
}
}
}
int changeWallpaper()
{
FILE * backgroundPathTXT;
wallpaper = oslLoadImageFilePNG("system/app/gallery/wallpaper.png", OSL_IN_RAM, OSL_PF_8888);
if (!wallpaper)
debugDisplay();
while (!osl_quit) {
oslStartDrawing();
controls();
oslIntraFontSetStyle(Roboto, fontSize, BLACK, 0, INTRAFONT_ALIGN_LEFT);
oslDrawImageXY(wallpaper, 65, 67);
oslDrawStringf(110,95,"Set picture as wallpaper?");
oslDrawStringf(110,115,"Press (X) to accept or (O) to cancel.");
if (osl_keys->pressed.cross)
{
oslDeleteImage(background);
oslPlaySound(KeypressStandard, 1);
backgroundPathTXT = fopen("system/settings/background.bin", "w");
fprintf(backgroundPathTXT,"%s", folderIcons[current].filePath);
fclose(backgroundPathTXT);
strcpy(backgroundPath, setFileDefaultsChar("system/settings/background.bin", "system/framework/framework-res/res/background.png", backgroundPath));
background = oslLoadImageFile(backgroundPath, OSL_IN_RAM, OSL_PF_8888);
oslDeleteImage(wallpaper);
return 1;
}
if (osl_keys->pressed.circle)
{
oslDeleteImage(wallpaper);
return 0;
}
oslEndDrawing();
oslEndFrame();
oslSyncFrame();
}
return 0;
}
int showImage(char * path, int n)
{
int zoomIn = 0, zoomOut = 0;
OSL_IMAGE * image = oslLoadImageFile(path, OSL_IN_RAM, OSL_PF_8888);
OSL_IMAGE * galleryBar = oslLoadImageFilePNG("system/app/gallery/galleryBar.png", OSL_IN_RAM, OSL_PF_8888);
if(!image)
return 0;
if (!galleryBar)
debugDisplay();
//Draw image in the centre
oslSetImageRotCenter(image);
image->x = OSL_SCREEN_WIDTH / 2;
image->y = OSL_SCREEN_HEIGHT / 2;
while (!osl_quit)
{
oslReadKeys();
oslStartDrawing();
oslClearScreen(RGB(255,255,255));
oslDrawImage(image);//draw image
oslDrawImageXY(galleryBar,0,0);
oslIntraFontSetStyle(Roboto, fontSize, WHITE, 0, INTRAFONT_ALIGN_LEFT);
oslDrawStringf(40,12, "%.55s", folderIcons[current].name);
if (n == 1)
{
if (osl_keys->pressed.cross)
{
oslPlaySound(KeypressStandard, 1);
changeWallpaper();
}
}
volumeController();
oslEndDrawing();
oslEndFrame();
oslSyncFrame();
if (experimentalF == 1)
{
if(osl_keys->analogY <= -50)
{
image->stretchX = image->sizeX * zoomIn++;
image->stretchY = image->sizeY * zoomOut++;
}
if(osl_keys->analogY >= 50)
{
image->stretchX = image->sizeX * zoomIn--;
image->stretchY = image->sizeY * zoomOut--;
}
}
if (osl_keys->pressed.square)
{
changeWallpaper();
}
if (osl_keys->pressed.circle)
{
if (n == 0)
{
oslDeleteImage(image);
oslDeleteImage(galleryBar);
return 1;
}
else if (n == 1)
{
oslDeleteImage(image);
oslDeleteImage(galleryBar);
displaySubThemes("system/framework/framework-res/res", 1);
}
else if ((n == 2) && (selection == 1))
{
oslDeleteImage(image);
oslDeleteImage(galleryBar);
galleryView("ms0:/PICTURE");
}
else if ((n == 2) && (selection == 2))
{
oslDeleteImage(image);
oslDeleteImage(galleryBar);
galleryView("ms0:/PSP/PHOTO");
}
else if ((n == 2) && (selection == 3))
{
oslDeleteImage(image);
oslDeleteImage(galleryBar);
galleryView("ms0:/PSP/GAME/CyanogenPSP/screenshots");
}
else
{
oslDeleteImage(image);
oslDeleteImage(galleryBar);
return 1;
}
}
captureScreenshot();
}
//delete image
oslDeleteImage(image);
return 0;
}
void galleryControls() //Controls
{
oslReadKeys();
if (pad.Buttons != oldpad.Buttons)
{
if (osl_keys->pressed.down)
{
galleryDown();
timer = 0;
}
if (osl_keys->pressed.up)
{
galleryUp();
timer = 0;
}
if (osl_keys->pressed.right)
{
galleryDownx5();
timer = 0;
}
else if (osl_keys->pressed.left)
{
galleryUpx5();
timer = 0;
}
if (osl_keys->pressed.triangle)
{
curScroll = 1;
current = 1;
}
if (osl_keys->pressed.cross)
{
oslPlaySound(KeypressStandard, 1);
openDir(folderIcons[current].filePath, folderIcons[current].fileType);
}
}
volumeController();
if (osl_keys->pressed.cross && (strcmp(folderIcons[current].filePath, "doesn't matter") != 0))
{
oslPlaySound(KeypressStandard, 1);
galleryUnload();
showImage(folderIcons[current].filePath, 2);
}
if (osl_keys->pressed.circle)
{
if((strcmp("ms0:/PICTURE", curDir)==0) || (strcmp("ms0:/PSP/PHOTO", curDir)==0) || (strcmp("ms0:/PSP/GAME/CyanogenPSP/screenshots", curDir)==0) || (strcmp("ms0:/", curDir)==0))
{
galleryUnload();
galleryApp();
}
else if((strcmp("ms0:/PICTURE", curDir)!=0))
{
dirBack(6);
}
else if((strcmp("ms0:/PSP/PHOTO", curDir)!=0))
{
dirBack(7);
}
else if((strcmp("ms0:/PSP/GAME/CyanogenPSP/screenshots", curDir)!=0))
{
dirBack(8);
}
}
if (osl_keys->pressed.square)
{
powermenu();
}
if (osl_keys->pressed.L)
{
oslPlaySound(Lock, 1);
lockscreen();
}
captureScreenshot();
timer++;
if ((timer > 30) && (pad.Buttons & PSP_CTRL_UP))
{
galleryUp();
timer = 25;
}
else if ((timer > 30) && (pad.Buttons & PSP_CTRL_DOWN))
{
galleryDown();
timer = 25;
}
if (current < 1)
current = 1;
if (current > MAX_FILES)
current = MAX_FILES;
}
// Just call 'path' with whichever path you want it to start off in
char * galleryBrowse(const char * path)
{
folderScan(path);
dirVars();
while (!osl_quit)
{
LowMemExit();
oslStartDrawing();
oslClearScreen(RGB(0,0,0));
oldpad = pad;
sceCtrlReadBufferPositive(&pad, 1);
galleryDisplay();
galleryControls();
if (strlen(returnMe) > 4)
break;
oslEndDrawing();
oslEndFrame();
oslSyncFrame();
}
return returnMe;
}
void galleryUnload()
{
oslDeleteImage(gallerybg);
oslDeleteImage(gallerySelection);
oslDeleteImage(galleryThumbnail);
}
int galleryView(char * browseDirectory)
{
gallerybg = oslLoadImageFilePNG(galleryBgPath, OSL_IN_RAM, OSL_PF_8888);
gallerySelection = oslLoadImageFilePNG(gallerySelectorPath, OSL_IN_RAM, OSL_PF_8888);
galleryThumbnail = oslLoadImageFilePNG("system/app/gallery/ic_images.png", OSL_IN_RAM, OSL_PF_8888);
oslSetFont(Roboto);
char * Directory = galleryBrowse(browseDirectory);
while (!osl_quit)
{
LowMemExit();
oslStartDrawing();
oslClearScreen(RGB(0,0,0));
centerText(480/2, 272/2, Directory, 50); // Shows the path that 'Directory' was supposed to receive from mp3Browse();
oslEndDrawing();
oslEndFrame();
oslSyncFrame();
}
return 0;
}
int galleryApp()
{
gallerybg = oslLoadImageFilePNG(galleryBgPath, OSL_IN_RAM, OSL_PF_8888);
gallerySelection = oslLoadImageFilePNG(gallerySelectorPath, OSL_IN_RAM, OSL_PF_8888);
galleryThumbnail = oslLoadImageFilePNG("system/app/gallery/ic_images.png", OSL_IN_RAM, OSL_PF_8888);
oslSetFont(Roboto);
if (!gallerybg || !gallerySelection || !galleryThumbnail)
debugDisplay();
int MenuSelection = 1; // Pretty obvious
int selector_x = 15; //The x position of the first selection
int selector_y = 10; //The y position of the first selection
int selector_image_x; //Determines the starting x position of the selection
int selector_image_y = 26; //Determines the starting y position of the selection
int numMenuItems = 3; //Amount of items in the menu
while (!osl_quit)
{
LowMemExit();
selector_image_x = selector_x+(galley_xSelection*MenuSelection); //Determines where the selection image is drawn for each selection
selector_image_y = selector_y+(galley_ySelection*MenuSelection); //Determines where the selection image is drawn for each selection
oslIntraFontSetStyle(Roboto, fontSize, WHITE, 0, 0);
oslStartDrawing();
oslReadKeys();
oslClearScreen(RGB(0,0,0));
oslDrawImageXY(gallerybg, 0, 0);
oslDrawStringf(25,25,"Album");
oslDrawImageXY(gallerySelection, selector_image_x, selector_image_y);
oslDrawStringf(25,89,"PICTURE");
oslDrawStringf(25,145,"PSP/PHOTO");
oslDrawStringf(25,201,"PSP/GAME/CyanogenPSP/screenshots");
battery(370,2,1);
digitaltime(420,4,0,hrTime);
volumeController();
if (osl_keys->pressed.down) MenuSelection++; //Moves the selector down
if (osl_keys->pressed.up) MenuSelection--; //Moves the selector up
if (MenuSelection > numMenuItems) MenuSelection = 1; //Sets the selection to the first
if (MenuSelection < 1) MenuSelection = numMenuItems; //Sets the selection back to last
if (MenuSelection == 1 && osl_keys->pressed.cross)
{
selection = 1;
oslPlaySound(KeypressStandard, 1);
galleryUnload();
galleryView("ms0:/PICTURE");
}
else if (MenuSelection == 2 && osl_keys->pressed.cross)
{
selection = 2;
oslPlaySound(KeypressStandard, 1);
galleryUnload();
galleryView("ms0:/PSP/PHOTO");
}
else if (MenuSelection == 3 && osl_keys->pressed.cross)
{
selection = 3;
oslPlaySound(KeypressStandard, 1);
galleryUnload();
galleryView("ms0:/PSP/GAME/CyanogenPSP/screenshots");
}
if (osl_keys->pressed.circle)
{
galleryUnload();
appdrawer();
}
if (osl_keys->pressed.square)
{
powermenu();
}
if (osl_keys->pressed.L)
{
oslPlaySound(Lock, 1);
lockscreen();
}
captureScreenshot();
oslEndDrawing();
oslEndFrame();
oslSyncFrame();
}
return selection;
}