11 #include "SDL_gfxPrimitives.h"
12 #include "SDL_rotozoom.h"
13 #include "SDL_thread.h"
16 #include "pnd_logger.h"
18 #include "pnd_container.h"
19 #include "pnd_discovery.h"
21 #include "pnd_device.h"
27 #include "mmwrapcmd.h"
31 SDL_Surface *sdl_realscreen = NULL;
32 unsigned int sdl_ticks = 0;
33 SDL_Thread *g_preview_thread = NULL;
35 enum { sdl_user_ticker = 0,
36 sdl_user_finishedpreview = 1,
37 sdl_user_finishedicon = 2,
42 unsigned short int g_scale = 1; // 1 == noscale
44 SDL_Surface *g_imgcache [ IMG_MAX ];
46 TTF_Font *g_big_font = NULL;
47 TTF_Font *g_grid_font = NULL;
48 TTF_Font *g_detailtext_font = NULL;
49 TTF_Font *g_tab_font = NULL;
51 extern pnd_conf_handle g_conf;
53 /* current display state
55 int ui_rows_scrolled_down = 0; // number of rows that should be missing from top of the display
56 mm_appref_t *ui_selected = NULL;
57 unsigned char ui_category = 0; // current category
58 unsigned char ui_catshift = 0; // how many cats are offscreen to the left
60 extern mm_category_t g_categories [ MAX_CATS ];
61 extern unsigned char g_categorycount;
63 static SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ); // height -1 means ignore
64 static int ui_selected_index ( void );
66 unsigned char ui_setup ( void ) {
71 SDL_Init ( SDL_INIT_EVERYTHING | SDL_INIT_NOPARACHUTE );
73 SDL_JoystickOpen ( 0 ); // turn on joy-0
75 SDL_WM_SetCaption ( "mmenu", "mmenu" );
77 // hide the mouse cursor if we can
78 if ( SDL_ShowCursor ( -1 ) == 1 ) {
85 unsigned int svm = SDL_SWSURFACE /*| SDL_FULLSCREEN*/ /* 0*/;
86 if ( pnd_conf_get_as_int_d ( g_conf, "display.fullscreen", 0 ) > 0 ) {
87 svm |= SDL_FULLSCREEN;
91 SDL_SetVideoMode ( 800 * g_scale, 480 * g_scale, 16 /*bpp*/, svm );
93 if ( ! sdl_realscreen ) {
94 pnd_log ( pndn_error, "ERROR: Couldn't open SDL real screen; dieing." );
98 pnd_log ( pndn_debug, "Pixel format:" );
99 pnd_log ( pndn_debug, "bpp b: %u\n", sdl_realscreen -> format -> BitsPerPixel );
100 pnd_log ( pndn_debug, "bpp B: %u\n", sdl_realscreen -> format -> BytesPerPixel );
101 pnd_log ( pndn_debug, "R mask: %08x\n", sdl_realscreen -> format -> Rmask );
102 pnd_log ( pndn_debug, "G mask: %08x\n", sdl_realscreen -> format -> Gmask );
103 pnd_log ( pndn_debug, "B mask: %08x\n", sdl_realscreen -> format -> Bmask );
109 /* Set 16-bit stereo audio at 22Khz */
110 fmt.freq = 44100; //22050;
111 fmt.format = AUDIO_S16; //AUDIO_S16;
113 fmt.samples = 2048; /* A good value for games */
114 fmt.callback = mixaudio;
117 /* Open the audio device and start playing sound! */
118 if ( SDL_OpenAudio ( &fmt, NULL ) < 0 ) {
119 zotlog ( "Unable to open audio: %s\n", SDL_GetError() );
123 SDL_PauseAudio ( 0 );
128 //IMG_Init ( IMG_INIT_JPG | IMG_INIT_PNG );
134 if ( TTF_Init() == -1 ) {
135 pnd_log ( pndn_error, "ERROR: Couldn't set up SDL TTF lib\n" );
136 return ( 0 ); // couldn't set up SDL TTF
139 char fullpath [ PATH_MAX ];
141 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "minimenu.font" ) );
142 g_big_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
143 if ( ! g_big_font ) {
144 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
145 pnd_conf_get_as_char ( g_conf, "minimenu.font" ), pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
146 return ( 0 ); // couldn't set up SDL TTF
150 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, MMENU_GRID_FONT ) );
151 g_grid_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, MMENU_GRID_FONTSIZE, 10 ) );
152 if ( ! g_grid_font ) {
153 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
154 pnd_conf_get_as_char ( g_conf, MMENU_GRID_FONT ), pnd_conf_get_as_int_d ( g_conf, MMENU_GRID_FONTSIZE, 10 ) );
155 return ( 0 ); // couldn't set up SDL TTF
159 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "detailtext.font" ) );
160 g_detailtext_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
161 if ( ! g_detailtext_font ) {
162 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
163 pnd_conf_get_as_char ( g_conf, "detailtext.font" ), pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
164 return ( 0 ); // couldn't set up SDL TTF
168 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "tabs.font" ) );
169 g_tab_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
170 if ( ! g_tab_font ) {
171 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
172 pnd_conf_get_as_char ( g_conf, "tabs.font" ), pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
173 return ( 0 ); // couldn't set up SDL TTF
179 mm_imgcache_t g_imagecache [ IMG_TRUEMAX ] = {
180 { IMG_BACKGROUND_800480, "graphics.IMG_BACKGROUND_800480" },
181 { IMG_BACKGROUND_TABMASK, "graphics.IMG_BACKGROUND_TABMASK" },
182 { IMG_DETAIL_PANEL, "graphics.IMG_DETAIL_PANEL" },
183 { IMG_DETAIL_BG, "graphics.IMG_DETAIL_BG" },
184 { IMG_SELECTED_ALPHAMASK, "graphics.IMG_SELECTED_ALPHAMASK" },
185 { IMG_TAB_SEL, "graphics.IMG_TAB_SEL" },
186 { IMG_TAB_UNSEL, "graphics.IMG_TAB_UNSEL" },
187 { IMG_TAB_LINE, "graphics.IMG_TAB_LINE" },
188 { IMG_TAB_LINEL, "graphics.IMG_TAB_LINEL" },
189 { IMG_TAB_LINER, "graphics.IMG_TAB_LINER" },
190 { IMG_ICON_MISSING, "graphics.IMG_ICON_MISSING" },
191 { IMG_SELECTED_HILITE, "graphics.IMG_SELECTED_HILITE" },
192 { IMG_PREVIEW_MISSING, "graphics.IMG_PREVIEW_MISSING" },
193 { IMG_ARROW_UP, "graphics.IMG_ARROW_UP", },
194 { IMG_ARROW_DOWN, "graphics.IMG_ARROW_DOWN", },
195 { IMG_ARROW_SCROLLBAR, "graphics.IMG_ARROW_SCROLLBAR", },
199 unsigned char ui_imagecache ( char *basepath ) {
201 char fullpath [ PATH_MAX ];
205 for ( i = 0; i < IMG_MAX; i++ ) {
207 if ( g_imagecache [ i ].id != i ) {
208 pnd_log ( pndn_error, "ERROR: Internal table mismatch during caching [%u]\n", i );
212 char *filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].confname );
215 pnd_log ( pndn_error, "ERROR: Missing filename in conf for key: %s\n", g_imagecache [ i ].confname );
219 sprintf ( fullpath, "%s/%s", basepath, filename );
221 if ( ! ( g_imagecache [ i ].i = IMG_Load ( fullpath ) ) ) {
222 pnd_log ( pndn_error, "ERROR: Couldn't load static cache image: %s\n", fullpath );
229 //g_imagecache [ IMG_SELECTED_ALPHAMASK ].i = SDL_CreateRGBSurface ( SDL_SWSURFACE, 60, 60, 32, 0xFF0000, 0x00FF00, 0xFF, 0xFF000000 );
230 //boxRGBA ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, 0, 0, 60, 60, 100, 100, 100, 250 );
236 g_imagecache [ IMG_SELECTED_ALPHAMASK ].i = ui_scale_image ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 ), -1 );
237 g_imagecache [ IMG_ICON_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_ICON_MISSING ].i, pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 ), -1 );
238 // scale text hilight
239 g_imagecache [ IMG_SELECTED_HILITE ].i = ui_scale_image ( g_imagecache [ IMG_SELECTED_HILITE ].i, pnd_conf_get_as_int_d ( g_conf, "grid.text_width", 50 ), -1 );
240 // scale preview no-pic
241 g_imagecache [ IMG_PREVIEW_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_PREVIEW_MISSING ].i,
242 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ),
243 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 50 ) );
245 // set alpha on detail panel
246 SDL_SetAlpha ( g_imagecache [ IMG_DETAIL_BG ].i, SDL_SRCALPHA, pnd_conf_get_as_int_d ( g_conf, "display.detail_bg_alpha", 50 ) );
251 void ui_render ( unsigned int render_mask ) {
254 // divide width: 550 / 250
255 // divide left side: 5 columns == 110px width
256 // 20px buffer either side == 70px wide icon + 20 + 20?
258 unsigned int icon_rows;
261 SDL_Rect rects [ MAXRECTS ], src;
262 SDL_Rect *dest = rects;
263 bzero ( dest, sizeof(SDL_Rect)*MAXRECTS );
265 unsigned int row, displayrow, col;
266 mm_appref_t *appiter;
268 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
270 unsigned char row_max = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_ROWMAX, 4 );
271 unsigned char col_max = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_COLMAX, 5 );
273 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
274 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
275 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
276 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
278 unsigned int grid_offset_x = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_x" );
279 unsigned int grid_offset_y = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_y" );
281 unsigned int icon_offset_x = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_x" );
282 unsigned int icon_offset_y = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_y" );
283 unsigned int icon_max_width = pnd_conf_get_as_int ( g_conf, "grid.icon_max_width" );
285 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
286 unsigned int text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
287 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "grid.text_offset_x" );
288 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_offset_y" );
290 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "grid.cell_width" );
291 unsigned int cell_height = pnd_conf_get_as_int ( g_conf, "grid.cell_height" );
293 // how many total rows do we need?
294 icon_rows = g_categories [ ui_category ].refcount / col_max;
295 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
299 // if no selected app yet, select the first one
301 if ( ! ui_selected ) {
302 ui_selected = g_categories [ ui_category ].refs;
306 // reset touchscreen regions
309 // ensure selection is visible
312 int index = ui_selected_index();
313 int topleft = col_max * ui_rows_scrolled_down;
314 int botright = ( col_max * ( ui_rows_scrolled_down + row_max ) - 1 );
316 //pnd_log ( PND_LOG_DEFAULT, "index %u tl %u br %u\n", index, topleft, botright );
318 if ( index < topleft ) {
319 ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
320 } else if ( index > botright ) {
321 ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
324 if ( ui_rows_scrolled_down < 0 ) {
325 ui_rows_scrolled_down = 0;
326 } else if ( ui_rows_scrolled_down > icon_rows ) {
327 ui_rows_scrolled_down = icon_rows;
333 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
336 dest -> w = sdl_realscreen -> w;
337 dest -> h = sdl_realscreen -> h;
338 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
343 if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
346 dest -> w = sdl_realscreen -> w;
347 dest -> h = sdl_realscreen -> h;
348 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
353 if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
354 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
355 unsigned int tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
356 unsigned int tab_selheight = pnd_conf_get_as_int ( g_conf, "tabs.tab_selheight" );
357 unsigned int tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
358 unsigned int tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
359 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
360 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
361 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
362 unsigned int maxtab = ( screen_width / tab_width ) < g_categorycount ? ( screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift;
364 for ( col = ui_catshift;
370 if ( col == ui_category ) {
371 s = g_imagecache [ IMG_TAB_SEL ].i;
373 s = g_imagecache [ IMG_TAB_UNSEL ].i;
380 if ( col == ui_category ) {
381 src.h = tab_selheight;
385 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
386 dest -> y = tab_offset_y;
387 //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
388 SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
391 ui_register_tab ( col, dest -> x, dest -> y, tab_width, tab_height );
396 if ( col == ui_category ) {
397 // no line for selected tab
399 if ( col - ui_catshift == 0 ) {
400 s = g_imagecache [ IMG_TAB_LINEL ].i;
401 } else if ( col - ui_catshift == maxtab - 1 ) {
402 s = g_imagecache [ IMG_TAB_LINER ].i;
404 s = g_imagecache [ IMG_TAB_LINE ].i;
406 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
407 dest -> y = tab_offset_y + tab_height;
408 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
414 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
415 rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ].catname, tmpfontcolor );
418 src.w = rtext -> w < text_width ? rtext -> w : text_width;
420 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
421 dest -> y = tab_offset_y + text_offset_y;
422 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
423 SDL_FreeSurface ( rtext );
430 // scroll bars and arrows
432 unsigned char show_bar = 0;
435 if ( ui_rows_scrolled_down && g_imagecache [ IMG_ARROW_UP ].i ) {
436 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
437 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
438 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
445 if ( ui_rows_scrolled_down + row_max < icon_rows && g_imagecache [ IMG_ARROW_DOWN ].i ) {
446 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
447 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
448 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
455 // show scrollbar as well
458 src.w = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_w", 10 );
459 src.h = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_h", 100 );
460 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
461 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
462 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
468 // render detail pane bg
469 if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
471 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
472 src.x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
473 src.y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
474 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
475 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
476 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
477 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
478 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
482 // render detail pane
483 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
484 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
485 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
486 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
490 } // detailpane frame/bg
492 // anything to render?
493 if ( g_categories [ ui_category ].refs ) {
495 appiter = g_categories [ ui_category ].refs;
499 // until we run out of apps, or run out of space
500 while ( appiter != NULL ) {
502 for ( col = 0; col < col_max && appiter != NULL; col++ ) {
504 // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
505 if ( row >= ui_rows_scrolled_down ) {
507 // selected? show hilights
508 if ( appiter == ui_selected ) {
510 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x;
511 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y;
512 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, NULL /* all */, sdl_realscreen, dest );
515 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
516 dest -> y = grid_offset_y + ( displayrow * cell_height ) + pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
517 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
522 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
523 SDL_Surface *iconsurface;
525 iconsurface = ic -> i;
527 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
528 iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
531 //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
537 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + (( icon_max_width - iconsurface -> w ) / 2);
538 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y;
540 SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
543 ui_register_app ( appiter, dest -> x, dest -> y, src.w, src.h );
550 if ( appiter -> ref -> title_en ) {
552 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
553 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, tmpfontcolor );
556 src.w = text_width < rtext -> w ? text_width : rtext -> w;
558 if ( rtext -> w > text_width ) {
559 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
561 dest -> x = grid_offset_x + ( col * cell_width ) + text_offset_x - ( rtext -> w / 2 );
563 dest -> y = grid_offset_y + ( displayrow * cell_height ) + text_offset_y;
564 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
565 SDL_FreeSurface ( rtext );
569 } // display now? or scrolled away..
572 appiter = appiter -> next;
574 } // for column 1...X
576 if ( row >= ui_rows_scrolled_down ) {
582 // are we done displaying rows?
583 if ( displayrow >= row_max ) {
590 // no apps to render?
591 pnd_log ( pndn_rem, "No applications to render?\n" );
597 unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
598 unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
599 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "detailtext.cell_width" );
601 unsigned int desty = cell_offset_y;
606 if ( ui_selected -> ref -> title_en ) {
608 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
609 rtext = TTF_RenderText_Blended ( g_detailtext_font, ui_selected -> ref -> title_en, tmpfontcolor );
612 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
614 dest -> x = cell_offset_x;
616 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
617 SDL_FreeSurface ( rtext );
623 if ( ui_selected -> ref -> main_category ) {
625 sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
628 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
629 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
632 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
634 dest -> x = cell_offset_x;
636 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
637 SDL_FreeSurface ( rtext );
643 if ( ui_selected -> ref -> clockspeed ) {
645 sprintf ( buffer, "CPU Clock: %s", ui_selected -> ref -> clockspeed );
648 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
649 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
652 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
654 dest -> x = cell_offset_x;
656 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
657 SDL_FreeSurface ( rtext );
663 if ( ui_selected -> ref -> clockspeed && ui_selected -> ref -> info_filename ) {
665 sprintf ( buffer, "Documentation - hit Y" );
668 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
669 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
672 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
674 dest -> x = cell_offset_x;
676 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
677 SDL_FreeSurface ( rtext );
683 mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
684 SDL_Surface *previewpic;
687 previewpic = ic -> i;
689 previewpic = g_imagecache [ IMG_PREVIEW_MISSING ].i;
693 dest -> x = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_x", 50 ) +
694 ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
695 dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
696 SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
707 static int last_battlevel = 0;
708 static unsigned char batterylevel = 0;
711 if ( time ( NULL ) - last_battlevel > 60 ) {
712 batterylevel = pnd_device_get_battery_gauge_perc();
713 last_battlevel = time ( NULL );
716 sprintf ( buffer, "Battery: %u%%", batterylevel );
719 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
720 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
721 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.battery_x", 20 );
722 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.battery_y", 450 );
723 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
724 SDL_FreeSurface ( rtext );
729 if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
730 char *buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
732 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
733 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
734 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
735 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
736 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
737 SDL_FreeSurface ( rtext );
742 if ( pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 ) {
745 time_t t = time ( NULL );
746 struct tm *tm = localtime ( &t );
747 strftime ( buffer, 50, "%a %H:%M %F", tm );
750 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
751 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
752 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.clock_x", 700 );
753 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.clock_y", 450 );
754 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
755 SDL_FreeSurface ( rtext );
759 // update all the rects and send it all to sdl
760 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
764 void ui_process_input ( unsigned char block_p ) {
767 unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
768 //static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
770 while ( ! ui_event &&
771 block_p ? SDL_WaitEvent ( &event ) : SDL_PollEvent ( &event ) )
774 switch ( event.type ) {
779 if ( event.user.code == sdl_user_ticker ) {
781 // timer went off, time to load something
782 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
784 pnd_log ( pndn_debug, "Deferred preview pic load ----------\n" );
786 // load the preview pics now!
787 pnd_disco_t *iter = ui_selected -> ref;
789 if ( iter -> preview_pic1 ) {
791 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.threaded_preview", 0 ) ) {
793 g_preview_thread = SDL_CreateThread ( (void*)ui_threaded_defered_preview, iter );
795 if ( ! g_preview_thread ) {
796 pnd_log ( pndn_error, "ERROR: Couldn't create preview thread\n" );
801 if ( ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
802 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
805 pnd_log ( pndn_debug, " Couldn't load preview pic: '%s' -> '%s'\n",
806 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
811 } // got a preview at all?
813 pnd_log ( pndn_debug, "Deferred preview pic load finish ---\n" );
818 } else if ( event.user.code == sdl_user_finishedpreview ) {
820 // if we just finished the one we happen to be looking at, better redraw now; otherwise, if
821 // we finished another, no big woop
822 if ( ui_selected && event.user.data1 == ui_selected -> ref ) {
826 } else if ( event.user.code == sdl_user_finishedicon ) {
827 // redraw, so we can show the newly loaded icon
834 #if 0 // joystick motion
835 case SDL_JOYAXISMOTION:
837 pnd_log ( PND_LOG_DEFAULT, "joystick axis\n" );
839 if ( event.jaxis.axis == 0 ) {
841 if ( event.jaxis.value < 0 ) {
843 pnd_log ( PND_LOG_DEFAULT, "joystick axis - LEFT\n" );
844 } else if ( event.jaxis.value > 0 ) {
846 pnd_log ( PND_LOG_DEFAULT, "joystick axis - RIGHT\n" );
848 } else if ( event.jaxis.axis == 1 ) {
850 if ( event.jaxis.value < 0 ) {
852 } else if ( event.jaxis.value > 0 ) {
862 #if 0 // joystick buttons
863 case SDL_JOYBUTTONDOWN:
865 pnd_log ( PND_LOG_DEFAULT, "joystick button down %u\n", event.jbutton.button );
867 if ( event.jbutton.button == 0 ) { // B
869 } else if ( event.jbutton.button == 1 ) { // Y
871 } else if ( event.jbutton.button == 2 ) { // X
873 } else if ( event.jbutton.button == 3 ) { // A
876 } else if ( event.jbutton.button == 4 ) { // Select
877 ui_mask |= uisb_select;
878 } else if ( event.jbutton.button == 5 ) { // Start
879 ui_mask |= uisb_start;
881 } else if ( event.jbutton.button == 7 ) { // L
883 } else if ( event.jbutton.button == 8 ) { // R
892 case SDL_JOYBUTTONUP:
894 pnd_log ( PND_LOG_DEFAULT, "joystick button up %u\n", event.jbutton.button );
896 if ( event.jbutton.button == 0 ) { // B
899 } else if ( event.jbutton.button == 1 ) { // Y
901 } else if ( event.jbutton.button == 2 ) { // X
903 } else if ( event.jbutton.button == 3 ) { // A
906 } else if ( event.jbutton.button == 4 ) { // Select
907 ui_mask &= ~uisb_select;
908 } else if ( event.jbutton.button == 5 ) { // Start
909 ui_mask &= ~uisb_start;
911 } else if ( event.jbutton.button == 7 ) { // L
914 } else if ( event.jbutton.button == 8 ) { // R
925 #if 1 // keyboard events
928 //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
930 // SDLK_LALT -> Start
933 if ( event.key.keysym.sym == SDLK_RIGHT ) {
936 } else if ( event.key.keysym.sym == SDLK_LEFT ) {
939 } else if ( event.key.keysym.sym == SDLK_UP ) {
942 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
945 } else if ( event.key.keysym.sym == SDLK_SPACE || event.key.keysym.sym == SDLK_END ) {
948 } else if ( event.key.keysym.sym == SDLK_z || event.key.keysym.sym == SDLK_RSHIFT ) {
951 } else if ( event.key.keysym.sym == SDLK_x || event.key.keysym.sym == SDLK_RCTRL ) {
954 } else if ( event.key.keysym.sym == SDLK_y || event.key.keysym.sym == SDLK_PAGEUP ) {
957 ui_show_info ( pnd_run_script, ui_selected -> ref );
961 } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
965 } else if ( event.key.keysym.sym == SDLK_LCTRL /*LALT*/ ) { // select button
966 char *opts [ 20 ] = {
967 "Return to Minimenu",
969 "Rescan for Applications",
970 "Run xfce4 from Minimenu",
971 "Run a terminal/console",
972 "Exit and run xfce4",
973 "Exit and run pmenu",
977 int sel = ui_modal_single_menu ( opts, 9, "Minimenu", "Enter to select; other to return." );
982 } else if ( sel == 1 ) {
984 sprintf ( buffer, "sudo poweroff" );
986 } else if ( sel == 2 ) {
988 pnd_log ( pndn_debug, "Freeing up applications\n" );
990 pnd_log ( pndn_debug, "Rescanning applications\n" );
994 ui_rows_scrolled_down = 0;
995 } else if ( sel == 3 ) {
997 char buffer [ PATH_MAX ];
998 sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/bin/startxfce4" );
999 emit_and_quit ( buffer );
1000 } else if ( sel == 4 ) {
1003 argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
1007 ui_forkexec ( argv );
1010 } else if ( sel == 5 ) {
1012 sprintf ( buffer, "echo startxfce4 > /tmp/gui.load" );
1014 //sprintf ( buffer, "sudo poweroff" );
1015 //system ( buffer );
1017 } else if ( sel == 6 ) {
1019 sprintf ( buffer, "echo pmenu > /tmp/gui.load" );
1021 //sprintf ( buffer, "sudo poweroff" );
1022 //system ( buffer );
1024 } else if ( sel == 7 ) {
1025 emit_and_quit ( MM_QUIT );
1026 } else if ( sel == 8 ) {
1034 if ( event.key.keysym.sym == SDLK_q ) {
1035 emit_and_quit ( MM_QUIT );
1041 #if 1 // mouse / touchscreen
1043 case SDL_MOUSEBUTTONDOWN:
1044 if ( event.button.button == SDL_BUTTON_LEFT ) {
1045 cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
1051 case SDL_MOUSEBUTTONUP:
1052 if ( event.button.button == SDL_BUTTON_LEFT ) {
1053 ui_touch_act ( event.button.x, event.button.y );
1066 } // switch event type
1073 void ui_push_left ( unsigned char forcecoil ) {
1075 if ( ! ui_selected ) {
1076 ui_push_right ( 0 );
1080 // what column we in?
1081 unsigned int col = ui_determine_screen_col ( ui_selected );
1083 // are we alreadt at first item?
1084 if ( forcecoil == 0 &&
1085 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1088 unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1090 ui_push_right ( 0 );
1094 } else if ( g_categories [ ui_category ].refs == ui_selected ) {
1095 // can't go any more left, we're at the head
1098 // figure out the previous item; yay for singly linked list :/
1099 mm_appref_t *i = g_categories [ ui_category ].refs;
1101 if ( i -> next == ui_selected ) {
1109 ui_set_selected ( ui_selected );
1114 void ui_push_right ( unsigned char forcecoil ) {
1116 if ( ui_selected ) {
1118 // what column we in?
1119 unsigned int col = ui_determine_screen_col ( ui_selected );
1122 if ( forcecoil == 0 &&
1123 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1124 col == pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1 )
1127 unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1134 // just go to the next
1136 if ( ui_selected -> next ) {
1137 ui_selected = ui_selected -> next;
1143 ui_selected = g_categories [ ui_category ].refs;
1146 ui_set_selected ( ui_selected );
1151 void ui_push_up ( void ) {
1152 unsigned char col_max = pnd_conf_get_as_int ( g_conf, MMENU_DISP_COLMAX );
1154 if ( ! ui_selected ) {
1159 unsigned int row = ui_determine_row ( ui_selected );
1162 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 1 ) == 0 )
1164 // wrap around instead
1166 unsigned int col = ui_determine_screen_col ( ui_selected );
1169 ui_selected = g_categories [ ui_category ].refs;
1170 while ( ui_selected -> next ) {
1171 ui_selected = ui_selected -> next;
1174 // try to move to same column
1175 unsigned int newcol = ui_determine_screen_col ( ui_selected );
1176 if ( newcol > col ) {
1184 // scroll down to show it
1185 int r = ui_determine_row ( ui_selected ) - 1;
1186 if ( r - pnd_conf_get_as_int ( g_conf, MMENU_DISP_ROWMAX ) > 0 ) {
1187 ui_rows_scrolled_down = (unsigned int) r;
1191 // stop at top/bottom
1203 void ui_push_down ( void ) {
1204 unsigned char col_max = pnd_conf_get_as_int ( g_conf, MMENU_DISP_COLMAX );
1206 if ( ui_selected ) {
1209 unsigned int row = ui_determine_row ( ui_selected );
1212 unsigned int icon_rows = g_categories [ ui_category ].refcount / col_max;
1213 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
1218 if ( row == ( icon_rows - 1 ) &&
1219 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 1 ) == 0 )
1222 unsigned char col = ui_determine_screen_col ( ui_selected );
1224 ui_selected = g_categories [ ui_category ].refs;
1227 ui_selected = ui_selected -> next;
1231 ui_rows_scrolled_down = 0;
1236 ui_push_right ( 1 );
1243 ui_push_right ( 0 );
1249 void ui_push_exec ( void ) {
1251 if ( ui_selected ) {
1252 char buffer [ PATH_MAX ];
1253 sprintf ( buffer, "%s/%s", ui_selected -> ref -> object_path, ui_selected -> ref -> object_filename );
1254 pnd_apps_exec ( pnd_run_script,
1256 ui_selected -> ref -> unique_id,
1257 ui_selected -> ref -> exec,
1258 ui_selected -> ref -> startdir,
1259 ui_selected -> ref -> execargs,
1260 atoi ( ui_selected -> ref -> clockspeed ),
1261 PND_EXEC_OPTION_NORUN );
1262 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1263 emit_and_quit ( buffer );
1269 void ui_push_ltrigger ( void ) {
1270 unsigned char oldcat = ui_category;
1272 if ( ui_category > 0 ) {
1275 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1276 ui_category = g_categorycount - 1;
1280 if ( oldcat != ui_category ) {
1282 ui_set_selected ( ui_selected );
1285 // make tab visible?
1286 if ( ui_catshift > 0 && ui_category == ui_catshift - 1 ) {
1291 ui_rows_scrolled_down = 0;
1296 void ui_push_rtrigger ( void ) {
1297 unsigned char oldcat = ui_category;
1299 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
1300 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1302 if ( ui_category < ( g_categorycount - 1 ) ) {
1305 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1310 if ( oldcat != ui_category ) {
1312 ui_set_selected ( ui_selected );
1315 // make tab visible?
1316 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
1321 ui_rows_scrolled_down = 0;
1326 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ) {
1327 double scale = 1000000.0;
1328 double scalex = 1000000.0;
1329 double scaley = 1000000.0;
1330 SDL_Surface *scaled;
1332 scalex = (double)maxwidth / (double)s -> w;
1334 if ( maxheight == -1 ) {
1337 scaley = (double)maxheight / (double)s -> h;
1339 if ( scaley < scalex ) {
1347 scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
1348 SDL_FreeSurface ( s );
1354 void ui_loadscreen ( void ) {
1358 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1359 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1360 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1361 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1364 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1368 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1369 rtext = TTF_RenderText_Blended ( g_big_font, "Setting up menu...", tmpfontcolor );
1372 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1373 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1374 SDL_FreeSurface ( rtext );
1379 void ui_discoverscreen ( unsigned char clearscreen ) {
1383 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1384 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1385 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1386 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1389 if ( clearscreen ) {
1390 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1392 // render background
1393 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1396 dest.w = sdl_realscreen -> w;
1397 dest.h = sdl_realscreen -> h;
1398 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1399 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1406 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1407 rtext = TTF_RenderText_Blended ( g_big_font, "Looking for applications...", tmpfontcolor );
1408 if ( clearscreen ) {
1415 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1416 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1417 SDL_FreeSurface ( rtext );
1420 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1421 dest.x = rtext -> w + 30;
1423 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, &dest );
1424 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1430 void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
1432 SDL_Rect rects [ 4 ];
1433 SDL_Rect *dest = rects;
1435 bzero ( dest, sizeof(SDL_Rect)* 4 );
1437 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1438 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1439 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1440 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1442 static unsigned int stepx = 0;
1445 if ( clearscreen ) {
1446 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1448 // render background
1449 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1452 dest -> w = sdl_realscreen -> w;
1453 dest -> h = sdl_realscreen -> h;
1454 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1460 // render background
1461 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1464 src.w = sdl_realscreen -> w;
1468 dest -> w = sdl_realscreen -> w;
1469 dest -> h = sdl_realscreen -> h;
1470 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
1478 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1479 rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
1482 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1483 SDL_FreeSurface ( rtext );
1487 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1488 dest -> x = rtext -> w + 30 + stepx;
1490 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, dest );
1496 rtext = TTF_RenderText_Blended ( g_tab_font, filename, tmpfontcolor );
1499 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1500 SDL_FreeSurface ( rtext );
1507 if ( stepx > 350 ) {
1511 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1516 int ui_selected_index ( void ) {
1518 if ( ! ui_selected ) {
1519 return ( -1 ); // no index
1522 mm_appref_t *r = g_categories [ ui_category ].refs;
1525 if ( r == ui_selected ) {
1535 static mm_appref_t *timer_ref = NULL;
1536 void ui_set_selected ( mm_appref_t *r ) {
1538 if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1539 return; // no desire to defer anything
1544 SDL_SetTimer ( 0, NULL );
1549 SDL_SetTimer ( pnd_conf_get_as_int_d ( g_conf, "previewpic.defer_timer_ms", 1000 ), ui_callback_f );
1555 unsigned int ui_callback_f ( unsigned int t ) {
1557 if ( ui_selected != timer_ref ) {
1558 return ( 0 ); // user has moved it, who cares
1562 bzero ( &e, sizeof(SDL_Event) );
1563 e.type = SDL_USEREVENT;
1564 e.user.code = sdl_user_ticker;
1565 SDL_PushEvent ( &e );
1570 int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer ) {
1571 SDL_Rect rects [ 40 ];
1572 SDL_Rect *dest = rects;
1576 bzero ( rects, sizeof(SDL_Rect) * 40 );
1578 unsigned int sel = 0;
1580 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1581 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1582 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1583 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1585 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1587 SDL_Color selfontcolor = { 0/*font_rgba_r*/, font_rgba_g, font_rgba_b, font_rgba_a };
1595 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1596 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1597 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
1598 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
1599 SDL_FillRect( sdl_realscreen, dest, 0 );
1601 // show dialog background
1602 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
1603 src.x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1604 src.y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1605 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
1606 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
1607 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1608 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1609 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1610 // repeat for darken?
1611 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1612 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1613 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1617 // show dialog frame
1618 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
1619 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1620 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1621 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
1622 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1628 rtext = TTF_RenderText_Blended ( g_tab_font, title, tmpfontcolor );
1629 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1630 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
1631 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1632 SDL_FreeSurface ( rtext );
1638 rtext = TTF_RenderText_Blended ( g_tab_font, footer, tmpfontcolor );
1639 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1640 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
1641 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
1643 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1644 SDL_FreeSurface ( rtext );
1649 for ( i = 0; i < argc; i++ ) {
1653 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
1655 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], tmpfontcolor );
1657 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1658 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 ) );
1659 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1660 SDL_FreeSurface ( rtext );
1665 // update all the rects and send it all to sdl
1666 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1670 while ( SDL_WaitEvent ( &event ) ) {
1672 switch ( event.type ) {
1676 if ( event.key.keysym.sym == SDLK_UP ) {
1680 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1681 if ( sel < argc - 1 ) {
1685 } else if ( event.key.keysym.sym == SDLK_RETURN ) {
1688 } else if ( event.key.keysym.sym == SDLK_q ) {
1692 return ( -1 ); // nada
1707 unsigned char ui_determine_row ( mm_appref_t *a ) {
1708 unsigned int row = 0;
1710 mm_appref_t *i = g_categories [ ui_category ].refs;
1715 row /= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
1720 unsigned char ui_determine_screen_row ( mm_appref_t *a ) {
1721 return ( ui_determine_row ( a ) % pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 5 ) );
1724 unsigned char ui_determine_screen_col ( mm_appref_t *a ) {
1725 unsigned int col = 0;
1727 mm_appref_t *i = g_categories [ ui_category ].refs;
1732 col %= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
1737 unsigned char ui_show_info ( char *pndrun, pnd_disco_t *p ) {
1738 char *viewer, *searchpath;
1739 pnd_conf_handle desktoph;
1742 searchpath = pnd_conf_query_searchpath();
1744 desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
1750 viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
1753 return ( 0 ); // no way to view the file
1757 if ( ! p -> unique_id ) {
1761 if ( ! p -> info_filename ) {
1765 if ( ! p -> info_name ) {
1776 if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) {
1777 snprintf ( pargs, 1001, "%s %s",
1778 pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
1783 char pndfile [ 1024 ];
1784 if ( p -> object_type == pnd_object_type_directory ) {
1785 // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
1786 strncpy ( pndfile, p -> object_path, 1000 );
1787 } else if ( p -> object_type == pnd_object_type_pnd ) {
1788 // pnd_run.sh wants the full path and filename for the .pnd file
1789 snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
1792 if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs,
1793 p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) )
1798 pnd_log ( pndn_debug, "Info Exec=%s\n", pnd_apps_exec_runline() );
1802 if ( ( x = fork() ) < 0 ) {
1803 pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
1808 execl ( "/bin/sh", "/bin/sh", "-c", pnd_apps_exec_runline(), (char*)NULL );
1809 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", pnd_apps_exec_runline() );
1821 #define MAXTOUCH 100
1822 ui_touch_t ui_touchrects [ MAXTOUCH ];
1823 unsigned char ui_touchrect_count = 0;
1825 void ui_register_reset ( void ) {
1826 bzero ( ui_touchrects, sizeof(ui_touch_t)*MAXTOUCH );
1827 ui_touchrect_count = 0;
1831 void ui_register_tab ( unsigned char catnum, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
1833 if ( ui_touchrect_count == MAXTOUCH ) {
1837 ui_touchrects [ ui_touchrect_count ].r.x = x;
1838 ui_touchrects [ ui_touchrect_count ].r.y = y;
1839 ui_touchrects [ ui_touchrect_count ].r.w = w;
1840 ui_touchrects [ ui_touchrect_count ].r.h = h;
1841 ui_touchrects [ ui_touchrect_count ].catnum = catnum;
1842 ui_touchrect_count++;
1847 void ui_register_app ( mm_appref_t *app, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
1849 if ( ui_touchrect_count == MAXTOUCH ) {
1853 ui_touchrects [ ui_touchrect_count ].r.x = x;
1854 ui_touchrects [ ui_touchrect_count ].r.y = y;
1855 ui_touchrects [ ui_touchrect_count ].r.w = w;
1856 ui_touchrects [ ui_touchrect_count ].r.h = h;
1857 ui_touchrects [ ui_touchrect_count ].ref = app;
1858 ui_touchrect_count++;
1863 void ui_touch_act ( unsigned int x, unsigned int y ) {
1868 for ( i = 0; i < ui_touchrect_count; i++ ) {
1869 t = &(ui_touchrects [ i ]);
1871 if ( x >= t -> r.x &&
1872 x <= t -> r.x + t -> r.w &&
1874 y <= t -> r.y + t -> r.h
1879 ui_selected = t -> ref;
1882 ui_category = t -> catnum;
1893 unsigned char ui_forkexec ( char *argv[] ) {
1894 char *fooby = argv[0];
1897 if ( ( x = fork() ) < 0 ) {
1898 pnd_log ( pndn_error, "ERROR: Couldn't fork() for '%s'\n", fooby );
1902 if ( x == 0 ) { // child
1903 execv ( fooby, argv );
1904 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", fooby );
1912 unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ) {
1914 if ( ! cache_preview ( p, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
1915 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
1918 pnd_log ( pndn_debug, "THREAD: Couldn't load preview pic: '%s' -> '%s'\n",
1919 IFNULL(p->title_en,"No Name"), p -> preview_pic1 );
1922 // trigger that we completed
1924 bzero ( &e, sizeof(SDL_Event) );
1925 e.type = SDL_USEREVENT;
1926 e.user.code = sdl_user_finishedpreview;
1928 SDL_PushEvent ( &e );
1933 SDL_Thread *g_icon_thread = NULL;
1934 void ui_post_scan ( void ) {
1936 // if deferred icon load, kick off the thread now
1937 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 1 ) {
1939 g_icon_thread = SDL_CreateThread ( (void*)ui_threaded_defered_icon, NULL );
1941 if ( ! g_icon_thread ) {
1942 pnd_log ( pndn_error, "ERROR: Couldn't create icon thread\n" );
1945 } // deferred icon load
1950 unsigned char ui_threaded_defered_icon ( void *p ) {
1951 extern pnd_box_handle g_active_apps;
1952 pnd_box_handle h = g_active_apps;
1954 unsigned char maxwidth, maxheight;
1955 maxwidth = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_ICON_MAX_WIDTH, 50 );
1956 maxheight = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_ICON_MAX_HEIGHT, 50 );
1958 pnd_disco_t *iter = pnd_box_get_head ( h );
1963 if ( iter -> pnd_icon_pos &&
1964 ! cache_icon ( iter, maxwidth, maxheight ) )
1966 pnd_log ( pndn_warning, " Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
1969 // trigger that we completed
1971 bzero ( &e, sizeof(SDL_Event) );
1972 e.type = SDL_USEREVENT;
1973 e.user.code = sdl_user_finishedicon;
1974 SDL_PushEvent ( &e );
1976 //pnd_log ( pndn_warning, " Finished deferred load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
1977 usleep ( pnd_conf_get_as_int_d ( g_conf, "minimenu.defer_icon_us", 50000 ) );
1982 iter = pnd_box_get_next ( iter );