9 #include "SDL_gfxPrimitives.h"
10 #include "SDL_rotozoom.h"
13 #include "pnd_logger.h"
15 #include "pnd_container.h"
16 #include "pnd_discovery.h"
23 #include "mmwrapcmd.h"
27 SDL_Surface *sdl_realscreen = NULL;
28 unsigned int sdl_ticks = 0;
32 unsigned short int g_scale = 1; // 1 == noscale
34 SDL_Surface *g_imgcache [ IMG_MAX ];
36 TTF_Font *g_big_font = NULL;
37 TTF_Font *g_grid_font = NULL;
38 TTF_Font *g_detailtext_font = NULL;
39 TTF_Font *g_tab_font = NULL;
41 extern pnd_conf_handle g_conf;
43 /* current display state
45 int ui_rows_scrolled_down = 0; // number of rows that should be missing from top of the display
46 mm_appref_t *ui_selected = NULL;
47 unsigned char ui_category = 0; // current category
48 unsigned char ui_catshift = 0; // how many cats are offscreen to the left
50 extern mm_category_t g_categories [ MAX_CATS ];
51 extern unsigned char g_categorycount;
53 static SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ); // height -1 means ignore
54 static int ui_selected_index ( void );
56 static unsigned int ui_timer ( unsigned int interval ) {
61 unsigned char ui_setup ( void ) {
66 SDL_Init ( SDL_INIT_EVERYTHING | SDL_INIT_NOPARACHUTE );
68 SDL_SetTimer ( 30, ui_timer ); // 30fps
70 SDL_JoystickOpen ( 0 ); // turn on joy-0
72 SDL_WM_SetCaption ( "mmenu", "mmenu" );
74 // hide the mouse cursor if we can
75 if ( SDL_ShowCursor ( -1 ) == 1 ) {
82 unsigned int svm = SDL_SWSURFACE /*| SDL_FULLSCREEN*/ /* 0*/;
83 if ( pnd_conf_get_as_int_d ( g_conf, "display.fullscreen", 0 ) > 0 ) {
84 svm |= SDL_FULLSCREEN;
88 SDL_SetVideoMode ( 800 * g_scale, 480 * g_scale, 16 /*bpp*/, svm );
90 if ( ! sdl_realscreen ) {
91 pnd_log ( pndn_error, "ERROR: Couldn't open SDL real screen; dieing." );
95 pnd_log ( pndn_debug, "Pixel format:" );
96 pnd_log ( pndn_debug, "bpp b: %u\n", sdl_realscreen -> format -> BitsPerPixel );
97 pnd_log ( pndn_debug, "bpp B: %u\n", sdl_realscreen -> format -> BytesPerPixel );
98 pnd_log ( pndn_debug, "R mask: %08x\n", sdl_realscreen -> format -> Rmask );
99 pnd_log ( pndn_debug, "G mask: %08x\n", sdl_realscreen -> format -> Gmask );
100 pnd_log ( pndn_debug, "B mask: %08x\n", sdl_realscreen -> format -> Bmask );
106 /* Set 16-bit stereo audio at 22Khz */
107 fmt.freq = 44100; //22050;
108 fmt.format = AUDIO_S16; //AUDIO_S16;
110 fmt.samples = 2048; /* A good value for games */
111 fmt.callback = mixaudio;
114 /* Open the audio device and start playing sound! */
115 if ( SDL_OpenAudio ( &fmt, NULL ) < 0 ) {
116 zotlog ( "Unable to open audio: %s\n", SDL_GetError() );
120 SDL_PauseAudio ( 0 );
125 //IMG_Init ( IMG_INIT_JPG | IMG_INIT_PNG );
131 if ( TTF_Init() == -1 ) {
132 pnd_log ( pndn_error, "ERROR: Couldn't set up SDL TTF lib\n" );
133 return ( 0 ); // couldn't set up SDL TTF
136 char fullpath [ PATH_MAX ];
138 sprintf ( fullpath, "%s/%s", pnd_conf_get_as_char ( g_conf, MMENU_ARTPATH ), pnd_conf_get_as_char ( g_conf, "minimenu.font" ) );
139 g_big_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
140 if ( ! g_big_font ) {
141 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
142 pnd_conf_get_as_char ( g_conf, "minimenu.font" ), pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
143 return ( 0 ); // couldn't set up SDL TTF
147 sprintf ( fullpath, "%s/%s", pnd_conf_get_as_char ( g_conf, MMENU_ARTPATH ), pnd_conf_get_as_char ( g_conf, MMENU_GRID_FONT ) );
148 g_grid_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, MMENU_GRID_FONTSIZE, 10 ) );
149 if ( ! g_grid_font ) {
150 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
151 pnd_conf_get_as_char ( g_conf, MMENU_GRID_FONT ), pnd_conf_get_as_int_d ( g_conf, MMENU_GRID_FONTSIZE, 10 ) );
152 return ( 0 ); // couldn't set up SDL TTF
156 sprintf ( fullpath, "%s/%s", pnd_conf_get_as_char ( g_conf, MMENU_ARTPATH ), pnd_conf_get_as_char ( g_conf, "detailtext.font" ) );
157 g_detailtext_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
158 if ( ! g_detailtext_font ) {
159 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
160 pnd_conf_get_as_char ( g_conf, "detailtext.font" ), pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
161 return ( 0 ); // couldn't set up SDL TTF
165 sprintf ( fullpath, "%s/%s", pnd_conf_get_as_char ( g_conf, MMENU_ARTPATH ), pnd_conf_get_as_char ( g_conf, "tabs.font" ) );
166 g_tab_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
167 if ( ! g_tab_font ) {
168 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
169 pnd_conf_get_as_char ( g_conf, "tabs.font" ), pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
170 return ( 0 ); // couldn't set up SDL TTF
176 mm_imgcache_t g_imagecache [ IMG_TRUEMAX ] = {
177 { IMG_BACKGROUND_800480, "graphics.IMG_BACKGROUND_800480" },
178 { IMG_BACKGROUND_TABMASK, "graphics.IMG_BACKGROUND_TABMASK" },
179 { IMG_DETAIL_PANEL, "graphics.IMG_DETAIL_PANEL" },
180 { IMG_DETAIL_BG, "graphics.IMG_DETAIL_BG" },
181 { IMG_SELECTED_ALPHAMASK, "graphics.IMG_SELECTED_ALPHAMASK" },
182 { IMG_TAB_SEL, "graphics.IMG_TAB_SEL" },
183 { IMG_TAB_UNSEL, "graphics.IMG_TAB_UNSEL" },
184 { IMG_ICON_MISSING, "graphics.IMG_ICON_MISSING" },
185 { IMG_SELECTED_HILITE, "graphics.IMG_SELECTED_HILITE" },
186 { IMG_PREVIEW_MISSING, "graphics.IMG_PREVIEW_MISSING" },
187 { IMG_ARROW_UP, "graphics.IMG_ARROW_UP", },
188 { IMG_ARROW_DOWN, "graphics.IMG_ARROW_DOWN", },
189 { IMG_ARROW_SCROLLBAR, "graphics.IMG_ARROW_SCROLLBAR", },
193 unsigned char ui_imagecache ( char *basepath ) {
195 char fullpath [ PATH_MAX ];
199 for ( i = 0; i < IMG_MAX; i++ ) {
201 if ( g_imagecache [ i ].id != i ) {
202 pnd_log ( pndn_error, "ERROR: Internal table mismatch during caching [%u]\n", i );
206 char *filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].confname );
209 pnd_log ( pndn_error, "ERROR: Missing filename in conf for key: %s\n", g_imagecache [ i ].confname );
213 sprintf ( fullpath, "%s/%s", basepath, filename );
215 if ( ! ( g_imagecache [ i ].i = IMG_Load ( fullpath ) ) ) {
216 pnd_log ( pndn_error, "ERROR: Couldn't load static cache image: %s\n", fullpath );
223 //g_imagecache [ IMG_SELECTED_ALPHAMASK ].i = SDL_CreateRGBSurface ( SDL_SWSURFACE, 60, 60, 32, 0xFF0000, 0x00FF00, 0xFF, 0xFF000000 );
224 //boxRGBA ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, 0, 0, 60, 60, 100, 100, 100, 250 );
230 g_imagecache [ IMG_SELECTED_ALPHAMASK ].i = ui_scale_image ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 ), -1 );
231 g_imagecache [ IMG_ICON_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_ICON_MISSING ].i, pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 ), -1 );
232 // scale text hilight
233 g_imagecache [ IMG_SELECTED_HILITE ].i = ui_scale_image ( g_imagecache [ IMG_SELECTED_HILITE ].i, pnd_conf_get_as_int_d ( g_conf, "grid.text_width", 50 ), -1 );
234 // scale preview no-pic
235 g_imagecache [ IMG_PREVIEW_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_PREVIEW_MISSING ].i,
236 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ),
237 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 50 ) );
239 // set alpha on detail panel
240 SDL_SetAlpha ( g_imagecache [ IMG_DETAIL_BG ].i, SDL_SRCALPHA, pnd_conf_get_as_int_d ( g_conf, "display.detail_bg_alpha", 50 ) );
245 void ui_render ( unsigned int render_mask ) {
248 // divide width: 550 / 250
249 // divide left side: 5 columns == 110px width
250 // 20px buffer either side == 70px wide icon + 20 + 20?
252 unsigned int icon_rows;
255 SDL_Rect rects [ MAXRECTS ], src;
256 SDL_Rect *dest = rects;
257 bzero ( dest, sizeof(SDL_Rect)*MAXRECTS );
259 unsigned int row, displayrow, col;
260 mm_appref_t *appiter;
262 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
264 unsigned char row_max = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_ROWMAX, 4 );
265 unsigned char col_max = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_COLMAX, 5 );
267 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
268 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
269 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
270 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
272 unsigned int grid_offset_x = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_x" );
273 unsigned int grid_offset_y = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_y" );
275 unsigned int icon_offset_x = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_x" );
276 unsigned int icon_offset_y = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_y" );
278 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
279 unsigned int text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
280 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "grid.text_offset_x" );
281 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_offset_y" );
283 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "grid.cell_width" );
284 unsigned int cell_height = pnd_conf_get_as_int ( g_conf, "grid.cell_height" );
286 // how many total rows do we need?
287 icon_rows = g_categories [ ui_category ].refcount / col_max;
288 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
292 // if no selected app yet, select the first one
294 if ( ! ui_selected ) {
295 ui_selected = g_categories [ ui_category ].refs;
299 // ensure selection is visible
302 int index = ui_selected_index();
303 int topleft = col_max * ui_rows_scrolled_down;
304 int botright = ( col_max * ( ui_rows_scrolled_down + row_max ) - 1 );
306 //pnd_log ( PND_LOG_DEFAULT, "index %u tl %u br %u\n", index, topleft, botright );
308 if ( index < topleft ) {
309 ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
310 } else if ( index > botright ) {
311 ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
314 if ( ui_rows_scrolled_down < 0 ) {
315 ui_rows_scrolled_down = 0;
316 } else if ( ui_rows_scrolled_down > icon_rows ) {
317 ui_rows_scrolled_down = icon_rows;
323 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
326 dest -> w = sdl_realscreen -> w;
327 dest -> h = sdl_realscreen -> h;
328 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
329 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
334 if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
337 dest -> w = sdl_realscreen -> w;
338 dest -> h = sdl_realscreen -> h;
339 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
340 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
345 if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
346 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
347 unsigned int tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
348 unsigned int tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
349 unsigned int tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
350 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
351 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
352 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
354 for ( col = ui_catshift;
356 ( screen_width / tab_width ) < g_categorycount ? ( screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift
362 if ( col == ui_category ) {
363 s = g_imagecache [ IMG_TAB_SEL ].i;
365 s = g_imagecache [ IMG_TAB_UNSEL ].i;
373 dest -> x = tab_offset_x + ( col * tab_width );
374 dest -> y = tab_offset_y;
375 //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
376 SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
377 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
382 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
383 rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ].catname, tmpfontcolor );
386 src.w = rtext -> w < text_width ? rtext -> w : text_width;
388 dest -> x = tab_offset_x + ( col * tab_width ) + text_offset_x;
389 dest -> y = tab_offset_y + text_offset_y;
390 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
391 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
398 // scroll bars and arrows
400 unsigned char show_bar = 0;
403 if ( ui_rows_scrolled_down && g_imagecache [ IMG_ARROW_UP ].i ) {
404 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
405 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
406 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
407 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
414 if ( ui_rows_scrolled_down + row_max < icon_rows && g_imagecache [ IMG_ARROW_DOWN ].i ) {
415 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
416 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
417 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
418 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
425 // show scrollbar as well
428 src.w = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_w", 10 );
429 src.h = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_h", 100 );
430 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
431 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
432 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
433 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
439 // render detail pane bg
440 if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
442 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
443 src.x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
444 src.y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
445 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
446 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
447 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
448 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
449 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
450 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
454 // render detail pane
455 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
456 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
457 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
458 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
459 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
463 } // detailpane frame/bg
465 // anything to render?
466 if ( g_categories [ ui_category ].refs ) {
468 appiter = g_categories [ ui_category ].refs;
472 // until we run out of apps, or run out of space
473 while ( appiter != NULL ) {
475 for ( col = 0; col < col_max && appiter != NULL; col++ ) {
477 // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
478 if ( row >= ui_rows_scrolled_down ) {
480 // selected? show hilights
481 if ( appiter == ui_selected ) {
483 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x;
484 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y;
485 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, NULL /* all */, sdl_realscreen, dest );
486 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
489 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
490 dest -> y = grid_offset_y + ( displayrow * cell_height ) + pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
491 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
492 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
497 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
498 SDL_Surface *iconsurface;
500 iconsurface = ic -> i;
502 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
503 iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
506 //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
512 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x;
513 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y;
515 SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
516 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
522 if ( appiter -> ref -> title_en ) {
524 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
525 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, tmpfontcolor );
528 src.w = text_width < rtext -> w ? text_width : rtext -> w;
530 if ( rtext -> w > text_width ) {
531 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
533 dest -> x = grid_offset_x + ( col * cell_width ) + text_offset_x - ( rtext -> w / 2 );
535 dest -> y = grid_offset_y + ( displayrow * cell_height ) + text_offset_y;
536 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
537 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
541 } // display now? or scrolled away..
544 appiter = appiter -> next;
546 } // for column 1...X
548 if ( row >= ui_rows_scrolled_down ) {
554 // are we done displaying rows?
555 if ( displayrow >= row_max ) {
562 // no apps to render?
563 pnd_log ( pndn_rem, "No applications to render?\n" );
569 unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
570 unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
571 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "detailtext.cell_width" );
573 unsigned int desty = cell_offset_y;
578 if ( ui_selected -> ref -> title_en ) {
580 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
581 rtext = TTF_RenderText_Blended ( g_detailtext_font, ui_selected -> ref -> title_en, tmpfontcolor );
584 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
586 dest -> x = cell_offset_x;
588 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
589 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
595 if ( ui_selected -> ref -> main_category ) {
597 sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
600 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
601 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
604 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
606 dest -> x = cell_offset_x;
608 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
609 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
615 if ( ui_selected -> ref -> clockspeed ) {
617 sprintf ( buffer, "CPU Clock: %s", ui_selected -> ref -> clockspeed );
620 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
621 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
624 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
626 dest -> x = cell_offset_x;
628 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
629 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
635 mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
636 SDL_Surface *previewpic;
639 previewpic = ic -> i;
641 previewpic = g_imagecache [ IMG_PREVIEW_MISSING ].i;
645 dest -> x = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_x", 50 ) +
646 ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
647 dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
648 SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
649 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
655 // update all the rects and send it all to sdl
656 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
660 void ui_process_input ( unsigned char block_p ) {
663 unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
664 static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
666 while ( ! ui_event &&
667 block_p ? SDL_WaitEvent ( &event ) : SDL_PollEvent ( &event ) )
670 switch ( event.type ) {
672 #if 0 // joystick motion
673 case SDL_JOYAXISMOTION:
675 pnd_log ( PND_LOG_DEFAULT, "joystick axis\n" );
677 if ( event.jaxis.axis == 0 ) {
679 if ( event.jaxis.value < 0 ) {
681 pnd_log ( PND_LOG_DEFAULT, "joystick axis - LEFT\n" );
682 } else if ( event.jaxis.value > 0 ) {
684 pnd_log ( PND_LOG_DEFAULT, "joystick axis - RIGHT\n" );
686 } else if ( event.jaxis.axis == 1 ) {
688 if ( event.jaxis.value < 0 ) {
690 } else if ( event.jaxis.value > 0 ) {
700 #if 0 // joystick buttons
701 case SDL_JOYBUTTONDOWN:
703 pnd_log ( PND_LOG_DEFAULT, "joystick button down %u\n", event.jbutton.button );
705 if ( event.jbutton.button == 0 ) { // B
707 } else if ( event.jbutton.button == 1 ) { // Y
709 } else if ( event.jbutton.button == 2 ) { // X
711 } else if ( event.jbutton.button == 3 ) { // A
714 } else if ( event.jbutton.button == 4 ) { // Select
715 ui_mask |= uisb_select;
716 } else if ( event.jbutton.button == 5 ) { // Start
717 ui_mask |= uisb_start;
719 } else if ( event.jbutton.button == 7 ) { // L
721 } else if ( event.jbutton.button == 8 ) { // R
730 case SDL_JOYBUTTONUP:
732 pnd_log ( PND_LOG_DEFAULT, "joystick button up %u\n", event.jbutton.button );
734 if ( event.jbutton.button == 0 ) { // B
737 } else if ( event.jbutton.button == 1 ) { // Y
739 } else if ( event.jbutton.button == 2 ) { // X
741 } else if ( event.jbutton.button == 3 ) { // A
744 } else if ( event.jbutton.button == 4 ) { // Select
745 ui_mask &= ~uisb_select;
746 } else if ( event.jbutton.button == 5 ) { // Start
747 ui_mask &= ~uisb_start;
749 } else if ( event.jbutton.button == 7 ) { // L
752 } else if ( event.jbutton.button == 8 ) { // R
763 #if 1 // keyboard events
766 //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
769 if ( event.key.keysym.sym == SDLK_RIGHT ) {
772 } else if ( event.key.keysym.sym == SDLK_LEFT ) {
775 } else if ( event.key.keysym.sym == SDLK_UP ) {
778 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
781 } else if ( event.key.keysym.sym == SDLK_SPACE || event.key.keysym.sym == SDLK_END ) {
784 } else if ( event.key.keysym.sym == SDLK_z || event.key.keysym.sym == SDLK_RSHIFT ) {
787 } else if ( event.key.keysym.sym == SDLK_x || event.key.keysym.sym == SDLK_RCTRL ) {
793 if ( event.key.keysym.sym == SDLK_q ) {
794 emit_and_quit ( MM_QUIT );
800 #if 0 // mouse / touchscreen
801 case SDL_MOUSEBUTTONDOWN:
802 if ( event.button.button == SDL_BUTTON_LEFT ) {
803 cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
808 case SDL_MOUSEBUTTONUP:
809 if ( event.button.button == SDL_BUTTON_LEFT ) {
810 cb_pointer_release ( gc, event.button.x / g_scale, event.button.y / g_scale );
824 } // switch event type
831 void ui_push_left ( void ) {
833 if ( ! ui_selected ) {
838 // are we alreadt at first item?
839 if ( g_categories [ ui_category ].refs == ui_selected ) {
840 // can't go any more left, we're at the head
842 // figure out the previous item; yay for singly linked list :/
843 mm_appref_t *i = g_categories [ ui_category ].refs;
845 if ( i -> next == ui_selected ) {
856 void ui_push_right ( void ) {
860 if ( ui_selected -> next ) {
861 ui_selected = ui_selected -> next;
865 ui_selected = g_categories [ ui_category ].refs;
871 void ui_push_up ( void ) {
872 unsigned char col_max = pnd_conf_get_as_int ( g_conf, MMENU_DISP_COLMAX );
882 void ui_push_down ( void ) {
883 unsigned char col_max = pnd_conf_get_as_int ( g_conf, MMENU_DISP_COLMAX );
897 void ui_push_exec ( void ) {
900 char buffer [ PATH_MAX ];
901 sprintf ( buffer, "%s/%s", ui_selected -> ref -> object_path, ui_selected -> ref -> object_filename );
902 pnd_apps_exec ( pnd_run_script,
904 ui_selected -> ref -> unique_id,
905 ui_selected -> ref -> exec,
906 ui_selected -> ref -> startdir,
907 ui_selected -> ref -> execargs,
908 atoi ( ui_selected -> ref -> clockspeed ),
909 PND_EXEC_OPTION_NORUN );
910 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
911 emit_and_quit ( buffer );
917 void ui_push_ltrigger ( void ) {
918 unsigned char oldcat = ui_category;
920 if ( ui_category > 0 ) {
923 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
924 ui_category = g_categorycount - 1;
928 if ( oldcat != ui_category ) {
935 void ui_push_rtrigger ( void ) {
936 unsigned char oldcat = ui_category;
938 if ( ui_category < ( g_categorycount - 1 ) ) {
941 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
946 if ( oldcat != ui_category ) {
953 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ) {
954 double scale = 1000000.0;
955 double scalex = 1000000.0;
956 double scaley = 1000000.0;
959 scalex = (double)maxwidth / (double)s -> w;
961 if ( maxheight == -1 ) {
964 scaley = (double)maxheight / (double)s -> h;
966 if ( scaley < scalex ) {
974 pnd_log ( pndn_debug, " Upscaling; scale factor %f\n", scale );
975 scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
976 SDL_FreeSurface ( s );
982 void ui_loadscreen ( void ) {
986 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
987 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
988 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
989 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
992 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
996 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
997 rtext = TTF_RenderText_Blended ( g_big_font, "Setting up menu...", tmpfontcolor );
1000 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1001 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1006 void ui_discoverscreen ( unsigned char clearscreen ) {
1010 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1011 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1012 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1013 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1016 if ( clearscreen ) {
1017 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1019 // render background
1020 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1023 dest.w = sdl_realscreen -> w;
1024 dest.h = sdl_realscreen -> h;
1025 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1026 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1033 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1034 rtext = TTF_RenderText_Blended ( g_big_font, "Looking for applications...", tmpfontcolor );
1035 if ( clearscreen ) {
1042 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1043 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1046 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1047 dest.x = rtext -> w + 30;
1049 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, &dest );
1050 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1056 void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
1058 SDL_Rect rects [ 4 ];
1059 SDL_Rect *dest = rects;
1060 bzero ( dest, sizeof(SDL_Rect)* 4 );
1062 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1063 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1064 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1065 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1067 static unsigned int stepx = 0;
1070 if ( clearscreen ) {
1071 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1073 // render background
1074 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1077 dest -> w = sdl_realscreen -> w;
1078 dest -> h = sdl_realscreen -> h;
1079 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1087 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1088 rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
1089 if ( clearscreen ) {
1096 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1100 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1101 dest -> x = rtext -> w + 30 + stepx;
1103 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, dest );
1109 rtext = TTF_RenderText_Blended ( g_tab_font, filename, tmpfontcolor );
1112 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1119 if ( stepx > 350 ) {
1123 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1128 int ui_selected_index ( void ) {
1130 if ( ! ui_selected ) {
1131 return ( -1 ); // no index
1134 mm_appref_t *r = g_categories [ ui_category ].refs;
1137 if ( r == ui_selected ) {