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", },
199 unsigned char ui_imagecache ( char *basepath ) {
201 char fullpath [ PATH_MAX ];
205 for ( i = 0; i < IMG_MAX; i++ ) {
207 if ( g_imagecache [ i ].id != i ) {
208 pnd_log ( pndn_error, "ERROR: Internal table mismatch during caching [%u]\n", i );
212 char *filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].confname );
215 pnd_log ( pndn_error, "ERROR: Missing filename in conf for key: %s\n", g_imagecache [ i ].confname );
219 sprintf ( fullpath, "%s/%s", basepath, filename );
221 if ( ! ( g_imagecache [ i ].i = IMG_Load ( fullpath ) ) ) {
222 pnd_log ( pndn_error, "ERROR: Couldn't load static cache image: %s\n", fullpath );
229 //g_imagecache [ IMG_SELECTED_ALPHAMASK ].i = SDL_CreateRGBSurface ( SDL_SWSURFACE, 60, 60, 32, 0xFF0000, 0x00FF00, 0xFF, 0xFF000000 );
230 //boxRGBA ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, 0, 0, 60, 60, 100, 100, 100, 250 );
236 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 );
237 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 );
238 // scale text hilight
239 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 );
240 // scale preview no-pic
241 g_imagecache [ IMG_PREVIEW_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_PREVIEW_MISSING ].i,
242 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ),
243 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 50 ) );
245 // set alpha on detail panel
246 SDL_SetAlpha ( g_imagecache [ IMG_DETAIL_BG ].i, SDL_SRCALPHA, pnd_conf_get_as_int_d ( g_conf, "display.detail_bg_alpha", 50 ) );
251 void ui_render ( unsigned int render_mask ) {
254 // divide width: 550 / 250
255 // divide left side: 5 columns == 110px width
256 // 20px buffer either side == 70px wide icon + 20 + 20?
258 unsigned int icon_rows;
261 SDL_Rect rects [ MAXRECTS ], src;
262 SDL_Rect *dest = rects;
263 bzero ( dest, sizeof(SDL_Rect)*MAXRECTS );
265 unsigned int row, displayrow, col;
266 mm_appref_t *appiter;
268 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
270 unsigned char row_max = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_ROWMAX, 4 );
271 unsigned char col_max = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_COLMAX, 5 );
273 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
274 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
275 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
276 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
278 unsigned int grid_offset_x = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_x" );
279 unsigned int grid_offset_y = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_y" );
281 unsigned int icon_offset_x = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_x" );
282 unsigned int icon_offset_y = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_y" );
283 unsigned int icon_max_width = pnd_conf_get_as_int ( g_conf, "grid.icon_max_width" );
284 unsigned int icon_max_height = pnd_conf_get_as_int ( g_conf, "grid.icon_max_height" );
286 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
287 unsigned int text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
288 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "grid.text_offset_x" );
289 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_offset_y" );
291 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "grid.cell_width" );
292 unsigned int cell_height = pnd_conf_get_as_int ( g_conf, "grid.cell_height" );
294 // how many total rows do we need?
295 icon_rows = g_categories [ ui_category ].refcount / col_max;
296 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
300 // if no selected app yet, select the first one
302 if ( ! ui_selected ) {
303 ui_selected = g_categories [ ui_category ].refs;
307 // reset touchscreen regions
310 // ensure selection is visible
313 int index = ui_selected_index();
314 int topleft = col_max * ui_rows_scrolled_down;
315 int botright = ( col_max * ( ui_rows_scrolled_down + row_max ) - 1 );
317 //pnd_log ( PND_LOG_DEFAULT, "index %u tl %u br %u\n", index, topleft, botright );
319 if ( index < topleft ) {
320 ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
321 } else if ( index > botright ) {
322 ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
325 if ( ui_rows_scrolled_down < 0 ) {
326 ui_rows_scrolled_down = 0;
327 } else if ( ui_rows_scrolled_down > icon_rows ) {
328 ui_rows_scrolled_down = icon_rows;
334 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
337 dest -> w = sdl_realscreen -> w;
338 dest -> h = sdl_realscreen -> h;
339 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
344 if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
347 dest -> w = sdl_realscreen -> w;
348 dest -> h = sdl_realscreen -> h;
349 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
354 if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
355 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
356 unsigned int tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
357 unsigned int tab_selheight = pnd_conf_get_as_int ( g_conf, "tabs.tab_selheight" );
358 unsigned int tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
359 unsigned int tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
360 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
361 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
362 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
363 unsigned int maxtab = ( screen_width / tab_width ) < g_categorycount ? ( screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift;
364 unsigned int maxtabspot = ( screen_width / tab_width );
366 // draw tabs with categories
367 for ( col = ui_catshift;
373 if ( col == ui_category ) {
374 s = g_imagecache [ IMG_TAB_SEL ].i;
376 s = g_imagecache [ IMG_TAB_UNSEL ].i;
383 if ( col == ui_category ) {
384 src.h = tab_selheight;
388 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
389 dest -> y = tab_offset_y;
390 //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
391 SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
394 ui_register_tab ( col, dest -> x, dest -> y, tab_width, tab_height );
399 if ( col == ui_category ) {
400 // no line for selected tab
402 if ( col - ui_catshift == 0 ) {
403 s = g_imagecache [ IMG_TAB_LINEL ].i;
404 } else if ( col - ui_catshift == maxtabspot - 1 ) {
405 s = g_imagecache [ IMG_TAB_LINER ].i;
407 s = g_imagecache [ IMG_TAB_LINE ].i;
409 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
410 dest -> y = tab_offset_y + tab_height;
411 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
417 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
418 rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ].catname, tmpfontcolor );
421 src.w = rtext -> w < text_width ? rtext -> w : text_width;
423 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
424 dest -> y = tab_offset_y + text_offset_y;
425 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
426 SDL_FreeSurface ( rtext );
431 // draw tab lines under where tabs would be if we had categories
432 for ( /* foo */; col < maxtabspot; col++ ) {
435 if ( col - ui_catshift == 0 ) {
436 s = g_imagecache [ IMG_TAB_LINEL ].i;
437 } else if ( col - ui_catshift == maxtabspot - 1 ) {
438 s = g_imagecache [ IMG_TAB_LINER ].i;
440 s = g_imagecache [ IMG_TAB_LINE ].i;
442 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
443 dest -> y = tab_offset_y + tab_height;
444 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
451 // scroll bars and arrows
453 unsigned char show_bar = 0;
456 if ( ui_rows_scrolled_down && g_imagecache [ IMG_ARROW_UP ].i ) {
457 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
458 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
459 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
466 if ( ui_rows_scrolled_down + row_max < icon_rows && g_imagecache [ IMG_ARROW_DOWN ].i ) {
467 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
468 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
469 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
476 // show scrollbar as well
479 src.w = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_w", 10 );
480 src.h = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_h", 100 );
481 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
482 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
483 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
489 // render detail pane bg
490 if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
492 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
493 src.x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
494 src.y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
495 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
496 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
497 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
498 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
499 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
503 // render detail pane
504 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
505 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
506 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
507 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
511 } // detailpane frame/bg
513 // anything to render?
514 if ( g_categories [ ui_category ].refs ) {
516 appiter = g_categories [ ui_category ].refs;
520 // until we run out of apps, or run out of space
521 while ( appiter != NULL ) {
523 for ( col = 0; col < col_max && appiter != NULL; col++ ) {
525 // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
526 if ( row >= ui_rows_scrolled_down ) {
528 // selected? show hilights
529 if ( appiter == ui_selected ) {
531 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x;
532 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y;
533 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, NULL /* all */, sdl_realscreen, dest );
536 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
537 dest -> y = grid_offset_y + ( displayrow * cell_height ) + pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
538 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
543 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
544 SDL_Surface *iconsurface;
546 iconsurface = ic -> i;
548 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
549 iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
552 //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
558 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + (( icon_max_width - iconsurface -> w ) / 2);
559 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + (( icon_max_height - iconsurface -> h ) / 2);
561 SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
564 ui_register_app ( appiter, dest -> x, dest -> y, src.w, src.h );
571 if ( appiter -> ref -> title_en ) {
573 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
574 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, tmpfontcolor );
577 src.w = text_width < rtext -> w ? text_width : rtext -> w;
579 if ( rtext -> w > text_width ) {
580 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
582 dest -> x = grid_offset_x + ( col * cell_width ) + text_offset_x - ( rtext -> w / 2 );
584 dest -> y = grid_offset_y + ( displayrow * cell_height ) + text_offset_y;
585 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
586 SDL_FreeSurface ( rtext );
590 } // display now? or scrolled away..
593 appiter = appiter -> next;
595 } // for column 1...X
597 if ( row >= ui_rows_scrolled_down ) {
603 // are we done displaying rows?
604 if ( displayrow >= row_max ) {
611 // no apps to render?
612 pnd_log ( pndn_rem, "No applications to render?\n" );
618 unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
619 unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
620 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "detailtext.cell_width" );
622 unsigned int desty = cell_offset_y;
627 if ( ui_selected -> ref -> title_en ) {
629 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
630 rtext = TTF_RenderText_Blended ( g_detailtext_font, ui_selected -> ref -> title_en, tmpfontcolor );
633 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
635 dest -> x = cell_offset_x;
637 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
638 SDL_FreeSurface ( rtext );
644 if ( ui_selected -> ref -> main_category ) {
646 sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
649 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
650 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
653 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
655 dest -> x = cell_offset_x;
657 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
658 SDL_FreeSurface ( rtext );
664 if ( ui_selected -> ref -> clockspeed ) {
666 sprintf ( buffer, "CPU Clock: %s", ui_selected -> ref -> clockspeed );
669 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
670 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
673 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
675 dest -> x = cell_offset_x;
677 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
678 SDL_FreeSurface ( rtext );
683 // show sub-app# on right side of cpu clock?
684 //if ( ui_selected -> ref -> subapp_number )
686 sprintf ( buffer, "(app#%u)", ui_selected -> ref -> subapp_number );
689 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
690 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
691 dest -> x = cell_offset_x + cell_width - rtext -> w;
692 dest -> y = desty - src.h;
693 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
694 SDL_FreeSurface ( rtext );
699 if ( ui_selected -> ref -> clockspeed && ui_selected -> ref -> info_filename ) {
701 sprintf ( buffer, "Documentation - hit Y" );
704 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
705 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
708 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
710 dest -> x = cell_offset_x;
712 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
713 SDL_FreeSurface ( rtext );
719 mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
720 SDL_Surface *previewpic;
723 previewpic = ic -> i;
725 previewpic = g_imagecache [ IMG_PREVIEW_MISSING ].i;
729 dest -> x = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_x", 50 ) +
730 ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
731 dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
732 SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
743 static int last_battlevel = 0;
744 static unsigned char batterylevel = 0;
747 if ( time ( NULL ) - last_battlevel > 60 ) {
748 batterylevel = pnd_device_get_battery_gauge_perc();
749 last_battlevel = time ( NULL );
752 sprintf ( buffer, "Battery: %u%%", batterylevel );
755 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
756 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
757 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.battery_x", 20 );
758 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.battery_y", 450 );
759 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
760 SDL_FreeSurface ( rtext );
765 if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
766 char *buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
768 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
769 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
770 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
771 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
772 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
773 SDL_FreeSurface ( rtext );
778 if ( pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 ) {
781 time_t t = time ( NULL );
782 struct tm *tm = localtime ( &t );
783 strftime ( buffer, 50, "%a %H:%M %F", tm );
786 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
787 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
788 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.clock_x", 700 );
789 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.clock_y", 450 );
790 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
791 SDL_FreeSurface ( rtext );
795 // update all the rects and send it all to sdl
796 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
800 void ui_process_input ( unsigned char block_p ) {
803 unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
804 //static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
806 while ( ! ui_event &&
807 block_p ? SDL_WaitEvent ( &event ) : SDL_PollEvent ( &event ) )
810 switch ( event.type ) {
815 if ( event.user.code == sdl_user_ticker ) {
817 // timer went off, time to load something
818 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
820 pnd_log ( pndn_debug, "Deferred preview pic load ----------\n" );
822 // load the preview pics now!
823 pnd_disco_t *iter = ui_selected -> ref;
825 if ( iter -> preview_pic1 ) {
827 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.threaded_preview", 0 ) ) {
829 g_preview_thread = SDL_CreateThread ( (void*)ui_threaded_defered_preview, iter );
831 if ( ! g_preview_thread ) {
832 pnd_log ( pndn_error, "ERROR: Couldn't create preview thread\n" );
837 if ( ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
838 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
841 pnd_log ( pndn_debug, " Couldn't load preview pic: '%s' -> '%s'\n",
842 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
847 } // got a preview at all?
849 pnd_log ( pndn_debug, "Deferred preview pic load finish ---\n" );
854 } else if ( event.user.code == sdl_user_finishedpreview ) {
856 // if we just finished the one we happen to be looking at, better redraw now; otherwise, if
857 // we finished another, no big woop
858 if ( ui_selected && event.user.data1 == ui_selected -> ref ) {
862 } else if ( event.user.code == sdl_user_finishedicon ) {
863 // redraw, so we can show the newly loaded icon
870 #if 0 // joystick motion
871 case SDL_JOYAXISMOTION:
873 pnd_log ( PND_LOG_DEFAULT, "joystick axis\n" );
875 if ( event.jaxis.axis == 0 ) {
877 if ( event.jaxis.value < 0 ) {
879 pnd_log ( PND_LOG_DEFAULT, "joystick axis - LEFT\n" );
880 } else if ( event.jaxis.value > 0 ) {
882 pnd_log ( PND_LOG_DEFAULT, "joystick axis - RIGHT\n" );
884 } else if ( event.jaxis.axis == 1 ) {
886 if ( event.jaxis.value < 0 ) {
888 } else if ( event.jaxis.value > 0 ) {
898 #if 0 // joystick buttons
899 case SDL_JOYBUTTONDOWN:
901 pnd_log ( PND_LOG_DEFAULT, "joystick button down %u\n", event.jbutton.button );
903 if ( event.jbutton.button == 0 ) { // B
905 } else if ( event.jbutton.button == 1 ) { // Y
907 } else if ( event.jbutton.button == 2 ) { // X
909 } else if ( event.jbutton.button == 3 ) { // A
912 } else if ( event.jbutton.button == 4 ) { // Select
913 ui_mask |= uisb_select;
914 } else if ( event.jbutton.button == 5 ) { // Start
915 ui_mask |= uisb_start;
917 } else if ( event.jbutton.button == 7 ) { // L
919 } else if ( event.jbutton.button == 8 ) { // R
928 case SDL_JOYBUTTONUP:
930 pnd_log ( PND_LOG_DEFAULT, "joystick button up %u\n", event.jbutton.button );
932 if ( event.jbutton.button == 0 ) { // B
935 } else if ( event.jbutton.button == 1 ) { // Y
937 } else if ( event.jbutton.button == 2 ) { // X
939 } else if ( event.jbutton.button == 3 ) { // A
942 } else if ( event.jbutton.button == 4 ) { // Select
943 ui_mask &= ~uisb_select;
944 } else if ( event.jbutton.button == 5 ) { // Start
945 ui_mask &= ~uisb_start;
947 } else if ( event.jbutton.button == 7 ) { // L
950 } else if ( event.jbutton.button == 8 ) { // R
961 #if 1 // keyboard events
964 //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
966 // SDLK_LALT -> Start
969 if ( event.key.keysym.sym == SDLK_RIGHT ) {
972 } else if ( event.key.keysym.sym == SDLK_LEFT ) {
975 } else if ( event.key.keysym.sym == SDLK_UP ) {
978 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
981 } else if ( event.key.keysym.sym == SDLK_SPACE || event.key.keysym.sym == SDLK_END ) {
984 } else if ( event.key.keysym.sym == SDLK_z || event.key.keysym.sym == SDLK_RSHIFT ) {
987 } else if ( event.key.keysym.sym == SDLK_x || event.key.keysym.sym == SDLK_RCTRL ) {
990 } else if ( event.key.keysym.sym == SDLK_y || event.key.keysym.sym == SDLK_PAGEUP ) {
993 ui_show_info ( pnd_run_script, ui_selected -> ref );
997 } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
1001 } else if ( event.key.keysym.sym == SDLK_LCTRL /*LALT*/ ) { // select button
1002 char *opts [ 20 ] = {
1003 "Return to Minimenu",
1005 "Rescan for Applications",
1006 "Run xfce4 from Minimenu",
1007 "Run a terminal/console",
1008 "Exit and run xfce4",
1009 "Exit and run pmenu",
1013 int sel = ui_modal_single_menu ( opts, 9, "Minimenu", "Enter to select; other to return." );
1015 char buffer [ 100 ];
1018 } else if ( sel == 1 ) {
1020 sprintf ( buffer, "sudo poweroff" );
1022 } else if ( sel == 2 ) {
1024 pnd_log ( pndn_debug, "Freeing up applications\n" );
1025 applications_free();
1026 pnd_log ( pndn_debug, "Rescanning applications\n" );
1027 applications_scan();
1030 ui_rows_scrolled_down = 0;
1031 } else if ( sel == 3 ) {
1033 char buffer [ PATH_MAX ];
1034 sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/bin/startxfce4" );
1035 emit_and_quit ( buffer );
1036 } else if ( sel == 4 ) {
1039 argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
1043 ui_forkexec ( argv );
1046 } else if ( sel == 5 ) {
1048 sprintf ( buffer, "echo startxfce4 > /tmp/gui.load" );
1050 //sprintf ( buffer, "sudo poweroff" );
1051 //system ( buffer );
1053 } else if ( sel == 6 ) {
1055 sprintf ( buffer, "echo pmenu > /tmp/gui.load" );
1057 //sprintf ( buffer, "sudo poweroff" );
1058 //system ( buffer );
1060 } else if ( sel == 7 ) {
1061 emit_and_quit ( MM_QUIT );
1062 } else if ( sel == 8 ) {
1070 if ( event.key.keysym.sym == SDLK_q ) {
1071 emit_and_quit ( MM_QUIT );
1077 #if 1 // mouse / touchscreen
1079 case SDL_MOUSEBUTTONDOWN:
1080 if ( event.button.button == SDL_BUTTON_LEFT ) {
1081 cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
1087 case SDL_MOUSEBUTTONUP:
1088 if ( event.button.button == SDL_BUTTON_LEFT ) {
1089 ui_touch_act ( event.button.x, event.button.y );
1102 } // switch event type
1109 void ui_push_left ( unsigned char forcecoil ) {
1111 if ( ! ui_selected ) {
1112 ui_push_right ( 0 );
1116 // what column we in?
1117 unsigned int col = ui_determine_screen_col ( ui_selected );
1119 // are we alreadt at first item?
1120 if ( forcecoil == 0 &&
1121 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1124 unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1126 ui_push_right ( 0 );
1130 } else if ( g_categories [ ui_category ].refs == ui_selected ) {
1131 // can't go any more left, we're at the head
1134 // figure out the previous item; yay for singly linked list :/
1135 mm_appref_t *i = g_categories [ ui_category ].refs;
1137 if ( i -> next == ui_selected ) {
1145 ui_set_selected ( ui_selected );
1150 void ui_push_right ( unsigned char forcecoil ) {
1152 if ( ui_selected ) {
1154 // what column we in?
1155 unsigned int col = ui_determine_screen_col ( ui_selected );
1158 if ( forcecoil == 0 &&
1159 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1160 col == pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1 )
1163 unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1170 // just go to the next
1172 if ( ui_selected -> next ) {
1173 ui_selected = ui_selected -> next;
1179 ui_selected = g_categories [ ui_category ].refs;
1182 ui_set_selected ( ui_selected );
1187 void ui_push_up ( void ) {
1188 unsigned char col_max = pnd_conf_get_as_int ( g_conf, MMENU_DISP_COLMAX );
1190 if ( ! ui_selected ) {
1195 unsigned int row = ui_determine_row ( ui_selected );
1198 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 1 ) == 0 )
1200 // wrap around instead
1202 unsigned int col = ui_determine_screen_col ( ui_selected );
1205 ui_selected = g_categories [ ui_category ].refs;
1206 while ( ui_selected -> next ) {
1207 ui_selected = ui_selected -> next;
1210 // try to move to same column
1211 unsigned int newcol = ui_determine_screen_col ( ui_selected );
1212 if ( newcol > col ) {
1220 // scroll down to show it
1221 int r = ui_determine_row ( ui_selected ) - 1;
1222 if ( r - pnd_conf_get_as_int ( g_conf, MMENU_DISP_ROWMAX ) > 0 ) {
1223 ui_rows_scrolled_down = (unsigned int) r;
1227 // stop at top/bottom
1239 void ui_push_down ( void ) {
1240 unsigned char col_max = pnd_conf_get_as_int ( g_conf, MMENU_DISP_COLMAX );
1242 if ( ui_selected ) {
1245 unsigned int row = ui_determine_row ( ui_selected );
1248 unsigned int icon_rows = g_categories [ ui_category ].refcount / col_max;
1249 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
1254 if ( row == ( icon_rows - 1 ) &&
1255 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 1 ) == 0 )
1258 unsigned char col = ui_determine_screen_col ( ui_selected );
1260 ui_selected = g_categories [ ui_category ].refs;
1263 ui_selected = ui_selected -> next;
1267 ui_rows_scrolled_down = 0;
1272 ui_push_right ( 1 );
1279 ui_push_right ( 0 );
1285 void ui_push_exec ( void ) {
1287 if ( ui_selected ) {
1288 char buffer [ PATH_MAX ];
1289 sprintf ( buffer, "%s/%s", ui_selected -> ref -> object_path, ui_selected -> ref -> object_filename );
1290 pnd_apps_exec ( pnd_run_script,
1292 ui_selected -> ref -> unique_id,
1293 ui_selected -> ref -> exec,
1294 ui_selected -> ref -> startdir,
1295 ui_selected -> ref -> execargs,
1296 atoi ( ui_selected -> ref -> clockspeed ),
1297 PND_EXEC_OPTION_NORUN );
1298 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1299 emit_and_quit ( buffer );
1305 void ui_push_ltrigger ( void ) {
1306 unsigned char oldcat = ui_category;
1308 if ( ui_category > 0 ) {
1311 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1312 ui_category = g_categorycount - 1;
1316 if ( oldcat != ui_category ) {
1318 ui_set_selected ( ui_selected );
1321 // make tab visible?
1322 if ( ui_catshift > 0 && ui_category == ui_catshift - 1 ) {
1327 ui_rows_scrolled_down = 0;
1332 void ui_push_rtrigger ( void ) {
1333 unsigned char oldcat = ui_category;
1335 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
1336 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1338 if ( ui_category < ( g_categorycount - 1 ) ) {
1341 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1346 if ( oldcat != ui_category ) {
1348 ui_set_selected ( ui_selected );
1351 // make tab visible?
1352 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
1357 ui_rows_scrolled_down = 0;
1362 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ) {
1363 double scale = 1000000.0;
1364 double scalex = 1000000.0;
1365 double scaley = 1000000.0;
1366 SDL_Surface *scaled;
1368 scalex = (double)maxwidth / (double)s -> w;
1370 if ( maxheight == -1 ) {
1373 scaley = (double)maxheight / (double)s -> h;
1375 if ( scaley < scalex ) {
1383 scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
1384 SDL_FreeSurface ( s );
1390 void ui_loadscreen ( void ) {
1394 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1395 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1396 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1397 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1400 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1404 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1405 rtext = TTF_RenderText_Blended ( g_big_font, "Setting up menu...", tmpfontcolor );
1408 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1409 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1410 SDL_FreeSurface ( rtext );
1415 void ui_discoverscreen ( unsigned char clearscreen ) {
1419 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1420 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1421 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1422 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1425 if ( clearscreen ) {
1426 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1428 // render background
1429 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1432 dest.w = sdl_realscreen -> w;
1433 dest.h = sdl_realscreen -> h;
1434 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1435 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1442 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1443 rtext = TTF_RenderText_Blended ( g_big_font, "Looking for applications...", tmpfontcolor );
1444 if ( clearscreen ) {
1451 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1452 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1453 SDL_FreeSurface ( rtext );
1456 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1457 dest.x = rtext -> w + 30;
1459 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, &dest );
1460 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1466 void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
1468 SDL_Rect rects [ 4 ];
1469 SDL_Rect *dest = rects;
1471 bzero ( dest, sizeof(SDL_Rect)* 4 );
1473 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1474 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1475 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1476 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1478 static unsigned int stepx = 0;
1481 if ( clearscreen ) {
1482 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1484 // render background
1485 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1488 dest -> w = sdl_realscreen -> w;
1489 dest -> h = sdl_realscreen -> h;
1490 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1496 // render background
1497 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1500 src.w = sdl_realscreen -> w;
1504 dest -> w = sdl_realscreen -> w;
1505 dest -> h = sdl_realscreen -> h;
1506 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
1514 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1515 rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
1518 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1519 SDL_FreeSurface ( rtext );
1523 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1524 dest -> x = rtext -> w + 30 + stepx;
1526 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, dest );
1532 rtext = TTF_RenderText_Blended ( g_tab_font, filename, tmpfontcolor );
1535 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1536 SDL_FreeSurface ( rtext );
1543 if ( stepx > 350 ) {
1547 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1552 int ui_selected_index ( void ) {
1554 if ( ! ui_selected ) {
1555 return ( -1 ); // no index
1558 mm_appref_t *r = g_categories [ ui_category ].refs;
1561 if ( r == ui_selected ) {
1571 static mm_appref_t *timer_ref = NULL;
1572 void ui_set_selected ( mm_appref_t *r ) {
1574 if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1575 return; // no desire to defer anything
1580 SDL_SetTimer ( 0, NULL );
1585 SDL_SetTimer ( pnd_conf_get_as_int_d ( g_conf, "previewpic.defer_timer_ms", 1000 ), ui_callback_f );
1591 unsigned int ui_callback_f ( unsigned int t ) {
1593 if ( ui_selected != timer_ref ) {
1594 return ( 0 ); // user has moved it, who cares
1598 bzero ( &e, sizeof(SDL_Event) );
1599 e.type = SDL_USEREVENT;
1600 e.user.code = sdl_user_ticker;
1601 SDL_PushEvent ( &e );
1606 int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer ) {
1607 SDL_Rect rects [ 40 ];
1608 SDL_Rect *dest = rects;
1612 bzero ( rects, sizeof(SDL_Rect) * 40 );
1614 unsigned int sel = 0;
1616 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1617 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1618 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1619 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1621 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1623 SDL_Color selfontcolor = { 0/*font_rgba_r*/, font_rgba_g, font_rgba_b, font_rgba_a };
1631 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1632 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1633 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
1634 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
1635 SDL_FillRect( sdl_realscreen, dest, 0 );
1637 // show dialog background
1638 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
1639 src.x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1640 src.y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1641 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
1642 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
1643 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1644 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1645 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1646 // repeat for darken?
1647 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1648 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1649 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1653 // show dialog frame
1654 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
1655 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1656 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1657 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
1658 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1664 rtext = TTF_RenderText_Blended ( g_tab_font, title, tmpfontcolor );
1665 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1666 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
1667 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1668 SDL_FreeSurface ( rtext );
1674 rtext = TTF_RenderText_Blended ( g_tab_font, footer, tmpfontcolor );
1675 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1676 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
1677 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
1679 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1680 SDL_FreeSurface ( rtext );
1685 for ( i = 0; i < argc; i++ ) {
1689 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
1691 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], tmpfontcolor );
1693 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1694 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 ) );
1695 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1696 SDL_FreeSurface ( rtext );
1701 // update all the rects and send it all to sdl
1702 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1706 while ( SDL_WaitEvent ( &event ) ) {
1708 switch ( event.type ) {
1712 if ( event.key.keysym.sym == SDLK_UP ) {
1716 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1717 if ( sel < argc - 1 ) {
1721 } else if ( event.key.keysym.sym == SDLK_RETURN ) {
1724 } else if ( event.key.keysym.sym == SDLK_q ) {
1728 return ( -1 ); // nada
1743 unsigned char ui_determine_row ( mm_appref_t *a ) {
1744 unsigned int row = 0;
1746 mm_appref_t *i = g_categories [ ui_category ].refs;
1751 row /= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
1756 unsigned char ui_determine_screen_row ( mm_appref_t *a ) {
1757 return ( ui_determine_row ( a ) % pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 5 ) );
1760 unsigned char ui_determine_screen_col ( mm_appref_t *a ) {
1761 unsigned int col = 0;
1763 mm_appref_t *i = g_categories [ ui_category ].refs;
1768 col %= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
1773 unsigned char ui_show_info ( char *pndrun, pnd_disco_t *p ) {
1774 char *viewer, *searchpath;
1775 pnd_conf_handle desktoph;
1778 searchpath = pnd_conf_query_searchpath();
1780 desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
1786 viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
1789 return ( 0 ); // no way to view the file
1793 if ( ! p -> unique_id ) {
1797 if ( ! p -> info_filename ) {
1801 if ( ! p -> info_name ) {
1812 if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) {
1813 snprintf ( pargs, 1001, "%s %s",
1814 pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
1819 char pndfile [ 1024 ];
1820 if ( p -> object_type == pnd_object_type_directory ) {
1821 // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
1822 strncpy ( pndfile, p -> object_path, 1000 );
1823 } else if ( p -> object_type == pnd_object_type_pnd ) {
1824 // pnd_run.sh wants the full path and filename for the .pnd file
1825 snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
1828 if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs,
1829 p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) )
1834 pnd_log ( pndn_debug, "Info Exec=%s\n", pnd_apps_exec_runline() );
1838 if ( ( x = fork() ) < 0 ) {
1839 pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
1844 execl ( "/bin/sh", "/bin/sh", "-c", pnd_apps_exec_runline(), (char*)NULL );
1845 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", pnd_apps_exec_runline() );
1857 #define MAXTOUCH 100
1858 ui_touch_t ui_touchrects [ MAXTOUCH ];
1859 unsigned char ui_touchrect_count = 0;
1861 void ui_register_reset ( void ) {
1862 bzero ( ui_touchrects, sizeof(ui_touch_t)*MAXTOUCH );
1863 ui_touchrect_count = 0;
1867 void ui_register_tab ( unsigned char catnum, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
1869 if ( ui_touchrect_count == MAXTOUCH ) {
1873 ui_touchrects [ ui_touchrect_count ].r.x = x;
1874 ui_touchrects [ ui_touchrect_count ].r.y = y;
1875 ui_touchrects [ ui_touchrect_count ].r.w = w;
1876 ui_touchrects [ ui_touchrect_count ].r.h = h;
1877 ui_touchrects [ ui_touchrect_count ].catnum = catnum;
1878 ui_touchrect_count++;
1883 void ui_register_app ( mm_appref_t *app, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
1885 if ( ui_touchrect_count == MAXTOUCH ) {
1889 ui_touchrects [ ui_touchrect_count ].r.x = x;
1890 ui_touchrects [ ui_touchrect_count ].r.y = y;
1891 ui_touchrects [ ui_touchrect_count ].r.w = w;
1892 ui_touchrects [ ui_touchrect_count ].r.h = h;
1893 ui_touchrects [ ui_touchrect_count ].ref = app;
1894 ui_touchrect_count++;
1899 void ui_touch_act ( unsigned int x, unsigned int y ) {
1904 for ( i = 0; i < ui_touchrect_count; i++ ) {
1905 t = &(ui_touchrects [ i ]);
1907 if ( x >= t -> r.x &&
1908 x <= t -> r.x + t -> r.w &&
1910 y <= t -> r.y + t -> r.h
1915 ui_selected = t -> ref;
1918 ui_category = t -> catnum;
1929 unsigned char ui_forkexec ( char *argv[] ) {
1930 char *fooby = argv[0];
1933 if ( ( x = fork() ) < 0 ) {
1934 pnd_log ( pndn_error, "ERROR: Couldn't fork() for '%s'\n", fooby );
1938 if ( x == 0 ) { // child
1939 execv ( fooby, argv );
1940 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", fooby );
1948 unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ) {
1950 if ( ! cache_preview ( p, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
1951 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
1954 pnd_log ( pndn_debug, "THREAD: Couldn't load preview pic: '%s' -> '%s'\n",
1955 IFNULL(p->title_en,"No Name"), p -> preview_pic1 );
1958 // trigger that we completed
1960 bzero ( &e, sizeof(SDL_Event) );
1961 e.type = SDL_USEREVENT;
1962 e.user.code = sdl_user_finishedpreview;
1964 SDL_PushEvent ( &e );
1969 SDL_Thread *g_icon_thread = NULL;
1970 void ui_post_scan ( void ) {
1972 // if deferred icon load, kick off the thread now
1973 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 1 ) {
1975 g_icon_thread = SDL_CreateThread ( (void*)ui_threaded_defered_icon, NULL );
1977 if ( ! g_icon_thread ) {
1978 pnd_log ( pndn_error, "ERROR: Couldn't create icon thread\n" );
1981 } // deferred icon load
1986 unsigned char ui_threaded_defered_icon ( void *p ) {
1987 extern pnd_box_handle g_active_apps;
1988 pnd_box_handle h = g_active_apps;
1990 unsigned char maxwidth, maxheight;
1991 maxwidth = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_ICON_MAX_WIDTH, 50 );
1992 maxheight = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_ICON_MAX_HEIGHT, 50 );
1994 pnd_disco_t *iter = pnd_box_get_head ( h );
1999 if ( iter -> pnd_icon_pos &&
2000 ! cache_icon ( iter, maxwidth, maxheight ) )
2002 pnd_log ( pndn_warning, " Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2005 // trigger that we completed
2007 bzero ( &e, sizeof(SDL_Event) );
2008 e.type = SDL_USEREVENT;
2009 e.user.code = sdl_user_finishedicon;
2010 SDL_PushEvent ( &e );
2012 //pnd_log ( pndn_warning, " Finished deferred load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2013 usleep ( pnd_conf_get_as_int_d ( g_conf, "minimenu.defer_icon_us", 50000 ) );
2018 iter = pnd_box_get_next ( iter );