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;
48 #define MIMETYPE_EXE "/usr/bin/file" /* check for file type prior to invocation */
52 SDL_Surface *sdl_realscreen = NULL;
53 unsigned int sdl_ticks = 0;
54 SDL_Thread *g_preview_thread = NULL;
56 enum { sdl_user_ticker = 0,
57 sdl_user_finishedpreview = 1,
58 sdl_user_finishedicon = 2,
63 unsigned short int g_scale = 1; // 1 == noscale
65 SDL_Surface *g_imgcache [ IMG_MAX ];
67 TTF_Font *g_big_font = NULL;
68 TTF_Font *g_grid_font = NULL;
69 TTF_Font *g_detailtext_font = NULL;
70 TTF_Font *g_tab_font = NULL;
72 extern pnd_conf_handle g_conf;
74 /* current display state
76 int ui_rows_scrolled_down = 0; // number of rows that should be missing from top of the display
77 mm_appref_t *ui_selected = NULL;
78 unsigned char ui_category = 0; // current category
79 unsigned char ui_catshift = 0; // how many cats are offscreen to the left
80 ui_context_t ui_display_context; // display paramaters: see mmui_context.h
81 unsigned char ui_detail_hidden = 0; // if >0, detail panel is hidden
82 // FUTURE: If multiple panels can be shown/hidden, convert ui_detail_hidden to a bitmask
84 static SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ); // height -1 means ignore
85 static int ui_selected_index ( void );
87 unsigned char ui_setup ( void ) {
92 SDL_Init ( SDL_INIT_EVERYTHING | SDL_INIT_NOPARACHUTE );
94 SDL_JoystickOpen ( 0 ); // turn on joy-0
96 SDL_WM_SetCaption ( "mmenu", "mmenu" );
98 // hide the mouse cursor if we can
99 if ( SDL_ShowCursor ( -1 ) == 1 ) {
100 SDL_ShowCursor ( 0 );
106 unsigned int svm = SDL_SWSURFACE /*| SDL_FULLSCREEN*/ /* 0*/;
107 if ( pnd_conf_get_as_int_d ( g_conf, "display.fullscreen", 0 ) > 0 ) {
108 svm |= SDL_FULLSCREEN;
112 SDL_SetVideoMode ( 800 * g_scale, 480 * g_scale, 16 /*bpp*/, svm );
114 if ( ! sdl_realscreen ) {
115 pnd_log ( pndn_error, "ERROR: Couldn't open SDL real screen; dieing." );
119 pnd_log ( pndn_debug, "Pixel format:" );
120 pnd_log ( pndn_debug, "bpp b: %u\n", sdl_realscreen -> format -> BitsPerPixel );
121 pnd_log ( pndn_debug, "bpp B: %u\n", sdl_realscreen -> format -> BytesPerPixel );
122 pnd_log ( pndn_debug, "R mask: %08x\n", sdl_realscreen -> format -> Rmask );
123 pnd_log ( pndn_debug, "G mask: %08x\n", sdl_realscreen -> format -> Gmask );
124 pnd_log ( pndn_debug, "B mask: %08x\n", sdl_realscreen -> format -> Bmask );
130 /* Set 16-bit stereo audio at 22Khz */
131 fmt.freq = 44100; //22050;
132 fmt.format = AUDIO_S16; //AUDIO_S16;
134 fmt.samples = 2048; /* A good value for games */
135 fmt.callback = mixaudio;
138 /* Open the audio device and start playing sound! */
139 if ( SDL_OpenAudio ( &fmt, NULL ) < 0 ) {
140 zotlog ( "Unable to open audio: %s\n", SDL_GetError() );
144 SDL_PauseAudio ( 0 );
149 SDL_EnableKeyRepeat ( 500, 150 );
152 //IMG_Init ( IMG_INIT_JPG | IMG_INIT_PNG );
158 if ( TTF_Init() == -1 ) {
159 pnd_log ( pndn_error, "ERROR: Couldn't set up SDL TTF lib\n" );
160 return ( 0 ); // couldn't set up SDL TTF
163 char fullpath [ PATH_MAX ];
165 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "minimenu.font" ) );
166 g_big_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
167 if ( ! g_big_font ) {
168 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
169 pnd_conf_get_as_char ( g_conf, "minimenu.font" ), pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
170 return ( 0 ); // couldn't set up SDL TTF
174 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "grid.font" ) );
175 g_grid_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
176 if ( ! g_grid_font ) {
177 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
178 pnd_conf_get_as_char ( g_conf, "grid.font" ), pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
179 return ( 0 ); // couldn't set up SDL TTF
183 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "detailtext.font" ) );
184 g_detailtext_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
185 if ( ! g_detailtext_font ) {
186 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
187 pnd_conf_get_as_char ( g_conf, "detailtext.font" ), pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
188 return ( 0 ); // couldn't set up SDL TTF
192 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "tabs.font" ) );
193 g_tab_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
194 if ( ! g_tab_font ) {
195 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
196 pnd_conf_get_as_char ( g_conf, "tabs.font" ), pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
197 return ( 0 ); // couldn't set up SDL TTF
200 // determine display context
201 if ( pnd_conf_get_as_int_d ( g_conf, "display.show_detail_pane", 1 ) > 0 ) {
202 ui_detail_hidden = 0;
204 ui_detail_hidden = 1;
206 ui_recache_context ( &ui_display_context );
211 mm_imgcache_t g_imagecache [ IMG_TRUEMAX ] = {
212 { IMG_BACKGROUND_800480, "graphics.IMG_BACKGROUND_800480" },
213 { IMG_BACKGROUND_TABMASK, "graphics.IMG_BACKGROUND_TABMASK" },
214 { IMG_DETAIL_PANEL, "graphics.IMG_DETAIL_PANEL" },
215 { IMG_DETAIL_BG, "graphics.IMG_DETAIL_BG" },
216 { IMG_SELECTED_ALPHAMASK, "graphics.IMG_SELECTED_ALPHAMASK" },
217 { IMG_TAB_SEL, "graphics.IMG_TAB_SEL" },
218 { IMG_TAB_SEL_L, "graphics.IMG_TAB_SEL_L" },
219 { IMG_TAB_SEL_R, "graphics.IMG_TAB_SEL_R" },
220 { IMG_TAB_UNSEL, "graphics.IMG_TAB_UNSEL" },
221 { IMG_TAB_UNSEL_L, "graphics.IMG_TAB_UNSEL_L" },
222 { IMG_TAB_UNSEL_R, "graphics.IMG_TAB_UNSEL_R" },
223 { IMG_TAB_LINE, "graphics.IMG_TAB_LINE" },
224 { IMG_TAB_LINEL, "graphics.IMG_TAB_LINEL" },
225 { IMG_TAB_LINER, "graphics.IMG_TAB_LINER" },
226 { IMG_ICON_MISSING, "graphics.IMG_ICON_MISSING" },
227 { IMG_SELECTED_HILITE, "graphics.IMG_SELECTED_HILITE" },
228 { IMG_PREVIEW_MISSING, "graphics.IMG_PREVIEW_MISSING" },
229 { IMG_ARROW_UP, "graphics.IMG_ARROW_UP", },
230 { IMG_ARROW_DOWN, "graphics.IMG_ARROW_DOWN", },
231 { IMG_ARROW_SCROLLBAR, "graphics.IMG_ARROW_SCROLLBAR", },
232 { IMG_HOURGLASS, "graphics.IMG_HOURGLASS", },
233 { IMG_FOLDER, "graphics.IMG_FOLDER", },
234 { IMG_EXECBIN, "graphics.IMG_EXECBIN", },
238 unsigned char ui_imagecache ( char *basepath ) {
240 char fullpath [ PATH_MAX ];
244 for ( i = 0; i < IMG_MAX; i++ ) {
246 if ( g_imagecache [ i ].id != i ) {
247 pnd_log ( pndn_error, "ERROR: Internal table mismatch during caching [%u]\n", i );
251 char *filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].confname );
254 pnd_log ( pndn_error, "ERROR: Missing filename in conf for key: %s\n", g_imagecache [ i ].confname );
258 if ( filename [ 0 ] == '/' ) {
259 strncpy ( fullpath, filename, PATH_MAX );
261 sprintf ( fullpath, "%s/%s", basepath, filename );
264 if ( ! ( g_imagecache [ i ].i = IMG_Load ( fullpath ) ) ) {
265 pnd_log ( pndn_error, "ERROR: Couldn't load static cache image: %s\n", fullpath );
272 //g_imagecache [ IMG_SELECTED_ALPHAMASK ].i = SDL_CreateRGBSurface ( SDL_SWSURFACE, 60, 60, 32, 0xFF0000, 0x00FF00, 0xFF, 0xFF000000 );
273 //boxRGBA ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, 0, 0, 60, 60, 100, 100, 100, 250 );
279 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 );
280 // scale text hilight
281 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 );
282 // scale preview no-pic
283 g_imagecache [ IMG_PREVIEW_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_PREVIEW_MISSING ].i,
284 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ),
285 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 50 ) );
287 // set alpha on detail panel
288 //SDL_SetAlpha ( g_imagecache [ IMG_DETAIL_BG ].i, SDL_SRCALPHA, pnd_conf_get_as_int_d ( g_conf, "display.detail_bg_alpha", 50 ) );
293 void ui_render ( void ) {
296 // divide width: 550 / 250
297 // divide left side: 5 columns == 110px width
298 // 20px buffer either side == 70px wide icon + 20 + 20?
300 // what jobs to do during render?
304 #define R_TABS (1<<1)
305 #define R_DETAIL (1<<2)
306 #define R_GRID (1<<3)
308 #define R_ALL (R_BG|R_TABS|R_DETAIL|R_GRID)
310 unsigned int render_jobs_b = 0;
312 if ( render_mask & CHANGED_EVERYTHING ) {
313 render_jobs_b |= R_ALL;
316 if ( render_mask & CHANGED_SELECTION ) {
317 render_jobs_b |= R_GRID;
318 render_jobs_b |= R_DETAIL;
321 if ( render_mask & CHANGED_CATEGORY ) {
322 render_jobs_b |= R_ALL;
325 render_mask = CHANGED_NOTHING;
329 unsigned int icon_rows;
332 SDL_Rect rects [ MAXRECTS ], src;
333 SDL_Rect *dest = rects;
334 bzero ( dest, sizeof(SDL_Rect)*MAXRECTS );
336 unsigned int row, displayrow, col;
337 mm_appref_t *appiter;
339 ui_context_t *c = &ui_display_context; // for convenience and shorthand
341 // how many total rows do we need?
342 if ( g_categorycount ) {
343 icon_rows = g_categories [ ui_category ] -> refcount / c -> col_max;
344 if ( g_categories [ ui_category ] -> refcount % c -> col_max > 0 ) {
352 // if no selected app yet, select the first one
353 if ( ! ui_selected && pnd_conf_get_as_int_d ( g_conf, "minimenu.start_selected", 0 ) ) {
354 ui_selected = g_categories [ ui_category ] -> refs;
358 // reset touchscreen regions
359 if ( render_jobs_b ) {
363 // ensure selection is visible
366 int index = ui_selected_index();
367 int topleft = c -> col_max * ui_rows_scrolled_down;
368 int botright = ( c -> col_max * ( ui_rows_scrolled_down + c -> row_max ) - 1 );
370 if ( index < topleft ) {
371 ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
372 render_jobs_b |= R_ALL;
373 } else if ( index > botright ) {
374 ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
375 render_jobs_b |= R_ALL;
378 if ( ui_rows_scrolled_down < 0 ) {
379 ui_rows_scrolled_down = 0;
380 } else if ( ui_rows_scrolled_down > icon_rows ) {
381 ui_rows_scrolled_down = icon_rows;
387 if ( render_jobs_b & R_BG ) {
389 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
392 dest -> w = sdl_realscreen -> w;
393 dest -> h = sdl_realscreen -> h;
394 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
399 if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
402 dest -> w = sdl_realscreen -> w;
403 dest -> h = sdl_realscreen -> h;
404 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
411 if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
412 static unsigned int tab_width;
413 static unsigned int tab_height;
414 static unsigned int tab_offset_x;
415 static unsigned int tab_offset_y;
416 static unsigned int text_offset_x;
417 static unsigned int text_offset_y;
418 static unsigned int text_width;
420 static unsigned char tab_first_run = 1;
421 if ( tab_first_run ) {
423 tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
424 tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
425 tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
426 tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
427 text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
428 text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
429 text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
432 unsigned int maxtab = ( c -> screen_width / tab_width ) < g_categorycount ? ( c -> screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift;
433 unsigned int maxtabspot = ( c -> screen_width / tab_width );
435 if ( g_categorycount > 0 ) {
437 // draw tabs with categories
438 for ( col = ui_catshift;
445 // if this is the first (leftmost) tab, we use different artwork
446 // than if the other tabs (so skinner can link lines up nicely.)
447 if ( col == ui_catshift ) {
448 // leftmost tab, special case
450 if ( col == ui_category ) {
451 s = g_imagecache [ IMG_TAB_SEL_L ].i;
453 s = g_imagecache [ IMG_TAB_UNSEL_L ].i;
456 } else if ( col == maxtab - 1 ) {
457 // rightmost tab, special case
459 if ( col == ui_category ) {
460 s = g_imagecache [ IMG_TAB_SEL_R ].i;
462 s = g_imagecache [ IMG_TAB_UNSEL_R ].i;
466 // normal (not leftmost) tab
468 if ( col == ui_category ) {
469 s = g_imagecache [ IMG_TAB_SEL ].i;
471 s = g_imagecache [ IMG_TAB_UNSEL ].i;
474 } // first col, or not first col?
481 if ( col == ui_category ) {
482 src.h = tab_selheight;
490 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
491 dest -> y = tab_offset_y;
494 ui_register_tab ( col, dest -> x, dest -> y, tab_width, tab_height );
496 if ( render_jobs_b & R_TABS ) {
497 //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
498 SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
502 if ( col == ui_category ) {
503 // no line for selected tab
505 if ( col - ui_catshift == 0 ) {
506 s = g_imagecache [ IMG_TAB_LINEL ].i;
507 } else if ( col - ui_catshift == maxtabspot - 1 ) {
508 s = g_imagecache [ IMG_TAB_LINER ].i;
510 s = g_imagecache [ IMG_TAB_LINE ].i;
512 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
513 dest -> y = tab_offset_y + tab_height;
514 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
520 rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ] -> catname, c -> fontcolor );
523 src.w = rtext -> w < text_width ? rtext -> w : text_width;
525 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
526 dest -> y = tab_offset_y + text_offset_y;
527 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
528 SDL_FreeSurface ( rtext );
535 } // if we got categories
537 if ( render_jobs_b & R_TABS ) {
539 // draw tab lines under where tabs would be if we had categories
540 for ( /* foo */; col < maxtabspot; col++ ) {
543 if ( col - ui_catshift == 0 ) {
544 s = g_imagecache [ IMG_TAB_LINEL ].i;
545 } else if ( col - ui_catshift == maxtabspot - 1 ) {
546 s = g_imagecache [ IMG_TAB_LINER ].i;
548 s = g_imagecache [ IMG_TAB_LINE ].i;
550 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
551 dest -> y = tab_offset_y + tab_height;
552 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
561 // scroll bars and arrows
562 if ( render_jobs_b & R_BG ) {
563 unsigned char show_bar = 0;
566 if ( ui_rows_scrolled_down && g_imagecache [ IMG_ARROW_UP ].i ) {
567 dest -> x = c -> arrow_up_x;
568 dest -> y = c -> arrow_up_y;
569 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
576 if ( ui_rows_scrolled_down + c -> row_max < icon_rows && g_imagecache [ IMG_ARROW_DOWN ].i ) {
577 dest -> x = c -> arrow_down_x;
578 dest -> y = c -> arrow_down_y;
579 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
586 // show scrollbar as well
589 src.w = c -> arrow_bar_clip_w;
590 src.h = c -> arrow_bar_clip_h;
591 dest -> x = c -> arrow_bar_x;
592 dest -> y = c -> arrow_bar_y;
593 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
597 } // r_bg, scroll bars
599 // render detail pane bg
600 if ( render_jobs_b & R_DETAIL && ui_detail_hidden == 0 ) {
602 if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
605 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
606 src.x = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
607 src.y = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
608 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
609 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
610 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
611 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
612 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
616 // render detail pane
617 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
618 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
619 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
620 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
624 } // detailpane frame/bg
628 // anything to render?
629 if ( render_jobs_b & R_GRID && g_categorycount ) {
631 // if just rendering grid, and nothing else, better clear it first
632 if ( ! ( render_jobs_b & R_BG ) ) {
633 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
634 src.x = c -> grid_offset_x;
635 src.y = c -> grid_offset_y + c -> sel_icon_offset_y;
636 src.w = c -> col_max * c -> cell_width;
637 src.h = c -> row_max * c -> cell_height;
639 dest -> x = c -> grid_offset_x;
640 dest -> y = c -> grid_offset_y + c -> sel_icon_offset_y;
642 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
648 if ( g_categories [ ui_category ] -> refs ) {
650 appiter = g_categories [ ui_category ] -> refs;
654 // until we run out of apps, or run out of space
655 while ( appiter != NULL ) {
657 for ( col = 0; col < c -> col_max && appiter != NULL; col++ ) {
659 // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
660 if ( row >= ui_rows_scrolled_down ) {
662 // selected? show hilights
663 if ( appiter == ui_selected ) {
664 SDL_Surface *s = g_imagecache [ IMG_SELECTED_ALPHAMASK ].i;
666 //dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + ( ( icon_max_width - s -> w ) / 2 );
667 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> icon_offset_x + c -> sel_icon_offset_x;
668 //dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + ( ( icon_max_height - s -> h ) / 2 );
669 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> icon_offset_y + c -> sel_icon_offset_y;
670 SDL_BlitSurface ( s, NULL /* all */, sdl_realscreen, dest );
673 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_clip_x;
674 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> text_hilite_offset_y;
675 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
680 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
681 SDL_Surface *iconsurface;
683 iconsurface = ic -> i;
685 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
687 // no icon override; was this a pnd-file (show the unknown icon then), or was this generated from
688 // filesystem (file or directory icon)
689 if ( appiter -> ref -> object_flags & PND_DISCO_GENERATED ) {
690 if ( appiter -> ref -> object_type == pnd_object_type_directory ) {
691 iconsurface = g_imagecache [ IMG_FOLDER ].i;
693 iconsurface = g_imagecache [ IMG_EXECBIN ].i;
696 iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
701 // got an icon I hope?
703 //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
709 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> icon_offset_x + (( c -> icon_max_width - iconsurface -> w ) / 2);
710 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> icon_offset_y + (( c -> icon_max_height - iconsurface -> h ) / 2);
712 SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
715 ui_register_app ( appiter, dest -> x, dest -> y, src.w, src.h );
722 if ( appiter -> ref -> title_en ) {
724 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, c -> fontcolor );
727 src.w = c -> text_width < rtext -> w ? c -> text_width : rtext -> w;
729 if ( rtext -> w > c -> text_width ) {
730 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_clip_x;
732 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_offset_x - ( rtext -> w / 2 );
734 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> text_offset_y;
735 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
736 SDL_FreeSurface ( rtext );
740 } // display now? or scrolled away..
743 appiter = appiter -> next;
745 } // for column 1...X
747 if ( row >= ui_rows_scrolled_down ) {
753 // are we done displaying rows?
754 if ( displayrow >= c -> row_max ) {
761 // no apps to render?
762 pnd_log ( pndn_rem, "No applications to render?\n" );
767 // detail panel - show app details or blank-message
768 if ( render_jobs_b & R_DETAIL && ui_detail_hidden == 0 ) {
770 unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
771 unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
772 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "detailtext.cell_width" );
774 unsigned int desty = cell_offset_y;
781 if ( ui_selected -> ref -> title_en ) {
783 rtext = TTF_RenderText_Blended ( g_detailtext_font, ui_selected -> ref -> title_en, c -> fontcolor );
786 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
788 dest -> x = cell_offset_x;
790 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
791 SDL_FreeSurface ( rtext );
798 if ( ui_selected -> ref -> main_category ) {
800 sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
803 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
806 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
808 dest -> x = cell_offset_x;
810 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
811 SDL_FreeSurface ( rtext );
818 if ( ui_selected -> ref -> clockspeed ) {
820 sprintf ( buffer, "CPU Clock: %s", ui_selected -> ref -> clockspeed );
823 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
826 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
828 dest -> x = cell_offset_x;
830 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
831 SDL_FreeSurface ( rtext );
836 // show sub-app# on right side of cpu clock?
837 //if ( ui_selected -> ref -> subapp_number )
839 sprintf ( buffer, "(app#%u)", ui_selected -> ref -> subapp_number );
842 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
843 dest -> x = cell_offset_x + cell_width - rtext -> w;
844 dest -> y = desty - src.h;
845 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
846 SDL_FreeSurface ( rtext );
851 #if 0 // merged into hint-line
852 if ( ui_selected -> ref -> info_filename ) {
854 sprintf ( buffer, "Documentation - hit Y" );
857 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
860 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
862 dest -> x = cell_offset_x;
864 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
865 SDL_FreeSurface ( rtext );
872 if ( ui_selected -> ovrh ) {
877 desty += 5; // a touch of spacing can't hurt
879 for ( i = 1; i < 4; i++ ) {
880 sprintf ( buffer, "Application-%u.note-%u", ui_selected -> ref -> subapp_number, i );
881 n = pnd_conf_get_as_char ( ui_selected -> ovrh, buffer );
885 rtext = TTF_RenderText_Blended ( g_detailtext_font, n, c -> fontcolor );
888 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
890 dest -> x = cell_offset_x;
892 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
893 SDL_FreeSurface ( rtext );
899 } // r_detail -> notes
902 mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
903 SDL_Surface *previewpic;
906 previewpic = ic -> i;
908 previewpic = g_imagecache [ IMG_PREVIEW_MISSING ].i;
912 dest -> x = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_x", 50 ) +
913 ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
914 dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
915 SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
921 char *empty_message = "Press SELECT for menu";
925 rtext = TTF_RenderText_Blended ( g_detailtext_font, empty_message, c -> fontcolor );
929 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
931 dest -> x = cell_offset_x;
933 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
934 SDL_FreeSurface ( rtext );
939 } // r_detail && selected?
947 if ( render_jobs_b & R_BG ) {
948 static int last_battlevel = 0;
949 static unsigned char batterylevel = 0;
952 if ( time ( NULL ) - last_battlevel > 60 ) {
953 batterylevel = pnd_device_get_battery_gauge_perc();
954 last_battlevel = time ( NULL );
957 sprintf ( buffer, "Battery: %u%%", batterylevel );
960 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
961 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.battery_x", 20 );
962 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.battery_y", 450 );
963 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
964 SDL_FreeSurface ( rtext );
969 if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
971 unsigned int hintx, hinty;
972 hintx = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
973 hinty = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
974 static unsigned int lastwidth = 3000;
976 if ( ui_selected && ui_selected -> ref -> info_filename ) {
977 buffer = "Documentation - hit Y";
979 buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
983 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
986 if ( ! ( render_jobs_b & R_BG ) ) {
993 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, &src, sdl_realscreen, dest );
995 lastwidth = rtext -> w;
1001 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1002 SDL_FreeSurface ( rtext );
1007 if ( render_jobs_b & R_BG &&
1008 pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 )
1012 time_t t = time ( NULL );
1013 struct tm *tm = localtime ( &t );
1014 strftime ( buffer, 50, "%a %H:%M %F", tm );
1017 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1018 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.clock_x", 700 );
1019 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.clock_y", 450 );
1020 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1021 SDL_FreeSurface ( rtext );
1025 // update all the rects and send it all to sdl
1026 // - at this point, we could probably just do 1 rect, of the
1027 // whole screen, and be faster :/
1028 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1032 void ui_process_input ( unsigned char block_p ) {
1035 unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
1036 //static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
1038 while ( ! ui_event &&
1039 block_p ? SDL_WaitEvent ( &event ) : SDL_PollEvent ( &event ) )
1042 switch ( event.type ) {
1047 if ( event.user.code == sdl_user_ticker ) {
1049 // timer went off, time to load something
1050 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1052 if ( ! ui_selected ) {
1056 // load the preview pics now!
1057 pnd_disco_t *iter = ui_selected -> ref;
1059 if ( iter -> preview_pic1 ) {
1061 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.threaded_preview", 0 ) ) {
1062 // load in bg thread, make user experience chuggy
1064 g_preview_thread = SDL_CreateThread ( (void*)ui_threaded_defered_preview, iter );
1066 if ( ! g_preview_thread ) {
1067 pnd_log ( pndn_error, "ERROR: Couldn't create preview thread\n" );
1071 // load it now, make user wait
1073 if ( ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
1074 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
1077 pnd_log ( pndn_debug, " Couldn't load preview pic: '%s' -> '%s'\n",
1078 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1083 } // got a preview at all?
1088 } else if ( event.user.code == sdl_user_finishedpreview ) {
1090 // if we just finished the one we happen to be looking at, better redraw now; otherwise, if
1091 // we finished another, no big woop
1092 if ( ui_selected && event.user.data1 == ui_selected -> ref ) {
1096 } else if ( event.user.code == sdl_user_finishedicon ) {
1097 // redraw, so we can show the newly loaded icon
1102 render_mask |= CHANGED_EVERYTHING;
1106 #if 0 // joystick motion
1107 case SDL_JOYAXISMOTION:
1109 pnd_log ( PND_LOG_DEFAULT, "joystick axis\n" );
1111 if ( event.jaxis.axis == 0 ) {
1113 if ( event.jaxis.value < 0 ) {
1115 pnd_log ( PND_LOG_DEFAULT, "joystick axis - LEFT\n" );
1116 } else if ( event.jaxis.value > 0 ) {
1117 ui_push_right ( 0 );
1118 pnd_log ( PND_LOG_DEFAULT, "joystick axis - RIGHT\n" );
1120 } else if ( event.jaxis.axis == 1 ) {
1122 if ( event.jaxis.value < 0 ) {
1124 } else if ( event.jaxis.value > 0 ) {
1134 #if 0 // joystick buttons
1135 case SDL_JOYBUTTONDOWN:
1137 pnd_log ( PND_LOG_DEFAULT, "joystick button down %u\n", event.jbutton.button );
1139 if ( event.jbutton.button == 0 ) { // B
1141 } else if ( event.jbutton.button == 1 ) { // Y
1143 } else if ( event.jbutton.button == 2 ) { // X
1145 } else if ( event.jbutton.button == 3 ) { // A
1148 } else if ( event.jbutton.button == 4 ) { // Select
1149 ui_mask |= uisb_select;
1150 } else if ( event.jbutton.button == 5 ) { // Start
1151 ui_mask |= uisb_start;
1153 } else if ( event.jbutton.button == 7 ) { // L
1155 } else if ( event.jbutton.button == 8 ) { // R
1164 case SDL_JOYBUTTONUP:
1166 pnd_log ( PND_LOG_DEFAULT, "joystick button up %u\n", event.jbutton.button );
1168 if ( event.jbutton.button == 0 ) { // B
1171 } else if ( event.jbutton.button == 1 ) { // Y
1173 } else if ( event.jbutton.button == 2 ) { // X
1175 } else if ( event.jbutton.button == 3 ) { // A
1178 } else if ( event.jbutton.button == 4 ) { // Select
1179 ui_mask &= ~uisb_select;
1180 } else if ( event.jbutton.button == 5 ) { // Start
1181 ui_mask &= ~uisb_start;
1183 } else if ( event.jbutton.button == 7 ) { // L
1186 } else if ( event.jbutton.button == 8 ) { // R
1197 #if 1 // keyboard events
1201 //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
1203 // SDLK_LALT -> Start
1204 // page up/down for y/x
1205 // home/end for a and b
1208 if ( event.key.keysym.sym == SDLK_RIGHT ) {
1209 ui_push_right ( 0 );
1211 } else if ( event.key.keysym.sym == SDLK_LEFT ) {
1214 } else if ( event.key.keysym.sym == SDLK_UP ) {
1217 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1220 } else if ( event.key.keysym.sym == SDLK_SPACE || event.key.keysym.sym == SDLK_END ) { // space or B
1223 } else if ( event.key.keysym.sym == SDLK_TAB || event.key.keysym.sym == SDLK_HOME ) { // tab or A
1224 // if detail panel is togglable, then toggle it
1225 // if not, make sure its ruddy well shown!
1226 if ( ui_is_detail_hideable() ) {
1227 ui_toggle_detail_pane();
1229 ui_detail_hidden = 0;
1232 } else if ( event.key.keysym.sym == SDLK_RSHIFT || event.key.keysym.sym == SDLK_COMMA ) { // left trigger or comma
1235 } else if ( event.key.keysym.sym == SDLK_RCTRL || event.key.keysym.sym == SDLK_PERIOD ) { // right trigger or period
1238 } else if ( event.key.keysym.sym == SDLK_PAGEUP ) { // Y
1240 if ( ui_selected ) {
1241 ui_show_info ( pnd_run_script, ui_selected -> ref );
1245 } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
1249 } else if ( event.key.keysym.sym == SDLK_LCTRL /*LALT*/ ) { // select button
1250 char *opts [ 20 ] = {
1251 "Reveal hidden category",
1253 "Configure Minimenu",
1254 "Rescan for applications",
1255 "Cache previews to SD now",
1256 "Run a terminal/console",
1257 "Run another GUI (xfce, etc)",
1259 "Select a Minimenu skin",
1262 int sel = ui_modal_single_menu ( opts, 10, "Minimenu", "Enter to select; other to return." );
1264 char buffer [ 100 ];
1268 } else if ( sel == 1 ) {
1270 sprintf ( buffer, "sudo poweroff" );
1272 } else if ( sel == 2 ) {
1274 unsigned char restart = conf_run_menu ( NULL );
1275 conf_write ( g_conf, conf_determine_location ( g_conf ) );
1277 emit_and_quit ( MM_RESTART );
1279 } else if ( sel == 3 ) {
1281 pnd_log ( pndn_debug, "Freeing up applications\n" );
1282 applications_free();
1283 pnd_log ( pndn_debug, "Rescanning applications\n" );
1284 applications_scan();
1285 } else if ( sel == 4 ) {
1286 // cache preview to SD now
1287 extern pnd_box_handle g_active_apps;
1288 pnd_box_handle h = g_active_apps;
1290 unsigned int maxwidth, maxheight;
1291 maxwidth = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 );
1292 maxheight = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 );
1294 pnd_disco_t *iter = pnd_box_get_head ( h );
1299 if ( ! cache_preview ( iter, maxwidth, maxheight ) ) {
1300 pnd_log ( pndn_debug, "Force cache: Couldn't load preview pic: '%s' -> '%s'\n",
1301 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1305 iter = pnd_box_get_next ( iter );
1308 } else if ( sel == 5 ) {
1311 argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
1315 ui_forkexec ( argv );
1318 } else if ( sel == 6 ) {
1319 char buffer [ PATH_MAX ];
1320 sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/pandora/scripts/op_switchgui.sh" );
1321 emit_and_quit ( buffer );
1322 } else if ( sel == 7 ) {
1323 emit_and_quit ( MM_QUIT );
1324 } else if ( sel == 8 ) {
1326 if ( ui_pick_skin() ) {
1327 emit_and_quit ( MM_RESTART );
1329 } else if ( sel == 9 ) {
1331 char buffer [ PATH_MAX ];
1332 sprintf ( buffer, "%s/about.txt", g_skinpath );
1333 ui_aboutscreen ( buffer );
1337 render_mask |= CHANGED_EVERYTHING;
1340 // unknown SDLK_ keycode?
1342 // many SDLK_keycodes map to ASCII ("a" is ascii(a)), so try to jump to a filename of that name, in this category?
1343 // and if already there, try to jump to next, maybe?
1344 // future: look for sequence typing? ie: user types 'm' then 'a', look for 'ma*' instead of 'm' then 'a' matching
1345 if ( isalpha ( event.key.keysym.sym ) && g_categories [ ui_category ] -> refcount > 0 ) {
1346 mm_appref_t *app = g_categories [ ui_category ] -> refs;
1348 //fprintf ( stderr, "sel %s next %s\n", ui_selected -> ref -> title_en, ui_selected -> next -> ref -> title_en );
1350 // are we already matching the same char? and next item is also same char?
1351 if ( app && ui_selected &&
1352 ui_selected -> ref -> title_en && ui_selected -> next -> ref -> title_en &&
1353 toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( ui_selected -> next -> ref -> title_en [ 0 ] ) &&
1354 toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym )
1357 // just skip down one
1358 app = ui_selected -> next;
1361 // walk the category, looking for a first-char match
1363 if ( app -> ref -> title_en && toupper ( app -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym ) ) {
1369 } // same start letter, or new run?
1371 // found something, or no?
1373 // looks like we found a potential match; try switching it to visible selection
1375 ui_set_selected ( ui_selected );
1382 } // SDLK_alphanumeric?
1388 if ( event.key.keysym.sym == SDLK_ESCAPE ) {
1389 emit_and_quit ( MM_QUIT );
1396 #if 1 // mouse / touchscreen
1398 case SDL_MOUSEBUTTONDOWN:
1399 if ( event.button.button == SDL_BUTTON_LEFT ) {
1400 cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
1406 case SDL_MOUSEBUTTONUP:
1407 if ( event.button.button == SDL_BUTTON_LEFT ) {
1408 ui_touch_act ( event.button.x, event.button.y );
1421 } // switch event type
1428 void ui_push_left ( unsigned char forcecoil ) {
1430 if ( ! ui_selected ) {
1431 ui_push_right ( 0 );
1435 // what column we in?
1436 unsigned int col = ui_determine_screen_col ( ui_selected );
1438 // are we already at first item?
1439 if ( forcecoil == 0 &&
1440 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1443 unsigned int i = ui_display_context.col_max - 1;
1444 while ( i && ui_selected -> next ) {
1445 ui_push_right ( 0 );
1449 } else if ( g_categories [ ui_category ] -> refs == ui_selected ) {
1450 // can't go any more left, we're at the head
1453 // figure out the previous item; yay for singly linked list :/
1454 mm_appref_t *i = g_categories [ ui_category ] -> refs;
1456 if ( i -> next == ui_selected ) {
1464 ui_set_selected ( ui_selected );
1469 void ui_push_right ( unsigned char forcecoil ) {
1471 if ( ui_selected ) {
1473 // what column we in?
1474 unsigned int col = ui_determine_screen_col ( ui_selected );
1477 if ( forcecoil == 0 &&
1478 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1479 // and selected is far-right, or last icon in category (might not be far right)
1480 ( ( col == ui_display_context.col_max - 1 ) ||
1481 ( ui_selected -> next == NULL ) )
1485 //unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1486 while ( col /*i*/ ) {
1492 // just go to the next
1494 if ( ui_selected -> next ) {
1495 ui_selected = ui_selected -> next;
1501 ui_selected = g_categories [ ui_category ] -> refs;
1504 ui_set_selected ( ui_selected );
1509 void ui_push_up ( void ) {
1510 unsigned char col_max = ui_display_context.col_max;
1512 if ( ! ui_selected ) {
1517 unsigned int row = ui_determine_row ( ui_selected );
1520 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 0 ) == 0 )
1522 // wrap around instead
1524 unsigned int col = ui_determine_screen_col ( ui_selected );
1527 ui_selected = g_categories [ ui_category ] -> refs;
1528 while ( ui_selected -> next ) {
1529 ui_selected = ui_selected -> next;
1532 // try to move to same column
1533 unsigned int newcol = ui_determine_screen_col ( ui_selected );
1534 if ( newcol > col ) {
1542 // scroll down to show it
1543 int r = ui_determine_row ( ui_selected ) - 1;
1544 if ( r - ui_display_context.row_max > 0 ) {
1545 ui_rows_scrolled_down = (unsigned int) r;
1549 // stop at top/bottom
1561 void ui_push_down ( void ) {
1562 unsigned char col_max = ui_display_context.col_max;
1564 if ( ui_selected ) {
1567 unsigned int row = ui_determine_row ( ui_selected );
1570 unsigned int icon_rows = g_categories [ ui_category ] -> refcount / col_max;
1571 if ( g_categories [ ui_category ] -> refcount % col_max > 0 ) {
1576 if ( row == ( icon_rows - 1 ) &&
1577 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 0 ) == 0 )
1580 unsigned char col = ui_determine_screen_col ( ui_selected );
1582 ui_selected = g_categories [ ui_category ] -> refs;
1585 ui_selected = ui_selected -> next;
1589 ui_rows_scrolled_down = 0;
1591 render_mask |= CHANGED_EVERYTHING;
1596 ui_push_right ( 1 );
1603 ui_push_right ( 0 );
1609 void ui_push_exec ( void ) {
1611 if ( ! ui_selected ) {
1615 // was this icon generated from filesystem, or from pnd-file?
1616 if ( ui_selected -> ref -> object_flags & PND_DISCO_GENERATED ) {
1618 if ( ! ui_selected -> ref -> title_en ) {
1619 return; // no filename
1622 if ( ui_selected -> ref -> object_type == pnd_object_type_directory ) {
1624 // check if this guy is a dir-browser tab, or is a directory on a pnd tab
1625 if ( ! g_categories [ ui_category] -> fspath ) {
1626 // pnd subcat as dir
1628 static char *ui_category_stack = NULL;
1630 // are we already in a subcat? if so, go back to parent; there is no grandparenting or deeper
1631 if ( g_categories [ ui_category ] -> parent_catname ) {
1634 // set to first cat!
1636 // republish cats .. shoudl just be the one
1637 category_publish ( CFNORMAL, NULL );
1639 if ( ui_category_stack ) {
1640 ui_category = category_index ( ui_category_stack );
1644 // delve into subcat
1646 // set to first cat!
1647 ui_category_stack = g_categories [ ui_category ] -> catname;
1649 // republish cats .. shoudl just be the one
1650 category_publish ( CFBYNAME, ui_selected -> ref -> object_path );
1654 // forget the selection, nolonger applies
1656 ui_set_selected ( ui_selected );
1658 render_mask |= CHANGED_EVERYTHING;
1662 // delve up/down the dir tree
1663 if ( strcmp ( ui_selected -> ref -> title_en, ".." ) == 0 ) {
1667 // lop off last word; if the thing ends with /, lop that one, then the next word.
1668 while ( ( c = strrchr ( g_categories [ ui_category] -> fspath, '/' ) ) ) {
1669 *c = '\0'; // lop off the last hunk
1670 if ( *(c+1) != '\0' ) {
1676 if ( g_categories [ ui_category] -> fspath [ 0 ] == '\0' ) {
1677 free ( g_categories [ ui_category] -> fspath );
1678 g_categories [ ui_category] -> fspath = strdup ( "/" );
1683 char *temp = malloc ( strlen ( g_categories [ ui_category] -> fspath ) + strlen ( ui_selected -> ref -> title_en ) + 1 + 1 );
1684 sprintf ( temp, "%s/%s", g_categories [ ui_category] -> fspath, ui_selected -> ref -> title_en );
1685 free ( g_categories [ ui_category] -> fspath );
1686 g_categories [ ui_category] -> fspath = temp;
1689 pnd_log ( pndn_debug, "Cat %s is now in path %s\n", g_categories [ ui_category ] -> catname, g_categories [ ui_category ]-> fspath );
1691 // forget the selection, nolonger applies
1693 ui_set_selected ( ui_selected );
1695 category_fs_restock ( g_categories [ ui_category ] );
1697 render_mask |= CHANGED_SELECTION;
1699 } // directory browser or pnd subcat?
1702 // just run it arbitrarily?
1704 // if this a pnd-file, or just some executable?
1705 if ( strcasestr ( ui_selected -> ref -> object_filename, PND_PACKAGE_FILEEXT ) ) {
1706 // looks like a pnd, now what do we do..
1707 pnd_box_handle h = pnd_disco_file ( ui_selected -> ref -> object_path, ui_selected -> ref -> object_filename );
1710 pnd_disco_t *d = pnd_box_get_head ( h );
1711 pnd_apps_exec_disco ( pnd_run_script, d, PND_EXEC_OPTION_NORUN, NULL );
1712 char buffer [ PATH_MAX ];
1713 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1714 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
1715 emit_and_quit ( buffer );
1717 emit_and_run ( buffer );
1724 // is it even executable? if we don't have handlers for non-executables yet (Jan 2011 we don't),
1725 // then don't even try to run things not-flagged as executable.. but wait most people are on
1726 // FAT filesystems, what a drag, we can't tell at the fs level.
1727 // ... but we can still invoke 'file' and grep out the good bits, at least.
1729 // open a stream reading 'file /path/to/file' and check output for 'executable'
1730 // -- not checking for "ARM" so it can pick up x86 (or whatever native) executables in build environment
1731 unsigned char is_executable = 0;
1735 char popenbuf [ FILENAME_MAX ];
1736 snprintf ( popenbuf, FILENAME_MAX, "%s %s/%s", MIMETYPE_EXE, g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
1739 if ( ! ( marceau = popen ( popenbuf, "r" ) ) ) {
1740 return; // error, we need some useful error handling and dialog boxes here
1743 if ( fgets ( popenbuf, FILENAME_MAX, marceau ) ) {
1744 //printf ( "File test returns: %s\n", popenbuf );
1745 if ( strstr ( popenbuf, "executable" ) != NULL ) {
1754 if ( ! is_executable ) {
1755 fprintf ( stderr, "ERROR: File to invoke is not executable, skipping. (%s)\n", ui_selected -> ref -> title_en );
1756 return; // need some error handling here
1759 #if 0 // eat up any pending SDL events and toss 'em?
1763 while ( SDL_PeepEvents ( &e, 1, SDL_GETEVENT, SDL_ALLEVENTS ) > 0 ) {
1773 // get CWD so we can restore it on return
1774 char cwd [ PATH_MAX ];
1775 getcwd ( cwd, PATH_MAX );
1777 // full path to executable so we don't rely on implicit "./"
1778 char execbuf [ FILENAME_MAX ];
1779 snprintf ( execbuf, FILENAME_MAX, "%s/%s", g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
1782 chdir ( g_categories [ ui_category ] -> fspath );
1783 exec_raw_binary ( execbuf /*ui_selected -> ref -> title_en*/ );
1786 // DEPRECATED / NOT TESTED
1787 // get mmwrapper to run it
1788 char buffer [ PATH_MAX ];
1789 sprintf ( buffer, "%s %s/%s\n", MM_RUN, g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
1790 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
1791 emit_and_quit ( buffer );
1793 emit_and_run ( buffer );
1802 // set app-run speed
1803 int use_run_speed = pnd_conf_get_as_int_d ( g_conf, "minimenu.use_run_speed", 0 );
1804 if ( use_run_speed > 0 ) {
1805 int mm_speed = pnd_conf_get_as_int_d ( g_conf, "minimenu.run_speed", -1 );
1806 if ( mm_speed > -1 ) {
1807 char buffer [ 512 ];
1808 snprintf ( buffer, 500, "sudo /usr/pandora/scripts/op_cpuspeed.sh %d", mm_speed );
1811 } // do speed change?
1813 // request app to run and quit mmenu
1814 pnd_apps_exec_disco ( pnd_run_script, ui_selected -> ref, PND_EXEC_OPTION_NORUN, NULL );
1815 char buffer [ PATH_MAX ];
1816 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1817 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
1818 emit_and_quit ( buffer );
1820 emit_and_run ( buffer );
1827 void ui_push_ltrigger ( void ) {
1828 unsigned char oldcat = ui_category;
1829 unsigned int screen_width = ui_display_context.screen_width;
1830 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1832 if ( g_categorycount == 0 ) {
1836 if ( ui_category > 0 ) {
1838 category_fs_restock ( g_categories [ ui_category ] );
1840 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1841 ui_category = g_categorycount - 1;
1843 if ( ui_category >= ( screen_width / tab_width ) ) {
1844 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
1846 category_fs_restock ( g_categories [ ui_category ] );
1850 if ( oldcat != ui_category ) {
1852 ui_set_selected ( ui_selected );
1855 // make tab visible?
1856 if ( ui_catshift > 0 && ui_category == ui_catshift - 1 ) {
1861 ui_rows_scrolled_down = 0;
1863 render_mask |= CHANGED_CATEGORY;
1868 void ui_push_rtrigger ( void ) {
1869 unsigned char oldcat = ui_category;
1871 if ( g_categorycount == 0 ) {
1875 unsigned int screen_width = ui_display_context.screen_width;
1876 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1878 if ( ui_category < ( g_categorycount - 1 ) ) {
1880 category_fs_restock ( g_categories [ ui_category ] );
1882 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1885 category_fs_restock ( g_categories [ ui_category ] );
1889 if ( oldcat != ui_category ) {
1891 ui_set_selected ( ui_selected );
1894 // make tab visible?
1895 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
1900 ui_rows_scrolled_down = 0;
1902 render_mask |= CHANGED_CATEGORY;
1907 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ) {
1908 double scale = 1000000.0;
1909 double scalex = 1000000.0;
1910 double scaley = 1000000.0;
1911 SDL_Surface *scaled;
1913 scalex = (double)maxwidth / (double)s -> w;
1915 if ( maxheight == -1 ) {
1918 scaley = (double)maxheight / (double)s -> h;
1920 if ( scaley < scalex ) {
1928 scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
1929 SDL_FreeSurface ( s );
1935 void ui_loadscreen ( void ) {
1940 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1944 rtext = TTF_RenderText_Blended ( g_big_font, "Setting up menu...", ui_display_context.fontcolor );
1947 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1948 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1949 SDL_FreeSurface ( rtext );
1954 void ui_discoverscreen ( unsigned char clearscreen ) {
1959 if ( clearscreen ) {
1960 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1962 // render background
1963 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1966 dest.w = sdl_realscreen -> w;
1967 dest.h = sdl_realscreen -> h;
1968 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1969 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1976 rtext = TTF_RenderText_Blended ( g_big_font, "Looking for applications...", ui_display_context.fontcolor );
1977 if ( clearscreen ) {
1984 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1985 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1986 SDL_FreeSurface ( rtext );
1989 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1990 dest.x = rtext -> w + 30;
1992 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, &dest );
1993 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1999 void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
2001 SDL_Rect rects [ 4 ];
2002 SDL_Rect *dest = rects;
2004 bzero ( dest, sizeof(SDL_Rect)* 4 );
2006 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
2007 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
2008 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
2009 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
2011 static unsigned int stepx = 0;
2014 if ( clearscreen ) {
2015 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2017 // render background
2018 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2021 dest -> w = sdl_realscreen -> w;
2022 dest -> h = sdl_realscreen -> h;
2023 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
2029 // render background
2030 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2033 src.w = sdl_realscreen -> w;
2037 dest -> w = sdl_realscreen -> w;
2038 dest -> h = sdl_realscreen -> h;
2039 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
2047 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
2048 rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
2051 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2052 SDL_FreeSurface ( rtext );
2056 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
2057 dest -> x = rtext -> w + 30 + stepx;
2059 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, dest );
2065 rtext = TTF_RenderText_Blended ( g_tab_font, filename, tmpfontcolor );
2068 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2069 SDL_FreeSurface ( rtext );
2076 if ( stepx > 350 ) {
2080 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
2085 int ui_selected_index ( void ) {
2087 if ( ! ui_selected ) {
2088 return ( -1 ); // no index
2091 mm_appref_t *r = g_categories [ ui_category ] -> refs;
2094 if ( r == ui_selected ) {
2104 static mm_appref_t *timer_ref = NULL;
2105 void ui_set_selected ( mm_appref_t *r ) {
2107 render_mask |= CHANGED_SELECTION;
2109 if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
2110 return; // no desire to defer anything
2115 SDL_SetTimer ( 0, NULL );
2120 SDL_SetTimer ( pnd_conf_get_as_int_d ( g_conf, "previewpic.defer_timer_ms", 1000 ), ui_callback_f );
2126 unsigned int ui_callback_f ( unsigned int t ) {
2128 if ( ui_selected != timer_ref ) {
2129 return ( 0 ); // user has moved it, who cares
2133 bzero ( &e, sizeof(SDL_Event) );
2134 e.type = SDL_USEREVENT;
2135 e.user.code = sdl_user_ticker;
2136 SDL_PushEvent ( &e );
2141 int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer ) {
2142 SDL_Rect rects [ 40 ];
2143 SDL_Rect *dest = rects;
2146 unsigned char max_visible = pnd_conf_get_as_int_d ( g_conf, "detailtext.max_visible" , 11 );
2147 unsigned char first_visible = 0;
2149 bzero ( rects, sizeof(SDL_Rect) * 40 );
2151 unsigned int sel = 0;
2153 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
2154 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
2155 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
2156 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
2158 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
2160 SDL_Color selfontcolor = { 0/*font_rgba_r*/, font_rgba_g, font_rgba_b, font_rgba_a };
2168 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2169 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2170 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
2171 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
2172 SDL_FillRect( sdl_realscreen, dest, 0 );
2174 // show dialog background
2175 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
2178 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> w;
2179 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> h;
2180 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2181 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2182 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2183 // repeat for darken?
2184 //SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2185 //SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2186 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2190 // show dialog frame
2191 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
2192 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2193 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2194 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
2195 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2201 rtext = TTF_RenderText_Blended ( g_tab_font, title, tmpfontcolor );
2202 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2203 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
2204 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2205 SDL_FreeSurface ( rtext );
2211 rtext = TTF_RenderText_Blended ( g_tab_font, footer, tmpfontcolor );
2212 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2213 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
2214 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
2216 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2217 SDL_FreeSurface ( rtext );
2222 for ( i = first_visible; i < first_visible + max_visible && i < argc; i++ ) {
2226 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
2228 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], tmpfontcolor );
2230 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2231 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 - first_visible ) );
2232 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2233 SDL_FreeSurface ( rtext );
2238 // update all the rects and send it all to sdl
2239 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
2243 while ( SDL_WaitEvent ( &event ) ) {
2245 switch ( event.type ) {
2250 if ( event.key.keysym.sym == SDLK_UP ) {
2254 if ( sel < first_visible ) {
2259 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
2261 if ( sel < argc - 1 ) {
2264 // ensure visibility
2265 if ( sel >= first_visible + max_visible ) {
2271 } else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_END ) { // return, or "B"
2275 } else if ( event.key.keysym.sym == SDLK_q ) {
2280 return ( -1 ); // nada
2295 unsigned char ui_determine_row ( mm_appref_t *a ) {
2296 unsigned int row = 0;
2298 mm_appref_t *i = g_categories [ ui_category ] -> refs;
2303 row /= ui_display_context.col_max;
2308 unsigned char ui_determine_screen_row ( mm_appref_t *a ) {
2309 return ( ui_determine_row ( a ) % ui_display_context.row_max );
2312 unsigned char ui_determine_screen_col ( mm_appref_t *a ) {
2313 unsigned int col = 0;
2315 mm_appref_t *i = g_categories [ ui_category ] -> refs;
2320 col %= ui_display_context.col_max;
2325 unsigned char ui_show_info ( char *pndrun, pnd_disco_t *p ) {
2326 char *viewer, *searchpath;
2327 pnd_conf_handle desktoph;
2330 searchpath = pnd_conf_query_searchpath();
2332 desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
2338 viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
2341 return ( 0 ); // no way to view the file
2345 if ( ! p -> unique_id ) {
2349 if ( ! p -> info_filename ) {
2353 if ( ! p -> info_name ) {
2364 if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) {
2365 snprintf ( pargs, 1001, "%s %s",
2366 pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
2371 char pndfile [ 1024 ];
2372 if ( p -> object_type == pnd_object_type_directory ) {
2373 // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
2374 strncpy ( pndfile, p -> object_path, 1000 );
2375 } else if ( p -> object_type == pnd_object_type_pnd ) {
2376 // pnd_run.sh wants the full path and filename for the .pnd file
2377 snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
2380 if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs,
2381 p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) )
2386 pnd_log ( pndn_debug, "Info Exec=%s\n", pnd_apps_exec_runline() );
2390 if ( ( x = fork() ) < 0 ) {
2391 pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
2396 execl ( "/bin/sh", "/bin/sh", "-c", pnd_apps_exec_runline(), (char*)NULL );
2397 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", pnd_apps_exec_runline() );
2409 #define MAXTOUCH 100
2410 ui_touch_t ui_touchrects [ MAXTOUCH ];
2411 unsigned char ui_touchrect_count = 0;
2413 void ui_register_reset ( void ) {
2414 bzero ( ui_touchrects, sizeof(ui_touch_t)*MAXTOUCH );
2415 ui_touchrect_count = 0;
2419 void ui_register_tab ( unsigned char catnum, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2421 if ( ui_touchrect_count == MAXTOUCH ) {
2425 ui_touchrects [ ui_touchrect_count ].r.x = x;
2426 ui_touchrects [ ui_touchrect_count ].r.y = y;
2427 ui_touchrects [ ui_touchrect_count ].r.w = w;
2428 ui_touchrects [ ui_touchrect_count ].r.h = h;
2429 ui_touchrects [ ui_touchrect_count ].catnum = catnum;
2430 ui_touchrect_count++;
2435 void ui_register_app ( mm_appref_t *app, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2437 if ( ui_touchrect_count == MAXTOUCH ) {
2441 ui_touchrects [ ui_touchrect_count ].r.x = x;
2442 ui_touchrects [ ui_touchrect_count ].r.y = y;
2443 ui_touchrects [ ui_touchrect_count ].r.w = w;
2444 ui_touchrects [ ui_touchrect_count ].r.h = h;
2445 ui_touchrects [ ui_touchrect_count ].ref = app;
2446 ui_touchrect_count++;
2451 void ui_touch_act ( unsigned int x, unsigned int y ) {
2456 for ( i = 0; i < ui_touchrect_count; i++ ) {
2457 t = &(ui_touchrects [ i ]);
2459 if ( x >= t -> r.x &&
2460 x <= t -> r.x + t -> r.w &&
2462 y <= t -> r.y + t -> r.h
2467 ui_selected = t -> ref;
2470 if ( ui_category != t -> catnum ) {
2473 ui_category = t -> catnum;
2474 render_mask |= CHANGED_CATEGORY;
2476 category_fs_restock ( g_categories [ ui_category ] );
2487 unsigned char ui_forkexec ( char *argv[] ) {
2488 char *fooby = argv[0];
2491 if ( ( x = fork() ) < 0 ) {
2492 pnd_log ( pndn_error, "ERROR: Couldn't fork() for '%s'\n", fooby );
2496 if ( x == 0 ) { // child
2497 execv ( fooby, argv );
2498 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", fooby );
2506 unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ) {
2508 if ( ! cache_preview ( p, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
2509 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
2512 pnd_log ( pndn_debug, "THREAD: Couldn't load preview pic: '%s' -> '%s'\n",
2513 IFNULL(p->title_en,"No Name"), p -> preview_pic1 );
2516 // trigger that we completed
2518 bzero ( &e, sizeof(SDL_Event) );
2519 e.type = SDL_USEREVENT;
2520 e.user.code = sdl_user_finishedpreview;
2522 SDL_PushEvent ( &e );
2527 SDL_Thread *g_icon_thread = NULL;
2528 void ui_post_scan ( void ) {
2530 // if deferred icon load, kick off the thread now
2531 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 1 ) {
2533 g_icon_thread = SDL_CreateThread ( (void*)ui_threaded_defered_icon, NULL );
2535 if ( ! g_icon_thread ) {
2536 pnd_log ( pndn_error, "ERROR: Couldn't create icon thread\n" );
2539 } // deferred icon load
2543 ui_rows_scrolled_down = 0;
2544 // set back to first tab, to be safe
2548 // do we have a preferred category to jump to?
2549 char *dc = pnd_conf_get_as_char ( g_conf, "categories.default_cat" );
2552 // attempt to find default cat; if we do find it, select it; otherwise
2553 // default behaviour will pick first cat (ie: usually All)
2555 for ( i = 0; i < g_categorycount; i++ ) {
2556 if ( strcasecmp ( g_categories [ i ] -> catname, dc ) == 0 ) {
2558 // ensure visibility
2559 unsigned int screen_width = ui_display_context.screen_width;
2560 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2561 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
2562 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
2568 if ( i == g_categorycount ) {
2569 pnd_log ( pndn_warning, " User defined default category '%s' but not found, so using default behaviour\n", dc );
2574 // if we're sent right to a dirbrowser tab, restock it now (normally we restock on entry)
2575 if ( g_categories [ ui_category ] -> fspath ) {
2576 printf ( "Restock on start: '%s'\n", g_categories [ ui_category ] -> fspath );
2577 category_fs_restock ( g_categories [ ui_category ] );
2581 render_mask |= CHANGED_EVERYTHING;
2586 unsigned char ui_threaded_defered_icon ( void *p ) {
2587 extern pnd_box_handle g_active_apps;
2588 pnd_box_handle h = g_active_apps;
2590 unsigned char maxwidth, maxheight;
2591 maxwidth = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 );
2592 maxheight = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_height", 50 );
2594 pnd_disco_t *iter = pnd_box_get_head ( h );
2599 if ( iter -> pnd_icon_pos &&
2600 ! cache_icon ( iter, maxwidth, maxheight ) )
2602 pnd_log ( pndn_warning, " Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2605 // trigger that we completed
2607 bzero ( &e, sizeof(SDL_Event) );
2608 e.type = SDL_USEREVENT;
2609 e.user.code = sdl_user_finishedicon;
2610 SDL_PushEvent ( &e );
2612 //pnd_log ( pndn_warning, " Finished deferred load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2613 usleep ( pnd_conf_get_as_int_d ( g_conf, "minimenu.defer_icon_us", 50000 ) );
2618 iter = pnd_box_get_next ( iter );
2624 void ui_show_hourglass ( unsigned char updaterect ) {
2627 SDL_Surface *s = g_imagecache [ IMG_HOURGLASS ].i;
2629 dest.x = ( 800 - s -> w ) / 2;
2630 dest.y = ( 480 - s -> h ) / 2;
2632 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, &dest );
2635 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2641 unsigned char ui_pick_skin ( void ) {
2643 char *skins [ MAXSKINS ];
2646 char *searchpath = pnd_conf_get_as_char ( g_conf, "minimenu.skin_searchpath" );
2647 char tempname [ 100 ];
2651 skins [ iter++ ] = "No skin change";
2655 DIR *d = opendir ( buffer );
2660 while ( ( dd = readdir ( d ) ) ) {
2662 if ( dd -> d_name [ 0 ] == '.' ) {
2664 } else if ( ( dd -> d_type == DT_DIR || dd -> d_type == DT_UNKNOWN ) &&
2667 snprintf ( tempname, 100, "Skin: %s", dd -> d_name );
2668 skins [ iter++ ] = strdup ( tempname );
2679 int sel = ui_modal_single_menu ( skins, iter, "Skins", "Enter to select; other to return." );
2681 // did they pick one?
2685 char *s = strdup ( pnd_conf_get_as_char ( g_conf, "minimenu.skin_selected" ) );
2686 s = pnd_expand_tilde ( s );
2688 f = fopen ( s, "w" );
2693 fprintf ( f, "%s\n", skins [ sel ] + 6 );
2703 void ui_aboutscreen ( char *textpath ) {
2710 #define ROWS SCRH / ( PIXELH + MARGINH )
2711 #define COLS SCRW / ( PIXELW + MARGINW )
2713 unsigned char pixelboard [ ROWS * COLS ]; // pixel heat
2714 bzero ( pixelboard, ROWS * COLS );
2719 SDL_Color rtextc = { 200, 200, 200, 100 };
2722 char *textloop [ 500 ];
2723 unsigned int textmax = 0;
2724 bzero ( textloop, 500 * sizeof(char*) );
2727 char cbuffer [ 50000 ];
2728 bzero ( cbuffer, 50000 );
2729 unsigned int crevealed = 0;
2731 FILE *f = fopen ( textpath, "r" );
2734 pnd_log ( pndn_error, "ERROR: Couldn't open about text: %s\n", textpath );
2738 char textbuf [ 100 ];
2739 while ( fgets ( textbuf, 100, f ) ) {
2741 // add to full buffer
2742 strncat ( cbuffer, textbuf, 50000 );
2745 if ( strchr ( textbuf, '\n' ) ) {
2746 * strchr ( textbuf, '\n' ) = '\0';
2749 // add to pixel loop
2750 if ( 1||textbuf [ 0 ] ) {
2751 textloop [ textmax ] = strdup ( textbuf );
2759 unsigned int textiter = 0;
2760 while ( textiter < textmax ) {
2761 char *text = textloop [ textiter ];
2765 // render to surface
2766 rtext = TTF_RenderText_Blended ( g_grid_font, text, rtextc );
2768 // render font to pixelboard
2769 unsigned int px, py;
2771 unsigned int *pixels = rtext -> pixels;
2772 unsigned char cr, cg, cb, ca;
2773 for ( py = 0; py < rtext -> h; py ++ ) {
2774 for ( px = 0; px < ( rtext -> w > COLS ? COLS : rtext -> w ); px++ ) {
2776 SDL_GetRGBA ( pixels [ ( py * rtext -> pitch / 4 ) + px ],
2777 rtext -> format, &cr, &cg, &cb, &ca );
2781 ph = pixelboard + ( /*y offset */ 30 * COLS ) + ( py * COLS ) + px /* / 2 */;
2788 if ( *ph + ca < 250 ) {
2799 unsigned int runcount = 10;
2800 while ( runcount-- ) {
2803 SDL_FillRect( sdl_realscreen, NULL /* whole */, 0 );
2805 // render pixelboard
2808 for ( y = 0; y < ROWS; y++ ) {
2809 for ( x = 0; x < COLS; x++ ) {
2811 if ( 1||pixelboard [ ( y * COLS ) + x ] ) {
2814 r.x = x * ( PIXELW + MARGINW );
2815 r.y = y * ( PIXELH + MARGINH );
2819 c = SDL_MapRGB ( sdl_realscreen -> format, 100 /* r */, 0 /* g */, pixelboard [ ( y * COLS ) + x ] );
2821 SDL_FillRect( sdl_realscreen, &r /* whole */, c );
2829 unsigned char *pc = pixelboard;
2830 for ( y = 0; y < ROWS; y++ ) {
2831 for ( x = 0; x < COLS; x++ ) {
2841 // slide pixels upwards
2842 memmove ( pixelboard, pixelboard + COLS, ( COLS * ROWS ) - COLS );
2844 // render actual readable text
2847 // display up to cursor
2849 unsigned int cdraw = 0;
2853 if ( crevealed > 200 ) {
2854 cdraw = crevealed - 200;
2860 for ( ; cdraw < crevealed; cdraw++ ) {
2861 ctb [ 0 ] = cbuffer [ cdraw ];
2863 // move over or down
2864 if ( cbuffer [ cdraw ] == '\n' ) {
2869 if ( dest.y > 450 ) {
2875 cs = TTF_RenderText_Blended ( g_tab_font, ctb, rtextc );
2877 SDL_BlitSurface ( cs, NULL /* all */, sdl_realscreen, &dest );
2878 SDL_FreeSurface ( cs );
2888 SDL_FillRect ( sdl_realscreen, &dest /* whole */, 220 );
2890 // increment cursor to next character
2891 if ( cbuffer [ crevealed ] != '\0' ) {
2895 } // draw cursor text
2899 SDL_UpdateRect ( sdl_realscreen, 0, 0, 0, 0 ); // whole screen
2903 // any button? if so, about
2909 if ( SDL_PeepEvents ( &e, 1, SDL_GETEVENT, SDL_EVENTMASK(/*SDL_KEYUP|*/SDL_KEYDOWN) ) > 0 ) {
2918 SDL_FreeSurface ( rtext );
2922 } // while more text
2926 for ( i = 0; i < textmax; i++ ) {
2927 if ( textloop [ i ] ) {
2928 free ( textloop [ i ] );
2936 void ui_revealscreen ( void ) {
2937 char *labels [ 500 ];
2938 unsigned int labelmax = 0;
2941 if ( ! category_count ( CFHIDDEN ) ) {
2942 return; // nothing to do
2945 // switch to hidden categories
2946 category_publish ( CFHIDDEN, NULL );
2948 // build up labels to show in menu
2949 for ( i = 0; i < g_categorycount; i++ ) {
2950 labels [ labelmax++ ] = g_categories [ i ] -> catname;
2954 int sel = ui_modal_single_menu ( labels, labelmax, "Temporary Category Reveal",
2955 "Enter to select; other to return." );
2957 // if selected, try to set this guy to visible
2960 // fix up category name, if its been hacked
2961 if ( strchr ( g_categories [ sel ] -> catname, '.' ) ) {
2962 char *t = g_categories [ sel ] -> catname;
2963 g_categories [ sel ] -> catname = strdup ( strchr ( g_categories [ sel ] -> catname, '.' ) + 1 );
2967 // reflag this guy to be visible
2968 g_categories [ sel ] -> catflags = CFNORMAL;
2970 // switch to the new category.. cache name.
2971 char *switch_to_name = g_categories [ sel ] -> catname;
2973 // republish categories
2974 category_publish ( CFNORMAL, NULL );
2976 // switch to the new category.. with the cached name!
2977 ui_category = category_index ( switch_to_name );
2979 // ensure visibility
2980 unsigned int screen_width = ui_display_context.screen_width;
2981 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2982 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
2983 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
2987 render_mask |= CHANGED_CATEGORY;
2993 void ui_recache_context ( ui_context_t *c ) {
2995 c -> screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
2997 c -> font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
2998 c -> font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
2999 c -> font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
3000 c -> font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
3002 c -> grid_offset_x = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_x" );
3003 c -> grid_offset_y = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_y" );
3005 c -> icon_offset_x = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_x" );
3006 c -> icon_offset_y = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_y" );
3007 c -> icon_max_width = pnd_conf_get_as_int ( g_conf, "grid.icon_max_width" );
3008 c -> icon_max_height = pnd_conf_get_as_int ( g_conf, "grid.icon_max_height" );
3009 c -> sel_icon_offset_x = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_x", 0 );
3010 c -> sel_icon_offset_y = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_y", 0 );
3012 c -> text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
3013 c -> text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
3014 c -> text_offset_x = pnd_conf_get_as_int ( g_conf, "grid.text_offset_x" );
3015 c -> text_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_offset_y" );
3016 c -> text_hilite_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
3018 c -> row_max = pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 4 );
3019 c -> col_max = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
3021 c -> cell_width = pnd_conf_get_as_int ( g_conf, "grid.cell_width" );
3022 c -> cell_height = pnd_conf_get_as_int ( g_conf, "grid.cell_height" );
3024 c -> arrow_bar_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
3025 c -> arrow_bar_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
3026 c -> arrow_bar_clip_w = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_w", 10 );
3027 c -> arrow_bar_clip_h = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_h", 100 );
3028 c -> arrow_up_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
3029 c -> arrow_up_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
3030 c -> arrow_down_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
3031 c -> arrow_down_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
3034 SDL_Color tmp = { c -> font_rgba_r, c -> font_rgba_g, c -> font_rgba_b, c -> font_rgba_a };
3035 c -> fontcolor = tmp;
3037 // now that we've got 'normal' (detail pane shown) param's, lets check if detail pane
3038 // is hidden; if so, override some values with those alternate skin values where possible.
3039 if ( ui_detail_hidden ) {
3040 // if detail panel is hidden, and theme cannot support it, unhide the bloody thing. (This may help
3041 // when someone is amid theme hacking or changing.)
3042 if ( ! ui_is_detail_hideable() ) {
3043 ui_detail_hidden = 0;
3047 if ( ui_detail_hidden ) {
3049 c -> row_max = pnd_conf_get_as_int_d ( g_conf, "grid.row_max_w", c -> row_max );
3050 c -> col_max = pnd_conf_get_as_int_d ( g_conf, "grid.col_max_w", c -> col_max );
3052 c -> cell_width = pnd_conf_get_as_int_d ( g_conf, "grid.cell_width_w", c -> cell_width );
3053 c -> cell_height = pnd_conf_get_as_int_d ( g_conf, "grid.cell_height_w", c -> cell_height );
3055 c -> arrow_bar_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x_w", 450 );
3056 c -> arrow_bar_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y_w", 100 );
3057 c -> arrow_up_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x_w", 450 );
3058 c -> arrow_up_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y_w", 80 );
3059 c -> arrow_down_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x_w", 450 );
3060 c -> arrow_down_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y_w", 80 );
3062 } // if detail hidden.. still.
3064 } // if detail hidden
3069 unsigned char ui_is_detail_hideable ( void ) {
3071 // if skin has a bit of info for wide-mode, we assume wide-mode is available
3072 if ( pnd_conf_get_as_char ( g_conf, "grid.row_max_w" ) != NULL ) {
3080 void ui_toggle_detail_pane ( void ) {
3082 // no bitmask trickery here; I like it to be stand-out obvious at 3am.
3084 if ( ui_detail_hidden ) {
3085 ui_detail_hidden = 0;
3087 ui_detail_hidden = 1;
3090 // repull skin config
3091 ui_recache_context ( &ui_display_context );
3094 render_mask |= CHANGED_EVERYTHING;