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"
39 #define CHANGED_NOTHING (0)
40 #define CHANGED_CATEGORY (1<<0) /* changed to different category */
41 #define CHANGED_SELECTION (1<<1) /* changed app selection */
42 #define CHANGED_DATAUPDATE (1<<2) /* deferred preview pic or icon came in */
43 #define CHANGED_APPRELOAD (1<<3) /* new set of applications entirely */
44 #define CHANGED_EVERYTHING (1<<4) /* redraw it all! */
45 unsigned int render_mask = CHANGED_EVERYTHING;
49 SDL_Surface *sdl_realscreen = NULL;
50 unsigned int sdl_ticks = 0;
51 SDL_Thread *g_preview_thread = NULL;
53 enum { sdl_user_ticker = 0,
54 sdl_user_finishedpreview = 1,
55 sdl_user_finishedicon = 2,
60 unsigned short int g_scale = 1; // 1 == noscale
62 SDL_Surface *g_imgcache [ IMG_MAX ];
64 TTF_Font *g_big_font = NULL;
65 TTF_Font *g_grid_font = NULL;
66 TTF_Font *g_detailtext_font = NULL;
67 TTF_Font *g_tab_font = NULL;
69 extern pnd_conf_handle g_conf;
71 /* current display state
73 int ui_rows_scrolled_down = 0; // number of rows that should be missing from top of the display
74 mm_appref_t *ui_selected = NULL;
75 unsigned char ui_category = 0; // current category
76 unsigned char ui_catshift = 0; // how many cats are offscreen to the left
78 extern mm_category_t *g_categories;
79 extern unsigned char g_categorycount;
80 extern mm_category_t _categories_invis [ MAX_CATS ];
81 extern unsigned char _categories_inviscount;
83 static SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ); // height -1 means ignore
84 static int ui_selected_index ( void );
86 unsigned char ui_setup ( void ) {
91 SDL_Init ( SDL_INIT_EVERYTHING | SDL_INIT_NOPARACHUTE );
93 SDL_JoystickOpen ( 0 ); // turn on joy-0
95 SDL_WM_SetCaption ( "mmenu", "mmenu" );
97 // hide the mouse cursor if we can
98 if ( SDL_ShowCursor ( -1 ) == 1 ) {
105 unsigned int svm = SDL_SWSURFACE /*| SDL_FULLSCREEN*/ /* 0*/;
106 if ( pnd_conf_get_as_int_d ( g_conf, "display.fullscreen", 0 ) > 0 ) {
107 svm |= SDL_FULLSCREEN;
111 SDL_SetVideoMode ( 800 * g_scale, 480 * g_scale, 16 /*bpp*/, svm );
113 if ( ! sdl_realscreen ) {
114 pnd_log ( pndn_error, "ERROR: Couldn't open SDL real screen; dieing." );
118 pnd_log ( pndn_debug, "Pixel format:" );
119 pnd_log ( pndn_debug, "bpp b: %u\n", sdl_realscreen -> format -> BitsPerPixel );
120 pnd_log ( pndn_debug, "bpp B: %u\n", sdl_realscreen -> format -> BytesPerPixel );
121 pnd_log ( pndn_debug, "R mask: %08x\n", sdl_realscreen -> format -> Rmask );
122 pnd_log ( pndn_debug, "G mask: %08x\n", sdl_realscreen -> format -> Gmask );
123 pnd_log ( pndn_debug, "B mask: %08x\n", sdl_realscreen -> format -> Bmask );
129 /* Set 16-bit stereo audio at 22Khz */
130 fmt.freq = 44100; //22050;
131 fmt.format = AUDIO_S16; //AUDIO_S16;
133 fmt.samples = 2048; /* A good value for games */
134 fmt.callback = mixaudio;
137 /* Open the audio device and start playing sound! */
138 if ( SDL_OpenAudio ( &fmt, NULL ) < 0 ) {
139 zotlog ( "Unable to open audio: %s\n", SDL_GetError() );
143 SDL_PauseAudio ( 0 );
148 SDL_EnableKeyRepeat ( 500, 150 );
151 //IMG_Init ( IMG_INIT_JPG | IMG_INIT_PNG );
157 if ( TTF_Init() == -1 ) {
158 pnd_log ( pndn_error, "ERROR: Couldn't set up SDL TTF lib\n" );
159 return ( 0 ); // couldn't set up SDL TTF
162 char fullpath [ PATH_MAX ];
164 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "minimenu.font" ) );
165 g_big_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
166 if ( ! g_big_font ) {
167 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
168 pnd_conf_get_as_char ( g_conf, "minimenu.font" ), pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
169 return ( 0 ); // couldn't set up SDL TTF
173 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "grid.font" ) );
174 g_grid_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
175 if ( ! g_grid_font ) {
176 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
177 pnd_conf_get_as_char ( g_conf, "grid.font" ), pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
178 return ( 0 ); // couldn't set up SDL TTF
182 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "detailtext.font" ) );
183 g_detailtext_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
184 if ( ! g_detailtext_font ) {
185 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
186 pnd_conf_get_as_char ( g_conf, "detailtext.font" ), pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
187 return ( 0 ); // couldn't set up SDL TTF
191 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "tabs.font" ) );
192 g_tab_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
193 if ( ! g_tab_font ) {
194 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
195 pnd_conf_get_as_char ( g_conf, "tabs.font" ), pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
196 return ( 0 ); // couldn't set up SDL TTF
202 mm_imgcache_t g_imagecache [ IMG_TRUEMAX ] = {
203 { IMG_BACKGROUND_800480, "graphics.IMG_BACKGROUND_800480" },
204 { IMG_BACKGROUND_TABMASK, "graphics.IMG_BACKGROUND_TABMASK" },
205 { IMG_DETAIL_PANEL, "graphics.IMG_DETAIL_PANEL" },
206 { IMG_DETAIL_BG, "graphics.IMG_DETAIL_BG" },
207 { IMG_SELECTED_ALPHAMASK, "graphics.IMG_SELECTED_ALPHAMASK" },
208 { IMG_TAB_SEL, "graphics.IMG_TAB_SEL" },
209 { IMG_TAB_SEL_L, "graphics.IMG_TAB_SEL_L" },
210 { IMG_TAB_SEL_R, "graphics.IMG_TAB_SEL_R" },
211 { IMG_TAB_UNSEL, "graphics.IMG_TAB_UNSEL" },
212 { IMG_TAB_UNSEL_L, "graphics.IMG_TAB_UNSEL_L" },
213 { IMG_TAB_UNSEL_R, "graphics.IMG_TAB_UNSEL_R" },
214 { IMG_TAB_LINE, "graphics.IMG_TAB_LINE" },
215 { IMG_TAB_LINEL, "graphics.IMG_TAB_LINEL" },
216 { IMG_TAB_LINER, "graphics.IMG_TAB_LINER" },
217 { IMG_ICON_MISSING, "graphics.IMG_ICON_MISSING" },
218 { IMG_SELECTED_HILITE, "graphics.IMG_SELECTED_HILITE" },
219 { IMG_PREVIEW_MISSING, "graphics.IMG_PREVIEW_MISSING" },
220 { IMG_ARROW_UP, "graphics.IMG_ARROW_UP", },
221 { IMG_ARROW_DOWN, "graphics.IMG_ARROW_DOWN", },
222 { IMG_ARROW_SCROLLBAR, "graphics.IMG_ARROW_SCROLLBAR", },
223 { IMG_HOURGLASS, "graphics.IMG_HOURGLASS", },
224 { IMG_FOLDER, "graphics.IMG_FOLDER", },
225 { IMG_EXECBIN, "graphics.IMG_EXECBIN", },
229 unsigned char ui_imagecache ( char *basepath ) {
231 char fullpath [ PATH_MAX ];
235 for ( i = 0; i < IMG_MAX; i++ ) {
237 if ( g_imagecache [ i ].id != i ) {
238 pnd_log ( pndn_error, "ERROR: Internal table mismatch during caching [%u]\n", i );
242 char *filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].confname );
245 pnd_log ( pndn_error, "ERROR: Missing filename in conf for key: %s\n", g_imagecache [ i ].confname );
249 if ( filename [ 0 ] == '/' ) {
250 strncpy ( fullpath, filename, PATH_MAX );
252 sprintf ( fullpath, "%s/%s", basepath, filename );
255 if ( ! ( g_imagecache [ i ].i = IMG_Load ( fullpath ) ) ) {
256 pnd_log ( pndn_error, "ERROR: Couldn't load static cache image: %s\n", fullpath );
263 //g_imagecache [ IMG_SELECTED_ALPHAMASK ].i = SDL_CreateRGBSurface ( SDL_SWSURFACE, 60, 60, 32, 0xFF0000, 0x00FF00, 0xFF, 0xFF000000 );
264 //boxRGBA ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, 0, 0, 60, 60, 100, 100, 100, 250 );
270 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 );
271 // scale text hilight
272 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 );
273 // scale preview no-pic
274 g_imagecache [ IMG_PREVIEW_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_PREVIEW_MISSING ].i,
275 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ),
276 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 50 ) );
278 // set alpha on detail panel
279 //SDL_SetAlpha ( g_imagecache [ IMG_DETAIL_BG ].i, SDL_SRCALPHA, pnd_conf_get_as_int_d ( g_conf, "display.detail_bg_alpha", 50 ) );
284 void ui_render ( void ) {
287 // divide width: 550 / 250
288 // divide left side: 5 columns == 110px width
289 // 20px buffer either side == 70px wide icon + 20 + 20?
291 // what jobs to do during render?
295 #define R_TABS (1<<1)
296 #define R_DETAIL (1<<2)
297 #define R_GRID (1<<3)
299 #define R_ALL (R_BG|R_TABS|R_DETAIL|R_GRID)
301 unsigned int render_jobs_b = 0;
303 if ( render_mask & CHANGED_EVERYTHING ) {
304 render_jobs_b |= R_ALL;
307 if ( render_mask & CHANGED_SELECTION ) {
308 render_jobs_b |= R_GRID;
309 render_jobs_b |= R_DETAIL;
312 if ( render_mask & CHANGED_CATEGORY ) {
313 render_jobs_b |= R_ALL;
316 render_mask = CHANGED_NOTHING;
320 unsigned int icon_rows;
323 SDL_Rect rects [ MAXRECTS ], src;
324 SDL_Rect *dest = rects;
325 bzero ( dest, sizeof(SDL_Rect)*MAXRECTS );
327 unsigned int row, displayrow, col;
328 mm_appref_t *appiter;
330 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
332 unsigned char row_max = pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 4 );
333 unsigned char col_max = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
335 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
336 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
337 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
338 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
340 unsigned int grid_offset_x = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_x" );
341 unsigned int grid_offset_y = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_y" );
343 unsigned int icon_offset_x = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_x" );
344 unsigned int icon_offset_y = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_y" );
345 unsigned int icon_max_width = pnd_conf_get_as_int ( g_conf, "grid.icon_max_width" );
346 unsigned int icon_max_height = pnd_conf_get_as_int ( g_conf, "grid.icon_max_height" );
347 unsigned int sel_icon_offset_x = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_x", 0 );
348 unsigned int sel_icon_offset_y = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_y", 0 );
350 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
351 unsigned int text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
352 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "grid.text_offset_x" );
353 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_offset_y" );
355 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "grid.cell_width" );
356 unsigned int cell_height = pnd_conf_get_as_int ( g_conf, "grid.cell_height" );
358 // how many total rows do we need?
359 icon_rows = g_categories [ ui_category ].refcount / col_max;
360 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
365 // if no selected app yet, select the first one
366 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.start_selected", 0 ) && ! ui_selected ) {
367 ui_selected = g_categories [ ui_category ].refs;
371 // reset touchscreen regions
372 if ( render_jobs_b ) {
376 // ensure selection is visible
379 int index = ui_selected_index();
380 int topleft = col_max * ui_rows_scrolled_down;
381 int botright = ( col_max * ( ui_rows_scrolled_down + row_max ) - 1 );
383 if ( index < topleft ) {
384 ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
385 render_jobs_b |= R_ALL;
386 } else if ( index > botright ) {
387 ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
388 render_jobs_b |= R_ALL;
391 if ( ui_rows_scrolled_down < 0 ) {
392 ui_rows_scrolled_down = 0;
393 } else if ( ui_rows_scrolled_down > icon_rows ) {
394 ui_rows_scrolled_down = icon_rows;
400 if ( render_jobs_b & R_BG ) {
402 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
405 dest -> w = sdl_realscreen -> w;
406 dest -> h = sdl_realscreen -> h;
407 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
412 if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
415 dest -> w = sdl_realscreen -> w;
416 dest -> h = sdl_realscreen -> h;
417 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
424 if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
425 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
426 unsigned int tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
427 //unsigned int tab_selheight = pnd_conf_get_as_int ( g_conf, "tabs.tab_selheight" );
428 unsigned int tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
429 unsigned int tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
430 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
431 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
432 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
433 unsigned int maxtab = ( screen_width / tab_width ) < g_categorycount ? ( screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift;
434 unsigned int maxtabspot = ( screen_width / tab_width );
436 if ( g_categorycount > 0 ) {
438 // draw tabs with categories
439 for ( col = ui_catshift;
446 // if this is the first (leftmost) tab, we use different artwork
447 // than if the other tabs (so skinner can link lines up nicely.)
448 if ( col == ui_catshift ) {
449 // leftmost tab, special case
451 if ( col == ui_category ) {
452 s = g_imagecache [ IMG_TAB_SEL_L ].i;
454 s = g_imagecache [ IMG_TAB_UNSEL_L ].i;
457 } else if ( col == maxtab - 1 ) {
458 // rightmost tab, special case
460 if ( col == ui_category ) {
461 s = g_imagecache [ IMG_TAB_SEL_R ].i;
463 s = g_imagecache [ IMG_TAB_UNSEL_R ].i;
467 // normal (not leftmost) tab
469 if ( col == ui_category ) {
470 s = g_imagecache [ IMG_TAB_SEL ].i;
472 s = g_imagecache [ IMG_TAB_UNSEL ].i;
475 } // first col, or not first col?
482 if ( col == ui_category ) {
483 src.h = tab_selheight;
491 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
492 dest -> y = tab_offset_y;
495 ui_register_tab ( col, dest -> x, dest -> y, tab_width, tab_height );
497 if ( render_jobs_b & R_TABS ) {
498 //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
499 SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
503 if ( col == ui_category ) {
504 // no line for selected tab
506 if ( col - ui_catshift == 0 ) {
507 s = g_imagecache [ IMG_TAB_LINEL ].i;
508 } else if ( col - ui_catshift == maxtabspot - 1 ) {
509 s = g_imagecache [ IMG_TAB_LINER ].i;
511 s = g_imagecache [ IMG_TAB_LINE ].i;
513 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
514 dest -> y = tab_offset_y + tab_height;
515 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
521 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
522 rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ].catname, tmpfontcolor );
525 src.w = rtext -> w < text_width ? rtext -> w : text_width;
527 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
528 dest -> y = tab_offset_y + text_offset_y;
529 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
530 SDL_FreeSurface ( rtext );
537 } // if we got categories
539 if ( render_jobs_b & R_TABS ) {
541 // draw tab lines under where tabs would be if we had categories
542 for ( /* foo */; col < maxtabspot; col++ ) {
545 if ( col - ui_catshift == 0 ) {
546 s = g_imagecache [ IMG_TAB_LINEL ].i;
547 } else if ( col - ui_catshift == maxtabspot - 1 ) {
548 s = g_imagecache [ IMG_TAB_LINER ].i;
550 s = g_imagecache [ IMG_TAB_LINE ].i;
552 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
553 dest -> y = tab_offset_y + tab_height;
554 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
563 // scroll bars and arrows
564 if ( render_jobs_b & R_BG ) {
565 unsigned char show_bar = 0;
568 if ( ui_rows_scrolled_down && g_imagecache [ IMG_ARROW_UP ].i ) {
569 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
570 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
571 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
578 if ( ui_rows_scrolled_down + row_max < icon_rows && g_imagecache [ IMG_ARROW_DOWN ].i ) {
579 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
580 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
581 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
588 // show scrollbar as well
591 src.w = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_w", 10 );
592 src.h = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_h", 100 );
593 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
594 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
595 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
599 } // r_bg, scroll bars
601 // render detail pane bg
602 if ( render_jobs_b & R_DETAIL ) {
604 if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
607 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
608 src.x = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
609 src.y = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
610 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
611 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
612 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
613 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
614 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
618 // render detail pane
619 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
620 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
621 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
622 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
626 } // detailpane frame/bg
630 // anything to render?
631 if ( render_jobs_b & R_GRID ) {
633 // if just rendering grid, and nothing else, better clear it first
634 if ( ! ( render_jobs_b & R_BG ) ) {
635 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
636 src.x = grid_offset_x;
637 src.y = grid_offset_y + sel_icon_offset_y;
638 src.w = col_max * cell_width;
639 src.h = row_max * cell_height;
641 dest -> x = grid_offset_x;
642 dest -> y = grid_offset_y + sel_icon_offset_y;
644 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
650 if ( g_categories [ ui_category ].refs ) {
652 appiter = g_categories [ ui_category ].refs;
656 // until we run out of apps, or run out of space
657 while ( appiter != NULL ) {
659 for ( col = 0; col < col_max && appiter != NULL; col++ ) {
661 // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
662 if ( row >= ui_rows_scrolled_down ) {
664 // selected? show hilights
665 if ( appiter == ui_selected ) {
666 SDL_Surface *s = g_imagecache [ IMG_SELECTED_ALPHAMASK ].i;
668 //dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + ( ( icon_max_width - s -> w ) / 2 );
669 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + sel_icon_offset_x;
670 //dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + ( ( icon_max_height - s -> h ) / 2 );
671 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + sel_icon_offset_y;
672 SDL_BlitSurface ( s, NULL /* all */, sdl_realscreen, dest );
675 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
676 dest -> y = grid_offset_y + ( displayrow * cell_height ) + pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
677 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
682 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
683 SDL_Surface *iconsurface;
685 iconsurface = ic -> i;
687 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
689 // no icon override; was this a pnd-file (show the unknown icon then), or was this generated from
690 // filesystem (file or directory icon)
691 if ( appiter -> ref -> object_flags & PND_DISCO_GENERATED ) {
692 if ( appiter -> ref -> object_type == pnd_object_type_directory ) {
693 iconsurface = g_imagecache [ IMG_FOLDER ].i;
695 iconsurface = g_imagecache [ IMG_EXECBIN ].i;
698 iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
703 // got an icon I hope?
705 //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
711 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + (( icon_max_width - iconsurface -> w ) / 2);
712 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + (( icon_max_height - iconsurface -> h ) / 2);
714 SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
717 ui_register_app ( appiter, dest -> x, dest -> y, src.w, src.h );
724 if ( appiter -> ref -> title_en ) {
726 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
727 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, tmpfontcolor );
730 src.w = text_width < rtext -> w ? text_width : rtext -> w;
732 if ( rtext -> w > text_width ) {
733 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
735 dest -> x = grid_offset_x + ( col * cell_width ) + text_offset_x - ( rtext -> w / 2 );
737 dest -> y = grid_offset_y + ( displayrow * cell_height ) + text_offset_y;
738 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
739 SDL_FreeSurface ( rtext );
743 } // display now? or scrolled away..
746 appiter = appiter -> next;
748 } // for column 1...X
750 if ( row >= ui_rows_scrolled_down ) {
756 // are we done displaying rows?
757 if ( displayrow >= row_max ) {
764 // no apps to render?
765 pnd_log ( pndn_rem, "No applications to render?\n" );
770 // detail panel - show app details or blank-message
771 if ( render_jobs_b & R_DETAIL ) {
773 unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
774 unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
775 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "detailtext.cell_width" );
777 unsigned int desty = cell_offset_y;
784 if ( ui_selected -> ref -> title_en ) {
786 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
787 rtext = TTF_RenderText_Blended ( g_detailtext_font, ui_selected -> ref -> title_en, tmpfontcolor );
790 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
792 dest -> x = cell_offset_x;
794 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
795 SDL_FreeSurface ( rtext );
802 if ( ui_selected -> ref -> main_category ) {
804 sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
807 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
808 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
811 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
813 dest -> x = cell_offset_x;
815 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
816 SDL_FreeSurface ( rtext );
823 if ( ui_selected -> ref -> clockspeed ) {
825 sprintf ( buffer, "CPU Clock: %s", ui_selected -> ref -> clockspeed );
828 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
829 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
832 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
834 dest -> x = cell_offset_x;
836 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
837 SDL_FreeSurface ( rtext );
842 // show sub-app# on right side of cpu clock?
843 //if ( ui_selected -> ref -> subapp_number )
845 sprintf ( buffer, "(app#%u)", ui_selected -> ref -> subapp_number );
848 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
849 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
850 dest -> x = cell_offset_x + cell_width - rtext -> w;
851 dest -> y = desty - src.h;
852 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
853 SDL_FreeSurface ( rtext );
858 #if 0 // merged into hint-line
859 if ( ui_selected -> ref -> info_filename ) {
861 sprintf ( buffer, "Documentation - hit Y" );
864 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
865 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
868 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
870 dest -> x = cell_offset_x;
872 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
873 SDL_FreeSurface ( rtext );
880 if ( ui_selected -> ovrh ) {
885 desty += 5; // a touch of spacing can't hurt
887 for ( i = 1; i < 4; i++ ) {
888 sprintf ( buffer, "Application-%u.note-%u", ui_selected -> ref -> subapp_number, i );
889 n = pnd_conf_get_as_char ( ui_selected -> ovrh, buffer );
893 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
894 rtext = TTF_RenderText_Blended ( g_detailtext_font, n, tmpfontcolor );
897 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
899 dest -> x = cell_offset_x;
901 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
902 SDL_FreeSurface ( rtext );
908 } // r_detail -> notes
911 mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
912 SDL_Surface *previewpic;
915 previewpic = ic -> i;
917 previewpic = g_imagecache [ IMG_PREVIEW_MISSING ].i;
921 dest -> x = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_x", 50 ) +
922 ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
923 dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
924 SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
930 char *empty_message = "Press SELECT for menu";
933 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
935 rtext = TTF_RenderText_Blended ( g_detailtext_font, empty_message, tmpfontcolor );
939 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
941 dest -> x = cell_offset_x;
943 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
944 SDL_FreeSurface ( rtext );
949 } // r_detail && selected?
957 if ( render_jobs_b & R_BG ) {
958 static int last_battlevel = 0;
959 static unsigned char batterylevel = 0;
962 if ( time ( NULL ) - last_battlevel > 60 ) {
963 batterylevel = pnd_device_get_battery_gauge_perc();
964 last_battlevel = time ( NULL );
967 sprintf ( buffer, "Battery: %u%%", batterylevel );
970 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
971 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
972 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.battery_x", 20 );
973 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.battery_y", 450 );
974 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
975 SDL_FreeSurface ( rtext );
980 if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
982 unsigned int hintx, hinty;
983 hintx = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
984 hinty = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
985 static unsigned int lastwidth = 3000;
987 if ( ui_selected && ui_selected -> ref -> info_filename ) {
988 buffer = "Documentation - hit Y";
990 buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
994 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
995 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
998 if ( ! ( render_jobs_b & R_BG ) ) {
1005 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, &src, sdl_realscreen, dest );
1007 lastwidth = rtext -> w;
1013 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1014 SDL_FreeSurface ( rtext );
1019 if ( render_jobs_b & R_BG &&
1020 pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 )
1024 time_t t = time ( NULL );
1025 struct tm *tm = localtime ( &t );
1026 strftime ( buffer, 50, "%a %H:%M %F", tm );
1029 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1030 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
1031 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.clock_x", 700 );
1032 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.clock_y", 450 );
1033 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1034 SDL_FreeSurface ( rtext );
1038 // update all the rects and send it all to sdl
1039 // - at this point, we could probably just do 1 rect, of the
1040 // whole screen, and be faster :/
1041 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1045 void ui_process_input ( unsigned char block_p ) {
1048 unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
1049 //static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
1051 while ( ! ui_event &&
1052 block_p ? SDL_WaitEvent ( &event ) : SDL_PollEvent ( &event ) )
1055 switch ( event.type ) {
1060 if ( event.user.code == sdl_user_ticker ) {
1062 // timer went off, time to load something
1063 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1065 // load the preview pics now!
1066 pnd_disco_t *iter = ui_selected -> ref;
1068 if ( iter -> preview_pic1 ) {
1070 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.threaded_preview", 0 ) ) {
1071 // load in bg thread, make user experience chuggy
1073 g_preview_thread = SDL_CreateThread ( (void*)ui_threaded_defered_preview, iter );
1075 if ( ! g_preview_thread ) {
1076 pnd_log ( pndn_error, "ERROR: Couldn't create preview thread\n" );
1080 // load it now, make user wait
1082 if ( ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
1083 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
1086 pnd_log ( pndn_debug, " Couldn't load preview pic: '%s' -> '%s'\n",
1087 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1092 } // got a preview at all?
1097 } else if ( event.user.code == sdl_user_finishedpreview ) {
1099 // if we just finished the one we happen to be looking at, better redraw now; otherwise, if
1100 // we finished another, no big woop
1101 if ( ui_selected && event.user.data1 == ui_selected -> ref ) {
1105 } else if ( event.user.code == sdl_user_finishedicon ) {
1106 // redraw, so we can show the newly loaded icon
1111 render_mask |= CHANGED_EVERYTHING;
1115 #if 0 // joystick motion
1116 case SDL_JOYAXISMOTION:
1118 pnd_log ( PND_LOG_DEFAULT, "joystick axis\n" );
1120 if ( event.jaxis.axis == 0 ) {
1122 if ( event.jaxis.value < 0 ) {
1124 pnd_log ( PND_LOG_DEFAULT, "joystick axis - LEFT\n" );
1125 } else if ( event.jaxis.value > 0 ) {
1126 ui_push_right ( 0 );
1127 pnd_log ( PND_LOG_DEFAULT, "joystick axis - RIGHT\n" );
1129 } else if ( event.jaxis.axis == 1 ) {
1131 if ( event.jaxis.value < 0 ) {
1133 } else if ( event.jaxis.value > 0 ) {
1143 #if 0 // joystick buttons
1144 case SDL_JOYBUTTONDOWN:
1146 pnd_log ( PND_LOG_DEFAULT, "joystick button down %u\n", event.jbutton.button );
1148 if ( event.jbutton.button == 0 ) { // B
1150 } else if ( event.jbutton.button == 1 ) { // Y
1152 } else if ( event.jbutton.button == 2 ) { // X
1154 } else if ( event.jbutton.button == 3 ) { // A
1157 } else if ( event.jbutton.button == 4 ) { // Select
1158 ui_mask |= uisb_select;
1159 } else if ( event.jbutton.button == 5 ) { // Start
1160 ui_mask |= uisb_start;
1162 } else if ( event.jbutton.button == 7 ) { // L
1164 } else if ( event.jbutton.button == 8 ) { // R
1173 case SDL_JOYBUTTONUP:
1175 pnd_log ( PND_LOG_DEFAULT, "joystick button up %u\n", event.jbutton.button );
1177 if ( event.jbutton.button == 0 ) { // B
1180 } else if ( event.jbutton.button == 1 ) { // Y
1182 } else if ( event.jbutton.button == 2 ) { // X
1184 } else if ( event.jbutton.button == 3 ) { // A
1187 } else if ( event.jbutton.button == 4 ) { // Select
1188 ui_mask &= ~uisb_select;
1189 } else if ( event.jbutton.button == 5 ) { // Start
1190 ui_mask &= ~uisb_start;
1192 } else if ( event.jbutton.button == 7 ) { // L
1195 } else if ( event.jbutton.button == 8 ) { // R
1206 #if 1 // keyboard events
1210 //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
1212 // SDLK_LALT -> Start
1215 if ( event.key.keysym.sym == SDLK_RIGHT ) {
1216 ui_push_right ( 0 );
1218 } else if ( event.key.keysym.sym == SDLK_LEFT ) {
1221 } else if ( event.key.keysym.sym == SDLK_UP ) {
1224 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1227 } else if ( event.key.keysym.sym == SDLK_SPACE || event.key.keysym.sym == SDLK_END ) {
1230 } else if ( event.key.keysym.sym == SDLK_RSHIFT ) {
1233 } else if ( event.key.keysym.sym == SDLK_RCTRL ) {
1236 } else if ( event.key.keysym.sym == SDLK_PAGEUP ) {
1238 if ( ui_selected ) {
1239 ui_show_info ( pnd_run_script, ui_selected -> ref );
1243 } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
1247 } else if ( event.key.keysym.sym == SDLK_LCTRL /*LALT*/ ) { // select button
1248 char *opts [ 20 ] = {
1249 "Reveal hidden category",
1251 "Configure Minimenu",
1252 "Rescan for applications",
1253 "Cache previews to SD now",
1254 "Run a terminal/console",
1255 "Run another GUI (xfce, etc)",
1257 "Select a Minimenu skin",
1260 int sel = ui_modal_single_menu ( opts, 10, "Minimenu", "Enter to select; other to return." );
1262 char buffer [ 100 ];
1266 } else if ( sel == 1 ) {
1268 sprintf ( buffer, "sudo poweroff" );
1270 } else if ( sel == 2 ) {
1272 unsigned char restart = conf_run_menu ( NULL );
1273 conf_write ( g_conf, conf_determine_location ( g_conf ) );
1275 emit_and_quit ( MM_RESTART );
1277 } else if ( sel == 3 ) {
1279 pnd_log ( pndn_debug, "Freeing up applications\n" );
1280 applications_free();
1281 pnd_log ( pndn_debug, "Rescanning applications\n" );
1282 applications_scan();
1283 } else if ( sel == 4 ) {
1284 // cache preview to SD now
1285 extern pnd_box_handle g_active_apps;
1286 pnd_box_handle h = g_active_apps;
1288 unsigned int maxwidth, maxheight;
1289 maxwidth = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 );
1290 maxheight = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 );
1292 pnd_disco_t *iter = pnd_box_get_head ( h );
1297 if ( ! cache_preview ( iter, maxwidth, maxheight ) ) {
1298 pnd_log ( pndn_debug, "Force cache: Couldn't load preview pic: '%s' -> '%s'\n",
1299 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1303 iter = pnd_box_get_next ( iter );
1306 } else if ( sel == 5 ) {
1309 argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
1313 ui_forkexec ( argv );
1316 } else if ( sel == 6 ) {
1317 char buffer [ PATH_MAX ];
1318 sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/pandora/scripts/op_switchgui.sh" );
1319 emit_and_quit ( buffer );
1320 } else if ( sel == 7 ) {
1321 emit_and_quit ( MM_QUIT );
1322 } else if ( sel == 8 ) {
1324 if ( ui_pick_skin() ) {
1325 emit_and_quit ( MM_RESTART );
1327 } else if ( sel == 9 ) {
1329 char buffer [ PATH_MAX ];
1330 sprintf ( buffer, "%s/about.txt", g_skinpath );
1331 ui_aboutscreen ( buffer );
1335 render_mask |= CHANGED_EVERYTHING;
1338 // unknown SDLK_ keycode?
1340 // many SDLK_keycodes map to ASCII ("a" is ascii(a)), so try to jump to a filename of that name, in this category?
1341 // and if already there, try to jump to next, maybe?
1342 // future: look for sequence typing? ie: user types 'm' then 'a', look for 'ma*' instead of 'm' then 'a' matching
1343 if ( isalpha ( event.key.keysym.sym ) && g_categories [ ui_category ].refcount > 0 ) {
1344 mm_appref_t *app = g_categories [ ui_category ].refs;
1346 //fprintf ( stderr, "sel %s next %s\n", ui_selected -> ref -> title_en, ui_selected -> next -> ref -> title_en );
1348 // are we already matching the same char? and next item is also same char?
1349 if ( app && ui_selected &&
1350 ui_selected -> ref -> title_en && ui_selected -> next -> ref -> title_en &&
1351 toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( ui_selected -> next -> ref -> title_en [ 0 ] ) &&
1352 toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym )
1355 // just skip down one
1356 app = ui_selected -> next;
1359 // walk the category, looking for a first-char match
1361 if ( app -> ref -> title_en && toupper ( app -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym ) ) {
1367 } // same start letter, or new run?
1369 // found something, or no?
1371 // looks like we found a potential match; try switching it to visible selection
1373 ui_set_selected ( ui_selected );
1380 } // SDLK_alphanumeric?
1386 if ( event.key.keysym.sym == SDLK_ESCAPE ) {
1387 emit_and_quit ( MM_QUIT );
1394 #if 1 // mouse / touchscreen
1396 case SDL_MOUSEBUTTONDOWN:
1397 if ( event.button.button == SDL_BUTTON_LEFT ) {
1398 cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
1404 case SDL_MOUSEBUTTONUP:
1405 if ( event.button.button == SDL_BUTTON_LEFT ) {
1406 ui_touch_act ( event.button.x, event.button.y );
1419 } // switch event type
1426 void ui_push_left ( unsigned char forcecoil ) {
1428 if ( ! ui_selected ) {
1429 ui_push_right ( 0 );
1433 // what column we in?
1434 unsigned int col = ui_determine_screen_col ( ui_selected );
1436 // are we already at first item?
1437 if ( forcecoil == 0 &&
1438 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1441 unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1442 while ( i && ui_selected -> next ) {
1443 ui_push_right ( 0 );
1447 } else if ( g_categories [ ui_category ].refs == ui_selected ) {
1448 // can't go any more left, we're at the head
1451 // figure out the previous item; yay for singly linked list :/
1452 mm_appref_t *i = g_categories [ ui_category ].refs;
1454 if ( i -> next == ui_selected ) {
1462 ui_set_selected ( ui_selected );
1467 void ui_push_right ( unsigned char forcecoil ) {
1469 if ( ui_selected ) {
1471 // what column we in?
1472 unsigned int col = ui_determine_screen_col ( ui_selected );
1475 if ( forcecoil == 0 &&
1476 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1477 // and selected is far-right, or last icon in category (might not be far right)
1478 ( ( col == pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1 ) ||
1479 ( ui_selected -> next == NULL ) )
1483 //unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1484 while ( col /*i*/ ) {
1490 // just go to the next
1492 if ( ui_selected -> next ) {
1493 ui_selected = ui_selected -> next;
1499 ui_selected = g_categories [ ui_category ].refs;
1502 ui_set_selected ( ui_selected );
1507 void ui_push_up ( void ) {
1508 unsigned char col_max = pnd_conf_get_as_int ( g_conf, "grid.col_max" );
1510 if ( ! ui_selected ) {
1515 unsigned int row = ui_determine_row ( ui_selected );
1518 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 0 ) == 0 )
1520 // wrap around instead
1522 unsigned int col = ui_determine_screen_col ( ui_selected );
1525 ui_selected = g_categories [ ui_category ].refs;
1526 while ( ui_selected -> next ) {
1527 ui_selected = ui_selected -> next;
1530 // try to move to same column
1531 unsigned int newcol = ui_determine_screen_col ( ui_selected );
1532 if ( newcol > col ) {
1540 // scroll down to show it
1541 int r = ui_determine_row ( ui_selected ) - 1;
1542 if ( r - pnd_conf_get_as_int ( g_conf, "grid.row_max" ) > 0 ) {
1543 ui_rows_scrolled_down = (unsigned int) r;
1547 // stop at top/bottom
1559 void ui_push_down ( void ) {
1560 unsigned char col_max = pnd_conf_get_as_int ( g_conf, "grid.col_max" );
1562 if ( ui_selected ) {
1565 unsigned int row = ui_determine_row ( ui_selected );
1568 unsigned int icon_rows = g_categories [ ui_category ].refcount / col_max;
1569 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
1574 if ( row == ( icon_rows - 1 ) &&
1575 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 0 ) == 0 )
1578 unsigned char col = ui_determine_screen_col ( ui_selected );
1580 ui_selected = g_categories [ ui_category ].refs;
1583 ui_selected = ui_selected -> next;
1587 ui_rows_scrolled_down = 0;
1589 render_mask |= CHANGED_EVERYTHING;
1594 ui_push_right ( 1 );
1601 ui_push_right ( 0 );
1607 void ui_push_exec ( void ) {
1609 if ( ! ui_selected ) {
1613 // was this icon generated from filesystem, or from pnd-file?
1614 if ( ui_selected -> ref -> object_flags & PND_DISCO_GENERATED ) {
1616 if ( ! ui_selected -> ref -> title_en ) {
1617 return; // no filename
1620 if ( ui_selected -> ref -> object_type == pnd_object_type_directory ) {
1621 // delve up/down the dir tree
1623 if ( strcmp ( ui_selected -> ref -> title_en, ".." ) == 0 ) {
1627 // lop off last word; if the thing ends with /, lop that one, then the next word.
1628 while ( ( c = strrchr ( g_categories [ ui_category].fspath, '/' ) ) ) {
1629 *c = '\0'; // lop off the last hunk
1630 if ( *(c+1) != '\0' ) {
1636 if ( g_categories [ ui_category].fspath [ 0 ] == '\0' ) {
1637 strcpy ( g_categories [ ui_category].fspath, "/" );
1642 strcat ( g_categories [ ui_category].fspath, "/" );
1643 strcat ( g_categories [ ui_category].fspath, ui_selected -> ref -> title_en );
1646 pnd_log ( pndn_debug, "Cat %s is now in path %s\n", g_categories [ ui_category ].catname, g_categories [ ui_category ].fspath );
1649 category_fs_restock ( &(g_categories [ ui_category]) );
1650 // forget the selection, nolonger applies
1652 ui_set_selected ( ui_selected );
1654 render_mask |= CHANGED_SELECTION;
1657 // just run it arbitrarily?
1659 // if this a pnd-file, or just some executable?
1660 if ( strcasestr ( ui_selected -> ref -> object_filename, PND_PACKAGE_FILEEXT ) ) {
1661 // looks like a pnd, now what do we do..
1662 pnd_box_handle h = pnd_disco_file ( ui_selected -> ref -> object_path, ui_selected -> ref -> object_filename );
1665 pnd_disco_t *d = pnd_box_get_head ( h );
1666 pnd_apps_exec_disco ( pnd_run_script, d, PND_EXEC_OPTION_NORUN, NULL );
1667 char buffer [ PATH_MAX ];
1668 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1669 emit_and_quit ( buffer );
1675 char cwd [ PATH_MAX ];
1676 getcwd ( cwd, PATH_MAX );
1678 chdir ( g_categories [ ui_category ].fspath );
1679 pnd_exec_no_wait_1 ( ui_selected -> ref -> title_en, NULL );
1682 char buffer [ PATH_MAX ];
1683 sprintf ( buffer, "%s %s/%s\n", MM_RUN, g_categories [ ui_category ].fspath, ui_selected -> ref -> title_en );
1684 emit_and_quit ( buffer );
1692 // set app-run speed
1693 int use_run_speed = pnd_conf_get_as_int_d ( g_conf, "minimenu.use_run_speed", 0 );
1694 if ( use_run_speed > 0 ) {
1695 int mm_speed = pnd_conf_get_as_int_d ( g_conf, "minimenu.run_speed", -1 );
1696 if ( mm_speed > -1 ) {
1697 char buffer [ 512 ];
1698 snprintf ( buffer, 500, "sudo /usr/pandora/scripts/op_cpuspeed.sh %d", mm_speed );
1701 } // do speed change?
1703 // request app to run and quit mmenu
1704 pnd_apps_exec_disco ( pnd_run_script, ui_selected -> ref, PND_EXEC_OPTION_NORUN, NULL );
1705 char buffer [ PATH_MAX ];
1706 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1707 emit_and_quit ( buffer );
1713 void ui_push_ltrigger ( void ) {
1714 unsigned char oldcat = ui_category;
1715 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
1716 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1718 if ( g_categorycount == 0 ) {
1722 if ( ui_category > 0 ) {
1724 category_fs_restock ( &(g_categories [ ui_category ]) );
1726 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1727 ui_category = g_categorycount - 1;
1729 if ( ui_category >= ( screen_width / tab_width ) ) {
1730 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
1732 category_fs_restock ( &(g_categories [ ui_category ]) );
1736 if ( oldcat != ui_category ) {
1738 ui_set_selected ( ui_selected );
1741 // make tab visible?
1742 if ( ui_catshift > 0 && ui_category == ui_catshift - 1 ) {
1747 ui_rows_scrolled_down = 0;
1749 render_mask |= CHANGED_CATEGORY;
1754 void ui_push_rtrigger ( void ) {
1755 unsigned char oldcat = ui_category;
1757 if ( g_categorycount == 0 ) {
1761 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
1762 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1764 if ( ui_category < ( g_categorycount - 1 ) ) {
1766 category_fs_restock ( &(g_categories [ ui_category ]) );
1768 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1771 category_fs_restock ( &(g_categories [ ui_category ]) );
1775 if ( oldcat != ui_category ) {
1777 ui_set_selected ( ui_selected );
1780 // make tab visible?
1781 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
1786 ui_rows_scrolled_down = 0;
1788 render_mask |= CHANGED_CATEGORY;
1793 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ) {
1794 double scale = 1000000.0;
1795 double scalex = 1000000.0;
1796 double scaley = 1000000.0;
1797 SDL_Surface *scaled;
1799 scalex = (double)maxwidth / (double)s -> w;
1801 if ( maxheight == -1 ) {
1804 scaley = (double)maxheight / (double)s -> h;
1806 if ( scaley < scalex ) {
1814 scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
1815 SDL_FreeSurface ( s );
1821 void ui_loadscreen ( void ) {
1825 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1826 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1827 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1828 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1831 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1835 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1836 rtext = TTF_RenderText_Blended ( g_big_font, "Setting up menu...", tmpfontcolor );
1839 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1840 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1841 SDL_FreeSurface ( rtext );
1846 void ui_discoverscreen ( unsigned char clearscreen ) {
1850 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1851 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1852 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1853 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1856 if ( clearscreen ) {
1857 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1859 // render background
1860 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1863 dest.w = sdl_realscreen -> w;
1864 dest.h = sdl_realscreen -> h;
1865 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1866 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1873 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1874 rtext = TTF_RenderText_Blended ( g_big_font, "Looking for applications...", tmpfontcolor );
1875 if ( clearscreen ) {
1882 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1883 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1884 SDL_FreeSurface ( rtext );
1887 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1888 dest.x = rtext -> w + 30;
1890 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, &dest );
1891 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1897 void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
1899 SDL_Rect rects [ 4 ];
1900 SDL_Rect *dest = rects;
1902 bzero ( dest, sizeof(SDL_Rect)* 4 );
1904 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1905 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1906 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1907 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1909 static unsigned int stepx = 0;
1912 if ( clearscreen ) {
1913 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1915 // render background
1916 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1919 dest -> w = sdl_realscreen -> w;
1920 dest -> h = sdl_realscreen -> h;
1921 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1927 // render background
1928 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1931 src.w = sdl_realscreen -> w;
1935 dest -> w = sdl_realscreen -> w;
1936 dest -> h = sdl_realscreen -> h;
1937 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
1945 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1946 rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
1949 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1950 SDL_FreeSurface ( rtext );
1954 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1955 dest -> x = rtext -> w + 30 + stepx;
1957 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, dest );
1963 rtext = TTF_RenderText_Blended ( g_tab_font, filename, tmpfontcolor );
1966 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1967 SDL_FreeSurface ( rtext );
1974 if ( stepx > 350 ) {
1978 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1983 int ui_selected_index ( void ) {
1985 if ( ! ui_selected ) {
1986 return ( -1 ); // no index
1989 mm_appref_t *r = g_categories [ ui_category ].refs;
1992 if ( r == ui_selected ) {
2002 static mm_appref_t *timer_ref = NULL;
2003 void ui_set_selected ( mm_appref_t *r ) {
2005 render_mask |= CHANGED_SELECTION;
2007 if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
2008 return; // no desire to defer anything
2013 SDL_SetTimer ( 0, NULL );
2018 SDL_SetTimer ( pnd_conf_get_as_int_d ( g_conf, "previewpic.defer_timer_ms", 1000 ), ui_callback_f );
2024 unsigned int ui_callback_f ( unsigned int t ) {
2026 if ( ui_selected != timer_ref ) {
2027 return ( 0 ); // user has moved it, who cares
2031 bzero ( &e, sizeof(SDL_Event) );
2032 e.type = SDL_USEREVENT;
2033 e.user.code = sdl_user_ticker;
2034 SDL_PushEvent ( &e );
2039 int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer ) {
2040 SDL_Rect rects [ 40 ];
2041 SDL_Rect *dest = rects;
2044 unsigned char max_visible = pnd_conf_get_as_int_d ( g_conf, "detailtext.max_visible" , 11 );
2045 unsigned char first_visible = 0;
2047 bzero ( rects, sizeof(SDL_Rect) * 40 );
2049 unsigned int sel = 0;
2051 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
2052 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
2053 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
2054 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
2056 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
2058 SDL_Color selfontcolor = { 0/*font_rgba_r*/, font_rgba_g, font_rgba_b, font_rgba_a };
2066 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2067 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2068 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
2069 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
2070 SDL_FillRect( sdl_realscreen, dest, 0 );
2072 // show dialog background
2073 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
2074 src.x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2075 src.y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2076 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
2077 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
2078 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2079 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2080 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2081 // repeat for darken?
2082 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2083 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2084 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2088 // show dialog frame
2089 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
2090 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2091 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2092 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
2093 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2099 rtext = TTF_RenderText_Blended ( g_tab_font, title, tmpfontcolor );
2100 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2101 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
2102 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2103 SDL_FreeSurface ( rtext );
2109 rtext = TTF_RenderText_Blended ( g_tab_font, footer, tmpfontcolor );
2110 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2111 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
2112 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
2114 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2115 SDL_FreeSurface ( rtext );
2120 for ( i = first_visible; i < first_visible + max_visible && i < argc; i++ ) {
2124 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
2126 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], tmpfontcolor );
2128 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2129 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 - first_visible ) );
2130 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2131 SDL_FreeSurface ( rtext );
2136 // update all the rects and send it all to sdl
2137 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
2141 while ( SDL_WaitEvent ( &event ) ) {
2143 switch ( event.type ) {
2148 if ( event.key.keysym.sym == SDLK_UP ) {
2152 if ( sel < first_visible ) {
2157 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
2159 if ( sel < argc - 1 ) {
2162 // ensure visibility
2163 if ( sel >= first_visible + max_visible ) {
2169 } else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_END ) { // return, or "B"
2173 } else if ( event.key.keysym.sym == SDLK_q ) {
2178 return ( -1 ); // nada
2193 unsigned char ui_determine_row ( mm_appref_t *a ) {
2194 unsigned int row = 0;
2196 mm_appref_t *i = g_categories [ ui_category ].refs;
2201 row /= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
2206 unsigned char ui_determine_screen_row ( mm_appref_t *a ) {
2207 return ( ui_determine_row ( a ) % pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 5 ) );
2210 unsigned char ui_determine_screen_col ( mm_appref_t *a ) {
2211 unsigned int col = 0;
2213 mm_appref_t *i = g_categories [ ui_category ].refs;
2218 col %= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
2223 unsigned char ui_show_info ( char *pndrun, pnd_disco_t *p ) {
2224 char *viewer, *searchpath;
2225 pnd_conf_handle desktoph;
2228 searchpath = pnd_conf_query_searchpath();
2230 desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
2236 viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
2239 return ( 0 ); // no way to view the file
2243 if ( ! p -> unique_id ) {
2247 if ( ! p -> info_filename ) {
2251 if ( ! p -> info_name ) {
2262 if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) {
2263 snprintf ( pargs, 1001, "%s %s",
2264 pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
2269 char pndfile [ 1024 ];
2270 if ( p -> object_type == pnd_object_type_directory ) {
2271 // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
2272 strncpy ( pndfile, p -> object_path, 1000 );
2273 } else if ( p -> object_type == pnd_object_type_pnd ) {
2274 // pnd_run.sh wants the full path and filename for the .pnd file
2275 snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
2278 if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs,
2279 p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) )
2284 pnd_log ( pndn_debug, "Info Exec=%s\n", pnd_apps_exec_runline() );
2288 if ( ( x = fork() ) < 0 ) {
2289 pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
2294 execl ( "/bin/sh", "/bin/sh", "-c", pnd_apps_exec_runline(), (char*)NULL );
2295 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", pnd_apps_exec_runline() );
2307 #define MAXTOUCH 100
2308 ui_touch_t ui_touchrects [ MAXTOUCH ];
2309 unsigned char ui_touchrect_count = 0;
2311 void ui_register_reset ( void ) {
2312 bzero ( ui_touchrects, sizeof(ui_touch_t)*MAXTOUCH );
2313 ui_touchrect_count = 0;
2317 void ui_register_tab ( unsigned char catnum, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2319 if ( ui_touchrect_count == MAXTOUCH ) {
2323 ui_touchrects [ ui_touchrect_count ].r.x = x;
2324 ui_touchrects [ ui_touchrect_count ].r.y = y;
2325 ui_touchrects [ ui_touchrect_count ].r.w = w;
2326 ui_touchrects [ ui_touchrect_count ].r.h = h;
2327 ui_touchrects [ ui_touchrect_count ].catnum = catnum;
2328 ui_touchrect_count++;
2333 void ui_register_app ( mm_appref_t *app, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2335 if ( ui_touchrect_count == MAXTOUCH ) {
2339 ui_touchrects [ ui_touchrect_count ].r.x = x;
2340 ui_touchrects [ ui_touchrect_count ].r.y = y;
2341 ui_touchrects [ ui_touchrect_count ].r.w = w;
2342 ui_touchrects [ ui_touchrect_count ].r.h = h;
2343 ui_touchrects [ ui_touchrect_count ].ref = app;
2344 ui_touchrect_count++;
2349 void ui_touch_act ( unsigned int x, unsigned int y ) {
2354 for ( i = 0; i < ui_touchrect_count; i++ ) {
2355 t = &(ui_touchrects [ i ]);
2357 if ( x >= t -> r.x &&
2358 x <= t -> r.x + t -> r.w &&
2360 y <= t -> r.y + t -> r.h
2365 ui_selected = t -> ref;
2368 if ( ui_category != t -> catnum ) {
2371 ui_category = t -> catnum;
2372 render_mask |= CHANGED_CATEGORY;
2383 unsigned char ui_forkexec ( char *argv[] ) {
2384 char *fooby = argv[0];
2387 if ( ( x = fork() ) < 0 ) {
2388 pnd_log ( pndn_error, "ERROR: Couldn't fork() for '%s'\n", fooby );
2392 if ( x == 0 ) { // child
2393 execv ( fooby, argv );
2394 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", fooby );
2402 unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ) {
2404 if ( ! cache_preview ( p, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
2405 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
2408 pnd_log ( pndn_debug, "THREAD: Couldn't load preview pic: '%s' -> '%s'\n",
2409 IFNULL(p->title_en,"No Name"), p -> preview_pic1 );
2412 // trigger that we completed
2414 bzero ( &e, sizeof(SDL_Event) );
2415 e.type = SDL_USEREVENT;
2416 e.user.code = sdl_user_finishedpreview;
2418 SDL_PushEvent ( &e );
2423 SDL_Thread *g_icon_thread = NULL;
2424 void ui_post_scan ( void ) {
2426 // if deferred icon load, kick off the thread now
2427 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 1 ) {
2429 g_icon_thread = SDL_CreateThread ( (void*)ui_threaded_defered_icon, NULL );
2431 if ( ! g_icon_thread ) {
2432 pnd_log ( pndn_error, "ERROR: Couldn't create icon thread\n" );
2435 } // deferred icon load
2439 ui_rows_scrolled_down = 0;
2440 // set back to first tab, to be safe
2444 // do we have a preferred category to jump to?
2445 char *dc = pnd_conf_get_as_char ( g_conf, "categories.default_cat" );
2448 // attempt to find default cat; if we do find it, select it; otherwise
2449 // default behaviour will pick first cat (ie: usually All)
2451 for ( i = 0; i < g_categorycount; i++ ) {
2452 if ( strcasecmp ( g_categories [ i ].catname, dc ) == 0 ) {
2454 // ensure visibility
2455 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
2456 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2457 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
2458 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
2464 if ( i == g_categorycount ) {
2465 pnd_log ( pndn_warning, " User defined default category '%s' but not found, so using default behaviour\n", dc );
2471 render_mask |= CHANGED_EVERYTHING;
2476 unsigned char ui_threaded_defered_icon ( void *p ) {
2477 extern pnd_box_handle g_active_apps;
2478 pnd_box_handle h = g_active_apps;
2480 unsigned char maxwidth, maxheight;
2481 maxwidth = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 );
2482 maxheight = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_height", 50 );
2484 pnd_disco_t *iter = pnd_box_get_head ( h );
2489 if ( iter -> pnd_icon_pos &&
2490 ! cache_icon ( iter, maxwidth, maxheight ) )
2492 pnd_log ( pndn_warning, " Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2495 // trigger that we completed
2497 bzero ( &e, sizeof(SDL_Event) );
2498 e.type = SDL_USEREVENT;
2499 e.user.code = sdl_user_finishedicon;
2500 SDL_PushEvent ( &e );
2502 //pnd_log ( pndn_warning, " Finished deferred load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2503 usleep ( pnd_conf_get_as_int_d ( g_conf, "minimenu.defer_icon_us", 50000 ) );
2508 iter = pnd_box_get_next ( iter );
2514 void ui_show_hourglass ( unsigned char updaterect ) {
2517 SDL_Surface *s = g_imagecache [ IMG_HOURGLASS ].i;
2519 dest.x = ( 800 - s -> w ) / 2;
2520 dest.y = ( 480 - s -> h ) / 2;
2522 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, &dest );
2525 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2531 unsigned char ui_pick_skin ( void ) {
2533 char *skins [ MAXSKINS ];
2536 char *searchpath = pnd_conf_get_as_char ( g_conf, "minimenu.skin_searchpath" );
2537 char tempname [ 100 ];
2541 skins [ iter++ ] = "No skin change";
2545 DIR *d = opendir ( buffer );
2550 while ( ( dd = readdir ( d ) ) ) {
2552 if ( dd -> d_name [ 0 ] == '.' ) {
2554 } else if ( ( dd -> d_type == DT_DIR || dd -> d_type == DT_UNKNOWN ) &&
2557 snprintf ( tempname, 100, "Skin: %s", dd -> d_name );
2558 skins [ iter++ ] = strdup ( tempname );
2569 int sel = ui_modal_single_menu ( skins, iter, "Skins", "Enter to select; other to return." );
2571 // did they pick one?
2575 char *s = strdup ( pnd_conf_get_as_char ( g_conf, "minimenu.skin_selected" ) );
2576 s = pnd_expand_tilde ( s );
2578 f = fopen ( s, "w" );
2583 fprintf ( f, "%s\n", skins [ sel ] + 6 );
2593 void ui_aboutscreen ( char *textpath ) {
2600 #define ROWS SCRH / ( PIXELH + MARGINH )
2601 #define COLS SCRW / ( PIXELW + MARGINW )
2603 unsigned char pixelboard [ ROWS * COLS ]; // pixel heat
2604 bzero ( pixelboard, ROWS * COLS );
2609 SDL_Color rtextc = { 200, 200, 200, 100 };
2612 char *textloop [ 500 ];
2613 unsigned int textmax = 0;
2614 bzero ( textloop, 500 * sizeof(char*) );
2617 char cbuffer [ 50000 ];
2618 bzero ( cbuffer, 50000 );
2619 unsigned int crevealed = 0;
2621 FILE *f = fopen ( textpath, "r" );
2624 pnd_log ( pndn_error, "ERROR: Couldn't open about text: %s\n", textpath );
2628 char textbuf [ 100 ];
2629 while ( fgets ( textbuf, 100, f ) ) {
2631 // add to full buffer
2632 strncat ( cbuffer, textbuf, 50000 );
2635 if ( strchr ( textbuf, '\n' ) ) {
2636 * strchr ( textbuf, '\n' ) = '\0';
2639 // add to pixel loop
2640 if ( 1||textbuf [ 0 ] ) {
2641 textloop [ textmax ] = strdup ( textbuf );
2649 unsigned int textiter = 0;
2650 while ( textiter < textmax ) {
2651 char *text = textloop [ textiter ];
2655 // render to surface
2656 rtext = TTF_RenderText_Blended ( g_grid_font, text, rtextc );
2658 // render font to pixelboard
2659 unsigned int px, py;
2661 unsigned int *pixels = rtext -> pixels;
2662 unsigned char cr, cg, cb, ca;
2663 for ( py = 0; py < rtext -> h; py ++ ) {
2664 for ( px = 0; px < ( rtext -> w > COLS ? COLS : rtext -> w ); px++ ) {
2666 SDL_GetRGBA ( pixels [ ( py * rtext -> pitch / 4 ) + px ],
2667 rtext -> format, &cr, &cg, &cb, &ca );
2671 ph = pixelboard + ( /*y offset */ 30 * COLS ) + ( py * COLS ) + px /* / 2 */;
2678 if ( *ph + ca < 250 ) {
2689 unsigned int runcount = 10;
2690 while ( runcount-- ) {
2693 SDL_FillRect( sdl_realscreen, NULL /* whole */, 0 );
2695 // render pixelboard
2698 for ( y = 0; y < ROWS; y++ ) {
2699 for ( x = 0; x < COLS; x++ ) {
2701 if ( 1||pixelboard [ ( y * COLS ) + x ] ) {
2704 r.x = x * ( PIXELW + MARGINW );
2705 r.y = y * ( PIXELH + MARGINH );
2709 c = SDL_MapRGB ( sdl_realscreen -> format, 100 /* r */, 0 /* g */, pixelboard [ ( y * COLS ) + x ] );
2711 SDL_FillRect( sdl_realscreen, &r /* whole */, c );
2719 unsigned char *pc = pixelboard;
2720 for ( y = 0; y < ROWS; y++ ) {
2721 for ( x = 0; x < COLS; x++ ) {
2731 // slide pixels upwards
2732 memmove ( pixelboard, pixelboard + COLS, ( COLS * ROWS ) - COLS );
2734 // render actual readable text
2737 // display up to cursor
2739 unsigned int cdraw = 0;
2743 if ( crevealed > 200 ) {
2744 cdraw = crevealed - 200;
2750 for ( ; cdraw < crevealed; cdraw++ ) {
2751 ctb [ 0 ] = cbuffer [ cdraw ];
2753 // move over or down
2754 if ( cbuffer [ cdraw ] == '\n' ) {
2759 if ( dest.y > 450 ) {
2765 cs = TTF_RenderText_Blended ( g_tab_font, ctb, rtextc );
2767 SDL_BlitSurface ( cs, NULL /* all */, sdl_realscreen, &dest );
2768 SDL_FreeSurface ( cs );
2778 SDL_FillRect ( sdl_realscreen, &dest /* whole */, 220 );
2780 // increment cursor to next character
2781 if ( cbuffer [ crevealed ] != '\0' ) {
2785 } // draw cursor text
2789 SDL_UpdateRect ( sdl_realscreen, 0, 0, 0, 0 ); // whole screen
2793 // any button? if so, about
2799 if ( SDL_PeepEvents ( &e, 1, SDL_GETEVENT, SDL_EVENTMASK(SDL_KEYUP|SDL_KEYDOWN) ) > 0 ) {
2808 SDL_FreeSurface ( rtext );
2812 } // while more text
2816 for ( i = 0; i < textmax; i++ ) {
2817 if ( textloop [ i ] ) {
2818 free ( textloop [ i ] );
2826 void ui_revealscreen ( void ) {
2827 char *labels [ 500 ];
2828 unsigned int labelmax = 0;
2831 if ( ! _categories_inviscount ) {
2832 return; // nothing to do
2835 for ( i = 0; i < _categories_inviscount; i++ ) {
2836 labels [ labelmax++ ] = _categories_invis [ i ].catname;
2839 int sel = ui_modal_single_menu ( labels, labelmax, "Temporary Category Reveal",
2840 "Enter to select; other to return." );
2844 if ( category_query ( _categories_invis [ sel ].catname ) ) {
2849 // fix up category name, if its been hacked
2850 if ( strchr ( _categories_invis [ sel ].catname, '.' ) ) {
2851 char *t = _categories_invis [ sel ].catname;
2852 _categories_invis [ sel ].catname = strdup ( strchr ( _categories_invis [ sel ].catname, '.' ) + 1 );
2855 // copy invisi-cat into live-cat
2856 memmove ( &(g_categories [ g_categorycount ]), &(_categories_invis [ sel ]), sizeof(mm_category_t) );
2858 // move subsequent invisi-cats up, so the selected invisi-cat is nolonger existing in invisi-list at
2859 // all (avoid double-free() later)
2860 memmove ( &(_categories_invis [ sel ]), &(_categories_invis [ sel + 1 ]), sizeof(mm_category_t) * ( _categories_inviscount - sel - 1 ) );
2861 _categories_inviscount--;
2863 // switch to the new category
2864 ui_category = g_categorycount - 1;
2866 // ensure visibility
2867 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
2868 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2869 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
2870 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
2874 render_mask |= CHANGED_CATEGORY;