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,
36 sdl_user_finishedpreview = 1,
37 sdl_user_finishedicon = 2,
42 unsigned short int g_scale = 1; // 1 == noscale
44 SDL_Surface *g_imgcache [ IMG_MAX ];
46 TTF_Font *g_big_font = NULL;
47 TTF_Font *g_grid_font = NULL;
48 TTF_Font *g_detailtext_font = NULL;
49 TTF_Font *g_tab_font = NULL;
51 extern pnd_conf_handle g_conf;
53 /* current display state
55 int ui_rows_scrolled_down = 0; // number of rows that should be missing from top of the display
56 mm_appref_t *ui_selected = NULL;
57 unsigned char ui_category = 0; // current category
58 unsigned char ui_catshift = 0; // how many cats are offscreen to the left
60 extern mm_category_t g_categories [ MAX_CATS ];
61 extern unsigned char g_categorycount;
63 static SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ); // height -1 means ignore
64 static int ui_selected_index ( void );
66 unsigned char ui_setup ( void ) {
71 SDL_Init ( SDL_INIT_EVERYTHING | SDL_INIT_NOPARACHUTE );
73 SDL_JoystickOpen ( 0 ); // turn on joy-0
75 SDL_WM_SetCaption ( "mmenu", "mmenu" );
77 // hide the mouse cursor if we can
78 if ( SDL_ShowCursor ( -1 ) == 1 ) {
85 unsigned int svm = SDL_SWSURFACE /*| SDL_FULLSCREEN*/ /* 0*/;
86 if ( pnd_conf_get_as_int_d ( g_conf, "display.fullscreen", 0 ) > 0 ) {
87 svm |= SDL_FULLSCREEN;
91 SDL_SetVideoMode ( 800 * g_scale, 480 * g_scale, 16 /*bpp*/, svm );
93 if ( ! sdl_realscreen ) {
94 pnd_log ( pndn_error, "ERROR: Couldn't open SDL real screen; dieing." );
98 pnd_log ( pndn_debug, "Pixel format:" );
99 pnd_log ( pndn_debug, "bpp b: %u\n", sdl_realscreen -> format -> BitsPerPixel );
100 pnd_log ( pndn_debug, "bpp B: %u\n", sdl_realscreen -> format -> BytesPerPixel );
101 pnd_log ( pndn_debug, "R mask: %08x\n", sdl_realscreen -> format -> Rmask );
102 pnd_log ( pndn_debug, "G mask: %08x\n", sdl_realscreen -> format -> Gmask );
103 pnd_log ( pndn_debug, "B mask: %08x\n", sdl_realscreen -> format -> Bmask );
109 /* Set 16-bit stereo audio at 22Khz */
110 fmt.freq = 44100; //22050;
111 fmt.format = AUDIO_S16; //AUDIO_S16;
113 fmt.samples = 2048; /* A good value for games */
114 fmt.callback = mixaudio;
117 /* Open the audio device and start playing sound! */
118 if ( SDL_OpenAudio ( &fmt, NULL ) < 0 ) {
119 zotlog ( "Unable to open audio: %s\n", SDL_GetError() );
123 SDL_PauseAudio ( 0 );
128 //IMG_Init ( IMG_INIT_JPG | IMG_INIT_PNG );
134 if ( TTF_Init() == -1 ) {
135 pnd_log ( pndn_error, "ERROR: Couldn't set up SDL TTF lib\n" );
136 return ( 0 ); // couldn't set up SDL TTF
139 char fullpath [ PATH_MAX ];
141 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "minimenu.font" ) );
142 g_big_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
143 if ( ! g_big_font ) {
144 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
145 pnd_conf_get_as_char ( g_conf, "minimenu.font" ), pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
146 return ( 0 ); // couldn't set up SDL TTF
150 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, MMENU_GRID_FONT ) );
151 g_grid_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, MMENU_GRID_FONTSIZE, 10 ) );
152 if ( ! g_grid_font ) {
153 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
154 pnd_conf_get_as_char ( g_conf, MMENU_GRID_FONT ), pnd_conf_get_as_int_d ( g_conf, MMENU_GRID_FONTSIZE, 10 ) );
155 return ( 0 ); // couldn't set up SDL TTF
159 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "detailtext.font" ) );
160 g_detailtext_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
161 if ( ! g_detailtext_font ) {
162 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
163 pnd_conf_get_as_char ( g_conf, "detailtext.font" ), pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
164 return ( 0 ); // couldn't set up SDL TTF
168 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "tabs.font" ) );
169 g_tab_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
170 if ( ! g_tab_font ) {
171 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
172 pnd_conf_get_as_char ( g_conf, "tabs.font" ), pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
173 return ( 0 ); // couldn't set up SDL TTF
179 mm_imgcache_t g_imagecache [ IMG_TRUEMAX ] = {
180 { IMG_BACKGROUND_800480, "graphics.IMG_BACKGROUND_800480" },
181 { IMG_BACKGROUND_TABMASK, "graphics.IMG_BACKGROUND_TABMASK" },
182 { IMG_DETAIL_PANEL, "graphics.IMG_DETAIL_PANEL" },
183 { IMG_DETAIL_BG, "graphics.IMG_DETAIL_BG" },
184 { IMG_SELECTED_ALPHAMASK, "graphics.IMG_SELECTED_ALPHAMASK" },
185 { IMG_TAB_SEL, "graphics.IMG_TAB_SEL" },
186 { IMG_TAB_UNSEL, "graphics.IMG_TAB_UNSEL" },
187 { IMG_TAB_LINE, "graphics.IMG_TAB_LINE" },
188 { IMG_TAB_LINEL, "graphics.IMG_TAB_LINEL" },
189 { IMG_TAB_LINER, "graphics.IMG_TAB_LINER" },
190 { IMG_ICON_MISSING, "graphics.IMG_ICON_MISSING" },
191 { IMG_SELECTED_HILITE, "graphics.IMG_SELECTED_HILITE" },
192 { IMG_PREVIEW_MISSING, "graphics.IMG_PREVIEW_MISSING" },
193 { IMG_ARROW_UP, "graphics.IMG_ARROW_UP", },
194 { IMG_ARROW_DOWN, "graphics.IMG_ARROW_DOWN", },
195 { IMG_ARROW_SCROLLBAR, "graphics.IMG_ARROW_SCROLLBAR", },
196 { IMG_HOURGLASS, "graphics.IMG_HOURGLASS", },
200 unsigned char ui_imagecache ( char *basepath ) {
202 char fullpath [ PATH_MAX ];
206 for ( i = 0; i < IMG_MAX; i++ ) {
208 if ( g_imagecache [ i ].id != i ) {
209 pnd_log ( pndn_error, "ERROR: Internal table mismatch during caching [%u]\n", i );
213 char *filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].confname );
216 pnd_log ( pndn_error, "ERROR: Missing filename in conf for key: %s\n", g_imagecache [ i ].confname );
220 if ( filename [ 0 ] == '/' ) {
221 strncpy ( fullpath, filename, PATH_MAX );
223 sprintf ( fullpath, "%s/%s", basepath, filename );
226 if ( ! ( g_imagecache [ i ].i = IMG_Load ( fullpath ) ) ) {
227 pnd_log ( pndn_error, "ERROR: Couldn't load static cache image: %s\n", fullpath );
234 //g_imagecache [ IMG_SELECTED_ALPHAMASK ].i = SDL_CreateRGBSurface ( SDL_SWSURFACE, 60, 60, 32, 0xFF0000, 0x00FF00, 0xFF, 0xFF000000 );
235 //boxRGBA ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, 0, 0, 60, 60, 100, 100, 100, 250 );
241 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 );
242 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 );
243 // scale text hilight
244 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 );
245 // scale preview no-pic
246 g_imagecache [ IMG_PREVIEW_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_PREVIEW_MISSING ].i,
247 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ),
248 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 50 ) );
250 // set alpha on detail panel
251 SDL_SetAlpha ( g_imagecache [ IMG_DETAIL_BG ].i, SDL_SRCALPHA, pnd_conf_get_as_int_d ( g_conf, "display.detail_bg_alpha", 50 ) );
256 void ui_render ( unsigned int render_mask ) {
259 // divide width: 550 / 250
260 // divide left side: 5 columns == 110px width
261 // 20px buffer either side == 70px wide icon + 20 + 20?
263 unsigned int icon_rows;
266 SDL_Rect rects [ MAXRECTS ], src;
267 SDL_Rect *dest = rects;
268 bzero ( dest, sizeof(SDL_Rect)*MAXRECTS );
270 unsigned int row, displayrow, col;
271 mm_appref_t *appiter;
273 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
275 unsigned char row_max = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_ROWMAX, 4 );
276 unsigned char col_max = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_COLMAX, 5 );
278 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
279 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
280 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
281 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
283 unsigned int grid_offset_x = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_x" );
284 unsigned int grid_offset_y = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_y" );
286 unsigned int icon_offset_x = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_x" );
287 unsigned int icon_offset_y = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_y" );
288 unsigned int icon_max_width = pnd_conf_get_as_int ( g_conf, "grid.icon_max_width" );
289 unsigned int icon_max_height = pnd_conf_get_as_int ( g_conf, "grid.icon_max_height" );
291 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
292 unsigned int text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
293 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "grid.text_offset_x" );
294 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_offset_y" );
296 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "grid.cell_width" );
297 unsigned int cell_height = pnd_conf_get_as_int ( g_conf, "grid.cell_height" );
299 // how many total rows do we need?
300 icon_rows = g_categories [ ui_category ].refcount / col_max;
301 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
305 // if no selected app yet, select the first one
307 if ( ! ui_selected ) {
308 ui_selected = g_categories [ ui_category ].refs;
312 // reset touchscreen regions
315 // ensure selection is visible
318 int index = ui_selected_index();
319 int topleft = col_max * ui_rows_scrolled_down;
320 int botright = ( col_max * ( ui_rows_scrolled_down + row_max ) - 1 );
322 //pnd_log ( PND_LOG_DEFAULT, "index %u tl %u br %u\n", index, topleft, botright );
324 if ( index < topleft ) {
325 ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
326 } else if ( index > botright ) {
327 ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
330 if ( ui_rows_scrolled_down < 0 ) {
331 ui_rows_scrolled_down = 0;
332 } else if ( ui_rows_scrolled_down > icon_rows ) {
333 ui_rows_scrolled_down = icon_rows;
339 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
342 dest -> w = sdl_realscreen -> w;
343 dest -> h = sdl_realscreen -> h;
344 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
349 if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
352 dest -> w = sdl_realscreen -> w;
353 dest -> h = sdl_realscreen -> h;
354 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
359 if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
360 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
361 unsigned int tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
362 unsigned int tab_selheight = pnd_conf_get_as_int ( g_conf, "tabs.tab_selheight" );
363 unsigned int tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
364 unsigned int tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
365 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
366 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
367 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
368 unsigned int maxtab = ( screen_width / tab_width ) < g_categorycount ? ( screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift;
369 unsigned int maxtabspot = ( screen_width / tab_width );
371 // draw tabs with categories
372 for ( col = ui_catshift;
378 if ( col == ui_category ) {
379 s = g_imagecache [ IMG_TAB_SEL ].i;
381 s = g_imagecache [ IMG_TAB_UNSEL ].i;
388 if ( col == ui_category ) {
389 src.h = tab_selheight;
393 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
394 dest -> y = tab_offset_y;
395 //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
396 SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
399 ui_register_tab ( col, dest -> x, dest -> y, tab_width, tab_height );
404 if ( col == ui_category ) {
405 // no line for selected tab
407 if ( col - ui_catshift == 0 ) {
408 s = g_imagecache [ IMG_TAB_LINEL ].i;
409 } else if ( col - ui_catshift == maxtabspot - 1 ) {
410 s = g_imagecache [ IMG_TAB_LINER ].i;
412 s = g_imagecache [ IMG_TAB_LINE ].i;
414 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
415 dest -> y = tab_offset_y + tab_height;
416 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
422 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
423 rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ].catname, tmpfontcolor );
426 src.w = rtext -> w < text_width ? rtext -> w : text_width;
428 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
429 dest -> y = tab_offset_y + text_offset_y;
430 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
431 SDL_FreeSurface ( rtext );
436 // draw tab lines under where tabs would be if we had categories
437 for ( /* foo */; col < maxtabspot; col++ ) {
440 if ( col - ui_catshift == 0 ) {
441 s = g_imagecache [ IMG_TAB_LINEL ].i;
442 } else if ( col - ui_catshift == maxtabspot - 1 ) {
443 s = g_imagecache [ IMG_TAB_LINER ].i;
445 s = g_imagecache [ IMG_TAB_LINE ].i;
447 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
448 dest -> y = tab_offset_y + tab_height;
449 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
456 // scroll bars and arrows
458 unsigned char show_bar = 0;
461 if ( ui_rows_scrolled_down && g_imagecache [ IMG_ARROW_UP ].i ) {
462 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
463 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
464 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
471 if ( ui_rows_scrolled_down + row_max < icon_rows && g_imagecache [ IMG_ARROW_DOWN ].i ) {
472 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
473 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
474 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
481 // show scrollbar as well
484 src.w = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_w", 10 );
485 src.h = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_h", 100 );
486 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
487 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
488 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
494 // render detail pane bg
495 if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
497 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
498 src.x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
499 src.y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
500 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
501 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
502 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
503 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
504 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
508 // render detail pane
509 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
510 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
511 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
512 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
516 } // detailpane frame/bg
518 // anything to render?
519 if ( g_categories [ ui_category ].refs ) {
521 appiter = g_categories [ ui_category ].refs;
525 // until we run out of apps, or run out of space
526 while ( appiter != NULL ) {
528 for ( col = 0; col < col_max && appiter != NULL; col++ ) {
530 // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
531 if ( row >= ui_rows_scrolled_down ) {
533 // selected? show hilights
534 if ( appiter == ui_selected ) {
536 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x;
537 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y;
538 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, NULL /* all */, sdl_realscreen, dest );
541 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
542 dest -> y = grid_offset_y + ( displayrow * cell_height ) + pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
543 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
548 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
549 SDL_Surface *iconsurface;
551 iconsurface = ic -> i;
553 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
554 iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
557 //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
563 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + (( icon_max_width - iconsurface -> w ) / 2);
564 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + (( icon_max_height - iconsurface -> h ) / 2);
566 SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
569 ui_register_app ( appiter, dest -> x, dest -> y, src.w, src.h );
576 if ( appiter -> ref -> title_en ) {
578 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
579 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, tmpfontcolor );
582 src.w = text_width < rtext -> w ? text_width : rtext -> w;
584 if ( rtext -> w > text_width ) {
585 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
587 dest -> x = grid_offset_x + ( col * cell_width ) + text_offset_x - ( rtext -> w / 2 );
589 dest -> y = grid_offset_y + ( displayrow * cell_height ) + text_offset_y;
590 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
591 SDL_FreeSurface ( rtext );
595 } // display now? or scrolled away..
598 appiter = appiter -> next;
600 } // for column 1...X
602 if ( row >= ui_rows_scrolled_down ) {
608 // are we done displaying rows?
609 if ( displayrow >= row_max ) {
616 // no apps to render?
617 pnd_log ( pndn_rem, "No applications to render?\n" );
623 unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
624 unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
625 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "detailtext.cell_width" );
627 unsigned int desty = cell_offset_y;
632 if ( ui_selected -> ref -> title_en ) {
634 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
635 rtext = TTF_RenderText_Blended ( g_detailtext_font, ui_selected -> ref -> title_en, tmpfontcolor );
638 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
640 dest -> x = cell_offset_x;
642 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
643 SDL_FreeSurface ( rtext );
649 if ( ui_selected -> ref -> main_category ) {
651 sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
654 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
655 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
658 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
660 dest -> x = cell_offset_x;
662 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
663 SDL_FreeSurface ( rtext );
669 if ( ui_selected -> ref -> clockspeed ) {
671 sprintf ( buffer, "CPU Clock: %s", ui_selected -> ref -> clockspeed );
674 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
675 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
678 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
680 dest -> x = cell_offset_x;
682 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
683 SDL_FreeSurface ( rtext );
688 // show sub-app# on right side of cpu clock?
689 //if ( ui_selected -> ref -> subapp_number )
691 sprintf ( buffer, "(app#%u)", ui_selected -> ref -> subapp_number );
694 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
695 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
696 dest -> x = cell_offset_x + cell_width - rtext -> w;
697 dest -> y = desty - src.h;
698 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
699 SDL_FreeSurface ( rtext );
704 if ( ui_selected -> ref -> clockspeed && ui_selected -> ref -> info_filename ) {
706 sprintf ( buffer, "Documentation - hit Y" );
709 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
710 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
713 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
715 dest -> x = cell_offset_x;
717 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
718 SDL_FreeSurface ( rtext );
724 mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
725 SDL_Surface *previewpic;
728 previewpic = ic -> i;
730 previewpic = g_imagecache [ IMG_PREVIEW_MISSING ].i;
734 dest -> x = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_x", 50 ) +
735 ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
736 dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
737 SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
748 static int last_battlevel = 0;
749 static unsigned char batterylevel = 0;
752 if ( time ( NULL ) - last_battlevel > 60 ) {
753 batterylevel = pnd_device_get_battery_gauge_perc();
754 last_battlevel = time ( NULL );
757 sprintf ( buffer, "Battery: %u%%", batterylevel );
760 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
761 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
762 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.battery_x", 20 );
763 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.battery_y", 450 );
764 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
765 SDL_FreeSurface ( rtext );
770 if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
771 char *buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
773 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
774 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
775 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
776 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
777 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
778 SDL_FreeSurface ( rtext );
783 if ( pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 ) {
786 time_t t = time ( NULL );
787 struct tm *tm = localtime ( &t );
788 strftime ( buffer, 50, "%a %H:%M %F", tm );
791 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
792 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
793 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.clock_x", 700 );
794 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.clock_y", 450 );
795 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
796 SDL_FreeSurface ( rtext );
800 // update all the rects and send it all to sdl
801 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
805 void ui_process_input ( unsigned char block_p ) {
808 unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
809 //static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
811 while ( ! ui_event &&
812 block_p ? SDL_WaitEvent ( &event ) : SDL_PollEvent ( &event ) )
815 switch ( event.type ) {
820 if ( event.user.code == sdl_user_ticker ) {
822 // timer went off, time to load something
823 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
825 // load the preview pics now!
826 pnd_disco_t *iter = ui_selected -> ref;
828 if ( iter -> preview_pic1 ) {
830 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.threaded_preview", 0 ) ) {
831 // load in bg thread, make user experience chuggy
833 g_preview_thread = SDL_CreateThread ( (void*)ui_threaded_defered_preview, iter );
835 if ( ! g_preview_thread ) {
836 pnd_log ( pndn_error, "ERROR: Couldn't create preview thread\n" );
840 // load it now, make user wait
842 if ( ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
843 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
846 pnd_log ( pndn_debug, " Couldn't load preview pic: '%s' -> '%s'\n",
847 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
852 } // got a preview at all?
857 } else if ( event.user.code == sdl_user_finishedpreview ) {
859 // if we just finished the one we happen to be looking at, better redraw now; otherwise, if
860 // we finished another, no big woop
861 if ( ui_selected && event.user.data1 == ui_selected -> ref ) {
865 } else if ( event.user.code == sdl_user_finishedicon ) {
866 // redraw, so we can show the newly loaded icon
873 #if 0 // joystick motion
874 case SDL_JOYAXISMOTION:
876 pnd_log ( PND_LOG_DEFAULT, "joystick axis\n" );
878 if ( event.jaxis.axis == 0 ) {
880 if ( event.jaxis.value < 0 ) {
882 pnd_log ( PND_LOG_DEFAULT, "joystick axis - LEFT\n" );
883 } else if ( event.jaxis.value > 0 ) {
885 pnd_log ( PND_LOG_DEFAULT, "joystick axis - RIGHT\n" );
887 } else if ( event.jaxis.axis == 1 ) {
889 if ( event.jaxis.value < 0 ) {
891 } else if ( event.jaxis.value > 0 ) {
901 #if 0 // joystick buttons
902 case SDL_JOYBUTTONDOWN:
904 pnd_log ( PND_LOG_DEFAULT, "joystick button down %u\n", event.jbutton.button );
906 if ( event.jbutton.button == 0 ) { // B
908 } else if ( event.jbutton.button == 1 ) { // Y
910 } else if ( event.jbutton.button == 2 ) { // X
912 } else if ( event.jbutton.button == 3 ) { // A
915 } else if ( event.jbutton.button == 4 ) { // Select
916 ui_mask |= uisb_select;
917 } else if ( event.jbutton.button == 5 ) { // Start
918 ui_mask |= uisb_start;
920 } else if ( event.jbutton.button == 7 ) { // L
922 } else if ( event.jbutton.button == 8 ) { // R
931 case SDL_JOYBUTTONUP:
933 pnd_log ( PND_LOG_DEFAULT, "joystick button up %u\n", event.jbutton.button );
935 if ( event.jbutton.button == 0 ) { // B
938 } else if ( event.jbutton.button == 1 ) { // Y
940 } else if ( event.jbutton.button == 2 ) { // X
942 } else if ( event.jbutton.button == 3 ) { // A
945 } else if ( event.jbutton.button == 4 ) { // Select
946 ui_mask &= ~uisb_select;
947 } else if ( event.jbutton.button == 5 ) { // Start
948 ui_mask &= ~uisb_start;
950 } else if ( event.jbutton.button == 7 ) { // L
953 } else if ( event.jbutton.button == 8 ) { // R
964 #if 1 // keyboard events
967 //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
969 // SDLK_LALT -> Start
972 if ( event.key.keysym.sym == SDLK_RIGHT ) {
975 } else if ( event.key.keysym.sym == SDLK_LEFT ) {
978 } else if ( event.key.keysym.sym == SDLK_UP ) {
981 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
984 } else if ( event.key.keysym.sym == SDLK_SPACE || event.key.keysym.sym == SDLK_END ) {
987 } else if ( event.key.keysym.sym == SDLK_z || event.key.keysym.sym == SDLK_RSHIFT ) {
990 } else if ( event.key.keysym.sym == SDLK_x || event.key.keysym.sym == SDLK_RCTRL ) {
993 } else if ( event.key.keysym.sym == SDLK_y || event.key.keysym.sym == SDLK_PAGEUP ) {
996 ui_show_info ( pnd_run_script, ui_selected -> ref );
1000 } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
1004 } else if ( event.key.keysym.sym == SDLK_LCTRL /*LALT*/ ) { // select button
1005 char *opts [ 20 ] = {
1006 "Return to Minimenu",
1008 "Rescan for Applications",
1009 "Cache previews to SD now",
1010 "Run xfce4 from Minimenu",
1011 "Run a terminal/console",
1012 "Exit and run xfce4",
1013 "Exit and run pmenu",
1017 int sel = ui_modal_single_menu ( opts, 9, "Minimenu", "Enter to select; other to return." );
1019 char buffer [ 100 ];
1022 } else if ( sel == 1 ) {
1024 sprintf ( buffer, "sudo poweroff" );
1026 } else if ( sel == 2 ) {
1028 pnd_log ( pndn_debug, "Freeing up applications\n" );
1029 applications_free();
1030 pnd_log ( pndn_debug, "Rescanning applications\n" );
1031 applications_scan();
1034 ui_rows_scrolled_down = 0;
1035 } else if ( sel == 3 ) {
1036 // cache preview to SD now
1037 extern pnd_box_handle g_active_apps;
1038 pnd_box_handle h = g_active_apps;
1040 unsigned char maxwidth, maxheight;
1041 maxwidth = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 );
1042 maxheight = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 );
1044 pnd_disco_t *iter = pnd_box_get_head ( h );
1049 if ( ! cache_preview ( iter, maxwidth, maxheight ) ) {
1050 pnd_log ( pndn_debug, "Force cache: Couldn't load preview pic: '%s' -> '%s'\n",
1051 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1055 iter = pnd_box_get_next ( iter );
1058 } else if ( sel == 4 ) {
1060 char buffer [ PATH_MAX ];
1061 sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/bin/startxfce4" );
1062 emit_and_quit ( buffer );
1063 } else if ( sel == 5 ) {
1066 argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
1070 ui_forkexec ( argv );
1073 } else if ( sel == 6 ) {
1075 sprintf ( buffer, "echo startxfce4 > /tmp/gui.load" );
1077 //sprintf ( buffer, "sudo poweroff" );
1078 //system ( buffer );
1080 } else if ( sel == 7 ) {
1082 sprintf ( buffer, "echo pmenu > /tmp/gui.load" );
1084 //sprintf ( buffer, "sudo poweroff" );
1085 //system ( buffer );
1087 } else if ( sel == 8 ) {
1088 emit_and_quit ( MM_QUIT );
1089 } else if ( sel == 9 ) {
1097 if ( event.key.keysym.sym == SDLK_q ) {
1098 emit_and_quit ( MM_QUIT );
1104 #if 1 // mouse / touchscreen
1106 case SDL_MOUSEBUTTONDOWN:
1107 if ( event.button.button == SDL_BUTTON_LEFT ) {
1108 cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
1114 case SDL_MOUSEBUTTONUP:
1115 if ( event.button.button == SDL_BUTTON_LEFT ) {
1116 ui_touch_act ( event.button.x, event.button.y );
1129 } // switch event type
1136 void ui_push_left ( unsigned char forcecoil ) {
1138 if ( ! ui_selected ) {
1139 ui_push_right ( 0 );
1143 // what column we in?
1144 unsigned int col = ui_determine_screen_col ( ui_selected );
1146 // are we alreadt at first item?
1147 if ( forcecoil == 0 &&
1148 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1151 unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1153 ui_push_right ( 0 );
1157 } else if ( g_categories [ ui_category ].refs == ui_selected ) {
1158 // can't go any more left, we're at the head
1161 // figure out the previous item; yay for singly linked list :/
1162 mm_appref_t *i = g_categories [ ui_category ].refs;
1164 if ( i -> next == ui_selected ) {
1172 ui_set_selected ( ui_selected );
1177 void ui_push_right ( unsigned char forcecoil ) {
1179 if ( ui_selected ) {
1181 // what column we in?
1182 unsigned int col = ui_determine_screen_col ( ui_selected );
1185 if ( forcecoil == 0 &&
1186 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1187 col == pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1 )
1190 unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1197 // just go to the next
1199 if ( ui_selected -> next ) {
1200 ui_selected = ui_selected -> next;
1206 ui_selected = g_categories [ ui_category ].refs;
1209 ui_set_selected ( ui_selected );
1214 void ui_push_up ( void ) {
1215 unsigned char col_max = pnd_conf_get_as_int ( g_conf, MMENU_DISP_COLMAX );
1217 if ( ! ui_selected ) {
1222 unsigned int row = ui_determine_row ( ui_selected );
1225 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 1 ) == 0 )
1227 // wrap around instead
1229 unsigned int col = ui_determine_screen_col ( ui_selected );
1232 ui_selected = g_categories [ ui_category ].refs;
1233 while ( ui_selected -> next ) {
1234 ui_selected = ui_selected -> next;
1237 // try to move to same column
1238 unsigned int newcol = ui_determine_screen_col ( ui_selected );
1239 if ( newcol > col ) {
1247 // scroll down to show it
1248 int r = ui_determine_row ( ui_selected ) - 1;
1249 if ( r - pnd_conf_get_as_int ( g_conf, MMENU_DISP_ROWMAX ) > 0 ) {
1250 ui_rows_scrolled_down = (unsigned int) r;
1254 // stop at top/bottom
1266 void ui_push_down ( void ) {
1267 unsigned char col_max = pnd_conf_get_as_int ( g_conf, MMENU_DISP_COLMAX );
1269 if ( ui_selected ) {
1272 unsigned int row = ui_determine_row ( ui_selected );
1275 unsigned int icon_rows = g_categories [ ui_category ].refcount / col_max;
1276 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
1281 if ( row == ( icon_rows - 1 ) &&
1282 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 1 ) == 0 )
1285 unsigned char col = ui_determine_screen_col ( ui_selected );
1287 ui_selected = g_categories [ ui_category ].refs;
1290 ui_selected = ui_selected -> next;
1294 ui_rows_scrolled_down = 0;
1299 ui_push_right ( 1 );
1306 ui_push_right ( 0 );
1312 void ui_push_exec ( void ) {
1314 if ( ui_selected ) {
1315 char buffer [ PATH_MAX ];
1316 sprintf ( buffer, "%s/%s", ui_selected -> ref -> object_path, ui_selected -> ref -> object_filename );
1317 pnd_apps_exec ( pnd_run_script,
1319 ui_selected -> ref -> unique_id,
1320 ui_selected -> ref -> exec,
1321 ui_selected -> ref -> startdir,
1322 ui_selected -> ref -> execargs,
1323 atoi ( ui_selected -> ref -> clockspeed ),
1324 PND_EXEC_OPTION_NORUN );
1325 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1326 emit_and_quit ( buffer );
1332 void ui_push_ltrigger ( void ) {
1333 unsigned char oldcat = ui_category;
1335 if ( ui_category > 0 ) {
1338 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1339 ui_category = g_categorycount - 1;
1343 if ( oldcat != ui_category ) {
1345 ui_set_selected ( ui_selected );
1348 // make tab visible?
1349 if ( ui_catshift > 0 && ui_category == ui_catshift - 1 ) {
1354 ui_rows_scrolled_down = 0;
1359 void ui_push_rtrigger ( void ) {
1360 unsigned char oldcat = ui_category;
1362 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
1363 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1365 if ( ui_category < ( g_categorycount - 1 ) ) {
1368 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1373 if ( oldcat != ui_category ) {
1375 ui_set_selected ( ui_selected );
1378 // make tab visible?
1379 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
1384 ui_rows_scrolled_down = 0;
1389 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ) {
1390 double scale = 1000000.0;
1391 double scalex = 1000000.0;
1392 double scaley = 1000000.0;
1393 SDL_Surface *scaled;
1395 scalex = (double)maxwidth / (double)s -> w;
1397 if ( maxheight == -1 ) {
1400 scaley = (double)maxheight / (double)s -> h;
1402 if ( scaley < scalex ) {
1410 scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
1411 SDL_FreeSurface ( s );
1417 void ui_loadscreen ( void ) {
1421 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1422 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1423 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1424 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1427 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1431 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1432 rtext = TTF_RenderText_Blended ( g_big_font, "Setting up menu...", tmpfontcolor );
1435 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1436 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1437 SDL_FreeSurface ( rtext );
1442 void ui_discoverscreen ( unsigned char clearscreen ) {
1446 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1447 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1448 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1449 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1452 if ( clearscreen ) {
1453 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1455 // render background
1456 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1459 dest.w = sdl_realscreen -> w;
1460 dest.h = sdl_realscreen -> h;
1461 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1462 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1469 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1470 rtext = TTF_RenderText_Blended ( g_big_font, "Looking for applications...", tmpfontcolor );
1471 if ( clearscreen ) {
1478 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1479 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1480 SDL_FreeSurface ( rtext );
1483 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1484 dest.x = rtext -> w + 30;
1486 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, &dest );
1487 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1493 void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
1495 SDL_Rect rects [ 4 ];
1496 SDL_Rect *dest = rects;
1498 bzero ( dest, sizeof(SDL_Rect)* 4 );
1500 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1501 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1502 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1503 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1505 static unsigned int stepx = 0;
1508 if ( clearscreen ) {
1509 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1511 // render background
1512 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1515 dest -> w = sdl_realscreen -> w;
1516 dest -> h = sdl_realscreen -> h;
1517 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1523 // render background
1524 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1527 src.w = sdl_realscreen -> w;
1531 dest -> w = sdl_realscreen -> w;
1532 dest -> h = sdl_realscreen -> h;
1533 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
1541 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1542 rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
1545 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1546 SDL_FreeSurface ( rtext );
1550 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1551 dest -> x = rtext -> w + 30 + stepx;
1553 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, dest );
1559 rtext = TTF_RenderText_Blended ( g_tab_font, filename, tmpfontcolor );
1562 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1563 SDL_FreeSurface ( rtext );
1570 if ( stepx > 350 ) {
1574 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1579 int ui_selected_index ( void ) {
1581 if ( ! ui_selected ) {
1582 return ( -1 ); // no index
1585 mm_appref_t *r = g_categories [ ui_category ].refs;
1588 if ( r == ui_selected ) {
1598 static mm_appref_t *timer_ref = NULL;
1599 void ui_set_selected ( mm_appref_t *r ) {
1601 if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1602 return; // no desire to defer anything
1607 SDL_SetTimer ( 0, NULL );
1612 SDL_SetTimer ( pnd_conf_get_as_int_d ( g_conf, "previewpic.defer_timer_ms", 1000 ), ui_callback_f );
1618 unsigned int ui_callback_f ( unsigned int t ) {
1620 if ( ui_selected != timer_ref ) {
1621 return ( 0 ); // user has moved it, who cares
1625 bzero ( &e, sizeof(SDL_Event) );
1626 e.type = SDL_USEREVENT;
1627 e.user.code = sdl_user_ticker;
1628 SDL_PushEvent ( &e );
1633 int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer ) {
1634 SDL_Rect rects [ 40 ];
1635 SDL_Rect *dest = rects;
1639 bzero ( rects, sizeof(SDL_Rect) * 40 );
1641 unsigned int sel = 0;
1643 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1644 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1645 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1646 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1648 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1650 SDL_Color selfontcolor = { 0/*font_rgba_r*/, font_rgba_g, font_rgba_b, font_rgba_a };
1658 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1659 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1660 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
1661 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
1662 SDL_FillRect( sdl_realscreen, dest, 0 );
1664 // show dialog background
1665 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
1666 src.x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1667 src.y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1668 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
1669 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
1670 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1671 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1672 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1673 // repeat for darken?
1674 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1675 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1676 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1680 // show dialog frame
1681 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
1682 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1683 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1684 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
1685 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1691 rtext = TTF_RenderText_Blended ( g_tab_font, title, tmpfontcolor );
1692 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1693 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
1694 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1695 SDL_FreeSurface ( rtext );
1701 rtext = TTF_RenderText_Blended ( g_tab_font, footer, tmpfontcolor );
1702 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1703 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
1704 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
1706 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1707 SDL_FreeSurface ( rtext );
1712 for ( i = 0; i < argc; i++ ) {
1716 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
1718 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], tmpfontcolor );
1720 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1721 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 ) );
1722 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1723 SDL_FreeSurface ( rtext );
1728 // update all the rects and send it all to sdl
1729 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1733 while ( SDL_WaitEvent ( &event ) ) {
1735 switch ( event.type ) {
1739 if ( event.key.keysym.sym == SDLK_UP ) {
1743 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1744 if ( sel < argc - 1 ) {
1748 } else if ( event.key.keysym.sym == SDLK_RETURN ) {
1751 } else if ( event.key.keysym.sym == SDLK_q ) {
1755 return ( -1 ); // nada
1770 unsigned char ui_determine_row ( mm_appref_t *a ) {
1771 unsigned int row = 0;
1773 mm_appref_t *i = g_categories [ ui_category ].refs;
1778 row /= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
1783 unsigned char ui_determine_screen_row ( mm_appref_t *a ) {
1784 return ( ui_determine_row ( a ) % pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 5 ) );
1787 unsigned char ui_determine_screen_col ( mm_appref_t *a ) {
1788 unsigned int col = 0;
1790 mm_appref_t *i = g_categories [ ui_category ].refs;
1795 col %= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
1800 unsigned char ui_show_info ( char *pndrun, pnd_disco_t *p ) {
1801 char *viewer, *searchpath;
1802 pnd_conf_handle desktoph;
1805 searchpath = pnd_conf_query_searchpath();
1807 desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
1813 viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
1816 return ( 0 ); // no way to view the file
1820 if ( ! p -> unique_id ) {
1824 if ( ! p -> info_filename ) {
1828 if ( ! p -> info_name ) {
1839 if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) {
1840 snprintf ( pargs, 1001, "%s %s",
1841 pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
1846 char pndfile [ 1024 ];
1847 if ( p -> object_type == pnd_object_type_directory ) {
1848 // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
1849 strncpy ( pndfile, p -> object_path, 1000 );
1850 } else if ( p -> object_type == pnd_object_type_pnd ) {
1851 // pnd_run.sh wants the full path and filename for the .pnd file
1852 snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
1855 if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs,
1856 p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) )
1861 pnd_log ( pndn_debug, "Info Exec=%s\n", pnd_apps_exec_runline() );
1865 if ( ( x = fork() ) < 0 ) {
1866 pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
1871 execl ( "/bin/sh", "/bin/sh", "-c", pnd_apps_exec_runline(), (char*)NULL );
1872 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", pnd_apps_exec_runline() );
1884 #define MAXTOUCH 100
1885 ui_touch_t ui_touchrects [ MAXTOUCH ];
1886 unsigned char ui_touchrect_count = 0;
1888 void ui_register_reset ( void ) {
1889 bzero ( ui_touchrects, sizeof(ui_touch_t)*MAXTOUCH );
1890 ui_touchrect_count = 0;
1894 void ui_register_tab ( unsigned char catnum, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
1896 if ( ui_touchrect_count == MAXTOUCH ) {
1900 ui_touchrects [ ui_touchrect_count ].r.x = x;
1901 ui_touchrects [ ui_touchrect_count ].r.y = y;
1902 ui_touchrects [ ui_touchrect_count ].r.w = w;
1903 ui_touchrects [ ui_touchrect_count ].r.h = h;
1904 ui_touchrects [ ui_touchrect_count ].catnum = catnum;
1905 ui_touchrect_count++;
1910 void ui_register_app ( mm_appref_t *app, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
1912 if ( ui_touchrect_count == MAXTOUCH ) {
1916 ui_touchrects [ ui_touchrect_count ].r.x = x;
1917 ui_touchrects [ ui_touchrect_count ].r.y = y;
1918 ui_touchrects [ ui_touchrect_count ].r.w = w;
1919 ui_touchrects [ ui_touchrect_count ].r.h = h;
1920 ui_touchrects [ ui_touchrect_count ].ref = app;
1921 ui_touchrect_count++;
1926 void ui_touch_act ( unsigned int x, unsigned int y ) {
1931 for ( i = 0; i < ui_touchrect_count; i++ ) {
1932 t = &(ui_touchrects [ i ]);
1934 if ( x >= t -> r.x &&
1935 x <= t -> r.x + t -> r.w &&
1937 y <= t -> r.y + t -> r.h
1942 ui_selected = t -> ref;
1945 ui_category = t -> catnum;
1956 unsigned char ui_forkexec ( char *argv[] ) {
1957 char *fooby = argv[0];
1960 if ( ( x = fork() ) < 0 ) {
1961 pnd_log ( pndn_error, "ERROR: Couldn't fork() for '%s'\n", fooby );
1965 if ( x == 0 ) { // child
1966 execv ( fooby, argv );
1967 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", fooby );
1975 unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ) {
1977 if ( ! cache_preview ( p, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
1978 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
1981 pnd_log ( pndn_debug, "THREAD: Couldn't load preview pic: '%s' -> '%s'\n",
1982 IFNULL(p->title_en,"No Name"), p -> preview_pic1 );
1985 // trigger that we completed
1987 bzero ( &e, sizeof(SDL_Event) );
1988 e.type = SDL_USEREVENT;
1989 e.user.code = sdl_user_finishedpreview;
1991 SDL_PushEvent ( &e );
1996 SDL_Thread *g_icon_thread = NULL;
1997 void ui_post_scan ( void ) {
1999 // if deferred icon load, kick off the thread now
2000 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 1 ) {
2002 g_icon_thread = SDL_CreateThread ( (void*)ui_threaded_defered_icon, NULL );
2004 if ( ! g_icon_thread ) {
2005 pnd_log ( pndn_error, "ERROR: Couldn't create icon thread\n" );
2008 } // deferred icon load
2013 unsigned char ui_threaded_defered_icon ( void *p ) {
2014 extern pnd_box_handle g_active_apps;
2015 pnd_box_handle h = g_active_apps;
2017 unsigned char maxwidth, maxheight;
2018 maxwidth = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_ICON_MAX_WIDTH, 50 );
2019 maxheight = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_ICON_MAX_HEIGHT, 50 );
2021 pnd_disco_t *iter = pnd_box_get_head ( h );
2026 if ( iter -> pnd_icon_pos &&
2027 ! cache_icon ( iter, maxwidth, maxheight ) )
2029 pnd_log ( pndn_warning, " Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2032 // trigger that we completed
2034 bzero ( &e, sizeof(SDL_Event) );
2035 e.type = SDL_USEREVENT;
2036 e.user.code = sdl_user_finishedicon;
2037 SDL_PushEvent ( &e );
2039 //pnd_log ( pndn_warning, " Finished deferred load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2040 usleep ( pnd_conf_get_as_int_d ( g_conf, "minimenu.defer_icon_us", 50000 ) );
2045 iter = pnd_box_get_next ( iter );
2051 void ui_show_hourglass ( unsigned char updaterect ) {
2054 SDL_Surface *s = g_imagecache [ IMG_HOURGLASS ].i;
2056 dest.x = ( 800 - s -> w ) / 2;
2057 dest.y = ( 480 - s -> h ) / 2;
2059 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, &dest );
2062 SDL_UpdateRects ( sdl_realscreen, 1, &dest );