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 #define CHANGED_NOTHING (0)
39 #define CHANGED_CATEGORY (1<<0) /* changed to different category */
40 #define CHANGED_SELECTION (1<<1) /* changed app selection */
41 #define CHANGED_DATAUPDATE (1<<2) /* deferred preview pic or icon came in */
42 #define CHANGED_APPRELOAD (1<<3) /* new set of applications entirely */
43 #define CHANGED_EVERYTHING (1<<4) /* redraw it all! */
44 unsigned int render_mask = CHANGED_EVERYTHING;
48 SDL_Surface *sdl_realscreen = NULL;
49 unsigned int sdl_ticks = 0;
50 SDL_Thread *g_preview_thread = NULL;
52 enum { sdl_user_ticker = 0,
53 sdl_user_finishedpreview = 1,
54 sdl_user_finishedicon = 2,
59 unsigned short int g_scale = 1; // 1 == noscale
61 SDL_Surface *g_imgcache [ IMG_MAX ];
63 TTF_Font *g_big_font = NULL;
64 TTF_Font *g_grid_font = NULL;
65 TTF_Font *g_detailtext_font = NULL;
66 TTF_Font *g_tab_font = NULL;
68 extern pnd_conf_handle g_conf;
70 /* current display state
72 int ui_rows_scrolled_down = 0; // number of rows that should be missing from top of the display
73 mm_appref_t *ui_selected = NULL;
74 unsigned char ui_category = 0; // current category
75 unsigned char ui_catshift = 0; // how many cats are offscreen to the left
77 extern mm_category_t *g_categories;
78 extern unsigned char g_categorycount;
79 extern mm_category_t _categories_invis [ MAX_CATS ];
80 extern unsigned char _categories_inviscount;
82 static SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ); // height -1 means ignore
83 static int ui_selected_index ( void );
85 unsigned char ui_setup ( void ) {
90 SDL_Init ( SDL_INIT_EVERYTHING | SDL_INIT_NOPARACHUTE );
92 SDL_JoystickOpen ( 0 ); // turn on joy-0
94 SDL_WM_SetCaption ( "mmenu", "mmenu" );
96 // hide the mouse cursor if we can
97 if ( SDL_ShowCursor ( -1 ) == 1 ) {
104 unsigned int svm = SDL_SWSURFACE /*| SDL_FULLSCREEN*/ /* 0*/;
105 if ( pnd_conf_get_as_int_d ( g_conf, "display.fullscreen", 0 ) > 0 ) {
106 svm |= SDL_FULLSCREEN;
110 SDL_SetVideoMode ( 800 * g_scale, 480 * g_scale, 16 /*bpp*/, svm );
112 if ( ! sdl_realscreen ) {
113 pnd_log ( pndn_error, "ERROR: Couldn't open SDL real screen; dieing." );
117 pnd_log ( pndn_debug, "Pixel format:" );
118 pnd_log ( pndn_debug, "bpp b: %u\n", sdl_realscreen -> format -> BitsPerPixel );
119 pnd_log ( pndn_debug, "bpp B: %u\n", sdl_realscreen -> format -> BytesPerPixel );
120 pnd_log ( pndn_debug, "R mask: %08x\n", sdl_realscreen -> format -> Rmask );
121 pnd_log ( pndn_debug, "G mask: %08x\n", sdl_realscreen -> format -> Gmask );
122 pnd_log ( pndn_debug, "B mask: %08x\n", sdl_realscreen -> format -> Bmask );
128 /* Set 16-bit stereo audio at 22Khz */
129 fmt.freq = 44100; //22050;
130 fmt.format = AUDIO_S16; //AUDIO_S16;
132 fmt.samples = 2048; /* A good value for games */
133 fmt.callback = mixaudio;
136 /* Open the audio device and start playing sound! */
137 if ( SDL_OpenAudio ( &fmt, NULL ) < 0 ) {
138 zotlog ( "Unable to open audio: %s\n", SDL_GetError() );
142 SDL_PauseAudio ( 0 );
147 //IMG_Init ( IMG_INIT_JPG | IMG_INIT_PNG );
153 if ( TTF_Init() == -1 ) {
154 pnd_log ( pndn_error, "ERROR: Couldn't set up SDL TTF lib\n" );
155 return ( 0 ); // couldn't set up SDL TTF
158 char fullpath [ PATH_MAX ];
160 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "minimenu.font" ) );
161 g_big_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
162 if ( ! g_big_font ) {
163 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
164 pnd_conf_get_as_char ( g_conf, "minimenu.font" ), pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
165 return ( 0 ); // couldn't set up SDL TTF
169 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "grid.font" ) );
170 g_grid_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
171 if ( ! g_grid_font ) {
172 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
173 pnd_conf_get_as_char ( g_conf, "grid.font" ), pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
174 return ( 0 ); // couldn't set up SDL TTF
178 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "detailtext.font" ) );
179 g_detailtext_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
180 if ( ! g_detailtext_font ) {
181 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
182 pnd_conf_get_as_char ( g_conf, "detailtext.font" ), pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
183 return ( 0 ); // couldn't set up SDL TTF
187 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "tabs.font" ) );
188 g_tab_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
189 if ( ! g_tab_font ) {
190 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
191 pnd_conf_get_as_char ( g_conf, "tabs.font" ), pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
192 return ( 0 ); // couldn't set up SDL TTF
198 mm_imgcache_t g_imagecache [ IMG_TRUEMAX ] = {
199 { IMG_BACKGROUND_800480, "graphics.IMG_BACKGROUND_800480" },
200 { IMG_BACKGROUND_TABMASK, "graphics.IMG_BACKGROUND_TABMASK" },
201 { IMG_DETAIL_PANEL, "graphics.IMG_DETAIL_PANEL" },
202 { IMG_DETAIL_BG, "graphics.IMG_DETAIL_BG" },
203 { IMG_SELECTED_ALPHAMASK, "graphics.IMG_SELECTED_ALPHAMASK" },
204 { IMG_TAB_SEL, "graphics.IMG_TAB_SEL" },
205 { IMG_TAB_SEL_L, "graphics.IMG_TAB_SEL_L" },
206 { IMG_TAB_SEL_R, "graphics.IMG_TAB_SEL_R" },
207 { IMG_TAB_UNSEL, "graphics.IMG_TAB_UNSEL" },
208 { IMG_TAB_UNSEL_L, "graphics.IMG_TAB_UNSEL_L" },
209 { IMG_TAB_UNSEL_R, "graphics.IMG_TAB_UNSEL_R" },
210 { IMG_TAB_LINE, "graphics.IMG_TAB_LINE" },
211 { IMG_TAB_LINEL, "graphics.IMG_TAB_LINEL" },
212 { IMG_TAB_LINER, "graphics.IMG_TAB_LINER" },
213 { IMG_ICON_MISSING, "graphics.IMG_ICON_MISSING" },
214 { IMG_SELECTED_HILITE, "graphics.IMG_SELECTED_HILITE" },
215 { IMG_PREVIEW_MISSING, "graphics.IMG_PREVIEW_MISSING" },
216 { IMG_ARROW_UP, "graphics.IMG_ARROW_UP", },
217 { IMG_ARROW_DOWN, "graphics.IMG_ARROW_DOWN", },
218 { IMG_ARROW_SCROLLBAR, "graphics.IMG_ARROW_SCROLLBAR", },
219 { IMG_HOURGLASS, "graphics.IMG_HOURGLASS", },
220 { IMG_FOLDER, "graphics.IMG_FOLDER", },
221 { IMG_EXECBIN, "graphics.IMG_EXECBIN", },
225 unsigned char ui_imagecache ( char *basepath ) {
227 char fullpath [ PATH_MAX ];
231 for ( i = 0; i < IMG_MAX; i++ ) {
233 if ( g_imagecache [ i ].id != i ) {
234 pnd_log ( pndn_error, "ERROR: Internal table mismatch during caching [%u]\n", i );
238 char *filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].confname );
241 pnd_log ( pndn_error, "ERROR: Missing filename in conf for key: %s\n", g_imagecache [ i ].confname );
245 if ( filename [ 0 ] == '/' ) {
246 strncpy ( fullpath, filename, PATH_MAX );
248 sprintf ( fullpath, "%s/%s", basepath, filename );
251 if ( ! ( g_imagecache [ i ].i = IMG_Load ( fullpath ) ) ) {
252 pnd_log ( pndn_error, "ERROR: Couldn't load static cache image: %s\n", fullpath );
259 //g_imagecache [ IMG_SELECTED_ALPHAMASK ].i = SDL_CreateRGBSurface ( SDL_SWSURFACE, 60, 60, 32, 0xFF0000, 0x00FF00, 0xFF, 0xFF000000 );
260 //boxRGBA ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, 0, 0, 60, 60, 100, 100, 100, 250 );
266 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 );
267 // scale text hilight
268 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 );
269 // scale preview no-pic
270 g_imagecache [ IMG_PREVIEW_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_PREVIEW_MISSING ].i,
271 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ),
272 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 50 ) );
274 // set alpha on detail panel
275 //SDL_SetAlpha ( g_imagecache [ IMG_DETAIL_BG ].i, SDL_SRCALPHA, pnd_conf_get_as_int_d ( g_conf, "display.detail_bg_alpha", 50 ) );
280 void ui_render ( void ) {
283 // divide width: 550 / 250
284 // divide left side: 5 columns == 110px width
285 // 20px buffer either side == 70px wide icon + 20 + 20?
287 // what jobs to do during render?
291 #define R_TABS (1<<1)
292 #define R_DETAIL (1<<2)
293 #define R_GRID (1<<3)
295 #define R_ALL (R_BG|R_TABS|R_DETAIL|R_GRID)
297 unsigned int render_jobs_b = 0;
299 if ( render_mask & CHANGED_EVERYTHING ) {
300 render_jobs_b |= R_ALL;
303 if ( render_mask & CHANGED_SELECTION ) {
304 render_jobs_b |= R_GRID;
305 render_jobs_b |= R_DETAIL;
308 if ( render_mask & CHANGED_CATEGORY ) {
309 render_jobs_b |= R_ALL;
312 render_mask = CHANGED_NOTHING;
316 unsigned int icon_rows;
319 SDL_Rect rects [ MAXRECTS ], src;
320 SDL_Rect *dest = rects;
321 bzero ( dest, sizeof(SDL_Rect)*MAXRECTS );
323 unsigned int row, displayrow, col;
324 mm_appref_t *appiter;
326 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
328 unsigned char row_max = pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 4 );
329 unsigned char col_max = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
331 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
332 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
333 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
334 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
336 unsigned int grid_offset_x = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_x" );
337 unsigned int grid_offset_y = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_y" );
339 unsigned int icon_offset_x = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_x" );
340 unsigned int icon_offset_y = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_y" );
341 unsigned int icon_max_width = pnd_conf_get_as_int ( g_conf, "grid.icon_max_width" );
342 unsigned int icon_max_height = pnd_conf_get_as_int ( g_conf, "grid.icon_max_height" );
343 unsigned int sel_icon_offset_x = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_x", 0 );
344 unsigned int sel_icon_offset_y = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_y", 0 );
346 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
347 unsigned int text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
348 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "grid.text_offset_x" );
349 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_offset_y" );
351 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "grid.cell_width" );
352 unsigned int cell_height = pnd_conf_get_as_int ( g_conf, "grid.cell_height" );
354 // how many total rows do we need?
355 icon_rows = g_categories [ ui_category ].refcount / col_max;
356 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
360 // if no selected app yet, select the first one
362 if ( ! ui_selected ) {
363 ui_selected = g_categories [ ui_category ].refs;
367 // reset touchscreen regions
368 if ( render_jobs_b ) {
372 // ensure selection is visible
375 int index = ui_selected_index();
376 int topleft = col_max * ui_rows_scrolled_down;
377 int botright = ( col_max * ( ui_rows_scrolled_down + row_max ) - 1 );
379 if ( index < topleft ) {
380 ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
381 render_jobs_b |= R_ALL;
382 } else if ( index > botright ) {
383 ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
384 render_jobs_b |= R_ALL;
387 if ( ui_rows_scrolled_down < 0 ) {
388 ui_rows_scrolled_down = 0;
389 } else if ( ui_rows_scrolled_down > icon_rows ) {
390 ui_rows_scrolled_down = icon_rows;
396 if ( render_jobs_b & R_BG ) {
398 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
401 dest -> w = sdl_realscreen -> w;
402 dest -> h = sdl_realscreen -> h;
403 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
408 if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
411 dest -> w = sdl_realscreen -> w;
412 dest -> h = sdl_realscreen -> h;
413 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
420 if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
421 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
422 unsigned int tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
423 //unsigned int tab_selheight = pnd_conf_get_as_int ( g_conf, "tabs.tab_selheight" );
424 unsigned int tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
425 unsigned int tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
426 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
427 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
428 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
429 unsigned int maxtab = ( screen_width / tab_width ) < g_categorycount ? ( screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift;
430 unsigned int maxtabspot = ( screen_width / tab_width );
432 if ( g_categorycount > 0 ) {
434 // draw tabs with categories
435 for ( col = ui_catshift;
442 // if this is the first (leftmost) tab, we use different artwork
443 // than if the other tabs (so skinner can link lines up nicely.)
444 if ( col == ui_catshift ) {
445 // leftmost tab, special case
447 if ( col == ui_category ) {
448 s = g_imagecache [ IMG_TAB_SEL_L ].i;
450 s = g_imagecache [ IMG_TAB_UNSEL_L ].i;
453 } else if ( col == maxtab - 1 ) {
454 // rightmost tab, special case
456 if ( col == ui_category ) {
457 s = g_imagecache [ IMG_TAB_SEL_R ].i;
459 s = g_imagecache [ IMG_TAB_UNSEL_R ].i;
463 // normal (not leftmost) tab
465 if ( col == ui_category ) {
466 s = g_imagecache [ IMG_TAB_SEL ].i;
468 s = g_imagecache [ IMG_TAB_UNSEL ].i;
471 } // first col, or not first col?
478 if ( col == ui_category ) {
479 src.h = tab_selheight;
487 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
488 dest -> y = tab_offset_y;
491 ui_register_tab ( col, dest -> x, dest -> y, tab_width, tab_height );
493 if ( render_jobs_b & R_TABS ) {
494 //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
495 SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
499 if ( col == ui_category ) {
500 // no line for selected tab
502 if ( col - ui_catshift == 0 ) {
503 s = g_imagecache [ IMG_TAB_LINEL ].i;
504 } else if ( col - ui_catshift == maxtabspot - 1 ) {
505 s = g_imagecache [ IMG_TAB_LINER ].i;
507 s = g_imagecache [ IMG_TAB_LINE ].i;
509 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
510 dest -> y = tab_offset_y + tab_height;
511 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
517 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
518 rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ].catname, tmpfontcolor );
521 src.w = rtext -> w < text_width ? rtext -> w : text_width;
523 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
524 dest -> y = tab_offset_y + text_offset_y;
525 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
526 SDL_FreeSurface ( rtext );
533 } // if we got categories
535 if ( render_jobs_b & R_TABS ) {
537 // draw tab lines under where tabs would be if we had categories
538 for ( /* foo */; col < maxtabspot; col++ ) {
541 if ( col - ui_catshift == 0 ) {
542 s = g_imagecache [ IMG_TAB_LINEL ].i;
543 } else if ( col - ui_catshift == maxtabspot - 1 ) {
544 s = g_imagecache [ IMG_TAB_LINER ].i;
546 s = g_imagecache [ IMG_TAB_LINE ].i;
548 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
549 dest -> y = tab_offset_y + tab_height;
550 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
559 // scroll bars and arrows
560 if ( render_jobs_b & R_BG ) {
561 unsigned char show_bar = 0;
564 if ( ui_rows_scrolled_down && g_imagecache [ IMG_ARROW_UP ].i ) {
565 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
566 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
567 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
574 if ( ui_rows_scrolled_down + row_max < icon_rows && g_imagecache [ IMG_ARROW_DOWN ].i ) {
575 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
576 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
577 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
584 // show scrollbar as well
587 src.w = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_w", 10 );
588 src.h = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_h", 100 );
589 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
590 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
591 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
595 } // r_bg, scroll bars
597 // render detail pane bg
598 if ( render_jobs_b & R_DETAIL ) {
600 if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
603 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
604 src.x = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
605 src.y = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
606 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
607 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
608 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
609 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
610 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
614 // render detail pane
615 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
616 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
617 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
618 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
622 } // detailpane frame/bg
626 // anything to render?
627 if ( render_jobs_b & R_GRID ) {
629 // if just rendering grid, and nothing else, better clear it first
630 if ( ! ( render_jobs_b & R_BG ) ) {
631 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
632 src.x = grid_offset_x;
633 src.y = grid_offset_y + sel_icon_offset_y;
634 src.w = col_max * cell_width;
635 src.h = row_max * cell_height;
637 dest -> x = grid_offset_x;
638 dest -> y = grid_offset_y + sel_icon_offset_y;
640 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
646 if ( g_categories [ ui_category ].refs ) {
648 appiter = g_categories [ ui_category ].refs;
652 // until we run out of apps, or run out of space
653 while ( appiter != NULL ) {
655 for ( col = 0; col < col_max && appiter != NULL; col++ ) {
657 // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
658 if ( row >= ui_rows_scrolled_down ) {
660 // selected? show hilights
661 if ( appiter == ui_selected ) {
662 SDL_Surface *s = g_imagecache [ IMG_SELECTED_ALPHAMASK ].i;
664 //dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + ( ( icon_max_width - s -> w ) / 2 );
665 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + sel_icon_offset_x;
666 //dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + ( ( icon_max_height - s -> h ) / 2 );
667 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + sel_icon_offset_y;
668 SDL_BlitSurface ( s, NULL /* all */, sdl_realscreen, dest );
671 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
672 dest -> y = grid_offset_y + ( displayrow * cell_height ) + pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
673 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
678 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
679 SDL_Surface *iconsurface;
681 iconsurface = ic -> i;
683 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
685 // no icon override; was this a pnd-file (show the unknown icon then), or was this generated from
686 // filesystem (file or directory icon)
687 if ( appiter -> ref -> object_flags & PND_DISCO_GENERATED ) {
688 if ( appiter -> ref -> object_type == pnd_object_type_directory ) {
689 iconsurface = g_imagecache [ IMG_FOLDER ].i;
691 iconsurface = g_imagecache [ IMG_EXECBIN ].i;
694 iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
699 // got an icon I hope?
701 //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
707 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + (( icon_max_width - iconsurface -> w ) / 2);
708 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + (( icon_max_height - iconsurface -> h ) / 2);
710 SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
713 ui_register_app ( appiter, dest -> x, dest -> y, src.w, src.h );
720 if ( appiter -> ref -> title_en ) {
722 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
723 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, tmpfontcolor );
726 src.w = text_width < rtext -> w ? text_width : rtext -> w;
728 if ( rtext -> w > text_width ) {
729 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
731 dest -> x = grid_offset_x + ( col * cell_width ) + text_offset_x - ( rtext -> w / 2 );
733 dest -> y = grid_offset_y + ( displayrow * cell_height ) + text_offset_y;
734 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
735 SDL_FreeSurface ( rtext );
739 } // display now? or scrolled away..
742 appiter = appiter -> next;
744 } // for column 1...X
746 if ( row >= ui_rows_scrolled_down ) {
752 // are we done displaying rows?
753 if ( displayrow >= row_max ) {
760 // no apps to render?
761 pnd_log ( pndn_rem, "No applications to render?\n" );
767 if ( ui_selected && render_jobs_b & R_DETAIL ) {
769 unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
770 unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
771 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "detailtext.cell_width" );
773 unsigned int desty = cell_offset_y;
778 if ( ui_selected -> ref -> title_en ) {
780 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
781 rtext = TTF_RenderText_Blended ( g_detailtext_font, ui_selected -> ref -> title_en, tmpfontcolor );
784 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
786 dest -> x = cell_offset_x;
788 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
789 SDL_FreeSurface ( rtext );
796 if ( ui_selected -> ref -> main_category ) {
798 sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
801 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
802 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
805 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
807 dest -> x = cell_offset_x;
809 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
810 SDL_FreeSurface ( rtext );
817 if ( ui_selected -> ref -> clockspeed ) {
819 sprintf ( buffer, "CPU Clock: %s", ui_selected -> ref -> clockspeed );
822 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
823 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
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 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
843 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
844 dest -> x = cell_offset_x + cell_width - rtext -> w;
845 dest -> y = desty - src.h;
846 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
847 SDL_FreeSurface ( rtext );
852 #if 0 // merged into hint-line
853 if ( ui_selected -> ref -> info_filename ) {
855 sprintf ( buffer, "Documentation - hit Y" );
858 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
859 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
862 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
864 dest -> x = cell_offset_x;
866 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
867 SDL_FreeSurface ( rtext );
874 if ( ui_selected -> ovrh ) {
879 desty += 5; // a touch of spacing can't hurt
881 for ( i = 1; i < 4; i++ ) {
882 sprintf ( buffer, "Application-%u.note-%u", ui_selected -> ref -> subapp_number, i );
883 n = pnd_conf_get_as_char ( ui_selected -> ovrh, buffer );
887 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
888 rtext = TTF_RenderText_Blended ( g_detailtext_font, n, tmpfontcolor );
891 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
893 dest -> x = cell_offset_x;
895 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
896 SDL_FreeSurface ( rtext );
902 } // r_detail -> notes
905 mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
906 SDL_Surface *previewpic;
909 previewpic = ic -> i;
911 previewpic = g_imagecache [ IMG_PREVIEW_MISSING ].i;
915 dest -> x = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_x", 50 ) +
916 ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
917 dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
918 SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
922 } // r_detail && selected?
928 if ( render_jobs_b & R_BG ) {
929 static int last_battlevel = 0;
930 static unsigned char batterylevel = 0;
933 if ( time ( NULL ) - last_battlevel > 60 ) {
934 batterylevel = pnd_device_get_battery_gauge_perc();
935 last_battlevel = time ( NULL );
938 sprintf ( buffer, "Battery: %u%%", batterylevel );
941 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
942 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
943 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.battery_x", 20 );
944 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.battery_y", 450 );
945 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
946 SDL_FreeSurface ( rtext );
951 if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
953 unsigned int hintx, hinty;
954 hintx = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
955 hinty = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
956 static unsigned int lastwidth = 3000;
958 if ( ui_selected && ui_selected -> ref -> info_filename ) {
959 buffer = "Documentation - hit Y";
961 buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
965 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
966 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
969 if ( ! ( render_jobs_b & R_BG ) ) {
976 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, &src, sdl_realscreen, dest );
978 lastwidth = rtext -> w;
984 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
985 SDL_FreeSurface ( rtext );
990 if ( render_jobs_b & R_BG &&
991 pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 )
995 time_t t = time ( NULL );
996 struct tm *tm = localtime ( &t );
997 strftime ( buffer, 50, "%a %H:%M %F", tm );
1000 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1001 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
1002 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.clock_x", 700 );
1003 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.clock_y", 450 );
1004 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1005 SDL_FreeSurface ( rtext );
1009 // update all the rects and send it all to sdl
1010 // - at this point, we could probably just do 1 rect, of the
1011 // whole screen, and be faster :/
1012 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1016 void ui_process_input ( unsigned char block_p ) {
1019 unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
1020 //static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
1022 while ( ! ui_event &&
1023 block_p ? SDL_WaitEvent ( &event ) : SDL_PollEvent ( &event ) )
1026 switch ( event.type ) {
1031 if ( event.user.code == sdl_user_ticker ) {
1033 // timer went off, time to load something
1034 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1036 // load the preview pics now!
1037 pnd_disco_t *iter = ui_selected -> ref;
1039 if ( iter -> preview_pic1 ) {
1041 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.threaded_preview", 0 ) ) {
1042 // load in bg thread, make user experience chuggy
1044 g_preview_thread = SDL_CreateThread ( (void*)ui_threaded_defered_preview, iter );
1046 if ( ! g_preview_thread ) {
1047 pnd_log ( pndn_error, "ERROR: Couldn't create preview thread\n" );
1051 // load it now, make user wait
1053 if ( ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
1054 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
1057 pnd_log ( pndn_debug, " Couldn't load preview pic: '%s' -> '%s'\n",
1058 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1063 } // got a preview at all?
1068 } else if ( event.user.code == sdl_user_finishedpreview ) {
1070 // if we just finished the one we happen to be looking at, better redraw now; otherwise, if
1071 // we finished another, no big woop
1072 if ( ui_selected && event.user.data1 == ui_selected -> ref ) {
1076 } else if ( event.user.code == sdl_user_finishedicon ) {
1077 // redraw, so we can show the newly loaded icon
1082 render_mask |= CHANGED_EVERYTHING;
1086 #if 0 // joystick motion
1087 case SDL_JOYAXISMOTION:
1089 pnd_log ( PND_LOG_DEFAULT, "joystick axis\n" );
1091 if ( event.jaxis.axis == 0 ) {
1093 if ( event.jaxis.value < 0 ) {
1095 pnd_log ( PND_LOG_DEFAULT, "joystick axis - LEFT\n" );
1096 } else if ( event.jaxis.value > 0 ) {
1097 ui_push_right ( 0 );
1098 pnd_log ( PND_LOG_DEFAULT, "joystick axis - RIGHT\n" );
1100 } else if ( event.jaxis.axis == 1 ) {
1102 if ( event.jaxis.value < 0 ) {
1104 } else if ( event.jaxis.value > 0 ) {
1114 #if 0 // joystick buttons
1115 case SDL_JOYBUTTONDOWN:
1117 pnd_log ( PND_LOG_DEFAULT, "joystick button down %u\n", event.jbutton.button );
1119 if ( event.jbutton.button == 0 ) { // B
1121 } else if ( event.jbutton.button == 1 ) { // Y
1123 } else if ( event.jbutton.button == 2 ) { // X
1125 } else if ( event.jbutton.button == 3 ) { // A
1128 } else if ( event.jbutton.button == 4 ) { // Select
1129 ui_mask |= uisb_select;
1130 } else if ( event.jbutton.button == 5 ) { // Start
1131 ui_mask |= uisb_start;
1133 } else if ( event.jbutton.button == 7 ) { // L
1135 } else if ( event.jbutton.button == 8 ) { // R
1144 case SDL_JOYBUTTONUP:
1146 pnd_log ( PND_LOG_DEFAULT, "joystick button up %u\n", event.jbutton.button );
1148 if ( event.jbutton.button == 0 ) { // B
1151 } else if ( event.jbutton.button == 1 ) { // Y
1153 } else if ( event.jbutton.button == 2 ) { // X
1155 } else if ( event.jbutton.button == 3 ) { // A
1158 } else if ( event.jbutton.button == 4 ) { // Select
1159 ui_mask &= ~uisb_select;
1160 } else if ( event.jbutton.button == 5 ) { // Start
1161 ui_mask &= ~uisb_start;
1163 } else if ( event.jbutton.button == 7 ) { // L
1166 } else if ( event.jbutton.button == 8 ) { // R
1177 #if 1 // keyboard events
1180 //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
1182 // SDLK_LALT -> Start
1185 if ( event.key.keysym.sym == SDLK_RIGHT ) {
1186 ui_push_right ( 0 );
1188 } else if ( event.key.keysym.sym == SDLK_LEFT ) {
1191 } else if ( event.key.keysym.sym == SDLK_UP ) {
1194 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1197 } else if ( event.key.keysym.sym == SDLK_SPACE || event.key.keysym.sym == SDLK_END ) {
1200 } else if ( event.key.keysym.sym == SDLK_RSHIFT ) {
1203 } else if ( event.key.keysym.sym == SDLK_RCTRL ) {
1206 } else if ( event.key.keysym.sym == SDLK_PAGEUP ) {
1208 if ( ui_selected ) {
1209 ui_show_info ( pnd_run_script, ui_selected -> ref );
1213 } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
1217 } else if ( event.key.keysym.sym == SDLK_LCTRL /*LALT*/ ) { // select button
1218 char *opts [ 20 ] = {
1219 "Reveal hidden category",
1221 "Rescan for applications",
1222 "Cache previews to SD now",
1223 "Run a terminal/console",
1224 "Run another GUI (xfce, etc)",
1226 "Select a Minimenu skin",
1229 int sel = ui_modal_single_menu ( opts, 9, "Minimenu", "Enter to select; other to return." );
1231 char buffer [ 100 ];
1235 } else if ( sel == 1 ) {
1237 sprintf ( buffer, "sudo poweroff" );
1239 } else if ( sel == 2 ) {
1241 pnd_log ( pndn_debug, "Freeing up applications\n" );
1242 applications_free();
1243 pnd_log ( pndn_debug, "Rescanning applications\n" );
1244 applications_scan();
1245 } else if ( sel == 3 ) {
1246 // cache preview to SD now
1247 extern pnd_box_handle g_active_apps;
1248 pnd_box_handle h = g_active_apps;
1250 unsigned int maxwidth, maxheight;
1251 maxwidth = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 );
1252 maxheight = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 );
1254 pnd_disco_t *iter = pnd_box_get_head ( h );
1259 if ( ! cache_preview ( iter, maxwidth, maxheight ) ) {
1260 pnd_log ( pndn_debug, "Force cache: Couldn't load preview pic: '%s' -> '%s'\n",
1261 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1265 iter = pnd_box_get_next ( iter );
1268 } else if ( sel == 4 ) {
1271 argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
1275 ui_forkexec ( argv );
1278 } else if ( sel == 5 ) {
1279 char buffer [ PATH_MAX ];
1280 sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/pandora/scripts/op_switchgui.sh" );
1281 emit_and_quit ( buffer );
1282 } else if ( sel == 6 ) {
1283 emit_and_quit ( MM_QUIT );
1284 } else if ( sel == 7 ) {
1286 if ( ui_pick_skin() ) {
1287 emit_and_quit ( MM_RESTART );
1289 } else if ( sel == 8 ) {
1291 char buffer [ PATH_MAX ];
1292 sprintf ( buffer, "%s/about.txt", g_skinpath );
1293 ui_aboutscreen ( buffer );
1297 render_mask |= CHANGED_EVERYTHING;
1300 // unknown SDLK_ keycode?
1302 // many SDLK_keycodes map to ASCII ("a" is ascii(a)), so try to jump to a filename of that name, in this category?
1303 // and if already there, try to jump to next, maybe?
1304 // future: look for sequence typing? ie: user types 'm' then 'a', look for 'ma*' instead of 'm' then 'a' matching
1305 if ( isalpha ( event.key.keysym.sym ) && g_categories [ ui_category ].refcount > 0 ) {
1306 mm_appref_t *app = g_categories [ ui_category ].refs;
1308 //fprintf ( stderr, "sel %s next %s\n", ui_selected -> ref -> title_en, ui_selected -> next -> ref -> title_en );
1310 // are we already matching the same char? and next item is also same char?
1311 if ( app && ui_selected &&
1312 ui_selected -> ref -> title_en && ui_selected -> next -> ref -> title_en &&
1313 toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( ui_selected -> next -> ref -> title_en [ 0 ] ) &&
1314 toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym )
1317 // just skip down one
1318 app = ui_selected -> next;
1321 // walk the category, looking for a first-char match
1323 if ( app -> ref -> title_en && toupper ( app -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym ) ) {
1329 } // same start letter, or new run?
1331 // found something, or no?
1333 // looks like we found a potential match; try switching it to visible selection
1335 ui_set_selected ( ui_selected );
1342 } // SDLK_alphanumeric?
1348 if ( event.key.keysym.sym == SDLK_q ) {
1349 emit_and_quit ( MM_QUIT );
1356 #if 1 // mouse / touchscreen
1358 case SDL_MOUSEBUTTONDOWN:
1359 if ( event.button.button == SDL_BUTTON_LEFT ) {
1360 cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
1366 case SDL_MOUSEBUTTONUP:
1367 if ( event.button.button == SDL_BUTTON_LEFT ) {
1368 ui_touch_act ( event.button.x, event.button.y );
1381 } // switch event type
1388 void ui_push_left ( unsigned char forcecoil ) {
1390 if ( ! ui_selected ) {
1391 ui_push_right ( 0 );
1395 // what column we in?
1396 unsigned int col = ui_determine_screen_col ( ui_selected );
1398 // are we already at first item?
1399 if ( forcecoil == 0 &&
1400 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1403 unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1404 while ( i && ui_selected -> next ) {
1405 ui_push_right ( 0 );
1409 } else if ( g_categories [ ui_category ].refs == ui_selected ) {
1410 // can't go any more left, we're at the head
1413 // figure out the previous item; yay for singly linked list :/
1414 mm_appref_t *i = g_categories [ ui_category ].refs;
1416 if ( i -> next == ui_selected ) {
1424 ui_set_selected ( ui_selected );
1429 void ui_push_right ( unsigned char forcecoil ) {
1431 if ( ui_selected ) {
1433 // what column we in?
1434 unsigned int col = ui_determine_screen_col ( ui_selected );
1437 if ( forcecoil == 0 &&
1438 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1439 // and selected is far-right, or last icon in category (might not be far right)
1440 ( ( col == pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1 ) ||
1441 ( ui_selected -> next == NULL ) )
1445 //unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1446 while ( col /*i*/ ) {
1452 // just go to the next
1454 if ( ui_selected -> next ) {
1455 ui_selected = ui_selected -> next;
1461 ui_selected = g_categories [ ui_category ].refs;
1464 ui_set_selected ( ui_selected );
1469 void ui_push_up ( void ) {
1470 unsigned char col_max = pnd_conf_get_as_int ( g_conf, "grid.col_max" );
1472 if ( ! ui_selected ) {
1477 unsigned int row = ui_determine_row ( ui_selected );
1480 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 1 ) == 0 )
1482 // wrap around instead
1484 unsigned int col = ui_determine_screen_col ( ui_selected );
1487 ui_selected = g_categories [ ui_category ].refs;
1488 while ( ui_selected -> next ) {
1489 ui_selected = ui_selected -> next;
1492 // try to move to same column
1493 unsigned int newcol = ui_determine_screen_col ( ui_selected );
1494 if ( newcol > col ) {
1502 // scroll down to show it
1503 int r = ui_determine_row ( ui_selected ) - 1;
1504 if ( r - pnd_conf_get_as_int ( g_conf, "grid.row_max" ) > 0 ) {
1505 ui_rows_scrolled_down = (unsigned int) r;
1509 // stop at top/bottom
1521 void ui_push_down ( void ) {
1522 unsigned char col_max = pnd_conf_get_as_int ( g_conf, "grid.col_max" );
1524 if ( ui_selected ) {
1527 unsigned int row = ui_determine_row ( ui_selected );
1530 unsigned int icon_rows = g_categories [ ui_category ].refcount / col_max;
1531 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
1536 if ( row == ( icon_rows - 1 ) &&
1537 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 1 ) == 0 )
1540 unsigned char col = ui_determine_screen_col ( ui_selected );
1542 ui_selected = g_categories [ ui_category ].refs;
1545 ui_selected = ui_selected -> next;
1549 ui_rows_scrolled_down = 0;
1551 render_mask |= CHANGED_EVERYTHING;
1556 ui_push_right ( 1 );
1563 ui_push_right ( 0 );
1569 void ui_push_exec ( void ) {
1571 if ( ! ui_selected ) {
1575 // was this icon generated from filesystem, or from pnd-file?
1576 if ( ui_selected -> ref -> object_flags & PND_DISCO_GENERATED ) {
1578 if ( ! ui_selected -> ref -> title_en ) {
1579 return; // no filename
1582 if ( ui_selected -> ref -> object_type == pnd_object_type_directory ) {
1583 // delve up/down the dir tree
1585 if ( strcmp ( ui_selected -> ref -> title_en, ".." ) == 0 ) {
1589 // lop off last word; if the thing ends with /, lop that one, then the next word.
1590 while ( ( c = strrchr ( g_categories [ ui_category].fspath, '/' ) ) ) {
1591 *c = '\0'; // lop off the last hunk
1592 if ( *(c+1) != '\0' ) {
1598 if ( g_categories [ ui_category].fspath [ 0 ] == '\0' ) {
1599 strcpy ( g_categories [ ui_category].fspath, "/" );
1604 strcat ( g_categories [ ui_category].fspath, "/" );
1605 strcat ( g_categories [ ui_category].fspath, ui_selected -> ref -> title_en );
1608 pnd_log ( pndn_debug, "Cat %s is now in path %s\n", g_categories [ ui_category ].catname, g_categories [ ui_category ].fspath );
1611 category_fs_restock ( &(g_categories [ ui_category]) );
1612 // forget the selection, nolonger applies
1614 ui_set_selected ( ui_selected );
1616 render_mask |= CHANGED_SELECTION;
1619 // just run it arbitrarily?
1621 // if this a pnd-file, or just some executable?
1622 if ( strcasestr ( ui_selected -> ref -> object_filename, PND_PACKAGE_FILEEXT ) ) {
1623 // looks like a pnd, now what do we do..
1624 pnd_box_handle h = pnd_disco_file ( ui_selected -> ref -> object_path, ui_selected -> ref -> object_filename );
1627 pnd_disco_t *d = pnd_box_get_head ( h );
1628 pnd_apps_exec_disco ( pnd_run_script, d, PND_EXEC_OPTION_NORUN, NULL );
1629 char buffer [ PATH_MAX ];
1630 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1631 emit_and_quit ( buffer );
1637 char cwd [ PATH_MAX ];
1638 getcwd ( cwd, PATH_MAX );
1640 chdir ( g_categories [ ui_category ].fspath );
1641 pnd_exec_no_wait_1 ( ui_selected -> ref -> title_en, NULL );
1644 char buffer [ PATH_MAX ];
1645 sprintf ( buffer, "%s %s/%s\n", MM_RUN, g_categories [ ui_category ].fspath, ui_selected -> ref -> title_en );
1646 emit_and_quit ( buffer );
1653 pnd_apps_exec_disco ( pnd_run_script, ui_selected -> ref, PND_EXEC_OPTION_NORUN, NULL );
1654 char buffer [ PATH_MAX ];
1655 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1656 emit_and_quit ( buffer );
1662 void ui_push_ltrigger ( void ) {
1663 unsigned char oldcat = ui_category;
1664 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
1665 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1667 if ( g_categorycount == 0 ) {
1671 if ( ui_category > 0 ) {
1673 category_fs_restock ( &(g_categories [ ui_category ]) );
1675 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1676 ui_category = g_categorycount - 1;
1678 if ( ui_category >= ( screen_width / tab_width ) ) {
1679 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
1681 category_fs_restock ( &(g_categories [ ui_category ]) );
1685 if ( oldcat != ui_category ) {
1687 ui_set_selected ( ui_selected );
1690 // make tab visible?
1691 if ( ui_catshift > 0 && ui_category == ui_catshift - 1 ) {
1696 ui_rows_scrolled_down = 0;
1698 render_mask |= CHANGED_CATEGORY;
1703 void ui_push_rtrigger ( void ) {
1704 unsigned char oldcat = ui_category;
1706 if ( g_categorycount == 0 ) {
1710 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
1711 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1713 if ( ui_category < ( g_categorycount - 1 ) ) {
1715 category_fs_restock ( &(g_categories [ ui_category ]) );
1717 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1720 category_fs_restock ( &(g_categories [ ui_category ]) );
1724 if ( oldcat != ui_category ) {
1726 ui_set_selected ( ui_selected );
1729 // make tab visible?
1730 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
1735 ui_rows_scrolled_down = 0;
1737 render_mask |= CHANGED_CATEGORY;
1742 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ) {
1743 double scale = 1000000.0;
1744 double scalex = 1000000.0;
1745 double scaley = 1000000.0;
1746 SDL_Surface *scaled;
1748 scalex = (double)maxwidth / (double)s -> w;
1750 if ( maxheight == -1 ) {
1753 scaley = (double)maxheight / (double)s -> h;
1755 if ( scaley < scalex ) {
1763 scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
1764 SDL_FreeSurface ( s );
1770 void ui_loadscreen ( void ) {
1774 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1775 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1776 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1777 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1780 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1784 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1785 rtext = TTF_RenderText_Blended ( g_big_font, "Setting up menu...", tmpfontcolor );
1788 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1789 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1790 SDL_FreeSurface ( rtext );
1795 void ui_discoverscreen ( unsigned char clearscreen ) {
1799 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1800 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1801 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1802 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1805 if ( clearscreen ) {
1806 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1808 // render background
1809 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1812 dest.w = sdl_realscreen -> w;
1813 dest.h = sdl_realscreen -> h;
1814 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1815 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1822 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1823 rtext = TTF_RenderText_Blended ( g_big_font, "Looking for applications...", tmpfontcolor );
1824 if ( clearscreen ) {
1831 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1832 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1833 SDL_FreeSurface ( rtext );
1836 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1837 dest.x = rtext -> w + 30;
1839 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, &dest );
1840 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1846 void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
1848 SDL_Rect rects [ 4 ];
1849 SDL_Rect *dest = rects;
1851 bzero ( dest, sizeof(SDL_Rect)* 4 );
1853 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1854 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1855 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1856 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1858 static unsigned int stepx = 0;
1861 if ( clearscreen ) {
1862 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1864 // render background
1865 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1868 dest -> w = sdl_realscreen -> w;
1869 dest -> h = sdl_realscreen -> h;
1870 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1876 // render background
1877 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1880 src.w = sdl_realscreen -> w;
1884 dest -> w = sdl_realscreen -> w;
1885 dest -> h = sdl_realscreen -> h;
1886 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
1894 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1895 rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
1898 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1899 SDL_FreeSurface ( rtext );
1903 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1904 dest -> x = rtext -> w + 30 + stepx;
1906 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, dest );
1912 rtext = TTF_RenderText_Blended ( g_tab_font, filename, tmpfontcolor );
1915 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1916 SDL_FreeSurface ( rtext );
1923 if ( stepx > 350 ) {
1927 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1932 int ui_selected_index ( void ) {
1934 if ( ! ui_selected ) {
1935 return ( -1 ); // no index
1938 mm_appref_t *r = g_categories [ ui_category ].refs;
1941 if ( r == ui_selected ) {
1951 static mm_appref_t *timer_ref = NULL;
1952 void ui_set_selected ( mm_appref_t *r ) {
1954 render_mask |= CHANGED_SELECTION;
1956 if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1957 return; // no desire to defer anything
1962 SDL_SetTimer ( 0, NULL );
1967 SDL_SetTimer ( pnd_conf_get_as_int_d ( g_conf, "previewpic.defer_timer_ms", 1000 ), ui_callback_f );
1973 unsigned int ui_callback_f ( unsigned int t ) {
1975 if ( ui_selected != timer_ref ) {
1976 return ( 0 ); // user has moved it, who cares
1980 bzero ( &e, sizeof(SDL_Event) );
1981 e.type = SDL_USEREVENT;
1982 e.user.code = sdl_user_ticker;
1983 SDL_PushEvent ( &e );
1988 int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer ) {
1989 SDL_Rect rects [ 40 ];
1990 SDL_Rect *dest = rects;
1993 unsigned char max_visible = pnd_conf_get_as_int_d ( g_conf, "detailtext.max_visible" , 11 );
1994 unsigned char first_visible = 0;
1996 bzero ( rects, sizeof(SDL_Rect) * 40 );
1998 unsigned int sel = 0;
2000 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
2001 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
2002 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
2003 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
2005 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
2007 SDL_Color selfontcolor = { 0/*font_rgba_r*/, font_rgba_g, font_rgba_b, font_rgba_a };
2015 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2016 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2017 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
2018 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
2019 SDL_FillRect( sdl_realscreen, dest, 0 );
2021 // show dialog background
2022 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
2023 src.x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2024 src.y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2025 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
2026 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
2027 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2028 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2029 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2030 // repeat for darken?
2031 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2032 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2033 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2037 // show dialog frame
2038 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
2039 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2040 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2041 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
2042 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2048 rtext = TTF_RenderText_Blended ( g_tab_font, title, tmpfontcolor );
2049 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2050 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
2051 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2052 SDL_FreeSurface ( rtext );
2058 rtext = TTF_RenderText_Blended ( g_tab_font, footer, tmpfontcolor );
2059 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2060 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
2061 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
2063 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2064 SDL_FreeSurface ( rtext );
2069 for ( i = first_visible; i < first_visible + max_visible && i < argc; i++ ) {
2073 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
2075 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], tmpfontcolor );
2077 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2078 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 - first_visible ) );
2079 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2080 SDL_FreeSurface ( rtext );
2085 // update all the rects and send it all to sdl
2086 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
2090 while ( SDL_WaitEvent ( &event ) ) {
2092 switch ( event.type ) {
2096 if ( event.key.keysym.sym == SDLK_UP ) {
2100 if ( sel < first_visible ) {
2105 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
2107 if ( sel < argc - 1 ) {
2110 // ensure visibility
2111 if ( sel >= first_visible + max_visible ) {
2117 } else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_END ) { // return, or "B"
2121 } else if ( event.key.keysym.sym == SDLK_q ) {
2126 return ( -1 ); // nada
2141 unsigned char ui_determine_row ( mm_appref_t *a ) {
2142 unsigned int row = 0;
2144 mm_appref_t *i = g_categories [ ui_category ].refs;
2149 row /= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
2154 unsigned char ui_determine_screen_row ( mm_appref_t *a ) {
2155 return ( ui_determine_row ( a ) % pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 5 ) );
2158 unsigned char ui_determine_screen_col ( mm_appref_t *a ) {
2159 unsigned int col = 0;
2161 mm_appref_t *i = g_categories [ ui_category ].refs;
2166 col %= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
2171 unsigned char ui_show_info ( char *pndrun, pnd_disco_t *p ) {
2172 char *viewer, *searchpath;
2173 pnd_conf_handle desktoph;
2176 searchpath = pnd_conf_query_searchpath();
2178 desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
2184 viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
2187 return ( 0 ); // no way to view the file
2191 if ( ! p -> unique_id ) {
2195 if ( ! p -> info_filename ) {
2199 if ( ! p -> info_name ) {
2210 if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) {
2211 snprintf ( pargs, 1001, "%s %s",
2212 pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
2217 char pndfile [ 1024 ];
2218 if ( p -> object_type == pnd_object_type_directory ) {
2219 // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
2220 strncpy ( pndfile, p -> object_path, 1000 );
2221 } else if ( p -> object_type == pnd_object_type_pnd ) {
2222 // pnd_run.sh wants the full path and filename for the .pnd file
2223 snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
2226 if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs,
2227 p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) )
2232 pnd_log ( pndn_debug, "Info Exec=%s\n", pnd_apps_exec_runline() );
2236 if ( ( x = fork() ) < 0 ) {
2237 pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
2242 execl ( "/bin/sh", "/bin/sh", "-c", pnd_apps_exec_runline(), (char*)NULL );
2243 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", pnd_apps_exec_runline() );
2255 #define MAXTOUCH 100
2256 ui_touch_t ui_touchrects [ MAXTOUCH ];
2257 unsigned char ui_touchrect_count = 0;
2259 void ui_register_reset ( void ) {
2260 bzero ( ui_touchrects, sizeof(ui_touch_t)*MAXTOUCH );
2261 ui_touchrect_count = 0;
2265 void ui_register_tab ( unsigned char catnum, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2267 if ( ui_touchrect_count == MAXTOUCH ) {
2271 ui_touchrects [ ui_touchrect_count ].r.x = x;
2272 ui_touchrects [ ui_touchrect_count ].r.y = y;
2273 ui_touchrects [ ui_touchrect_count ].r.w = w;
2274 ui_touchrects [ ui_touchrect_count ].r.h = h;
2275 ui_touchrects [ ui_touchrect_count ].catnum = catnum;
2276 ui_touchrect_count++;
2281 void ui_register_app ( mm_appref_t *app, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2283 if ( ui_touchrect_count == MAXTOUCH ) {
2287 ui_touchrects [ ui_touchrect_count ].r.x = x;
2288 ui_touchrects [ ui_touchrect_count ].r.y = y;
2289 ui_touchrects [ ui_touchrect_count ].r.w = w;
2290 ui_touchrects [ ui_touchrect_count ].r.h = h;
2291 ui_touchrects [ ui_touchrect_count ].ref = app;
2292 ui_touchrect_count++;
2297 void ui_touch_act ( unsigned int x, unsigned int y ) {
2302 for ( i = 0; i < ui_touchrect_count; i++ ) {
2303 t = &(ui_touchrects [ i ]);
2305 if ( x >= t -> r.x &&
2306 x <= t -> r.x + t -> r.w &&
2308 y <= t -> r.y + t -> r.h
2313 ui_selected = t -> ref;
2316 if ( ui_category != t -> catnum ) {
2319 ui_category = t -> catnum;
2320 render_mask |= CHANGED_CATEGORY;
2331 unsigned char ui_forkexec ( char *argv[] ) {
2332 char *fooby = argv[0];
2335 if ( ( x = fork() ) < 0 ) {
2336 pnd_log ( pndn_error, "ERROR: Couldn't fork() for '%s'\n", fooby );
2340 if ( x == 0 ) { // child
2341 execv ( fooby, argv );
2342 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", fooby );
2350 unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ) {
2352 if ( ! cache_preview ( p, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
2353 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
2356 pnd_log ( pndn_debug, "THREAD: Couldn't load preview pic: '%s' -> '%s'\n",
2357 IFNULL(p->title_en,"No Name"), p -> preview_pic1 );
2360 // trigger that we completed
2362 bzero ( &e, sizeof(SDL_Event) );
2363 e.type = SDL_USEREVENT;
2364 e.user.code = sdl_user_finishedpreview;
2366 SDL_PushEvent ( &e );
2371 SDL_Thread *g_icon_thread = NULL;
2372 void ui_post_scan ( void ) {
2374 // if deferred icon load, kick off the thread now
2375 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 1 ) {
2377 g_icon_thread = SDL_CreateThread ( (void*)ui_threaded_defered_icon, NULL );
2379 if ( ! g_icon_thread ) {
2380 pnd_log ( pndn_error, "ERROR: Couldn't create icon thread\n" );
2383 } // deferred icon load
2387 ui_rows_scrolled_down = 0;
2388 // set back to first tab, to be safe
2392 // do we have a preferred category to jump to?
2393 char *dc = pnd_conf_get_as_char ( g_conf, "categories.default_cat" );
2396 // attempt to find default cat; if we do find it, select it; otherwise
2397 // default behaviour will pick first cat (ie: usually All)
2399 for ( i = 0; i < g_categorycount; i++ ) {
2400 if ( strcasecmp ( g_categories [ i ].catname, dc ) == 0 ) {
2402 // ensure visibility
2403 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
2404 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2405 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
2406 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
2412 if ( i == g_categorycount ) {
2413 pnd_log ( pndn_warning, " User defined default category '%s' but not found, so using default behaviour\n", dc );
2419 render_mask |= CHANGED_EVERYTHING;
2424 unsigned char ui_threaded_defered_icon ( void *p ) {
2425 extern pnd_box_handle g_active_apps;
2426 pnd_box_handle h = g_active_apps;
2428 unsigned char maxwidth, maxheight;
2429 maxwidth = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 );
2430 maxheight = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_height", 50 );
2432 pnd_disco_t *iter = pnd_box_get_head ( h );
2437 if ( iter -> pnd_icon_pos &&
2438 ! cache_icon ( iter, maxwidth, maxheight ) )
2440 pnd_log ( pndn_warning, " Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2443 // trigger that we completed
2445 bzero ( &e, sizeof(SDL_Event) );
2446 e.type = SDL_USEREVENT;
2447 e.user.code = sdl_user_finishedicon;
2448 SDL_PushEvent ( &e );
2450 //pnd_log ( pndn_warning, " Finished deferred load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2451 usleep ( pnd_conf_get_as_int_d ( g_conf, "minimenu.defer_icon_us", 50000 ) );
2456 iter = pnd_box_get_next ( iter );
2462 void ui_show_hourglass ( unsigned char updaterect ) {
2465 SDL_Surface *s = g_imagecache [ IMG_HOURGLASS ].i;
2467 dest.x = ( 800 - s -> w ) / 2;
2468 dest.y = ( 480 - s -> h ) / 2;
2470 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, &dest );
2473 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2479 unsigned char ui_pick_skin ( void ) {
2481 char *skins [ MAXSKINS ];
2484 char *searchpath = pnd_conf_get_as_char ( g_conf, "minimenu.skin_searchpath" );
2485 char tempname [ 100 ];
2489 skins [ iter++ ] = "No skin change";
2493 DIR *d = opendir ( buffer );
2498 while ( ( dd = readdir ( d ) ) ) {
2500 if ( dd -> d_name [ 0 ] == '.' ) {
2502 } else if ( ( dd -> d_type == DT_DIR || dd -> d_type == DT_UNKNOWN ) &&
2505 snprintf ( tempname, 100, "Skin: %s", dd -> d_name );
2506 skins [ iter++ ] = strdup ( tempname );
2517 int sel = ui_modal_single_menu ( skins, iter, "Skins", "Enter to select; other to return." );
2519 // did they pick one?
2523 char *s = strdup ( pnd_conf_get_as_char ( g_conf, "minimenu.skin_selected" ) );
2524 s = pnd_expand_tilde ( s );
2526 f = fopen ( s, "w" );
2531 fprintf ( f, "%s\n", skins [ sel ] + 6 );
2541 void ui_aboutscreen ( char *textpath ) {
2548 #define ROWS SCRH / ( PIXELH + MARGINH )
2549 #define COLS SCRW / ( PIXELW + MARGINW )
2551 unsigned char pixelboard [ ROWS * COLS ]; // pixel heat
2552 bzero ( pixelboard, ROWS * COLS );
2557 SDL_Color rtextc = { 200, 200, 200, 100 };
2560 char *textloop [ 500 ];
2561 unsigned int textmax = 0;
2562 bzero ( textloop, 500 * sizeof(char*) );
2565 char cbuffer [ 50000 ];
2566 bzero ( cbuffer, 50000 );
2567 unsigned int crevealed = 0;
2569 FILE *f = fopen ( textpath, "r" );
2572 pnd_log ( pndn_error, "ERROR: Couldn't open about text: %s\n", textpath );
2576 char textbuf [ 100 ];
2577 while ( fgets ( textbuf, 100, f ) ) {
2579 // add to full buffer
2580 strncat ( cbuffer, textbuf, 50000 );
2583 if ( strchr ( textbuf, '\n' ) ) {
2584 * strchr ( textbuf, '\n' ) = '\0';
2587 // add to pixel loop
2588 if ( 1||textbuf [ 0 ] ) {
2589 textloop [ textmax ] = strdup ( textbuf );
2597 unsigned int textiter = 0;
2598 while ( textiter < textmax ) {
2599 char *text = textloop [ textiter ];
2603 // render to surface
2604 rtext = TTF_RenderText_Blended ( g_grid_font, text, rtextc );
2606 // render font to pixelboard
2607 unsigned int px, py;
2609 unsigned int *pixels = rtext -> pixels;
2610 unsigned char cr, cg, cb, ca;
2611 for ( py = 0; py < rtext -> h; py ++ ) {
2612 for ( px = 0; px < ( rtext -> w > COLS ? COLS : rtext -> w ); px++ ) {
2614 SDL_GetRGBA ( pixels [ ( py * rtext -> pitch / 4 ) + px ],
2615 rtext -> format, &cr, &cg, &cb, &ca );
2619 ph = pixelboard + ( /*y offset */ 30 * COLS ) + ( py * COLS ) + px /* / 2 */;
2626 if ( *ph + ca < 250 ) {
2637 unsigned int runcount = 10;
2638 while ( runcount-- ) {
2641 SDL_FillRect( sdl_realscreen, NULL /* whole */, 0 );
2643 // render pixelboard
2646 for ( y = 0; y < ROWS; y++ ) {
2647 for ( x = 0; x < COLS; x++ ) {
2649 if ( 1||pixelboard [ ( y * COLS ) + x ] ) {
2652 r.x = x * ( PIXELW + MARGINW );
2653 r.y = y * ( PIXELH + MARGINH );
2657 c = SDL_MapRGB ( sdl_realscreen -> format, 100 /* r */, 0 /* g */, pixelboard [ ( y * COLS ) + x ] );
2659 SDL_FillRect( sdl_realscreen, &r /* whole */, c );
2667 unsigned char *pc = pixelboard;
2668 for ( y = 0; y < ROWS; y++ ) {
2669 for ( x = 0; x < COLS; x++ ) {
2679 // slide pixels upwards
2680 memmove ( pixelboard, pixelboard + COLS, ( COLS * ROWS ) - COLS );
2682 // render actual readable text
2685 // display up to cursor
2687 unsigned int cdraw = 0;
2691 if ( crevealed > 200 ) {
2692 cdraw = crevealed - 200;
2698 for ( ; cdraw < crevealed; cdraw++ ) {
2699 ctb [ 0 ] = cbuffer [ cdraw ];
2701 // move over or down
2702 if ( cbuffer [ cdraw ] == '\n' ) {
2707 if ( dest.y > 450 ) {
2713 cs = TTF_RenderText_Blended ( g_tab_font, ctb, rtextc );
2715 SDL_BlitSurface ( cs, NULL /* all */, sdl_realscreen, &dest );
2716 SDL_FreeSurface ( cs );
2726 SDL_FillRect ( sdl_realscreen, &dest /* whole */, 220 );
2728 // increment cursor to next character
2729 if ( cbuffer [ crevealed ] != '\0' ) {
2733 } // draw cursor text
2737 SDL_UpdateRect ( sdl_realscreen, 0, 0, 0, 0 ); // whole screen
2741 // any button? if so, about
2747 if ( SDL_PeepEvents ( &e, 1, SDL_GETEVENT, SDL_EVENTMASK(SDL_KEYUP) ) > 0 ) {
2756 SDL_FreeSurface ( rtext );
2760 } // while more text
2764 for ( i = 0; i < textmax; i++ ) {
2765 if ( textloop [ i ] ) {
2766 free ( textloop [ i ] );
2774 void ui_revealscreen ( void ) {
2775 char *labels [ 500 ];
2776 unsigned int labelmax = 0;
2779 if ( ! _categories_inviscount ) {
2780 return; // nothing to do
2783 for ( i = 0; i < _categories_inviscount; i++ ) {
2784 labels [ labelmax++ ] = _categories_invis [ i ].catname;
2787 int sel = ui_modal_single_menu ( labels, labelmax, "Temporary Category Reveal",
2788 "Enter to select; other to return." );
2792 if ( category_query ( _categories_invis [ sel ].catname ) ) {
2797 // fix up category name, if its been hacked
2798 if ( strchr ( _categories_invis [ sel ].catname, '.' ) ) {
2799 char *t = _categories_invis [ sel ].catname;
2800 _categories_invis [ sel ].catname = strdup ( strchr ( _categories_invis [ sel ].catname, '.' ) + 1 );
2803 // copy invisi-cat into live-cat
2804 memmove ( &(g_categories [ g_categorycount ]), &(_categories_invis [ sel ]), sizeof(mm_category_t) );
2806 // move subsequent invisi-cats up, so the selected invisi-cat is nolonger existing in invisi-list at
2807 // all (avoid double-free() later)
2808 memmove ( &(_categories_invis [ sel ]), &(_categories_invis [ sel + 1 ]), sizeof(mm_category_t) * ( _categories_inviscount - sel - 1 ) );
2809 _categories_inviscount--;
2811 // switch to the new category
2812 ui_category = g_categorycount - 1;
2814 // ensure visibility
2815 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
2816 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2817 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
2818 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
2822 render_mask |= CHANGED_CATEGORY;