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, sdl_user_finishedpreview = 1 };
39 unsigned short int g_scale = 1; // 1 == noscale
41 SDL_Surface *g_imgcache [ IMG_MAX ];
43 TTF_Font *g_big_font = NULL;
44 TTF_Font *g_grid_font = NULL;
45 TTF_Font *g_detailtext_font = NULL;
46 TTF_Font *g_tab_font = NULL;
48 extern pnd_conf_handle g_conf;
50 /* current display state
52 int ui_rows_scrolled_down = 0; // number of rows that should be missing from top of the display
53 mm_appref_t *ui_selected = NULL;
54 unsigned char ui_category = 0; // current category
55 unsigned char ui_catshift = 0; // how many cats are offscreen to the left
57 extern mm_category_t g_categories [ MAX_CATS ];
58 extern unsigned char g_categorycount;
60 static SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ); // height -1 means ignore
61 static int ui_selected_index ( void );
63 unsigned char ui_setup ( void ) {
68 SDL_Init ( SDL_INIT_EVERYTHING | SDL_INIT_NOPARACHUTE );
70 SDL_JoystickOpen ( 0 ); // turn on joy-0
72 SDL_WM_SetCaption ( "mmenu", "mmenu" );
74 // hide the mouse cursor if we can
75 if ( SDL_ShowCursor ( -1 ) == 1 ) {
82 unsigned int svm = SDL_SWSURFACE /*| SDL_FULLSCREEN*/ /* 0*/;
83 if ( pnd_conf_get_as_int_d ( g_conf, "display.fullscreen", 0 ) > 0 ) {
84 svm |= SDL_FULLSCREEN;
88 SDL_SetVideoMode ( 800 * g_scale, 480 * g_scale, 16 /*bpp*/, svm );
90 if ( ! sdl_realscreen ) {
91 pnd_log ( pndn_error, "ERROR: Couldn't open SDL real screen; dieing." );
95 pnd_log ( pndn_debug, "Pixel format:" );
96 pnd_log ( pndn_debug, "bpp b: %u\n", sdl_realscreen -> format -> BitsPerPixel );
97 pnd_log ( pndn_debug, "bpp B: %u\n", sdl_realscreen -> format -> BytesPerPixel );
98 pnd_log ( pndn_debug, "R mask: %08x\n", sdl_realscreen -> format -> Rmask );
99 pnd_log ( pndn_debug, "G mask: %08x\n", sdl_realscreen -> format -> Gmask );
100 pnd_log ( pndn_debug, "B mask: %08x\n", sdl_realscreen -> format -> Bmask );
106 /* Set 16-bit stereo audio at 22Khz */
107 fmt.freq = 44100; //22050;
108 fmt.format = AUDIO_S16; //AUDIO_S16;
110 fmt.samples = 2048; /* A good value for games */
111 fmt.callback = mixaudio;
114 /* Open the audio device and start playing sound! */
115 if ( SDL_OpenAudio ( &fmt, NULL ) < 0 ) {
116 zotlog ( "Unable to open audio: %s\n", SDL_GetError() );
120 SDL_PauseAudio ( 0 );
125 //IMG_Init ( IMG_INIT_JPG | IMG_INIT_PNG );
131 if ( TTF_Init() == -1 ) {
132 pnd_log ( pndn_error, "ERROR: Couldn't set up SDL TTF lib\n" );
133 return ( 0 ); // couldn't set up SDL TTF
136 char fullpath [ PATH_MAX ];
138 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "minimenu.font" ) );
139 g_big_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
140 if ( ! g_big_font ) {
141 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
142 pnd_conf_get_as_char ( g_conf, "minimenu.font" ), pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
143 return ( 0 ); // couldn't set up SDL TTF
147 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, MMENU_GRID_FONT ) );
148 g_grid_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, MMENU_GRID_FONTSIZE, 10 ) );
149 if ( ! g_grid_font ) {
150 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
151 pnd_conf_get_as_char ( g_conf, MMENU_GRID_FONT ), pnd_conf_get_as_int_d ( g_conf, MMENU_GRID_FONTSIZE, 10 ) );
152 return ( 0 ); // couldn't set up SDL TTF
156 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "detailtext.font" ) );
157 g_detailtext_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
158 if ( ! g_detailtext_font ) {
159 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
160 pnd_conf_get_as_char ( g_conf, "detailtext.font" ), pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
161 return ( 0 ); // couldn't set up SDL TTF
165 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "tabs.font" ) );
166 g_tab_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
167 if ( ! g_tab_font ) {
168 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
169 pnd_conf_get_as_char ( g_conf, "tabs.font" ), pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
170 return ( 0 ); // couldn't set up SDL TTF
176 mm_imgcache_t g_imagecache [ IMG_TRUEMAX ] = {
177 { IMG_BACKGROUND_800480, "graphics.IMG_BACKGROUND_800480" },
178 { IMG_BACKGROUND_TABMASK, "graphics.IMG_BACKGROUND_TABMASK" },
179 { IMG_DETAIL_PANEL, "graphics.IMG_DETAIL_PANEL" },
180 { IMG_DETAIL_BG, "graphics.IMG_DETAIL_BG" },
181 { IMG_SELECTED_ALPHAMASK, "graphics.IMG_SELECTED_ALPHAMASK" },
182 { IMG_TAB_SEL, "graphics.IMG_TAB_SEL" },
183 { IMG_TAB_UNSEL, "graphics.IMG_TAB_UNSEL" },
184 { IMG_TAB_LINE, "graphics.IMG_TAB_LINE" },
185 { IMG_TAB_LINEL, "graphics.IMG_TAB_LINEL" },
186 { IMG_TAB_LINER, "graphics.IMG_TAB_LINER" },
187 { IMG_ICON_MISSING, "graphics.IMG_ICON_MISSING" },
188 { IMG_SELECTED_HILITE, "graphics.IMG_SELECTED_HILITE" },
189 { IMG_PREVIEW_MISSING, "graphics.IMG_PREVIEW_MISSING" },
190 { IMG_ARROW_UP, "graphics.IMG_ARROW_UP", },
191 { IMG_ARROW_DOWN, "graphics.IMG_ARROW_DOWN", },
192 { IMG_ARROW_SCROLLBAR, "graphics.IMG_ARROW_SCROLLBAR", },
196 unsigned char ui_imagecache ( char *basepath ) {
198 char fullpath [ PATH_MAX ];
202 for ( i = 0; i < IMG_MAX; i++ ) {
204 if ( g_imagecache [ i ].id != i ) {
205 pnd_log ( pndn_error, "ERROR: Internal table mismatch during caching [%u]\n", i );
209 char *filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].confname );
212 pnd_log ( pndn_error, "ERROR: Missing filename in conf for key: %s\n", g_imagecache [ i ].confname );
216 sprintf ( fullpath, "%s/%s", basepath, filename );
218 if ( ! ( g_imagecache [ i ].i = IMG_Load ( fullpath ) ) ) {
219 pnd_log ( pndn_error, "ERROR: Couldn't load static cache image: %s\n", fullpath );
226 //g_imagecache [ IMG_SELECTED_ALPHAMASK ].i = SDL_CreateRGBSurface ( SDL_SWSURFACE, 60, 60, 32, 0xFF0000, 0x00FF00, 0xFF, 0xFF000000 );
227 //boxRGBA ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, 0, 0, 60, 60, 100, 100, 100, 250 );
233 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 );
234 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 );
235 // scale text hilight
236 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 );
237 // scale preview no-pic
238 g_imagecache [ IMG_PREVIEW_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_PREVIEW_MISSING ].i,
239 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ),
240 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 50 ) );
242 // set alpha on detail panel
243 SDL_SetAlpha ( g_imagecache [ IMG_DETAIL_BG ].i, SDL_SRCALPHA, pnd_conf_get_as_int_d ( g_conf, "display.detail_bg_alpha", 50 ) );
248 void ui_render ( unsigned int render_mask ) {
251 // divide width: 550 / 250
252 // divide left side: 5 columns == 110px width
253 // 20px buffer either side == 70px wide icon + 20 + 20?
255 unsigned int icon_rows;
258 SDL_Rect rects [ MAXRECTS ], src;
259 SDL_Rect *dest = rects;
260 bzero ( dest, sizeof(SDL_Rect)*MAXRECTS );
262 unsigned int row, displayrow, col;
263 mm_appref_t *appiter;
265 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
267 unsigned char row_max = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_ROWMAX, 4 );
268 unsigned char col_max = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_COLMAX, 5 );
270 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
271 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
272 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
273 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
275 unsigned int grid_offset_x = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_x" );
276 unsigned int grid_offset_y = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_y" );
278 unsigned int icon_offset_x = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_x" );
279 unsigned int icon_offset_y = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_y" );
280 unsigned int icon_max_width = pnd_conf_get_as_int ( g_conf, "grid.icon_max_width" );
282 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
283 unsigned int text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
284 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "grid.text_offset_x" );
285 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_offset_y" );
287 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "grid.cell_width" );
288 unsigned int cell_height = pnd_conf_get_as_int ( g_conf, "grid.cell_height" );
290 // how many total rows do we need?
291 icon_rows = g_categories [ ui_category ].refcount / col_max;
292 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
296 // if no selected app yet, select the first one
298 if ( ! ui_selected ) {
299 ui_selected = g_categories [ ui_category ].refs;
303 // reset touchscreen regions
306 // ensure selection is visible
309 int index = ui_selected_index();
310 int topleft = col_max * ui_rows_scrolled_down;
311 int botright = ( col_max * ( ui_rows_scrolled_down + row_max ) - 1 );
313 //pnd_log ( PND_LOG_DEFAULT, "index %u tl %u br %u\n", index, topleft, botright );
315 if ( index < topleft ) {
316 ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
317 } else if ( index > botright ) {
318 ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
321 if ( ui_rows_scrolled_down < 0 ) {
322 ui_rows_scrolled_down = 0;
323 } else if ( ui_rows_scrolled_down > icon_rows ) {
324 ui_rows_scrolled_down = icon_rows;
330 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
333 dest -> w = sdl_realscreen -> w;
334 dest -> h = sdl_realscreen -> h;
335 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
340 if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
343 dest -> w = sdl_realscreen -> w;
344 dest -> h = sdl_realscreen -> h;
345 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
350 if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
351 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
352 unsigned int tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
353 unsigned int tab_selheight = pnd_conf_get_as_int ( g_conf, "tabs.tab_selheight" );
354 unsigned int tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
355 unsigned int tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
356 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
357 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
358 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
359 unsigned int maxtab = ( screen_width / tab_width ) < g_categorycount ? ( screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift;
361 for ( col = ui_catshift;
367 if ( col == ui_category ) {
368 s = g_imagecache [ IMG_TAB_SEL ].i;
370 s = g_imagecache [ IMG_TAB_UNSEL ].i;
377 if ( col == ui_category ) {
378 src.h = tab_selheight;
382 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
383 dest -> y = tab_offset_y;
384 //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
385 SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
388 ui_register_tab ( col, dest -> x, dest -> y, tab_width, tab_height );
393 if ( col == ui_category ) {
394 // no line for selected tab
395 printf ( "skipselevting L\n" );
397 if ( col - ui_catshift == 0 ) {
398 s = g_imagecache [ IMG_TAB_LINEL ].i;
399 printf ( "selevting L\n" );
400 } else if ( col - ui_catshift == maxtab - 1 ) {
401 s = g_imagecache [ IMG_TAB_LINER ].i;
402 printf ( "selevting R\n" );
404 s = g_imagecache [ IMG_TAB_LINE ].i;
405 printf ( "selevting M\n" );
407 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
408 dest -> y = tab_offset_y + tab_height;
409 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
415 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
416 rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ].catname, tmpfontcolor );
419 src.w = rtext -> w < text_width ? rtext -> w : text_width;
421 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
422 dest -> y = tab_offset_y + text_offset_y;
423 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
424 SDL_FreeSurface ( rtext );
431 // scroll bars and arrows
433 unsigned char show_bar = 0;
436 if ( ui_rows_scrolled_down && g_imagecache [ IMG_ARROW_UP ].i ) {
437 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
438 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
439 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
446 if ( ui_rows_scrolled_down + row_max < icon_rows && g_imagecache [ IMG_ARROW_DOWN ].i ) {
447 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
448 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
449 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
456 // show scrollbar as well
459 src.w = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_w", 10 );
460 src.h = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_h", 100 );
461 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
462 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
463 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
469 // render detail pane bg
470 if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
472 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
473 src.x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
474 src.y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
475 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
476 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
477 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
478 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
479 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
483 // render detail pane
484 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
485 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
486 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
487 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
491 } // detailpane frame/bg
493 // anything to render?
494 if ( g_categories [ ui_category ].refs ) {
496 appiter = g_categories [ ui_category ].refs;
500 // until we run out of apps, or run out of space
501 while ( appiter != NULL ) {
503 for ( col = 0; col < col_max && appiter != NULL; col++ ) {
505 // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
506 if ( row >= ui_rows_scrolled_down ) {
508 // selected? show hilights
509 if ( appiter == ui_selected ) {
511 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x;
512 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y;
513 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, NULL /* all */, sdl_realscreen, dest );
516 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
517 dest -> y = grid_offset_y + ( displayrow * cell_height ) + pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
518 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
523 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
524 SDL_Surface *iconsurface;
526 iconsurface = ic -> i;
528 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
529 iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
532 //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
538 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + (( icon_max_width - iconsurface -> w ) / 2);
539 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y;
541 SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
544 ui_register_app ( appiter, dest -> x, dest -> y, src.w, src.h );
551 if ( appiter -> ref -> title_en ) {
553 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
554 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, tmpfontcolor );
557 src.w = text_width < rtext -> w ? text_width : rtext -> w;
559 if ( rtext -> w > text_width ) {
560 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
562 dest -> x = grid_offset_x + ( col * cell_width ) + text_offset_x - ( rtext -> w / 2 );
564 dest -> y = grid_offset_y + ( displayrow * cell_height ) + text_offset_y;
565 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
566 SDL_FreeSurface ( rtext );
570 } // display now? or scrolled away..
573 appiter = appiter -> next;
575 } // for column 1...X
577 if ( row >= ui_rows_scrolled_down ) {
583 // are we done displaying rows?
584 if ( displayrow >= row_max ) {
591 // no apps to render?
592 pnd_log ( pndn_rem, "No applications to render?\n" );
598 unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
599 unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
600 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "detailtext.cell_width" );
602 unsigned int desty = cell_offset_y;
607 if ( ui_selected -> ref -> title_en ) {
609 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
610 rtext = TTF_RenderText_Blended ( g_detailtext_font, ui_selected -> ref -> title_en, tmpfontcolor );
613 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
615 dest -> x = cell_offset_x;
617 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
618 SDL_FreeSurface ( rtext );
624 if ( ui_selected -> ref -> main_category ) {
626 sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
629 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
630 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
633 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
635 dest -> x = cell_offset_x;
637 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
638 SDL_FreeSurface ( rtext );
644 if ( ui_selected -> ref -> clockspeed ) {
646 sprintf ( buffer, "CPU Clock: %s", ui_selected -> ref -> clockspeed );
649 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
650 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
653 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
655 dest -> x = cell_offset_x;
657 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
658 SDL_FreeSurface ( rtext );
664 if ( ui_selected -> ref -> clockspeed && ui_selected -> ref -> info_filename ) {
666 sprintf ( buffer, "Documentation - hit Y" );
669 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
670 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
673 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
675 dest -> x = cell_offset_x;
677 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
678 SDL_FreeSurface ( rtext );
684 mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
685 SDL_Surface *previewpic;
688 previewpic = ic -> i;
690 previewpic = g_imagecache [ IMG_PREVIEW_MISSING ].i;
694 dest -> x = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_x", 50 ) +
695 ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
696 dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
697 SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
708 static int last_battlevel = 0;
709 static unsigned char batterylevel = 0;
712 if ( time ( NULL ) - last_battlevel > 60 ) {
713 batterylevel = pnd_device_get_battery_gauge_perc();
714 last_battlevel = time ( NULL );
717 sprintf ( buffer, "Battery: %u%%", batterylevel );
720 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
721 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
722 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.battery_x", 20 );
723 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.battery_y", 450 );
724 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
725 SDL_FreeSurface ( rtext );
730 if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
731 char *buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
733 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
734 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
735 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
736 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
737 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
738 SDL_FreeSurface ( rtext );
743 if ( pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 ) {
746 time_t t = time ( NULL );
747 struct tm *tm = localtime ( &t );
748 strftime ( buffer, 50, "%a %H:%M %F", tm );
751 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
752 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
753 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.clock_x", 700 );
754 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.clock_y", 450 );
755 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
756 SDL_FreeSurface ( rtext );
760 // update all the rects and send it all to sdl
761 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
765 void ui_process_input ( unsigned char block_p ) {
768 unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
769 //static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
771 while ( ! ui_event &&
772 block_p ? SDL_WaitEvent ( &event ) : SDL_PollEvent ( &event ) )
775 switch ( event.type ) {
780 if ( event.user.code == sdl_user_ticker ) {
782 // timer went off, time to load something
783 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
785 pnd_log ( pndn_debug, "Deferred preview pic load ----------\n" );
787 // load the preview pics now!
788 pnd_disco_t *iter = ui_selected -> ref;
790 if ( iter -> preview_pic1 ) {
792 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.threaded_preview", 0 ) ) {
794 g_preview_thread = SDL_CreateThread ( (void*)ui_threaded_defered_preview, iter );
796 if ( ! g_preview_thread ) {
797 pnd_log ( pndn_error, "ERROR: Couldn't create preview thread\n" );
802 if ( ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
803 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
806 pnd_log ( pndn_debug, " Couldn't load preview pic: '%s' -> '%s'\n",
807 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
812 } // got a preview at all?
814 pnd_log ( pndn_debug, "Deferred preview pic load finish ---\n" );
819 } else if ( event.user.code == sdl_user_finishedpreview ) {
821 // if we just finished the one we happen to be looking at, better redraw now; otherwise, if
822 // we finished another, no big woop
823 if ( ui_selected && event.user.data1 == ui_selected -> ref ) {
831 #if 0 // joystick motion
832 case SDL_JOYAXISMOTION:
834 pnd_log ( PND_LOG_DEFAULT, "joystick axis\n" );
836 if ( event.jaxis.axis == 0 ) {
838 if ( event.jaxis.value < 0 ) {
840 pnd_log ( PND_LOG_DEFAULT, "joystick axis - LEFT\n" );
841 } else if ( event.jaxis.value > 0 ) {
843 pnd_log ( PND_LOG_DEFAULT, "joystick axis - RIGHT\n" );
845 } else if ( event.jaxis.axis == 1 ) {
847 if ( event.jaxis.value < 0 ) {
849 } else if ( event.jaxis.value > 0 ) {
859 #if 0 // joystick buttons
860 case SDL_JOYBUTTONDOWN:
862 pnd_log ( PND_LOG_DEFAULT, "joystick button down %u\n", event.jbutton.button );
864 if ( event.jbutton.button == 0 ) { // B
866 } else if ( event.jbutton.button == 1 ) { // Y
868 } else if ( event.jbutton.button == 2 ) { // X
870 } else if ( event.jbutton.button == 3 ) { // A
873 } else if ( event.jbutton.button == 4 ) { // Select
874 ui_mask |= uisb_select;
875 } else if ( event.jbutton.button == 5 ) { // Start
876 ui_mask |= uisb_start;
878 } else if ( event.jbutton.button == 7 ) { // L
880 } else if ( event.jbutton.button == 8 ) { // R
889 case SDL_JOYBUTTONUP:
891 pnd_log ( PND_LOG_DEFAULT, "joystick button up %u\n", event.jbutton.button );
893 if ( event.jbutton.button == 0 ) { // B
896 } else if ( event.jbutton.button == 1 ) { // Y
898 } else if ( event.jbutton.button == 2 ) { // X
900 } else if ( event.jbutton.button == 3 ) { // A
903 } else if ( event.jbutton.button == 4 ) { // Select
904 ui_mask &= ~uisb_select;
905 } else if ( event.jbutton.button == 5 ) { // Start
906 ui_mask &= ~uisb_start;
908 } else if ( event.jbutton.button == 7 ) { // L
911 } else if ( event.jbutton.button == 8 ) { // R
922 #if 1 // keyboard events
925 //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
927 // SDLK_LALT -> Start
930 if ( event.key.keysym.sym == SDLK_RIGHT ) {
933 } else if ( event.key.keysym.sym == SDLK_LEFT ) {
936 } else if ( event.key.keysym.sym == SDLK_UP ) {
939 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
942 } else if ( event.key.keysym.sym == SDLK_SPACE || event.key.keysym.sym == SDLK_END ) {
945 } else if ( event.key.keysym.sym == SDLK_z || event.key.keysym.sym == SDLK_RSHIFT ) {
948 } else if ( event.key.keysym.sym == SDLK_x || event.key.keysym.sym == SDLK_RCTRL ) {
951 } else if ( event.key.keysym.sym == SDLK_y || event.key.keysym.sym == SDLK_PAGEUP ) {
954 ui_show_info ( pnd_run_script, ui_selected -> ref );
958 } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
962 } else if ( event.key.keysym.sym == SDLK_LCTRL /*LALT*/ ) { // select button
963 char *opts [ 20 ] = {
964 "Return to Minimenu",
966 "Rescan for Applications",
967 "Run xfce4 from Minimenu",
968 "Run a terminal/console",
969 "Exit and run xfce4",
970 "Exit and run pmenu",
974 int sel = ui_modal_single_menu ( opts, 9, "Minimenu", "Enter to select; other to return." );
979 } else if ( sel == 1 ) {
981 sprintf ( buffer, "sudo poweroff" );
983 } else if ( sel == 2 ) {
985 pnd_log ( pndn_debug, "Freeing up applications\n" );
987 pnd_log ( pndn_debug, "Rescanning applications\n" );
991 ui_rows_scrolled_down = 0;
992 } else if ( sel == 3 ) {
994 char buffer [ PATH_MAX ];
995 sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/bin/startxfce4" );
996 emit_and_quit ( buffer );
997 } else if ( sel == 4 ) {
1000 argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
1004 ui_forkexec ( argv );
1007 } else if ( sel == 5 ) {
1009 sprintf ( buffer, "echo startxfce4 > /tmp/gui.load" );
1011 //sprintf ( buffer, "sudo poweroff" );
1012 //system ( buffer );
1014 } else if ( sel == 6 ) {
1016 sprintf ( buffer, "echo pmenu > /tmp/gui.load" );
1018 //sprintf ( buffer, "sudo poweroff" );
1019 //system ( buffer );
1021 } else if ( sel == 7 ) {
1022 emit_and_quit ( MM_QUIT );
1023 } else if ( sel == 8 ) {
1031 if ( event.key.keysym.sym == SDLK_q ) {
1032 emit_and_quit ( MM_QUIT );
1038 #if 1 // mouse / touchscreen
1040 case SDL_MOUSEBUTTONDOWN:
1041 if ( event.button.button == SDL_BUTTON_LEFT ) {
1042 cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
1048 case SDL_MOUSEBUTTONUP:
1049 if ( event.button.button == SDL_BUTTON_LEFT ) {
1050 ui_touch_act ( event.button.x, event.button.y );
1063 } // switch event type
1070 void ui_push_left ( unsigned char forcecoil ) {
1072 if ( ! ui_selected ) {
1073 ui_push_right ( 0 );
1077 // what column we in?
1078 unsigned int col = ui_determine_screen_col ( ui_selected );
1080 // are we alreadt at first item?
1081 if ( forcecoil == 0 &&
1082 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1085 unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1087 ui_push_right ( 0 );
1091 } else if ( g_categories [ ui_category ].refs == ui_selected ) {
1092 // can't go any more left, we're at the head
1095 // figure out the previous item; yay for singly linked list :/
1096 mm_appref_t *i = g_categories [ ui_category ].refs;
1098 if ( i -> next == ui_selected ) {
1106 ui_set_selected ( ui_selected );
1111 void ui_push_right ( unsigned char forcecoil ) {
1113 if ( ui_selected ) {
1115 // what column we in?
1116 unsigned int col = ui_determine_screen_col ( ui_selected );
1119 if ( forcecoil == 0 &&
1120 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1121 col == pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1 )
1124 unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1131 // just go to the next
1133 if ( ui_selected -> next ) {
1134 ui_selected = ui_selected -> next;
1140 ui_selected = g_categories [ ui_category ].refs;
1143 ui_set_selected ( ui_selected );
1148 void ui_push_up ( void ) {
1149 unsigned char col_max = pnd_conf_get_as_int ( g_conf, MMENU_DISP_COLMAX );
1151 if ( ! ui_selected ) {
1156 unsigned int row = ui_determine_row ( ui_selected );
1159 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 1 ) == 0 )
1161 // wrap around instead
1163 unsigned int col = ui_determine_screen_col ( ui_selected );
1166 ui_selected = g_categories [ ui_category ].refs;
1167 while ( ui_selected -> next ) {
1168 ui_selected = ui_selected -> next;
1171 // try to move to same column
1172 unsigned int newcol = ui_determine_screen_col ( ui_selected );
1173 if ( newcol > col ) {
1181 // scroll down to show it
1182 int r = ui_determine_row ( ui_selected ) - 1;
1183 if ( r - pnd_conf_get_as_int ( g_conf, MMENU_DISP_ROWMAX ) > 0 ) {
1184 ui_rows_scrolled_down = (unsigned int) r;
1188 // stop at top/bottom
1200 void ui_push_down ( void ) {
1201 unsigned char col_max = pnd_conf_get_as_int ( g_conf, MMENU_DISP_COLMAX );
1203 if ( ui_selected ) {
1206 unsigned int row = ui_determine_row ( ui_selected );
1209 unsigned int icon_rows = g_categories [ ui_category ].refcount / col_max;
1210 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
1215 if ( row == ( icon_rows - 1 ) &&
1216 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 1 ) == 0 )
1219 unsigned char col = ui_determine_screen_col ( ui_selected );
1221 ui_selected = g_categories [ ui_category ].refs;
1224 ui_selected = ui_selected -> next;
1228 ui_rows_scrolled_down = 0;
1233 ui_push_right ( 1 );
1240 ui_push_right ( 0 );
1246 void ui_push_exec ( void ) {
1248 if ( ui_selected ) {
1249 char buffer [ PATH_MAX ];
1250 sprintf ( buffer, "%s/%s", ui_selected -> ref -> object_path, ui_selected -> ref -> object_filename );
1251 pnd_apps_exec ( pnd_run_script,
1253 ui_selected -> ref -> unique_id,
1254 ui_selected -> ref -> exec,
1255 ui_selected -> ref -> startdir,
1256 ui_selected -> ref -> execargs,
1257 atoi ( ui_selected -> ref -> clockspeed ),
1258 PND_EXEC_OPTION_NORUN );
1259 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1260 emit_and_quit ( buffer );
1266 void ui_push_ltrigger ( void ) {
1267 unsigned char oldcat = ui_category;
1269 if ( ui_category > 0 ) {
1272 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1273 ui_category = g_categorycount - 1;
1277 if ( oldcat != ui_category ) {
1279 ui_set_selected ( ui_selected );
1282 // make tab visible?
1283 if ( ui_catshift > 0 && ui_category == ui_catshift - 1 ) {
1288 ui_rows_scrolled_down = 0;
1293 void ui_push_rtrigger ( void ) {
1294 unsigned char oldcat = ui_category;
1296 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
1297 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1299 if ( ui_category < ( g_categorycount - 1 ) ) {
1302 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1307 if ( oldcat != ui_category ) {
1309 ui_set_selected ( ui_selected );
1312 // make tab visible?
1313 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
1318 ui_rows_scrolled_down = 0;
1323 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ) {
1324 double scale = 1000000.0;
1325 double scalex = 1000000.0;
1326 double scaley = 1000000.0;
1327 SDL_Surface *scaled;
1329 scalex = (double)maxwidth / (double)s -> w;
1331 if ( maxheight == -1 ) {
1334 scaley = (double)maxheight / (double)s -> h;
1336 if ( scaley < scalex ) {
1344 scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
1345 SDL_FreeSurface ( s );
1351 void ui_loadscreen ( void ) {
1355 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1356 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1357 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1358 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1361 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1365 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1366 rtext = TTF_RenderText_Blended ( g_big_font, "Setting up menu...", tmpfontcolor );
1369 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1370 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1371 SDL_FreeSurface ( rtext );
1376 void ui_discoverscreen ( unsigned char clearscreen ) {
1380 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1381 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1382 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1383 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1386 if ( clearscreen ) {
1387 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1389 // render background
1390 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1393 dest.w = sdl_realscreen -> w;
1394 dest.h = sdl_realscreen -> h;
1395 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1396 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1403 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1404 rtext = TTF_RenderText_Blended ( g_big_font, "Looking for applications...", tmpfontcolor );
1405 if ( clearscreen ) {
1412 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1413 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1414 SDL_FreeSurface ( rtext );
1417 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1418 dest.x = rtext -> w + 30;
1420 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, &dest );
1421 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1427 void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
1429 SDL_Rect rects [ 4 ];
1430 SDL_Rect *dest = rects;
1432 bzero ( dest, sizeof(SDL_Rect)* 4 );
1434 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1435 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1436 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1437 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1439 static unsigned int stepx = 0;
1442 if ( clearscreen ) {
1443 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1445 // render background
1446 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1449 dest -> w = sdl_realscreen -> w;
1450 dest -> h = sdl_realscreen -> h;
1451 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1457 // render background
1458 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1461 src.w = sdl_realscreen -> w;
1465 dest -> w = sdl_realscreen -> w;
1466 dest -> h = sdl_realscreen -> h;
1467 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
1475 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1476 rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
1479 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1480 SDL_FreeSurface ( rtext );
1484 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1485 dest -> x = rtext -> w + 30 + stepx;
1487 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, dest );
1493 rtext = TTF_RenderText_Blended ( g_tab_font, filename, tmpfontcolor );
1496 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1497 SDL_FreeSurface ( rtext );
1504 if ( stepx > 350 ) {
1508 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1513 int ui_selected_index ( void ) {
1515 if ( ! ui_selected ) {
1516 return ( -1 ); // no index
1519 mm_appref_t *r = g_categories [ ui_category ].refs;
1522 if ( r == ui_selected ) {
1532 static mm_appref_t *timer_ref = NULL;
1533 void ui_set_selected ( mm_appref_t *r ) {
1535 if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1536 return; // no desire to defer anything
1541 SDL_SetTimer ( 0, NULL );
1546 SDL_SetTimer ( pnd_conf_get_as_int_d ( g_conf, "previewpic.defer_timer_ms", 1000 ), ui_callback_f );
1552 unsigned int ui_callback_f ( unsigned int t ) {
1554 if ( ui_selected != timer_ref ) {
1555 return ( 0 ); // user has moved it, who cares
1559 bzero ( &e, sizeof(SDL_Event) );
1560 e.type = SDL_USEREVENT;
1561 e.user.code = sdl_user_ticker;
1562 SDL_PushEvent ( &e );
1567 int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer ) {
1568 SDL_Rect rects [ 40 ];
1569 SDL_Rect *dest = rects;
1573 bzero ( rects, sizeof(SDL_Rect) * 40 );
1575 unsigned int sel = 0;
1577 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1578 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1579 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1580 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1582 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1584 SDL_Color selfontcolor = { 0/*font_rgba_r*/, font_rgba_g, font_rgba_b, font_rgba_a };
1592 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1593 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1594 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
1595 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
1596 SDL_FillRect( sdl_realscreen, dest, 0 );
1598 // show dialog background
1599 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
1600 src.x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1601 src.y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1602 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
1603 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
1604 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1605 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1606 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1607 // repeat for darken?
1608 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1609 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1610 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1614 // show dialog frame
1615 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
1616 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1617 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1618 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
1619 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1625 rtext = TTF_RenderText_Blended ( g_tab_font, title, tmpfontcolor );
1626 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1627 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
1628 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1629 SDL_FreeSurface ( rtext );
1635 rtext = TTF_RenderText_Blended ( g_tab_font, footer, tmpfontcolor );
1636 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1637 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
1638 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
1640 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1641 SDL_FreeSurface ( rtext );
1646 for ( i = 0; i < argc; i++ ) {
1650 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
1652 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], tmpfontcolor );
1654 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1655 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 ) );
1656 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1657 SDL_FreeSurface ( rtext );
1662 // update all the rects and send it all to sdl
1663 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1667 while ( SDL_WaitEvent ( &event ) ) {
1669 switch ( event.type ) {
1673 if ( event.key.keysym.sym == SDLK_UP ) {
1677 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1678 if ( sel < argc - 1 ) {
1682 } else if ( event.key.keysym.sym == SDLK_RETURN ) {
1685 } else if ( event.key.keysym.sym == SDLK_q ) {
1689 return ( -1 ); // nada
1704 unsigned char ui_determine_row ( mm_appref_t *a ) {
1705 unsigned int row = 0;
1707 mm_appref_t *i = g_categories [ ui_category ].refs;
1712 row /= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
1717 unsigned char ui_determine_screen_row ( mm_appref_t *a ) {
1718 return ( ui_determine_row ( a ) % pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 5 ) );
1721 unsigned char ui_determine_screen_col ( mm_appref_t *a ) {
1722 unsigned int col = 0;
1724 mm_appref_t *i = g_categories [ ui_category ].refs;
1729 col %= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
1734 unsigned char ui_show_info ( char *pndrun, pnd_disco_t *p ) {
1735 char *viewer, *searchpath;
1736 pnd_conf_handle desktoph;
1739 searchpath = pnd_conf_query_searchpath();
1741 desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
1747 viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
1750 return ( 0 ); // no way to view the file
1754 if ( ! p -> unique_id ) {
1758 if ( ! p -> info_filename ) {
1762 if ( ! p -> info_name ) {
1773 if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) {
1774 snprintf ( pargs, 1001, "%s %s",
1775 pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
1780 char pndfile [ 1024 ];
1781 if ( p -> object_type == pnd_object_type_directory ) {
1782 // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
1783 strncpy ( pndfile, p -> object_path, 1000 );
1784 } else if ( p -> object_type == pnd_object_type_pnd ) {
1785 // pnd_run.sh wants the full path and filename for the .pnd file
1786 snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
1789 if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs,
1790 p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) )
1795 pnd_log ( pndn_debug, "Info Exec=%s\n", pnd_apps_exec_runline() );
1799 if ( ( x = fork() ) < 0 ) {
1800 pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
1805 execl ( "/bin/sh", "/bin/sh", "-c", pnd_apps_exec_runline(), (char*)NULL );
1806 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", pnd_apps_exec_runline() );
1818 #define MAXTOUCH 100
1819 ui_touch_t ui_touchrects [ MAXTOUCH ];
1820 unsigned char ui_touchrect_count = 0;
1822 void ui_register_reset ( void ) {
1823 bzero ( ui_touchrects, sizeof(ui_touch_t)*MAXTOUCH );
1824 ui_touchrect_count = 0;
1828 void ui_register_tab ( unsigned char catnum, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
1830 if ( ui_touchrect_count == MAXTOUCH ) {
1834 ui_touchrects [ ui_touchrect_count ].r.x = x;
1835 ui_touchrects [ ui_touchrect_count ].r.y = y;
1836 ui_touchrects [ ui_touchrect_count ].r.w = w;
1837 ui_touchrects [ ui_touchrect_count ].r.h = h;
1838 ui_touchrects [ ui_touchrect_count ].catnum = catnum;
1839 ui_touchrect_count++;
1844 void ui_register_app ( mm_appref_t *app, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
1846 if ( ui_touchrect_count == MAXTOUCH ) {
1850 ui_touchrects [ ui_touchrect_count ].r.x = x;
1851 ui_touchrects [ ui_touchrect_count ].r.y = y;
1852 ui_touchrects [ ui_touchrect_count ].r.w = w;
1853 ui_touchrects [ ui_touchrect_count ].r.h = h;
1854 ui_touchrects [ ui_touchrect_count ].ref = app;
1855 ui_touchrect_count++;
1860 void ui_touch_act ( unsigned int x, unsigned int y ) {
1865 for ( i = 0; i < ui_touchrect_count; i++ ) {
1866 t = &(ui_touchrects [ i ]);
1868 if ( x >= t -> r.x &&
1869 x <= t -> r.x + t -> r.w &&
1871 y <= t -> r.y + t -> r.h
1876 ui_selected = t -> ref;
1879 ui_category = t -> catnum;
1890 unsigned char ui_forkexec ( char *argv[] ) {
1891 char *fooby = argv[0];
1894 if ( ( x = fork() ) < 0 ) {
1895 pnd_log ( pndn_error, "ERROR: Couldn't fork() for '%s'\n", fooby );
1899 if ( x == 0 ) { // child
1900 execv ( fooby, argv );
1901 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", fooby );
1909 unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ) {
1911 if ( ! cache_preview ( p, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
1912 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
1915 pnd_log ( pndn_debug, "THREAD: Couldn't load preview pic: '%s' -> '%s'\n",
1916 IFNULL(p->title_en,"No Name"), p -> preview_pic1 );
1919 // trigger that we completed
1921 bzero ( &e, sizeof(SDL_Event) );
1922 e.type = SDL_USEREVENT;
1923 e.user.code = sdl_user_finishedpreview;
1925 SDL_PushEvent ( &e );