forked from ps2homebrew/wLaunchELF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jpgviewer.c
991 lines (913 loc) · 39 KB
/
jpgviewer.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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
//--------------------------------------------------------------
//File name: jpgviewer.c
//--------------------------------------------------------------
#include "launchelf.h"
static char msg0[MAX_PATH], msg1[MAX_PATH], jpgpath[MAX_PATH];
static int SlideShowTime = 5, SlideShowTrans = 2, SlideShowBegin, SlideShowStart, SlideShowStop, SlideShowSkip;
static int Brightness, TimeRemain, PrintLen;
static float PanPosX, PanPosY, PanPosX1, PanPosY1;
static float PanZoom, PanOffsetX, PanOffsetY;
float PicW, PicH, PicCoeff;
float PicWidth, PicHeight;
int PicRotate, FullScreen;
#define OFF 1
#define ZOOM 2
#define FADE 3
#define ZOOM_FADE 4
#define LIST 1
#define THUMBNAIL 2
#define NOTLOADED -1
#define BADJPG 0
#define LOADED 1
//--------------------------------------------------------------
static void Command_List(void)
{
int x, y;
int event, post_event = 0;
int command_len = strlen(LNG(Start_StartStop_Slideshow)) > strlen(LNG(Start_StartStop_Slideshow)) ?
strlen(LNG(Start_StartStop_Slideshow)) :
strlen(LNG(Start_StartStop_Slideshow));
command_len = strlen(LNG(L1R1_Slideshow_Timer)) > command_len ?
strlen(LNG(L1R1_Slideshow_Timer)) :
command_len;
command_len = strlen(LNG(L2R2_Slideshow_Transition)) > command_len ?
strlen(LNG(L2R2_Slideshow_Transition)) :
command_len;
command_len = strlen(LNG(LeftRight_Pad_PrevNext_Picture)) > command_len ?
strlen(LNG(LeftRight_Pad_PrevNext_Picture)) :
command_len;
command_len = strlen(LNG(UpDown_Pad_Rotate_Picture)) > command_len ?
strlen(LNG(UpDown_Pad_Rotate_Picture)) :
command_len;
command_len = strlen(LNG(Left_Joystick_Panorama)) > command_len ?
strlen(LNG(Left_Joystick_Panorama)) :
command_len;
command_len = strlen(LNG(Right_Joystick_Vertical_Zoom)) > command_len ?
strlen(LNG(Right_Joystick_Vertical_Zoom)) :
command_len;
command_len = strlen(LNG(FullScreen_Mode)) + 3 > command_len ?
strlen(LNG(FullScreen_Mode)) + 3 :
command_len;
command_len = strlen(LNG(Exit_To_Jpg_Browser)) + 3 > command_len ?
strlen(LNG(Exit_To_Jpg_Browser)) + 3 :
command_len;
int Command_ch_w = command_len + 1; //Total characters in longest Command Name.
int Command_ch_h = 9; //Total Command lines number.
int cSprite_Y1 = SCREEN_HEIGHT / 2 - ((Command_ch_h + 1) * FONT_HEIGHT) / 2; //Top edge
int cSprite_X2 = SCREEN_WIDTH / 2 + ((Command_ch_w + 3) * FONT_WIDTH) / 2; //Right edge
int cSprite_X1 = cSprite_X2 - (Command_ch_w + 3) * FONT_WIDTH - 4; //Left edge
int cSprite_Y2 = cSprite_Y1 + (Command_ch_h + 1) * FONT_HEIGHT; //Bottom edge
char tmp[MAX_PATH];
event = 1; //event = initial entry.
while (1) {
//Pad response section.
waitPadReady(0, 0);
if (readpad()) {
if (new_pad) {
event |= 2; //event |= valid pad command.
break;
}
}
if (event || post_event) { //NB: We need to update two frame buffers per event.
//Display section.
drawOpSprite(setting->color[COLOR_BACKGR], cSprite_X1, cSprite_Y1, cSprite_X2, cSprite_Y2);
drawFrame(cSprite_X1, cSprite_Y1, cSprite_X2, cSprite_Y2, setting->color[COLOR_FRAME]);
y = cSprite_Y1 + FONT_HEIGHT / 2;
x = cSprite_X1 + 2 * FONT_WIDTH;
printXY(LNG(Start_StartStop_Slideshow), x, y, setting->color[COLOR_TEXT], TRUE, 0);
y += FONT_HEIGHT;
printXY(LNG(L1R1_Slideshow_Timer), x, y, setting->color[COLOR_TEXT], TRUE, 0);
y += FONT_HEIGHT;
printXY(LNG(L2R2_Slideshow_Transition), x, y, setting->color[COLOR_TEXT], TRUE, 0);
y += FONT_HEIGHT;
printXY(LNG(LeftRight_Pad_PrevNext_Picture), x, y, setting->color[COLOR_TEXT], TRUE, 0);
y += FONT_HEIGHT;
printXY(LNG(UpDown_Pad_Rotate_Picture), x, y, setting->color[COLOR_TEXT], TRUE, 0);
y += FONT_HEIGHT;
printXY(LNG(Left_Joystick_Panorama), x, y, setting->color[COLOR_TEXT], TRUE, 0);
y += FONT_HEIGHT;
printXY(LNG(Right_Joystick_Vertical_Zoom), x, y, setting->color[COLOR_TEXT], TRUE, 0);
y += FONT_HEIGHT;
if (swapKeys)
sprintf(tmp, "�1: %s", LNG(FullScreen_Mode));
else
sprintf(tmp, "�0: %s", LNG(FullScreen_Mode));
printXY(tmp, x, y, setting->color[COLOR_TEXT], TRUE, 0);
y += FONT_HEIGHT;
sprintf(tmp, "�3: %s", LNG(Exit_To_Jpg_Browser));
printXY(tmp, x, y, setting->color[COLOR_TEXT], TRUE, 0);
y += FONT_HEIGHT;
} //ends if(event||post_event).
drawScr();
post_event = event;
event = 0;
} //ends while.
} //ends Command_List.
//--------------------------------------------------------------
static void View_Render(void)
{
char *name, tmp[MAX_PATH];
float ScreenPosX, ScreenPosX1, ScreenPosY, ScreenPosY1;
float ScreenOffsetX, ScreenOffsetY;
float TmpPosX, TmpPosY;
// Init picture position on screen
if (FullScreen) {
ScreenPosX = 0.0f;
ScreenPosX1 = SCREEN_WIDTH;
ScreenPosY = 0.0f;
ScreenPosY1 = SCREEN_HEIGHT;
} else {
ScreenPosX = SCREEN_MARGIN;
ScreenPosX1 = SCREEN_WIDTH - SCREEN_MARGIN;
ScreenPosY = Frame_start_y;
ScreenPosY1 = Frame_end_y;
}
// Init black bars
if ((ScreenOffsetX = ((ScreenPosX1 - ScreenPosX) - ((ScreenPosY1 - ScreenPosY) * PicCoeff)) / 2) <= 0.0f)
ScreenOffsetX = 0.0f;
if ((ScreenOffsetY = ((ScreenPosY1 - ScreenPosY) - ((ScreenPosX1 - ScreenPosX) / PicCoeff)) / 2) <= 0.0f)
ScreenOffsetY = 0.0f;
// Init panorama
PanPosX = 0.0f;
PanPosY = 0.0f;
PanPosX1 = PicWidth;
PanPosY1 = PicHeight;
if (PanZoom == 1.0f) {
PanOffsetX = 0.0f;
PanOffsetY = 0.0f;
} else {
PanPosX = TmpPosX = ((PicWidth / 8) - ((1.5f - PanZoom) * (PicWidth / 4)));
if ((PanPosX += PanOffsetX * TmpPosX) <= 0.0f)
PanPosX = 0.0f;
if ((PanPosX1 = PicWidth - (TmpPosX * 2 - PanPosX)) >= PicWidth)
PanPosX1 = PicWidth;
PanPosY = TmpPosY = ((PicHeight / 8) - ((1.5f - PanZoom) * (PicHeight / 4)));
if ((PanPosY += PanOffsetY * TmpPosY) <= 0.0f)
PanPosY = 0.0f;
if ((PanPosY1 = PicHeight - (TmpPosY * 2 - PanPosY)) >= PicHeight)
PanPosY1 = PicHeight;
}
// Clear screen
clrScr(setting->color[COLOR_BACKGR]);
// Draw color8 graph4
gsKit_prim_sprite(gsGlobal, ScreenPosX, ScreenPosY, ScreenPosX1, ScreenPosY1, 0, setting->color[COLOR_GRAPH4]);
// Draw picture
if (PicRotate == 0 || PicRotate == 1 || PicRotate == 3) { // No rotation, rotate +90�, -90�
gsKit_prim_sprite_texture(gsGlobal,
&TexPicture,
ScreenPosX + ScreenOffsetX, ScreenPosY + ScreenOffsetY, PanPosX, PanPosY,
ScreenPosX1 - ScreenOffsetX, ScreenPosY1 - ScreenOffsetY, PanPosX1, PanPosY1,
0, GS_SETREG_RGBAQ(Brightness * 1.28f, Brightness * 1.28f, Brightness * 1.28f, 0x80, 0x00));
} else if (PicRotate == 2) { // Rotate 180�
gsKit_prim_sprite_texture(gsGlobal,
&TexPicture,
ScreenPosX + ScreenOffsetX, ScreenPosY + ScreenOffsetY, PanPosX1, PanPosY1,
ScreenPosX1 - ScreenOffsetX, ScreenPosY1 - ScreenOffsetY, PanPosX, PanPosY,
0, GS_SETREG_RGBAQ(Brightness * 1.28f, Brightness * 1.28f, Brightness * 1.28f, 0x80, 0x00));
}
setBrightness(50);
if (!FullScreen) {
//Tooltip section
strcpy(tmp, jpgpath);
name = strrchr(tmp, '/');
strcpy(name, name + 1);
msg0[0] = '\0';
sprintf(msg0, "%s %s: %s %s: %d*%d ",
LNG(Jpg_Viewer), LNG(Picture), name, LNG(Size), (int)PicW, (int)PicH);
msg1[0] = '\0';
sprintf(msg1, "Select: %s ", LNG(Command_List));
tmp[0] = '\0';
if (TimeRemain < 60)
sprintf(tmp, "%s: %d sec %s: ", LNG(Timer), TimeRemain, LNG(Transition));
else
sprintf(tmp, "%s: %d m %d sec %s: ", LNG(Timer), TimeRemain / 60, TimeRemain % 60, LNG(Transition));
strcat(msg1, tmp);
if (SlideShowTrans == OFF)
strcat(msg1, LNG(Off));
else if (SlideShowTrans == ZOOM)
strcat(msg1, LNG(Zoom));
else if (SlideShowTrans == FADE)
strcat(msg1, LNG(Fade));
else if (SlideShowTrans == ZOOM_FADE)
strcat(msg1, LNG(ZoomFade));
setScrTmp(msg0, msg1);
} /* end FullScreen */
drawScr();
} /* end View_Render */
//--------------------------------------------------------------
static void View_Input(void)
{
int i = 0;
u64 OldTime = Timer() + 1000;
while (1) {
if (SlideShowStart) {
if (Timer() >= OldTime) {
OldTime = Timer() + 1000;
if (--TimeRemain <= 0)
break;
View_Render();
}
} else {
if (Timer() >= OldTime) {
OldTime = Timer() + 1000;
TimeRemain = SlideShowTime;
View_Render();
}
}
//Pad response section
waitPadReady(0, 0);
if (readpad()) {
if (new_pad & PAD_R3_V0) { // PanZoom In
if (PanZoom < 2.75f) {
PanZoom += 0.01f * joy_value / 32;
SlideShowStart = 0;
View_Render();
} /* end if */
} else if (new_pad & PAD_R3_V1) { // PanZoom Out
if (PanZoom > 1.0f) {
PanZoom -= 0.01f * joy_value / 32;
SlideShowStart = 0;
View_Render();
} /* end if */
} else if (new_pad & PAD_L3_H1) { // Move Right
if (PanOffsetX < 0.95f) {
PanOffsetX += 0.05f / PanZoom * joy_value / 32;
SlideShowStart = 0;
View_Render();
} /* end if */
} else if (new_pad & PAD_L3_H0) { // Move Left
if (PanOffsetX > -0.95f) {
PanOffsetX -= 0.05f / PanZoom * joy_value / 32;
SlideShowStart = 0;
View_Render();
} /* end if */
} else if (new_pad & PAD_L3_V1) { // Move Down
if (PanOffsetY < 0.95f) {
PanOffsetY += 0.05f / PanZoom * joy_value / 32;
SlideShowStart = 0;
View_Render();
} /* end if */
} else if (new_pad & PAD_L3_V0) { // Move Up
if (PanOffsetY > -0.95f) {
PanOffsetY -= 0.05f / PanZoom * joy_value / 32;
SlideShowStart = 0;
View_Render();
} /* end if */
} else if (new_pad & PAD_RIGHT) { // Next Pic
SlideShowSkip = 1;
break;
} else if (new_pad & PAD_LEFT) { // Prev Pic
SlideShowSkip = -1;
break;
} else if (new_pad & PAD_UP) { // Rotate Pic +
if (PanZoom != 1.0f) {
for (i = 0; i < 35; ++i) {
if ((PanZoom -= 0.05F) <= 1.0F)
PanZoom = 1.0F;
View_Render();
} /* end for */
} /* end if */
if (++PicRotate >= 4)
PicRotate = 0;
loadSkin(JPG_PIC, jpgpath, 0);
WaitTime = Timer();
while (Timer() < WaitTime + 500)
; // Wait To Ensure Switch
View_Render();
TimeRemain = SlideShowTime;
} else if (new_pad & PAD_DOWN) { // Rotate Pic -
if (PanZoom != 1.0f) {
for (i = 0; i < 35; ++i) {
if ((PanZoom -= 0.05F) <= 1.0F)
PanZoom = 1.0F;
View_Render();
} /* end for */
} /* end if */
if (--PicRotate <= -1)
PicRotate = 3;
loadSkin(JPG_PIC, jpgpath, 0);
WaitTime = Timer();
while (Timer() < WaitTime + 500)
; // Wait To Ensure Switch
View_Render();
TimeRemain = SlideShowTime;
} else if (new_pad & PAD_R1) {
if (++SlideShowTime >= 3600)
SlideShowTime = 3600;
WaitTime = Timer();
while (Timer() < WaitTime + 100)
; // Wait To Ensure Switch
if (++TimeRemain >= 3600)
TimeRemain = 3600;
View_Render();
} else if (new_pad & PAD_L1) {
if (--SlideShowTime <= 1)
SlideShowTime = 1;
WaitTime = Timer();
while (Timer() < WaitTime + 100)
; // Wait To Ensure Switch
if (--TimeRemain <= 1)
TimeRemain = 1;
View_Render();
} else if (new_pad & PAD_R2) {
if (++SlideShowTrans > 4)
SlideShowTrans = 1;
WaitTime = Timer();
while (Timer() < WaitTime + 500)
; // Wait To Ensure Switch
View_Render();
} else if (new_pad & PAD_L2) {
if (--SlideShowTrans < 1)
SlideShowTrans = 4;
WaitTime = Timer();
while (Timer() < WaitTime + 500)
; // Wait To Ensure Switch
View_Render();
} else if (new_pad & PAD_TRIANGLE) { // Stop SlideShow
SlideShowStop = 1;
break;
} else if (new_pad & PAD_START) { // Play/Pause SlideShow
if (PanZoom != 1.0f) {
for (i = 0; i < 35; ++i) {
if ((PanZoom -= 0.05F) <= 1.0F)
PanZoom = 1.0F;
View_Render();
} /* end for */
} /* end if */
SlideShowStart = !SlideShowStart;
WaitTime = Timer();
while (Timer() < WaitTime + 500)
; // Wait To Ensure Switch
TimeRemain = SlideShowTime;
View_Render();
} else if (new_pad & PAD_SELECT) { // Command List
Command_List();
View_Render();
WaitTime = Timer();
while (Timer() < WaitTime + 500)
; // Wait To Ensure Switch
OldTime = Timer() + 1000;
} else if ((swapKeys && new_pad & PAD_CROSS) || (!swapKeys && new_pad & PAD_CIRCLE)) { // Full Screen
if (PanZoom != 1.0f) {
for (i = 0; i < 35; ++i) {
if ((PanZoom -= 0.05F) <= 1.0F)
PanZoom = 1.0F;
View_Render();
} /* end for */
} /* end if */
FullScreen = !FullScreen;
if (FullScreen) {
loadSkin(JPG_PIC, jpgpath, 0);
} else {
loadSkin(BACKGROUND_PIC, 0, 0);
loadSkin(JPG_PIC, jpgpath, 0);
}
WaitTime = Timer();
while (Timer() < WaitTime + 500)
; // Wait To Ensure Switch
View_Render();
} /* end else */
} //ends pad response section
} //ends while
} /* end View_Input */
//--------------------------------------------------------------
static void loadPic(void)
{
int i = 0;
loadSkin(JPG_PIC, jpgpath, 0);
Brightness = 0;
PanZoom = 3.0f;
PanOffsetX = 0.0f;
PanOffsetY = 0.0f;
if (testjpg) {
switch (SlideShowTrans) {
case OFF: {
View_Render();
} break;
case ZOOM: {
Brightness = 100;
for (i = 0; i < 100; ++i) {
if ((PanZoom -= 0.02F) <= 1.0F)
PanZoom = 1.0F;
View_Render();
} /* end for */
} break;
case FADE: {
PanZoom = 1.0f;
for (i = 0; i < 100; ++i) {
++Brightness;
View_Render();
} /* end for */
} break;
case ZOOM_FADE: {
for (i = 0; i < 100; ++i) {
if ((PanZoom -= 0.02F) <= 1.0F)
PanZoom = 1.0F;
++Brightness;
View_Render();
} /* end for */
} break;
} /* end switch */
Brightness = 100;
PanZoom = 1.0f;
PanOffsetX = 0.0f;
PanOffsetY = 0.0f;
TimeRemain = SlideShowTime;
View_Render();
View_Input();
switch (SlideShowTrans) {
case OFF: {
View_Render();
} break;
case ZOOM: {
for (i = 0; i < 100; ++i) {
if ((PanZoom += 0.02F) >= 3.0F)
PanZoom = 3.0F;
View_Render();
} /* end for */
} break;
case FADE: {
for (i = 0; i < 100; ++i) {
--Brightness;
View_Render();
} /* end for */
} break;
case ZOOM_FADE: {
for (i = 0; i < 100; ++i) {
if ((PanZoom += 0.02F) >= 3.0F)
PanZoom = 3.0F;
--Brightness;
View_Render();
} /* end for */
} break;
} /* end switch */
} /* end testjpg */
} /* end loadPic */
//--------------------------------------------------------------
void JpgViewer(char *file)
{
char path[MAX_PATH],
cursorEntry[MAX_PATH], ext[8],
tmp[MAX_PATH], tmp1[MAX_PATH], *p;
u64 color;
FILEINFO files[MAX_ENTRY];
int thumb_test[MAX_ENTRY];
int jpg_browser_cd, jpg_browser_up, jpg_browser_repos, jpg_browser_pushed;
int thumb_load;
int jpg_browser_sel, jpg_browser_nfiles, old_jpg_browser_sel;
int top = 0, test_top = 0, rows = 0, rows_down = 0;
int x = 0, y = 0, y0 = 0, y1 = 0;
int thumb_num = 0, thumb_top = 0;
int jpg_browser_mode = LIST;
int print_name = 0;
int Len = 0;
int event, post_event = 0;
int i, t = 0;
int CountJpg = 0;
int StartShowSingle = FALSE;
jpg_browser_cd = TRUE;
jpg_browser_up = FALSE;
jpg_browser_repos = FALSE;
jpg_browser_pushed = TRUE;
thumb_load = TRUE;
jpg_browser_sel = 0;
jpg_browser_nfiles = 0;
old_jpg_browser_sel = 0;
SlideShowTime = setting->JpgView_Timer;
SlideShowTrans = setting->JpgView_Trans;
FullScreen = setting->JpgView_Full;
SlideShowBegin = SlideShowStart = SlideShowStop = SlideShowSkip = 0;
PicRotate = PrintLen = 0;
for (i = 0; i < MAX_ENTRY; ++i)
thumb_test[i] = NOTLOADED;
strcpy(ext, "jpg");
mountedParty[0][0] = 0;
mountedParty[1][0] = 0;
path[0] = '\0';
jpgpath[0] = '\0';
if (jpg_browser_mode == LIST) {
rows = (Menu_end_y - Menu_start_y) / FONT_HEIGHT;
} else {
if (TV_mode == TV_mode_NTSC)
rows = 4;
else if (TV_mode == TV_mode_PAL)
rows = 5;
}
loadIcon();
event = 1; //event = initial entry
if (file != NULL) {
strncpy(jpgpath, file, MAX_PATH - 1);
jpgpath[MAX_PATH - 1] = '\0';
strncpy(path, file, MAX_PATH - 1);
path[MAX_PATH - 1] = '\0';
//Separate the path and filename. path must have a trailing slash.
if ((p = strrchr(path, '/')) != NULL) {
strcpy(cursorEntry, p + 1);
*(p + 1) = '\0';
} else {
//Should not happen.
strncpy(cursorEntry, path, MAX_PATH - 1);
cursorEntry[MAX_PATH - 1] = '\0';
}
StartShowSingle = TRUE;
jpg_browser_cd = TRUE; //Initial entry into the directory.
jpg_browser_repos = TRUE; //Track the displayed file.
}
while (1) {
//Thumb init
if (thumb_load) {
jpg_browser_sel = 0;
gsGlobal->CurrentPointer = 0x288000;
for (i = 0; i < MAX_ENTRY; ++i)
thumb_test[i] = NOTLOADED;
}
//browser path adjustment section
if (jpg_browser_up) {
if ((p = strrchr(path, '/')) != NULL)
*p = 0;
if ((p = strrchr(path, '/')) != NULL) {
p++;
strcpy(cursorEntry, p);
*p = 0;
} else {
strcpy(cursorEntry, path);
path[0] = 0;
}
jpg_browser_cd = TRUE;
jpg_browser_repos = TRUE;
} //ends 'if(jpg_browser_up)'
//----- Process newly entered directory here (incl initial entry)
if (jpg_browser_cd) {
jpg_browser_nfiles = setFileList(path, ext, files, JPG_CNF);
jpg_browser_sel = 0;
top = 0;
if (jpg_browser_repos) {
jpg_browser_repos = FALSE;
for (i = 0; i < jpg_browser_nfiles; i++) {
if (!strcmp(cursorEntry, files[i].name)) {
jpg_browser_sel = i;
top = jpg_browser_sel - 3;
break;
}
}
} //ends if(jpg_browser_repos)
jpg_browser_cd = FALSE;
jpg_browser_up = FALSE;
} //ends if(jpg_browser_cd)
if (!strncmp(path, "cdfs", 4)) {
sceCdStop();
}
if (top > jpg_browser_nfiles - rows)
top = jpg_browser_nfiles - rows;
if (top < 0)
top = 0;
if (jpg_browser_sel >= jpg_browser_nfiles)
jpg_browser_sel = jpg_browser_nfiles - 1;
if (jpg_browser_sel < 0)
jpg_browser_sel = 0;
if (jpg_browser_sel >= top + rows)
top = jpg_browser_sel - rows + 1;
if (jpg_browser_sel < top)
top = jpg_browser_sel;
t++;
if (t & 0x0F)
event |= 4; //repetitive timer event
if (event || post_event) { //NB: We need to update two frame buffers per event
//Display section
clrScr(setting->color[COLOR_BACKGR]);
if (jpg_browser_mode == LIST) {
x = Menu_start_x;
y = Menu_start_y;
rows = (Menu_end_y - Menu_start_y) / FONT_HEIGHT;
if (rows_down == 1) {
jpg_browser_sel = old_jpg_browser_sel;
rows_down = 0;
old_jpg_browser_sel = 0;
} /* end if rows_down */
goto list;
} else {
x = Menu_start_x + 13;
if (TV_mode == TV_mode_NTSC) {
y = Menu_start_y + 15;
rows = 4;
} else if (TV_mode == TV_mode_PAL) {
y = Menu_start_y + 11;
rows = 5;
}
}
if (test_top != top) {
if (top > test_top) {
down:
thumb_top = thumb_num = 0;
for (i = 0; i < jpg_browser_sel; ++i) {
if (i < top && thumb_test[i] == LOADED)
++thumb_top;
if (i >= top && thumb_test[i] == LOADED)
++thumb_num;
} /* end for */
if (thumb_test[jpg_browser_sel] == NOTLOADED && !(files[jpg_browser_sel].stats.AttrFile & sceMcFileAttrSubdir)) {
sprintf(jpgpath, "%s%s", path, files[jpg_browser_sel].name);
loadSkin(THUMB_PIC, jpgpath, thumb_top + thumb_num);
thumb_test[jpg_browser_sel] = testthumb;
} /* end if notloaded */
if (rows_down == 1) {
if (++jpg_browser_sel >= old_jpg_browser_sel) {
rows_down = 0;
old_jpg_browser_sel = 0;
} else
goto down;
} /* end if rows_down */
} else {
thumb_top = 0;
for (i = 0; i < top; ++i) {
if (thumb_test[i] == LOADED)
++thumb_top;
} /* end for */
} /* end else test_top */
test_top = top;
} else {
if (rows_down == 1) {
jpg_browser_sel = old_jpg_browser_sel;
rows_down = 0;
old_jpg_browser_sel = 0;
} /* end if rows_down */
} /* end else test_top!=top */
thumb_num = 0;
list:
for (i = 0; i < rows; i++) {
int name_limit = 0; //Assume that no name length problems exist
if (top + i >= jpg_browser_nfiles)
break;
if (top + i == jpg_browser_sel)
color = setting->color[COLOR_SELECT]; //Highlight cursor line
else
color = setting->color[COLOR_TEXT];
if (!strcmp(files[top + i].name, ".."))
strcpy(tmp, "..");
else {
strcpy(tmp, files[top + i].name);
name_limit = 71 * 8;
}
if (jpg_browser_mode == LIST) { //List mode
if (name_limit) { //Do we need to check name length ?
int name_end = name_limit / 7; //Max string length for acceptable spacing
if (files[top + i].stats.AttrFile & sceMcFileAttrSubdir)
name_end -= 1; //For folders, reserve one character for final '/'
if (strlen(tmp) > name_end) { //Is name too long for clean display ?
tmp[name_end - 1] = '~'; //indicate filename abbreviation
tmp[name_end] = 0; //abbreviate name length to make room for details
}
}
if (files[top + i].stats.AttrFile & sceMcFileAttrSubdir)
strcat(tmp, "/");
printXY(tmp, x + 4, y, color, TRUE, name_limit);
y += FONT_HEIGHT;
} else { //Thumbnail mode
if (files[top + i].stats.AttrFile & sceMcFileAttrSubdir) {
strcat(tmp, "/");
gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0, 1, 0, 1, 0), 0);
gsKit_set_test(gsGlobal, GS_ATEST_OFF);
gsKit_prim_sprite_texture(gsGlobal,
&TexIcon[0], x + 20, (y + 10), 0, 0, x + 72 - 20, (y + 55 - 10), 16, 16,
0, GS_SETREG_RGBAQ(0x80, 0x80, 0x80, 0x80, 0x00));
gsKit_set_test(gsGlobal, GS_ATEST_ON);
gsKit_set_primalpha(gsGlobal, GS_BLEND_BACK2FRONT, 0);
gsGlobal->PrimAlphaEnable = GS_SETTING_OFF;
thumb_test[top + i] = BADJPG;
goto frame;
}
if (thumb_load) {
sprintf(jpgpath, "%s%s", path, files[top + i].name);
loadSkin(THUMB_PIC, jpgpath, thumb_num + thumb_top);
thumb_test[top + i] = testthumb;
}
if (thumb_test[top + i] == LOADED) {
gsKit_prim_sprite_texture(gsGlobal,
&TexThumb[thumb_num + thumb_top], x, y, 0, 0, x + 72, (y + 55), 64, 32,
0, BrightColor);
++thumb_num;
} else { // BADJPG
gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0, 1, 0, 1, 0), 0);
gsKit_set_test(gsGlobal, GS_ATEST_OFF);
gsKit_prim_sprite_texture(gsGlobal,
&TexIcon[0], x + 20, (y + 10), 0, 0, x + 72 - 20, (y + 55 - 10), 16, 16,
0, GS_SETREG_RGBAQ(0x80, 0x80, 0x80, 0x80, 0x00));
gsKit_set_test(gsGlobal, GS_ATEST_ON);
gsKit_set_primalpha(gsGlobal, GS_BLEND_BACK2FRONT, 0);
gsGlobal->PrimAlphaEnable = GS_SETTING_OFF;
}
frame:
drawFrame(x, y, x + 72, (y + 55), color);
Len = printXY(tmp, 0, 0, 0, FALSE, 0);
if (Len > 72 && top + i == jpg_browser_sel) {
if (t % 0x10 == 0) {
strcpy(tmp1, tmp + print_name);
tmp1[10] = '\0';
if (++print_name > (Len / FONT_WIDTH - 10))
print_name = 0;
}
Len = printXY(tmp1, 0, 0, 0, FALSE, 0);
printXY(tmp1, x + 72 / 2 - Len / 2, (y + 58), color, TRUE, 0);
} else if (Len > 72) {
tmp[7] = '.';
tmp[8] = '.';
tmp[9] = '.';
tmp[10] = '\0';
printXY(tmp, x - 4, (y + 58), color, TRUE, 0);
} else
printXY(tmp, x + 72 / 2 - Len / 2, (y + 58), color, TRUE, 0);
if (TV_mode == TV_mode_NTSC)
y += 71 + 15;
else if (TV_mode == TV_mode_PAL)
y += 71 + 11;
} /* end else THUMBNAIL */
} //ends for, so all browser rows were fixed above
thumb_load = FALSE;
if (jpg_browser_nfiles > rows) { //if more files than available rows, use scrollbar
drawFrame(SCREEN_WIDTH - SCREEN_MARGIN - LINE_THICKNESS * 8, Frame_start_y,
SCREEN_WIDTH - SCREEN_MARGIN, Frame_end_y, setting->color[COLOR_FRAME]);
y0 = (Menu_end_y - Menu_start_y + 8) * ((double)top / jpg_browser_nfiles);
y1 = (Menu_end_y - Menu_start_y + 8) * ((double)(top + rows) / jpg_browser_nfiles);
drawOpSprite(setting->color[COLOR_FRAME],
SCREEN_WIDTH - SCREEN_MARGIN - LINE_THICKNESS * 6, (y0 + Menu_start_y - 4),
SCREEN_WIDTH - SCREEN_MARGIN - LINE_THICKNESS * 2, (y1 + Menu_start_y - 4));
} //ends clause for scrollbar
msg0[0] = '\0';
if (jpg_browser_pushed)
sprintf(msg0, "%s %s: %s", LNG(Jpg_Viewer), LNG(Path), path);
//Tooltip section
msg1[0] = '\0';
if (swapKeys)
sprintf(msg1, "�1:%s", LNG(View));
else
sprintf(msg1, "�0:%s", LNG(View));
if (jpg_browser_mode == LIST)
sprintf(tmp, " �3:%s �2:%s", LNG(Up), LNG(Thumb));
else
sprintf(tmp, " �3:%s �2:%s", LNG(Up), LNG(List));
strcat(msg1, tmp);
sprintf(tmp, " Sel:%s Start:%s L1/R1:%dsec L2:",
LNG(Exit), LNG(SlideShow), SlideShowTime);
strcat(msg1, tmp);
if (SlideShowTrans == OFF)
strcat(msg1, LNG(Off));
else if (SlideShowTrans == ZOOM)
strcat(msg1, LNG(Zoom));
else if (SlideShowTrans == FADE)
strcat(msg1, LNG(Fade));
else if (SlideShowTrans == ZOOM_FADE)
strcat(msg1, LNG(ZoomFade));
sprintf(tmp, " R2:%s", LNG(PathPad));
strcat(msg1, tmp);
setScrTmp(msg0, msg1);
} //ends if(event||post_event)
if (StartShowSingle) {
StartShowSingle = FALSE;
goto single;
}
//Pad response section
waitPadReady(0, 0);
if (readpad()) {
if (new_pad) {
jpg_browser_pushed = TRUE;
print_name = 0;
event |= 2; //event |= pad command
tmp[0] = 0;
tmp1[0] = 0;
t = 0;
}
if (new_pad & PAD_UP)
jpg_browser_sel--;
else if (new_pad & PAD_DOWN)
jpg_browser_sel++;
else if (new_pad & PAD_LEFT)
jpg_browser_sel -= rows - 1;
else if (new_pad & PAD_RIGHT) {
rows_down = 1;
old_jpg_browser_sel = jpg_browser_sel + rows - 1;
jpg_browser_sel++;
} else if (new_pad & PAD_TRIANGLE) {
jpg_browser_up = TRUE;
thumb_load = TRUE;
} else if (new_pad & PAD_SQUARE) {
if (jpg_browser_mode == LIST) {
jpg_browser_mode = THUMBNAIL;
jpg_browser_sel = 0;
thumb_load = TRUE;
} else
jpg_browser_mode = LIST;
} else if (new_pad & PAD_R1) {
if (++SlideShowTime >= 300)
SlideShowTime = 300;
} else if (new_pad & PAD_L1) {
if (--SlideShowTime <= 1)
SlideShowTime = 1;
} else if (new_pad & PAD_R2) {
char *temp = PathPad_menu(path);
if (temp != NULL) {
strcpy(path, temp);
jpg_browser_cd = TRUE;
thumb_load = TRUE;
}
} else if (new_pad & PAD_L2) {
if (--SlideShowTrans < 1)
SlideShowTrans = 4;
} else if ((swapKeys && new_pad & PAD_CROSS) || (!swapKeys && new_pad & PAD_CIRCLE)) { //Pushed OK
if (files[jpg_browser_sel].stats.AttrFile & sceMcFileAttrSubdir) {
//pushed OK for a folder
thumb_load = TRUE;
if (!strcmp(files[jpg_browser_sel].name, "..")) {
jpg_browser_up = TRUE;
} else {
strcat(path, files[jpg_browser_sel].name);
strcat(path, "/");
jpg_browser_cd = TRUE;
}
} else {
//pushed OK for a file
restart:
sprintf(jpgpath, "%s%s", path, files[jpg_browser_sel].name);
SlideShowBegin = 1;
if (!SlideShowStart)
goto single;
repeat:
for (i = 0; i < jpg_browser_nfiles; ++i) {
if (SlideShowBegin) {
i = jpg_browser_sel + 1;
SlideShowBegin = 0;
}
sprintf(jpgpath, "%s%s", path, files[i].name);
loadPic();
PicRotate = 0;
if (testjpg)
++CountJpg;
if (SlideShowSkip == 1)
SlideShowSkip = 0;
else if (SlideShowSkip == -1) {
i -= 2; //Loop index back to JPG before previous
if (i <= 0)
i += jpg_browser_nfiles - 1; //Loop index back to JPG before final
SlideShowSkip = 0;
}
if (SlideShowStop)
goto end;
} /* end for */
goto end;
single:
loadPic();
PicRotate = 0;
if (testjpg)
++CountJpg;
if (SlideShowSkip == 1 || !testjpg) {
if (++jpg_browser_sel > jpg_browser_nfiles)
jpg_browser_sel = 0;
SlideShowSkip = 0;
goto restart;
} else if (SlideShowSkip == -1) {
jpg_browser_sel -= 1;
if (jpg_browser_sel <= 0)
jpg_browser_sel += jpg_browser_nfiles - 1; //Go back to final JPG
SlideShowSkip = 0;
goto restart;
}
end:
if (SlideShowStart && !SlideShowStop && CountJpg > 0)
goto repeat;
if (FullScreen) {
loadSkin(BACKGROUND_PIC, 0, 0);
loadIcon();
}
SlideShowStart = SlideShowStop = CountJpg = PicRotate = 0;
thumb_load = TRUE;
} /* end else file */
} else if (new_pad & PAD_SELECT) {
if (mountedParty[0][0] != 0) {
fileXioUmount("pfs0:");
mountedParty[0][0] = 0;
}
if (mountedParty[1][0] != 0) {
fileXioUmount("pfs1:");
mountedParty[1][0] = 0;
}
setting->JpgView_Timer = SlideShowTime;
setting->JpgView_Trans = SlideShowTrans;
setting->JpgView_Full = FullScreen;
return;
} else if (new_pad & PAD_START) {
if (path[0] != 0) {
SlideShowStart = 1;
SlideShowBegin = 0;
goto repeat;
}
}
} //ends pad response section
drawScr();
post_event = event;
event = 0;
} //ends while
} /* end JpgViewer */
//--------------------------------------------------------------
//End of file: jpgviewer.c
//--------------------------------------------------------------