10 #include "SDL_gfxPrimitives.h"
11 #include "SDL_rotozoom.h"
14 #include "pnd_logger.h"
16 #include "pnd_container.h"
17 #include "pnd_discovery.h"
19 #include "pnd_device.h"
25 #include "mmwrapcmd.h"
29 SDL_Surface *sdl_realscreen = NULL;
30 unsigned int sdl_ticks = 0;
34 unsigned short int g_scale = 1; // 1 == noscale
36 SDL_Surface *g_imgcache [ IMG_MAX ];
38 TTF_Font *g_big_font = NULL;
39 TTF_Font *g_grid_font = NULL;
40 TTF_Font *g_detailtext_font = NULL;
41 TTF_Font *g_tab_font = NULL;
43 extern pnd_conf_handle g_conf;
45 /* current display state
47 int ui_rows_scrolled_down = 0; // number of rows that should be missing from top of the display
48 mm_appref_t *ui_selected = NULL;
49 unsigned char ui_category = 0; // current category
50 unsigned char ui_catshift = 0; // how many cats are offscreen to the left
52 extern mm_category_t g_categories [ MAX_CATS ];
53 extern unsigned char g_categorycount;
55 static SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ); // height -1 means ignore
56 static int ui_selected_index ( void );
58 unsigned char ui_setup ( void ) {
63 SDL_Init ( SDL_INIT_EVERYTHING | SDL_INIT_NOPARACHUTE );
65 SDL_JoystickOpen ( 0 ); // turn on joy-0
67 SDL_WM_SetCaption ( "mmenu", "mmenu" );
69 // hide the mouse cursor if we can
70 if ( SDL_ShowCursor ( -1 ) == 1 ) {
77 unsigned int svm = SDL_SWSURFACE /*| SDL_FULLSCREEN*/ /* 0*/;
78 if ( pnd_conf_get_as_int_d ( g_conf, "display.fullscreen", 0 ) > 0 ) {
79 svm |= SDL_FULLSCREEN;
83 SDL_SetVideoMode ( 800 * g_scale, 480 * g_scale, 16 /*bpp*/, svm );
85 if ( ! sdl_realscreen ) {
86 pnd_log ( pndn_error, "ERROR: Couldn't open SDL real screen; dieing." );
90 pnd_log ( pndn_debug, "Pixel format:" );
91 pnd_log ( pndn_debug, "bpp b: %u\n", sdl_realscreen -> format -> BitsPerPixel );
92 pnd_log ( pndn_debug, "bpp B: %u\n", sdl_realscreen -> format -> BytesPerPixel );
93 pnd_log ( pndn_debug, "R mask: %08x\n", sdl_realscreen -> format -> Rmask );
94 pnd_log ( pndn_debug, "G mask: %08x\n", sdl_realscreen -> format -> Gmask );
95 pnd_log ( pndn_debug, "B mask: %08x\n", sdl_realscreen -> format -> Bmask );
101 /* Set 16-bit stereo audio at 22Khz */
102 fmt.freq = 44100; //22050;
103 fmt.format = AUDIO_S16; //AUDIO_S16;
105 fmt.samples = 2048; /* A good value for games */
106 fmt.callback = mixaudio;
109 /* Open the audio device and start playing sound! */
110 if ( SDL_OpenAudio ( &fmt, NULL ) < 0 ) {
111 zotlog ( "Unable to open audio: %s\n", SDL_GetError() );
115 SDL_PauseAudio ( 0 );
120 //IMG_Init ( IMG_INIT_JPG | IMG_INIT_PNG );
126 if ( TTF_Init() == -1 ) {
127 pnd_log ( pndn_error, "ERROR: Couldn't set up SDL TTF lib\n" );
128 return ( 0 ); // couldn't set up SDL TTF
131 char fullpath [ PATH_MAX ];
133 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "minimenu.font" ) );
134 g_big_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
135 if ( ! g_big_font ) {
136 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
137 pnd_conf_get_as_char ( g_conf, "minimenu.font" ), pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
138 return ( 0 ); // couldn't set up SDL TTF
142 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, MMENU_GRID_FONT ) );
143 g_grid_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, MMENU_GRID_FONTSIZE, 10 ) );
144 if ( ! g_grid_font ) {
145 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
146 pnd_conf_get_as_char ( g_conf, MMENU_GRID_FONT ), pnd_conf_get_as_int_d ( g_conf, MMENU_GRID_FONTSIZE, 10 ) );
147 return ( 0 ); // couldn't set up SDL TTF
151 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "detailtext.font" ) );
152 g_detailtext_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
153 if ( ! g_detailtext_font ) {
154 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
155 pnd_conf_get_as_char ( g_conf, "detailtext.font" ), pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
156 return ( 0 ); // couldn't set up SDL TTF
160 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "tabs.font" ) );
161 g_tab_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
162 if ( ! g_tab_font ) {
163 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
164 pnd_conf_get_as_char ( g_conf, "tabs.font" ), pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
165 return ( 0 ); // couldn't set up SDL TTF
171 mm_imgcache_t g_imagecache [ IMG_TRUEMAX ] = {
172 { IMG_BACKGROUND_800480, "graphics.IMG_BACKGROUND_800480" },
173 { IMG_BACKGROUND_TABMASK, "graphics.IMG_BACKGROUND_TABMASK" },
174 { IMG_DETAIL_PANEL, "graphics.IMG_DETAIL_PANEL" },
175 { IMG_DETAIL_BG, "graphics.IMG_DETAIL_BG" },
176 { IMG_SELECTED_ALPHAMASK, "graphics.IMG_SELECTED_ALPHAMASK" },
177 { IMG_TAB_SEL, "graphics.IMG_TAB_SEL" },
178 { IMG_TAB_UNSEL, "graphics.IMG_TAB_UNSEL" },
179 { IMG_ICON_MISSING, "graphics.IMG_ICON_MISSING" },
180 { IMG_SELECTED_HILITE, "graphics.IMG_SELECTED_HILITE" },
181 { IMG_PREVIEW_MISSING, "graphics.IMG_PREVIEW_MISSING" },
182 { IMG_ARROW_UP, "graphics.IMG_ARROW_UP", },
183 { IMG_ARROW_DOWN, "graphics.IMG_ARROW_DOWN", },
184 { IMG_ARROW_SCROLLBAR, "graphics.IMG_ARROW_SCROLLBAR", },
188 unsigned char ui_imagecache ( char *basepath ) {
190 char fullpath [ PATH_MAX ];
194 for ( i = 0; i < IMG_MAX; i++ ) {
196 if ( g_imagecache [ i ].id != i ) {
197 pnd_log ( pndn_error, "ERROR: Internal table mismatch during caching [%u]\n", i );
201 char *filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].confname );
204 pnd_log ( pndn_error, "ERROR: Missing filename in conf for key: %s\n", g_imagecache [ i ].confname );
208 sprintf ( fullpath, "%s/%s", basepath, filename );
210 if ( ! ( g_imagecache [ i ].i = IMG_Load ( fullpath ) ) ) {
211 pnd_log ( pndn_error, "ERROR: Couldn't load static cache image: %s\n", fullpath );
218 //g_imagecache [ IMG_SELECTED_ALPHAMASK ].i = SDL_CreateRGBSurface ( SDL_SWSURFACE, 60, 60, 32, 0xFF0000, 0x00FF00, 0xFF, 0xFF000000 );
219 //boxRGBA ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, 0, 0, 60, 60, 100, 100, 100, 250 );
225 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 );
226 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 );
227 // scale text hilight
228 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 );
229 // scale preview no-pic
230 g_imagecache [ IMG_PREVIEW_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_PREVIEW_MISSING ].i,
231 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ),
232 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 50 ) );
234 // set alpha on detail panel
235 SDL_SetAlpha ( g_imagecache [ IMG_DETAIL_BG ].i, SDL_SRCALPHA, pnd_conf_get_as_int_d ( g_conf, "display.detail_bg_alpha", 50 ) );
240 void ui_render ( unsigned int render_mask ) {
243 // divide width: 550 / 250
244 // divide left side: 5 columns == 110px width
245 // 20px buffer either side == 70px wide icon + 20 + 20?
247 unsigned int icon_rows;
250 SDL_Rect rects [ MAXRECTS ], src;
251 SDL_Rect *dest = rects;
252 bzero ( dest, sizeof(SDL_Rect)*MAXRECTS );
254 unsigned int row, displayrow, col;
255 mm_appref_t *appiter;
257 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
259 unsigned char row_max = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_ROWMAX, 4 );
260 unsigned char col_max = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_COLMAX, 5 );
262 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
263 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
264 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
265 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
267 unsigned int grid_offset_x = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_x" );
268 unsigned int grid_offset_y = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_y" );
270 unsigned int icon_offset_x = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_x" );
271 unsigned int icon_offset_y = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_y" );
272 unsigned int icon_max_width = pnd_conf_get_as_int ( g_conf, "grid.icon_max_width" );
274 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
275 unsigned int text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
276 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "grid.text_offset_x" );
277 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_offset_y" );
279 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "grid.cell_width" );
280 unsigned int cell_height = pnd_conf_get_as_int ( g_conf, "grid.cell_height" );
282 // how many total rows do we need?
283 icon_rows = g_categories [ ui_category ].refcount / col_max;
284 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
288 // if no selected app yet, select the first one
290 if ( ! ui_selected ) {
291 ui_selected = g_categories [ ui_category ].refs;
295 // ensure selection is visible
298 int index = ui_selected_index();
299 int topleft = col_max * ui_rows_scrolled_down;
300 int botright = ( col_max * ( ui_rows_scrolled_down + row_max ) - 1 );
302 //pnd_log ( PND_LOG_DEFAULT, "index %u tl %u br %u\n", index, topleft, botright );
304 if ( index < topleft ) {
305 ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
306 } else if ( index > botright ) {
307 ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
310 if ( ui_rows_scrolled_down < 0 ) {
311 ui_rows_scrolled_down = 0;
312 } else if ( ui_rows_scrolled_down > icon_rows ) {
313 ui_rows_scrolled_down = icon_rows;
319 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
322 dest -> w = sdl_realscreen -> w;
323 dest -> h = sdl_realscreen -> h;
324 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
325 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
330 if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
333 dest -> w = sdl_realscreen -> w;
334 dest -> h = sdl_realscreen -> h;
335 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
336 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
341 if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
342 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
343 unsigned int tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
344 unsigned int tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
345 unsigned int tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
346 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
347 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
348 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
350 for ( col = ui_catshift;
352 ( screen_width / tab_width ) < g_categorycount ? ( screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift
358 if ( col == ui_category ) {
359 s = g_imagecache [ IMG_TAB_SEL ].i;
361 s = g_imagecache [ IMG_TAB_UNSEL ].i;
369 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
370 dest -> y = tab_offset_y;
371 //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
372 SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
373 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
378 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
379 rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ].catname, tmpfontcolor );
382 src.w = rtext -> w < text_width ? rtext -> w : text_width;
384 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
385 dest -> y = tab_offset_y + text_offset_y;
386 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
387 SDL_FreeSurface ( rtext );
394 // scroll bars and arrows
396 unsigned char show_bar = 0;
399 if ( ui_rows_scrolled_down && g_imagecache [ IMG_ARROW_UP ].i ) {
400 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
401 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
402 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
403 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
410 if ( ui_rows_scrolled_down + row_max < icon_rows && g_imagecache [ IMG_ARROW_DOWN ].i ) {
411 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
412 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
413 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
414 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
421 // show scrollbar as well
424 src.w = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_w", 10 );
425 src.h = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_h", 100 );
426 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
427 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
428 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
429 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
435 // render detail pane bg
436 if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
438 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
439 src.x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
440 src.y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
441 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
442 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
443 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
444 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
445 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
446 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
450 // render detail pane
451 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
452 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
453 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
454 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
455 //SDL_UpdateRects ( sdl_realscreen, 1, &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 );
482 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
485 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
486 dest -> y = grid_offset_y + ( displayrow * cell_height ) + pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
487 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
488 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
493 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
494 SDL_Surface *iconsurface;
496 iconsurface = ic -> i;
498 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
499 iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
502 //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
508 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + (( icon_max_width - iconsurface -> w ) / 2);
509 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y;
511 SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
512 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
518 if ( appiter -> ref -> title_en ) {
520 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
521 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, tmpfontcolor );
524 src.w = text_width < rtext -> w ? text_width : rtext -> w;
526 if ( rtext -> w > text_width ) {
527 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
529 dest -> x = grid_offset_x + ( col * cell_width ) + text_offset_x - ( rtext -> w / 2 );
531 dest -> y = grid_offset_y + ( displayrow * cell_height ) + text_offset_y;
532 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
533 SDL_FreeSurface ( rtext );
537 } // display now? or scrolled away..
540 appiter = appiter -> next;
542 } // for column 1...X
544 if ( row >= ui_rows_scrolled_down ) {
550 // are we done displaying rows?
551 if ( displayrow >= row_max ) {
558 // no apps to render?
559 pnd_log ( pndn_rem, "No applications to render?\n" );
565 unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
566 unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
567 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "detailtext.cell_width" );
569 unsigned int desty = cell_offset_y;
574 if ( ui_selected -> ref -> title_en ) {
576 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
577 rtext = TTF_RenderText_Blended ( g_detailtext_font, ui_selected -> ref -> title_en, tmpfontcolor );
580 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
582 dest -> x = cell_offset_x;
584 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
585 SDL_FreeSurface ( rtext );
591 if ( ui_selected -> ref -> main_category ) {
593 sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
596 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
597 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
600 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
602 dest -> x = cell_offset_x;
604 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
605 SDL_FreeSurface ( rtext );
611 if ( ui_selected -> ref -> clockspeed ) {
613 sprintf ( buffer, "CPU Clock: %s", ui_selected -> ref -> clockspeed );
616 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
617 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
620 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
622 dest -> x = cell_offset_x;
624 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
625 SDL_FreeSurface ( rtext );
631 mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
632 SDL_Surface *previewpic;
635 previewpic = ic -> i;
637 previewpic = g_imagecache [ IMG_PREVIEW_MISSING ].i;
641 dest -> x = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_x", 50 ) +
642 ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
643 dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
644 SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
645 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
656 unsigned char batterylevel = pnd_device_get_battery_gauge_perc();
659 sprintf ( buffer, "Battery: %u%%", batterylevel );
662 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
663 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
664 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.battery_x", 20 );
665 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.battery_y", 450 );
666 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
667 SDL_FreeSurface ( rtext );
672 if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
673 char *buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
675 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
676 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
677 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
678 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
679 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
680 SDL_FreeSurface ( rtext );
685 if ( pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 ) {
688 time_t t = time ( NULL );
689 struct tm *tm = localtime ( &t );
690 strftime ( buffer, 50, "%a %H:%M %F", tm );
693 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
694 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
695 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.clock_x", 700 );
696 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.clock_y", 450 );
697 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
698 SDL_FreeSurface ( rtext );
702 // update all the rects and send it all to sdl
703 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
707 void ui_process_input ( unsigned char block_p ) {
710 unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
711 static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
713 while ( ! ui_event &&
714 block_p ? SDL_WaitEvent ( &event ) : SDL_PollEvent ( &event ) )
717 switch ( event.type ) {
722 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
724 pnd_log ( pndn_debug, "Deferred preview pic load ----------\n" );
726 // load the preview pics now!
727 pnd_disco_t *iter = ui_selected -> ref;
729 if ( iter -> preview_pic1 &&
730 ! 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 ) ) )
732 pnd_log ( pndn_debug, " Couldn't load preview pic: '%s' -> '%s'\n", IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
735 pnd_log ( pndn_debug, "Deferred preview pic load finish ---\n" );
742 #if 0 // joystick motion
743 case SDL_JOYAXISMOTION:
745 pnd_log ( PND_LOG_DEFAULT, "joystick axis\n" );
747 if ( event.jaxis.axis == 0 ) {
749 if ( event.jaxis.value < 0 ) {
751 pnd_log ( PND_LOG_DEFAULT, "joystick axis - LEFT\n" );
752 } else if ( event.jaxis.value > 0 ) {
754 pnd_log ( PND_LOG_DEFAULT, "joystick axis - RIGHT\n" );
756 } else if ( event.jaxis.axis == 1 ) {
758 if ( event.jaxis.value < 0 ) {
760 } else if ( event.jaxis.value > 0 ) {
770 #if 0 // joystick buttons
771 case SDL_JOYBUTTONDOWN:
773 pnd_log ( PND_LOG_DEFAULT, "joystick button down %u\n", event.jbutton.button );
775 if ( event.jbutton.button == 0 ) { // B
777 } else if ( event.jbutton.button == 1 ) { // Y
779 } else if ( event.jbutton.button == 2 ) { // X
781 } else if ( event.jbutton.button == 3 ) { // A
784 } else if ( event.jbutton.button == 4 ) { // Select
785 ui_mask |= uisb_select;
786 } else if ( event.jbutton.button == 5 ) { // Start
787 ui_mask |= uisb_start;
789 } else if ( event.jbutton.button == 7 ) { // L
791 } else if ( event.jbutton.button == 8 ) { // R
800 case SDL_JOYBUTTONUP:
802 pnd_log ( PND_LOG_DEFAULT, "joystick button up %u\n", event.jbutton.button );
804 if ( event.jbutton.button == 0 ) { // B
807 } else if ( event.jbutton.button == 1 ) { // Y
809 } else if ( event.jbutton.button == 2 ) { // X
811 } else if ( event.jbutton.button == 3 ) { // A
814 } else if ( event.jbutton.button == 4 ) { // Select
815 ui_mask &= ~uisb_select;
816 } else if ( event.jbutton.button == 5 ) { // Start
817 ui_mask &= ~uisb_start;
819 } else if ( event.jbutton.button == 7 ) { // L
822 } else if ( event.jbutton.button == 8 ) { // R
833 #if 1 // keyboard events
836 //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
838 // SDLK_LALT -> Start
841 if ( event.key.keysym.sym == SDLK_RIGHT ) {
844 } else if ( event.key.keysym.sym == SDLK_LEFT ) {
847 } else if ( event.key.keysym.sym == SDLK_UP ) {
850 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
853 } else if ( event.key.keysym.sym == SDLK_SPACE || event.key.keysym.sym == SDLK_END ) {
856 } else if ( event.key.keysym.sym == SDLK_z || event.key.keysym.sym == SDLK_RSHIFT ) {
859 } else if ( event.key.keysym.sym == SDLK_x || event.key.keysym.sym == SDLK_RCTRL ) {
863 } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
864 char *opts [ 20 ] = {
865 "Return to Minimenu",
867 "Rescan for Applications",
868 "Run xfce4 from Minimenu",
869 "Set to full desktop and reboot",
870 "Set to pmenu and reboot",
874 int sel = ui_modal_single_menu ( opts, 8, "Minimenu", "Enter to select; other to return." );
879 } else if ( sel == 1 ) {
881 sprintf ( buffer, "sudo poweroff" );
883 } else if ( sel == 2 ) {
885 } else if ( sel == 3 ) {
887 char buffer [ PATH_MAX ];
888 sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/bin/startxfce4" );
889 emit_and_quit ( buffer );
890 } else if ( sel == 4 ) {
892 sprintf ( buffer, "echo startxfce4 > /tmp/gui.load" );
894 sprintf ( buffer, "sudo poweroff" );
896 } else if ( sel == 5 ) {
898 sprintf ( buffer, "echo pmenu > /tmp/gui.load" );
900 sprintf ( buffer, "sudo poweroff" );
902 } else if ( sel == 6 ) {
903 emit_and_quit ( MM_QUIT );
904 } else if ( sel == 7 ) {
912 if ( event.key.keysym.sym == SDLK_q ) {
913 emit_and_quit ( MM_QUIT );
919 #if 0 // mouse / touchscreen
920 case SDL_MOUSEBUTTONDOWN:
921 if ( event.button.button == SDL_BUTTON_LEFT ) {
922 cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
927 case SDL_MOUSEBUTTONUP:
928 if ( event.button.button == SDL_BUTTON_LEFT ) {
929 cb_pointer_release ( gc, event.button.x / g_scale, event.button.y / g_scale );
943 } // switch event type
950 void ui_push_left ( unsigned char forcecoil ) {
952 if ( ! ui_selected ) {
957 // what column we in?
958 unsigned int col = ui_determine_screen_col ( ui_selected );
960 // are we alreadt at first item?
961 if ( forcecoil == 0 &&
962 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
965 unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
971 } else if ( g_categories [ ui_category ].refs == ui_selected ) {
972 // can't go any more left, we're at the head
975 // figure out the previous item; yay for singly linked list :/
976 mm_appref_t *i = g_categories [ ui_category ].refs;
978 if ( i -> next == ui_selected ) {
986 ui_set_selected ( ui_selected );
991 void ui_push_right ( unsigned char forcecoil ) {
995 // what column we in?
996 unsigned int col = ui_determine_screen_col ( ui_selected );
999 if ( forcecoil == 0 &&
1000 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1001 col == pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1 )
1004 unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1011 // just go to the next
1013 if ( ui_selected -> next ) {
1014 ui_selected = ui_selected -> next;
1020 ui_selected = g_categories [ ui_category ].refs;
1023 ui_set_selected ( ui_selected );
1028 void ui_push_up ( void ) {
1029 unsigned char col_max = pnd_conf_get_as_int ( g_conf, MMENU_DISP_COLMAX );
1032 unsigned int row = ui_determine_row ( ui_selected );
1035 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 1 ) == 0 )
1037 // wrap around instead
1039 unsigned int col = ui_determine_screen_col ( ui_selected );
1042 ui_selected = g_categories [ ui_category ].refs;
1043 while ( ui_selected -> next ) {
1044 ui_selected = ui_selected -> next;
1047 // try to move to same column
1048 unsigned int newcol = ui_determine_screen_col ( ui_selected );
1049 if ( newcol > col ) {
1057 // scroll down to show it
1058 int r = ui_determine_row ( ui_selected ) - 1;
1059 if ( r - pnd_conf_get_as_int ( g_conf, MMENU_DISP_ROWMAX ) > 0 ) {
1060 ui_rows_scrolled_down = (unsigned int) r;
1064 // stop at top/bottom
1076 void ui_push_down ( void ) {
1077 unsigned char col_max = pnd_conf_get_as_int ( g_conf, MMENU_DISP_COLMAX );
1079 if ( ui_selected ) {
1082 unsigned int row = ui_determine_row ( ui_selected );
1085 unsigned int icon_rows = g_categories [ ui_category ].refcount / col_max;
1086 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
1091 if ( row == ( icon_rows - 1 ) &&
1092 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 1 ) == 0 )
1095 unsigned char col = ui_determine_screen_col ( ui_selected );
1097 ui_selected = g_categories [ ui_category ].refs;
1100 ui_selected = ui_selected -> next;
1104 ui_rows_scrolled_down = 0;
1109 ui_push_right ( 1 );
1116 ui_push_right ( 0 );
1122 void ui_push_exec ( void ) {
1124 if ( ui_selected ) {
1125 char buffer [ PATH_MAX ];
1126 sprintf ( buffer, "%s/%s", ui_selected -> ref -> object_path, ui_selected -> ref -> object_filename );
1127 pnd_apps_exec ( pnd_run_script,
1129 ui_selected -> ref -> unique_id,
1130 ui_selected -> ref -> exec,
1131 ui_selected -> ref -> startdir,
1132 ui_selected -> ref -> execargs,
1133 atoi ( ui_selected -> ref -> clockspeed ),
1134 PND_EXEC_OPTION_NORUN );
1135 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1136 emit_and_quit ( buffer );
1142 void ui_push_ltrigger ( void ) {
1143 unsigned char oldcat = ui_category;
1145 if ( ui_category > 0 ) {
1148 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1149 ui_category = g_categorycount - 1;
1153 if ( oldcat != ui_category ) {
1155 ui_set_selected ( ui_selected );
1158 // make tab visible?
1159 if ( ui_catshift > 0 && ui_category == ui_catshift - 1 ) {
1164 ui_rows_scrolled_down = 0;
1169 void ui_push_rtrigger ( void ) {
1170 unsigned char oldcat = ui_category;
1172 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
1173 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1175 if ( ui_category < ( g_categorycount - 1 ) ) {
1178 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1183 if ( oldcat != ui_category ) {
1185 ui_set_selected ( ui_selected );
1188 // make tab visible?
1189 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
1194 ui_rows_scrolled_down = 0;
1199 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ) {
1200 double scale = 1000000.0;
1201 double scalex = 1000000.0;
1202 double scaley = 1000000.0;
1203 SDL_Surface *scaled;
1205 scalex = (double)maxwidth / (double)s -> w;
1207 if ( maxheight == -1 ) {
1210 scaley = (double)maxheight / (double)s -> h;
1212 if ( scaley < scalex ) {
1220 scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
1221 SDL_FreeSurface ( s );
1227 void ui_loadscreen ( void ) {
1231 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1232 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1233 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1234 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1237 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1241 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1242 rtext = TTF_RenderText_Blended ( g_big_font, "Setting up menu...", tmpfontcolor );
1245 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1246 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1247 SDL_FreeSurface ( rtext );
1252 void ui_discoverscreen ( unsigned char clearscreen ) {
1256 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1257 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1258 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1259 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1262 if ( clearscreen ) {
1263 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1265 // render background
1266 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1269 dest.w = sdl_realscreen -> w;
1270 dest.h = sdl_realscreen -> h;
1271 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1272 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1279 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1280 rtext = TTF_RenderText_Blended ( g_big_font, "Looking for applications...", tmpfontcolor );
1281 if ( clearscreen ) {
1288 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1289 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1290 SDL_FreeSurface ( rtext );
1293 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1294 dest.x = rtext -> w + 30;
1296 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, &dest );
1297 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1303 void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
1305 SDL_Rect rects [ 4 ];
1306 SDL_Rect *dest = rects;
1307 bzero ( dest, sizeof(SDL_Rect)* 4 );
1309 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1310 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1311 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1312 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1314 static unsigned int stepx = 0;
1317 if ( clearscreen ) {
1318 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1320 // render background
1321 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1324 dest -> w = sdl_realscreen -> w;
1325 dest -> h = sdl_realscreen -> h;
1326 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1334 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1335 rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
1336 if ( clearscreen ) {
1343 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1344 SDL_FreeSurface ( rtext );
1348 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1349 dest -> x = rtext -> w + 30 + stepx;
1351 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, dest );
1357 rtext = TTF_RenderText_Blended ( g_tab_font, filename, tmpfontcolor );
1360 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1361 SDL_FreeSurface ( rtext );
1368 if ( stepx > 350 ) {
1372 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1377 int ui_selected_index ( void ) {
1379 if ( ! ui_selected ) {
1380 return ( -1 ); // no index
1383 mm_appref_t *r = g_categories [ ui_category ].refs;
1386 if ( r == ui_selected ) {
1396 static mm_appref_t *timer_ref = NULL;
1397 void ui_set_selected ( mm_appref_t *r ) {
1399 if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1400 return; // no desire to defer anything
1405 SDL_SetTimer ( 0, NULL );
1410 SDL_SetTimer ( pnd_conf_get_as_int_d ( g_conf, "previewpic.defer_timer_ms", 1000 ), ui_callback_f );
1416 unsigned int ui_callback_f ( unsigned int t ) {
1418 if ( ui_selected != timer_ref ) {
1419 return ( 0 ); // user has moved it, who cares
1423 e.type = SDL_USEREVENT;
1424 SDL_PushEvent ( &e );
1429 int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer ) {
1430 SDL_Rect rects [ 40 ];
1431 SDL_Rect *dest = rects;
1435 bzero ( rects, sizeof(SDL_Rect) * 40 );
1437 unsigned int sel = 0;
1439 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1440 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1441 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1442 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1444 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1446 SDL_Color selfontcolor = { 0/*font_rgba_r*/, font_rgba_g, font_rgba_b, font_rgba_a };
1454 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1455 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1456 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
1457 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
1458 SDL_FillRect( sdl_realscreen, dest, 0 );
1460 // show dialog background
1461 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
1462 src.x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1463 src.y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1464 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
1465 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
1466 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1467 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1468 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1469 // repeat for darken?
1470 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1471 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1472 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1476 // show dialog frame
1477 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
1478 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1479 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1480 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
1481 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1487 rtext = TTF_RenderText_Blended ( g_tab_font, title, tmpfontcolor );
1488 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1489 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
1490 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1491 SDL_FreeSurface ( rtext );
1497 rtext = TTF_RenderText_Blended ( g_tab_font, footer, tmpfontcolor );
1498 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1499 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
1500 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
1502 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1503 SDL_FreeSurface ( rtext );
1508 for ( i = 0; i < argc; i++ ) {
1512 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
1514 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], tmpfontcolor );
1516 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1517 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 ) );
1518 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1519 SDL_FreeSurface ( rtext );
1524 // update all the rects and send it all to sdl
1525 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1529 while ( SDL_WaitEvent ( &event ) ) {
1531 switch ( event.type ) {
1535 if ( event.key.keysym.sym == SDLK_UP ) {
1539 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1540 if ( sel < argc - 1 ) {
1544 } else if ( event.key.keysym.sym == SDLK_RETURN ) {
1547 } else if ( event.key.keysym.sym == SDLK_q ) {
1551 return ( -1 ); // nada
1566 unsigned char ui_determine_row ( mm_appref_t *a ) {
1567 unsigned int row = 0;
1569 mm_appref_t *i = g_categories [ ui_category ].refs;
1574 row /= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
1579 unsigned char ui_determine_screen_row ( mm_appref_t *a ) {
1580 return ( ui_determine_row ( a ) % pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 5 ) );
1583 unsigned char ui_determine_screen_col ( mm_appref_t *a ) {
1584 unsigned int col = 0;
1586 mm_appref_t *i = g_categories [ ui_category ].refs;
1591 col %= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );