2 #include <stdio.h> /* for FILE etc */
3 #include <stdlib.h> /* for malloc */
4 #include <unistd.h> /* for unlink */
5 #include <limits.h> /* for PATH_MAX */
8 #define __USE_GNU /* for strcasestr */
9 #include <string.h> /* for making ftw.h happy */
13 #include "SDL_audio.h"
14 #include "SDL_image.h"
16 #include "SDL_gfxPrimitives.h"
17 #include "SDL_rotozoom.h"
18 #include "SDL_thread.h"
22 #include "pnd_logger.h"
24 #include "pnd_container.h"
25 #include "pnd_discovery.h"
27 #include "pnd_device.h"
28 #include "../lib/pnd_pathiter.h"
29 #include "pnd_utility.h"
30 #include "pnd_pndfiles.h"
36 #include "mmwrapcmd.h"
38 #include "mmui_context.h"
40 #define CHANGED_NOTHING (0)
41 #define CHANGED_CATEGORY (1<<0) /* changed to different category */
42 #define CHANGED_SELECTION (1<<1) /* changed app selection */
43 #define CHANGED_DATAUPDATE (1<<2) /* deferred preview pic or icon came in */
44 #define CHANGED_APPRELOAD (1<<3) /* new set of applications entirely */
45 #define CHANGED_EVERYTHING (1<<4) /* redraw it all! */
46 unsigned int render_mask = CHANGED_EVERYTHING;
50 SDL_Surface *sdl_realscreen = NULL;
51 unsigned int sdl_ticks = 0;
52 SDL_Thread *g_preview_thread = NULL;
54 enum { sdl_user_ticker = 0,
55 sdl_user_finishedpreview = 1,
56 sdl_user_finishedicon = 2,
61 unsigned short int g_scale = 1; // 1 == noscale
63 SDL_Surface *g_imgcache [ IMG_MAX ];
65 TTF_Font *g_big_font = NULL;
66 TTF_Font *g_grid_font = NULL;
67 TTF_Font *g_detailtext_font = NULL;
68 TTF_Font *g_tab_font = NULL;
70 extern pnd_conf_handle g_conf;
72 /* current display state
74 int ui_rows_scrolled_down = 0; // number of rows that should be missing from top of the display
75 mm_appref_t *ui_selected = NULL;
76 unsigned char ui_category = 0; // current category
77 unsigned char ui_catshift = 0; // how many cats are offscreen to the left
78 ui_context_t ui_display_context; // display paramaters: see mmui_context.h
79 unsigned char ui_detail_hidden = 0; // if >0, detail panel is hidden
80 // FUTURE: If multiple panels can be shown/hidden, convert ui_detail_hidden to a bitmask
82 extern mm_category_t *g_categories;
83 extern unsigned char g_categorycount;
84 extern mm_category_t _categories_invis [ MAX_CATS ];
85 extern unsigned char _categories_inviscount;
87 static SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ); // height -1 means ignore
88 static int ui_selected_index ( void );
90 unsigned char ui_setup ( void ) {
95 SDL_Init ( SDL_INIT_EVERYTHING | SDL_INIT_NOPARACHUTE );
97 SDL_JoystickOpen ( 0 ); // turn on joy-0
99 SDL_WM_SetCaption ( "mmenu", "mmenu" );
101 // hide the mouse cursor if we can
102 if ( SDL_ShowCursor ( -1 ) == 1 ) {
103 SDL_ShowCursor ( 0 );
109 unsigned int svm = SDL_SWSURFACE /*| SDL_FULLSCREEN*/ /* 0*/;
110 if ( pnd_conf_get_as_int_d ( g_conf, "display.fullscreen", 0 ) > 0 ) {
111 svm |= SDL_FULLSCREEN;
115 SDL_SetVideoMode ( 800 * g_scale, 480 * g_scale, 16 /*bpp*/, svm );
117 if ( ! sdl_realscreen ) {
118 pnd_log ( pndn_error, "ERROR: Couldn't open SDL real screen; dieing." );
122 pnd_log ( pndn_debug, "Pixel format:" );
123 pnd_log ( pndn_debug, "bpp b: %u\n", sdl_realscreen -> format -> BitsPerPixel );
124 pnd_log ( pndn_debug, "bpp B: %u\n", sdl_realscreen -> format -> BytesPerPixel );
125 pnd_log ( pndn_debug, "R mask: %08x\n", sdl_realscreen -> format -> Rmask );
126 pnd_log ( pndn_debug, "G mask: %08x\n", sdl_realscreen -> format -> Gmask );
127 pnd_log ( pndn_debug, "B mask: %08x\n", sdl_realscreen -> format -> Bmask );
133 /* Set 16-bit stereo audio at 22Khz */
134 fmt.freq = 44100; //22050;
135 fmt.format = AUDIO_S16; //AUDIO_S16;
137 fmt.samples = 2048; /* A good value for games */
138 fmt.callback = mixaudio;
141 /* Open the audio device and start playing sound! */
142 if ( SDL_OpenAudio ( &fmt, NULL ) < 0 ) {
143 zotlog ( "Unable to open audio: %s\n", SDL_GetError() );
147 SDL_PauseAudio ( 0 );
152 SDL_EnableKeyRepeat ( 500, 150 );
155 //IMG_Init ( IMG_INIT_JPG | IMG_INIT_PNG );
161 if ( TTF_Init() == -1 ) {
162 pnd_log ( pndn_error, "ERROR: Couldn't set up SDL TTF lib\n" );
163 return ( 0 ); // couldn't set up SDL TTF
166 char fullpath [ PATH_MAX ];
168 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "minimenu.font" ) );
169 g_big_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
170 if ( ! g_big_font ) {
171 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
172 pnd_conf_get_as_char ( g_conf, "minimenu.font" ), pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
173 return ( 0 ); // couldn't set up SDL TTF
177 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "grid.font" ) );
178 g_grid_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
179 if ( ! g_grid_font ) {
180 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
181 pnd_conf_get_as_char ( g_conf, "grid.font" ), pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
182 return ( 0 ); // couldn't set up SDL TTF
186 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "detailtext.font" ) );
187 g_detailtext_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
188 if ( ! g_detailtext_font ) {
189 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
190 pnd_conf_get_as_char ( g_conf, "detailtext.font" ), pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
191 return ( 0 ); // couldn't set up SDL TTF
195 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "tabs.font" ) );
196 g_tab_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
197 if ( ! g_tab_font ) {
198 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
199 pnd_conf_get_as_char ( g_conf, "tabs.font" ), pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
200 return ( 0 ); // couldn't set up SDL TTF
203 // determine display context
204 if ( pnd_conf_get_as_int_d ( g_conf, "display.show_detail_pane", 1 ) > 0 ) {
205 ui_detail_hidden = 0;
207 ui_detail_hidden = 1;
209 ui_recache_context ( &ui_display_context );
214 mm_imgcache_t g_imagecache [ IMG_TRUEMAX ] = {
215 { IMG_BACKGROUND_800480, "graphics.IMG_BACKGROUND_800480" },
216 { IMG_BACKGROUND_TABMASK, "graphics.IMG_BACKGROUND_TABMASK" },
217 { IMG_DETAIL_PANEL, "graphics.IMG_DETAIL_PANEL" },
218 { IMG_DETAIL_BG, "graphics.IMG_DETAIL_BG" },
219 { IMG_SELECTED_ALPHAMASK, "graphics.IMG_SELECTED_ALPHAMASK" },
220 { IMG_TAB_SEL, "graphics.IMG_TAB_SEL" },
221 { IMG_TAB_SEL_L, "graphics.IMG_TAB_SEL_L" },
222 { IMG_TAB_SEL_R, "graphics.IMG_TAB_SEL_R" },
223 { IMG_TAB_UNSEL, "graphics.IMG_TAB_UNSEL" },
224 { IMG_TAB_UNSEL_L, "graphics.IMG_TAB_UNSEL_L" },
225 { IMG_TAB_UNSEL_R, "graphics.IMG_TAB_UNSEL_R" },
226 { IMG_TAB_LINE, "graphics.IMG_TAB_LINE" },
227 { IMG_TAB_LINEL, "graphics.IMG_TAB_LINEL" },
228 { IMG_TAB_LINER, "graphics.IMG_TAB_LINER" },
229 { IMG_ICON_MISSING, "graphics.IMG_ICON_MISSING" },
230 { IMG_SELECTED_HILITE, "graphics.IMG_SELECTED_HILITE" },
231 { IMG_PREVIEW_MISSING, "graphics.IMG_PREVIEW_MISSING" },
232 { IMG_ARROW_UP, "graphics.IMG_ARROW_UP", },
233 { IMG_ARROW_DOWN, "graphics.IMG_ARROW_DOWN", },
234 { IMG_ARROW_SCROLLBAR, "graphics.IMG_ARROW_SCROLLBAR", },
235 { IMG_HOURGLASS, "graphics.IMG_HOURGLASS", },
236 { IMG_FOLDER, "graphics.IMG_FOLDER", },
237 { IMG_EXECBIN, "graphics.IMG_EXECBIN", },
241 unsigned char ui_imagecache ( char *basepath ) {
243 char fullpath [ PATH_MAX ];
247 for ( i = 0; i < IMG_MAX; i++ ) {
249 if ( g_imagecache [ i ].id != i ) {
250 pnd_log ( pndn_error, "ERROR: Internal table mismatch during caching [%u]\n", i );
254 char *filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].confname );
257 pnd_log ( pndn_error, "ERROR: Missing filename in conf for key: %s\n", g_imagecache [ i ].confname );
261 if ( filename [ 0 ] == '/' ) {
262 strncpy ( fullpath, filename, PATH_MAX );
264 sprintf ( fullpath, "%s/%s", basepath, filename );
267 if ( ! ( g_imagecache [ i ].i = IMG_Load ( fullpath ) ) ) {
268 pnd_log ( pndn_error, "ERROR: Couldn't load static cache image: %s\n", fullpath );
275 //g_imagecache [ IMG_SELECTED_ALPHAMASK ].i = SDL_CreateRGBSurface ( SDL_SWSURFACE, 60, 60, 32, 0xFF0000, 0x00FF00, 0xFF, 0xFF000000 );
276 //boxRGBA ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, 0, 0, 60, 60, 100, 100, 100, 250 );
282 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 );
283 // scale text hilight
284 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 );
285 // scale preview no-pic
286 g_imagecache [ IMG_PREVIEW_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_PREVIEW_MISSING ].i,
287 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ),
288 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 50 ) );
290 // set alpha on detail panel
291 //SDL_SetAlpha ( g_imagecache [ IMG_DETAIL_BG ].i, SDL_SRCALPHA, pnd_conf_get_as_int_d ( g_conf, "display.detail_bg_alpha", 50 ) );
296 void ui_render ( void ) {
299 // divide width: 550 / 250
300 // divide left side: 5 columns == 110px width
301 // 20px buffer either side == 70px wide icon + 20 + 20?
303 // what jobs to do during render?
307 #define R_TABS (1<<1)
308 #define R_DETAIL (1<<2)
309 #define R_GRID (1<<3)
311 #define R_ALL (R_BG|R_TABS|R_DETAIL|R_GRID)
313 unsigned int render_jobs_b = 0;
315 if ( render_mask & CHANGED_EVERYTHING ) {
316 render_jobs_b |= R_ALL;
319 if ( render_mask & CHANGED_SELECTION ) {
320 render_jobs_b |= R_GRID;
321 render_jobs_b |= R_DETAIL;
324 if ( render_mask & CHANGED_CATEGORY ) {
325 render_jobs_b |= R_ALL;
328 render_mask = CHANGED_NOTHING;
332 unsigned int icon_rows;
335 SDL_Rect rects [ MAXRECTS ], src;
336 SDL_Rect *dest = rects;
337 bzero ( dest, sizeof(SDL_Rect)*MAXRECTS );
339 unsigned int row, displayrow, col;
340 mm_appref_t *appiter;
342 ui_context_t *c = &ui_display_context; // for convenience and shorthand
344 // how many total rows do we need?
345 icon_rows = g_categories [ ui_category ].refcount / c -> col_max;
346 if ( g_categories [ ui_category ].refcount % c -> col_max > 0 ) {
351 // if no selected app yet, select the first one
352 if ( ! ui_selected && pnd_conf_get_as_int_d ( g_conf, "minimenu.start_selected", 0 ) ) {
353 ui_selected = g_categories [ ui_category ].refs;
357 // reset touchscreen regions
358 if ( render_jobs_b ) {
362 // ensure selection is visible
365 int index = ui_selected_index();
366 int topleft = c -> col_max * ui_rows_scrolled_down;
367 int botright = ( c -> col_max * ( ui_rows_scrolled_down + c -> row_max ) - 1 );
369 if ( index < topleft ) {
370 ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
371 render_jobs_b |= R_ALL;
372 } else if ( index > botright ) {
373 ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
374 render_jobs_b |= R_ALL;
377 if ( ui_rows_scrolled_down < 0 ) {
378 ui_rows_scrolled_down = 0;
379 } else if ( ui_rows_scrolled_down > icon_rows ) {
380 ui_rows_scrolled_down = icon_rows;
386 if ( render_jobs_b & R_BG ) {
388 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
391 dest -> w = sdl_realscreen -> w;
392 dest -> h = sdl_realscreen -> h;
393 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
398 if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
401 dest -> w = sdl_realscreen -> w;
402 dest -> h = sdl_realscreen -> h;
403 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
410 if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
411 static unsigned int tab_width;
412 static unsigned int tab_height;
413 static unsigned int tab_offset_x;
414 static unsigned int tab_offset_y;
415 static unsigned int text_offset_x;
416 static unsigned int text_offset_y;
417 static unsigned int text_width;
419 static unsigned char tab_first_run = 1;
420 if ( tab_first_run ) {
422 tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
423 tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
424 tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
425 tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
426 text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
427 text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
428 text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
431 unsigned int maxtab = ( c -> screen_width / tab_width ) < g_categorycount ? ( c -> screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift;
432 unsigned int maxtabspot = ( c -> screen_width / tab_width );
434 if ( g_categorycount > 0 ) {
436 // draw tabs with categories
437 for ( col = ui_catshift;
444 // if this is the first (leftmost) tab, we use different artwork
445 // than if the other tabs (so skinner can link lines up nicely.)
446 if ( col == ui_catshift ) {
447 // leftmost tab, special case
449 if ( col == ui_category ) {
450 s = g_imagecache [ IMG_TAB_SEL_L ].i;
452 s = g_imagecache [ IMG_TAB_UNSEL_L ].i;
455 } else if ( col == maxtab - 1 ) {
456 // rightmost tab, special case
458 if ( col == ui_category ) {
459 s = g_imagecache [ IMG_TAB_SEL_R ].i;
461 s = g_imagecache [ IMG_TAB_UNSEL_R ].i;
465 // normal (not leftmost) tab
467 if ( col == ui_category ) {
468 s = g_imagecache [ IMG_TAB_SEL ].i;
470 s = g_imagecache [ IMG_TAB_UNSEL ].i;
473 } // first col, or not first col?
480 if ( col == ui_category ) {
481 src.h = tab_selheight;
489 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
490 dest -> y = tab_offset_y;
493 ui_register_tab ( col, dest -> x, dest -> y, tab_width, tab_height );
495 if ( render_jobs_b & R_TABS ) {
496 //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
497 SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
501 if ( col == ui_category ) {
502 // no line for selected tab
504 if ( col - ui_catshift == 0 ) {
505 s = g_imagecache [ IMG_TAB_LINEL ].i;
506 } else if ( col - ui_catshift == maxtabspot - 1 ) {
507 s = g_imagecache [ IMG_TAB_LINER ].i;
509 s = g_imagecache [ IMG_TAB_LINE ].i;
511 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
512 dest -> y = tab_offset_y + tab_height;
513 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
519 rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ].catname, c -> fontcolor );
522 src.w = rtext -> w < text_width ? rtext -> w : text_width;
524 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
525 dest -> y = tab_offset_y + text_offset_y;
526 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
527 SDL_FreeSurface ( rtext );
534 } // if we got categories
536 if ( render_jobs_b & R_TABS ) {
538 // draw tab lines under where tabs would be if we had categories
539 for ( /* foo */; col < maxtabspot; col++ ) {
542 if ( col - ui_catshift == 0 ) {
543 s = g_imagecache [ IMG_TAB_LINEL ].i;
544 } else if ( col - ui_catshift == maxtabspot - 1 ) {
545 s = g_imagecache [ IMG_TAB_LINER ].i;
547 s = g_imagecache [ IMG_TAB_LINE ].i;
549 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
550 dest -> y = tab_offset_y + tab_height;
551 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
560 // scroll bars and arrows
561 if ( render_jobs_b & R_BG ) {
562 unsigned char show_bar = 0;
565 if ( ui_rows_scrolled_down && g_imagecache [ IMG_ARROW_UP ].i ) {
566 dest -> x = c -> arrow_up_x;
567 dest -> y = c -> arrow_up_y;
568 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
575 if ( ui_rows_scrolled_down + c -> row_max < icon_rows && g_imagecache [ IMG_ARROW_DOWN ].i ) {
576 dest -> x = c -> arrow_down_x;
577 dest -> y = c -> arrow_down_y;
578 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
585 // show scrollbar as well
588 src.w = c -> arrow_bar_clip_w;
589 src.h = c -> arrow_bar_clip_h;
590 dest -> x = c -> arrow_bar_x;
591 dest -> y = c -> arrow_bar_y;
592 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
596 } // r_bg, scroll bars
598 // render detail pane bg
599 if ( render_jobs_b & R_DETAIL && ui_detail_hidden == 0 ) {
601 if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
604 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
605 src.x = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
606 src.y = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
607 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
608 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
609 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
610 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
611 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
615 // render detail pane
616 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
617 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
618 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
619 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
623 } // detailpane frame/bg
627 // anything to render?
628 if ( render_jobs_b & R_GRID ) {
630 // if just rendering grid, and nothing else, better clear it first
631 if ( ! ( render_jobs_b & R_BG ) ) {
632 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
633 src.x = c -> grid_offset_x;
634 src.y = c -> grid_offset_y + c -> sel_icon_offset_y;
635 src.w = c -> col_max * c -> cell_width;
636 src.h = c -> row_max * c -> cell_height;
638 dest -> x = c -> grid_offset_x;
639 dest -> y = c -> grid_offset_y + c -> sel_icon_offset_y;
641 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
647 if ( g_categories [ ui_category ].refs ) {
649 appiter = g_categories [ ui_category ].refs;
653 // until we run out of apps, or run out of space
654 while ( appiter != NULL ) {
656 for ( col = 0; col < c -> col_max && appiter != NULL; col++ ) {
658 // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
659 if ( row >= ui_rows_scrolled_down ) {
661 // selected? show hilights
662 if ( appiter == ui_selected ) {
663 SDL_Surface *s = g_imagecache [ IMG_SELECTED_ALPHAMASK ].i;
665 //dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + ( ( icon_max_width - s -> w ) / 2 );
666 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> icon_offset_x + c -> sel_icon_offset_x;
667 //dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + ( ( icon_max_height - s -> h ) / 2 );
668 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> icon_offset_y + c -> sel_icon_offset_y;
669 SDL_BlitSurface ( s, NULL /* all */, sdl_realscreen, dest );
672 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_clip_x;
673 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> text_hilite_offset_y;
674 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
679 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
680 SDL_Surface *iconsurface;
682 iconsurface = ic -> i;
684 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
686 // no icon override; was this a pnd-file (show the unknown icon then), or was this generated from
687 // filesystem (file or directory icon)
688 if ( appiter -> ref -> object_flags & PND_DISCO_GENERATED ) {
689 if ( appiter -> ref -> object_type == pnd_object_type_directory ) {
690 iconsurface = g_imagecache [ IMG_FOLDER ].i;
692 iconsurface = g_imagecache [ IMG_EXECBIN ].i;
695 iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
700 // got an icon I hope?
702 //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
708 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> icon_offset_x + (( c -> icon_max_width - iconsurface -> w ) / 2);
709 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> icon_offset_y + (( c -> icon_max_height - iconsurface -> h ) / 2);
711 SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
714 ui_register_app ( appiter, dest -> x, dest -> y, src.w, src.h );
721 if ( appiter -> ref -> title_en ) {
723 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, c -> fontcolor );
726 src.w = c -> text_width < rtext -> w ? c -> text_width : rtext -> w;
728 if ( rtext -> w > c -> text_width ) {
729 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_clip_x;
731 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_offset_x - ( rtext -> w / 2 );
733 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> text_offset_y;
734 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
735 SDL_FreeSurface ( rtext );
739 } // display now? or scrolled away..
742 appiter = appiter -> next;
744 } // for column 1...X
746 if ( row >= ui_rows_scrolled_down ) {
752 // are we done displaying rows?
753 if ( displayrow >= c -> row_max ) {
760 // no apps to render?
761 pnd_log ( pndn_rem, "No applications to render?\n" );
766 // detail panel - show app details or blank-message
767 if ( render_jobs_b & R_DETAIL && ui_detail_hidden == 0 ) {
769 unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
770 unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
771 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "detailtext.cell_width" );
773 unsigned int desty = cell_offset_y;
780 if ( ui_selected -> ref -> title_en ) {
782 rtext = TTF_RenderText_Blended ( g_detailtext_font, ui_selected -> ref -> title_en, c -> fontcolor );
785 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
787 dest -> x = cell_offset_x;
789 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
790 SDL_FreeSurface ( rtext );
797 if ( ui_selected -> ref -> main_category ) {
799 sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
802 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
805 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
807 dest -> x = cell_offset_x;
809 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
810 SDL_FreeSurface ( rtext );
817 if ( ui_selected -> ref -> clockspeed ) {
819 sprintf ( buffer, "CPU Clock: %s", ui_selected -> ref -> clockspeed );
822 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
825 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
827 dest -> x = cell_offset_x;
829 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
830 SDL_FreeSurface ( rtext );
835 // show sub-app# on right side of cpu clock?
836 //if ( ui_selected -> ref -> subapp_number )
838 sprintf ( buffer, "(app#%u)", ui_selected -> ref -> subapp_number );
841 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
842 dest -> x = cell_offset_x + cell_width - rtext -> w;
843 dest -> y = desty - src.h;
844 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
845 SDL_FreeSurface ( rtext );
850 #if 0 // merged into hint-line
851 if ( ui_selected -> ref -> info_filename ) {
853 sprintf ( buffer, "Documentation - hit Y" );
856 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
859 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
861 dest -> x = cell_offset_x;
863 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
864 SDL_FreeSurface ( rtext );
871 if ( ui_selected -> ovrh ) {
876 desty += 5; // a touch of spacing can't hurt
878 for ( i = 1; i < 4; i++ ) {
879 sprintf ( buffer, "Application-%u.note-%u", ui_selected -> ref -> subapp_number, i );
880 n = pnd_conf_get_as_char ( ui_selected -> ovrh, buffer );
884 rtext = TTF_RenderText_Blended ( g_detailtext_font, n, c -> fontcolor );
887 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
889 dest -> x = cell_offset_x;
891 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
892 SDL_FreeSurface ( rtext );
898 } // r_detail -> notes
901 mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
902 SDL_Surface *previewpic;
905 previewpic = ic -> i;
907 previewpic = g_imagecache [ IMG_PREVIEW_MISSING ].i;
911 dest -> x = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_x", 50 ) +
912 ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
913 dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
914 SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
920 char *empty_message = "Press SELECT for menu";
924 rtext = TTF_RenderText_Blended ( g_detailtext_font, empty_message, c -> fontcolor );
928 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
930 dest -> x = cell_offset_x;
932 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
933 SDL_FreeSurface ( rtext );
938 } // r_detail && selected?
946 if ( render_jobs_b & R_BG ) {
947 static int last_battlevel = 0;
948 static unsigned char batterylevel = 0;
951 if ( time ( NULL ) - last_battlevel > 60 ) {
952 batterylevel = pnd_device_get_battery_gauge_perc();
953 last_battlevel = time ( NULL );
956 sprintf ( buffer, "Battery: %u%%", batterylevel );
959 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
960 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.battery_x", 20 );
961 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.battery_y", 450 );
962 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
963 SDL_FreeSurface ( rtext );
968 if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
970 unsigned int hintx, hinty;
971 hintx = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
972 hinty = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
973 static unsigned int lastwidth = 3000;
975 if ( ui_selected && ui_selected -> ref -> info_filename ) {
976 buffer = "Documentation - hit Y";
978 buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
982 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
985 if ( ! ( render_jobs_b & R_BG ) ) {
992 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, &src, sdl_realscreen, dest );
994 lastwidth = rtext -> w;
1000 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1001 SDL_FreeSurface ( rtext );
1006 if ( render_jobs_b & R_BG &&
1007 pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 )
1011 time_t t = time ( NULL );
1012 struct tm *tm = localtime ( &t );
1013 strftime ( buffer, 50, "%a %H:%M %F", tm );
1016 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1017 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.clock_x", 700 );
1018 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.clock_y", 450 );
1019 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1020 SDL_FreeSurface ( rtext );
1024 // update all the rects and send it all to sdl
1025 // - at this point, we could probably just do 1 rect, of the
1026 // whole screen, and be faster :/
1027 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1031 void ui_process_input ( unsigned char block_p ) {
1034 unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
1035 //static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
1037 while ( ! ui_event &&
1038 block_p ? SDL_WaitEvent ( &event ) : SDL_PollEvent ( &event ) )
1041 switch ( event.type ) {
1046 if ( event.user.code == sdl_user_ticker ) {
1048 // timer went off, time to load something
1049 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1051 // load the preview pics now!
1052 pnd_disco_t *iter = ui_selected -> ref;
1054 if ( iter -> preview_pic1 ) {
1056 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.threaded_preview", 0 ) ) {
1057 // load in bg thread, make user experience chuggy
1059 g_preview_thread = SDL_CreateThread ( (void*)ui_threaded_defered_preview, iter );
1061 if ( ! g_preview_thread ) {
1062 pnd_log ( pndn_error, "ERROR: Couldn't create preview thread\n" );
1066 // load it now, make user wait
1068 if ( ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
1069 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
1072 pnd_log ( pndn_debug, " Couldn't load preview pic: '%s' -> '%s'\n",
1073 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1078 } // got a preview at all?
1083 } else if ( event.user.code == sdl_user_finishedpreview ) {
1085 // if we just finished the one we happen to be looking at, better redraw now; otherwise, if
1086 // we finished another, no big woop
1087 if ( ui_selected && event.user.data1 == ui_selected -> ref ) {
1091 } else if ( event.user.code == sdl_user_finishedicon ) {
1092 // redraw, so we can show the newly loaded icon
1097 render_mask |= CHANGED_EVERYTHING;
1101 #if 0 // joystick motion
1102 case SDL_JOYAXISMOTION:
1104 pnd_log ( PND_LOG_DEFAULT, "joystick axis\n" );
1106 if ( event.jaxis.axis == 0 ) {
1108 if ( event.jaxis.value < 0 ) {
1110 pnd_log ( PND_LOG_DEFAULT, "joystick axis - LEFT\n" );
1111 } else if ( event.jaxis.value > 0 ) {
1112 ui_push_right ( 0 );
1113 pnd_log ( PND_LOG_DEFAULT, "joystick axis - RIGHT\n" );
1115 } else if ( event.jaxis.axis == 1 ) {
1117 if ( event.jaxis.value < 0 ) {
1119 } else if ( event.jaxis.value > 0 ) {
1129 #if 0 // joystick buttons
1130 case SDL_JOYBUTTONDOWN:
1132 pnd_log ( PND_LOG_DEFAULT, "joystick button down %u\n", event.jbutton.button );
1134 if ( event.jbutton.button == 0 ) { // B
1136 } else if ( event.jbutton.button == 1 ) { // Y
1138 } else if ( event.jbutton.button == 2 ) { // X
1140 } else if ( event.jbutton.button == 3 ) { // A
1143 } else if ( event.jbutton.button == 4 ) { // Select
1144 ui_mask |= uisb_select;
1145 } else if ( event.jbutton.button == 5 ) { // Start
1146 ui_mask |= uisb_start;
1148 } else if ( event.jbutton.button == 7 ) { // L
1150 } else if ( event.jbutton.button == 8 ) { // R
1159 case SDL_JOYBUTTONUP:
1161 pnd_log ( PND_LOG_DEFAULT, "joystick button up %u\n", event.jbutton.button );
1163 if ( event.jbutton.button == 0 ) { // B
1166 } else if ( event.jbutton.button == 1 ) { // Y
1168 } else if ( event.jbutton.button == 2 ) { // X
1170 } else if ( event.jbutton.button == 3 ) { // A
1173 } else if ( event.jbutton.button == 4 ) { // Select
1174 ui_mask &= ~uisb_select;
1175 } else if ( event.jbutton.button == 5 ) { // Start
1176 ui_mask &= ~uisb_start;
1178 } else if ( event.jbutton.button == 7 ) { // L
1181 } else if ( event.jbutton.button == 8 ) { // R
1192 #if 1 // keyboard events
1196 //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
1198 // SDLK_LALT -> Start
1199 // page up/down for y/x
1200 // home/end for a and b
1203 if ( event.key.keysym.sym == SDLK_RIGHT ) {
1204 ui_push_right ( 0 );
1206 } else if ( event.key.keysym.sym == SDLK_LEFT ) {
1209 } else if ( event.key.keysym.sym == SDLK_UP ) {
1212 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1215 } else if ( event.key.keysym.sym == SDLK_SPACE || event.key.keysym.sym == SDLK_END ) { // space or B
1218 } else if ( event.key.keysym.sym == SDLK_TAB || event.key.keysym.sym == SDLK_HOME ) { // tab or A
1219 // if detail panel is togglable, then toggle it
1220 // if not, make sure its ruddy well shown!
1221 if ( ui_is_detail_hideable() ) {
1222 ui_toggle_detail_pane();
1224 ui_detail_hidden = 0;
1227 } else if ( event.key.keysym.sym == SDLK_RSHIFT ) { // left trigger
1230 } else if ( event.key.keysym.sym == SDLK_RCTRL ) { // right trigger
1233 } else if ( event.key.keysym.sym == SDLK_PAGEUP ) { // Y
1235 if ( ui_selected ) {
1236 ui_show_info ( pnd_run_script, ui_selected -> ref );
1240 } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
1244 } else if ( event.key.keysym.sym == SDLK_LCTRL /*LALT*/ ) { // select button
1245 char *opts [ 20 ] = {
1246 "Reveal hidden category",
1248 "Configure Minimenu",
1249 "Rescan for applications",
1250 "Cache previews to SD now",
1251 "Run a terminal/console",
1252 "Run another GUI (xfce, etc)",
1254 "Select a Minimenu skin",
1257 int sel = ui_modal_single_menu ( opts, 10, "Minimenu", "Enter to select; other to return." );
1259 char buffer [ 100 ];
1263 } else if ( sel == 1 ) {
1265 sprintf ( buffer, "sudo poweroff" );
1267 } else if ( sel == 2 ) {
1269 unsigned char restart = conf_run_menu ( NULL );
1270 conf_write ( g_conf, conf_determine_location ( g_conf ) );
1272 emit_and_quit ( MM_RESTART );
1274 } else if ( sel == 3 ) {
1276 pnd_log ( pndn_debug, "Freeing up applications\n" );
1277 applications_free();
1278 pnd_log ( pndn_debug, "Rescanning applications\n" );
1279 applications_scan();
1280 } else if ( sel == 4 ) {
1281 // cache preview to SD now
1282 extern pnd_box_handle g_active_apps;
1283 pnd_box_handle h = g_active_apps;
1285 unsigned int maxwidth, maxheight;
1286 maxwidth = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 );
1287 maxheight = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 );
1289 pnd_disco_t *iter = pnd_box_get_head ( h );
1294 if ( ! cache_preview ( iter, maxwidth, maxheight ) ) {
1295 pnd_log ( pndn_debug, "Force cache: Couldn't load preview pic: '%s' -> '%s'\n",
1296 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1300 iter = pnd_box_get_next ( iter );
1303 } else if ( sel == 5 ) {
1306 argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
1310 ui_forkexec ( argv );
1313 } else if ( sel == 6 ) {
1314 char buffer [ PATH_MAX ];
1315 sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/pandora/scripts/op_switchgui.sh" );
1316 emit_and_quit ( buffer );
1317 } else if ( sel == 7 ) {
1318 emit_and_quit ( MM_QUIT );
1319 } else if ( sel == 8 ) {
1321 if ( ui_pick_skin() ) {
1322 emit_and_quit ( MM_RESTART );
1324 } else if ( sel == 9 ) {
1326 char buffer [ PATH_MAX ];
1327 sprintf ( buffer, "%s/about.txt", g_skinpath );
1328 ui_aboutscreen ( buffer );
1332 render_mask |= CHANGED_EVERYTHING;
1335 // unknown SDLK_ keycode?
1337 // many SDLK_keycodes map to ASCII ("a" is ascii(a)), so try to jump to a filename of that name, in this category?
1338 // and if already there, try to jump to next, maybe?
1339 // future: look for sequence typing? ie: user types 'm' then 'a', look for 'ma*' instead of 'm' then 'a' matching
1340 if ( isalpha ( event.key.keysym.sym ) && g_categories [ ui_category ].refcount > 0 ) {
1341 mm_appref_t *app = g_categories [ ui_category ].refs;
1343 //fprintf ( stderr, "sel %s next %s\n", ui_selected -> ref -> title_en, ui_selected -> next -> ref -> title_en );
1345 // are we already matching the same char? and next item is also same char?
1346 if ( app && ui_selected &&
1347 ui_selected -> ref -> title_en && ui_selected -> next -> ref -> title_en &&
1348 toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( ui_selected -> next -> ref -> title_en [ 0 ] ) &&
1349 toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym )
1352 // just skip down one
1353 app = ui_selected -> next;
1356 // walk the category, looking for a first-char match
1358 if ( app -> ref -> title_en && toupper ( app -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym ) ) {
1364 } // same start letter, or new run?
1366 // found something, or no?
1368 // looks like we found a potential match; try switching it to visible selection
1370 ui_set_selected ( ui_selected );
1377 } // SDLK_alphanumeric?
1383 if ( event.key.keysym.sym == SDLK_ESCAPE ) {
1384 emit_and_quit ( MM_QUIT );
1391 #if 1 // mouse / touchscreen
1393 case SDL_MOUSEBUTTONDOWN:
1394 if ( event.button.button == SDL_BUTTON_LEFT ) {
1395 cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
1401 case SDL_MOUSEBUTTONUP:
1402 if ( event.button.button == SDL_BUTTON_LEFT ) {
1403 ui_touch_act ( event.button.x, event.button.y );
1416 } // switch event type
1423 void ui_push_left ( unsigned char forcecoil ) {
1425 if ( ! ui_selected ) {
1426 ui_push_right ( 0 );
1430 // what column we in?
1431 unsigned int col = ui_determine_screen_col ( ui_selected );
1433 // are we already at first item?
1434 if ( forcecoil == 0 &&
1435 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1438 unsigned int i = ui_display_context.col_max - 1;
1439 while ( i && ui_selected -> next ) {
1440 ui_push_right ( 0 );
1444 } else if ( g_categories [ ui_category ].refs == ui_selected ) {
1445 // can't go any more left, we're at the head
1448 // figure out the previous item; yay for singly linked list :/
1449 mm_appref_t *i = g_categories [ ui_category ].refs;
1451 if ( i -> next == ui_selected ) {
1459 ui_set_selected ( ui_selected );
1464 void ui_push_right ( unsigned char forcecoil ) {
1466 if ( ui_selected ) {
1468 // what column we in?
1469 unsigned int col = ui_determine_screen_col ( ui_selected );
1472 if ( forcecoil == 0 &&
1473 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1474 // and selected is far-right, or last icon in category (might not be far right)
1475 ( ( col == ui_display_context.col_max - 1 ) ||
1476 ( ui_selected -> next == NULL ) )
1480 //unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1481 while ( col /*i*/ ) {
1487 // just go to the next
1489 if ( ui_selected -> next ) {
1490 ui_selected = ui_selected -> next;
1496 ui_selected = g_categories [ ui_category ].refs;
1499 ui_set_selected ( ui_selected );
1504 void ui_push_up ( void ) {
1505 unsigned char col_max = ui_display_context.col_max;
1507 if ( ! ui_selected ) {
1512 unsigned int row = ui_determine_row ( ui_selected );
1515 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 0 ) == 0 )
1517 // wrap around instead
1519 unsigned int col = ui_determine_screen_col ( ui_selected );
1522 ui_selected = g_categories [ ui_category ].refs;
1523 while ( ui_selected -> next ) {
1524 ui_selected = ui_selected -> next;
1527 // try to move to same column
1528 unsigned int newcol = ui_determine_screen_col ( ui_selected );
1529 if ( newcol > col ) {
1537 // scroll down to show it
1538 int r = ui_determine_row ( ui_selected ) - 1;
1539 if ( r - ui_display_context.row_max > 0 ) {
1540 ui_rows_scrolled_down = (unsigned int) r;
1544 // stop at top/bottom
1556 void ui_push_down ( void ) {
1557 unsigned char col_max = ui_display_context.col_max;
1559 if ( ui_selected ) {
1562 unsigned int row = ui_determine_row ( ui_selected );
1565 unsigned int icon_rows = g_categories [ ui_category ].refcount / col_max;
1566 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
1571 if ( row == ( icon_rows - 1 ) &&
1572 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 0 ) == 0 )
1575 unsigned char col = ui_determine_screen_col ( ui_selected );
1577 ui_selected = g_categories [ ui_category ].refs;
1580 ui_selected = ui_selected -> next;
1584 ui_rows_scrolled_down = 0;
1586 render_mask |= CHANGED_EVERYTHING;
1591 ui_push_right ( 1 );
1598 ui_push_right ( 0 );
1604 void ui_push_exec ( void ) {
1606 if ( ! ui_selected ) {
1610 // was this icon generated from filesystem, or from pnd-file?
1611 if ( ui_selected -> ref -> object_flags & PND_DISCO_GENERATED ) {
1613 if ( ! ui_selected -> ref -> title_en ) {
1614 return; // no filename
1617 if ( ui_selected -> ref -> object_type == pnd_object_type_directory ) {
1618 // delve up/down the dir tree
1620 if ( strcmp ( ui_selected -> ref -> title_en, ".." ) == 0 ) {
1624 // lop off last word; if the thing ends with /, lop that one, then the next word.
1625 while ( ( c = strrchr ( g_categories [ ui_category].fspath, '/' ) ) ) {
1626 *c = '\0'; // lop off the last hunk
1627 if ( *(c+1) != '\0' ) {
1633 if ( g_categories [ ui_category].fspath [ 0 ] == '\0' ) {
1634 strcpy ( g_categories [ ui_category].fspath, "/" );
1639 strcat ( g_categories [ ui_category].fspath, "/" );
1640 strcat ( g_categories [ ui_category].fspath, ui_selected -> ref -> title_en );
1643 pnd_log ( pndn_debug, "Cat %s is now in path %s\n", g_categories [ ui_category ].catname, g_categories [ ui_category ].fspath );
1646 category_fs_restock ( &(g_categories [ ui_category]) );
1647 // forget the selection, nolonger applies
1649 ui_set_selected ( ui_selected );
1651 render_mask |= CHANGED_SELECTION;
1654 // just run it arbitrarily?
1656 // if this a pnd-file, or just some executable?
1657 if ( strcasestr ( ui_selected -> ref -> object_filename, PND_PACKAGE_FILEEXT ) ) {
1658 // looks like a pnd, now what do we do..
1659 pnd_box_handle h = pnd_disco_file ( ui_selected -> ref -> object_path, ui_selected -> ref -> object_filename );
1662 pnd_disco_t *d = pnd_box_get_head ( h );
1663 pnd_apps_exec_disco ( pnd_run_script, d, PND_EXEC_OPTION_NORUN, NULL );
1664 char buffer [ PATH_MAX ];
1665 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1666 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
1667 emit_and_quit ( buffer );
1669 emit_and_run ( buffer );
1676 char cwd [ PATH_MAX ];
1677 getcwd ( cwd, PATH_MAX );
1679 chdir ( g_categories [ ui_category ].fspath );
1680 pnd_exec_no_wait_1 ( ui_selected -> ref -> title_en, NULL );
1683 char buffer [ PATH_MAX ];
1684 sprintf ( buffer, "%s %s/%s\n", MM_RUN, g_categories [ ui_category ].fspath, ui_selected -> ref -> title_en );
1685 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
1686 emit_and_quit ( buffer );
1688 emit_and_run ( buffer );
1697 // set app-run speed
1698 int use_run_speed = pnd_conf_get_as_int_d ( g_conf, "minimenu.use_run_speed", 0 );
1699 if ( use_run_speed > 0 ) {
1700 int mm_speed = pnd_conf_get_as_int_d ( g_conf, "minimenu.run_speed", -1 );
1701 if ( mm_speed > -1 ) {
1702 char buffer [ 512 ];
1703 snprintf ( buffer, 500, "sudo /usr/pandora/scripts/op_cpuspeed.sh %d", mm_speed );
1706 } // do speed change?
1708 // request app to run and quit mmenu
1709 pnd_apps_exec_disco ( pnd_run_script, ui_selected -> ref, PND_EXEC_OPTION_NORUN, NULL );
1710 char buffer [ PATH_MAX ];
1711 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1712 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
1713 emit_and_quit ( buffer );
1715 emit_and_run ( buffer );
1722 void ui_push_ltrigger ( void ) {
1723 unsigned char oldcat = ui_category;
1724 unsigned int screen_width = ui_display_context.screen_width;
1725 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1727 if ( g_categorycount == 0 ) {
1731 if ( ui_category > 0 ) {
1733 category_fs_restock ( &(g_categories [ ui_category ]) );
1735 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1736 ui_category = g_categorycount - 1;
1738 if ( ui_category >= ( screen_width / tab_width ) ) {
1739 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
1741 category_fs_restock ( &(g_categories [ ui_category ]) );
1745 if ( oldcat != ui_category ) {
1747 ui_set_selected ( ui_selected );
1750 // make tab visible?
1751 if ( ui_catshift > 0 && ui_category == ui_catshift - 1 ) {
1756 ui_rows_scrolled_down = 0;
1758 render_mask |= CHANGED_CATEGORY;
1763 void ui_push_rtrigger ( void ) {
1764 unsigned char oldcat = ui_category;
1766 if ( g_categorycount == 0 ) {
1770 unsigned int screen_width = ui_display_context.screen_width;
1771 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1773 if ( ui_category < ( g_categorycount - 1 ) ) {
1775 category_fs_restock ( &(g_categories [ ui_category ]) );
1777 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1780 category_fs_restock ( &(g_categories [ ui_category ]) );
1784 if ( oldcat != ui_category ) {
1786 ui_set_selected ( ui_selected );
1789 // make tab visible?
1790 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
1795 ui_rows_scrolled_down = 0;
1797 render_mask |= CHANGED_CATEGORY;
1802 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ) {
1803 double scale = 1000000.0;
1804 double scalex = 1000000.0;
1805 double scaley = 1000000.0;
1806 SDL_Surface *scaled;
1808 scalex = (double)maxwidth / (double)s -> w;
1810 if ( maxheight == -1 ) {
1813 scaley = (double)maxheight / (double)s -> h;
1815 if ( scaley < scalex ) {
1823 scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
1824 SDL_FreeSurface ( s );
1830 void ui_loadscreen ( void ) {
1835 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1839 rtext = TTF_RenderText_Blended ( g_big_font, "Setting up menu...", ui_display_context.fontcolor );
1842 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1843 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1844 SDL_FreeSurface ( rtext );
1849 void ui_discoverscreen ( unsigned char clearscreen ) {
1854 if ( clearscreen ) {
1855 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1857 // render background
1858 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1861 dest.w = sdl_realscreen -> w;
1862 dest.h = sdl_realscreen -> h;
1863 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1864 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1871 rtext = TTF_RenderText_Blended ( g_big_font, "Looking for applications...", ui_display_context.fontcolor );
1872 if ( clearscreen ) {
1879 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1880 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1881 SDL_FreeSurface ( rtext );
1884 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1885 dest.x = rtext -> w + 30;
1887 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, &dest );
1888 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1894 void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
1896 SDL_Rect rects [ 4 ];
1897 SDL_Rect *dest = rects;
1899 bzero ( dest, sizeof(SDL_Rect)* 4 );
1901 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1902 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1903 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1904 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1906 static unsigned int stepx = 0;
1909 if ( clearscreen ) {
1910 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1912 // render background
1913 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1916 dest -> w = sdl_realscreen -> w;
1917 dest -> h = sdl_realscreen -> h;
1918 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1924 // render background
1925 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1928 src.w = sdl_realscreen -> w;
1932 dest -> w = sdl_realscreen -> w;
1933 dest -> h = sdl_realscreen -> h;
1934 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
1942 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1943 rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
1946 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1947 SDL_FreeSurface ( rtext );
1951 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1952 dest -> x = rtext -> w + 30 + stepx;
1954 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, dest );
1960 rtext = TTF_RenderText_Blended ( g_tab_font, filename, tmpfontcolor );
1963 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1964 SDL_FreeSurface ( rtext );
1971 if ( stepx > 350 ) {
1975 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1980 int ui_selected_index ( void ) {
1982 if ( ! ui_selected ) {
1983 return ( -1 ); // no index
1986 mm_appref_t *r = g_categories [ ui_category ].refs;
1989 if ( r == ui_selected ) {
1999 static mm_appref_t *timer_ref = NULL;
2000 void ui_set_selected ( mm_appref_t *r ) {
2002 render_mask |= CHANGED_SELECTION;
2004 if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
2005 return; // no desire to defer anything
2010 SDL_SetTimer ( 0, NULL );
2015 SDL_SetTimer ( pnd_conf_get_as_int_d ( g_conf, "previewpic.defer_timer_ms", 1000 ), ui_callback_f );
2021 unsigned int ui_callback_f ( unsigned int t ) {
2023 if ( ui_selected != timer_ref ) {
2024 return ( 0 ); // user has moved it, who cares
2028 bzero ( &e, sizeof(SDL_Event) );
2029 e.type = SDL_USEREVENT;
2030 e.user.code = sdl_user_ticker;
2031 SDL_PushEvent ( &e );
2036 int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer ) {
2037 SDL_Rect rects [ 40 ];
2038 SDL_Rect *dest = rects;
2041 unsigned char max_visible = pnd_conf_get_as_int_d ( g_conf, "detailtext.max_visible" , 11 );
2042 unsigned char first_visible = 0;
2044 bzero ( rects, sizeof(SDL_Rect) * 40 );
2046 unsigned int sel = 0;
2048 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
2049 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
2050 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
2051 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
2053 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
2055 SDL_Color selfontcolor = { 0/*font_rgba_r*/, font_rgba_g, font_rgba_b, font_rgba_a };
2063 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2064 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2065 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
2066 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
2067 SDL_FillRect( sdl_realscreen, dest, 0 );
2069 // show dialog background
2070 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
2073 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> w;
2074 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> h;
2075 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2076 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2077 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2078 // repeat for darken?
2079 //SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2080 //SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2081 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2085 // show dialog frame
2086 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
2087 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2088 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2089 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
2090 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2096 rtext = TTF_RenderText_Blended ( g_tab_font, title, tmpfontcolor );
2097 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2098 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
2099 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2100 SDL_FreeSurface ( rtext );
2106 rtext = TTF_RenderText_Blended ( g_tab_font, footer, tmpfontcolor );
2107 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2108 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
2109 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
2111 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2112 SDL_FreeSurface ( rtext );
2117 for ( i = first_visible; i < first_visible + max_visible && i < argc; i++ ) {
2121 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
2123 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], tmpfontcolor );
2125 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2126 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 - first_visible ) );
2127 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2128 SDL_FreeSurface ( rtext );
2133 // update all the rects and send it all to sdl
2134 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
2138 while ( SDL_WaitEvent ( &event ) ) {
2140 switch ( event.type ) {
2145 if ( event.key.keysym.sym == SDLK_UP ) {
2149 if ( sel < first_visible ) {
2154 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
2156 if ( sel < argc - 1 ) {
2159 // ensure visibility
2160 if ( sel >= first_visible + max_visible ) {
2166 } else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_END ) { // return, or "B"
2170 } else if ( event.key.keysym.sym == SDLK_q ) {
2175 return ( -1 ); // nada
2190 unsigned char ui_determine_row ( mm_appref_t *a ) {
2191 unsigned int row = 0;
2193 mm_appref_t *i = g_categories [ ui_category ].refs;
2198 row /= ui_display_context.col_max;
2203 unsigned char ui_determine_screen_row ( mm_appref_t *a ) {
2204 return ( ui_determine_row ( a ) % ui_display_context.row_max );
2207 unsigned char ui_determine_screen_col ( mm_appref_t *a ) {
2208 unsigned int col = 0;
2210 mm_appref_t *i = g_categories [ ui_category ].refs;
2215 col %= ui_display_context.col_max;
2220 unsigned char ui_show_info ( char *pndrun, pnd_disco_t *p ) {
2221 char *viewer, *searchpath;
2222 pnd_conf_handle desktoph;
2225 searchpath = pnd_conf_query_searchpath();
2227 desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
2233 viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
2236 return ( 0 ); // no way to view the file
2240 if ( ! p -> unique_id ) {
2244 if ( ! p -> info_filename ) {
2248 if ( ! p -> info_name ) {
2259 if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) {
2260 snprintf ( pargs, 1001, "%s %s",
2261 pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
2266 char pndfile [ 1024 ];
2267 if ( p -> object_type == pnd_object_type_directory ) {
2268 // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
2269 strncpy ( pndfile, p -> object_path, 1000 );
2270 } else if ( p -> object_type == pnd_object_type_pnd ) {
2271 // pnd_run.sh wants the full path and filename for the .pnd file
2272 snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
2275 if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs,
2276 p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) )
2281 pnd_log ( pndn_debug, "Info Exec=%s\n", pnd_apps_exec_runline() );
2285 if ( ( x = fork() ) < 0 ) {
2286 pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
2291 execl ( "/bin/sh", "/bin/sh", "-c", pnd_apps_exec_runline(), (char*)NULL );
2292 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", pnd_apps_exec_runline() );
2304 #define MAXTOUCH 100
2305 ui_touch_t ui_touchrects [ MAXTOUCH ];
2306 unsigned char ui_touchrect_count = 0;
2308 void ui_register_reset ( void ) {
2309 bzero ( ui_touchrects, sizeof(ui_touch_t)*MAXTOUCH );
2310 ui_touchrect_count = 0;
2314 void ui_register_tab ( unsigned char catnum, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2316 if ( ui_touchrect_count == MAXTOUCH ) {
2320 ui_touchrects [ ui_touchrect_count ].r.x = x;
2321 ui_touchrects [ ui_touchrect_count ].r.y = y;
2322 ui_touchrects [ ui_touchrect_count ].r.w = w;
2323 ui_touchrects [ ui_touchrect_count ].r.h = h;
2324 ui_touchrects [ ui_touchrect_count ].catnum = catnum;
2325 ui_touchrect_count++;
2330 void ui_register_app ( mm_appref_t *app, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2332 if ( ui_touchrect_count == MAXTOUCH ) {
2336 ui_touchrects [ ui_touchrect_count ].r.x = x;
2337 ui_touchrects [ ui_touchrect_count ].r.y = y;
2338 ui_touchrects [ ui_touchrect_count ].r.w = w;
2339 ui_touchrects [ ui_touchrect_count ].r.h = h;
2340 ui_touchrects [ ui_touchrect_count ].ref = app;
2341 ui_touchrect_count++;
2346 void ui_touch_act ( unsigned int x, unsigned int y ) {
2351 for ( i = 0; i < ui_touchrect_count; i++ ) {
2352 t = &(ui_touchrects [ i ]);
2354 if ( x >= t -> r.x &&
2355 x <= t -> r.x + t -> r.w &&
2357 y <= t -> r.y + t -> r.h
2362 ui_selected = t -> ref;
2365 if ( ui_category != t -> catnum ) {
2368 ui_category = t -> catnum;
2369 render_mask |= CHANGED_CATEGORY;
2380 unsigned char ui_forkexec ( char *argv[] ) {
2381 char *fooby = argv[0];
2384 if ( ( x = fork() ) < 0 ) {
2385 pnd_log ( pndn_error, "ERROR: Couldn't fork() for '%s'\n", fooby );
2389 if ( x == 0 ) { // child
2390 execv ( fooby, argv );
2391 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", fooby );
2399 unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ) {
2401 if ( ! cache_preview ( p, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
2402 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
2405 pnd_log ( pndn_debug, "THREAD: Couldn't load preview pic: '%s' -> '%s'\n",
2406 IFNULL(p->title_en,"No Name"), p -> preview_pic1 );
2409 // trigger that we completed
2411 bzero ( &e, sizeof(SDL_Event) );
2412 e.type = SDL_USEREVENT;
2413 e.user.code = sdl_user_finishedpreview;
2415 SDL_PushEvent ( &e );
2420 SDL_Thread *g_icon_thread = NULL;
2421 void ui_post_scan ( void ) {
2423 // if deferred icon load, kick off the thread now
2424 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 1 ) {
2426 g_icon_thread = SDL_CreateThread ( (void*)ui_threaded_defered_icon, NULL );
2428 if ( ! g_icon_thread ) {
2429 pnd_log ( pndn_error, "ERROR: Couldn't create icon thread\n" );
2432 } // deferred icon load
2436 ui_rows_scrolled_down = 0;
2437 // set back to first tab, to be safe
2441 // do we have a preferred category to jump to?
2442 char *dc = pnd_conf_get_as_char ( g_conf, "categories.default_cat" );
2445 // attempt to find default cat; if we do find it, select it; otherwise
2446 // default behaviour will pick first cat (ie: usually All)
2448 for ( i = 0; i < g_categorycount; i++ ) {
2449 if ( strcasecmp ( g_categories [ i ].catname, dc ) == 0 ) {
2451 // ensure visibility
2452 unsigned int screen_width = ui_display_context.screen_width;
2453 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2454 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
2455 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
2461 if ( i == g_categorycount ) {
2462 pnd_log ( pndn_warning, " User defined default category '%s' but not found, so using default behaviour\n", dc );
2468 render_mask |= CHANGED_EVERYTHING;
2473 unsigned char ui_threaded_defered_icon ( void *p ) {
2474 extern pnd_box_handle g_active_apps;
2475 pnd_box_handle h = g_active_apps;
2477 unsigned char maxwidth, maxheight;
2478 maxwidth = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 );
2479 maxheight = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_height", 50 );
2481 pnd_disco_t *iter = pnd_box_get_head ( h );
2486 if ( iter -> pnd_icon_pos &&
2487 ! cache_icon ( iter, maxwidth, maxheight ) )
2489 pnd_log ( pndn_warning, " Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2492 // trigger that we completed
2494 bzero ( &e, sizeof(SDL_Event) );
2495 e.type = SDL_USEREVENT;
2496 e.user.code = sdl_user_finishedicon;
2497 SDL_PushEvent ( &e );
2499 //pnd_log ( pndn_warning, " Finished deferred load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2500 usleep ( pnd_conf_get_as_int_d ( g_conf, "minimenu.defer_icon_us", 50000 ) );
2505 iter = pnd_box_get_next ( iter );
2511 void ui_show_hourglass ( unsigned char updaterect ) {
2514 SDL_Surface *s = g_imagecache [ IMG_HOURGLASS ].i;
2516 dest.x = ( 800 - s -> w ) / 2;
2517 dest.y = ( 480 - s -> h ) / 2;
2519 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, &dest );
2522 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2528 unsigned char ui_pick_skin ( void ) {
2530 char *skins [ MAXSKINS ];
2533 char *searchpath = pnd_conf_get_as_char ( g_conf, "minimenu.skin_searchpath" );
2534 char tempname [ 100 ];
2538 skins [ iter++ ] = "No skin change";
2542 DIR *d = opendir ( buffer );
2547 while ( ( dd = readdir ( d ) ) ) {
2549 if ( dd -> d_name [ 0 ] == '.' ) {
2551 } else if ( ( dd -> d_type == DT_DIR || dd -> d_type == DT_UNKNOWN ) &&
2554 snprintf ( tempname, 100, "Skin: %s", dd -> d_name );
2555 skins [ iter++ ] = strdup ( tempname );
2566 int sel = ui_modal_single_menu ( skins, iter, "Skins", "Enter to select; other to return." );
2568 // did they pick one?
2572 char *s = strdup ( pnd_conf_get_as_char ( g_conf, "minimenu.skin_selected" ) );
2573 s = pnd_expand_tilde ( s );
2575 f = fopen ( s, "w" );
2580 fprintf ( f, "%s\n", skins [ sel ] + 6 );
2590 void ui_aboutscreen ( char *textpath ) {
2597 #define ROWS SCRH / ( PIXELH + MARGINH )
2598 #define COLS SCRW / ( PIXELW + MARGINW )
2600 unsigned char pixelboard [ ROWS * COLS ]; // pixel heat
2601 bzero ( pixelboard, ROWS * COLS );
2606 SDL_Color rtextc = { 200, 200, 200, 100 };
2609 char *textloop [ 500 ];
2610 unsigned int textmax = 0;
2611 bzero ( textloop, 500 * sizeof(char*) );
2614 char cbuffer [ 50000 ];
2615 bzero ( cbuffer, 50000 );
2616 unsigned int crevealed = 0;
2618 FILE *f = fopen ( textpath, "r" );
2621 pnd_log ( pndn_error, "ERROR: Couldn't open about text: %s\n", textpath );
2625 char textbuf [ 100 ];
2626 while ( fgets ( textbuf, 100, f ) ) {
2628 // add to full buffer
2629 strncat ( cbuffer, textbuf, 50000 );
2632 if ( strchr ( textbuf, '\n' ) ) {
2633 * strchr ( textbuf, '\n' ) = '\0';
2636 // add to pixel loop
2637 if ( 1||textbuf [ 0 ] ) {
2638 textloop [ textmax ] = strdup ( textbuf );
2646 unsigned int textiter = 0;
2647 while ( textiter < textmax ) {
2648 char *text = textloop [ textiter ];
2652 // render to surface
2653 rtext = TTF_RenderText_Blended ( g_grid_font, text, rtextc );
2655 // render font to pixelboard
2656 unsigned int px, py;
2658 unsigned int *pixels = rtext -> pixels;
2659 unsigned char cr, cg, cb, ca;
2660 for ( py = 0; py < rtext -> h; py ++ ) {
2661 for ( px = 0; px < ( rtext -> w > COLS ? COLS : rtext -> w ); px++ ) {
2663 SDL_GetRGBA ( pixels [ ( py * rtext -> pitch / 4 ) + px ],
2664 rtext -> format, &cr, &cg, &cb, &ca );
2668 ph = pixelboard + ( /*y offset */ 30 * COLS ) + ( py * COLS ) + px /* / 2 */;
2675 if ( *ph + ca < 250 ) {
2686 unsigned int runcount = 10;
2687 while ( runcount-- ) {
2690 SDL_FillRect( sdl_realscreen, NULL /* whole */, 0 );
2692 // render pixelboard
2695 for ( y = 0; y < ROWS; y++ ) {
2696 for ( x = 0; x < COLS; x++ ) {
2698 if ( 1||pixelboard [ ( y * COLS ) + x ] ) {
2701 r.x = x * ( PIXELW + MARGINW );
2702 r.y = y * ( PIXELH + MARGINH );
2706 c = SDL_MapRGB ( sdl_realscreen -> format, 100 /* r */, 0 /* g */, pixelboard [ ( y * COLS ) + x ] );
2708 SDL_FillRect( sdl_realscreen, &r /* whole */, c );
2716 unsigned char *pc = pixelboard;
2717 for ( y = 0; y < ROWS; y++ ) {
2718 for ( x = 0; x < COLS; x++ ) {
2728 // slide pixels upwards
2729 memmove ( pixelboard, pixelboard + COLS, ( COLS * ROWS ) - COLS );
2731 // render actual readable text
2734 // display up to cursor
2736 unsigned int cdraw = 0;
2740 if ( crevealed > 200 ) {
2741 cdraw = crevealed - 200;
2747 for ( ; cdraw < crevealed; cdraw++ ) {
2748 ctb [ 0 ] = cbuffer [ cdraw ];
2750 // move over or down
2751 if ( cbuffer [ cdraw ] == '\n' ) {
2756 if ( dest.y > 450 ) {
2762 cs = TTF_RenderText_Blended ( g_tab_font, ctb, rtextc );
2764 SDL_BlitSurface ( cs, NULL /* all */, sdl_realscreen, &dest );
2765 SDL_FreeSurface ( cs );
2775 SDL_FillRect ( sdl_realscreen, &dest /* whole */, 220 );
2777 // increment cursor to next character
2778 if ( cbuffer [ crevealed ] != '\0' ) {
2782 } // draw cursor text
2786 SDL_UpdateRect ( sdl_realscreen, 0, 0, 0, 0 ); // whole screen
2790 // any button? if so, about
2796 if ( SDL_PeepEvents ( &e, 1, SDL_GETEVENT, SDL_EVENTMASK(/*SDL_KEYUP|*/SDL_KEYDOWN) ) > 0 ) {
2805 SDL_FreeSurface ( rtext );
2809 } // while more text
2813 for ( i = 0; i < textmax; i++ ) {
2814 if ( textloop [ i ] ) {
2815 free ( textloop [ i ] );
2823 void ui_revealscreen ( void ) {
2824 char *labels [ 500 ];
2825 unsigned int labelmax = 0;
2828 if ( ! _categories_inviscount ) {
2829 return; // nothing to do
2832 for ( i = 0; i < _categories_inviscount; i++ ) {
2833 labels [ labelmax++ ] = _categories_invis [ i ].catname;
2836 int sel = ui_modal_single_menu ( labels, labelmax, "Temporary Category Reveal",
2837 "Enter to select; other to return." );
2841 if ( category_query ( _categories_invis [ sel ].catname ) ) {
2846 // fix up category name, if its been hacked
2847 if ( strchr ( _categories_invis [ sel ].catname, '.' ) ) {
2848 char *t = _categories_invis [ sel ].catname;
2849 _categories_invis [ sel ].catname = strdup ( strchr ( _categories_invis [ sel ].catname, '.' ) + 1 );
2852 // copy invisi-cat into live-cat
2853 memmove ( &(g_categories [ g_categorycount ]), &(_categories_invis [ sel ]), sizeof(mm_category_t) );
2855 // move subsequent invisi-cats up, so the selected invisi-cat is nolonger existing in invisi-list at
2856 // all (avoid double-free() later)
2857 memmove ( &(_categories_invis [ sel ]), &(_categories_invis [ sel + 1 ]), sizeof(mm_category_t) * ( _categories_inviscount - sel - 1 ) );
2858 _categories_inviscount--;
2860 // switch to the new category
2861 ui_category = g_categorycount - 1;
2863 // ensure visibility
2864 unsigned int screen_width = ui_display_context.screen_width;
2865 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2866 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
2867 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
2871 render_mask |= CHANGED_CATEGORY;
2877 void ui_recache_context ( ui_context_t *c ) {
2879 c -> screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
2881 c -> font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
2882 c -> font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
2883 c -> font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
2884 c -> font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
2886 c -> grid_offset_x = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_x" );
2887 c -> grid_offset_y = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_y" );
2889 c -> icon_offset_x = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_x" );
2890 c -> icon_offset_y = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_y" );
2891 c -> icon_max_width = pnd_conf_get_as_int ( g_conf, "grid.icon_max_width" );
2892 c -> icon_max_height = pnd_conf_get_as_int ( g_conf, "grid.icon_max_height" );
2893 c -> sel_icon_offset_x = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_x", 0 );
2894 c -> sel_icon_offset_y = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_y", 0 );
2896 c -> text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
2897 c -> text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
2898 c -> text_offset_x = pnd_conf_get_as_int ( g_conf, "grid.text_offset_x" );
2899 c -> text_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_offset_y" );
2900 c -> text_hilite_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
2902 c -> row_max = pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 4 );
2903 c -> col_max = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
2905 c -> cell_width = pnd_conf_get_as_int ( g_conf, "grid.cell_width" );
2906 c -> cell_height = pnd_conf_get_as_int ( g_conf, "grid.cell_height" );
2908 c -> arrow_bar_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
2909 c -> arrow_bar_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
2910 c -> arrow_bar_clip_w = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_w", 10 );
2911 c -> arrow_bar_clip_h = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_h", 100 );
2912 c -> arrow_up_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
2913 c -> arrow_up_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
2914 c -> arrow_down_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
2915 c -> arrow_down_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
2918 SDL_Color tmp = { c -> font_rgba_r, c -> font_rgba_g, c -> font_rgba_b, c -> font_rgba_a };
2919 c -> fontcolor = tmp;
2921 // now that we've got 'normal' (detail pane shown) param's, lets check if detail pane
2922 // is hidden; if so, override some values with those alternate skin values where possible.
2923 if ( ui_detail_hidden ) {
2924 // if detail panel is hidden, and theme cannot support it, unhide the bloody thing. (This may help
2925 // when someone is amid theme hacking or changing.)
2926 if ( ! ui_is_detail_hideable() ) {
2927 ui_detail_hidden = 0;
2931 if ( ui_detail_hidden ) {
2933 c -> row_max = pnd_conf_get_as_int_d ( g_conf, "grid.row_max_w", c -> row_max );
2934 c -> col_max = pnd_conf_get_as_int_d ( g_conf, "grid.col_max_w", c -> col_max );
2936 c -> cell_width = pnd_conf_get_as_int_d ( g_conf, "grid.cell_width_w", c -> cell_width );
2937 c -> cell_height = pnd_conf_get_as_int_d ( g_conf, "grid.cell_height_w", c -> cell_height );
2939 c -> arrow_bar_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x_w", 450 );
2940 c -> arrow_bar_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y_w", 100 );
2941 c -> arrow_up_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x_w", 450 );
2942 c -> arrow_up_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y_w", 80 );
2943 c -> arrow_down_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x_w", 450 );
2944 c -> arrow_down_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y_w", 80 );
2946 } // if detail hidden.. still.
2948 } // if detail hidden
2953 unsigned char ui_is_detail_hideable ( void ) {
2955 // if skin has a bit of info for wide-mode, we assume wide-mode is available
2956 if ( pnd_conf_get_as_char ( g_conf, "grid.row_max_w" ) != NULL ) {
2964 void ui_toggle_detail_pane ( void ) {
2966 // no bitmask trickery here; I like it to be stand-out obvious at 3am.
2968 if ( ui_detail_hidden ) {
2969 ui_detail_hidden = 0;
2971 ui_detail_hidden = 1;
2974 // repull skin config
2975 ui_recache_context ( &ui_display_context );
2978 render_mask |= CHANGED_EVERYTHING;