11 #include "SDL_gfxPrimitives.h"
12 #include "SDL_rotozoom.h"
13 #include "SDL_thread.h"
16 #include "pnd_logger.h"
18 #include "pnd_container.h"
19 #include "pnd_discovery.h"
21 #include "pnd_device.h"
27 #include "mmwrapcmd.h"
31 SDL_Surface *sdl_realscreen = NULL;
32 unsigned int sdl_ticks = 0;
33 SDL_Thread *g_preview_thread = NULL;
35 enum { sdl_user_ticker = 0, sdl_user_finishedpreview = 1 };
39 unsigned short int g_scale = 1; // 1 == noscale
41 SDL_Surface *g_imgcache [ IMG_MAX ];
43 TTF_Font *g_big_font = NULL;
44 TTF_Font *g_grid_font = NULL;
45 TTF_Font *g_detailtext_font = NULL;
46 TTF_Font *g_tab_font = NULL;
48 extern pnd_conf_handle g_conf;
50 /* current display state
52 int ui_rows_scrolled_down = 0; // number of rows that should be missing from top of the display
53 mm_appref_t *ui_selected = NULL;
54 unsigned char ui_category = 0; // current category
55 unsigned char ui_catshift = 0; // how many cats are offscreen to the left
57 extern mm_category_t g_categories [ MAX_CATS ];
58 extern unsigned char g_categorycount;
60 static SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ); // height -1 means ignore
61 static int ui_selected_index ( void );
63 unsigned char ui_setup ( void ) {
68 SDL_Init ( SDL_INIT_EVERYTHING | SDL_INIT_NOPARACHUTE );
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", g_skinpath, 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", g_skinpath, 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", g_skinpath, 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", g_skinpath, 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" );
277 unsigned int icon_max_width = pnd_conf_get_as_int ( g_conf, "grid.icon_max_width" );
279 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
280 unsigned int text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
281 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "grid.text_offset_x" );
282 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_offset_y" );
284 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "grid.cell_width" );
285 unsigned int cell_height = pnd_conf_get_as_int ( g_conf, "grid.cell_height" );
287 // how many total rows do we need?
288 icon_rows = g_categories [ ui_category ].refcount / col_max;
289 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
293 // if no selected app yet, select the first one
295 if ( ! ui_selected ) {
296 ui_selected = g_categories [ ui_category ].refs;
300 // reset touchscreen regions
303 // ensure selection is visible
306 int index = ui_selected_index();
307 int topleft = col_max * ui_rows_scrolled_down;
308 int botright = ( col_max * ( ui_rows_scrolled_down + row_max ) - 1 );
310 //pnd_log ( PND_LOG_DEFAULT, "index %u tl %u br %u\n", index, topleft, botright );
312 if ( index < topleft ) {
313 ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
314 } else if ( index > botright ) {
315 ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
318 if ( ui_rows_scrolled_down < 0 ) {
319 ui_rows_scrolled_down = 0;
320 } else if ( ui_rows_scrolled_down > icon_rows ) {
321 ui_rows_scrolled_down = icon_rows;
327 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
330 dest -> w = sdl_realscreen -> w;
331 dest -> h = sdl_realscreen -> h;
332 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
337 if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
340 dest -> w = sdl_realscreen -> w;
341 dest -> h = sdl_realscreen -> h;
342 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
347 if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
348 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
349 unsigned int tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
350 unsigned int tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
351 unsigned int tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
352 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
353 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
354 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
356 for ( col = ui_catshift;
358 ( screen_width / tab_width ) < g_categorycount ? ( screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift
364 if ( col == ui_category ) {
365 s = g_imagecache [ IMG_TAB_SEL ].i;
367 s = g_imagecache [ IMG_TAB_UNSEL ].i;
375 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
376 dest -> y = tab_offset_y;
377 //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
378 SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
381 ui_register_tab ( col, dest -> x, dest -> y, tab_width, tab_height );
387 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
388 rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ].catname, tmpfontcolor );
391 src.w = rtext -> w < text_width ? rtext -> w : text_width;
393 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
394 dest -> y = tab_offset_y + text_offset_y;
395 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
396 SDL_FreeSurface ( rtext );
403 // scroll bars and arrows
405 unsigned char show_bar = 0;
408 if ( ui_rows_scrolled_down && g_imagecache [ IMG_ARROW_UP ].i ) {
409 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
410 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
411 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
418 if ( ui_rows_scrolled_down + row_max < icon_rows && g_imagecache [ IMG_ARROW_DOWN ].i ) {
419 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
420 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
421 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
428 // show scrollbar as well
431 src.w = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_w", 10 );
432 src.h = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_h", 100 );
433 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
434 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
435 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
441 // render detail pane bg
442 if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
444 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
445 src.x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
446 src.y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
447 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
448 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
449 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
450 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
451 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
455 // render detail pane
456 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
457 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
458 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
459 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, 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 );
488 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
489 dest -> y = grid_offset_y + ( displayrow * cell_height ) + pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
490 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
495 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
496 SDL_Surface *iconsurface;
498 iconsurface = ic -> i;
500 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
501 iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
504 //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
510 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + (( icon_max_width - iconsurface -> w ) / 2);
511 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y;
513 SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
516 ui_register_app ( appiter, dest -> x, dest -> y, src.w, src.h );
523 if ( appiter -> ref -> title_en ) {
525 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
526 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, tmpfontcolor );
529 src.w = text_width < rtext -> w ? text_width : rtext -> w;
531 if ( rtext -> w > text_width ) {
532 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
534 dest -> x = grid_offset_x + ( col * cell_width ) + text_offset_x - ( rtext -> w / 2 );
536 dest -> y = grid_offset_y + ( displayrow * cell_height ) + text_offset_y;
537 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
538 SDL_FreeSurface ( rtext );
542 } // display now? or scrolled away..
545 appiter = appiter -> next;
547 } // for column 1...X
549 if ( row >= ui_rows_scrolled_down ) {
555 // are we done displaying rows?
556 if ( displayrow >= row_max ) {
563 // no apps to render?
564 pnd_log ( pndn_rem, "No applications to render?\n" );
570 unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
571 unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
572 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "detailtext.cell_width" );
574 unsigned int desty = cell_offset_y;
579 if ( ui_selected -> ref -> title_en ) {
581 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
582 rtext = TTF_RenderText_Blended ( g_detailtext_font, ui_selected -> ref -> title_en, tmpfontcolor );
585 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
587 dest -> x = cell_offset_x;
589 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
590 SDL_FreeSurface ( rtext );
596 if ( ui_selected -> ref -> main_category ) {
598 sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
601 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
602 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
605 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
607 dest -> x = cell_offset_x;
609 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
610 SDL_FreeSurface ( rtext );
616 if ( ui_selected -> ref -> clockspeed ) {
618 sprintf ( buffer, "CPU Clock: %s", ui_selected -> ref -> clockspeed );
621 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
622 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
625 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
627 dest -> x = cell_offset_x;
629 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
630 SDL_FreeSurface ( rtext );
636 if ( ui_selected -> ref -> clockspeed && ui_selected -> ref -> info_filename ) {
638 sprintf ( buffer, "Documentation - hit Y" );
641 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
642 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
645 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
647 dest -> x = cell_offset_x;
649 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
650 SDL_FreeSurface ( rtext );
656 mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
657 SDL_Surface *previewpic;
660 previewpic = ic -> i;
662 previewpic = g_imagecache [ IMG_PREVIEW_MISSING ].i;
666 dest -> x = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_x", 50 ) +
667 ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
668 dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
669 SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
680 static int last_battlevel = 0;
681 static unsigned char batterylevel = 0;
684 if ( time ( NULL ) - last_battlevel > 60 ) {
685 batterylevel = pnd_device_get_battery_gauge_perc();
686 last_battlevel = time ( NULL );
689 sprintf ( buffer, "Battery: %u%%", batterylevel );
692 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
693 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
694 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.battery_x", 20 );
695 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.battery_y", 450 );
696 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
697 SDL_FreeSurface ( rtext );
702 if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
703 char *buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
705 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
706 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
707 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
708 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
709 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
710 SDL_FreeSurface ( rtext );
715 if ( pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 ) {
718 time_t t = time ( NULL );
719 struct tm *tm = localtime ( &t );
720 strftime ( buffer, 50, "%a %H:%M %F", tm );
723 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
724 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
725 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.clock_x", 700 );
726 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.clock_y", 450 );
727 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
728 SDL_FreeSurface ( rtext );
732 // update all the rects and send it all to sdl
733 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
737 void ui_process_input ( unsigned char block_p ) {
740 unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
741 //static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
743 while ( ! ui_event &&
744 block_p ? SDL_WaitEvent ( &event ) : SDL_PollEvent ( &event ) )
747 switch ( event.type ) {
752 if ( event.user.code == sdl_user_ticker ) {
754 // timer went off, time to load something
755 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
757 pnd_log ( pndn_debug, "Deferred preview pic load ----------\n" );
759 // load the preview pics now!
760 pnd_disco_t *iter = ui_selected -> ref;
762 if ( iter -> preview_pic1 ) {
764 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.threaded_preview", 0 ) ) {
766 g_preview_thread = SDL_CreateThread ( (void*)ui_threaded_defered_preview, iter );
768 if ( ! g_preview_thread ) {
769 pnd_log ( pndn_error, "ERROR: Couldn't create preview thread\n" );
774 if ( ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
775 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
778 pnd_log ( pndn_debug, " Couldn't load preview pic: '%s' -> '%s'\n",
779 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
784 } // got a preview at all?
786 pnd_log ( pndn_debug, "Deferred preview pic load finish ---\n" );
791 } else if ( event.user.code == sdl_user_finishedpreview ) {
793 // if we just finished the one we happen to be looking at, better redraw now; otherwise, if
794 // we finished another, no big woop
795 if ( ui_selected && event.user.data1 == ui_selected -> ref ) {
803 #if 0 // joystick motion
804 case SDL_JOYAXISMOTION:
806 pnd_log ( PND_LOG_DEFAULT, "joystick axis\n" );
808 if ( event.jaxis.axis == 0 ) {
810 if ( event.jaxis.value < 0 ) {
812 pnd_log ( PND_LOG_DEFAULT, "joystick axis - LEFT\n" );
813 } else if ( event.jaxis.value > 0 ) {
815 pnd_log ( PND_LOG_DEFAULT, "joystick axis - RIGHT\n" );
817 } else if ( event.jaxis.axis == 1 ) {
819 if ( event.jaxis.value < 0 ) {
821 } else if ( event.jaxis.value > 0 ) {
831 #if 0 // joystick buttons
832 case SDL_JOYBUTTONDOWN:
834 pnd_log ( PND_LOG_DEFAULT, "joystick button down %u\n", event.jbutton.button );
836 if ( event.jbutton.button == 0 ) { // B
838 } else if ( event.jbutton.button == 1 ) { // Y
840 } else if ( event.jbutton.button == 2 ) { // X
842 } else if ( event.jbutton.button == 3 ) { // A
845 } else if ( event.jbutton.button == 4 ) { // Select
846 ui_mask |= uisb_select;
847 } else if ( event.jbutton.button == 5 ) { // Start
848 ui_mask |= uisb_start;
850 } else if ( event.jbutton.button == 7 ) { // L
852 } else if ( event.jbutton.button == 8 ) { // R
861 case SDL_JOYBUTTONUP:
863 pnd_log ( PND_LOG_DEFAULT, "joystick button up %u\n", event.jbutton.button );
865 if ( event.jbutton.button == 0 ) { // B
868 } else if ( event.jbutton.button == 1 ) { // Y
870 } else if ( event.jbutton.button == 2 ) { // X
872 } else if ( event.jbutton.button == 3 ) { // A
875 } else if ( event.jbutton.button == 4 ) { // Select
876 ui_mask &= ~uisb_select;
877 } else if ( event.jbutton.button == 5 ) { // Start
878 ui_mask &= ~uisb_start;
880 } else if ( event.jbutton.button == 7 ) { // L
883 } else if ( event.jbutton.button == 8 ) { // R
894 #if 1 // keyboard events
897 //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
899 // SDLK_LALT -> Start
902 if ( event.key.keysym.sym == SDLK_RIGHT ) {
905 } else if ( event.key.keysym.sym == SDLK_LEFT ) {
908 } else if ( event.key.keysym.sym == SDLK_UP ) {
911 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
914 } else if ( event.key.keysym.sym == SDLK_SPACE || event.key.keysym.sym == SDLK_END ) {
917 } else if ( event.key.keysym.sym == SDLK_z || event.key.keysym.sym == SDLK_RSHIFT ) {
920 } else if ( event.key.keysym.sym == SDLK_x || event.key.keysym.sym == SDLK_RCTRL ) {
923 } else if ( event.key.keysym.sym == SDLK_y || event.key.keysym.sym == SDLK_PAGEUP ) {
926 ui_show_info ( pnd_run_script, ui_selected -> ref );
930 } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
934 } else if ( event.key.keysym.sym == SDLK_LCTRL /*LALT*/ ) { // select button
935 char *opts [ 20 ] = {
936 "Return to Minimenu",
938 "Rescan for Applications",
939 "Run xfce4 from Minimenu",
940 "Run a terminal/console",
941 "Exit and run xfce4",
942 "Exit and run pmenu",
946 int sel = ui_modal_single_menu ( opts, 9, "Minimenu", "Enter to select; other to return." );
951 } else if ( sel == 1 ) {
953 sprintf ( buffer, "sudo poweroff" );
955 } else if ( sel == 2 ) {
957 pnd_log ( pndn_debug, "Freeing up applications\n" );
959 pnd_log ( pndn_debug, "Rescanning applications\n" );
963 ui_rows_scrolled_down = 0;
964 } else if ( sel == 3 ) {
966 char buffer [ PATH_MAX ];
967 sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/bin/startxfce4" );
968 emit_and_quit ( buffer );
969 } else if ( sel == 4 ) {
972 argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
976 ui_forkexec ( argv );
979 } else if ( sel == 5 ) {
981 sprintf ( buffer, "echo startxfce4 > /tmp/gui.load" );
983 //sprintf ( buffer, "sudo poweroff" );
986 } else if ( sel == 6 ) {
988 sprintf ( buffer, "echo pmenu > /tmp/gui.load" );
990 //sprintf ( buffer, "sudo poweroff" );
993 } else if ( sel == 7 ) {
994 emit_and_quit ( MM_QUIT );
995 } else if ( sel == 8 ) {
1003 if ( event.key.keysym.sym == SDLK_q ) {
1004 emit_and_quit ( MM_QUIT );
1010 #if 1 // mouse / touchscreen
1012 case SDL_MOUSEBUTTONDOWN:
1013 if ( event.button.button == SDL_BUTTON_LEFT ) {
1014 cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
1020 case SDL_MOUSEBUTTONUP:
1021 if ( event.button.button == SDL_BUTTON_LEFT ) {
1022 ui_touch_act ( event.button.x, event.button.y );
1035 } // switch event type
1042 void ui_push_left ( unsigned char forcecoil ) {
1044 if ( ! ui_selected ) {
1045 ui_push_right ( 0 );
1049 // what column we in?
1050 unsigned int col = ui_determine_screen_col ( ui_selected );
1052 // are we alreadt at first item?
1053 if ( forcecoil == 0 &&
1054 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1057 unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1059 ui_push_right ( 0 );
1063 } else if ( g_categories [ ui_category ].refs == ui_selected ) {
1064 // can't go any more left, we're at the head
1067 // figure out the previous item; yay for singly linked list :/
1068 mm_appref_t *i = g_categories [ ui_category ].refs;
1070 if ( i -> next == ui_selected ) {
1078 ui_set_selected ( ui_selected );
1083 void ui_push_right ( unsigned char forcecoil ) {
1085 if ( ui_selected ) {
1087 // what column we in?
1088 unsigned int col = ui_determine_screen_col ( ui_selected );
1091 if ( forcecoil == 0 &&
1092 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1093 col == pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1 )
1096 unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1103 // just go to the next
1105 if ( ui_selected -> next ) {
1106 ui_selected = ui_selected -> next;
1112 ui_selected = g_categories [ ui_category ].refs;
1115 ui_set_selected ( ui_selected );
1120 void ui_push_up ( void ) {
1121 unsigned char col_max = pnd_conf_get_as_int ( g_conf, MMENU_DISP_COLMAX );
1123 if ( ! ui_selected ) {
1128 unsigned int row = ui_determine_row ( ui_selected );
1131 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 1 ) == 0 )
1133 // wrap around instead
1135 unsigned int col = ui_determine_screen_col ( ui_selected );
1138 ui_selected = g_categories [ ui_category ].refs;
1139 while ( ui_selected -> next ) {
1140 ui_selected = ui_selected -> next;
1143 // try to move to same column
1144 unsigned int newcol = ui_determine_screen_col ( ui_selected );
1145 if ( newcol > col ) {
1153 // scroll down to show it
1154 int r = ui_determine_row ( ui_selected ) - 1;
1155 if ( r - pnd_conf_get_as_int ( g_conf, MMENU_DISP_ROWMAX ) > 0 ) {
1156 ui_rows_scrolled_down = (unsigned int) r;
1160 // stop at top/bottom
1172 void ui_push_down ( void ) {
1173 unsigned char col_max = pnd_conf_get_as_int ( g_conf, MMENU_DISP_COLMAX );
1175 if ( ui_selected ) {
1178 unsigned int row = ui_determine_row ( ui_selected );
1181 unsigned int icon_rows = g_categories [ ui_category ].refcount / col_max;
1182 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
1187 if ( row == ( icon_rows - 1 ) &&
1188 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 1 ) == 0 )
1191 unsigned char col = ui_determine_screen_col ( ui_selected );
1193 ui_selected = g_categories [ ui_category ].refs;
1196 ui_selected = ui_selected -> next;
1200 ui_rows_scrolled_down = 0;
1205 ui_push_right ( 1 );
1212 ui_push_right ( 0 );
1218 void ui_push_exec ( void ) {
1220 if ( ui_selected ) {
1221 char buffer [ PATH_MAX ];
1222 sprintf ( buffer, "%s/%s", ui_selected -> ref -> object_path, ui_selected -> ref -> object_filename );
1223 pnd_apps_exec ( pnd_run_script,
1225 ui_selected -> ref -> unique_id,
1226 ui_selected -> ref -> exec,
1227 ui_selected -> ref -> startdir,
1228 ui_selected -> ref -> execargs,
1229 atoi ( ui_selected -> ref -> clockspeed ),
1230 PND_EXEC_OPTION_NORUN );
1231 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1232 emit_and_quit ( buffer );
1238 void ui_push_ltrigger ( void ) {
1239 unsigned char oldcat = ui_category;
1241 if ( ui_category > 0 ) {
1244 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1245 ui_category = g_categorycount - 1;
1249 if ( oldcat != ui_category ) {
1251 ui_set_selected ( ui_selected );
1254 // make tab visible?
1255 if ( ui_catshift > 0 && ui_category == ui_catshift - 1 ) {
1260 ui_rows_scrolled_down = 0;
1265 void ui_push_rtrigger ( void ) {
1266 unsigned char oldcat = ui_category;
1268 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
1269 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1271 if ( ui_category < ( g_categorycount - 1 ) ) {
1274 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1279 if ( oldcat != ui_category ) {
1281 ui_set_selected ( ui_selected );
1284 // make tab visible?
1285 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
1290 ui_rows_scrolled_down = 0;
1295 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ) {
1296 double scale = 1000000.0;
1297 double scalex = 1000000.0;
1298 double scaley = 1000000.0;
1299 SDL_Surface *scaled;
1301 scalex = (double)maxwidth / (double)s -> w;
1303 if ( maxheight == -1 ) {
1306 scaley = (double)maxheight / (double)s -> h;
1308 if ( scaley < scalex ) {
1316 scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
1317 SDL_FreeSurface ( s );
1323 void ui_loadscreen ( void ) {
1327 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1328 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1329 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1330 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1333 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1337 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1338 rtext = TTF_RenderText_Blended ( g_big_font, "Setting up menu...", tmpfontcolor );
1341 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1342 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1343 SDL_FreeSurface ( rtext );
1348 void ui_discoverscreen ( unsigned char clearscreen ) {
1352 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1353 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1354 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1355 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1358 if ( clearscreen ) {
1359 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1361 // render background
1362 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1365 dest.w = sdl_realscreen -> w;
1366 dest.h = sdl_realscreen -> h;
1367 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1368 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1375 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1376 rtext = TTF_RenderText_Blended ( g_big_font, "Looking for applications...", tmpfontcolor );
1377 if ( clearscreen ) {
1384 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1385 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1386 SDL_FreeSurface ( rtext );
1389 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1390 dest.x = rtext -> w + 30;
1392 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, &dest );
1393 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1399 void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
1401 SDL_Rect rects [ 4 ];
1402 SDL_Rect *dest = rects;
1403 bzero ( dest, sizeof(SDL_Rect)* 4 );
1405 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1406 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1407 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1408 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1410 static unsigned int stepx = 0;
1413 if ( clearscreen ) {
1414 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1416 // render background
1417 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1420 dest -> w = sdl_realscreen -> w;
1421 dest -> h = sdl_realscreen -> h;
1422 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1430 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1431 rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
1432 if ( clearscreen ) {
1439 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1440 SDL_FreeSurface ( rtext );
1444 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1445 dest -> x = rtext -> w + 30 + stepx;
1447 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, dest );
1453 rtext = TTF_RenderText_Blended ( g_tab_font, filename, tmpfontcolor );
1456 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1457 SDL_FreeSurface ( rtext );
1464 if ( stepx > 350 ) {
1468 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1473 int ui_selected_index ( void ) {
1475 if ( ! ui_selected ) {
1476 return ( -1 ); // no index
1479 mm_appref_t *r = g_categories [ ui_category ].refs;
1482 if ( r == ui_selected ) {
1492 static mm_appref_t *timer_ref = NULL;
1493 void ui_set_selected ( mm_appref_t *r ) {
1495 if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1496 return; // no desire to defer anything
1501 SDL_SetTimer ( 0, NULL );
1506 SDL_SetTimer ( pnd_conf_get_as_int_d ( g_conf, "previewpic.defer_timer_ms", 1000 ), ui_callback_f );
1512 unsigned int ui_callback_f ( unsigned int t ) {
1514 if ( ui_selected != timer_ref ) {
1515 return ( 0 ); // user has moved it, who cares
1519 bzero ( &e, sizeof(SDL_Event) );
1520 e.type = SDL_USEREVENT;
1521 e.user.code = sdl_user_ticker;
1522 SDL_PushEvent ( &e );
1527 int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer ) {
1528 SDL_Rect rects [ 40 ];
1529 SDL_Rect *dest = rects;
1533 bzero ( rects, sizeof(SDL_Rect) * 40 );
1535 unsigned int sel = 0;
1537 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1538 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1539 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1540 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1542 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1544 SDL_Color selfontcolor = { 0/*font_rgba_r*/, font_rgba_g, font_rgba_b, font_rgba_a };
1552 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1553 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1554 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
1555 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
1556 SDL_FillRect( sdl_realscreen, dest, 0 );
1558 // show dialog background
1559 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
1560 src.x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1561 src.y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1562 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
1563 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
1564 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1565 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1566 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1567 // repeat for darken?
1568 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1569 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1570 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1574 // show dialog frame
1575 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
1576 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1577 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1578 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
1579 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1585 rtext = TTF_RenderText_Blended ( g_tab_font, title, tmpfontcolor );
1586 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1587 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
1588 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1589 SDL_FreeSurface ( rtext );
1595 rtext = TTF_RenderText_Blended ( g_tab_font, footer, tmpfontcolor );
1596 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1597 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
1598 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
1600 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1601 SDL_FreeSurface ( rtext );
1606 for ( i = 0; i < argc; i++ ) {
1610 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
1612 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], tmpfontcolor );
1614 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1615 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 ) );
1616 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1617 SDL_FreeSurface ( rtext );
1622 // update all the rects and send it all to sdl
1623 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1627 while ( SDL_WaitEvent ( &event ) ) {
1629 switch ( event.type ) {
1633 if ( event.key.keysym.sym == SDLK_UP ) {
1637 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1638 if ( sel < argc - 1 ) {
1642 } else if ( event.key.keysym.sym == SDLK_RETURN ) {
1645 } else if ( event.key.keysym.sym == SDLK_q ) {
1649 return ( -1 ); // nada
1664 unsigned char ui_determine_row ( mm_appref_t *a ) {
1665 unsigned int row = 0;
1667 mm_appref_t *i = g_categories [ ui_category ].refs;
1672 row /= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
1677 unsigned char ui_determine_screen_row ( mm_appref_t *a ) {
1678 return ( ui_determine_row ( a ) % pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 5 ) );
1681 unsigned char ui_determine_screen_col ( mm_appref_t *a ) {
1682 unsigned int col = 0;
1684 mm_appref_t *i = g_categories [ ui_category ].refs;
1689 col %= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
1694 unsigned char ui_show_info ( char *pndrun, pnd_disco_t *p ) {
1695 char *viewer, *searchpath;
1696 pnd_conf_handle desktoph;
1699 searchpath = pnd_conf_query_searchpath();
1701 desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
1707 viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
1710 return ( 0 ); // no way to view the file
1714 if ( ! p -> unique_id ) {
1718 if ( ! p -> info_filename ) {
1722 if ( ! p -> info_name ) {
1733 if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) {
1734 snprintf ( pargs, 1001, "%s %s",
1735 pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
1740 char pndfile [ 1024 ];
1741 if ( p -> object_type == pnd_object_type_directory ) {
1742 // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
1743 strncpy ( pndfile, p -> object_path, 1000 );
1744 } else if ( p -> object_type == pnd_object_type_pnd ) {
1745 // pnd_run.sh wants the full path and filename for the .pnd file
1746 snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
1749 if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs,
1750 p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) )
1755 pnd_log ( pndn_debug, "Info Exec=%s\n", pnd_apps_exec_runline() );
1759 if ( ( x = fork() ) < 0 ) {
1760 pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
1765 execl ( "/bin/sh", "/bin/sh", "-c", pnd_apps_exec_runline(), (char*)NULL );
1766 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", pnd_apps_exec_runline() );
1778 #define MAXTOUCH 100
1779 ui_touch_t ui_touchrects [ MAXTOUCH ];
1780 unsigned char ui_touchrect_count = 0;
1782 void ui_register_reset ( void ) {
1783 bzero ( ui_touchrects, sizeof(ui_touch_t)*MAXTOUCH );
1784 ui_touchrect_count = 0;
1788 void ui_register_tab ( unsigned char catnum, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
1790 if ( ui_touchrect_count == MAXTOUCH ) {
1794 ui_touchrects [ ui_touchrect_count ].r.x = x;
1795 ui_touchrects [ ui_touchrect_count ].r.y = y;
1796 ui_touchrects [ ui_touchrect_count ].r.w = w;
1797 ui_touchrects [ ui_touchrect_count ].r.h = h;
1798 ui_touchrects [ ui_touchrect_count ].catnum = catnum;
1799 ui_touchrect_count++;
1804 void ui_register_app ( mm_appref_t *app, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
1806 if ( ui_touchrect_count == MAXTOUCH ) {
1810 ui_touchrects [ ui_touchrect_count ].r.x = x;
1811 ui_touchrects [ ui_touchrect_count ].r.y = y;
1812 ui_touchrects [ ui_touchrect_count ].r.w = w;
1813 ui_touchrects [ ui_touchrect_count ].r.h = h;
1814 ui_touchrects [ ui_touchrect_count ].ref = app;
1815 ui_touchrect_count++;
1820 void ui_touch_act ( unsigned int x, unsigned int y ) {
1825 for ( i = 0; i < ui_touchrect_count; i++ ) {
1826 t = &(ui_touchrects [ i ]);
1828 if ( x >= t -> r.x &&
1829 x <= t -> r.x + t -> r.w &&
1831 y <= t -> r.y + t -> r.h
1836 ui_selected = t -> ref;
1839 ui_category = t -> catnum;
1850 unsigned char ui_forkexec ( char *argv[] ) {
1851 char *fooby = argv[0];
1854 if ( ( x = fork() ) < 0 ) {
1855 pnd_log ( pndn_error, "ERROR: Couldn't fork() for '%s'\n", fooby );
1859 if ( x == 0 ) { // child
1860 execv ( fooby, argv );
1861 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", fooby );
1869 unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ) {
1871 if ( ! cache_preview ( p, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
1872 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
1875 pnd_log ( pndn_debug, "THREAD: Couldn't load preview pic: '%s' -> '%s'\n",
1876 IFNULL(p->title_en,"No Name"), p -> preview_pic1 );
1879 // trigger that we completed
1881 bzero ( &e, sizeof(SDL_Event) );
1882 e.type = SDL_USEREVENT;
1883 e.user.code = sdl_user_finishedpreview;
1885 SDL_PushEvent ( &e );