11 #include "SDL_gfxPrimitives.h"
12 #include "SDL_rotozoom.h"
15 #include "pnd_logger.h"
17 #include "pnd_container.h"
18 #include "pnd_discovery.h"
20 #include "pnd_device.h"
26 #include "mmwrapcmd.h"
30 SDL_Surface *sdl_realscreen = NULL;
31 unsigned int sdl_ticks = 0;
35 unsigned short int g_scale = 1; // 1 == noscale
37 SDL_Surface *g_imgcache [ IMG_MAX ];
39 TTF_Font *g_big_font = NULL;
40 TTF_Font *g_grid_font = NULL;
41 TTF_Font *g_detailtext_font = NULL;
42 TTF_Font *g_tab_font = NULL;
44 extern pnd_conf_handle g_conf;
46 /* current display state
48 int ui_rows_scrolled_down = 0; // number of rows that should be missing from top of the display
49 mm_appref_t *ui_selected = NULL;
50 unsigned char ui_category = 0; // current category
51 unsigned char ui_catshift = 0; // how many cats are offscreen to the left
53 extern mm_category_t g_categories [ MAX_CATS ];
54 extern unsigned char g_categorycount;
56 static SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ); // height -1 means ignore
57 static int ui_selected_index ( void );
59 unsigned char ui_setup ( void ) {
64 SDL_Init ( SDL_INIT_EVERYTHING | SDL_INIT_NOPARACHUTE );
66 SDL_JoystickOpen ( 0 ); // turn on joy-0
68 SDL_WM_SetCaption ( "mmenu", "mmenu" );
70 // hide the mouse cursor if we can
71 if ( SDL_ShowCursor ( -1 ) == 1 ) {
78 unsigned int svm = SDL_SWSURFACE /*| SDL_FULLSCREEN*/ /* 0*/;
79 if ( pnd_conf_get_as_int_d ( g_conf, "display.fullscreen", 0 ) > 0 ) {
80 svm |= SDL_FULLSCREEN;
84 SDL_SetVideoMode ( 800 * g_scale, 480 * g_scale, 16 /*bpp*/, svm );
86 if ( ! sdl_realscreen ) {
87 pnd_log ( pndn_error, "ERROR: Couldn't open SDL real screen; dieing." );
91 pnd_log ( pndn_debug, "Pixel format:" );
92 pnd_log ( pndn_debug, "bpp b: %u\n", sdl_realscreen -> format -> BitsPerPixel );
93 pnd_log ( pndn_debug, "bpp B: %u\n", sdl_realscreen -> format -> BytesPerPixel );
94 pnd_log ( pndn_debug, "R mask: %08x\n", sdl_realscreen -> format -> Rmask );
95 pnd_log ( pndn_debug, "G mask: %08x\n", sdl_realscreen -> format -> Gmask );
96 pnd_log ( pndn_debug, "B mask: %08x\n", sdl_realscreen -> format -> Bmask );
102 /* Set 16-bit stereo audio at 22Khz */
103 fmt.freq = 44100; //22050;
104 fmt.format = AUDIO_S16; //AUDIO_S16;
106 fmt.samples = 2048; /* A good value for games */
107 fmt.callback = mixaudio;
110 /* Open the audio device and start playing sound! */
111 if ( SDL_OpenAudio ( &fmt, NULL ) < 0 ) {
112 zotlog ( "Unable to open audio: %s\n", SDL_GetError() );
116 SDL_PauseAudio ( 0 );
121 //IMG_Init ( IMG_INIT_JPG | IMG_INIT_PNG );
127 if ( TTF_Init() == -1 ) {
128 pnd_log ( pndn_error, "ERROR: Couldn't set up SDL TTF lib\n" );
129 return ( 0 ); // couldn't set up SDL TTF
132 char fullpath [ PATH_MAX ];
134 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "minimenu.font" ) );
135 g_big_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
136 if ( ! g_big_font ) {
137 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
138 pnd_conf_get_as_char ( g_conf, "minimenu.font" ), pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
139 return ( 0 ); // couldn't set up SDL TTF
143 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, MMENU_GRID_FONT ) );
144 g_grid_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, MMENU_GRID_FONTSIZE, 10 ) );
145 if ( ! g_grid_font ) {
146 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
147 pnd_conf_get_as_char ( g_conf, MMENU_GRID_FONT ), pnd_conf_get_as_int_d ( g_conf, MMENU_GRID_FONTSIZE, 10 ) );
148 return ( 0 ); // couldn't set up SDL TTF
152 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "detailtext.font" ) );
153 g_detailtext_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
154 if ( ! g_detailtext_font ) {
155 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
156 pnd_conf_get_as_char ( g_conf, "detailtext.font" ), pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
157 return ( 0 ); // couldn't set up SDL TTF
161 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "tabs.font" ) );
162 g_tab_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
163 if ( ! g_tab_font ) {
164 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
165 pnd_conf_get_as_char ( g_conf, "tabs.font" ), pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
166 return ( 0 ); // couldn't set up SDL TTF
172 mm_imgcache_t g_imagecache [ IMG_TRUEMAX ] = {
173 { IMG_BACKGROUND_800480, "graphics.IMG_BACKGROUND_800480" },
174 { IMG_BACKGROUND_TABMASK, "graphics.IMG_BACKGROUND_TABMASK" },
175 { IMG_DETAIL_PANEL, "graphics.IMG_DETAIL_PANEL" },
176 { IMG_DETAIL_BG, "graphics.IMG_DETAIL_BG" },
177 { IMG_SELECTED_ALPHAMASK, "graphics.IMG_SELECTED_ALPHAMASK" },
178 { IMG_TAB_SEL, "graphics.IMG_TAB_SEL" },
179 { IMG_TAB_UNSEL, "graphics.IMG_TAB_UNSEL" },
180 { IMG_ICON_MISSING, "graphics.IMG_ICON_MISSING" },
181 { IMG_SELECTED_HILITE, "graphics.IMG_SELECTED_HILITE" },
182 { IMG_PREVIEW_MISSING, "graphics.IMG_PREVIEW_MISSING" },
183 { IMG_ARROW_UP, "graphics.IMG_ARROW_UP", },
184 { IMG_ARROW_DOWN, "graphics.IMG_ARROW_DOWN", },
185 { IMG_ARROW_SCROLLBAR, "graphics.IMG_ARROW_SCROLLBAR", },
189 unsigned char ui_imagecache ( char *basepath ) {
191 char fullpath [ PATH_MAX ];
195 for ( i = 0; i < IMG_MAX; i++ ) {
197 if ( g_imagecache [ i ].id != i ) {
198 pnd_log ( pndn_error, "ERROR: Internal table mismatch during caching [%u]\n", i );
202 char *filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].confname );
205 pnd_log ( pndn_error, "ERROR: Missing filename in conf for key: %s\n", g_imagecache [ i ].confname );
209 sprintf ( fullpath, "%s/%s", basepath, filename );
211 if ( ! ( g_imagecache [ i ].i = IMG_Load ( fullpath ) ) ) {
212 pnd_log ( pndn_error, "ERROR: Couldn't load static cache image: %s\n", fullpath );
219 //g_imagecache [ IMG_SELECTED_ALPHAMASK ].i = SDL_CreateRGBSurface ( SDL_SWSURFACE, 60, 60, 32, 0xFF0000, 0x00FF00, 0xFF, 0xFF000000 );
220 //boxRGBA ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, 0, 0, 60, 60, 100, 100, 100, 250 );
226 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 );
227 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 );
228 // scale text hilight
229 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 );
230 // scale preview no-pic
231 g_imagecache [ IMG_PREVIEW_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_PREVIEW_MISSING ].i,
232 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ),
233 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 50 ) );
235 // set alpha on detail panel
236 SDL_SetAlpha ( g_imagecache [ IMG_DETAIL_BG ].i, SDL_SRCALPHA, pnd_conf_get_as_int_d ( g_conf, "display.detail_bg_alpha", 50 ) );
241 void ui_render ( unsigned int render_mask ) {
244 // divide width: 550 / 250
245 // divide left side: 5 columns == 110px width
246 // 20px buffer either side == 70px wide icon + 20 + 20?
248 unsigned int icon_rows;
251 SDL_Rect rects [ MAXRECTS ], src;
252 SDL_Rect *dest = rects;
253 bzero ( dest, sizeof(SDL_Rect)*MAXRECTS );
255 unsigned int row, displayrow, col;
256 mm_appref_t *appiter;
258 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
260 unsigned char row_max = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_ROWMAX, 4 );
261 unsigned char col_max = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_COLMAX, 5 );
263 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
264 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
265 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
266 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
268 unsigned int grid_offset_x = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_x" );
269 unsigned int grid_offset_y = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_y" );
271 unsigned int icon_offset_x = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_x" );
272 unsigned int icon_offset_y = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_y" );
273 unsigned int icon_max_width = pnd_conf_get_as_int ( g_conf, "grid.icon_max_width" );
275 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
276 unsigned int text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
277 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "grid.text_offset_x" );
278 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_offset_y" );
280 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "grid.cell_width" );
281 unsigned int cell_height = pnd_conf_get_as_int ( g_conf, "grid.cell_height" );
283 // how many total rows do we need?
284 icon_rows = g_categories [ ui_category ].refcount / col_max;
285 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
289 // if no selected app yet, select the first one
291 if ( ! ui_selected ) {
292 ui_selected = g_categories [ ui_category ].refs;
296 // reset touchscreen regions
299 // ensure selection is visible
302 int index = ui_selected_index();
303 int topleft = col_max * ui_rows_scrolled_down;
304 int botright = ( col_max * ( ui_rows_scrolled_down + row_max ) - 1 );
306 //pnd_log ( PND_LOG_DEFAULT, "index %u tl %u br %u\n", index, topleft, botright );
308 if ( index < topleft ) {
309 ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
310 } else if ( index > botright ) {
311 ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
314 if ( ui_rows_scrolled_down < 0 ) {
315 ui_rows_scrolled_down = 0;
316 } else if ( ui_rows_scrolled_down > icon_rows ) {
317 ui_rows_scrolled_down = icon_rows;
323 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
326 dest -> w = sdl_realscreen -> w;
327 dest -> h = sdl_realscreen -> h;
328 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
333 if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
336 dest -> w = sdl_realscreen -> w;
337 dest -> h = sdl_realscreen -> h;
338 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
343 if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
344 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
345 unsigned int tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
346 unsigned int tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
347 unsigned int tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
348 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
349 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
350 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
352 for ( col = ui_catshift;
354 ( screen_width / tab_width ) < g_categorycount ? ( screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift
360 if ( col == ui_category ) {
361 s = g_imagecache [ IMG_TAB_SEL ].i;
363 s = g_imagecache [ IMG_TAB_UNSEL ].i;
371 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
372 dest -> y = tab_offset_y;
373 //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
374 SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
377 ui_register_tab ( col, dest -> x, dest -> y, tab_width, tab_height );
383 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
384 rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ].catname, tmpfontcolor );
387 src.w = rtext -> w < text_width ? rtext -> w : text_width;
389 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
390 dest -> y = tab_offset_y + text_offset_y;
391 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
392 SDL_FreeSurface ( rtext );
399 // scroll bars and arrows
401 unsigned char show_bar = 0;
404 if ( ui_rows_scrolled_down && g_imagecache [ IMG_ARROW_UP ].i ) {
405 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
406 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
407 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
414 if ( ui_rows_scrolled_down + row_max < icon_rows && g_imagecache [ IMG_ARROW_DOWN ].i ) {
415 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
416 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
417 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
424 // show scrollbar as well
427 src.w = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_w", 10 );
428 src.h = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_h", 100 );
429 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
430 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
431 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
437 // render detail pane bg
438 if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
440 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
441 src.x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
442 src.y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
443 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
444 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
445 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
446 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
447 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
451 // render detail pane
452 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
453 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
454 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
455 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
459 } // detailpane frame/bg
461 // anything to render?
462 if ( g_categories [ ui_category ].refs ) {
464 appiter = g_categories [ ui_category ].refs;
468 // until we run out of apps, or run out of space
469 while ( appiter != NULL ) {
471 for ( col = 0; col < col_max && appiter != NULL; col++ ) {
473 // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
474 if ( row >= ui_rows_scrolled_down ) {
476 // selected? show hilights
477 if ( appiter == ui_selected ) {
479 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x;
480 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y;
481 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, NULL /* all */, sdl_realscreen, dest );
484 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
485 dest -> y = grid_offset_y + ( displayrow * cell_height ) + pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
486 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
491 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
492 SDL_Surface *iconsurface;
494 iconsurface = ic -> i;
496 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
497 iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
500 //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
506 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + (( icon_max_width - iconsurface -> w ) / 2);
507 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y;
509 SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
512 ui_register_app ( appiter, dest -> x, dest -> y, src.w, src.h );
519 if ( appiter -> ref -> title_en ) {
521 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
522 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, tmpfontcolor );
525 src.w = text_width < rtext -> w ? text_width : rtext -> w;
527 if ( rtext -> w > text_width ) {
528 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
530 dest -> x = grid_offset_x + ( col * cell_width ) + text_offset_x - ( rtext -> w / 2 );
532 dest -> y = grid_offset_y + ( displayrow * cell_height ) + text_offset_y;
533 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
534 SDL_FreeSurface ( rtext );
538 } // display now? or scrolled away..
541 appiter = appiter -> next;
543 } // for column 1...X
545 if ( row >= ui_rows_scrolled_down ) {
551 // are we done displaying rows?
552 if ( displayrow >= row_max ) {
559 // no apps to render?
560 pnd_log ( pndn_rem, "No applications to render?\n" );
566 unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
567 unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
568 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "detailtext.cell_width" );
570 unsigned int desty = cell_offset_y;
575 if ( ui_selected -> ref -> title_en ) {
577 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
578 rtext = TTF_RenderText_Blended ( g_detailtext_font, ui_selected -> ref -> title_en, tmpfontcolor );
581 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
583 dest -> x = cell_offset_x;
585 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
586 SDL_FreeSurface ( rtext );
592 if ( ui_selected -> ref -> main_category ) {
594 sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
597 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
598 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
601 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
603 dest -> x = cell_offset_x;
605 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
606 SDL_FreeSurface ( rtext );
612 if ( ui_selected -> ref -> clockspeed ) {
614 sprintf ( buffer, "CPU Clock: %s", ui_selected -> ref -> clockspeed );
617 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
618 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
621 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
623 dest -> x = cell_offset_x;
625 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
626 SDL_FreeSurface ( rtext );
632 if ( ui_selected -> ref -> clockspeed && ui_selected -> ref -> info_filename ) {
634 sprintf ( buffer, "Documentation - hit Y" );
637 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
638 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
641 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
643 dest -> x = cell_offset_x;
645 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
646 SDL_FreeSurface ( rtext );
652 mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
653 SDL_Surface *previewpic;
656 previewpic = ic -> i;
658 previewpic = g_imagecache [ IMG_PREVIEW_MISSING ].i;
662 dest -> x = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_x", 50 ) +
663 ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
664 dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
665 SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
676 unsigned char batterylevel = pnd_device_get_battery_gauge_perc();
679 sprintf ( buffer, "Battery: %u%%", batterylevel );
682 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
683 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
684 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.battery_x", 20 );
685 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.battery_y", 450 );
686 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
687 SDL_FreeSurface ( rtext );
692 if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
693 char *buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
695 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
696 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
697 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
698 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
699 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
700 SDL_FreeSurface ( rtext );
705 if ( pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 ) {
708 time_t t = time ( NULL );
709 struct tm *tm = localtime ( &t );
710 strftime ( buffer, 50, "%a %H:%M %F", tm );
713 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
714 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
715 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.clock_x", 700 );
716 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.clock_y", 450 );
717 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
718 SDL_FreeSurface ( rtext );
722 // update all the rects and send it all to sdl
723 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
727 void ui_process_input ( unsigned char block_p ) {
730 unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
731 //static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
733 while ( ! ui_event &&
734 block_p ? SDL_WaitEvent ( &event ) : SDL_PollEvent ( &event ) )
737 switch ( event.type ) {
742 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
744 pnd_log ( pndn_debug, "Deferred preview pic load ----------\n" );
746 // load the preview pics now!
747 pnd_disco_t *iter = ui_selected -> ref;
749 if ( iter -> preview_pic1 &&
750 ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ), pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) ) )
752 pnd_log ( pndn_debug, " Couldn't load preview pic: '%s' -> '%s'\n", IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
755 pnd_log ( pndn_debug, "Deferred preview pic load finish ---\n" );
762 #if 0 // joystick motion
763 case SDL_JOYAXISMOTION:
765 pnd_log ( PND_LOG_DEFAULT, "joystick axis\n" );
767 if ( event.jaxis.axis == 0 ) {
769 if ( event.jaxis.value < 0 ) {
771 pnd_log ( PND_LOG_DEFAULT, "joystick axis - LEFT\n" );
772 } else if ( event.jaxis.value > 0 ) {
774 pnd_log ( PND_LOG_DEFAULT, "joystick axis - RIGHT\n" );
776 } else if ( event.jaxis.axis == 1 ) {
778 if ( event.jaxis.value < 0 ) {
780 } else if ( event.jaxis.value > 0 ) {
790 #if 0 // joystick buttons
791 case SDL_JOYBUTTONDOWN:
793 pnd_log ( PND_LOG_DEFAULT, "joystick button down %u\n", event.jbutton.button );
795 if ( event.jbutton.button == 0 ) { // B
797 } else if ( event.jbutton.button == 1 ) { // Y
799 } else if ( event.jbutton.button == 2 ) { // X
801 } else if ( event.jbutton.button == 3 ) { // A
804 } else if ( event.jbutton.button == 4 ) { // Select
805 ui_mask |= uisb_select;
806 } else if ( event.jbutton.button == 5 ) { // Start
807 ui_mask |= uisb_start;
809 } else if ( event.jbutton.button == 7 ) { // L
811 } else if ( event.jbutton.button == 8 ) { // R
820 case SDL_JOYBUTTONUP:
822 pnd_log ( PND_LOG_DEFAULT, "joystick button up %u\n", event.jbutton.button );
824 if ( event.jbutton.button == 0 ) { // B
827 } else if ( event.jbutton.button == 1 ) { // Y
829 } else if ( event.jbutton.button == 2 ) { // X
831 } else if ( event.jbutton.button == 3 ) { // A
834 } else if ( event.jbutton.button == 4 ) { // Select
835 ui_mask &= ~uisb_select;
836 } else if ( event.jbutton.button == 5 ) { // Start
837 ui_mask &= ~uisb_start;
839 } else if ( event.jbutton.button == 7 ) { // L
842 } else if ( event.jbutton.button == 8 ) { // R
853 #if 1 // keyboard events
856 //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
858 // SDLK_LALT -> Start
861 if ( event.key.keysym.sym == SDLK_RIGHT ) {
864 } else if ( event.key.keysym.sym == SDLK_LEFT ) {
867 } else if ( event.key.keysym.sym == SDLK_UP ) {
870 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
873 } else if ( event.key.keysym.sym == SDLK_SPACE || event.key.keysym.sym == SDLK_END ) {
876 } else if ( event.key.keysym.sym == SDLK_z || event.key.keysym.sym == SDLK_RSHIFT ) {
879 } else if ( event.key.keysym.sym == SDLK_x || event.key.keysym.sym == SDLK_RCTRL ) {
882 } else if ( event.key.keysym.sym == SDLK_y || event.key.keysym.sym == SDLK_PAGEUP ) {
885 ui_show_info ( pnd_run_script, ui_selected -> ref );
889 } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
893 } else if ( event.key.keysym.sym == SDLK_LCTRL /*LALT*/ ) { // select button
894 char *opts [ 20 ] = {
895 "Return to Minimenu",
897 "Rescan for Applications",
898 "Run xfce4 from Minimenu",
899 "Exit and run xfce4",
900 "Exit and run pmenu",
904 int sel = ui_modal_single_menu ( opts, 8, "Minimenu", "Enter to select; other to return." );
909 } else if ( sel == 1 ) {
911 sprintf ( buffer, "sudo poweroff" );
913 } else if ( sel == 2 ) {
915 pnd_log ( pndn_debug, "Freeing up applications\n" );
917 pnd_log ( pndn_debug, "Rescanning applications\n" );
921 ui_rows_scrolled_down = 0;
922 } else if ( sel == 3 ) {
924 char buffer [ PATH_MAX ];
925 sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/bin/startxfce4" );
926 emit_and_quit ( buffer );
927 } else if ( sel == 4 ) {
929 sprintf ( buffer, "echo startxfce4 > /tmp/gui.load" );
931 //sprintf ( buffer, "sudo poweroff" );
934 } else if ( sel == 5 ) {
936 sprintf ( buffer, "echo pmenu > /tmp/gui.load" );
938 //sprintf ( buffer, "sudo poweroff" );
941 } else if ( sel == 6 ) {
942 emit_and_quit ( MM_QUIT );
943 } else if ( sel == 7 ) {
951 if ( event.key.keysym.sym == SDLK_q ) {
952 emit_and_quit ( MM_QUIT );
958 #if 1 // mouse / touchscreen
960 case SDL_MOUSEBUTTONDOWN:
961 if ( event.button.button == SDL_BUTTON_LEFT ) {
962 cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
968 case SDL_MOUSEBUTTONUP:
969 if ( event.button.button == SDL_BUTTON_LEFT ) {
970 ui_touch_act ( event.button.x, event.button.y );
983 } // switch event type
990 void ui_push_left ( unsigned char forcecoil ) {
992 if ( ! ui_selected ) {
997 // what column we in?
998 unsigned int col = ui_determine_screen_col ( ui_selected );
1000 // are we alreadt at first item?
1001 if ( forcecoil == 0 &&
1002 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1005 unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1007 ui_push_right ( 0 );
1011 } else if ( g_categories [ ui_category ].refs == ui_selected ) {
1012 // can't go any more left, we're at the head
1015 // figure out the previous item; yay for singly linked list :/
1016 mm_appref_t *i = g_categories [ ui_category ].refs;
1018 if ( i -> next == ui_selected ) {
1026 ui_set_selected ( ui_selected );
1031 void ui_push_right ( unsigned char forcecoil ) {
1033 if ( ui_selected ) {
1035 // what column we in?
1036 unsigned int col = ui_determine_screen_col ( ui_selected );
1039 if ( forcecoil == 0 &&
1040 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1041 col == pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1 )
1044 unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1051 // just go to the next
1053 if ( ui_selected -> next ) {
1054 ui_selected = ui_selected -> next;
1060 ui_selected = g_categories [ ui_category ].refs;
1063 ui_set_selected ( ui_selected );
1068 void ui_push_up ( void ) {
1069 unsigned char col_max = pnd_conf_get_as_int ( g_conf, MMENU_DISP_COLMAX );
1072 unsigned int row = ui_determine_row ( ui_selected );
1075 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 1 ) == 0 )
1077 // wrap around instead
1079 unsigned int col = ui_determine_screen_col ( ui_selected );
1082 ui_selected = g_categories [ ui_category ].refs;
1083 while ( ui_selected -> next ) {
1084 ui_selected = ui_selected -> next;
1087 // try to move to same column
1088 unsigned int newcol = ui_determine_screen_col ( ui_selected );
1089 if ( newcol > col ) {
1097 // scroll down to show it
1098 int r = ui_determine_row ( ui_selected ) - 1;
1099 if ( r - pnd_conf_get_as_int ( g_conf, MMENU_DISP_ROWMAX ) > 0 ) {
1100 ui_rows_scrolled_down = (unsigned int) r;
1104 // stop at top/bottom
1116 void ui_push_down ( void ) {
1117 unsigned char col_max = pnd_conf_get_as_int ( g_conf, MMENU_DISP_COLMAX );
1119 if ( ui_selected ) {
1122 unsigned int row = ui_determine_row ( ui_selected );
1125 unsigned int icon_rows = g_categories [ ui_category ].refcount / col_max;
1126 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
1131 if ( row == ( icon_rows - 1 ) &&
1132 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 1 ) == 0 )
1135 unsigned char col = ui_determine_screen_col ( ui_selected );
1137 ui_selected = g_categories [ ui_category ].refs;
1140 ui_selected = ui_selected -> next;
1144 ui_rows_scrolled_down = 0;
1149 ui_push_right ( 1 );
1156 ui_push_right ( 0 );
1162 void ui_push_exec ( void ) {
1164 if ( ui_selected ) {
1165 char buffer [ PATH_MAX ];
1166 sprintf ( buffer, "%s/%s", ui_selected -> ref -> object_path, ui_selected -> ref -> object_filename );
1167 pnd_apps_exec ( pnd_run_script,
1169 ui_selected -> ref -> unique_id,
1170 ui_selected -> ref -> exec,
1171 ui_selected -> ref -> startdir,
1172 ui_selected -> ref -> execargs,
1173 atoi ( ui_selected -> ref -> clockspeed ),
1174 PND_EXEC_OPTION_NORUN );
1175 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1176 emit_and_quit ( buffer );
1182 void ui_push_ltrigger ( void ) {
1183 unsigned char oldcat = ui_category;
1185 if ( ui_category > 0 ) {
1188 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1189 ui_category = g_categorycount - 1;
1193 if ( oldcat != ui_category ) {
1195 ui_set_selected ( ui_selected );
1198 // make tab visible?
1199 if ( ui_catshift > 0 && ui_category == ui_catshift - 1 ) {
1204 ui_rows_scrolled_down = 0;
1209 void ui_push_rtrigger ( void ) {
1210 unsigned char oldcat = ui_category;
1212 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
1213 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1215 if ( ui_category < ( g_categorycount - 1 ) ) {
1218 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1223 if ( oldcat != ui_category ) {
1225 ui_set_selected ( ui_selected );
1228 // make tab visible?
1229 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
1234 ui_rows_scrolled_down = 0;
1239 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ) {
1240 double scale = 1000000.0;
1241 double scalex = 1000000.0;
1242 double scaley = 1000000.0;
1243 SDL_Surface *scaled;
1245 scalex = (double)maxwidth / (double)s -> w;
1247 if ( maxheight == -1 ) {
1250 scaley = (double)maxheight / (double)s -> h;
1252 if ( scaley < scalex ) {
1260 scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
1261 SDL_FreeSurface ( s );
1267 void ui_loadscreen ( void ) {
1271 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1272 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1273 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1274 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1277 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1281 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1282 rtext = TTF_RenderText_Blended ( g_big_font, "Setting up menu...", tmpfontcolor );
1285 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1286 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1287 SDL_FreeSurface ( rtext );
1292 void ui_discoverscreen ( unsigned char clearscreen ) {
1296 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1297 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1298 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1299 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1302 if ( clearscreen ) {
1303 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1305 // render background
1306 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1309 dest.w = sdl_realscreen -> w;
1310 dest.h = sdl_realscreen -> h;
1311 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1312 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1319 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1320 rtext = TTF_RenderText_Blended ( g_big_font, "Looking for applications...", tmpfontcolor );
1321 if ( clearscreen ) {
1328 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1329 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1330 SDL_FreeSurface ( rtext );
1333 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1334 dest.x = rtext -> w + 30;
1336 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, &dest );
1337 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1343 void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
1345 SDL_Rect rects [ 4 ];
1346 SDL_Rect *dest = rects;
1347 bzero ( dest, sizeof(SDL_Rect)* 4 );
1349 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1350 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1351 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1352 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1354 static unsigned int stepx = 0;
1357 if ( clearscreen ) {
1358 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1360 // render background
1361 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1364 dest -> w = sdl_realscreen -> w;
1365 dest -> h = sdl_realscreen -> h;
1366 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1374 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1375 rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
1376 if ( clearscreen ) {
1383 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1384 SDL_FreeSurface ( rtext );
1388 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1389 dest -> x = rtext -> w + 30 + stepx;
1391 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, dest );
1397 rtext = TTF_RenderText_Blended ( g_tab_font, filename, tmpfontcolor );
1400 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1401 SDL_FreeSurface ( rtext );
1408 if ( stepx > 350 ) {
1412 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1417 int ui_selected_index ( void ) {
1419 if ( ! ui_selected ) {
1420 return ( -1 ); // no index
1423 mm_appref_t *r = g_categories [ ui_category ].refs;
1426 if ( r == ui_selected ) {
1436 static mm_appref_t *timer_ref = NULL;
1437 void ui_set_selected ( mm_appref_t *r ) {
1439 if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1440 return; // no desire to defer anything
1445 SDL_SetTimer ( 0, NULL );
1450 SDL_SetTimer ( pnd_conf_get_as_int_d ( g_conf, "previewpic.defer_timer_ms", 1000 ), ui_callback_f );
1456 unsigned int ui_callback_f ( unsigned int t ) {
1458 if ( ui_selected != timer_ref ) {
1459 return ( 0 ); // user has moved it, who cares
1463 e.type = SDL_USEREVENT;
1464 SDL_PushEvent ( &e );
1469 int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer ) {
1470 SDL_Rect rects [ 40 ];
1471 SDL_Rect *dest = rects;
1475 bzero ( rects, sizeof(SDL_Rect) * 40 );
1477 unsigned int sel = 0;
1479 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1480 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1481 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1482 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1484 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1486 SDL_Color selfontcolor = { 0/*font_rgba_r*/, font_rgba_g, font_rgba_b, font_rgba_a };
1494 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1495 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1496 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
1497 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
1498 SDL_FillRect( sdl_realscreen, dest, 0 );
1500 // show dialog background
1501 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
1502 src.x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1503 src.y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1504 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
1505 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
1506 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1507 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1508 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1509 // repeat for darken?
1510 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1511 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1512 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1516 // show dialog frame
1517 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
1518 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1519 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1520 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
1521 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1527 rtext = TTF_RenderText_Blended ( g_tab_font, title, tmpfontcolor );
1528 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1529 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
1530 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1531 SDL_FreeSurface ( rtext );
1537 rtext = TTF_RenderText_Blended ( g_tab_font, footer, tmpfontcolor );
1538 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1539 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
1540 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
1542 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1543 SDL_FreeSurface ( rtext );
1548 for ( i = 0; i < argc; i++ ) {
1552 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
1554 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], tmpfontcolor );
1556 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1557 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 ) );
1558 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1559 SDL_FreeSurface ( rtext );
1564 // update all the rects and send it all to sdl
1565 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1569 while ( SDL_WaitEvent ( &event ) ) {
1571 switch ( event.type ) {
1575 if ( event.key.keysym.sym == SDLK_UP ) {
1579 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1580 if ( sel < argc - 1 ) {
1584 } else if ( event.key.keysym.sym == SDLK_RETURN ) {
1587 } else if ( event.key.keysym.sym == SDLK_q ) {
1591 return ( -1 ); // nada
1606 unsigned char ui_determine_row ( mm_appref_t *a ) {
1607 unsigned int row = 0;
1609 mm_appref_t *i = g_categories [ ui_category ].refs;
1614 row /= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
1619 unsigned char ui_determine_screen_row ( mm_appref_t *a ) {
1620 return ( ui_determine_row ( a ) % pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 5 ) );
1623 unsigned char ui_determine_screen_col ( mm_appref_t *a ) {
1624 unsigned int col = 0;
1626 mm_appref_t *i = g_categories [ ui_category ].refs;
1631 col %= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
1636 unsigned char ui_show_info ( char *pndrun, pnd_disco_t *p ) {
1637 char *viewer, *searchpath;
1638 pnd_conf_handle desktoph;
1641 searchpath = pnd_conf_query_searchpath();
1643 desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
1649 viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
1652 return ( 0 ); // no way to view the file
1656 if ( ! p -> unique_id ) {
1660 if ( ! p -> info_filename ) {
1664 if ( ! p -> info_name ) {
1675 if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) {
1676 snprintf ( pargs, 1001, "%s %s",
1677 pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
1682 char pndfile [ 1024 ];
1683 if ( p -> object_type == pnd_object_type_directory ) {
1684 // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
1685 strncpy ( pndfile, p -> object_path, 1000 );
1686 } else if ( p -> object_type == pnd_object_type_pnd ) {
1687 // pnd_run.sh wants the full path and filename for the .pnd file
1688 snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
1691 if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs,
1692 p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) )
1697 pnd_log ( pndn_debug, "Info Exec=%s\n", pnd_apps_exec_runline() );
1701 if ( ( x = fork() ) < 0 ) {
1702 pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
1707 execl ( "/bin/sh", "/bin/sh", "-c", pnd_apps_exec_runline(), (char*)NULL );
1708 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", pnd_apps_exec_runline() );
1720 #define MAXTOUCH 100
1721 ui_touch_t ui_touchrects [ MAXTOUCH ];
1722 unsigned char ui_touchrect_count = 0;
1724 void ui_register_reset ( void ) {
1725 bzero ( ui_touchrects, sizeof(ui_touch_t)*MAXTOUCH );
1726 ui_touchrect_count = 0;
1730 void ui_register_tab ( unsigned char catnum, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
1732 if ( ui_touchrect_count == MAXTOUCH ) {
1736 ui_touchrects [ ui_touchrect_count ].r.x = x;
1737 ui_touchrects [ ui_touchrect_count ].r.y = y;
1738 ui_touchrects [ ui_touchrect_count ].r.w = w;
1739 ui_touchrects [ ui_touchrect_count ].r.h = h;
1740 ui_touchrects [ ui_touchrect_count ].catnum = catnum;
1741 ui_touchrect_count++;
1746 void ui_register_app ( mm_appref_t *app, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
1748 if ( ui_touchrect_count == MAXTOUCH ) {
1752 ui_touchrects [ ui_touchrect_count ].r.x = x;
1753 ui_touchrects [ ui_touchrect_count ].r.y = y;
1754 ui_touchrects [ ui_touchrect_count ].r.w = w;
1755 ui_touchrects [ ui_touchrect_count ].r.h = h;
1756 ui_touchrects [ ui_touchrect_count ].ref = app;
1757 ui_touchrect_count++;
1762 void ui_touch_act ( unsigned int x, unsigned int y ) {
1767 for ( i = 0; i < ui_touchrect_count; i++ ) {
1768 t = &(ui_touchrects [ i ]);
1770 if ( x >= t -> r.x &&
1771 x <= t -> r.x + t -> r.w &&
1773 y <= t -> r.y + t -> r.h
1778 ui_selected = t -> ref;
1781 ui_category = t -> catnum;