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"
29 #define CHANGED_NOTHING (0)
30 #define CHANGED_CATEGORY (1<<0) /* changed to different category */
31 #define CHANGED_SELECTION (1<<1) /* changed app selection */
32 #define CHANGED_DATAUPDATE (1<<2) /* deferred preview pic or icon came in */
33 #define CHANGED_APPRELOAD (1<<3) /* new set of applications entirely */
34 #define CHANGED_EVERYTHING (1<<4) /* redraw it all! */
35 unsigned int render_mask = CHANGED_EVERYTHING;
39 SDL_Surface *sdl_realscreen = NULL;
40 unsigned int sdl_ticks = 0;
41 SDL_Thread *g_preview_thread = NULL;
43 enum { sdl_user_ticker = 0,
44 sdl_user_finishedpreview = 1,
45 sdl_user_finishedicon = 2,
50 unsigned short int g_scale = 1; // 1 == noscale
52 SDL_Surface *g_imgcache [ IMG_MAX ];
54 TTF_Font *g_big_font = NULL;
55 TTF_Font *g_grid_font = NULL;
56 TTF_Font *g_detailtext_font = NULL;
57 TTF_Font *g_tab_font = NULL;
59 extern pnd_conf_handle g_conf;
61 /* current display state
63 int ui_rows_scrolled_down = 0; // number of rows that should be missing from top of the display
64 mm_appref_t *ui_selected = NULL;
65 unsigned char ui_category = 0; // current category
66 unsigned char ui_catshift = 0; // how many cats are offscreen to the left
68 extern mm_category_t g_categories [ MAX_CATS ];
69 extern unsigned char g_categorycount;
71 static SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ); // height -1 means ignore
72 static int ui_selected_index ( void );
74 unsigned char ui_setup ( void ) {
79 SDL_Init ( SDL_INIT_EVERYTHING | SDL_INIT_NOPARACHUTE );
81 SDL_JoystickOpen ( 0 ); // turn on joy-0
83 SDL_WM_SetCaption ( "mmenu", "mmenu" );
85 // hide the mouse cursor if we can
86 if ( SDL_ShowCursor ( -1 ) == 1 ) {
93 unsigned int svm = SDL_SWSURFACE /*| SDL_FULLSCREEN*/ /* 0*/;
94 if ( pnd_conf_get_as_int_d ( g_conf, "display.fullscreen", 0 ) > 0 ) {
95 svm |= SDL_FULLSCREEN;
99 SDL_SetVideoMode ( 800 * g_scale, 480 * g_scale, 16 /*bpp*/, svm );
101 if ( ! sdl_realscreen ) {
102 pnd_log ( pndn_error, "ERROR: Couldn't open SDL real screen; dieing." );
106 pnd_log ( pndn_debug, "Pixel format:" );
107 pnd_log ( pndn_debug, "bpp b: %u\n", sdl_realscreen -> format -> BitsPerPixel );
108 pnd_log ( pndn_debug, "bpp B: %u\n", sdl_realscreen -> format -> BytesPerPixel );
109 pnd_log ( pndn_debug, "R mask: %08x\n", sdl_realscreen -> format -> Rmask );
110 pnd_log ( pndn_debug, "G mask: %08x\n", sdl_realscreen -> format -> Gmask );
111 pnd_log ( pndn_debug, "B mask: %08x\n", sdl_realscreen -> format -> Bmask );
117 /* Set 16-bit stereo audio at 22Khz */
118 fmt.freq = 44100; //22050;
119 fmt.format = AUDIO_S16; //AUDIO_S16;
121 fmt.samples = 2048; /* A good value for games */
122 fmt.callback = mixaudio;
125 /* Open the audio device and start playing sound! */
126 if ( SDL_OpenAudio ( &fmt, NULL ) < 0 ) {
127 zotlog ( "Unable to open audio: %s\n", SDL_GetError() );
131 SDL_PauseAudio ( 0 );
136 //IMG_Init ( IMG_INIT_JPG | IMG_INIT_PNG );
142 if ( TTF_Init() == -1 ) {
143 pnd_log ( pndn_error, "ERROR: Couldn't set up SDL TTF lib\n" );
144 return ( 0 ); // couldn't set up SDL TTF
147 char fullpath [ PATH_MAX ];
149 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "minimenu.font" ) );
150 g_big_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
151 if ( ! g_big_font ) {
152 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
153 pnd_conf_get_as_char ( g_conf, "minimenu.font" ), pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
154 return ( 0 ); // couldn't set up SDL TTF
158 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, MMENU_GRID_FONT ) );
159 g_grid_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, MMENU_GRID_FONTSIZE, 10 ) );
160 if ( ! g_grid_font ) {
161 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
162 pnd_conf_get_as_char ( g_conf, MMENU_GRID_FONT ), pnd_conf_get_as_int_d ( g_conf, MMENU_GRID_FONTSIZE, 10 ) );
163 return ( 0 ); // couldn't set up SDL TTF
167 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "detailtext.font" ) );
168 g_detailtext_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
169 if ( ! g_detailtext_font ) {
170 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
171 pnd_conf_get_as_char ( g_conf, "detailtext.font" ), pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
172 return ( 0 ); // couldn't set up SDL TTF
176 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "tabs.font" ) );
177 g_tab_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
178 if ( ! g_tab_font ) {
179 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
180 pnd_conf_get_as_char ( g_conf, "tabs.font" ), pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
181 return ( 0 ); // couldn't set up SDL TTF
187 mm_imgcache_t g_imagecache [ IMG_TRUEMAX ] = {
188 { IMG_BACKGROUND_800480, "graphics.IMG_BACKGROUND_800480" },
189 { IMG_BACKGROUND_TABMASK, "graphics.IMG_BACKGROUND_TABMASK" },
190 { IMG_DETAIL_PANEL, "graphics.IMG_DETAIL_PANEL" },
191 { IMG_DETAIL_BG, "graphics.IMG_DETAIL_BG" },
192 { IMG_SELECTED_ALPHAMASK, "graphics.IMG_SELECTED_ALPHAMASK" },
193 { IMG_TAB_SEL, "graphics.IMG_TAB_SEL" },
194 { IMG_TAB_UNSEL, "graphics.IMG_TAB_UNSEL" },
195 { IMG_TAB_LINE, "graphics.IMG_TAB_LINE" },
196 { IMG_TAB_LINEL, "graphics.IMG_TAB_LINEL" },
197 { IMG_TAB_LINER, "graphics.IMG_TAB_LINER" },
198 { IMG_ICON_MISSING, "graphics.IMG_ICON_MISSING" },
199 { IMG_SELECTED_HILITE, "graphics.IMG_SELECTED_HILITE" },
200 { IMG_PREVIEW_MISSING, "graphics.IMG_PREVIEW_MISSING" },
201 { IMG_ARROW_UP, "graphics.IMG_ARROW_UP", },
202 { IMG_ARROW_DOWN, "graphics.IMG_ARROW_DOWN", },
203 { IMG_ARROW_SCROLLBAR, "graphics.IMG_ARROW_SCROLLBAR", },
204 { IMG_HOURGLASS, "graphics.IMG_HOURGLASS", },
208 unsigned char ui_imagecache ( char *basepath ) {
210 char fullpath [ PATH_MAX ];
214 for ( i = 0; i < IMG_MAX; i++ ) {
216 if ( g_imagecache [ i ].id != i ) {
217 pnd_log ( pndn_error, "ERROR: Internal table mismatch during caching [%u]\n", i );
221 char *filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].confname );
224 pnd_log ( pndn_error, "ERROR: Missing filename in conf for key: %s\n", g_imagecache [ i ].confname );
228 if ( filename [ 0 ] == '/' ) {
229 strncpy ( fullpath, filename, PATH_MAX );
231 sprintf ( fullpath, "%s/%s", basepath, filename );
234 if ( ! ( g_imagecache [ i ].i = IMG_Load ( fullpath ) ) ) {
235 pnd_log ( pndn_error, "ERROR: Couldn't load static cache image: %s\n", fullpath );
242 //g_imagecache [ IMG_SELECTED_ALPHAMASK ].i = SDL_CreateRGBSurface ( SDL_SWSURFACE, 60, 60, 32, 0xFF0000, 0x00FF00, 0xFF, 0xFF000000 );
243 //boxRGBA ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, 0, 0, 60, 60, 100, 100, 100, 250 );
249 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 );
250 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 );
251 // scale text hilight
252 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 );
253 // scale preview no-pic
254 g_imagecache [ IMG_PREVIEW_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_PREVIEW_MISSING ].i,
255 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ),
256 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 50 ) );
258 // set alpha on detail panel
259 //SDL_SetAlpha ( g_imagecache [ IMG_DETAIL_BG ].i, SDL_SRCALPHA, pnd_conf_get_as_int_d ( g_conf, "display.detail_bg_alpha", 50 ) );
264 void ui_render ( void ) {
267 // divide width: 550 / 250
268 // divide left side: 5 columns == 110px width
269 // 20px buffer either side == 70px wide icon + 20 + 20?
271 // what jobs to do during render?
275 #define R_TABS (1<<1)
276 #define R_DETAIL (1<<2)
277 #define R_GRID (1<<3)
279 #define R_ALL (R_BG|R_TABS|R_DETAIL|R_GRID)
281 unsigned int render_jobs_b = 0;
283 if ( render_mask & CHANGED_EVERYTHING ) {
284 render_jobs_b |= R_ALL;
287 if ( render_mask & CHANGED_SELECTION ) {
288 render_jobs_b |= R_GRID;
289 render_jobs_b |= R_DETAIL;
292 if ( render_mask & CHANGED_CATEGORY ) {
293 render_jobs_b |= R_ALL;
296 render_mask = CHANGED_NOTHING;
300 unsigned int icon_rows;
303 SDL_Rect rects [ MAXRECTS ], src;
304 SDL_Rect *dest = rects;
305 bzero ( dest, sizeof(SDL_Rect)*MAXRECTS );
307 unsigned int row, displayrow, col;
308 mm_appref_t *appiter;
310 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
312 unsigned char row_max = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_ROWMAX, 4 );
313 unsigned char col_max = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_COLMAX, 5 );
315 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
316 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
317 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
318 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
320 unsigned int grid_offset_x = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_x" );
321 unsigned int grid_offset_y = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_y" );
323 unsigned int icon_offset_x = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_x" );
324 unsigned int icon_offset_y = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_y" );
325 unsigned int icon_max_width = pnd_conf_get_as_int ( g_conf, "grid.icon_max_width" );
326 unsigned int icon_max_height = pnd_conf_get_as_int ( g_conf, "grid.icon_max_height" );
328 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
329 unsigned int text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
330 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "grid.text_offset_x" );
331 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_offset_y" );
333 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "grid.cell_width" );
334 unsigned int cell_height = pnd_conf_get_as_int ( g_conf, "grid.cell_height" );
336 // how many total rows do we need?
337 icon_rows = g_categories [ ui_category ].refcount / col_max;
338 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
342 // if no selected app yet, select the first one
344 if ( ! ui_selected ) {
345 ui_selected = g_categories [ ui_category ].refs;
349 // reset touchscreen regions
352 // ensure selection is visible
355 int index = ui_selected_index();
356 int topleft = col_max * ui_rows_scrolled_down;
357 int botright = ( col_max * ( ui_rows_scrolled_down + row_max ) - 1 );
359 //pnd_log ( PND_LOG_DEFAULT, "index %u tl %u br %u\n", index, topleft, botright );
361 if ( index < topleft ) {
362 ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
363 render_jobs_b |= R_ALL;
364 } else if ( index > botright ) {
365 ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
366 render_jobs_b |= R_ALL;
369 if ( ui_rows_scrolled_down < 0 ) {
370 ui_rows_scrolled_down = 0;
371 } else if ( ui_rows_scrolled_down > icon_rows ) {
372 ui_rows_scrolled_down = icon_rows;
378 if ( render_jobs_b & R_BG ) {
380 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
383 dest -> w = sdl_realscreen -> w;
384 dest -> h = sdl_realscreen -> h;
385 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
390 if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
393 dest -> w = sdl_realscreen -> w;
394 dest -> h = sdl_realscreen -> h;
395 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
402 if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
403 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
404 unsigned int tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
405 unsigned int tab_selheight = pnd_conf_get_as_int ( g_conf, "tabs.tab_selheight" );
406 unsigned int tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
407 unsigned int tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
408 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
409 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
410 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
411 unsigned int maxtab = ( screen_width / tab_width ) < g_categorycount ? ( screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift;
412 unsigned int maxtabspot = ( screen_width / tab_width );
414 // draw tabs with categories
415 for ( col = ui_catshift;
421 if ( col == ui_category ) {
422 s = g_imagecache [ IMG_TAB_SEL ].i;
424 s = g_imagecache [ IMG_TAB_UNSEL ].i;
431 if ( col == ui_category ) {
432 src.h = tab_selheight;
436 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
437 dest -> y = tab_offset_y;
440 ui_register_tab ( col, dest -> x, dest -> y, tab_width, tab_height );
442 if ( render_jobs_b & R_TABS ) {
443 //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
444 SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
448 if ( col == ui_category ) {
449 // no line for selected tab
451 if ( col - ui_catshift == 0 ) {
452 s = g_imagecache [ IMG_TAB_LINEL ].i;
453 } else if ( col - ui_catshift == maxtabspot - 1 ) {
454 s = g_imagecache [ IMG_TAB_LINER ].i;
456 s = g_imagecache [ IMG_TAB_LINE ].i;
458 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
459 dest -> y = tab_offset_y + tab_height;
460 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
466 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
467 rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ].catname, tmpfontcolor );
470 src.w = rtext -> w < text_width ? rtext -> w : text_width;
472 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
473 dest -> y = tab_offset_y + text_offset_y;
474 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
475 SDL_FreeSurface ( rtext );
482 if ( render_jobs_b & R_TABS ) {
484 // draw tab lines under where tabs would be if we had categories
485 for ( /* foo */; col < maxtabspot; col++ ) {
488 if ( col - ui_catshift == 0 ) {
489 s = g_imagecache [ IMG_TAB_LINEL ].i;
490 } else if ( col - ui_catshift == maxtabspot - 1 ) {
491 s = g_imagecache [ IMG_TAB_LINER ].i;
493 s = g_imagecache [ IMG_TAB_LINE ].i;
495 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
496 dest -> y = tab_offset_y + tab_height;
497 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
506 // scroll bars and arrows
507 if ( render_jobs_b & R_BG ) {
508 unsigned char show_bar = 0;
511 if ( ui_rows_scrolled_down && g_imagecache [ IMG_ARROW_UP ].i ) {
512 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
513 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
514 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
521 if ( ui_rows_scrolled_down + row_max < icon_rows && g_imagecache [ IMG_ARROW_DOWN ].i ) {
522 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
523 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
524 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
531 // show scrollbar as well
534 src.w = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_w", 10 );
535 src.h = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_h", 100 );
536 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
537 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
538 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
542 } // r_bg, scroll bars
544 // render detail pane bg
545 if ( render_jobs_b & R_DETAIL ) {
547 if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
550 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
551 src.x = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
552 src.y = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
553 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
554 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
555 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
556 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
557 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
561 // render detail pane
562 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
563 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
564 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
565 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
569 } // detailpane frame/bg
573 // anything to render?
574 if ( render_jobs_b & R_GRID ) {
576 // if just rendering grid, and nothing else, better clear it first
577 if ( ! ( render_jobs_b & R_BG ) ) {
578 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
579 src.x = grid_offset_x;
580 src.y = grid_offset_y;
581 src.w = col_max * cell_width;
582 src.h = row_max * cell_height;
584 dest -> x = grid_offset_x;
585 dest -> y = grid_offset_y;
587 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
593 if ( g_categories [ ui_category ].refs ) {
595 appiter = g_categories [ ui_category ].refs;
599 // until we run out of apps, or run out of space
600 while ( appiter != NULL ) {
602 for ( col = 0; col < col_max && appiter != NULL; col++ ) {
604 // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
605 if ( row >= ui_rows_scrolled_down ) {
607 // selected? show hilights
608 if ( appiter == ui_selected ) {
610 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x;
611 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y;
612 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, NULL /* all */, sdl_realscreen, dest );
615 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
616 dest -> y = grid_offset_y + ( displayrow * cell_height ) + pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
617 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
622 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
623 SDL_Surface *iconsurface;
625 iconsurface = ic -> i;
627 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
628 iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
631 //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
637 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + (( icon_max_width - iconsurface -> w ) / 2);
638 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + (( icon_max_height - iconsurface -> h ) / 2);
640 SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
643 ui_register_app ( appiter, dest -> x, dest -> y, src.w, src.h );
650 if ( appiter -> ref -> title_en ) {
652 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
653 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, tmpfontcolor );
656 src.w = text_width < rtext -> w ? text_width : rtext -> w;
658 if ( rtext -> w > text_width ) {
659 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
661 dest -> x = grid_offset_x + ( col * cell_width ) + text_offset_x - ( rtext -> w / 2 );
663 dest -> y = grid_offset_y + ( displayrow * cell_height ) + text_offset_y;
664 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
665 SDL_FreeSurface ( rtext );
669 } // display now? or scrolled away..
672 appiter = appiter -> next;
674 } // for column 1...X
676 if ( row >= ui_rows_scrolled_down ) {
682 // are we done displaying rows?
683 if ( displayrow >= row_max ) {
690 // no apps to render?
691 pnd_log ( pndn_rem, "No applications to render?\n" );
697 if ( ui_selected && render_jobs_b & R_DETAIL ) {
699 unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
700 unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
701 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "detailtext.cell_width" );
703 unsigned int desty = cell_offset_y;
708 if ( ui_selected -> ref -> title_en ) {
710 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
711 rtext = TTF_RenderText_Blended ( g_detailtext_font, ui_selected -> ref -> title_en, tmpfontcolor );
714 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
716 dest -> x = cell_offset_x;
718 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
719 SDL_FreeSurface ( rtext );
725 if ( ui_selected -> ref -> main_category ) {
727 sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
730 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
731 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
734 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
736 dest -> x = cell_offset_x;
738 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
739 SDL_FreeSurface ( rtext );
745 if ( ui_selected -> ref -> clockspeed ) {
747 sprintf ( buffer, "CPU Clock: %s", ui_selected -> ref -> clockspeed );
750 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
751 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
754 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
756 dest -> x = cell_offset_x;
758 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
759 SDL_FreeSurface ( rtext );
764 // show sub-app# on right side of cpu clock?
765 //if ( ui_selected -> ref -> subapp_number )
767 sprintf ( buffer, "(app#%u)", ui_selected -> ref -> subapp_number );
770 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
771 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
772 dest -> x = cell_offset_x + cell_width - rtext -> w;
773 dest -> y = desty - src.h;
774 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
775 SDL_FreeSurface ( rtext );
780 if ( ui_selected -> ref -> clockspeed && ui_selected -> ref -> info_filename ) {
782 sprintf ( buffer, "Documentation - hit Y" );
785 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
786 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
789 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
791 dest -> x = cell_offset_x;
793 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
794 SDL_FreeSurface ( rtext );
800 mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
801 SDL_Surface *previewpic;
804 previewpic = ic -> i;
806 previewpic = g_imagecache [ IMG_PREVIEW_MISSING ].i;
810 dest -> x = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_x", 50 ) +
811 ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
812 dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
813 SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
824 static int last_battlevel = 0;
825 static unsigned char batterylevel = 0;
828 if ( time ( NULL ) - last_battlevel > 60 ) {
829 batterylevel = pnd_device_get_battery_gauge_perc();
830 last_battlevel = time ( NULL );
833 sprintf ( buffer, "Battery: %u%%", batterylevel );
836 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
837 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
838 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.battery_x", 20 );
839 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.battery_y", 450 );
840 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
841 SDL_FreeSurface ( rtext );
846 if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
847 char *buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
849 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
850 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
851 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
852 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
853 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
854 SDL_FreeSurface ( rtext );
859 if ( pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 ) {
862 time_t t = time ( NULL );
863 struct tm *tm = localtime ( &t );
864 strftime ( buffer, 50, "%a %H:%M %F", tm );
867 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
868 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
869 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.clock_x", 700 );
870 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.clock_y", 450 );
871 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
872 SDL_FreeSurface ( rtext );
876 // update all the rects and send it all to sdl
877 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
881 void ui_process_input ( unsigned char block_p ) {
884 unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
885 //static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
887 while ( ! ui_event &&
888 block_p ? SDL_WaitEvent ( &event ) : SDL_PollEvent ( &event ) )
891 switch ( event.type ) {
896 if ( event.user.code == sdl_user_ticker ) {
898 // timer went off, time to load something
899 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
901 // load the preview pics now!
902 pnd_disco_t *iter = ui_selected -> ref;
904 if ( iter -> preview_pic1 ) {
906 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.threaded_preview", 0 ) ) {
907 // load in bg thread, make user experience chuggy
909 g_preview_thread = SDL_CreateThread ( (void*)ui_threaded_defered_preview, iter );
911 if ( ! g_preview_thread ) {
912 pnd_log ( pndn_error, "ERROR: Couldn't create preview thread\n" );
916 // load it now, make user wait
918 if ( ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
919 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
922 pnd_log ( pndn_debug, " Couldn't load preview pic: '%s' -> '%s'\n",
923 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
928 } // got a preview at all?
933 } else if ( event.user.code == sdl_user_finishedpreview ) {
935 // if we just finished the one we happen to be looking at, better redraw now; otherwise, if
936 // we finished another, no big woop
937 if ( ui_selected && event.user.data1 == ui_selected -> ref ) {
941 } else if ( event.user.code == sdl_user_finishedicon ) {
942 // redraw, so we can show the newly loaded icon
947 render_mask |= CHANGED_EVERYTHING;
951 #if 0 // joystick motion
952 case SDL_JOYAXISMOTION:
954 pnd_log ( PND_LOG_DEFAULT, "joystick axis\n" );
956 if ( event.jaxis.axis == 0 ) {
958 if ( event.jaxis.value < 0 ) {
960 pnd_log ( PND_LOG_DEFAULT, "joystick axis - LEFT\n" );
961 } else if ( event.jaxis.value > 0 ) {
963 pnd_log ( PND_LOG_DEFAULT, "joystick axis - RIGHT\n" );
965 } else if ( event.jaxis.axis == 1 ) {
967 if ( event.jaxis.value < 0 ) {
969 } else if ( event.jaxis.value > 0 ) {
979 #if 0 // joystick buttons
980 case SDL_JOYBUTTONDOWN:
982 pnd_log ( PND_LOG_DEFAULT, "joystick button down %u\n", event.jbutton.button );
984 if ( event.jbutton.button == 0 ) { // B
986 } else if ( event.jbutton.button == 1 ) { // Y
988 } else if ( event.jbutton.button == 2 ) { // X
990 } else if ( event.jbutton.button == 3 ) { // A
993 } else if ( event.jbutton.button == 4 ) { // Select
994 ui_mask |= uisb_select;
995 } else if ( event.jbutton.button == 5 ) { // Start
996 ui_mask |= uisb_start;
998 } else if ( event.jbutton.button == 7 ) { // L
1000 } else if ( event.jbutton.button == 8 ) { // R
1009 case SDL_JOYBUTTONUP:
1011 pnd_log ( PND_LOG_DEFAULT, "joystick button up %u\n", event.jbutton.button );
1013 if ( event.jbutton.button == 0 ) { // B
1016 } else if ( event.jbutton.button == 1 ) { // Y
1018 } else if ( event.jbutton.button == 2 ) { // X
1020 } else if ( event.jbutton.button == 3 ) { // A
1023 } else if ( event.jbutton.button == 4 ) { // Select
1024 ui_mask &= ~uisb_select;
1025 } else if ( event.jbutton.button == 5 ) { // Start
1026 ui_mask &= ~uisb_start;
1028 } else if ( event.jbutton.button == 7 ) { // L
1031 } else if ( event.jbutton.button == 8 ) { // R
1042 #if 1 // keyboard events
1045 //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
1047 // SDLK_LALT -> Start
1050 if ( event.key.keysym.sym == SDLK_RIGHT ) {
1051 ui_push_right ( 0 );
1053 } else if ( event.key.keysym.sym == SDLK_LEFT ) {
1056 } else if ( event.key.keysym.sym == SDLK_UP ) {
1059 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1062 } else if ( event.key.keysym.sym == SDLK_SPACE || event.key.keysym.sym == SDLK_END ) {
1065 } else if ( event.key.keysym.sym == SDLK_z || event.key.keysym.sym == SDLK_RSHIFT ) {
1068 } else if ( event.key.keysym.sym == SDLK_x || event.key.keysym.sym == SDLK_RCTRL ) {
1071 } else if ( event.key.keysym.sym == SDLK_y || event.key.keysym.sym == SDLK_PAGEUP ) {
1073 if ( ui_selected ) {
1074 ui_show_info ( pnd_run_script, ui_selected -> ref );
1078 } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
1082 } else if ( event.key.keysym.sym == SDLK_LCTRL /*LALT*/ ) { // select button
1083 char *opts [ 20 ] = {
1084 "Return to Minimenu",
1086 "Rescan for Applications",
1087 "Cache previews to SD now",
1088 "Run xfce4 from Minimenu",
1089 "Run a terminal/console",
1090 "Exit and run xfce4",
1091 "Exit and run pmenu",
1095 int sel = ui_modal_single_menu ( opts, 9, "Minimenu", "Enter to select; other to return." );
1097 char buffer [ 100 ];
1100 } else if ( sel == 1 ) {
1102 sprintf ( buffer, "sudo poweroff" );
1104 } else if ( sel == 2 ) {
1106 pnd_log ( pndn_debug, "Freeing up applications\n" );
1107 applications_free();
1108 pnd_log ( pndn_debug, "Rescanning applications\n" );
1109 applications_scan();
1112 ui_rows_scrolled_down = 0;
1113 } else if ( sel == 3 ) {
1114 // cache preview to SD now
1115 extern pnd_box_handle g_active_apps;
1116 pnd_box_handle h = g_active_apps;
1118 unsigned int maxwidth, maxheight;
1119 maxwidth = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 );
1120 maxheight = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 );
1122 pnd_disco_t *iter = pnd_box_get_head ( h );
1127 if ( ! cache_preview ( iter, maxwidth, maxheight ) ) {
1128 pnd_log ( pndn_debug, "Force cache: Couldn't load preview pic: '%s' -> '%s'\n",
1129 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1133 iter = pnd_box_get_next ( iter );
1136 } else if ( sel == 4 ) {
1138 char buffer [ PATH_MAX ];
1139 sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/bin/startxfce4" );
1140 emit_and_quit ( buffer );
1141 } else if ( sel == 5 ) {
1144 argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
1148 ui_forkexec ( argv );
1151 } else if ( sel == 6 ) {
1153 sprintf ( buffer, "echo startxfce4 > /tmp/gui.load" );
1155 //sprintf ( buffer, "sudo poweroff" );
1156 //system ( buffer );
1158 } else if ( sel == 7 ) {
1160 sprintf ( buffer, "echo pmenu > /tmp/gui.load" );
1162 //sprintf ( buffer, "sudo poweroff" );
1163 //system ( buffer );
1165 } else if ( sel == 8 ) {
1166 emit_and_quit ( MM_QUIT );
1167 } else if ( sel == 9 ) {
1172 render_mask |= CHANGED_EVERYTHING;
1176 if ( event.key.keysym.sym == SDLK_q ) {
1177 emit_and_quit ( MM_QUIT );
1183 #if 1 // mouse / touchscreen
1185 case SDL_MOUSEBUTTONDOWN:
1186 if ( event.button.button == SDL_BUTTON_LEFT ) {
1187 cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
1193 case SDL_MOUSEBUTTONUP:
1194 if ( event.button.button == SDL_BUTTON_LEFT ) {
1195 ui_touch_act ( event.button.x, event.button.y );
1208 } // switch event type
1215 void ui_push_left ( unsigned char forcecoil ) {
1217 if ( ! ui_selected ) {
1218 ui_push_right ( 0 );
1222 // what column we in?
1223 unsigned int col = ui_determine_screen_col ( ui_selected );
1225 // are we alreadt at first item?
1226 if ( forcecoil == 0 &&
1227 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1230 unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1232 ui_push_right ( 0 );
1236 } else if ( g_categories [ ui_category ].refs == ui_selected ) {
1237 // can't go any more left, we're at the head
1240 // figure out the previous item; yay for singly linked list :/
1241 mm_appref_t *i = g_categories [ ui_category ].refs;
1243 if ( i -> next == ui_selected ) {
1251 ui_set_selected ( ui_selected );
1256 void ui_push_right ( unsigned char forcecoil ) {
1258 if ( ui_selected ) {
1260 // what column we in?
1261 unsigned int col = ui_determine_screen_col ( ui_selected );
1264 if ( forcecoil == 0 &&
1265 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1266 col == pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1 )
1269 unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1276 // just go to the next
1278 if ( ui_selected -> next ) {
1279 ui_selected = ui_selected -> next;
1285 ui_selected = g_categories [ ui_category ].refs;
1288 ui_set_selected ( ui_selected );
1293 void ui_push_up ( void ) {
1294 unsigned char col_max = pnd_conf_get_as_int ( g_conf, MMENU_DISP_COLMAX );
1296 if ( ! ui_selected ) {
1301 unsigned int row = ui_determine_row ( ui_selected );
1304 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 1 ) == 0 )
1306 // wrap around instead
1308 unsigned int col = ui_determine_screen_col ( ui_selected );
1311 ui_selected = g_categories [ ui_category ].refs;
1312 while ( ui_selected -> next ) {
1313 ui_selected = ui_selected -> next;
1316 // try to move to same column
1317 unsigned int newcol = ui_determine_screen_col ( ui_selected );
1318 if ( newcol > col ) {
1326 // scroll down to show it
1327 int r = ui_determine_row ( ui_selected ) - 1;
1328 if ( r - pnd_conf_get_as_int ( g_conf, MMENU_DISP_ROWMAX ) > 0 ) {
1329 ui_rows_scrolled_down = (unsigned int) r;
1333 // stop at top/bottom
1345 void ui_push_down ( void ) {
1346 unsigned char col_max = pnd_conf_get_as_int ( g_conf, MMENU_DISP_COLMAX );
1348 if ( ui_selected ) {
1351 unsigned int row = ui_determine_row ( ui_selected );
1354 unsigned int icon_rows = g_categories [ ui_category ].refcount / col_max;
1355 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
1360 if ( row == ( icon_rows - 1 ) &&
1361 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 1 ) == 0 )
1364 unsigned char col = ui_determine_screen_col ( ui_selected );
1366 ui_selected = g_categories [ ui_category ].refs;
1369 ui_selected = ui_selected -> next;
1373 ui_rows_scrolled_down = 0;
1378 ui_push_right ( 1 );
1385 ui_push_right ( 0 );
1391 void ui_push_exec ( void ) {
1393 if ( ui_selected ) {
1394 char buffer [ PATH_MAX ];
1395 sprintf ( buffer, "%s/%s", ui_selected -> ref -> object_path, ui_selected -> ref -> object_filename );
1396 pnd_apps_exec ( pnd_run_script,
1398 ui_selected -> ref -> unique_id,
1399 ui_selected -> ref -> exec,
1400 ui_selected -> ref -> startdir,
1401 ui_selected -> ref -> execargs,
1402 ui_selected -> ref -> clockspeed ? atoi ( ui_selected -> ref -> clockspeed ) : 0,
1403 PND_EXEC_OPTION_NORUN );
1404 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1405 emit_and_quit ( buffer );
1411 void ui_push_ltrigger ( void ) {
1412 unsigned char oldcat = ui_category;
1414 if ( ui_category > 0 ) {
1417 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1418 ui_category = g_categorycount - 1;
1422 if ( oldcat != ui_category ) {
1424 ui_set_selected ( ui_selected );
1427 // make tab visible?
1428 if ( ui_catshift > 0 && ui_category == ui_catshift - 1 ) {
1433 ui_rows_scrolled_down = 0;
1435 render_mask |= CHANGED_CATEGORY;
1440 void ui_push_rtrigger ( void ) {
1441 unsigned char oldcat = ui_category;
1443 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
1444 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1446 if ( ui_category < ( g_categorycount - 1 ) ) {
1449 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1454 if ( oldcat != ui_category ) {
1456 ui_set_selected ( ui_selected );
1459 // make tab visible?
1460 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
1465 ui_rows_scrolled_down = 0;
1467 render_mask |= CHANGED_CATEGORY;
1472 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ) {
1473 double scale = 1000000.0;
1474 double scalex = 1000000.0;
1475 double scaley = 1000000.0;
1476 SDL_Surface *scaled;
1478 scalex = (double)maxwidth / (double)s -> w;
1480 if ( maxheight == -1 ) {
1483 scaley = (double)maxheight / (double)s -> h;
1485 if ( scaley < scalex ) {
1493 scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
1494 SDL_FreeSurface ( s );
1500 void ui_loadscreen ( void ) {
1504 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1505 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1506 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1507 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1510 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1514 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1515 rtext = TTF_RenderText_Blended ( g_big_font, "Setting up menu...", tmpfontcolor );
1518 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1519 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1520 SDL_FreeSurface ( rtext );
1525 void ui_discoverscreen ( unsigned char clearscreen ) {
1529 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1530 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1531 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1532 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1535 if ( clearscreen ) {
1536 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1538 // render background
1539 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1542 dest.w = sdl_realscreen -> w;
1543 dest.h = sdl_realscreen -> h;
1544 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1545 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1552 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1553 rtext = TTF_RenderText_Blended ( g_big_font, "Looking for applications...", tmpfontcolor );
1554 if ( clearscreen ) {
1561 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1562 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1563 SDL_FreeSurface ( rtext );
1566 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1567 dest.x = rtext -> w + 30;
1569 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, &dest );
1570 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1576 void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
1578 SDL_Rect rects [ 4 ];
1579 SDL_Rect *dest = rects;
1581 bzero ( dest, sizeof(SDL_Rect)* 4 );
1583 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1584 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1585 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1586 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1588 static unsigned int stepx = 0;
1591 if ( clearscreen ) {
1592 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1594 // render background
1595 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1598 dest -> w = sdl_realscreen -> w;
1599 dest -> h = sdl_realscreen -> h;
1600 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1606 // render background
1607 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1610 src.w = sdl_realscreen -> w;
1614 dest -> w = sdl_realscreen -> w;
1615 dest -> h = sdl_realscreen -> h;
1616 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
1624 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1625 rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
1628 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1629 SDL_FreeSurface ( rtext );
1633 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1634 dest -> x = rtext -> w + 30 + stepx;
1636 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, dest );
1642 rtext = TTF_RenderText_Blended ( g_tab_font, filename, tmpfontcolor );
1645 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1646 SDL_FreeSurface ( rtext );
1653 if ( stepx > 350 ) {
1657 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1662 int ui_selected_index ( void ) {
1664 if ( ! ui_selected ) {
1665 return ( -1 ); // no index
1668 mm_appref_t *r = g_categories [ ui_category ].refs;
1671 if ( r == ui_selected ) {
1681 static mm_appref_t *timer_ref = NULL;
1682 void ui_set_selected ( mm_appref_t *r ) {
1684 render_mask |= CHANGED_SELECTION;
1686 if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1687 return; // no desire to defer anything
1692 SDL_SetTimer ( 0, NULL );
1697 SDL_SetTimer ( pnd_conf_get_as_int_d ( g_conf, "previewpic.defer_timer_ms", 1000 ), ui_callback_f );
1703 unsigned int ui_callback_f ( unsigned int t ) {
1705 if ( ui_selected != timer_ref ) {
1706 return ( 0 ); // user has moved it, who cares
1710 bzero ( &e, sizeof(SDL_Event) );
1711 e.type = SDL_USEREVENT;
1712 e.user.code = sdl_user_ticker;
1713 SDL_PushEvent ( &e );
1718 int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer ) {
1719 SDL_Rect rects [ 40 ];
1720 SDL_Rect *dest = rects;
1724 bzero ( rects, sizeof(SDL_Rect) * 40 );
1726 unsigned int sel = 0;
1728 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1729 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1730 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1731 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1733 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1735 SDL_Color selfontcolor = { 0/*font_rgba_r*/, font_rgba_g, font_rgba_b, font_rgba_a };
1743 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1744 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1745 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
1746 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
1747 SDL_FillRect( sdl_realscreen, dest, 0 );
1749 // show dialog background
1750 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
1751 src.x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1752 src.y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1753 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
1754 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
1755 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1756 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1757 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1758 // repeat for darken?
1759 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1760 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1761 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1765 // show dialog frame
1766 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
1767 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1768 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1769 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
1770 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1776 rtext = TTF_RenderText_Blended ( g_tab_font, title, tmpfontcolor );
1777 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1778 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
1779 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1780 SDL_FreeSurface ( rtext );
1786 rtext = TTF_RenderText_Blended ( g_tab_font, footer, tmpfontcolor );
1787 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1788 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
1789 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
1791 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1792 SDL_FreeSurface ( rtext );
1797 for ( i = 0; i < argc; i++ ) {
1801 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
1803 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], tmpfontcolor );
1805 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1806 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 ) );
1807 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1808 SDL_FreeSurface ( rtext );
1813 // update all the rects and send it all to sdl
1814 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1818 while ( SDL_WaitEvent ( &event ) ) {
1820 switch ( event.type ) {
1824 if ( event.key.keysym.sym == SDLK_UP ) {
1828 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1829 if ( sel < argc - 1 ) {
1833 } else if ( event.key.keysym.sym == SDLK_RETURN ) {
1836 } else if ( event.key.keysym.sym == SDLK_q ) {
1840 return ( -1 ); // nada
1855 unsigned char ui_determine_row ( mm_appref_t *a ) {
1856 unsigned int row = 0;
1858 mm_appref_t *i = g_categories [ ui_category ].refs;
1863 row /= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
1868 unsigned char ui_determine_screen_row ( mm_appref_t *a ) {
1869 return ( ui_determine_row ( a ) % pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 5 ) );
1872 unsigned char ui_determine_screen_col ( mm_appref_t *a ) {
1873 unsigned int col = 0;
1875 mm_appref_t *i = g_categories [ ui_category ].refs;
1880 col %= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
1885 unsigned char ui_show_info ( char *pndrun, pnd_disco_t *p ) {
1886 char *viewer, *searchpath;
1887 pnd_conf_handle desktoph;
1890 searchpath = pnd_conf_query_searchpath();
1892 desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
1898 viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
1901 return ( 0 ); // no way to view the file
1905 if ( ! p -> unique_id ) {
1909 if ( ! p -> info_filename ) {
1913 if ( ! p -> info_name ) {
1924 if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) {
1925 snprintf ( pargs, 1001, "%s %s",
1926 pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
1931 char pndfile [ 1024 ];
1932 if ( p -> object_type == pnd_object_type_directory ) {
1933 // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
1934 strncpy ( pndfile, p -> object_path, 1000 );
1935 } else if ( p -> object_type == pnd_object_type_pnd ) {
1936 // pnd_run.sh wants the full path and filename for the .pnd file
1937 snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
1940 if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs,
1941 p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) )
1946 pnd_log ( pndn_debug, "Info Exec=%s\n", pnd_apps_exec_runline() );
1950 if ( ( x = fork() ) < 0 ) {
1951 pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
1956 execl ( "/bin/sh", "/bin/sh", "-c", pnd_apps_exec_runline(), (char*)NULL );
1957 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", pnd_apps_exec_runline() );
1969 #define MAXTOUCH 100
1970 ui_touch_t ui_touchrects [ MAXTOUCH ];
1971 unsigned char ui_touchrect_count = 0;
1973 void ui_register_reset ( void ) {
1974 bzero ( ui_touchrects, sizeof(ui_touch_t)*MAXTOUCH );
1975 ui_touchrect_count = 0;
1979 void ui_register_tab ( unsigned char catnum, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
1981 if ( ui_touchrect_count == MAXTOUCH ) {
1985 ui_touchrects [ ui_touchrect_count ].r.x = x;
1986 ui_touchrects [ ui_touchrect_count ].r.y = y;
1987 ui_touchrects [ ui_touchrect_count ].r.w = w;
1988 ui_touchrects [ ui_touchrect_count ].r.h = h;
1989 ui_touchrects [ ui_touchrect_count ].catnum = catnum;
1990 ui_touchrect_count++;
1995 void ui_register_app ( mm_appref_t *app, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
1997 if ( ui_touchrect_count == MAXTOUCH ) {
2001 ui_touchrects [ ui_touchrect_count ].r.x = x;
2002 ui_touchrects [ ui_touchrect_count ].r.y = y;
2003 ui_touchrects [ ui_touchrect_count ].r.w = w;
2004 ui_touchrects [ ui_touchrect_count ].r.h = h;
2005 ui_touchrects [ ui_touchrect_count ].ref = app;
2006 ui_touchrect_count++;
2011 void ui_touch_act ( unsigned int x, unsigned int y ) {
2016 for ( i = 0; i < ui_touchrect_count; i++ ) {
2017 t = &(ui_touchrects [ i ]);
2019 if ( x >= t -> r.x &&
2020 x <= t -> r.x + t -> r.w &&
2022 y <= t -> r.y + t -> r.h
2027 ui_selected = t -> ref;
2030 if ( ui_category != t -> catnum ) {
2033 ui_category = t -> catnum;
2034 render_mask |= CHANGED_CATEGORY;
2045 unsigned char ui_forkexec ( char *argv[] ) {
2046 char *fooby = argv[0];
2049 if ( ( x = fork() ) < 0 ) {
2050 pnd_log ( pndn_error, "ERROR: Couldn't fork() for '%s'\n", fooby );
2054 if ( x == 0 ) { // child
2055 execv ( fooby, argv );
2056 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", fooby );
2064 unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ) {
2066 if ( ! cache_preview ( p, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
2067 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
2070 pnd_log ( pndn_debug, "THREAD: Couldn't load preview pic: '%s' -> '%s'\n",
2071 IFNULL(p->title_en,"No Name"), p -> preview_pic1 );
2074 // trigger that we completed
2076 bzero ( &e, sizeof(SDL_Event) );
2077 e.type = SDL_USEREVENT;
2078 e.user.code = sdl_user_finishedpreview;
2080 SDL_PushEvent ( &e );
2085 SDL_Thread *g_icon_thread = NULL;
2086 void ui_post_scan ( void ) {
2088 // if deferred icon load, kick off the thread now
2089 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 1 ) {
2091 g_icon_thread = SDL_CreateThread ( (void*)ui_threaded_defered_icon, NULL );
2093 if ( ! g_icon_thread ) {
2094 pnd_log ( pndn_error, "ERROR: Couldn't create icon thread\n" );
2097 } // deferred icon load
2102 unsigned char ui_threaded_defered_icon ( void *p ) {
2103 extern pnd_box_handle g_active_apps;
2104 pnd_box_handle h = g_active_apps;
2106 unsigned char maxwidth, maxheight;
2107 maxwidth = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_ICON_MAX_WIDTH, 50 );
2108 maxheight = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_ICON_MAX_HEIGHT, 50 );
2110 pnd_disco_t *iter = pnd_box_get_head ( h );
2115 if ( iter -> pnd_icon_pos &&
2116 ! cache_icon ( iter, maxwidth, maxheight ) )
2118 pnd_log ( pndn_warning, " Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2121 // trigger that we completed
2123 bzero ( &e, sizeof(SDL_Event) );
2124 e.type = SDL_USEREVENT;
2125 e.user.code = sdl_user_finishedicon;
2126 SDL_PushEvent ( &e );
2128 //pnd_log ( pndn_warning, " Finished deferred load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2129 usleep ( pnd_conf_get_as_int_d ( g_conf, "minimenu.defer_icon_us", 50000 ) );
2134 iter = pnd_box_get_next ( iter );
2140 void ui_show_hourglass ( unsigned char updaterect ) {
2143 SDL_Surface *s = g_imagecache [ IMG_HOURGLASS ].i;
2145 dest.x = ( 800 - s -> w ) / 2;
2146 dest.y = ( 480 - s -> h ) / 2;
2148 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, &dest );
2151 SDL_UpdateRects ( sdl_realscreen, 1, &dest );