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
370 // ensure selection is visible
373 int index = ui_selected_index();
374 int topleft = col_max * ui_rows_scrolled_down;
375 int botright = ( col_max * ( ui_rows_scrolled_down + row_max ) - 1 );
377 if ( index < topleft ) {
378 ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
379 render_jobs_b |= R_ALL;
380 } else if ( index > botright ) {
381 ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
382 render_jobs_b |= R_ALL;
385 if ( ui_rows_scrolled_down < 0 ) {
386 ui_rows_scrolled_down = 0;
387 } else if ( ui_rows_scrolled_down > icon_rows ) {
388 ui_rows_scrolled_down = icon_rows;
394 if ( render_jobs_b & R_BG ) {
396 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
399 dest -> w = sdl_realscreen -> w;
400 dest -> h = sdl_realscreen -> h;
401 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
406 if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
409 dest -> w = sdl_realscreen -> w;
410 dest -> h = sdl_realscreen -> h;
411 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
418 if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
419 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
420 unsigned int tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
421 //unsigned int tab_selheight = pnd_conf_get_as_int ( g_conf, "tabs.tab_selheight" );
422 unsigned int tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
423 unsigned int tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
424 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
425 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
426 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
427 unsigned int maxtab = ( screen_width / tab_width ) < g_categorycount ? ( screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift;
428 unsigned int maxtabspot = ( screen_width / tab_width );
430 if ( g_categorycount > 0 ) {
432 // draw tabs with categories
433 for ( col = ui_catshift;
440 // if this is the first (leftmost) tab, we use different artwork
441 // than if the other tabs (so skinner can link lines up nicely.)
442 if ( col == ui_catshift ) {
443 // leftmost tab, special case
445 if ( col == ui_category ) {
446 s = g_imagecache [ IMG_TAB_SEL_L ].i;
448 s = g_imagecache [ IMG_TAB_UNSEL_L ].i;
451 } else if ( col == maxtab - 1 ) {
452 // rightmost tab, special case
454 if ( col == ui_category ) {
455 s = g_imagecache [ IMG_TAB_SEL_R ].i;
457 s = g_imagecache [ IMG_TAB_UNSEL_R ].i;
461 // normal (not leftmost) tab
463 if ( col == ui_category ) {
464 s = g_imagecache [ IMG_TAB_SEL ].i;
466 s = g_imagecache [ IMG_TAB_UNSEL ].i;
469 } // first col, or not first col?
476 if ( col == ui_category ) {
477 src.h = tab_selheight;
485 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
486 dest -> y = tab_offset_y;
489 ui_register_tab ( col, dest -> x, dest -> y, tab_width, tab_height );
491 if ( render_jobs_b & R_TABS ) {
492 //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
493 SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
497 if ( col == ui_category ) {
498 // no line for selected tab
500 if ( col - ui_catshift == 0 ) {
501 s = g_imagecache [ IMG_TAB_LINEL ].i;
502 } else if ( col - ui_catshift == maxtabspot - 1 ) {
503 s = g_imagecache [ IMG_TAB_LINER ].i;
505 s = g_imagecache [ IMG_TAB_LINE ].i;
507 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
508 dest -> y = tab_offset_y + tab_height;
509 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
515 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
516 rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ].catname, tmpfontcolor );
519 src.w = rtext -> w < text_width ? rtext -> w : text_width;
521 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
522 dest -> y = tab_offset_y + text_offset_y;
523 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
524 SDL_FreeSurface ( rtext );
531 } // if we got categories
533 if ( render_jobs_b & R_TABS ) {
535 // draw tab lines under where tabs would be if we had categories
536 for ( /* foo */; col < maxtabspot; col++ ) {
539 if ( col - ui_catshift == 0 ) {
540 s = g_imagecache [ IMG_TAB_LINEL ].i;
541 } else if ( col - ui_catshift == maxtabspot - 1 ) {
542 s = g_imagecache [ IMG_TAB_LINER ].i;
544 s = g_imagecache [ IMG_TAB_LINE ].i;
546 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
547 dest -> y = tab_offset_y + tab_height;
548 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
557 // scroll bars and arrows
558 if ( render_jobs_b & R_BG ) {
559 unsigned char show_bar = 0;
562 if ( ui_rows_scrolled_down && g_imagecache [ IMG_ARROW_UP ].i ) {
563 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
564 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
565 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
572 if ( ui_rows_scrolled_down + row_max < icon_rows && g_imagecache [ IMG_ARROW_DOWN ].i ) {
573 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
574 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
575 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
582 // show scrollbar as well
585 src.w = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_w", 10 );
586 src.h = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_h", 100 );
587 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
588 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
589 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
593 } // r_bg, scroll bars
595 // render detail pane bg
596 if ( render_jobs_b & R_DETAIL ) {
598 if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
601 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
602 src.x = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
603 src.y = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
604 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
605 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
606 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
607 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
608 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
612 // render detail pane
613 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
614 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
615 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
616 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
620 } // detailpane frame/bg
624 // anything to render?
625 if ( render_jobs_b & R_GRID ) {
627 // if just rendering grid, and nothing else, better clear it first
628 if ( ! ( render_jobs_b & R_BG ) ) {
629 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
630 src.x = grid_offset_x;
631 src.y = grid_offset_y + sel_icon_offset_y;
632 src.w = col_max * cell_width;
633 src.h = row_max * cell_height;
635 dest -> x = grid_offset_x;
636 dest -> y = grid_offset_y + sel_icon_offset_y;
638 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
644 if ( g_categories [ ui_category ].refs ) {
646 appiter = g_categories [ ui_category ].refs;
650 // until we run out of apps, or run out of space
651 while ( appiter != NULL ) {
653 for ( col = 0; col < col_max && appiter != NULL; col++ ) {
655 // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
656 if ( row >= ui_rows_scrolled_down ) {
658 // selected? show hilights
659 if ( appiter == ui_selected ) {
660 SDL_Surface *s = g_imagecache [ IMG_SELECTED_ALPHAMASK ].i;
662 //dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + ( ( icon_max_width - s -> w ) / 2 );
663 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + sel_icon_offset_x;
664 //dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + ( ( icon_max_height - s -> h ) / 2 );
665 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + sel_icon_offset_y;
666 SDL_BlitSurface ( s, NULL /* all */, sdl_realscreen, dest );
669 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
670 dest -> y = grid_offset_y + ( displayrow * cell_height ) + pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
671 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
676 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
677 SDL_Surface *iconsurface;
679 iconsurface = ic -> i;
681 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
683 // no icon override; was this a pnd-file (show the unknown icon then), or was this generated from
684 // filesystem (file or directory icon)
685 if ( appiter -> ref -> object_flags & PND_DISCO_GENERATED ) {
686 if ( appiter -> ref -> object_type == pnd_object_type_directory ) {
687 iconsurface = g_imagecache [ IMG_FOLDER ].i;
689 iconsurface = g_imagecache [ IMG_EXECBIN ].i;
692 iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
697 // got an icon I hope?
699 //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
705 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + (( icon_max_width - iconsurface -> w ) / 2);
706 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + (( icon_max_height - iconsurface -> h ) / 2);
708 SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
711 ui_register_app ( appiter, dest -> x, dest -> y, src.w, src.h );
718 if ( appiter -> ref -> title_en ) {
720 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
721 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, tmpfontcolor );
724 src.w = text_width < rtext -> w ? text_width : rtext -> w;
726 if ( rtext -> w > text_width ) {
727 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
729 dest -> x = grid_offset_x + ( col * cell_width ) + text_offset_x - ( rtext -> w / 2 );
731 dest -> y = grid_offset_y + ( displayrow * cell_height ) + text_offset_y;
732 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
733 SDL_FreeSurface ( rtext );
737 } // display now? or scrolled away..
740 appiter = appiter -> next;
742 } // for column 1...X
744 if ( row >= ui_rows_scrolled_down ) {
750 // are we done displaying rows?
751 if ( displayrow >= row_max ) {
758 // no apps to render?
759 pnd_log ( pndn_rem, "No applications to render?\n" );
765 if ( ui_selected && render_jobs_b & R_DETAIL ) {
767 unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
768 unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
769 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "detailtext.cell_width" );
771 unsigned int desty = cell_offset_y;
776 if ( ui_selected -> ref -> title_en ) {
778 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
779 rtext = TTF_RenderText_Blended ( g_detailtext_font, ui_selected -> ref -> title_en, tmpfontcolor );
782 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
784 dest -> x = cell_offset_x;
786 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
787 SDL_FreeSurface ( rtext );
794 if ( ui_selected -> ref -> main_category ) {
796 sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
799 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
800 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
803 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
805 dest -> x = cell_offset_x;
807 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
808 SDL_FreeSurface ( rtext );
815 if ( ui_selected -> ref -> clockspeed ) {
817 sprintf ( buffer, "CPU Clock: %s", ui_selected -> ref -> clockspeed );
820 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
821 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
824 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
826 dest -> x = cell_offset_x;
828 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
829 SDL_FreeSurface ( rtext );
834 // show sub-app# on right side of cpu clock?
835 //if ( ui_selected -> ref -> subapp_number )
837 sprintf ( buffer, "(app#%u)", ui_selected -> ref -> subapp_number );
840 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
841 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
842 dest -> x = cell_offset_x + cell_width - rtext -> w;
843 dest -> y = desty - src.h;
844 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
845 SDL_FreeSurface ( rtext );
850 #if 0 // merged into hint-line
851 if ( ui_selected -> ref -> info_filename ) {
853 sprintf ( buffer, "Documentation - hit Y" );
856 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
857 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
860 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
862 dest -> x = cell_offset_x;
864 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
865 SDL_FreeSurface ( rtext );
872 if ( ui_selected -> ovrh ) {
877 desty += 5; // a touch of spacing can't hurt
879 for ( i = 1; i < 4; i++ ) {
880 sprintf ( buffer, "Application-%u.note-%u", ui_selected -> ref -> subapp_number, i );
881 n = pnd_conf_get_as_char ( ui_selected -> ovrh, buffer );
885 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
886 rtext = TTF_RenderText_Blended ( g_detailtext_font, n, tmpfontcolor );
889 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
891 dest -> x = cell_offset_x;
893 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
894 SDL_FreeSurface ( rtext );
900 } // r_detail -> notes
903 mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
904 SDL_Surface *previewpic;
907 previewpic = ic -> i;
909 previewpic = g_imagecache [ IMG_PREVIEW_MISSING ].i;
913 dest -> x = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_x", 50 ) +
914 ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
915 dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
916 SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
920 } // r_detail && selected?
926 if ( render_jobs_b & R_BG ) {
927 static int last_battlevel = 0;
928 static unsigned char batterylevel = 0;
931 if ( time ( NULL ) - last_battlevel > 60 ) {
932 batterylevel = pnd_device_get_battery_gauge_perc();
933 last_battlevel = time ( NULL );
936 sprintf ( buffer, "Battery: %u%%", batterylevel );
939 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
940 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
941 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.battery_x", 20 );
942 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.battery_y", 450 );
943 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
944 SDL_FreeSurface ( rtext );
949 if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
951 unsigned int hintx, hinty;
952 hintx = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
953 hinty = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
954 static unsigned int lastwidth = 3000;
956 if ( ui_selected && ui_selected -> ref -> info_filename ) {
957 buffer = "Documentation - hit Y";
959 buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
963 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
964 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
967 if ( ! ( render_jobs_b & R_BG ) ) {
974 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, &src, sdl_realscreen, dest );
976 lastwidth = rtext -> w;
982 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
983 SDL_FreeSurface ( rtext );
988 if ( render_jobs_b & R_BG &&
989 pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 )
993 time_t t = time ( NULL );
994 struct tm *tm = localtime ( &t );
995 strftime ( buffer, 50, "%a %H:%M %F", tm );
998 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
999 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
1000 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.clock_x", 700 );
1001 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.clock_y", 450 );
1002 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1003 SDL_FreeSurface ( rtext );
1007 // update all the rects and send it all to sdl
1008 // - at this point, we could probably just do 1 rect, of the
1009 // whole screen, and be faster :/
1010 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1014 void ui_process_input ( unsigned char block_p ) {
1017 unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
1018 //static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
1020 while ( ! ui_event &&
1021 block_p ? SDL_WaitEvent ( &event ) : SDL_PollEvent ( &event ) )
1024 switch ( event.type ) {
1029 if ( event.user.code == sdl_user_ticker ) {
1031 // timer went off, time to load something
1032 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1034 // load the preview pics now!
1035 pnd_disco_t *iter = ui_selected -> ref;
1037 if ( iter -> preview_pic1 ) {
1039 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.threaded_preview", 0 ) ) {
1040 // load in bg thread, make user experience chuggy
1042 g_preview_thread = SDL_CreateThread ( (void*)ui_threaded_defered_preview, iter );
1044 if ( ! g_preview_thread ) {
1045 pnd_log ( pndn_error, "ERROR: Couldn't create preview thread\n" );
1049 // load it now, make user wait
1051 if ( ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
1052 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
1055 pnd_log ( pndn_debug, " Couldn't load preview pic: '%s' -> '%s'\n",
1056 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1061 } // got a preview at all?
1066 } else if ( event.user.code == sdl_user_finishedpreview ) {
1068 // if we just finished the one we happen to be looking at, better redraw now; otherwise, if
1069 // we finished another, no big woop
1070 if ( ui_selected && event.user.data1 == ui_selected -> ref ) {
1074 } else if ( event.user.code == sdl_user_finishedicon ) {
1075 // redraw, so we can show the newly loaded icon
1080 render_mask |= CHANGED_EVERYTHING;
1084 #if 0 // joystick motion
1085 case SDL_JOYAXISMOTION:
1087 pnd_log ( PND_LOG_DEFAULT, "joystick axis\n" );
1089 if ( event.jaxis.axis == 0 ) {
1091 if ( event.jaxis.value < 0 ) {
1093 pnd_log ( PND_LOG_DEFAULT, "joystick axis - LEFT\n" );
1094 } else if ( event.jaxis.value > 0 ) {
1095 ui_push_right ( 0 );
1096 pnd_log ( PND_LOG_DEFAULT, "joystick axis - RIGHT\n" );
1098 } else if ( event.jaxis.axis == 1 ) {
1100 if ( event.jaxis.value < 0 ) {
1102 } else if ( event.jaxis.value > 0 ) {
1112 #if 0 // joystick buttons
1113 case SDL_JOYBUTTONDOWN:
1115 pnd_log ( PND_LOG_DEFAULT, "joystick button down %u\n", event.jbutton.button );
1117 if ( event.jbutton.button == 0 ) { // B
1119 } else if ( event.jbutton.button == 1 ) { // Y
1121 } else if ( event.jbutton.button == 2 ) { // X
1123 } else if ( event.jbutton.button == 3 ) { // A
1126 } else if ( event.jbutton.button == 4 ) { // Select
1127 ui_mask |= uisb_select;
1128 } else if ( event.jbutton.button == 5 ) { // Start
1129 ui_mask |= uisb_start;
1131 } else if ( event.jbutton.button == 7 ) { // L
1133 } else if ( event.jbutton.button == 8 ) { // R
1142 case SDL_JOYBUTTONUP:
1144 pnd_log ( PND_LOG_DEFAULT, "joystick button up %u\n", event.jbutton.button );
1146 if ( event.jbutton.button == 0 ) { // B
1149 } else if ( event.jbutton.button == 1 ) { // Y
1151 } else if ( event.jbutton.button == 2 ) { // X
1153 } else if ( event.jbutton.button == 3 ) { // A
1156 } else if ( event.jbutton.button == 4 ) { // Select
1157 ui_mask &= ~uisb_select;
1158 } else if ( event.jbutton.button == 5 ) { // Start
1159 ui_mask &= ~uisb_start;
1161 } else if ( event.jbutton.button == 7 ) { // L
1164 } else if ( event.jbutton.button == 8 ) { // R
1175 #if 1 // keyboard events
1178 //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
1180 // SDLK_LALT -> Start
1183 if ( event.key.keysym.sym == SDLK_RIGHT ) {
1184 ui_push_right ( 0 );
1186 } else if ( event.key.keysym.sym == SDLK_LEFT ) {
1189 } else if ( event.key.keysym.sym == SDLK_UP ) {
1192 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1195 } else if ( event.key.keysym.sym == SDLK_SPACE || event.key.keysym.sym == SDLK_END ) {
1198 } else if ( event.key.keysym.sym == SDLK_z || event.key.keysym.sym == SDLK_RSHIFT ) {
1201 } else if ( event.key.keysym.sym == SDLK_x || event.key.keysym.sym == SDLK_RCTRL ) {
1204 } else if ( event.key.keysym.sym == SDLK_y || event.key.keysym.sym == SDLK_PAGEUP ) {
1206 if ( ui_selected ) {
1207 ui_show_info ( pnd_run_script, ui_selected -> ref );
1211 } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
1215 } else if ( event.key.keysym.sym == SDLK_LCTRL /*LALT*/ ) { // select button
1216 char *opts [ 20 ] = {
1217 "Reveal hidden category",
1219 "Rescan for applications",
1220 "Cache previews to SD now",
1221 "Run a terminal/console",
1222 "Run another GUI (xfce, etc)",
1224 "Select a Minimenu skin",
1227 int sel = ui_modal_single_menu ( opts, 9, "Minimenu", "Enter to select; other to return." );
1229 char buffer [ 100 ];
1233 } else if ( sel == 1 ) {
1235 sprintf ( buffer, "sudo poweroff" );
1237 } else if ( sel == 2 ) {
1239 pnd_log ( pndn_debug, "Freeing up applications\n" );
1240 applications_free();
1241 pnd_log ( pndn_debug, "Rescanning applications\n" );
1242 applications_scan();
1243 } else if ( sel == 3 ) {
1244 // cache preview to SD now
1245 extern pnd_box_handle g_active_apps;
1246 pnd_box_handle h = g_active_apps;
1248 unsigned int maxwidth, maxheight;
1249 maxwidth = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 );
1250 maxheight = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 );
1252 pnd_disco_t *iter = pnd_box_get_head ( h );
1257 if ( ! cache_preview ( iter, maxwidth, maxheight ) ) {
1258 pnd_log ( pndn_debug, "Force cache: Couldn't load preview pic: '%s' -> '%s'\n",
1259 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1263 iter = pnd_box_get_next ( iter );
1266 } else if ( sel == 4 ) {
1269 argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
1273 ui_forkexec ( argv );
1276 } else if ( sel == 5 ) {
1277 char buffer [ PATH_MAX ];
1278 sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/pandora/scripts/op_switchgui.sh" );
1279 emit_and_quit ( buffer );
1280 } else if ( sel == 6 ) {
1281 emit_and_quit ( MM_QUIT );
1282 } else if ( sel == 7 ) {
1284 if ( ui_pick_skin() ) {
1285 emit_and_quit ( MM_RESTART );
1287 } else if ( sel == 8 ) {
1289 char buffer [ PATH_MAX ];
1290 sprintf ( buffer, "%s/about.txt", g_skinpath );
1291 ui_aboutscreen ( buffer );
1295 render_mask |= CHANGED_EVERYTHING;
1299 if ( event.key.keysym.sym == SDLK_q ) {
1300 emit_and_quit ( MM_QUIT );
1306 #if 1 // mouse / touchscreen
1308 case SDL_MOUSEBUTTONDOWN:
1309 if ( event.button.button == SDL_BUTTON_LEFT ) {
1310 cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
1316 case SDL_MOUSEBUTTONUP:
1317 if ( event.button.button == SDL_BUTTON_LEFT ) {
1318 ui_touch_act ( event.button.x, event.button.y );
1331 } // switch event type
1338 void ui_push_left ( unsigned char forcecoil ) {
1340 if ( ! ui_selected ) {
1341 ui_push_right ( 0 );
1345 // what column we in?
1346 unsigned int col = ui_determine_screen_col ( ui_selected );
1348 // are we already at first item?
1349 if ( forcecoil == 0 &&
1350 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1353 unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1354 while ( i && ui_selected -> next ) {
1355 ui_push_right ( 0 );
1359 } else if ( g_categories [ ui_category ].refs == ui_selected ) {
1360 // can't go any more left, we're at the head
1363 // figure out the previous item; yay for singly linked list :/
1364 mm_appref_t *i = g_categories [ ui_category ].refs;
1366 if ( i -> next == ui_selected ) {
1374 ui_set_selected ( ui_selected );
1379 void ui_push_right ( unsigned char forcecoil ) {
1381 if ( ui_selected ) {
1383 // what column we in?
1384 unsigned int col = ui_determine_screen_col ( ui_selected );
1387 if ( forcecoil == 0 &&
1388 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1389 // and selected is far-right, or last icon in category (might not be far right)
1390 ( ( col == pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1 ) ||
1391 ( ui_selected -> next == NULL ) )
1395 //unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1396 while ( col /*i*/ ) {
1402 // just go to the next
1404 if ( ui_selected -> next ) {
1405 ui_selected = ui_selected -> next;
1411 ui_selected = g_categories [ ui_category ].refs;
1414 ui_set_selected ( ui_selected );
1419 void ui_push_up ( void ) {
1420 unsigned char col_max = pnd_conf_get_as_int ( g_conf, "grid.col_max" );
1422 if ( ! ui_selected ) {
1427 unsigned int row = ui_determine_row ( ui_selected );
1430 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 1 ) == 0 )
1432 // wrap around instead
1434 unsigned int col = ui_determine_screen_col ( ui_selected );
1437 ui_selected = g_categories [ ui_category ].refs;
1438 while ( ui_selected -> next ) {
1439 ui_selected = ui_selected -> next;
1442 // try to move to same column
1443 unsigned int newcol = ui_determine_screen_col ( ui_selected );
1444 if ( newcol > col ) {
1452 // scroll down to show it
1453 int r = ui_determine_row ( ui_selected ) - 1;
1454 if ( r - pnd_conf_get_as_int ( g_conf, "grid.row_max" ) > 0 ) {
1455 ui_rows_scrolled_down = (unsigned int) r;
1459 // stop at top/bottom
1471 void ui_push_down ( void ) {
1472 unsigned char col_max = pnd_conf_get_as_int ( g_conf, "grid.col_max" );
1474 if ( ui_selected ) {
1477 unsigned int row = ui_determine_row ( ui_selected );
1480 unsigned int icon_rows = g_categories [ ui_category ].refcount / col_max;
1481 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
1486 if ( row == ( icon_rows - 1 ) &&
1487 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 1 ) == 0 )
1490 unsigned char col = ui_determine_screen_col ( ui_selected );
1492 ui_selected = g_categories [ ui_category ].refs;
1495 ui_selected = ui_selected -> next;
1499 ui_rows_scrolled_down = 0;
1501 render_mask |= CHANGED_EVERYTHING;
1506 ui_push_right ( 1 );
1513 ui_push_right ( 0 );
1519 void ui_push_exec ( void ) {
1521 if ( ! ui_selected ) {
1525 // was this icon generated from filesystem, or from pnd-file?
1526 if ( ui_selected -> ref -> object_flags & PND_DISCO_GENERATED ) {
1528 if ( ! ui_selected -> ref -> title_en ) {
1529 return; // no filename
1532 if ( ui_selected -> ref -> object_type == pnd_object_type_directory ) {
1533 // delve up/down the dir tree
1535 if ( strcmp ( ui_selected -> ref -> title_en, ".." ) == 0 ) {
1539 // lop off last word; if the thing ends with /, lop that one, then the next word.
1540 while ( ( c = strrchr ( g_categories [ ui_category].fspath, '/' ) ) ) {
1541 *c = '\0'; // lop off the last hunk
1542 if ( *(c+1) != '\0' ) {
1548 if ( g_categories [ ui_category].fspath [ 0 ] == '\0' ) {
1549 strcpy ( g_categories [ ui_category].fspath, "/" );
1554 strcat ( g_categories [ ui_category].fspath, "/" );
1555 strcat ( g_categories [ ui_category].fspath, ui_selected -> ref -> title_en );
1558 pnd_log ( pndn_debug, "Cat %s is now in path %s\n", g_categories [ ui_category ].catname, g_categories [ ui_category ].fspath );
1561 category_fs_restock ( &(g_categories [ ui_category]) );
1562 // forget the selection, nolonger applies
1564 ui_set_selected ( ui_selected );
1566 render_mask |= CHANGED_SELECTION;
1569 // just run it arbitrarily?
1571 // if this a pnd-file, or just some executable?
1572 if ( strcasestr ( ui_selected -> ref -> object_filename, PND_PACKAGE_FILEEXT ) ) {
1573 // looks like a pnd, now what do we do..
1574 pnd_box_handle h = pnd_disco_file ( ui_selected -> ref -> object_path, ui_selected -> ref -> object_filename );
1577 pnd_disco_t *d = pnd_box_get_head ( h );
1578 pnd_apps_exec_disco ( pnd_run_script, d, PND_EXEC_OPTION_NORUN, NULL );
1579 char buffer [ PATH_MAX ];
1580 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1581 emit_and_quit ( buffer );
1587 char cwd [ PATH_MAX ];
1588 getcwd ( cwd, PATH_MAX );
1590 chdir ( g_categories [ ui_category ].fspath );
1591 pnd_exec_no_wait_1 ( ui_selected -> ref -> title_en, NULL );
1594 char buffer [ PATH_MAX ];
1595 sprintf ( buffer, "%s %s/%s\n", MM_RUN, g_categories [ ui_category ].fspath, ui_selected -> ref -> title_en );
1596 emit_and_quit ( buffer );
1603 pnd_apps_exec_disco ( pnd_run_script, ui_selected -> ref, PND_EXEC_OPTION_NORUN, NULL );
1604 char buffer [ PATH_MAX ];
1605 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1606 emit_and_quit ( buffer );
1612 void ui_push_ltrigger ( void ) {
1613 unsigned char oldcat = ui_category;
1614 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
1615 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1617 if ( g_categorycount == 0 ) {
1621 if ( ui_category > 0 ) {
1623 category_fs_restock ( &(g_categories [ ui_category ]) );
1625 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1626 ui_category = g_categorycount - 1;
1628 if ( ui_category >= ( screen_width / tab_width ) ) {
1629 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
1631 category_fs_restock ( &(g_categories [ ui_category ]) );
1635 if ( oldcat != ui_category ) {
1637 ui_set_selected ( ui_selected );
1640 // make tab visible?
1641 if ( ui_catshift > 0 && ui_category == ui_catshift - 1 ) {
1646 ui_rows_scrolled_down = 0;
1648 render_mask |= CHANGED_CATEGORY;
1653 void ui_push_rtrigger ( void ) {
1654 unsigned char oldcat = ui_category;
1656 if ( g_categorycount == 0 ) {
1660 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
1661 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1663 if ( ui_category < ( g_categorycount - 1 ) ) {
1665 category_fs_restock ( &(g_categories [ ui_category ]) );
1667 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1670 category_fs_restock ( &(g_categories [ ui_category ]) );
1674 if ( oldcat != ui_category ) {
1676 ui_set_selected ( ui_selected );
1679 // make tab visible?
1680 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
1685 ui_rows_scrolled_down = 0;
1687 render_mask |= CHANGED_CATEGORY;
1692 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ) {
1693 double scale = 1000000.0;
1694 double scalex = 1000000.0;
1695 double scaley = 1000000.0;
1696 SDL_Surface *scaled;
1698 scalex = (double)maxwidth / (double)s -> w;
1700 if ( maxheight == -1 ) {
1703 scaley = (double)maxheight / (double)s -> h;
1705 if ( scaley < scalex ) {
1713 scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
1714 SDL_FreeSurface ( s );
1720 void ui_loadscreen ( void ) {
1724 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1725 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1726 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1727 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1730 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1734 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1735 rtext = TTF_RenderText_Blended ( g_big_font, "Setting up menu...", tmpfontcolor );
1738 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1739 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1740 SDL_FreeSurface ( rtext );
1745 void ui_discoverscreen ( unsigned char clearscreen ) {
1749 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1750 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1751 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1752 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1755 if ( clearscreen ) {
1756 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1758 // render background
1759 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1762 dest.w = sdl_realscreen -> w;
1763 dest.h = sdl_realscreen -> h;
1764 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1765 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1772 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1773 rtext = TTF_RenderText_Blended ( g_big_font, "Looking for applications...", tmpfontcolor );
1774 if ( clearscreen ) {
1781 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1782 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1783 SDL_FreeSurface ( rtext );
1786 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1787 dest.x = rtext -> w + 30;
1789 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, &dest );
1790 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1796 void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
1798 SDL_Rect rects [ 4 ];
1799 SDL_Rect *dest = rects;
1801 bzero ( dest, sizeof(SDL_Rect)* 4 );
1803 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1804 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1805 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1806 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1808 static unsigned int stepx = 0;
1811 if ( clearscreen ) {
1812 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1814 // render background
1815 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1818 dest -> w = sdl_realscreen -> w;
1819 dest -> h = sdl_realscreen -> h;
1820 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1826 // render background
1827 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1830 src.w = sdl_realscreen -> w;
1834 dest -> w = sdl_realscreen -> w;
1835 dest -> h = sdl_realscreen -> h;
1836 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
1844 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1845 rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
1848 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1849 SDL_FreeSurface ( rtext );
1853 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1854 dest -> x = rtext -> w + 30 + stepx;
1856 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, dest );
1862 rtext = TTF_RenderText_Blended ( g_tab_font, filename, tmpfontcolor );
1865 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1866 SDL_FreeSurface ( rtext );
1873 if ( stepx > 350 ) {
1877 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1882 int ui_selected_index ( void ) {
1884 if ( ! ui_selected ) {
1885 return ( -1 ); // no index
1888 mm_appref_t *r = g_categories [ ui_category ].refs;
1891 if ( r == ui_selected ) {
1901 static mm_appref_t *timer_ref = NULL;
1902 void ui_set_selected ( mm_appref_t *r ) {
1904 render_mask |= CHANGED_SELECTION;
1906 if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1907 return; // no desire to defer anything
1912 SDL_SetTimer ( 0, NULL );
1917 SDL_SetTimer ( pnd_conf_get_as_int_d ( g_conf, "previewpic.defer_timer_ms", 1000 ), ui_callback_f );
1923 unsigned int ui_callback_f ( unsigned int t ) {
1925 if ( ui_selected != timer_ref ) {
1926 return ( 0 ); // user has moved it, who cares
1930 bzero ( &e, sizeof(SDL_Event) );
1931 e.type = SDL_USEREVENT;
1932 e.user.code = sdl_user_ticker;
1933 SDL_PushEvent ( &e );
1938 int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer ) {
1939 SDL_Rect rects [ 40 ];
1940 SDL_Rect *dest = rects;
1943 unsigned char max_visible = pnd_conf_get_as_int_d ( g_conf, "detailtext.max_visible" , 11 );
1944 unsigned char first_visible = 0;
1946 bzero ( rects, sizeof(SDL_Rect) * 40 );
1948 unsigned int sel = 0;
1950 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1951 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1952 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1953 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1955 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1957 SDL_Color selfontcolor = { 0/*font_rgba_r*/, font_rgba_g, font_rgba_b, font_rgba_a };
1965 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1966 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1967 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
1968 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
1969 SDL_FillRect( sdl_realscreen, dest, 0 );
1971 // show dialog background
1972 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
1973 src.x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1974 src.y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1975 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
1976 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
1977 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1978 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1979 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1980 // repeat for darken?
1981 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1982 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1983 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1987 // show dialog frame
1988 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
1989 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1990 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1991 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
1992 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1998 rtext = TTF_RenderText_Blended ( g_tab_font, title, tmpfontcolor );
1999 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2000 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
2001 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2002 SDL_FreeSurface ( rtext );
2008 rtext = TTF_RenderText_Blended ( g_tab_font, footer, tmpfontcolor );
2009 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2010 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
2011 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
2013 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2014 SDL_FreeSurface ( rtext );
2019 for ( i = first_visible; i < first_visible + max_visible && i < argc; i++ ) {
2023 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
2025 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], tmpfontcolor );
2027 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2028 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 - first_visible ) );
2029 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2030 SDL_FreeSurface ( rtext );
2035 // update all the rects and send it all to sdl
2036 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
2040 while ( SDL_WaitEvent ( &event ) ) {
2042 switch ( event.type ) {
2046 if ( event.key.keysym.sym == SDLK_UP ) {
2050 if ( sel < first_visible ) {
2055 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
2057 if ( sel < argc - 1 ) {
2060 // ensure visibility
2061 if ( sel >= first_visible + max_visible ) {
2067 } else if ( event.key.keysym.sym == SDLK_RETURN ) {
2070 } else if ( event.key.keysym.sym == SDLK_q ) {
2074 return ( -1 ); // nada
2089 unsigned char ui_determine_row ( mm_appref_t *a ) {
2090 unsigned int row = 0;
2092 mm_appref_t *i = g_categories [ ui_category ].refs;
2097 row /= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
2102 unsigned char ui_determine_screen_row ( mm_appref_t *a ) {
2103 return ( ui_determine_row ( a ) % pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 5 ) );
2106 unsigned char ui_determine_screen_col ( mm_appref_t *a ) {
2107 unsigned int col = 0;
2109 mm_appref_t *i = g_categories [ ui_category ].refs;
2114 col %= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
2119 unsigned char ui_show_info ( char *pndrun, pnd_disco_t *p ) {
2120 char *viewer, *searchpath;
2121 pnd_conf_handle desktoph;
2124 searchpath = pnd_conf_query_searchpath();
2126 desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
2132 viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
2135 return ( 0 ); // no way to view the file
2139 if ( ! p -> unique_id ) {
2143 if ( ! p -> info_filename ) {
2147 if ( ! p -> info_name ) {
2158 if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) {
2159 snprintf ( pargs, 1001, "%s %s",
2160 pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
2165 char pndfile [ 1024 ];
2166 if ( p -> object_type == pnd_object_type_directory ) {
2167 // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
2168 strncpy ( pndfile, p -> object_path, 1000 );
2169 } else if ( p -> object_type == pnd_object_type_pnd ) {
2170 // pnd_run.sh wants the full path and filename for the .pnd file
2171 snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
2174 if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs,
2175 p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) )
2180 pnd_log ( pndn_debug, "Info Exec=%s\n", pnd_apps_exec_runline() );
2184 if ( ( x = fork() ) < 0 ) {
2185 pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
2190 execl ( "/bin/sh", "/bin/sh", "-c", pnd_apps_exec_runline(), (char*)NULL );
2191 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", pnd_apps_exec_runline() );
2203 #define MAXTOUCH 100
2204 ui_touch_t ui_touchrects [ MAXTOUCH ];
2205 unsigned char ui_touchrect_count = 0;
2207 void ui_register_reset ( void ) {
2208 bzero ( ui_touchrects, sizeof(ui_touch_t)*MAXTOUCH );
2209 ui_touchrect_count = 0;
2213 void ui_register_tab ( unsigned char catnum, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2215 if ( ui_touchrect_count == MAXTOUCH ) {
2219 ui_touchrects [ ui_touchrect_count ].r.x = x;
2220 ui_touchrects [ ui_touchrect_count ].r.y = y;
2221 ui_touchrects [ ui_touchrect_count ].r.w = w;
2222 ui_touchrects [ ui_touchrect_count ].r.h = h;
2223 ui_touchrects [ ui_touchrect_count ].catnum = catnum;
2224 ui_touchrect_count++;
2229 void ui_register_app ( mm_appref_t *app, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2231 if ( ui_touchrect_count == MAXTOUCH ) {
2235 ui_touchrects [ ui_touchrect_count ].r.x = x;
2236 ui_touchrects [ ui_touchrect_count ].r.y = y;
2237 ui_touchrects [ ui_touchrect_count ].r.w = w;
2238 ui_touchrects [ ui_touchrect_count ].r.h = h;
2239 ui_touchrects [ ui_touchrect_count ].ref = app;
2240 ui_touchrect_count++;
2245 void ui_touch_act ( unsigned int x, unsigned int y ) {
2250 for ( i = 0; i < ui_touchrect_count; i++ ) {
2251 t = &(ui_touchrects [ i ]);
2253 if ( x >= t -> r.x &&
2254 x <= t -> r.x + t -> r.w &&
2256 y <= t -> r.y + t -> r.h
2261 ui_selected = t -> ref;
2264 if ( ui_category != t -> catnum ) {
2267 ui_category = t -> catnum;
2268 render_mask |= CHANGED_CATEGORY;
2279 unsigned char ui_forkexec ( char *argv[] ) {
2280 char *fooby = argv[0];
2283 if ( ( x = fork() ) < 0 ) {
2284 pnd_log ( pndn_error, "ERROR: Couldn't fork() for '%s'\n", fooby );
2288 if ( x == 0 ) { // child
2289 execv ( fooby, argv );
2290 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", fooby );
2298 unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ) {
2300 if ( ! cache_preview ( p, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
2301 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
2304 pnd_log ( pndn_debug, "THREAD: Couldn't load preview pic: '%s' -> '%s'\n",
2305 IFNULL(p->title_en,"No Name"), p -> preview_pic1 );
2308 // trigger that we completed
2310 bzero ( &e, sizeof(SDL_Event) );
2311 e.type = SDL_USEREVENT;
2312 e.user.code = sdl_user_finishedpreview;
2314 SDL_PushEvent ( &e );
2319 SDL_Thread *g_icon_thread = NULL;
2320 void ui_post_scan ( void ) {
2322 // if deferred icon load, kick off the thread now
2323 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 1 ) {
2325 g_icon_thread = SDL_CreateThread ( (void*)ui_threaded_defered_icon, NULL );
2327 if ( ! g_icon_thread ) {
2328 pnd_log ( pndn_error, "ERROR: Couldn't create icon thread\n" );
2331 } // deferred icon load
2335 ui_rows_scrolled_down = 0;
2336 // set back to first tab, to be safe
2340 // do we have a preferred category to jump to?
2341 char *dc = pnd_conf_get_as_char ( g_conf, "categories.default_cat" );
2344 // attempt to find default cat; if we do find it, select it; otherwise
2345 // default behaviour will pick first cat (ie: usually All)
2347 for ( i = 0; i < g_categorycount; i++ ) {
2348 if ( strcasecmp ( g_categories [ i ].catname, dc ) == 0 ) {
2350 // ensure visibility
2351 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
2352 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2353 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
2354 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
2360 if ( i == g_categorycount ) {
2361 pnd_log ( pndn_warning, " User defined default category '%s' but not found, so using default behaviour\n", dc );
2367 render_mask |= CHANGED_EVERYTHING;
2372 unsigned char ui_threaded_defered_icon ( void *p ) {
2373 extern pnd_box_handle g_active_apps;
2374 pnd_box_handle h = g_active_apps;
2376 unsigned char maxwidth, maxheight;
2377 maxwidth = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 );
2378 maxheight = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_height", 50 );
2380 pnd_disco_t *iter = pnd_box_get_head ( h );
2385 if ( iter -> pnd_icon_pos &&
2386 ! cache_icon ( iter, maxwidth, maxheight ) )
2388 pnd_log ( pndn_warning, " Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2391 // trigger that we completed
2393 bzero ( &e, sizeof(SDL_Event) );
2394 e.type = SDL_USEREVENT;
2395 e.user.code = sdl_user_finishedicon;
2396 SDL_PushEvent ( &e );
2398 //pnd_log ( pndn_warning, " Finished deferred load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2399 usleep ( pnd_conf_get_as_int_d ( g_conf, "minimenu.defer_icon_us", 50000 ) );
2404 iter = pnd_box_get_next ( iter );
2410 void ui_show_hourglass ( unsigned char updaterect ) {
2413 SDL_Surface *s = g_imagecache [ IMG_HOURGLASS ].i;
2415 dest.x = ( 800 - s -> w ) / 2;
2416 dest.y = ( 480 - s -> h ) / 2;
2418 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, &dest );
2421 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2427 unsigned char ui_pick_skin ( void ) {
2429 char *skins [ MAXSKINS ];
2432 char *searchpath = pnd_conf_get_as_char ( g_conf, "minimenu.skin_searchpath" );
2433 char tempname [ 100 ];
2437 skins [ iter++ ] = "No skin change";
2441 DIR *d = opendir ( buffer );
2446 while ( ( dd = readdir ( d ) ) ) {
2448 if ( dd -> d_name [ 0 ] == '.' ) {
2450 } else if ( ( dd -> d_type == DT_DIR || dd -> d_type == DT_UNKNOWN ) &&
2453 snprintf ( tempname, 100, "Skin: %s", dd -> d_name );
2454 skins [ iter++ ] = strdup ( tempname );
2465 int sel = ui_modal_single_menu ( skins, iter, "Skins", "Enter to select; other to return." );
2467 // did they pick one?
2471 char *s = strdup ( pnd_conf_get_as_char ( g_conf, "minimenu.skin_selected" ) );
2472 s = pnd_expand_tilde ( s );
2474 f = fopen ( s, "w" );
2479 fprintf ( f, "%s\n", skins [ sel ] + 6 );
2489 void ui_aboutscreen ( char *textpath ) {
2496 #define ROWS SCRH / ( PIXELH + MARGINH )
2497 #define COLS SCRW / ( PIXELW + MARGINW )
2499 unsigned char pixelboard [ ROWS * COLS ]; // pixel heat
2500 bzero ( pixelboard, ROWS * COLS );
2505 SDL_Color rtextc = { 200, 200, 200, 100 };
2508 char *textloop [ 500 ];
2509 unsigned int textmax = 0;
2510 bzero ( textloop, 500 * sizeof(char*) );
2513 char cbuffer [ 50000 ];
2514 bzero ( cbuffer, 50000 );
2515 unsigned int crevealed = 0;
2517 FILE *f = fopen ( textpath, "r" );
2520 pnd_log ( pndn_error, "ERROR: Couldn't open about text: %s\n", textpath );
2524 char textbuf [ 100 ];
2525 while ( fgets ( textbuf, 100, f ) ) {
2527 // add to full buffer
2528 strncat ( cbuffer, textbuf, 50000 );
2531 if ( strchr ( textbuf, '\n' ) ) {
2532 * strchr ( textbuf, '\n' ) = '\0';
2535 // add to pixel loop
2536 if ( 1||textbuf [ 0 ] ) {
2537 textloop [ textmax ] = strdup ( textbuf );
2545 unsigned int textiter = 0;
2546 while ( textiter < textmax ) {
2547 char *text = textloop [ textiter ];
2551 // render to surface
2552 rtext = TTF_RenderText_Blended ( g_grid_font, text, rtextc );
2554 // render font to pixelboard
2555 unsigned int px, py;
2557 unsigned int *pixels = rtext -> pixels;
2558 unsigned char cr, cg, cb, ca;
2559 for ( py = 0; py < rtext -> h; py ++ ) {
2560 for ( px = 0; px < ( rtext -> w > COLS ? COLS : rtext -> w ); px++ ) {
2562 SDL_GetRGBA ( pixels [ ( py * rtext -> pitch / 4 ) + px ],
2563 rtext -> format, &cr, &cg, &cb, &ca );
2567 ph = pixelboard + ( /*y offset */ 30 * COLS ) + ( py * COLS ) + px /* / 2 */;
2574 if ( *ph + ca < 250 ) {
2585 unsigned int runcount = 10;
2586 while ( runcount-- ) {
2589 SDL_FillRect( sdl_realscreen, NULL /* whole */, 0 );
2591 // render pixelboard
2594 for ( y = 0; y < ROWS; y++ ) {
2595 for ( x = 0; x < COLS; x++ ) {
2597 if ( 1||pixelboard [ ( y * COLS ) + x ] ) {
2600 r.x = x * ( PIXELW + MARGINW );
2601 r.y = y * ( PIXELH + MARGINH );
2605 c = SDL_MapRGB ( sdl_realscreen -> format, 100 /* r */, 0 /* g */, pixelboard [ ( y * COLS ) + x ] );
2607 SDL_FillRect( sdl_realscreen, &r /* whole */, c );
2615 unsigned char *pc = pixelboard;
2616 for ( y = 0; y < ROWS; y++ ) {
2617 for ( x = 0; x < COLS; x++ ) {
2627 // slide pixels upwards
2628 memmove ( pixelboard, pixelboard + COLS, ( COLS * ROWS ) - COLS );
2630 // render actual readable text
2633 // display up to cursor
2635 unsigned int cdraw = 0;
2639 if ( crevealed > 200 ) {
2640 cdraw = crevealed - 200;
2646 for ( ; cdraw < crevealed; cdraw++ ) {
2647 ctb [ 0 ] = cbuffer [ cdraw ];
2649 // move over or down
2650 if ( cbuffer [ cdraw ] == '\n' ) {
2655 if ( dest.y > 450 ) {
2661 cs = TTF_RenderText_Blended ( g_tab_font, ctb, rtextc );
2663 SDL_BlitSurface ( cs, NULL /* all */, sdl_realscreen, &dest );
2664 SDL_FreeSurface ( cs );
2674 SDL_FillRect ( sdl_realscreen, &dest /* whole */, 220 );
2676 // increment cursor to next character
2677 if ( cbuffer [ crevealed ] != '\0' ) {
2681 } // draw cursor text
2685 SDL_UpdateRect ( sdl_realscreen, 0, 0, 0, 0 ); // whole screen
2689 // any button? if so, about
2695 if ( SDL_PeepEvents ( &e, 1, SDL_GETEVENT, SDL_EVENTMASK(SDL_KEYUP) ) > 0 ) {
2704 SDL_FreeSurface ( rtext );
2708 } // while more text
2712 for ( i = 0; i < textmax; i++ ) {
2713 if ( textloop [ i ] ) {
2714 free ( textloop [ i ] );
2722 void ui_revealscreen ( void ) {
2723 char *labels [ 500 ];
2724 unsigned int labelmax = 0;
2727 if ( ! _categories_inviscount ) {
2728 return; // nothing to do
2731 for ( i = 0; i < _categories_inviscount; i++ ) {
2732 labels [ labelmax++ ] = _categories_invis [ i ].catname;
2735 int sel = ui_modal_single_menu ( labels, labelmax, "Temporary Category Reveal",
2736 "Enter to select; other to return." );
2740 if ( category_query ( _categories_invis [ sel ].catname ) ) {
2745 // fix up category name, if its been hacked
2746 if ( strchr ( _categories_invis [ sel ].catname, '.' ) ) {
2747 char *t = _categories_invis [ sel ].catname;
2748 _categories_invis [ sel ].catname = strdup ( strchr ( _categories_invis [ sel ].catname, '.' ) + 1 );
2751 // copy invisi-cat into live-cat
2752 memmove ( &(g_categories [ g_categorycount ]), &(_categories_invis [ sel ]), sizeof(mm_category_t) );
2754 // move subsequent invisi-cats up, so the selected invisi-cat is nolonger existing in invisi-list at
2755 // all (avoid double-free() later)
2756 memmove ( &(_categories_invis [ sel ]), &(_categories_invis [ sel + 1 ]), sizeof(mm_category_t) * ( _categories_inviscount - sel - 1 ) );
2757 _categories_inviscount--;
2759 // switch to the new category
2760 ui_category = g_categorycount - 1;
2762 // ensure visibility
2763 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
2764 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2765 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
2766 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
2770 render_mask |= CHANGED_CATEGORY;