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_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 );
250 // scale text hilight
251 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 );
252 // scale preview no-pic
253 g_imagecache [ IMG_PREVIEW_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_PREVIEW_MISSING ].i,
254 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ),
255 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 50 ) );
257 // set alpha on detail panel
258 //SDL_SetAlpha ( g_imagecache [ IMG_DETAIL_BG ].i, SDL_SRCALPHA, pnd_conf_get_as_int_d ( g_conf, "display.detail_bg_alpha", 50 ) );
263 void ui_render ( void ) {
266 // divide width: 550 / 250
267 // divide left side: 5 columns == 110px width
268 // 20px buffer either side == 70px wide icon + 20 + 20?
270 // what jobs to do during render?
274 #define R_TABS (1<<1)
275 #define R_DETAIL (1<<2)
276 #define R_GRID (1<<3)
278 #define R_ALL (R_BG|R_TABS|R_DETAIL|R_GRID)
280 unsigned int render_jobs_b = 0;
282 if ( render_mask & CHANGED_EVERYTHING ) {
283 render_jobs_b |= R_ALL;
286 if ( render_mask & CHANGED_SELECTION ) {
287 render_jobs_b |= R_GRID;
288 render_jobs_b |= R_DETAIL;
291 if ( render_mask & CHANGED_CATEGORY ) {
292 render_jobs_b |= R_ALL;
295 render_mask = CHANGED_NOTHING;
299 unsigned int icon_rows;
302 SDL_Rect rects [ MAXRECTS ], src;
303 SDL_Rect *dest = rects;
304 bzero ( dest, sizeof(SDL_Rect)*MAXRECTS );
306 unsigned int row, displayrow, col;
307 mm_appref_t *appiter;
309 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
311 unsigned char row_max = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_ROWMAX, 4 );
312 unsigned char col_max = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_COLMAX, 5 );
314 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
315 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
316 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
317 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
319 unsigned int grid_offset_x = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_x" );
320 unsigned int grid_offset_y = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_y" );
322 unsigned int icon_offset_x = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_x" );
323 unsigned int icon_offset_y = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_y" );
324 unsigned int icon_max_width = pnd_conf_get_as_int ( g_conf, "grid.icon_max_width" );
325 unsigned int icon_max_height = pnd_conf_get_as_int ( g_conf, "grid.icon_max_height" );
326 unsigned int sel_icon_offset_x = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_x", 0 );
327 unsigned int sel_icon_offset_y = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_y", 0 );
329 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
330 unsigned int text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
331 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "grid.text_offset_x" );
332 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_offset_y" );
334 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "grid.cell_width" );
335 unsigned int cell_height = pnd_conf_get_as_int ( g_conf, "grid.cell_height" );
337 // how many total rows do we need?
338 icon_rows = g_categories [ ui_category ].refcount / col_max;
339 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
343 // if no selected app yet, select the first one
345 if ( ! ui_selected ) {
346 ui_selected = g_categories [ ui_category ].refs;
350 // reset touchscreen regions
353 // ensure selection is visible
356 int index = ui_selected_index();
357 int topleft = col_max * ui_rows_scrolled_down;
358 int botright = ( col_max * ( ui_rows_scrolled_down + row_max ) - 1 );
360 //pnd_log ( PND_LOG_DEFAULT, "index %u tl %u br %u\n", index, topleft, botright );
362 if ( index < topleft ) {
363 ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
364 render_jobs_b |= R_ALL;
365 } else if ( index > botright ) {
366 ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
367 render_jobs_b |= R_ALL;
370 if ( ui_rows_scrolled_down < 0 ) {
371 ui_rows_scrolled_down = 0;
372 } else if ( ui_rows_scrolled_down > icon_rows ) {
373 ui_rows_scrolled_down = icon_rows;
379 if ( render_jobs_b & R_BG ) {
381 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
384 dest -> w = sdl_realscreen -> w;
385 dest -> h = sdl_realscreen -> h;
386 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
391 if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
394 dest -> w = sdl_realscreen -> w;
395 dest -> h = sdl_realscreen -> h;
396 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
403 if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
404 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
405 unsigned int tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
406 unsigned int tab_selheight = pnd_conf_get_as_int ( g_conf, "tabs.tab_selheight" );
407 unsigned int tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
408 unsigned int tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
409 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
410 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
411 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
412 unsigned int maxtab = ( screen_width / tab_width ) < g_categorycount ? ( screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift;
413 unsigned int maxtabspot = ( screen_width / tab_width );
415 // draw tabs with categories
416 for ( col = ui_catshift;
422 if ( col == ui_category ) {
423 s = g_imagecache [ IMG_TAB_SEL ].i;
425 s = g_imagecache [ IMG_TAB_UNSEL ].i;
432 if ( col == ui_category ) {
433 src.h = tab_selheight;
437 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
438 dest -> y = tab_offset_y;
441 ui_register_tab ( col, dest -> x, dest -> y, tab_width, tab_height );
443 if ( render_jobs_b & R_TABS ) {
444 //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
445 SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
449 if ( col == ui_category ) {
450 // no line for selected tab
452 if ( col - ui_catshift == 0 ) {
453 s = g_imagecache [ IMG_TAB_LINEL ].i;
454 } else if ( col - ui_catshift == maxtabspot - 1 ) {
455 s = g_imagecache [ IMG_TAB_LINER ].i;
457 s = g_imagecache [ IMG_TAB_LINE ].i;
459 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
460 dest -> y = tab_offset_y + tab_height;
461 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
467 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
468 rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ].catname, tmpfontcolor );
471 src.w = rtext -> w < text_width ? rtext -> w : text_width;
473 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
474 dest -> y = tab_offset_y + text_offset_y;
475 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
476 SDL_FreeSurface ( rtext );
483 if ( render_jobs_b & R_TABS ) {
485 // draw tab lines under where tabs would be if we had categories
486 for ( /* foo */; col < maxtabspot; col++ ) {
489 if ( col - ui_catshift == 0 ) {
490 s = g_imagecache [ IMG_TAB_LINEL ].i;
491 } else if ( col - ui_catshift == maxtabspot - 1 ) {
492 s = g_imagecache [ IMG_TAB_LINER ].i;
494 s = g_imagecache [ IMG_TAB_LINE ].i;
496 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
497 dest -> y = tab_offset_y + tab_height;
498 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
507 // scroll bars and arrows
508 if ( render_jobs_b & R_BG ) {
509 unsigned char show_bar = 0;
512 if ( ui_rows_scrolled_down && g_imagecache [ IMG_ARROW_UP ].i ) {
513 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
514 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
515 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
522 if ( ui_rows_scrolled_down + row_max < icon_rows && g_imagecache [ IMG_ARROW_DOWN ].i ) {
523 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
524 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
525 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
532 // show scrollbar as well
535 src.w = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_w", 10 );
536 src.h = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_h", 100 );
537 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
538 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
539 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
543 } // r_bg, scroll bars
545 // render detail pane bg
546 if ( render_jobs_b & R_DETAIL ) {
548 if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
551 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
552 src.x = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
553 src.y = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
554 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
555 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
556 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
557 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
558 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
562 // render detail pane
563 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
564 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
565 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
566 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
570 } // detailpane frame/bg
574 // anything to render?
575 if ( render_jobs_b & R_GRID ) {
577 // if just rendering grid, and nothing else, better clear it first
578 if ( ! ( render_jobs_b & R_BG ) ) {
579 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
580 src.x = grid_offset_x;
581 src.y = grid_offset_y + sel_icon_offset_y;
582 src.w = col_max * cell_width;
583 src.h = row_max * cell_height;
585 dest -> x = grid_offset_x;
586 dest -> y = grid_offset_y + sel_icon_offset_y;
588 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
594 if ( g_categories [ ui_category ].refs ) {
596 appiter = g_categories [ ui_category ].refs;
600 // until we run out of apps, or run out of space
601 while ( appiter != NULL ) {
603 for ( col = 0; col < col_max && appiter != NULL; col++ ) {
605 // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
606 if ( row >= ui_rows_scrolled_down ) {
608 // selected? show hilights
609 if ( appiter == ui_selected ) {
610 SDL_Surface *s = g_imagecache [ IMG_SELECTED_ALPHAMASK ].i;
612 //dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + ( ( icon_max_width - s -> w ) / 2 );
613 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + sel_icon_offset_x;
614 //dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + ( ( icon_max_height - s -> h ) / 2 );
615 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + sel_icon_offset_y;
616 SDL_BlitSurface ( s, NULL /* all */, sdl_realscreen, dest );
619 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
620 dest -> y = grid_offset_y + ( displayrow * cell_height ) + pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
621 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
626 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
627 SDL_Surface *iconsurface;
629 iconsurface = ic -> i;
631 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
632 iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
635 //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
641 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + (( icon_max_width - iconsurface -> w ) / 2);
642 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + (( icon_max_height - iconsurface -> h ) / 2);
644 SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
647 ui_register_app ( appiter, dest -> x, dest -> y, src.w, src.h );
654 if ( appiter -> ref -> title_en ) {
656 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
657 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, tmpfontcolor );
660 src.w = text_width < rtext -> w ? text_width : rtext -> w;
662 if ( rtext -> w > text_width ) {
663 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
665 dest -> x = grid_offset_x + ( col * cell_width ) + text_offset_x - ( rtext -> w / 2 );
667 dest -> y = grid_offset_y + ( displayrow * cell_height ) + text_offset_y;
668 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
669 SDL_FreeSurface ( rtext );
673 } // display now? or scrolled away..
676 appiter = appiter -> next;
678 } // for column 1...X
680 if ( row >= ui_rows_scrolled_down ) {
686 // are we done displaying rows?
687 if ( displayrow >= row_max ) {
694 // no apps to render?
695 pnd_log ( pndn_rem, "No applications to render?\n" );
701 if ( ui_selected && render_jobs_b & R_DETAIL ) {
703 unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
704 unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
705 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "detailtext.cell_width" );
707 unsigned int desty = cell_offset_y;
712 if ( ui_selected -> ref -> title_en ) {
714 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
715 rtext = TTF_RenderText_Blended ( g_detailtext_font, ui_selected -> ref -> title_en, tmpfontcolor );
718 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
720 dest -> x = cell_offset_x;
722 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
723 SDL_FreeSurface ( rtext );
730 if ( ui_selected -> ref -> main_category ) {
732 sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
735 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
736 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
739 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
741 dest -> x = cell_offset_x;
743 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
744 SDL_FreeSurface ( rtext );
751 if ( ui_selected -> ref -> clockspeed ) {
753 sprintf ( buffer, "CPU Clock: %s", ui_selected -> ref -> clockspeed );
756 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
757 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
760 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
762 dest -> x = cell_offset_x;
764 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
765 SDL_FreeSurface ( rtext );
770 // show sub-app# on right side of cpu clock?
771 //if ( ui_selected -> ref -> subapp_number )
773 sprintf ( buffer, "(app#%u)", ui_selected -> ref -> subapp_number );
776 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
777 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
778 dest -> x = cell_offset_x + cell_width - rtext -> w;
779 dest -> y = desty - src.h;
780 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
781 SDL_FreeSurface ( rtext );
786 #if 0 // merged into hint-line
787 if ( ui_selected -> ref -> info_filename ) {
789 sprintf ( buffer, "Documentation - hit Y" );
792 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
793 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
796 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
798 dest -> x = cell_offset_x;
800 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
801 SDL_FreeSurface ( rtext );
808 if ( ui_selected -> ovrh ) {
813 desty += 5; // a touch of spacing can't hurt
815 for ( i = 1; i < 4; i++ ) {
816 sprintf ( buffer, "Application-%u.note-%u", ui_selected -> ref -> subapp_number, i );
817 n = pnd_conf_get_as_char ( ui_selected -> ovrh, buffer );
821 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
822 rtext = TTF_RenderText_Blended ( g_detailtext_font, n, tmpfontcolor );
825 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
827 dest -> x = cell_offset_x;
829 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
830 SDL_FreeSurface ( rtext );
836 } // r_detail -> notes
839 mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
840 SDL_Surface *previewpic;
843 previewpic = ic -> i;
845 previewpic = g_imagecache [ IMG_PREVIEW_MISSING ].i;
849 dest -> x = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_x", 50 ) +
850 ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
851 dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
852 SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
856 } // r_detail && selected?
862 if ( render_jobs_b & R_BG ) {
863 static int last_battlevel = 0;
864 static unsigned char batterylevel = 0;
867 if ( time ( NULL ) - last_battlevel > 60 ) {
868 batterylevel = pnd_device_get_battery_gauge_perc();
869 last_battlevel = time ( NULL );
872 sprintf ( buffer, "Battery: %u%%", batterylevel );
875 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
876 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
877 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.battery_x", 20 );
878 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.battery_y", 450 );
879 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
880 SDL_FreeSurface ( rtext );
885 if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
887 unsigned int hintx, hinty;
888 hintx = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
889 hinty = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
890 static unsigned int lastwidth = 3000;
892 if ( ui_selected && ui_selected -> ref -> info_filename ) {
893 buffer = "Documentation - hit Y";
895 buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
899 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
900 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
903 if ( ! ( render_jobs_b & R_BG ) ) {
910 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, &src, sdl_realscreen, dest );
912 lastwidth = rtext -> w;
918 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
919 SDL_FreeSurface ( rtext );
924 if ( render_jobs_b & R_BG &&
925 pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 )
929 time_t t = time ( NULL );
930 struct tm *tm = localtime ( &t );
931 strftime ( buffer, 50, "%a %H:%M %F", tm );
934 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
935 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
936 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.clock_x", 700 );
937 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.clock_y", 450 );
938 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
939 SDL_FreeSurface ( rtext );
943 // update all the rects and send it all to sdl
944 // - at this point, we could probably just do 1 rect, of the
945 // whole screen, and be faster :/
946 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
950 void ui_process_input ( unsigned char block_p ) {
953 unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
954 //static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
956 while ( ! ui_event &&
957 block_p ? SDL_WaitEvent ( &event ) : SDL_PollEvent ( &event ) )
960 switch ( event.type ) {
965 if ( event.user.code == sdl_user_ticker ) {
967 // timer went off, time to load something
968 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
970 // load the preview pics now!
971 pnd_disco_t *iter = ui_selected -> ref;
973 if ( iter -> preview_pic1 ) {
975 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.threaded_preview", 0 ) ) {
976 // load in bg thread, make user experience chuggy
978 g_preview_thread = SDL_CreateThread ( (void*)ui_threaded_defered_preview, iter );
980 if ( ! g_preview_thread ) {
981 pnd_log ( pndn_error, "ERROR: Couldn't create preview thread\n" );
985 // load it now, make user wait
987 if ( ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
988 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
991 pnd_log ( pndn_debug, " Couldn't load preview pic: '%s' -> '%s'\n",
992 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
997 } // got a preview at all?
1002 } else if ( event.user.code == sdl_user_finishedpreview ) {
1004 // if we just finished the one we happen to be looking at, better redraw now; otherwise, if
1005 // we finished another, no big woop
1006 if ( ui_selected && event.user.data1 == ui_selected -> ref ) {
1010 } else if ( event.user.code == sdl_user_finishedicon ) {
1011 // redraw, so we can show the newly loaded icon
1016 render_mask |= CHANGED_EVERYTHING;
1020 #if 0 // joystick motion
1021 case SDL_JOYAXISMOTION:
1023 pnd_log ( PND_LOG_DEFAULT, "joystick axis\n" );
1025 if ( event.jaxis.axis == 0 ) {
1027 if ( event.jaxis.value < 0 ) {
1029 pnd_log ( PND_LOG_DEFAULT, "joystick axis - LEFT\n" );
1030 } else if ( event.jaxis.value > 0 ) {
1031 ui_push_right ( 0 );
1032 pnd_log ( PND_LOG_DEFAULT, "joystick axis - RIGHT\n" );
1034 } else if ( event.jaxis.axis == 1 ) {
1036 if ( event.jaxis.value < 0 ) {
1038 } else if ( event.jaxis.value > 0 ) {
1048 #if 0 // joystick buttons
1049 case SDL_JOYBUTTONDOWN:
1051 pnd_log ( PND_LOG_DEFAULT, "joystick button down %u\n", event.jbutton.button );
1053 if ( event.jbutton.button == 0 ) { // B
1055 } else if ( event.jbutton.button == 1 ) { // Y
1057 } else if ( event.jbutton.button == 2 ) { // X
1059 } else if ( event.jbutton.button == 3 ) { // A
1062 } else if ( event.jbutton.button == 4 ) { // Select
1063 ui_mask |= uisb_select;
1064 } else if ( event.jbutton.button == 5 ) { // Start
1065 ui_mask |= uisb_start;
1067 } else if ( event.jbutton.button == 7 ) { // L
1069 } else if ( event.jbutton.button == 8 ) { // R
1078 case SDL_JOYBUTTONUP:
1080 pnd_log ( PND_LOG_DEFAULT, "joystick button up %u\n", event.jbutton.button );
1082 if ( event.jbutton.button == 0 ) { // B
1085 } else if ( event.jbutton.button == 1 ) { // Y
1087 } else if ( event.jbutton.button == 2 ) { // X
1089 } else if ( event.jbutton.button == 3 ) { // A
1092 } else if ( event.jbutton.button == 4 ) { // Select
1093 ui_mask &= ~uisb_select;
1094 } else if ( event.jbutton.button == 5 ) { // Start
1095 ui_mask &= ~uisb_start;
1097 } else if ( event.jbutton.button == 7 ) { // L
1100 } else if ( event.jbutton.button == 8 ) { // R
1111 #if 1 // keyboard events
1114 //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
1116 // SDLK_LALT -> Start
1119 if ( event.key.keysym.sym == SDLK_RIGHT ) {
1120 ui_push_right ( 0 );
1122 } else if ( event.key.keysym.sym == SDLK_LEFT ) {
1125 } else if ( event.key.keysym.sym == SDLK_UP ) {
1128 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1131 } else if ( event.key.keysym.sym == SDLK_SPACE || event.key.keysym.sym == SDLK_END ) {
1134 } else if ( event.key.keysym.sym == SDLK_z || event.key.keysym.sym == SDLK_RSHIFT ) {
1137 } else if ( event.key.keysym.sym == SDLK_x || event.key.keysym.sym == SDLK_RCTRL ) {
1140 } else if ( event.key.keysym.sym == SDLK_y || event.key.keysym.sym == SDLK_PAGEUP ) {
1142 if ( ui_selected ) {
1143 ui_show_info ( pnd_run_script, ui_selected -> ref );
1147 } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
1151 } else if ( event.key.keysym.sym == SDLK_LCTRL /*LALT*/ ) { // select button
1152 char *opts [ 20 ] = {
1153 "Return to Minimenu",
1155 "Rescan for Applications",
1156 "Cache previews to SD now",
1157 "Run xfce4 from Minimenu",
1158 "Run a terminal/console",
1159 "Exit and run xfce4",
1160 "Exit and run pmenu",
1164 int sel = ui_modal_single_menu ( opts, 9, "Minimenu", "Enter to select; other to return." );
1166 char buffer [ 100 ];
1169 } else if ( sel == 1 ) {
1171 sprintf ( buffer, "sudo poweroff" );
1173 } else if ( sel == 2 ) {
1175 pnd_log ( pndn_debug, "Freeing up applications\n" );
1176 applications_free();
1177 pnd_log ( pndn_debug, "Rescanning applications\n" );
1178 applications_scan();
1181 ui_rows_scrolled_down = 0;
1182 } else if ( sel == 3 ) {
1183 // cache preview to SD now
1184 extern pnd_box_handle g_active_apps;
1185 pnd_box_handle h = g_active_apps;
1187 unsigned int maxwidth, maxheight;
1188 maxwidth = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 );
1189 maxheight = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 );
1191 pnd_disco_t *iter = pnd_box_get_head ( h );
1196 if ( ! cache_preview ( iter, maxwidth, maxheight ) ) {
1197 pnd_log ( pndn_debug, "Force cache: Couldn't load preview pic: '%s' -> '%s'\n",
1198 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1202 iter = pnd_box_get_next ( iter );
1205 } else if ( sel == 4 ) {
1207 char buffer [ PATH_MAX ];
1208 sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/bin/startxfce4" );
1209 emit_and_quit ( buffer );
1210 } else if ( sel == 5 ) {
1213 argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
1217 ui_forkexec ( argv );
1220 } else if ( sel == 6 ) {
1222 sprintf ( buffer, "echo startxfce4 > /tmp/gui.load" );
1224 emit_and_quit ( buffer );
1225 //sprintf ( buffer, "sudo poweroff" );
1226 //system ( buffer );
1228 } else if ( sel == 7 ) {
1230 sprintf ( buffer, "echo pmenu > /tmp/gui.load" );
1232 emit_and_quit ( buffer );
1233 //sprintf ( buffer, "sudo poweroff" );
1234 //system ( buffer );
1236 } else if ( sel == 8 ) {
1237 emit_and_quit ( MM_QUIT );
1238 } else if ( sel == 9 ) {
1243 render_mask |= CHANGED_EVERYTHING;
1247 if ( event.key.keysym.sym == SDLK_q ) {
1248 emit_and_quit ( MM_QUIT );
1254 #if 1 // mouse / touchscreen
1256 case SDL_MOUSEBUTTONDOWN:
1257 if ( event.button.button == SDL_BUTTON_LEFT ) {
1258 cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
1264 case SDL_MOUSEBUTTONUP:
1265 if ( event.button.button == SDL_BUTTON_LEFT ) {
1266 ui_touch_act ( event.button.x, event.button.y );
1279 } // switch event type
1286 void ui_push_left ( unsigned char forcecoil ) {
1288 if ( ! ui_selected ) {
1289 ui_push_right ( 0 );
1293 // what column we in?
1294 unsigned int col = ui_determine_screen_col ( ui_selected );
1296 // are we alreadt at first item?
1297 if ( forcecoil == 0 &&
1298 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1301 unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1303 ui_push_right ( 0 );
1307 } else if ( g_categories [ ui_category ].refs == ui_selected ) {
1308 // can't go any more left, we're at the head
1311 // figure out the previous item; yay for singly linked list :/
1312 mm_appref_t *i = g_categories [ ui_category ].refs;
1314 if ( i -> next == ui_selected ) {
1322 ui_set_selected ( ui_selected );
1327 void ui_push_right ( unsigned char forcecoil ) {
1329 if ( ui_selected ) {
1331 // what column we in?
1332 unsigned int col = ui_determine_screen_col ( ui_selected );
1335 if ( forcecoil == 0 &&
1336 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1337 col == pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1 )
1340 unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1347 // just go to the next
1349 if ( ui_selected -> next ) {
1350 ui_selected = ui_selected -> next;
1356 ui_selected = g_categories [ ui_category ].refs;
1359 ui_set_selected ( ui_selected );
1364 void ui_push_up ( void ) {
1365 unsigned char col_max = pnd_conf_get_as_int ( g_conf, MMENU_DISP_COLMAX );
1367 if ( ! ui_selected ) {
1372 unsigned int row = ui_determine_row ( ui_selected );
1375 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 1 ) == 0 )
1377 // wrap around instead
1379 unsigned int col = ui_determine_screen_col ( ui_selected );
1382 ui_selected = g_categories [ ui_category ].refs;
1383 while ( ui_selected -> next ) {
1384 ui_selected = ui_selected -> next;
1387 // try to move to same column
1388 unsigned int newcol = ui_determine_screen_col ( ui_selected );
1389 if ( newcol > col ) {
1397 // scroll down to show it
1398 int r = ui_determine_row ( ui_selected ) - 1;
1399 if ( r - pnd_conf_get_as_int ( g_conf, MMENU_DISP_ROWMAX ) > 0 ) {
1400 ui_rows_scrolled_down = (unsigned int) r;
1404 // stop at top/bottom
1416 void ui_push_down ( void ) {
1417 unsigned char col_max = pnd_conf_get_as_int ( g_conf, MMENU_DISP_COLMAX );
1419 if ( ui_selected ) {
1422 unsigned int row = ui_determine_row ( ui_selected );
1425 unsigned int icon_rows = g_categories [ ui_category ].refcount / col_max;
1426 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
1431 if ( row == ( icon_rows - 1 ) &&
1432 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 1 ) == 0 )
1435 unsigned char col = ui_determine_screen_col ( ui_selected );
1437 ui_selected = g_categories [ ui_category ].refs;
1440 ui_selected = ui_selected -> next;
1444 ui_rows_scrolled_down = 0;
1449 ui_push_right ( 1 );
1456 ui_push_right ( 0 );
1462 void ui_push_exec ( void ) {
1464 if ( ui_selected ) {
1465 pnd_apps_exec_disco ( pnd_run_script, ui_selected -> ref, PND_EXEC_OPTION_NORUN, NULL );
1466 char buffer [ PATH_MAX ];
1467 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1468 emit_and_quit ( buffer );
1474 void ui_push_ltrigger ( void ) {
1475 unsigned char oldcat = ui_category;
1477 if ( ui_category > 0 ) {
1480 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1481 ui_category = g_categorycount - 1;
1485 if ( oldcat != ui_category ) {
1487 ui_set_selected ( ui_selected );
1490 // make tab visible?
1491 if ( ui_catshift > 0 && ui_category == ui_catshift - 1 ) {
1496 ui_rows_scrolled_down = 0;
1498 render_mask |= CHANGED_CATEGORY;
1503 void ui_push_rtrigger ( void ) {
1504 unsigned char oldcat = ui_category;
1506 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
1507 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1509 if ( ui_category < ( g_categorycount - 1 ) ) {
1512 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1517 if ( oldcat != ui_category ) {
1519 ui_set_selected ( ui_selected );
1522 // make tab visible?
1523 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
1528 ui_rows_scrolled_down = 0;
1530 render_mask |= CHANGED_CATEGORY;
1535 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ) {
1536 double scale = 1000000.0;
1537 double scalex = 1000000.0;
1538 double scaley = 1000000.0;
1539 SDL_Surface *scaled;
1541 scalex = (double)maxwidth / (double)s -> w;
1543 if ( maxheight == -1 ) {
1546 scaley = (double)maxheight / (double)s -> h;
1548 if ( scaley < scalex ) {
1556 scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
1557 SDL_FreeSurface ( s );
1563 void ui_loadscreen ( void ) {
1567 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1568 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1569 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1570 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1573 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1577 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1578 rtext = TTF_RenderText_Blended ( g_big_font, "Setting up menu...", tmpfontcolor );
1581 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1582 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1583 SDL_FreeSurface ( rtext );
1588 void ui_discoverscreen ( unsigned char clearscreen ) {
1592 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1593 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1594 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1595 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1598 if ( clearscreen ) {
1599 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1601 // render background
1602 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1605 dest.w = sdl_realscreen -> w;
1606 dest.h = sdl_realscreen -> h;
1607 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1608 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1615 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1616 rtext = TTF_RenderText_Blended ( g_big_font, "Looking for applications...", tmpfontcolor );
1617 if ( clearscreen ) {
1624 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1625 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1626 SDL_FreeSurface ( rtext );
1629 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1630 dest.x = rtext -> w + 30;
1632 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, &dest );
1633 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1639 void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
1641 SDL_Rect rects [ 4 ];
1642 SDL_Rect *dest = rects;
1644 bzero ( dest, sizeof(SDL_Rect)* 4 );
1646 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1647 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1648 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1649 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1651 static unsigned int stepx = 0;
1654 if ( clearscreen ) {
1655 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1657 // render background
1658 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1661 dest -> w = sdl_realscreen -> w;
1662 dest -> h = sdl_realscreen -> h;
1663 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1669 // render background
1670 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1673 src.w = sdl_realscreen -> w;
1677 dest -> w = sdl_realscreen -> w;
1678 dest -> h = sdl_realscreen -> h;
1679 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
1687 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1688 rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
1691 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1692 SDL_FreeSurface ( rtext );
1696 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1697 dest -> x = rtext -> w + 30 + stepx;
1699 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, dest );
1705 rtext = TTF_RenderText_Blended ( g_tab_font, filename, tmpfontcolor );
1708 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1709 SDL_FreeSurface ( rtext );
1716 if ( stepx > 350 ) {
1720 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1725 int ui_selected_index ( void ) {
1727 if ( ! ui_selected ) {
1728 return ( -1 ); // no index
1731 mm_appref_t *r = g_categories [ ui_category ].refs;
1734 if ( r == ui_selected ) {
1744 static mm_appref_t *timer_ref = NULL;
1745 void ui_set_selected ( mm_appref_t *r ) {
1747 render_mask |= CHANGED_SELECTION;
1749 if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1750 return; // no desire to defer anything
1755 SDL_SetTimer ( 0, NULL );
1760 SDL_SetTimer ( pnd_conf_get_as_int_d ( g_conf, "previewpic.defer_timer_ms", 1000 ), ui_callback_f );
1766 unsigned int ui_callback_f ( unsigned int t ) {
1768 if ( ui_selected != timer_ref ) {
1769 return ( 0 ); // user has moved it, who cares
1773 bzero ( &e, sizeof(SDL_Event) );
1774 e.type = SDL_USEREVENT;
1775 e.user.code = sdl_user_ticker;
1776 SDL_PushEvent ( &e );
1781 int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer ) {
1782 SDL_Rect rects [ 40 ];
1783 SDL_Rect *dest = rects;
1787 bzero ( rects, sizeof(SDL_Rect) * 40 );
1789 unsigned int sel = 0;
1791 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1792 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1793 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1794 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1796 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1798 SDL_Color selfontcolor = { 0/*font_rgba_r*/, font_rgba_g, font_rgba_b, font_rgba_a };
1806 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1807 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1808 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
1809 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
1810 SDL_FillRect( sdl_realscreen, dest, 0 );
1812 // show dialog background
1813 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
1814 src.x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1815 src.y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1816 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
1817 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
1818 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1819 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1820 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1821 // repeat for darken?
1822 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1823 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1824 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1828 // show dialog frame
1829 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
1830 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1831 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1832 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
1833 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1839 rtext = TTF_RenderText_Blended ( g_tab_font, title, tmpfontcolor );
1840 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1841 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
1842 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1843 SDL_FreeSurface ( rtext );
1849 rtext = TTF_RenderText_Blended ( g_tab_font, footer, tmpfontcolor );
1850 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1851 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
1852 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
1854 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1855 SDL_FreeSurface ( rtext );
1860 for ( i = 0; i < argc; i++ ) {
1864 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
1866 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], tmpfontcolor );
1868 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1869 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 ) );
1870 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1871 SDL_FreeSurface ( rtext );
1876 // update all the rects and send it all to sdl
1877 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1881 while ( SDL_WaitEvent ( &event ) ) {
1883 switch ( event.type ) {
1887 if ( event.key.keysym.sym == SDLK_UP ) {
1891 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1892 if ( sel < argc - 1 ) {
1896 } else if ( event.key.keysym.sym == SDLK_RETURN ) {
1899 } else if ( event.key.keysym.sym == SDLK_q ) {
1903 return ( -1 ); // nada
1918 unsigned char ui_determine_row ( mm_appref_t *a ) {
1919 unsigned int row = 0;
1921 mm_appref_t *i = g_categories [ ui_category ].refs;
1926 row /= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
1931 unsigned char ui_determine_screen_row ( mm_appref_t *a ) {
1932 return ( ui_determine_row ( a ) % pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 5 ) );
1935 unsigned char ui_determine_screen_col ( mm_appref_t *a ) {
1936 unsigned int col = 0;
1938 mm_appref_t *i = g_categories [ ui_category ].refs;
1943 col %= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
1948 unsigned char ui_show_info ( char *pndrun, pnd_disco_t *p ) {
1949 char *viewer, *searchpath;
1950 pnd_conf_handle desktoph;
1953 searchpath = pnd_conf_query_searchpath();
1955 desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
1961 viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
1964 return ( 0 ); // no way to view the file
1968 if ( ! p -> unique_id ) {
1972 if ( ! p -> info_filename ) {
1976 if ( ! p -> info_name ) {
1987 if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) {
1988 snprintf ( pargs, 1001, "%s %s",
1989 pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
1994 char pndfile [ 1024 ];
1995 if ( p -> object_type == pnd_object_type_directory ) {
1996 // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
1997 strncpy ( pndfile, p -> object_path, 1000 );
1998 } else if ( p -> object_type == pnd_object_type_pnd ) {
1999 // pnd_run.sh wants the full path and filename for the .pnd file
2000 snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
2003 if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs,
2004 p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) )
2009 pnd_log ( pndn_debug, "Info Exec=%s\n", pnd_apps_exec_runline() );
2013 if ( ( x = fork() ) < 0 ) {
2014 pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
2019 execl ( "/bin/sh", "/bin/sh", "-c", pnd_apps_exec_runline(), (char*)NULL );
2020 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", pnd_apps_exec_runline() );
2032 #define MAXTOUCH 100
2033 ui_touch_t ui_touchrects [ MAXTOUCH ];
2034 unsigned char ui_touchrect_count = 0;
2036 void ui_register_reset ( void ) {
2037 bzero ( ui_touchrects, sizeof(ui_touch_t)*MAXTOUCH );
2038 ui_touchrect_count = 0;
2042 void ui_register_tab ( unsigned char catnum, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2044 if ( ui_touchrect_count == MAXTOUCH ) {
2048 ui_touchrects [ ui_touchrect_count ].r.x = x;
2049 ui_touchrects [ ui_touchrect_count ].r.y = y;
2050 ui_touchrects [ ui_touchrect_count ].r.w = w;
2051 ui_touchrects [ ui_touchrect_count ].r.h = h;
2052 ui_touchrects [ ui_touchrect_count ].catnum = catnum;
2053 ui_touchrect_count++;
2058 void ui_register_app ( mm_appref_t *app, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2060 if ( ui_touchrect_count == MAXTOUCH ) {
2064 ui_touchrects [ ui_touchrect_count ].r.x = x;
2065 ui_touchrects [ ui_touchrect_count ].r.y = y;
2066 ui_touchrects [ ui_touchrect_count ].r.w = w;
2067 ui_touchrects [ ui_touchrect_count ].r.h = h;
2068 ui_touchrects [ ui_touchrect_count ].ref = app;
2069 ui_touchrect_count++;
2074 void ui_touch_act ( unsigned int x, unsigned int y ) {
2079 for ( i = 0; i < ui_touchrect_count; i++ ) {
2080 t = &(ui_touchrects [ i ]);
2082 if ( x >= t -> r.x &&
2083 x <= t -> r.x + t -> r.w &&
2085 y <= t -> r.y + t -> r.h
2090 ui_selected = t -> ref;
2093 if ( ui_category != t -> catnum ) {
2096 ui_category = t -> catnum;
2097 render_mask |= CHANGED_CATEGORY;
2108 unsigned char ui_forkexec ( char *argv[] ) {
2109 char *fooby = argv[0];
2112 if ( ( x = fork() ) < 0 ) {
2113 pnd_log ( pndn_error, "ERROR: Couldn't fork() for '%s'\n", fooby );
2117 if ( x == 0 ) { // child
2118 execv ( fooby, argv );
2119 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", fooby );
2127 unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ) {
2129 if ( ! cache_preview ( p, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
2130 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
2133 pnd_log ( pndn_debug, "THREAD: Couldn't load preview pic: '%s' -> '%s'\n",
2134 IFNULL(p->title_en,"No Name"), p -> preview_pic1 );
2137 // trigger that we completed
2139 bzero ( &e, sizeof(SDL_Event) );
2140 e.type = SDL_USEREVENT;
2141 e.user.code = sdl_user_finishedpreview;
2143 SDL_PushEvent ( &e );
2148 SDL_Thread *g_icon_thread = NULL;
2149 void ui_post_scan ( void ) {
2151 // if deferred icon load, kick off the thread now
2152 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 1 ) {
2154 g_icon_thread = SDL_CreateThread ( (void*)ui_threaded_defered_icon, NULL );
2156 if ( ! g_icon_thread ) {
2157 pnd_log ( pndn_error, "ERROR: Couldn't create icon thread\n" );
2160 } // deferred icon load
2165 unsigned char ui_threaded_defered_icon ( void *p ) {
2166 extern pnd_box_handle g_active_apps;
2167 pnd_box_handle h = g_active_apps;
2169 unsigned char maxwidth, maxheight;
2170 maxwidth = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_ICON_MAX_WIDTH, 50 );
2171 maxheight = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_ICON_MAX_HEIGHT, 50 );
2173 pnd_disco_t *iter = pnd_box_get_head ( h );
2178 if ( iter -> pnd_icon_pos &&
2179 ! cache_icon ( iter, maxwidth, maxheight ) )
2181 pnd_log ( pndn_warning, " Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2184 // trigger that we completed
2186 bzero ( &e, sizeof(SDL_Event) );
2187 e.type = SDL_USEREVENT;
2188 e.user.code = sdl_user_finishedicon;
2189 SDL_PushEvent ( &e );
2191 //pnd_log ( pndn_warning, " Finished deferred load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2192 usleep ( pnd_conf_get_as_int_d ( g_conf, "minimenu.defer_icon_us", 50000 ) );
2197 iter = pnd_box_get_next ( iter );
2203 void ui_show_hourglass ( unsigned char updaterect ) {
2206 SDL_Surface *s = g_imagecache [ IMG_HOURGLASS ].i;
2208 dest.x = ( 800 - s -> w ) / 2;
2209 dest.y = ( 480 - s -> h ) / 2;
2211 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, &dest );
2214 SDL_UpdateRects ( sdl_realscreen, 1, &dest );