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 [ MAX_CATS ];
78 extern unsigned char g_categorycount;
80 static SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ); // height -1 means ignore
81 static int ui_selected_index ( void );
83 unsigned char ui_setup ( void ) {
88 SDL_Init ( SDL_INIT_EVERYTHING | SDL_INIT_NOPARACHUTE );
90 SDL_JoystickOpen ( 0 ); // turn on joy-0
92 SDL_WM_SetCaption ( "mmenu", "mmenu" );
94 // hide the mouse cursor if we can
95 if ( SDL_ShowCursor ( -1 ) == 1 ) {
102 unsigned int svm = SDL_SWSURFACE /*| SDL_FULLSCREEN*/ /* 0*/;
103 if ( pnd_conf_get_as_int_d ( g_conf, "display.fullscreen", 0 ) > 0 ) {
104 svm |= SDL_FULLSCREEN;
108 SDL_SetVideoMode ( 800 * g_scale, 480 * g_scale, 16 /*bpp*/, svm );
110 if ( ! sdl_realscreen ) {
111 pnd_log ( pndn_error, "ERROR: Couldn't open SDL real screen; dieing." );
115 pnd_log ( pndn_debug, "Pixel format:" );
116 pnd_log ( pndn_debug, "bpp b: %u\n", sdl_realscreen -> format -> BitsPerPixel );
117 pnd_log ( pndn_debug, "bpp B: %u\n", sdl_realscreen -> format -> BytesPerPixel );
118 pnd_log ( pndn_debug, "R mask: %08x\n", sdl_realscreen -> format -> Rmask );
119 pnd_log ( pndn_debug, "G mask: %08x\n", sdl_realscreen -> format -> Gmask );
120 pnd_log ( pndn_debug, "B mask: %08x\n", sdl_realscreen -> format -> Bmask );
126 /* Set 16-bit stereo audio at 22Khz */
127 fmt.freq = 44100; //22050;
128 fmt.format = AUDIO_S16; //AUDIO_S16;
130 fmt.samples = 2048; /* A good value for games */
131 fmt.callback = mixaudio;
134 /* Open the audio device and start playing sound! */
135 if ( SDL_OpenAudio ( &fmt, NULL ) < 0 ) {
136 zotlog ( "Unable to open audio: %s\n", SDL_GetError() );
140 SDL_PauseAudio ( 0 );
145 //IMG_Init ( IMG_INIT_JPG | IMG_INIT_PNG );
151 if ( TTF_Init() == -1 ) {
152 pnd_log ( pndn_error, "ERROR: Couldn't set up SDL TTF lib\n" );
153 return ( 0 ); // couldn't set up SDL TTF
156 char fullpath [ PATH_MAX ];
158 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "minimenu.font" ) );
159 g_big_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
160 if ( ! g_big_font ) {
161 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
162 pnd_conf_get_as_char ( g_conf, "minimenu.font" ), pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
163 return ( 0 ); // couldn't set up SDL TTF
167 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "grid.font" ) );
168 g_grid_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
169 if ( ! g_grid_font ) {
170 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
171 pnd_conf_get_as_char ( g_conf, "grid.font" ), pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
172 return ( 0 ); // couldn't set up SDL TTF
176 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "detailtext.font" ) );
177 g_detailtext_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
178 if ( ! g_detailtext_font ) {
179 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
180 pnd_conf_get_as_char ( g_conf, "detailtext.font" ), pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
181 return ( 0 ); // couldn't set up SDL TTF
185 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "tabs.font" ) );
186 g_tab_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
187 if ( ! g_tab_font ) {
188 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
189 pnd_conf_get_as_char ( g_conf, "tabs.font" ), pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
190 return ( 0 ); // couldn't set up SDL TTF
196 mm_imgcache_t g_imagecache [ IMG_TRUEMAX ] = {
197 { IMG_BACKGROUND_800480, "graphics.IMG_BACKGROUND_800480" },
198 { IMG_BACKGROUND_TABMASK, "graphics.IMG_BACKGROUND_TABMASK" },
199 { IMG_DETAIL_PANEL, "graphics.IMG_DETAIL_PANEL" },
200 { IMG_DETAIL_BG, "graphics.IMG_DETAIL_BG" },
201 { IMG_SELECTED_ALPHAMASK, "graphics.IMG_SELECTED_ALPHAMASK" },
202 { IMG_TAB_SEL, "graphics.IMG_TAB_SEL" },
203 { IMG_TAB_SEL_L, "graphics.IMG_TAB_SEL_L" },
204 { IMG_TAB_SEL_R, "graphics.IMG_TAB_SEL_R" },
205 { IMG_TAB_UNSEL, "graphics.IMG_TAB_UNSEL" },
206 { IMG_TAB_UNSEL_L, "graphics.IMG_TAB_UNSEL_L" },
207 { IMG_TAB_UNSEL_R, "graphics.IMG_TAB_UNSEL_R" },
208 { IMG_TAB_LINE, "graphics.IMG_TAB_LINE" },
209 { IMG_TAB_LINEL, "graphics.IMG_TAB_LINEL" },
210 { IMG_TAB_LINER, "graphics.IMG_TAB_LINER" },
211 { IMG_ICON_MISSING, "graphics.IMG_ICON_MISSING" },
212 { IMG_SELECTED_HILITE, "graphics.IMG_SELECTED_HILITE" },
213 { IMG_PREVIEW_MISSING, "graphics.IMG_PREVIEW_MISSING" },
214 { IMG_ARROW_UP, "graphics.IMG_ARROW_UP", },
215 { IMG_ARROW_DOWN, "graphics.IMG_ARROW_DOWN", },
216 { IMG_ARROW_SCROLLBAR, "graphics.IMG_ARROW_SCROLLBAR", },
217 { IMG_HOURGLASS, "graphics.IMG_HOURGLASS", },
218 { IMG_FOLDER, "graphics.IMG_FOLDER", },
219 { IMG_EXECBIN, "graphics.IMG_EXECBIN", },
223 unsigned char ui_imagecache ( char *basepath ) {
225 char fullpath [ PATH_MAX ];
229 for ( i = 0; i < IMG_MAX; i++ ) {
231 if ( g_imagecache [ i ].id != i ) {
232 pnd_log ( pndn_error, "ERROR: Internal table mismatch during caching [%u]\n", i );
236 char *filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].confname );
239 pnd_log ( pndn_error, "ERROR: Missing filename in conf for key: %s\n", g_imagecache [ i ].confname );
243 if ( filename [ 0 ] == '/' ) {
244 strncpy ( fullpath, filename, PATH_MAX );
246 sprintf ( fullpath, "%s/%s", basepath, filename );
249 if ( ! ( g_imagecache [ i ].i = IMG_Load ( fullpath ) ) ) {
250 pnd_log ( pndn_error, "ERROR: Couldn't load static cache image: %s\n", fullpath );
257 //g_imagecache [ IMG_SELECTED_ALPHAMASK ].i = SDL_CreateRGBSurface ( SDL_SWSURFACE, 60, 60, 32, 0xFF0000, 0x00FF00, 0xFF, 0xFF000000 );
258 //boxRGBA ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, 0, 0, 60, 60, 100, 100, 100, 250 );
264 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 );
265 // scale text hilight
266 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 );
267 // scale preview no-pic
268 g_imagecache [ IMG_PREVIEW_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_PREVIEW_MISSING ].i,
269 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ),
270 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 50 ) );
272 // set alpha on detail panel
273 //SDL_SetAlpha ( g_imagecache [ IMG_DETAIL_BG ].i, SDL_SRCALPHA, pnd_conf_get_as_int_d ( g_conf, "display.detail_bg_alpha", 50 ) );
278 void ui_render ( void ) {
281 // divide width: 550 / 250
282 // divide left side: 5 columns == 110px width
283 // 20px buffer either side == 70px wide icon + 20 + 20?
285 // what jobs to do during render?
289 #define R_TABS (1<<1)
290 #define R_DETAIL (1<<2)
291 #define R_GRID (1<<3)
293 #define R_ALL (R_BG|R_TABS|R_DETAIL|R_GRID)
295 unsigned int render_jobs_b = 0;
297 if ( render_mask & CHANGED_EVERYTHING ) {
298 render_jobs_b |= R_ALL;
301 if ( render_mask & CHANGED_SELECTION ) {
302 render_jobs_b |= R_GRID;
303 render_jobs_b |= R_DETAIL;
306 if ( render_mask & CHANGED_CATEGORY ) {
307 render_jobs_b |= R_ALL;
310 render_mask = CHANGED_NOTHING;
314 unsigned int icon_rows;
317 SDL_Rect rects [ MAXRECTS ], src;
318 SDL_Rect *dest = rects;
319 bzero ( dest, sizeof(SDL_Rect)*MAXRECTS );
321 unsigned int row, displayrow, col;
322 mm_appref_t *appiter;
324 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
326 unsigned char row_max = pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 4 );
327 unsigned char col_max = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
329 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
330 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
331 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
332 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
334 unsigned int grid_offset_x = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_x" );
335 unsigned int grid_offset_y = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_y" );
337 unsigned int icon_offset_x = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_x" );
338 unsigned int icon_offset_y = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_y" );
339 unsigned int icon_max_width = pnd_conf_get_as_int ( g_conf, "grid.icon_max_width" );
340 unsigned int icon_max_height = pnd_conf_get_as_int ( g_conf, "grid.icon_max_height" );
341 unsigned int sel_icon_offset_x = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_x", 0 );
342 unsigned int sel_icon_offset_y = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_y", 0 );
344 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
345 unsigned int text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
346 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "grid.text_offset_x" );
347 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_offset_y" );
349 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "grid.cell_width" );
350 unsigned int cell_height = pnd_conf_get_as_int ( g_conf, "grid.cell_height" );
352 // how many total rows do we need?
353 icon_rows = g_categories [ ui_category ].refcount / col_max;
354 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
358 // if no selected app yet, select the first one
360 if ( ! ui_selected ) {
361 ui_selected = g_categories [ ui_category ].refs;
365 // reset touchscreen regions
368 // ensure selection is visible
371 int index = ui_selected_index();
372 int topleft = col_max * ui_rows_scrolled_down;
373 int botright = ( col_max * ( ui_rows_scrolled_down + row_max ) - 1 );
375 if ( index < topleft ) {
376 ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
377 render_jobs_b |= R_ALL;
378 } else if ( index > botright ) {
379 ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
380 render_jobs_b |= R_ALL;
383 if ( ui_rows_scrolled_down < 0 ) {
384 ui_rows_scrolled_down = 0;
385 } else if ( ui_rows_scrolled_down > icon_rows ) {
386 ui_rows_scrolled_down = icon_rows;
392 if ( render_jobs_b & R_BG ) {
394 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
397 dest -> w = sdl_realscreen -> w;
398 dest -> h = sdl_realscreen -> h;
399 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
404 if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
407 dest -> w = sdl_realscreen -> w;
408 dest -> h = sdl_realscreen -> h;
409 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
416 if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
417 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
418 unsigned int tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
419 //unsigned int tab_selheight = pnd_conf_get_as_int ( g_conf, "tabs.tab_selheight" );
420 unsigned int tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
421 unsigned int tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
422 unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
423 unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
424 unsigned int text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
425 unsigned int maxtab = ( screen_width / tab_width ) < g_categorycount ? ( screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift;
426 unsigned int maxtabspot = ( screen_width / tab_width );
428 // draw tabs with categories
429 for ( col = ui_catshift;
436 // if this is the first (leftmost) tab, we use different artwork
437 // than if the other tabs (so skinner can link lines up nicely.)
438 if ( col == ui_catshift ) {
439 // leftmost tab, special case
441 if ( col == ui_category ) {
442 s = g_imagecache [ IMG_TAB_SEL_L ].i;
444 s = g_imagecache [ IMG_TAB_UNSEL_L ].i;
447 } else if ( col == maxtab - 1 ) {
448 // rightmost tab, special case
450 if ( col == ui_category ) {
451 s = g_imagecache [ IMG_TAB_SEL_R ].i;
453 s = g_imagecache [ IMG_TAB_UNSEL_R ].i;
457 // normal (not leftmost) tab
459 if ( col == ui_category ) {
460 s = g_imagecache [ IMG_TAB_SEL ].i;
462 s = g_imagecache [ IMG_TAB_UNSEL ].i;
465 } // first col, or not first col?
472 if ( col == ui_category ) {
473 src.h = tab_selheight;
481 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
482 dest -> y = tab_offset_y;
485 ui_register_tab ( col, dest -> x, dest -> y, tab_width, tab_height );
487 if ( render_jobs_b & R_TABS ) {
488 //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
489 SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
493 if ( col == ui_category ) {
494 // no line for selected tab
496 if ( col - ui_catshift == 0 ) {
497 s = g_imagecache [ IMG_TAB_LINEL ].i;
498 } else if ( col - ui_catshift == maxtabspot - 1 ) {
499 s = g_imagecache [ IMG_TAB_LINER ].i;
501 s = g_imagecache [ IMG_TAB_LINE ].i;
503 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
504 dest -> y = tab_offset_y + tab_height;
505 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
511 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
512 rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ].catname, tmpfontcolor );
515 src.w = rtext -> w < text_width ? rtext -> w : text_width;
517 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
518 dest -> y = tab_offset_y + text_offset_y;
519 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
520 SDL_FreeSurface ( rtext );
527 if ( render_jobs_b & R_TABS ) {
529 // draw tab lines under where tabs would be if we had categories
530 for ( /* foo */; col < maxtabspot; col++ ) {
533 if ( col - ui_catshift == 0 ) {
534 s = g_imagecache [ IMG_TAB_LINEL ].i;
535 } else if ( col - ui_catshift == maxtabspot - 1 ) {
536 s = g_imagecache [ IMG_TAB_LINER ].i;
538 s = g_imagecache [ IMG_TAB_LINE ].i;
540 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
541 dest -> y = tab_offset_y + tab_height;
542 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
551 // scroll bars and arrows
552 if ( render_jobs_b & R_BG ) {
553 unsigned char show_bar = 0;
556 if ( ui_rows_scrolled_down && g_imagecache [ IMG_ARROW_UP ].i ) {
557 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
558 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
559 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
566 if ( ui_rows_scrolled_down + row_max < icon_rows && g_imagecache [ IMG_ARROW_DOWN ].i ) {
567 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
568 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
569 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
576 // show scrollbar as well
579 src.w = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_w", 10 );
580 src.h = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_h", 100 );
581 dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
582 dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
583 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
587 } // r_bg, scroll bars
589 // render detail pane bg
590 if ( render_jobs_b & R_DETAIL ) {
592 if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
595 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
596 src.x = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
597 src.y = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
598 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
599 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
600 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
601 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
602 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
606 // render detail pane
607 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
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_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
614 } // detailpane frame/bg
618 // anything to render?
619 if ( render_jobs_b & R_GRID ) {
621 // if just rendering grid, and nothing else, better clear it first
622 if ( ! ( render_jobs_b & R_BG ) ) {
623 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
624 src.x = grid_offset_x;
625 src.y = grid_offset_y + sel_icon_offset_y;
626 src.w = col_max * cell_width;
627 src.h = row_max * cell_height;
629 dest -> x = grid_offset_x;
630 dest -> y = grid_offset_y + sel_icon_offset_y;
632 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
638 if ( g_categories [ ui_category ].refs ) {
640 appiter = g_categories [ ui_category ].refs;
644 // until we run out of apps, or run out of space
645 while ( appiter != NULL ) {
647 for ( col = 0; col < col_max && appiter != NULL; col++ ) {
649 // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
650 if ( row >= ui_rows_scrolled_down ) {
652 // selected? show hilights
653 if ( appiter == ui_selected ) {
654 SDL_Surface *s = g_imagecache [ IMG_SELECTED_ALPHAMASK ].i;
656 //dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + ( ( icon_max_width - s -> w ) / 2 );
657 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + sel_icon_offset_x;
658 //dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + ( ( icon_max_height - s -> h ) / 2 );
659 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + sel_icon_offset_y;
660 SDL_BlitSurface ( s, NULL /* all */, sdl_realscreen, dest );
663 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
664 dest -> y = grid_offset_y + ( displayrow * cell_height ) + pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
665 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
670 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
671 SDL_Surface *iconsurface;
673 iconsurface = ic -> i;
675 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
677 // no icon override; was this a pnd-file (show the unknown icon then), or was this generated from
678 // filesystem (file or directory icon)
679 if ( appiter -> ref -> object_flags & PND_DISCO_GENERATED ) {
680 if ( appiter -> ref -> object_type == pnd_object_type_directory ) {
681 iconsurface = g_imagecache [ IMG_FOLDER ].i;
683 iconsurface = g_imagecache [ IMG_EXECBIN ].i;
686 iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
691 // got an icon I hope?
693 //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
699 dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + (( icon_max_width - iconsurface -> w ) / 2);
700 dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + (( icon_max_height - iconsurface -> h ) / 2);
702 SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
705 ui_register_app ( appiter, dest -> x, dest -> y, src.w, src.h );
712 if ( appiter -> ref -> title_en ) {
714 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
715 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, tmpfontcolor );
718 src.w = text_width < rtext -> w ? text_width : rtext -> w;
720 if ( rtext -> w > text_width ) {
721 dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
723 dest -> x = grid_offset_x + ( col * cell_width ) + text_offset_x - ( rtext -> w / 2 );
725 dest -> y = grid_offset_y + ( displayrow * cell_height ) + text_offset_y;
726 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
727 SDL_FreeSurface ( rtext );
731 } // display now? or scrolled away..
734 appiter = appiter -> next;
736 } // for column 1...X
738 if ( row >= ui_rows_scrolled_down ) {
744 // are we done displaying rows?
745 if ( displayrow >= row_max ) {
752 // no apps to render?
753 pnd_log ( pndn_rem, "No applications to render?\n" );
759 if ( ui_selected && render_jobs_b & R_DETAIL ) {
761 unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
762 unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
763 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "detailtext.cell_width" );
765 unsigned int desty = cell_offset_y;
770 if ( ui_selected -> ref -> title_en ) {
772 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
773 rtext = TTF_RenderText_Blended ( g_detailtext_font, ui_selected -> ref -> title_en, tmpfontcolor );
776 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
778 dest -> x = cell_offset_x;
780 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
781 SDL_FreeSurface ( rtext );
788 if ( ui_selected -> ref -> main_category ) {
790 sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
793 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
794 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
797 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
799 dest -> x = cell_offset_x;
801 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
802 SDL_FreeSurface ( rtext );
809 if ( ui_selected -> ref -> clockspeed ) {
811 sprintf ( buffer, "CPU Clock: %s", ui_selected -> ref -> clockspeed );
814 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
815 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
818 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
820 dest -> x = cell_offset_x;
822 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
823 SDL_FreeSurface ( rtext );
828 // show sub-app# on right side of cpu clock?
829 //if ( ui_selected -> ref -> subapp_number )
831 sprintf ( buffer, "(app#%u)", ui_selected -> ref -> subapp_number );
834 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
835 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
836 dest -> x = cell_offset_x + cell_width - rtext -> w;
837 dest -> y = desty - src.h;
838 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
839 SDL_FreeSurface ( rtext );
844 #if 0 // merged into hint-line
845 if ( ui_selected -> ref -> info_filename ) {
847 sprintf ( buffer, "Documentation - hit Y" );
850 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
851 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
854 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
856 dest -> x = cell_offset_x;
858 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
859 SDL_FreeSurface ( rtext );
866 if ( ui_selected -> ovrh ) {
871 desty += 5; // a touch of spacing can't hurt
873 for ( i = 1; i < 4; i++ ) {
874 sprintf ( buffer, "Application-%u.note-%u", ui_selected -> ref -> subapp_number, i );
875 n = pnd_conf_get_as_char ( ui_selected -> ovrh, buffer );
879 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
880 rtext = TTF_RenderText_Blended ( g_detailtext_font, n, tmpfontcolor );
883 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
885 dest -> x = cell_offset_x;
887 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
888 SDL_FreeSurface ( rtext );
894 } // r_detail -> notes
897 mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
898 SDL_Surface *previewpic;
901 previewpic = ic -> i;
903 previewpic = g_imagecache [ IMG_PREVIEW_MISSING ].i;
907 dest -> x = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_x", 50 ) +
908 ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
909 dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
910 SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
914 } // r_detail && selected?
920 if ( render_jobs_b & R_BG ) {
921 static int last_battlevel = 0;
922 static unsigned char batterylevel = 0;
925 if ( time ( NULL ) - last_battlevel > 60 ) {
926 batterylevel = pnd_device_get_battery_gauge_perc();
927 last_battlevel = time ( NULL );
930 sprintf ( buffer, "Battery: %u%%", batterylevel );
933 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
934 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
935 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.battery_x", 20 );
936 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.battery_y", 450 );
937 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
938 SDL_FreeSurface ( rtext );
943 if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
945 unsigned int hintx, hinty;
946 hintx = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
947 hinty = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
948 static unsigned int lastwidth = 3000;
950 if ( ui_selected && ui_selected -> ref -> info_filename ) {
951 buffer = "Documentation - hit Y";
953 buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
957 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
958 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
961 if ( ! ( render_jobs_b & R_BG ) ) {
968 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, &src, sdl_realscreen, dest );
970 lastwidth = rtext -> w;
976 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
977 SDL_FreeSurface ( rtext );
982 if ( render_jobs_b & R_BG &&
983 pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 )
987 time_t t = time ( NULL );
988 struct tm *tm = localtime ( &t );
989 strftime ( buffer, 50, "%a %H:%M %F", tm );
992 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
993 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
994 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.clock_x", 700 );
995 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.clock_y", 450 );
996 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
997 SDL_FreeSurface ( rtext );
1001 // update all the rects and send it all to sdl
1002 // - at this point, we could probably just do 1 rect, of the
1003 // whole screen, and be faster :/
1004 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1008 void ui_process_input ( unsigned char block_p ) {
1011 unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
1012 //static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
1014 while ( ! ui_event &&
1015 block_p ? SDL_WaitEvent ( &event ) : SDL_PollEvent ( &event ) )
1018 switch ( event.type ) {
1023 if ( event.user.code == sdl_user_ticker ) {
1025 // timer went off, time to load something
1026 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1028 // load the preview pics now!
1029 pnd_disco_t *iter = ui_selected -> ref;
1031 if ( iter -> preview_pic1 ) {
1033 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.threaded_preview", 0 ) ) {
1034 // load in bg thread, make user experience chuggy
1036 g_preview_thread = SDL_CreateThread ( (void*)ui_threaded_defered_preview, iter );
1038 if ( ! g_preview_thread ) {
1039 pnd_log ( pndn_error, "ERROR: Couldn't create preview thread\n" );
1043 // load it now, make user wait
1045 if ( ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
1046 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
1049 pnd_log ( pndn_debug, " Couldn't load preview pic: '%s' -> '%s'\n",
1050 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1055 } // got a preview at all?
1060 } else if ( event.user.code == sdl_user_finishedpreview ) {
1062 // if we just finished the one we happen to be looking at, better redraw now; otherwise, if
1063 // we finished another, no big woop
1064 if ( ui_selected && event.user.data1 == ui_selected -> ref ) {
1068 } else if ( event.user.code == sdl_user_finishedicon ) {
1069 // redraw, so we can show the newly loaded icon
1074 render_mask |= CHANGED_EVERYTHING;
1078 #if 0 // joystick motion
1079 case SDL_JOYAXISMOTION:
1081 pnd_log ( PND_LOG_DEFAULT, "joystick axis\n" );
1083 if ( event.jaxis.axis == 0 ) {
1085 if ( event.jaxis.value < 0 ) {
1087 pnd_log ( PND_LOG_DEFAULT, "joystick axis - LEFT\n" );
1088 } else if ( event.jaxis.value > 0 ) {
1089 ui_push_right ( 0 );
1090 pnd_log ( PND_LOG_DEFAULT, "joystick axis - RIGHT\n" );
1092 } else if ( event.jaxis.axis == 1 ) {
1094 if ( event.jaxis.value < 0 ) {
1096 } else if ( event.jaxis.value > 0 ) {
1106 #if 0 // joystick buttons
1107 case SDL_JOYBUTTONDOWN:
1109 pnd_log ( PND_LOG_DEFAULT, "joystick button down %u\n", event.jbutton.button );
1111 if ( event.jbutton.button == 0 ) { // B
1113 } else if ( event.jbutton.button == 1 ) { // Y
1115 } else if ( event.jbutton.button == 2 ) { // X
1117 } else if ( event.jbutton.button == 3 ) { // A
1120 } else if ( event.jbutton.button == 4 ) { // Select
1121 ui_mask |= uisb_select;
1122 } else if ( event.jbutton.button == 5 ) { // Start
1123 ui_mask |= uisb_start;
1125 } else if ( event.jbutton.button == 7 ) { // L
1127 } else if ( event.jbutton.button == 8 ) { // R
1136 case SDL_JOYBUTTONUP:
1138 pnd_log ( PND_LOG_DEFAULT, "joystick button up %u\n", event.jbutton.button );
1140 if ( event.jbutton.button == 0 ) { // B
1143 } else if ( event.jbutton.button == 1 ) { // Y
1145 } else if ( event.jbutton.button == 2 ) { // X
1147 } else if ( event.jbutton.button == 3 ) { // A
1150 } else if ( event.jbutton.button == 4 ) { // Select
1151 ui_mask &= ~uisb_select;
1152 } else if ( event.jbutton.button == 5 ) { // Start
1153 ui_mask &= ~uisb_start;
1155 } else if ( event.jbutton.button == 7 ) { // L
1158 } else if ( event.jbutton.button == 8 ) { // R
1169 #if 1 // keyboard events
1172 //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
1174 // SDLK_LALT -> Start
1177 if ( event.key.keysym.sym == SDLK_RIGHT ) {
1178 ui_push_right ( 0 );
1180 } else if ( event.key.keysym.sym == SDLK_LEFT ) {
1183 } else if ( event.key.keysym.sym == SDLK_UP ) {
1186 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1189 } else if ( event.key.keysym.sym == SDLK_SPACE || event.key.keysym.sym == SDLK_END ) {
1192 } else if ( event.key.keysym.sym == SDLK_z || event.key.keysym.sym == SDLK_RSHIFT ) {
1195 } else if ( event.key.keysym.sym == SDLK_x || event.key.keysym.sym == SDLK_RCTRL ) {
1198 } else if ( event.key.keysym.sym == SDLK_y || event.key.keysym.sym == SDLK_PAGEUP ) {
1200 if ( ui_selected ) {
1201 ui_show_info ( pnd_run_script, ui_selected -> ref );
1205 } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
1209 } else if ( event.key.keysym.sym == SDLK_LCTRL /*LALT*/ ) { // select button
1210 char *opts [ 20 ] = {
1211 "Return to Minimenu",
1213 "Rescan for Applications",
1214 "Cache previews to SD now",
1215 "Run xfce4 from Minimenu",
1216 "Run a terminal/console",
1217 "Switch preferred GUI",
1219 "Select a Minimenu skin",
1222 int sel = ui_modal_single_menu ( opts, 10, "Minimenu", "Enter to select; other to return." );
1224 char buffer [ 100 ];
1227 } else if ( sel == 1 ) {
1229 sprintf ( buffer, "sudo poweroff" );
1231 } else if ( sel == 2 ) {
1233 pnd_log ( pndn_debug, "Freeing up applications\n" );
1234 applications_free();
1235 pnd_log ( pndn_debug, "Rescanning applications\n" );
1236 applications_scan();
1239 ui_rows_scrolled_down = 0;
1240 // set back to first tab, to be safe
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 ) {
1268 char buffer [ PATH_MAX ];
1269 sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/bin/startxfce4" );
1270 emit_and_quit ( buffer );
1271 } else if ( sel == 5 ) {
1274 argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
1278 ui_forkexec ( argv );
1281 } else if ( sel == 6 ) {
1282 char buffer [ PATH_MAX ];
1283 sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/pandora/scripts/op_switchgui.sh" );
1284 emit_and_quit ( buffer );
1285 } else if ( sel == 7 ) {
1286 emit_and_quit ( MM_QUIT );
1287 } else if ( sel == 8 ) {
1289 if ( ui_pick_skin() ) {
1290 emit_and_quit ( MM_RESTART );
1292 } else if ( sel == 9 ) {
1294 char buffer [ PATH_MAX ];
1295 sprintf ( buffer, "%s/about.txt", g_skinpath );
1296 ui_aboutscreen ( buffer );
1300 render_mask |= CHANGED_EVERYTHING;
1304 if ( event.key.keysym.sym == SDLK_q ) {
1305 emit_and_quit ( MM_QUIT );
1311 #if 1 // mouse / touchscreen
1313 case SDL_MOUSEBUTTONDOWN:
1314 if ( event.button.button == SDL_BUTTON_LEFT ) {
1315 cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
1321 case SDL_MOUSEBUTTONUP:
1322 if ( event.button.button == SDL_BUTTON_LEFT ) {
1323 ui_touch_act ( event.button.x, event.button.y );
1336 } // switch event type
1343 void ui_push_left ( unsigned char forcecoil ) {
1345 if ( ! ui_selected ) {
1346 ui_push_right ( 0 );
1350 // what column we in?
1351 unsigned int col = ui_determine_screen_col ( ui_selected );
1353 // are we already at first item?
1354 if ( forcecoil == 0 &&
1355 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1358 unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1359 while ( i && ui_selected -> next ) {
1360 ui_push_right ( 0 );
1364 } else if ( g_categories [ ui_category ].refs == ui_selected ) {
1365 // can't go any more left, we're at the head
1368 // figure out the previous item; yay for singly linked list :/
1369 mm_appref_t *i = g_categories [ ui_category ].refs;
1371 if ( i -> next == ui_selected ) {
1379 ui_set_selected ( ui_selected );
1384 void ui_push_right ( unsigned char forcecoil ) {
1386 if ( ui_selected ) {
1388 // what column we in?
1389 unsigned int col = ui_determine_screen_col ( ui_selected );
1392 if ( forcecoil == 0 &&
1393 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1394 // and selected is far-right, or last icon in category (might not be far right)
1395 ( ( col == pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1 ) ||
1396 ( ui_selected -> next == NULL ) )
1400 //unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1401 while ( col /*i*/ ) {
1407 // just go to the next
1409 if ( ui_selected -> next ) {
1410 ui_selected = ui_selected -> next;
1416 ui_selected = g_categories [ ui_category ].refs;
1419 ui_set_selected ( ui_selected );
1424 void ui_push_up ( void ) {
1425 unsigned char col_max = pnd_conf_get_as_int ( g_conf, "grid.col_max" );
1427 if ( ! ui_selected ) {
1432 unsigned int row = ui_determine_row ( ui_selected );
1435 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 1 ) == 0 )
1437 // wrap around instead
1439 unsigned int col = ui_determine_screen_col ( ui_selected );
1442 ui_selected = g_categories [ ui_category ].refs;
1443 while ( ui_selected -> next ) {
1444 ui_selected = ui_selected -> next;
1447 // try to move to same column
1448 unsigned int newcol = ui_determine_screen_col ( ui_selected );
1449 if ( newcol > col ) {
1457 // scroll down to show it
1458 int r = ui_determine_row ( ui_selected ) - 1;
1459 if ( r - pnd_conf_get_as_int ( g_conf, "grid.row_max" ) > 0 ) {
1460 ui_rows_scrolled_down = (unsigned int) r;
1464 // stop at top/bottom
1476 void ui_push_down ( void ) {
1477 unsigned char col_max = pnd_conf_get_as_int ( g_conf, "grid.col_max" );
1479 if ( ui_selected ) {
1482 unsigned int row = ui_determine_row ( ui_selected );
1485 unsigned int icon_rows = g_categories [ ui_category ].refcount / col_max;
1486 if ( g_categories [ ui_category ].refcount % col_max > 0 ) {
1491 if ( row == ( icon_rows - 1 ) &&
1492 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 1 ) == 0 )
1495 unsigned char col = ui_determine_screen_col ( ui_selected );
1497 ui_selected = g_categories [ ui_category ].refs;
1500 ui_selected = ui_selected -> next;
1504 ui_rows_scrolled_down = 0;
1506 render_mask |= CHANGED_EVERYTHING;
1511 ui_push_right ( 1 );
1518 ui_push_right ( 0 );
1524 void ui_push_exec ( void ) {
1526 if ( ! ui_selected ) {
1530 // was this icon generated from filesystem, or from pnd-file?
1531 if ( ui_selected -> ref -> object_flags & PND_DISCO_GENERATED ) {
1533 if ( ! ui_selected -> ref -> title_en ) {
1534 return; // no filename
1537 if ( ui_selected -> ref -> object_type == pnd_object_type_directory ) {
1538 // delve up/down the dir tree
1540 if ( strcmp ( ui_selected -> ref -> title_en, ".." ) == 0 ) {
1544 // lop off last word; if the thing ends with /, lop that one, then the next word.
1545 while ( ( c = strrchr ( g_categories [ ui_category].fspath, '/' ) ) ) {
1546 *c = '\0'; // lop off the last hunk
1547 if ( *(c+1) != '\0' ) {
1553 if ( g_categories [ ui_category].fspath [ 0 ] == '\0' ) {
1554 strcpy ( g_categories [ ui_category].fspath, "/" );
1559 strcat ( g_categories [ ui_category].fspath, "/" );
1560 strcat ( g_categories [ ui_category].fspath, ui_selected -> ref -> title_en );
1563 pnd_log ( pndn_debug, "Cat %s is now in path %s\n", g_categories [ ui_category ].catname, g_categories [ ui_category ].fspath );
1566 category_fs_restock ( &(g_categories [ ui_category]) );
1567 // forget the selection, nolonger applies
1569 ui_set_selected ( ui_selected );
1571 render_mask |= CHANGED_SELECTION;
1574 // just run it arbitrarily?
1576 // if this a pnd-file, or just some executable?
1577 if ( strcasestr ( ui_selected -> ref -> object_filename, PND_PACKAGE_FILEEXT ) ) {
1578 // looks like a pnd, now what do we do..
1579 pnd_box_handle h = pnd_disco_file ( ui_selected -> ref -> object_path, ui_selected -> ref -> object_filename );
1582 pnd_disco_t *d = pnd_box_get_head ( h );
1583 pnd_apps_exec_disco ( pnd_run_script, d, PND_EXEC_OPTION_NORUN, NULL );
1584 char buffer [ PATH_MAX ];
1585 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1586 emit_and_quit ( buffer );
1592 char cwd [ PATH_MAX ];
1593 getcwd ( cwd, PATH_MAX );
1595 chdir ( g_categories [ ui_category ].fspath );
1596 pnd_exec_no_wait_1 ( ui_selected -> ref -> title_en, NULL );
1599 char buffer [ PATH_MAX ];
1600 sprintf ( buffer, "%s %s/%s\n", MM_RUN, g_categories [ ui_category ].fspath, ui_selected -> ref -> title_en );
1601 emit_and_quit ( buffer );
1608 pnd_apps_exec_disco ( pnd_run_script, ui_selected -> ref, PND_EXEC_OPTION_NORUN, NULL );
1609 char buffer [ PATH_MAX ];
1610 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1611 emit_and_quit ( buffer );
1617 void ui_push_ltrigger ( void ) {
1618 unsigned char oldcat = ui_category;
1619 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
1620 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1622 if ( ui_category > 0 ) {
1624 category_fs_restock ( &(g_categories [ ui_category ]) );
1626 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1627 ui_category = g_categorycount - 1;
1629 if ( ui_category >= ( screen_width / tab_width ) ) {
1630 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
1632 category_fs_restock ( &(g_categories [ ui_category ]) );
1636 if ( oldcat != ui_category ) {
1638 ui_set_selected ( ui_selected );
1641 // make tab visible?
1642 if ( ui_catshift > 0 && ui_category == ui_catshift - 1 ) {
1647 ui_rows_scrolled_down = 0;
1649 render_mask |= CHANGED_CATEGORY;
1654 void ui_push_rtrigger ( void ) {
1655 unsigned char oldcat = ui_category;
1657 unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
1658 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1660 if ( ui_category < ( g_categorycount - 1 ) ) {
1662 category_fs_restock ( &(g_categories [ ui_category ]) );
1664 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1667 category_fs_restock ( &(g_categories [ ui_category ]) );
1671 if ( oldcat != ui_category ) {
1673 ui_set_selected ( ui_selected );
1676 // make tab visible?
1677 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
1682 ui_rows_scrolled_down = 0;
1684 render_mask |= CHANGED_CATEGORY;
1689 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ) {
1690 double scale = 1000000.0;
1691 double scalex = 1000000.0;
1692 double scaley = 1000000.0;
1693 SDL_Surface *scaled;
1695 scalex = (double)maxwidth / (double)s -> w;
1697 if ( maxheight == -1 ) {
1700 scaley = (double)maxheight / (double)s -> h;
1702 if ( scaley < scalex ) {
1710 scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
1711 SDL_FreeSurface ( s );
1717 void ui_loadscreen ( void ) {
1721 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1722 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1723 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1724 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1727 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1731 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1732 rtext = TTF_RenderText_Blended ( g_big_font, "Setting up menu...", tmpfontcolor );
1735 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1736 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1737 SDL_FreeSurface ( rtext );
1742 void ui_discoverscreen ( unsigned char clearscreen ) {
1746 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1747 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1748 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1749 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1752 if ( clearscreen ) {
1753 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1755 // render background
1756 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1759 dest.w = sdl_realscreen -> w;
1760 dest.h = sdl_realscreen -> h;
1761 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1762 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1769 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1770 rtext = TTF_RenderText_Blended ( g_big_font, "Looking for applications...", tmpfontcolor );
1771 if ( clearscreen ) {
1778 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
1779 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1780 SDL_FreeSurface ( rtext );
1783 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1784 dest.x = rtext -> w + 30;
1786 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, &dest );
1787 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1793 void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
1795 SDL_Rect rects [ 4 ];
1796 SDL_Rect *dest = rects;
1798 bzero ( dest, sizeof(SDL_Rect)* 4 );
1800 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1801 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1802 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1803 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1805 static unsigned int stepx = 0;
1808 if ( clearscreen ) {
1809 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
1811 // render background
1812 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1815 dest -> w = sdl_realscreen -> w;
1816 dest -> h = sdl_realscreen -> h;
1817 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
1823 // render background
1824 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
1827 src.w = sdl_realscreen -> w;
1831 dest -> w = sdl_realscreen -> w;
1832 dest -> h = sdl_realscreen -> h;
1833 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
1841 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1842 rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
1845 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1846 SDL_FreeSurface ( rtext );
1850 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
1851 dest -> x = rtext -> w + 30 + stepx;
1853 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, dest );
1859 rtext = TTF_RenderText_Blended ( g_tab_font, filename, tmpfontcolor );
1862 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1863 SDL_FreeSurface ( rtext );
1870 if ( stepx > 350 ) {
1874 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1879 int ui_selected_index ( void ) {
1881 if ( ! ui_selected ) {
1882 return ( -1 ); // no index
1885 mm_appref_t *r = g_categories [ ui_category ].refs;
1888 if ( r == ui_selected ) {
1898 static mm_appref_t *timer_ref = NULL;
1899 void ui_set_selected ( mm_appref_t *r ) {
1901 render_mask |= CHANGED_SELECTION;
1903 if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1904 return; // no desire to defer anything
1909 SDL_SetTimer ( 0, NULL );
1914 SDL_SetTimer ( pnd_conf_get_as_int_d ( g_conf, "previewpic.defer_timer_ms", 1000 ), ui_callback_f );
1920 unsigned int ui_callback_f ( unsigned int t ) {
1922 if ( ui_selected != timer_ref ) {
1923 return ( 0 ); // user has moved it, who cares
1927 bzero ( &e, sizeof(SDL_Event) );
1928 e.type = SDL_USEREVENT;
1929 e.user.code = sdl_user_ticker;
1930 SDL_PushEvent ( &e );
1935 int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer ) {
1936 SDL_Rect rects [ 40 ];
1937 SDL_Rect *dest = rects;
1941 bzero ( rects, sizeof(SDL_Rect) * 40 );
1943 unsigned int sel = 0;
1945 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
1946 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
1947 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
1948 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
1950 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
1952 SDL_Color selfontcolor = { 0/*font_rgba_r*/, font_rgba_g, font_rgba_b, font_rgba_a };
1960 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1961 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1962 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
1963 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
1964 SDL_FillRect( sdl_realscreen, dest, 0 );
1966 // show dialog background
1967 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
1968 src.x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1969 src.y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1970 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
1971 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
1972 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1973 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1974 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1975 // repeat for darken?
1976 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1977 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
1978 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1982 // show dialog frame
1983 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
1984 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
1985 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
1986 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
1987 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
1993 rtext = TTF_RenderText_Blended ( g_tab_font, title, tmpfontcolor );
1994 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
1995 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
1996 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
1997 SDL_FreeSurface ( rtext );
2003 rtext = TTF_RenderText_Blended ( g_tab_font, footer, tmpfontcolor );
2004 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2005 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
2006 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
2008 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2009 SDL_FreeSurface ( rtext );
2014 for ( i = 0; i < argc; i++ ) {
2018 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
2020 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], tmpfontcolor );
2022 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2023 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 ) );
2024 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2025 SDL_FreeSurface ( rtext );
2030 // update all the rects and send it all to sdl
2031 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
2035 while ( SDL_WaitEvent ( &event ) ) {
2037 switch ( event.type ) {
2041 if ( event.key.keysym.sym == SDLK_UP ) {
2045 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
2046 if ( sel < argc - 1 ) {
2050 } else if ( event.key.keysym.sym == SDLK_RETURN ) {
2053 } else if ( event.key.keysym.sym == SDLK_q ) {
2057 return ( -1 ); // nada
2072 unsigned char ui_determine_row ( mm_appref_t *a ) {
2073 unsigned int row = 0;
2075 mm_appref_t *i = g_categories [ ui_category ].refs;
2080 row /= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
2085 unsigned char ui_determine_screen_row ( mm_appref_t *a ) {
2086 return ( ui_determine_row ( a ) % pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 5 ) );
2089 unsigned char ui_determine_screen_col ( mm_appref_t *a ) {
2090 unsigned int col = 0;
2092 mm_appref_t *i = g_categories [ ui_category ].refs;
2097 col %= pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
2102 unsigned char ui_show_info ( char *pndrun, pnd_disco_t *p ) {
2103 char *viewer, *searchpath;
2104 pnd_conf_handle desktoph;
2107 searchpath = pnd_conf_query_searchpath();
2109 desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
2115 viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
2118 return ( 0 ); // no way to view the file
2122 if ( ! p -> unique_id ) {
2126 if ( ! p -> info_filename ) {
2130 if ( ! p -> info_name ) {
2141 if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) {
2142 snprintf ( pargs, 1001, "%s %s",
2143 pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
2148 char pndfile [ 1024 ];
2149 if ( p -> object_type == pnd_object_type_directory ) {
2150 // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
2151 strncpy ( pndfile, p -> object_path, 1000 );
2152 } else if ( p -> object_type == pnd_object_type_pnd ) {
2153 // pnd_run.sh wants the full path and filename for the .pnd file
2154 snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
2157 if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs,
2158 p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) )
2163 pnd_log ( pndn_debug, "Info Exec=%s\n", pnd_apps_exec_runline() );
2167 if ( ( x = fork() ) < 0 ) {
2168 pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
2173 execl ( "/bin/sh", "/bin/sh", "-c", pnd_apps_exec_runline(), (char*)NULL );
2174 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", pnd_apps_exec_runline() );
2186 #define MAXTOUCH 100
2187 ui_touch_t ui_touchrects [ MAXTOUCH ];
2188 unsigned char ui_touchrect_count = 0;
2190 void ui_register_reset ( void ) {
2191 bzero ( ui_touchrects, sizeof(ui_touch_t)*MAXTOUCH );
2192 ui_touchrect_count = 0;
2196 void ui_register_tab ( unsigned char catnum, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2198 if ( ui_touchrect_count == MAXTOUCH ) {
2202 ui_touchrects [ ui_touchrect_count ].r.x = x;
2203 ui_touchrects [ ui_touchrect_count ].r.y = y;
2204 ui_touchrects [ ui_touchrect_count ].r.w = w;
2205 ui_touchrects [ ui_touchrect_count ].r.h = h;
2206 ui_touchrects [ ui_touchrect_count ].catnum = catnum;
2207 ui_touchrect_count++;
2212 void ui_register_app ( mm_appref_t *app, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2214 if ( ui_touchrect_count == MAXTOUCH ) {
2218 ui_touchrects [ ui_touchrect_count ].r.x = x;
2219 ui_touchrects [ ui_touchrect_count ].r.y = y;
2220 ui_touchrects [ ui_touchrect_count ].r.w = w;
2221 ui_touchrects [ ui_touchrect_count ].r.h = h;
2222 ui_touchrects [ ui_touchrect_count ].ref = app;
2223 ui_touchrect_count++;
2228 void ui_touch_act ( unsigned int x, unsigned int y ) {
2233 for ( i = 0; i < ui_touchrect_count; i++ ) {
2234 t = &(ui_touchrects [ i ]);
2236 if ( x >= t -> r.x &&
2237 x <= t -> r.x + t -> r.w &&
2239 y <= t -> r.y + t -> r.h
2244 ui_selected = t -> ref;
2247 if ( ui_category != t -> catnum ) {
2250 ui_category = t -> catnum;
2251 render_mask |= CHANGED_CATEGORY;
2262 unsigned char ui_forkexec ( char *argv[] ) {
2263 char *fooby = argv[0];
2266 if ( ( x = fork() ) < 0 ) {
2267 pnd_log ( pndn_error, "ERROR: Couldn't fork() for '%s'\n", fooby );
2271 if ( x == 0 ) { // child
2272 execv ( fooby, argv );
2273 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", fooby );
2281 unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ) {
2283 if ( ! cache_preview ( p, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
2284 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
2287 pnd_log ( pndn_debug, "THREAD: Couldn't load preview pic: '%s' -> '%s'\n",
2288 IFNULL(p->title_en,"No Name"), p -> preview_pic1 );
2291 // trigger that we completed
2293 bzero ( &e, sizeof(SDL_Event) );
2294 e.type = SDL_USEREVENT;
2295 e.user.code = sdl_user_finishedpreview;
2297 SDL_PushEvent ( &e );
2302 SDL_Thread *g_icon_thread = NULL;
2303 void ui_post_scan ( void ) {
2305 // if deferred icon load, kick off the thread now
2306 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 1 ) {
2308 g_icon_thread = SDL_CreateThread ( (void*)ui_threaded_defered_icon, NULL );
2310 if ( ! g_icon_thread ) {
2311 pnd_log ( pndn_error, "ERROR: Couldn't create icon thread\n" );
2314 } // deferred icon load
2319 unsigned char ui_threaded_defered_icon ( void *p ) {
2320 extern pnd_box_handle g_active_apps;
2321 pnd_box_handle h = g_active_apps;
2323 unsigned char maxwidth, maxheight;
2324 maxwidth = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 );
2325 maxheight = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_height", 50 );
2327 pnd_disco_t *iter = pnd_box_get_head ( h );
2332 if ( iter -> pnd_icon_pos &&
2333 ! cache_icon ( iter, maxwidth, maxheight ) )
2335 pnd_log ( pndn_warning, " Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2338 // trigger that we completed
2340 bzero ( &e, sizeof(SDL_Event) );
2341 e.type = SDL_USEREVENT;
2342 e.user.code = sdl_user_finishedicon;
2343 SDL_PushEvent ( &e );
2345 //pnd_log ( pndn_warning, " Finished deferred load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2346 usleep ( pnd_conf_get_as_int_d ( g_conf, "minimenu.defer_icon_us", 50000 ) );
2351 iter = pnd_box_get_next ( iter );
2357 void ui_show_hourglass ( unsigned char updaterect ) {
2360 SDL_Surface *s = g_imagecache [ IMG_HOURGLASS ].i;
2362 dest.x = ( 800 - s -> w ) / 2;
2363 dest.y = ( 480 - s -> h ) / 2;
2365 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, &dest );
2368 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2374 unsigned char ui_pick_skin ( void ) {
2376 char *skins [ MAXSKINS ];
2379 char *searchpath = pnd_conf_get_as_char ( g_conf, "minimenu.skin_searchpath" );
2380 char tempname [ 100 ];
2384 skins [ iter++ ] = "No skin change";
2388 DIR *d = opendir ( buffer );
2393 while ( ( dd = readdir ( d ) ) ) {
2395 if ( dd -> d_name [ 0 ] == '.' ) {
2397 } else if ( ( dd -> d_type == DT_DIR || dd -> d_type == DT_UNKNOWN ) &&
2400 snprintf ( tempname, 100, "Skin: %s", dd -> d_name );
2401 skins [ iter++ ] = strdup ( tempname );
2412 int sel = ui_modal_single_menu ( skins, iter, "Skins", "Enter to select; other to return." );
2414 // did they pick one?
2418 char *s = strdup ( pnd_conf_get_as_char ( g_conf, "minimenu.skin_selected" ) );
2419 s = pnd_expand_tilde ( s );
2421 f = fopen ( s, "w" );
2426 fprintf ( f, "%s\n", skins [ sel ] + 6 );
2436 void ui_aboutscreen ( char *textpath ) {
2443 #define ROWS SCRH / ( PIXELH + MARGINH )
2444 #define COLS SCRW / ( PIXELW + MARGINW )
2446 unsigned char pixelboard [ ROWS * COLS ]; // pixel heat
2447 bzero ( pixelboard, ROWS * COLS );
2452 SDL_Color rtextc = { 200, 200, 200, 100 };
2455 char *textloop [ 500 ];
2456 unsigned int textmax = 0;
2457 bzero ( textloop, 500 * sizeof(char*) );
2460 char cbuffer [ 50000 ];
2461 bzero ( cbuffer, 50000 );
2462 unsigned int crevealed = 0;
2464 FILE *f = fopen ( textpath, "r" );
2467 pnd_log ( pndn_error, "ERROR: Couldn't open about text: %s\n", textpath );
2471 char textbuf [ 100 ];
2472 while ( fgets ( textbuf, 100, f ) ) {
2474 // add to full buffer
2475 strncat ( cbuffer, textbuf, 50000 );
2478 if ( strchr ( textbuf, '\n' ) ) {
2479 * strchr ( textbuf, '\n' ) = '\0';
2482 // add to pixel loop
2483 if ( 1||textbuf [ 0 ] ) {
2484 textloop [ textmax ] = strdup ( textbuf );
2492 unsigned int textiter = 0;
2493 while ( textiter < textmax ) {
2494 char *text = textloop [ textiter ];
2498 // render to surface
2499 rtext = TTF_RenderText_Blended ( g_grid_font, text, rtextc );
2501 // render font to pixelboard
2502 unsigned int px, py;
2504 unsigned int *pixels = rtext -> pixels;
2505 unsigned char cr, cg, cb, ca;
2506 for ( py = 0; py < rtext -> h; py ++ ) {
2507 for ( px = 0; px < ( rtext -> w > COLS ? COLS : rtext -> w ); px++ ) {
2509 SDL_GetRGBA ( pixels [ ( py * rtext -> pitch / 4 ) + px ],
2510 rtext -> format, &cr, &cg, &cb, &ca );
2514 ph = pixelboard + ( /*y offset */ 30 * COLS ) + ( py * COLS ) + px /* / 2 */;
2521 if ( *ph + ca < 250 ) {
2532 unsigned int runcount = 10;
2533 while ( runcount-- ) {
2536 SDL_FillRect( sdl_realscreen, NULL /* whole */, 0 );
2538 // render pixelboard
2541 for ( y = 0; y < ROWS; y++ ) {
2542 for ( x = 0; x < COLS; x++ ) {
2544 if ( 1||pixelboard [ ( y * COLS ) + x ] ) {
2547 r.x = x * ( PIXELW + MARGINW );
2548 r.y = y * ( PIXELH + MARGINH );
2552 c = SDL_MapRGB ( sdl_realscreen -> format, 100 /* r */, 0 /* g */, pixelboard [ ( y * COLS ) + x ] );
2554 SDL_FillRect( sdl_realscreen, &r /* whole */, c );
2562 unsigned char *pc = pixelboard;
2563 for ( y = 0; y < ROWS; y++ ) {
2564 for ( x = 0; x < COLS; x++ ) {
2574 // slide pixels upwards
2575 memmove ( pixelboard, pixelboard + COLS, ( COLS * ROWS ) - COLS );
2577 // render actual readable text
2580 // display up to cursor
2582 unsigned int cdraw = 0;
2586 if ( crevealed > 200 ) {
2587 cdraw = crevealed - 200;
2593 for ( ; cdraw < crevealed; cdraw++ ) {
2594 ctb [ 0 ] = cbuffer [ cdraw ];
2596 // move over or down
2597 if ( cbuffer [ cdraw ] == '\n' ) {
2602 if ( dest.y > 450 ) {
2608 cs = TTF_RenderText_Blended ( g_tab_font, ctb, rtextc );
2610 SDL_BlitSurface ( cs, NULL /* all */, sdl_realscreen, &dest );
2611 SDL_FreeSurface ( cs );
2621 SDL_FillRect ( sdl_realscreen, &dest /* whole */, 220 );
2623 // increment cursor to next character
2624 if ( cbuffer [ crevealed ] != '\0' ) {
2628 } // draw cursor text
2632 SDL_UpdateRect ( sdl_realscreen, 0, 0, 0, 0 ); // whole screen
2636 // any button? if so, about
2642 if ( SDL_PeepEvents ( &e, 1, SDL_GETEVENT, SDL_EVENTMASK(SDL_KEYUP) ) > 0 ) {
2651 SDL_FreeSurface ( rtext );
2655 } // while more text