source: ps2launchargs/source/uLaunchELF/jpgviewer.c@ 1102

Last change on this file since 1102 was 1101, checked in by iritscen, 7 years ago

Added following to ps2launchargs:\n-Source code.\n-DLL needed to run ps2client.\n-Instructions for building uLaunchELF.

  • Property svn:executable set to *
File size: 27.4 KB
Line 
1//--------------------------------------------------------------
2//File name: jpgviewer.c
3//--------------------------------------------------------------
4#include "launchelf.h"
5
6static char msg0[MAX_PATH], msg1[MAX_PATH], jpgpath[MAX_PATH];
7static int SlideShowTime=5, SlideShowTrans=2, SlideShowBegin, SlideShowStart, SlideShowStop, SlideShowSkip;
8static int Brightness, TimeRemain, PrintLen;
9static float PanPosX, PanPosY, PanPosX1, PanPosY1;
10static float PanZoom, PanOffsetX, PanOffsetY;
11float PicW, PicH, PicCoeff;
12float PicWidth, PicHeight;
13int PicRotate, FullScreen;
14
15#define OFF 1
16#define ZOOM 2
17#define FADE 3
18#define ZOOM_FADE 4
19
20#define LIST 1
21#define THUMBNAIL 2
22
23#define NOTLOADED -1
24#define BADJPG 0
25#define LOADED 1
26
27//--------------------------------------------------------------
28static void Command_List( void )
29{
30 int x, y;
31 int event, post_event=0;
32
33 int command_len=strlen(LNG(Start_StartStop_Slideshow))>strlen(LNG(Start_StartStop_Slideshow))?
34 strlen(LNG(Start_StartStop_Slideshow)):strlen(LNG(Start_StartStop_Slideshow));
35 command_len=strlen(LNG(L1R1_Slideshow_Timer))>command_len?
36 strlen(LNG(L1R1_Slideshow_Timer)):command_len;
37 command_len=strlen(LNG(L2R2_Slideshow_Transition))>command_len?
38 strlen(LNG(L2R2_Slideshow_Transition)):command_len;
39 command_len=strlen(LNG(LeftRight_Pad_PrevNext_Picture))>command_len?
40 strlen(LNG(LeftRight_Pad_PrevNext_Picture)):command_len;
41 command_len=strlen(LNG(UpDown_Pad_Rotate_Picture))>command_len?
42 strlen(LNG(UpDown_Pad_Rotate_Picture)):command_len;
43 command_len=strlen(LNG(Left_Joystick_Panorama))>command_len?
44 strlen(LNG(Left_Joystick_Panorama)):command_len;
45 command_len=strlen(LNG(Right_Joystick_Vertical_Zoom))>command_len?
46 strlen(LNG(Right_Joystick_Vertical_Zoom)):command_len;
47 command_len=strlen(LNG(FullScreen_Mode))+3>command_len?
48 strlen(LNG(FullScreen_Mode))+3:command_len;
49 command_len=strlen(LNG(Exit_To_Jpg_Browser))+3>command_len?
50 strlen(LNG(Exit_To_Jpg_Browser))+3:command_len;
51
52 int Command_ch_w = command_len+1; //Total characters in longest Command Name.
53 int Command_ch_h = 9; //Total Command lines number.
54 int cSprite_Y1 = SCREEN_HEIGHT/2-((Command_ch_h+1)*FONT_HEIGHT)/2; //Top edge
55 int cSprite_X2 = SCREEN_WIDTH/2+((Command_ch_w+3)*FONT_WIDTH)/2; //Right edge
56 int cSprite_X1 = cSprite_X2-(Command_ch_w+3)*FONT_WIDTH-4; //Left edge
57 int cSprite_Y2 = cSprite_Y1+(Command_ch_h+1)*FONT_HEIGHT; //Bottom edge
58
59 char tmp[MAX_PATH];
60
61 event = 1; //event = initial entry.
62 while(1){
63 //Pad response section.
64 waitPadReady(0, 0);
65 if(readpad()){
66 if(new_pad){
67 event |= 2; //event |= valid pad command.
68 break;
69 }
70 }
71
72 if(event||post_event){ //NB: We need to update two frame buffers per event.
73
74 //Display section.
75 drawOpSprite(setting->color[0], cSprite_X1, cSprite_Y1, cSprite_X2, cSprite_Y2);
76 drawFrame(cSprite_X1, cSprite_Y1, cSprite_X2, cSprite_Y2, setting->color[1]);
77
78 y=cSprite_Y1+FONT_HEIGHT/2;
79 x=cSprite_X1+2*FONT_WIDTH;
80
81 printXY(LNG(Start_StartStop_Slideshow), x, y, setting->color[3], TRUE, 0);
82 y+=FONT_HEIGHT;
83 printXY(LNG(L1R1_Slideshow_Timer), x, y, setting->color[3], TRUE, 0);
84 y+=FONT_HEIGHT;
85 printXY(LNG(L2R2_Slideshow_Transition), x, y, setting->color[3], TRUE, 0);
86 y+=FONT_HEIGHT;
87 printXY(LNG(LeftRight_Pad_PrevNext_Picture), x, y, setting->color[3], TRUE, 0);
88 y+=FONT_HEIGHT;
89 printXY(LNG(UpDown_Pad_Rotate_Picture), x, y, setting->color[3], TRUE, 0);
90 y+=FONT_HEIGHT;
91 printXY(LNG(Left_Joystick_Panorama), x, y, setting->color[3], TRUE, 0);
92 y+=FONT_HEIGHT;
93 printXY(LNG(Right_Joystick_Vertical_Zoom), x, y, setting->color[3], TRUE, 0);
94 y+=FONT_HEIGHT;
95 if (swapKeys)
96 sprintf(tmp, "ÿ1: %s", LNG(FullScreen_Mode));
97 else
98 sprintf(tmp, "ÿ0: %s", LNG(FullScreen_Mode));
99 printXY(tmp, x, y, setting->color[3], TRUE, 0);
100 y+=FONT_HEIGHT;
101 sprintf(tmp, "ÿ3: %s", LNG(Exit_To_Jpg_Browser));
102 printXY(tmp, x, y, setting->color[3], TRUE, 0);
103 y+=FONT_HEIGHT;
104
105 }//ends if(event||post_event).
106 drawScr();
107 post_event = event;
108 event = 0;
109 }//ends while.
110}//ends Command_List.
111//--------------------------------------------------------------
112static void View_Render( void ) {
113
114 char *name, tmp[MAX_PATH];
115
116 float ScreenPosX, ScreenPosX1, ScreenPosY, ScreenPosY1;
117 float ScreenOffsetX, ScreenOffsetY;
118 float TmpPosX, TmpPosY;
119
120 // Init picture position on screen
121 if(FullScreen){
122 ScreenPosX =0.0f;
123 ScreenPosX1=SCREEN_WIDTH;
124 ScreenPosY =0.0f;
125 ScreenPosY1=SCREEN_HEIGHT;
126 }else{
127 ScreenPosX =SCREEN_MARGIN;
128 ScreenPosX1=SCREEN_WIDTH-SCREEN_MARGIN;
129 ScreenPosY =Frame_start_y;
130 ScreenPosY1=Frame_end_y;
131 }
132
133 // Init black bars
134 if((ScreenOffsetX=((ScreenPosX1-ScreenPosX)-((ScreenPosY1-ScreenPosY)*PicCoeff))/2)<=0.0f)
135 ScreenOffsetX=0.0f;
136 if((ScreenOffsetY=((ScreenPosY1-ScreenPosY)-((ScreenPosX1-ScreenPosX)/PicCoeff))/2)<=0.0f)
137 ScreenOffsetY=0.0f;
138
139 // Init panorama
140 PanPosX=0.0f;
141 PanPosY=0.0f;
142 PanPosX1=PicWidth;
143 PanPosY1=PicHeight;
144 if(PanZoom==1.0f){
145 PanOffsetX=0.0f;
146 PanOffsetY=0.0f;
147 }else{
148 PanPosX=TmpPosX=((PicWidth/8)-((1.5f-PanZoom)*(PicWidth/4)));
149 if((PanPosX+=PanOffsetX*TmpPosX)<=0.0f)
150 PanPosX=0.0f;
151 if((PanPosX1=PicWidth-(TmpPosX*2-PanPosX))>=PicWidth)
152 PanPosX1=PicWidth;
153 PanPosY=TmpPosY=((PicHeight/8)-((1.5f-PanZoom)*(PicHeight/4)));
154 if((PanPosY+=PanOffsetY*TmpPosY)<=0.0f)
155 PanPosY=0.0f;
156 if((PanPosY1=PicHeight-(TmpPosY*2-PanPosY))>=PicHeight)
157 PanPosY1=PicHeight;
158 }
159
160 // Clear screen
161 clrScr(setting->color[0]);
162
163 // Draw color8 graph4
164 gsKit_prim_sprite(gsGlobal, ScreenPosX, ScreenPosY, ScreenPosX1, ScreenPosY1, 0, setting->color[7]);
165 // Draw picture
166 if(PicRotate==0 || PicRotate==1 ||PicRotate==3){ // No rotation, rotate +90°, -90°
167 gsKit_prim_sprite_texture(gsGlobal,
168 &TexPicture,
169 ScreenPosX+ScreenOffsetX, ScreenPosY+ScreenOffsetY, PanPosX, PanPosY,
170 ScreenPosX1-ScreenOffsetX, ScreenPosY1-ScreenOffsetY, PanPosX1, PanPosY1,
171 0, GS_SETREG_RGBAQ(Brightness*1.28f, Brightness*1.28f, Brightness*1.28f, 0x80, 0x00));
172 }else if(PicRotate==2){ // Rotate 180°
173 gsKit_prim_sprite_texture(gsGlobal,
174 &TexPicture,
175 ScreenPosX+ScreenOffsetX, ScreenPosY+ScreenOffsetY, PanPosX1, PanPosY1,
176 ScreenPosX1-ScreenOffsetX, ScreenPosY1-ScreenOffsetY, PanPosX, PanPosY,
177 0, GS_SETREG_RGBAQ(Brightness*1.28f, Brightness*1.28f, Brightness*1.28f, 0x80, 0x00));
178 }
179 setBrightness(50);
180
181 if(!FullScreen){
182 //Tooltip section
183 strcpy(tmp, jpgpath);
184 name=strrchr(tmp, '/');
185 strcpy(name, name+1);
186 msg0[0]='\0';
187 sprintf(msg0, "%s %s: %s %s: %d*%d ",
188 LNG(Jpg_Viewer), LNG(Picture), name, LNG(Size), (int)PicW, (int)PicH);
189 msg1[0]='\0';
190 sprintf(msg1, "Select: %s ", LNG(Command_List));
191 tmp[0]='\0';
192 if(TimeRemain<60)
193 sprintf(tmp, "%s: %d sec %s: ", LNG(Timer), TimeRemain, LNG(Transition));
194 else
195 sprintf(tmp, "%s: %d m %d sec %s: ", LNG(Timer), TimeRemain/60, TimeRemain%60, LNG(Transition));
196 strcat(msg1, tmp);
197 if(SlideShowTrans==OFF)
198 strcat(msg1, LNG(Off));
199 else if(SlideShowTrans==ZOOM)
200 strcat(msg1, LNG(Zoom));
201 else if(SlideShowTrans==FADE)
202 strcat(msg1, LNG(Fade));
203 else if(SlideShowTrans==ZOOM_FADE)
204 strcat(msg1, LNG(ZoomFade));
205 setScrTmp(msg0, msg1);
206 } /* end FullScreen */
207 drawScr();
208} /* end View_Render */
209
210//--------------------------------------------------------------
211static void View_Input( void ) {
212
213 int i=0;
214 u64 OldTime=Timer()+1000;
215
216 while(1){
217
218 if(SlideShowStart){
219 if(Timer()>=OldTime){
220 OldTime=Timer()+1000;
221 if(--TimeRemain<=0)
222 break;
223 View_Render();
224 }
225 }else{
226 if(Timer()>=OldTime){
227 OldTime=Timer()+1000;
228 TimeRemain=SlideShowTime;
229 View_Render();
230 }
231 }
232
233 //Pad response section
234 waitPadReady(0, 0);
235 if(readpad()){
236 if(new_pad & PAD_R3_V0){ // PanZoom In
237 if( PanZoom < 2.75f ) {
238 PanZoom += 0.01f*joy_value/32;
239 SlideShowStart=0;
240 View_Render();
241 } /* end if */
242 }else if(new_pad & PAD_R3_V1){ // PanZoom Out
243 if( PanZoom > 1.0f ) {
244 PanZoom -= 0.01f*joy_value/32;
245 SlideShowStart=0;
246 View_Render();
247 } /* end if */
248 }else if(new_pad & PAD_L3_H1){ // Move Right
249 if ( PanOffsetX < 0.95f ) {
250 PanOffsetX += 0.05f/PanZoom*joy_value/32;
251 SlideShowStart=0;
252 View_Render();
253 } /* end if */
254 }else if(new_pad & PAD_L3_H0){ // Move Left
255 if ( PanOffsetX > -0.95f ) {
256 PanOffsetX -= 0.05f/PanZoom*joy_value/32;
257 SlideShowStart=0;
258 View_Render();
259 } /* end if */
260 }else if(new_pad & PAD_L3_V1){ // Move Down
261 if ( PanOffsetY < 0.95f ) {
262 PanOffsetY += 0.05f/PanZoom*joy_value/32;
263 SlideShowStart=0;
264 View_Render();
265 } /* end if */
266 }else if(new_pad & PAD_L3_V0){ // Move Up
267 if ( PanOffsetY > -0.95f ) {
268 PanOffsetY -= 0.05f/PanZoom*joy_value/32;
269 SlideShowStart=0;
270 View_Render();
271 } /* end if */
272 }else if(new_pad & PAD_RIGHT){ // Next Pic
273 SlideShowSkip=1;
274 break;
275 }else if(new_pad & PAD_LEFT){ // Prev Pic
276 SlideShowSkip=-1;
277 break;
278 }else if(new_pad & PAD_UP){ // Rotate Pic +
279 if(PanZoom!=1.0f){
280 for ( i = 0; i < 35; ++i ) {
281 if ( ( PanZoom -= 0.05F ) <= 1.0F ) PanZoom = 1.0F;
282 View_Render();
283 } /* end for */
284 } /* end if */
285 if(++PicRotate>=4) PicRotate=0;
286 loadSkin( JPG_PIC, jpgpath, 0 );
287 WaitTime=Timer();
288 while(Timer()<WaitTime+500); // Wait To Ensure Switch
289 View_Render();
290 TimeRemain=SlideShowTime;
291 }else if(new_pad & PAD_DOWN){ // Rotate Pic -
292 if(PanZoom!=1.0f){
293 for ( i = 0; i < 35; ++i ) {
294 if ( ( PanZoom -= 0.05F ) <= 1.0F ) PanZoom = 1.0F;
295 View_Render();
296 } /* end for */
297 } /* end if */
298 if(--PicRotate<=-1) PicRotate=3;
299 loadSkin( JPG_PIC, jpgpath, 0 );
300 WaitTime=Timer();
301 while(Timer()<WaitTime+500); // Wait To Ensure Switch
302 View_Render();
303 TimeRemain=SlideShowTime;
304 }else if(new_pad & PAD_R1){
305 if(++SlideShowTime>=3600) SlideShowTime=3600;
306 WaitTime=Timer();
307 while(Timer()<WaitTime+100); // Wait To Ensure Switch
308 if(++TimeRemain>=3600) TimeRemain=3600;
309 View_Render();
310 }else if(new_pad & PAD_L1){
311 if(--SlideShowTime<=1) SlideShowTime=1;
312 WaitTime=Timer();
313 while(Timer()<WaitTime+100); // Wait To Ensure Switch
314 if(--TimeRemain<=1) TimeRemain=1;
315 View_Render();
316 }else if(new_pad & PAD_R2){
317 if(++SlideShowTrans>4) SlideShowTrans=1;
318 WaitTime=Timer();
319 while(Timer()<WaitTime+500); // Wait To Ensure Switch
320 View_Render();
321 }else if(new_pad & PAD_L2){
322 if(--SlideShowTrans<1) SlideShowTrans=4;
323 WaitTime=Timer();
324 while(Timer()<WaitTime+500); // Wait To Ensure Switch
325 View_Render();
326 }else if(new_pad & PAD_TRIANGLE){ // Stop SlideShow
327 SlideShowStop=1;
328 break;
329 }else if(new_pad & PAD_START){ // Play/Pause SlideShow
330 if(PanZoom!=1.0f){
331 for ( i = 0; i < 35; ++i ) {
332 if ( ( PanZoom -= 0.05F ) <= 1.0F ) PanZoom = 1.0F;
333 View_Render();
334 } /* end for */
335 } /* end if */
336 SlideShowStart=!SlideShowStart;
337 WaitTime=Timer();
338 while(Timer()<WaitTime+500); // Wait To Ensure Switch
339 TimeRemain=SlideShowTime;
340 View_Render();
341 }else if(new_pad & PAD_SELECT){ // Command List
342 Command_List();
343 View_Render();
344 WaitTime=Timer();
345 while(Timer()<WaitTime+500); // Wait To Ensure Switch
346 OldTime=Timer()+1000;
347 }else if((swapKeys && new_pad & PAD_CROSS)
348 || (!swapKeys && new_pad & PAD_CIRCLE) ){ // Full Screen
349 if(PanZoom!=1.0f){
350 for ( i = 0; i < 35; ++i ) {
351 if ( ( PanZoom -= 0.05F ) <= 1.0F ) PanZoom = 1.0F;
352 View_Render();
353 } /* end for */
354 } /* end if */
355 FullScreen=!FullScreen;
356 if(FullScreen){
357 loadSkin( JPG_PIC, jpgpath, 0 );
358 }else{
359 loadSkin(BACKGROUND_PIC, 0, 0);
360 loadSkin( JPG_PIC, jpgpath, 0 );
361 }
362 WaitTime=Timer();
363 while(Timer()<WaitTime+500); // Wait To Ensure Switch
364 View_Render();
365 } /* end else */
366 }//ends pad response section
367 }//ends while
368} /* end View_Input */
369
370//--------------------------------------------------------------
371static void loadPic(void)
372{
373 int i=0;
374
375 loadSkin( JPG_PIC, jpgpath, 0 );
376
377 Brightness = 0;
378 PanZoom = 3.0f;
379 PanOffsetX = 0.0f;
380 PanOffsetY = 0.0f;
381
382 if(testjpg){
383 switch ( SlideShowTrans ) {
384 case OFF : {
385 View_Render();
386 } break;
387 case ZOOM : {
388 Brightness = 100;
389 for ( i = 0; i < 100; ++i ) {
390 if ( ( PanZoom -= 0.02F ) <= 1.0F ) PanZoom = 1.0F;
391 View_Render();
392 } /* end for */
393 } break;
394 case FADE : {
395 PanZoom = 1.0f;
396 for ( i = 0; i < 100; ++i ) {
397 ++Brightness;
398 View_Render();
399 } /* end for */
400 } break;
401 case ZOOM_FADE : {
402 for ( i = 0; i < 100; ++i ) {
403 if ( ( PanZoom -= 0.02F ) <= 1.0F ) PanZoom = 1.0F;
404 ++Brightness;
405 View_Render();
406 } /* end for */
407 } break;
408 } /* end switch */
409
410 Brightness = 100;
411 PanZoom = 1.0f;
412 PanOffsetX = 0.0f;
413 PanOffsetY = 0.0f;
414 TimeRemain = SlideShowTime;
415
416 View_Render();
417 View_Input();
418
419 switch ( SlideShowTrans ) {
420 case OFF : {
421 View_Render();
422 } break;
423 case ZOOM : {
424 for ( i = 0; i < 100; ++i ) {
425 if ( ( PanZoom += 0.02F ) >= 3.0F ) PanZoom = 3.0F;
426 View_Render();
427 } /* end for */
428 } break;
429 case FADE : {
430 for ( i = 0; i < 100; ++i ) {
431 --Brightness;
432 View_Render();
433 } /* end for */
434 } break;
435 case ZOOM_FADE : {
436 for ( i = 0; i < 100; ++i ) {
437 if ( ( PanZoom += 0.02F ) >= 3.0F ) PanZoom = 3.0F;
438 --Brightness;
439 View_Render();
440 } /* end for */
441 } break;
442 } /* end switch */
443 } /* end testjpg */
444} /* end loadPic */
445
446//--------------------------------------------------------------
447void JpgViewer( void )
448{
449 char path[MAX_PATH],
450 cursorEntry[MAX_PATH], ext[8],
451 tmp[MAX_PATH], tmp1[MAX_PATH], *p;
452 u64 color;
453 FILEINFO files[MAX_ENTRY];
454 int thumb_test[MAX_ENTRY];
455 int jpg_browser_cd, jpg_browser_up, jpg_browser_repos, jpg_browser_pushed;
456 int thumb_load;
457 int jpg_browser_sel, jpg_browser_nfiles, old_jpg_browser_sel;
458 int top=0, test_top=0, rows=0, rows_down=0;
459 int x=0, y=0, y0=0, y1=0;
460 int thumb_num=0, thumb_top=0;
461 int jpg_browser_mode=LIST;
462 int print_name=0;
463 int Len=0;
464 int event, post_event=0;
465 int i, t=0;
466 int CountJpg=0;
467
468 jpg_browser_cd=TRUE;
469 jpg_browser_up=FALSE;
470 jpg_browser_repos=FALSE;
471 jpg_browser_pushed=TRUE;
472 thumb_load=TRUE;
473 jpg_browser_sel=0;
474 jpg_browser_nfiles=0;
475 old_jpg_browser_sel=0;
476
477 SlideShowTime = setting->JpgView_Timer;
478 SlideShowTrans = setting->JpgView_Trans;
479 FullScreen = setting->JpgView_Full;
480 SlideShowBegin=SlideShowStart=SlideShowStop=SlideShowSkip=0;
481 PicRotate=PrintLen=0;
482
483 for(i=0;i<MAX_ENTRY;++i)
484 thumb_test[i]=NOTLOADED;
485
486 strcpy(ext, "jpg");
487
488 mountedParty[0][0]=0;
489 mountedParty[1][0]=0;
490
491 path[0]='\0';
492 jpgpath[0]='\0';
493
494 if(jpg_browser_mode==LIST){
495 rows = (Menu_end_y-Menu_start_y)/FONT_HEIGHT;
496 }else{
497 if(TV_mode == TV_mode_NTSC)
498 rows=4;
499 else if(TV_mode == TV_mode_PAL)
500 rows=5;
501 }
502
503 loadIcon();
504
505 event = 1; //event = initial entry
506 while(1){
507
508 //Pad response section
509 waitPadReady(0, 0);
510 if(readpad()){
511 if(new_pad){
512 jpg_browser_pushed=TRUE;
513 print_name=0;
514 event |= 2; //event |= pad command
515 tmp[0]=0;
516 tmp1[0]=0;
517 t=0;
518 }
519 if(new_pad & PAD_UP)
520 jpg_browser_sel--;
521 else if(new_pad & PAD_DOWN)
522 jpg_browser_sel++;
523 else if(new_pad & PAD_LEFT)
524 jpg_browser_sel-=rows-1;
525 else if(new_pad & PAD_RIGHT){
526 rows_down=1;
527 old_jpg_browser_sel=jpg_browser_sel+rows-1;
528 jpg_browser_sel++;
529 }else if(new_pad & PAD_TRIANGLE){
530 jpg_browser_up=TRUE;
531 thumb_load=TRUE;
532 }else if(new_pad & PAD_SQUARE){
533 if(jpg_browser_mode==LIST){
534 jpg_browser_mode=THUMBNAIL;
535 jpg_browser_sel=0;
536 thumb_load=TRUE;
537 }else
538 jpg_browser_mode=LIST;
539 }else if(new_pad & PAD_R1){
540 if(++SlideShowTime>=300) SlideShowTime=300;
541 }else if(new_pad & PAD_L1){
542 if(--SlideShowTime<=1) SlideShowTime=1;
543 }else if(new_pad & PAD_R2){
544 char *temp = PathPad_menu(path);
545
546 if(temp != NULL){
547 strcpy(path, temp);
548 jpg_browser_cd=TRUE;
549 thumb_load=TRUE;
550 }
551 }else if(new_pad & PAD_L2){
552 if(--SlideShowTrans<1) SlideShowTrans=4;
553 }else if((swapKeys && new_pad & PAD_CROSS)
554 || (!swapKeys && new_pad & PAD_CIRCLE) ){ //Pushed OK
555 if(files[jpg_browser_sel].stats.attrFile & MC_ATTR_SUBDIR){
556 //pushed OK for a folder
557 thumb_load=TRUE;
558 if(!strcmp(files[jpg_browser_sel].name,"..")){
559 jpg_browser_up=TRUE;
560 }else {
561 strcat(path, files[jpg_browser_sel].name);
562 strcat(path, "/");
563 jpg_browser_cd=TRUE;
564 }
565 }else{
566 //pushed OK for a file
567restart:
568 sprintf(jpgpath, "%s%s", path, files[jpg_browser_sel].name);
569
570 SlideShowBegin=1;
571
572 if(!SlideShowStart)
573 goto single;
574repeat:
575 for(i=0;i<jpg_browser_nfiles;++i){
576 if(SlideShowBegin){
577 i=jpg_browser_sel+1;
578 SlideShowBegin=0;
579 }
580 sprintf(jpgpath, "%s%s", path, files[i].name);
581 loadPic();
582 PicRotate=0;
583 if(testjpg) ++CountJpg;
584 if(SlideShowSkip==1)
585 SlideShowSkip=0;
586 else if(SlideShowSkip==-1){
587 i-=2; //Loop index back to JPG before previous
588 if(i<=0)
589 i += jpg_browser_nfiles-1; //Loop index back to JPG before final
590 SlideShowSkip=0;
591 }
592 if(SlideShowStop)
593 goto end;
594 } /* end for */
595 goto end;
596single:
597 loadPic();
598 PicRotate=0;
599 if(testjpg) ++CountJpg;
600 if(SlideShowSkip==1 || !testjpg){
601 if(++jpg_browser_sel>jpg_browser_nfiles) jpg_browser_sel=0;
602 SlideShowSkip=0;
603 goto restart;
604 }else if(SlideShowSkip==-1){
605 jpg_browser_sel-=1;
606 if(jpg_browser_sel<=0)
607 jpg_browser_sel += jpg_browser_nfiles-1; //Go back to final JPG
608 SlideShowSkip=0;
609 goto restart;
610 }
611end:
612 if(SlideShowStart && !SlideShowStop && CountJpg>0)
613 goto repeat;
614 if(FullScreen){
615 loadSkin(BACKGROUND_PIC, 0, 0);
616 loadIcon();
617 }
618 SlideShowStart=SlideShowStop=CountJpg=PicRotate=0;
619 thumb_load=TRUE;
620 } /* end else file */
621 } else if(new_pad & PAD_SELECT){
622 if(mountedParty[0][0]!=0){
623 fileXioUmount("pfs0:");
624 mountedParty[0][0]=0;
625 }
626 if(mountedParty[1][0]!=0){
627 fileXioUmount("pfs1:");
628 mountedParty[1][0]=0;
629 }
630 setting->JpgView_Timer = SlideShowTime;
631 setting->JpgView_Trans = SlideShowTrans;
632 setting->JpgView_Full = FullScreen;
633 return;
634 } else if(new_pad & PAD_START){
635 if(path[0]!=0){
636 SlideShowStart=1;
637 SlideShowBegin=0;
638 goto repeat;
639 }
640 }
641 }//ends pad response section
642
643 //Thumb init
644 if(thumb_load){
645 jpg_browser_sel=0;
646 gsGlobal->CurrentPointer=0x288000;
647 for(i=0;i<MAX_ENTRY;++i)
648 thumb_test[i]=NOTLOADED;
649 }
650
651 //browser path adjustment section
652 if(jpg_browser_up){
653 if((p=strrchr(path, '/'))!=NULL)
654 *p = 0;
655 if((p=strrchr(path, '/'))!=NULL){
656 p++;
657 strcpy(cursorEntry, p);
658 *p = 0;
659 }else{
660 strcpy(cursorEntry, path);
661 path[0] = 0;
662 }
663 jpg_browser_cd=TRUE;
664 jpg_browser_repos=TRUE;
665 }//ends 'if(jpg_browser_up)'
666 //----- Process newly entered directory here (incl initial entry)
667 if(jpg_browser_cd){
668 jpg_browser_nfiles = setFileList(path, ext, files, JPG_CNF);
669 jpg_browser_sel=0;
670 top=0;
671 if(jpg_browser_repos){
672 jpg_browser_repos = FALSE;
673 for(i=0; i<jpg_browser_nfiles; i++) {
674 if(!strcmp(cursorEntry, files[i].name)) {
675 jpg_browser_sel=i;
676 top=jpg_browser_sel-3;
677 break;
678 }
679 }
680 } //ends if(jpg_browser_repos)
681 jpg_browser_cd=FALSE;
682 jpg_browser_up=FALSE;
683 } //ends if(jpg_browser_cd)
684 if(setting->discControl && !strncmp(path,"cdfs",4))
685 CDVD_Stop();
686 if(top > jpg_browser_nfiles-rows) top=jpg_browser_nfiles-rows;
687 if(top < 0) top=0;
688 if(jpg_browser_sel >= jpg_browser_nfiles) jpg_browser_sel=jpg_browser_nfiles-1;
689 if(jpg_browser_sel < 0) jpg_browser_sel=0;
690 if(jpg_browser_sel >= top+rows) top=jpg_browser_sel-rows+1;
691 if(jpg_browser_sel < top) top=jpg_browser_sel;
692
693 t++;
694
695 if(t & 0x0F) event |= 4; //repetitive timer event
696
697 if(event||post_event){ //NB: We need to update two frame buffers per event
698
699 //Display section
700 clrScr(setting->color[0]);
701
702 if(jpg_browser_mode==LIST){
703 x = Menu_start_x;
704 y = Menu_start_y;
705 rows = (Menu_end_y-Menu_start_y)/FONT_HEIGHT;
706 if(rows_down==1){
707 jpg_browser_sel=old_jpg_browser_sel;
708 rows_down=0;
709 old_jpg_browser_sel=0;
710 } /* end if rows_down */
711 goto list;
712 }else{
713 x = Menu_start_x+13;
714 if(TV_mode == TV_mode_NTSC){
715 y = Menu_start_y+15;
716 rows=4;
717 }else if(TV_mode == TV_mode_PAL){
718 y = Menu_start_y+11;
719 rows=5;
720 }
721 }
722
723 if(test_top!=top){
724 if(top>test_top){
725down:
726 thumb_top=thumb_num=0;
727 for(i=0;i<jpg_browser_sel;++i){
728 if(i<top && thumb_test[i]==LOADED)
729 ++thumb_top;
730 if(i>=top && thumb_test[i]==LOADED)
731 ++thumb_num;
732 } /* end for */
733 if(thumb_test[jpg_browser_sel]==NOTLOADED && !(files[jpg_browser_sel].stats.attrFile & MC_ATTR_SUBDIR)){
734 sprintf(jpgpath, "%s%s", path, files[jpg_browser_sel].name);
735 loadSkin( THUMB_PIC, jpgpath, thumb_top+thumb_num);
736 thumb_test[jpg_browser_sel]=testthumb;
737 } /* end if notloaded */
738 if(rows_down==1){
739 if(++jpg_browser_sel>=old_jpg_browser_sel){
740 rows_down=0;
741 old_jpg_browser_sel=0;
742 }else
743 goto down;
744 } /* end if rows_down */
745 }else{
746 thumb_top=0;
747 for(i=0;i<top;++i){
748 if(thumb_test[i]==LOADED)
749 ++thumb_top;
750 } /* end for */
751 } /* end else test_top */
752 test_top=top;
753 }else{
754 if(rows_down==1){
755 jpg_browser_sel=old_jpg_browser_sel;
756 rows_down=0;
757 old_jpg_browser_sel=0;
758 } /* end if rows_down */
759 }/* end else test_top!=top */
760
761 thumb_num=0;
762
763list:
764 for(i=0; i<rows; i++)
765 {
766 int name_limit = 0; //Assume that no name length problems exist
767
768 if(top+i >= jpg_browser_nfiles) break;
769 if(top+i == jpg_browser_sel) color = setting->color[2]; //Highlight cursor line
770 else color = setting->color[3];
771
772 if(!strcmp(files[top+i].name,".."))
773 strcpy(tmp,"..");
774 else {
775 strcpy(tmp,files[top+i].name);
776 name_limit = 71*8;
777 }
778
779 if(jpg_browser_mode==LIST){ //List mode
780
781 if(name_limit){ //Do we need to check name length ?
782 int name_end = name_limit/7; //Max string length for acceptable spacing
783
784 if(files[top+i].stats.attrFile & MC_ATTR_SUBDIR)
785 name_end -= 1; //For folders, reserve one character for final '/'
786 if(strlen(tmp) > name_end){ //Is name too long for clean display ?
787 tmp[name_end-1] = '~'; //indicate filename abbreviation
788 tmp[name_end] = 0; //abbreviate name length to make room for details
789 }
790 }
791 if(files[top+i].stats.attrFile & MC_ATTR_SUBDIR)
792 strcat(tmp, "/");
793 printXY(tmp, x+4, y, color, TRUE, name_limit);
794 y += FONT_HEIGHT;
795
796 }else{ //Thumbnail mode
797
798 if(files[top+i].stats.attrFile & MC_ATTR_SUBDIR){
799 strcat(tmp, "/");
800 gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
801 gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0,1,0,1,0), 0);
802 gsKit_set_test(gsGlobal, GS_ATEST_OFF);
803 gsKit_prim_sprite_texture(gsGlobal,
804 &TexIcon[0], x+20, (y+10), 0, 0, x+72-20, (y+55-10), 16, 16,
805 0, GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00));
806 gsKit_set_test(gsGlobal, GS_ATEST_ON);
807 gsKit_set_primalpha(gsGlobal, GS_BLEND_BACK2FRONT, 0);
808 gsGlobal->PrimAlphaEnable = GS_SETTING_OFF;
809 thumb_test[top+i]=BADJPG;
810 goto frame;
811 }
812
813 if(thumb_load){
814 sprintf(jpgpath, "%s%s", path, files[top+i].name);
815 loadSkin( THUMB_PIC, jpgpath, thumb_num+thumb_top);
816 thumb_test[top+i]=testthumb;
817 }
818
819 if(thumb_test[top+i]==LOADED){
820 gsKit_prim_sprite_texture(gsGlobal,
821 &TexThumb[thumb_num+thumb_top], x, y, 0, 0, x+72, (y+55), 64, 32,
822 0, BrightColor);
823 ++thumb_num;
824 }else{ // BADJPG
825 gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
826 gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0,1,0,1,0), 0);
827 gsKit_set_test(gsGlobal, GS_ATEST_OFF);
828 gsKit_prim_sprite_texture(gsGlobal,
829 &TexIcon[0], x+20, (y+10), 0, 0, x+72-20, (y+55-10), 16, 16,
830 0, GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00));
831 gsKit_set_test(gsGlobal, GS_ATEST_ON);
832 gsKit_set_primalpha(gsGlobal, GS_BLEND_BACK2FRONT, 0);
833 gsGlobal->PrimAlphaEnable = GS_SETTING_OFF;
834 }
835
836frame:
837 drawFrame(x, y, x+72, (y+55),color);
838
839 Len = printXY(tmp, 0, 0, 0, FALSE, 0);
840 if(Len>72 && top+i==jpg_browser_sel){
841 if(t%0x10==0){
842 strcpy(tmp1,tmp+print_name);
843 tmp1[10]='\0';
844 if(++print_name>(Len/FONT_WIDTH-10))
845 print_name=0;
846 }
847 Len = printXY(tmp1, 0, 0, 0, FALSE, 0);
848 printXY(tmp1, x+72/2-Len/2, (y+58), color, TRUE, 0);
849 }else if(Len>72){
850 tmp[7]='.'; tmp[8]='.'; tmp[9]='.'; tmp[10]='\0';
851 printXY(tmp, x-4, (y+58), color, TRUE, 0);
852 }else
853 printXY(tmp, x+72/2-Len/2, (y+58), color, TRUE, 0);
854
855 if(TV_mode == TV_mode_NTSC)
856 y += 71+15;
857 else if(TV_mode == TV_mode_PAL)
858 y += 71+11;
859
860 }/* end else THUMBNAIL */
861
862 } //ends for, so all browser rows were fixed above
863 thumb_load=FALSE;
864 if(jpg_browser_nfiles > rows) { //if more files than available rows, use scrollbar
865 drawFrame(SCREEN_WIDTH-SCREEN_MARGIN-LINE_THICKNESS*8, Frame_start_y,
866 SCREEN_WIDTH-SCREEN_MARGIN, Frame_end_y, setting->color[1]);
867 y0=(Menu_end_y-Menu_start_y+8) * ((double)top/jpg_browser_nfiles);
868 y1=(Menu_end_y-Menu_start_y+8) * ((double)(top+rows)/jpg_browser_nfiles);
869 drawOpSprite(setting->color[1],
870 SCREEN_WIDTH-SCREEN_MARGIN-LINE_THICKNESS*6, (y0+Menu_start_y-4),
871 SCREEN_WIDTH-SCREEN_MARGIN-LINE_THICKNESS*2, (y1+Menu_start_y-4));
872 } //ends clause for scrollbar
873 msg0[0]='\0';
874 if(jpg_browser_pushed)
875 sprintf(msg0, "%s %s: %s", LNG(Jpg_Viewer), LNG(Path), path);
876
877 //Tooltip section
878 msg1[0]='\0';
879 if (swapKeys)
880 sprintf(msg1, "ÿ1:%s", LNG(View));
881 else
882 sprintf(msg1, "ÿ0:%s", LNG(View));
883 if(jpg_browser_mode==LIST)
884 sprintf(tmp, " ÿ3:%s ÿ2:%s", LNG(Up), LNG(Thumb));
885 else
886 sprintf(tmp, " ÿ3:%s ÿ2:%s", LNG(Up), LNG(List));
887 strcat(msg1, tmp);
888 sprintf(tmp, " Sel:%s Start:%s L1/R1:%dsec L2:",
889 LNG(Exit), LNG(SlideShow), SlideShowTime);
890 strcat(msg1, tmp);
891 if(SlideShowTrans==OFF)
892 strcat(msg1, LNG(Off));
893 else if(SlideShowTrans==ZOOM)
894 strcat(msg1, LNG(Zoom));
895 else if(SlideShowTrans==FADE)
896 strcat(msg1, LNG(Fade));
897 else if(SlideShowTrans==ZOOM_FADE)
898 strcat(msg1, LNG(ZoomFade));
899 sprintf(tmp, " R2:%s", LNG(PathPad));
900 strcat(msg1, tmp);
901 setScrTmp(msg0, msg1);
902 }//ends if(event||post_event)
903 drawScr();
904 post_event = event;
905 event = 0;
906 }//ends while
907} /* end JpgViewer */
908//--------------------------------------------------------------
909//End of file: jpgviewer.c
910//--------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.