change one comment in pnd_pxml.h to be more right
[pandora-libraries.git] / minimenu / mmui.c
index 68ae3c8..d0d3f78 100644 (file)
@@ -32,7 +32,10 @@ SDL_Surface *sdl_realscreen = NULL;
 unsigned int sdl_ticks = 0;
 SDL_Thread *g_preview_thread = NULL;
 
-enum { sdl_user_ticker = 0, sdl_user_finishedpreview = 1 };
+enum { sdl_user_ticker = 0,
+       sdl_user_finishedpreview = 1,
+       sdl_user_finishedicon = 2,
+};
 
 /* app state
  */
@@ -278,6 +281,7 @@ void ui_render ( unsigned int render_mask ) {
   unsigned int icon_offset_x = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_x" );
   unsigned int icon_offset_y = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_y" );
   unsigned int icon_max_width = pnd_conf_get_as_int ( g_conf, "grid.icon_max_width" );
+  unsigned int icon_max_height = pnd_conf_get_as_int ( g_conf, "grid.icon_max_height" );
 
   unsigned int text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
   unsigned int text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
@@ -358,6 +362,7 @@ void ui_render ( unsigned int render_mask ) {
     unsigned int text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
     unsigned int maxtab = ( screen_width / tab_width ) < g_categorycount ? ( screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift;
 
+    // draw tabs with categories
     for ( col = ui_catshift;
          col < maxtab;
          col++ )
@@ -392,17 +397,13 @@ void ui_render ( unsigned int render_mask ) {
       // draw tab line
       if ( col == ui_category ) {
        // no line for selected tab
-       printf ( "skipselevting L\n" );
       } else {
        if ( col - ui_catshift == 0 ) {
          s = g_imagecache [ IMG_TAB_LINEL ].i;
-         printf ( "selevting L\n" );
        } else if ( col - ui_catshift == maxtab - 1 ) {
          s = g_imagecache [ IMG_TAB_LINER ].i;
-         printf ( "selevting R\n" );
        } else {
          s = g_imagecache [ IMG_TAB_LINE ].i;
-         printf ( "selevting M\n" );
        }
        dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
        dest -> y = tab_offset_y + tab_height;
@@ -426,6 +427,25 @@ void ui_render ( unsigned int render_mask ) {
 
     } // for
 
+    // draw tab lines under where tabs would be if we had categories
+    maxtab = ( screen_width / tab_width );
+    for ( /* foo */; col < maxtab; col++ ) {
+      SDL_Surface *s;
+
+      if ( col - ui_catshift == 0 ) {
+       s = g_imagecache [ IMG_TAB_LINEL ].i;
+      } else if ( col - ui_catshift == maxtab - 1 ) {
+       s = g_imagecache [ IMG_TAB_LINER ].i;
+      } else {
+       s = g_imagecache [ IMG_TAB_LINE ].i;
+      }
+      dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
+      dest -> y = tab_offset_y + tab_height;
+      SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
+      dest++;
+
+    } // for
+
   } // tabs
 
   // scroll bars and arrows
@@ -536,7 +556,7 @@ void ui_render ( unsigned int render_mask ) {
            src.w = 60;
            src.h = 60;
            dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + (( icon_max_width - iconsurface -> w ) / 2);
-           dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y;
+           dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + (( icon_max_height - iconsurface -> h ) / 2);
 
            SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
 
@@ -660,6 +680,21 @@ void ui_render ( unsigned int render_mask ) {
       desty += src.h;
     }
 
+    // show sub-app# on right side of cpu clock?
+    //if ( ui_selected -> ref -> subapp_number )
+    {
+      sprintf ( buffer, "(app#%u)", ui_selected -> ref -> subapp_number );
+
+      SDL_Surface *rtext;
+      SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
+      rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
+      dest -> x = cell_offset_x + cell_width - rtext -> w;
+      dest -> y = desty - src.h;
+      SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
+      SDL_FreeSurface ( rtext );
+      dest++;
+    }
+
     // info hint
     if ( ui_selected -> ref -> clockspeed && ui_selected -> ref -> info_filename ) {
 
@@ -824,6 +859,10 @@ void ui_process_input ( unsigned char block_p ) {
          ui_event++;
        }
 
+      } else if ( event.user.code == sdl_user_finishedicon ) {
+       // redraw, so we can show the newly loaded icon
+       ui_event++;
+
       }
 
       break;
@@ -1926,3 +1965,58 @@ unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ) {
 
   return ( 0 );
 }
+
+SDL_Thread *g_icon_thread = NULL;
+void ui_post_scan ( void ) {
+
+  // if deferred icon load, kick off the thread now
+  if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 1 ) {
+
+    g_icon_thread = SDL_CreateThread ( (void*)ui_threaded_defered_icon, NULL );
+
+    if ( ! g_icon_thread ) {
+      pnd_log ( pndn_error, "ERROR: Couldn't create icon thread\n" );
+    }
+
+  } // deferred icon load
+
+  return;
+}
+
+unsigned char ui_threaded_defered_icon ( void *p ) {
+  extern pnd_box_handle g_active_apps;
+  pnd_box_handle h = g_active_apps;
+
+  unsigned char maxwidth, maxheight;
+  maxwidth = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_ICON_MAX_WIDTH, 50 );
+  maxheight = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_ICON_MAX_HEIGHT, 50 );
+
+  pnd_disco_t *iter = pnd_box_get_head ( h );
+
+  while ( iter ) {
+
+    // cache it
+    if ( iter -> pnd_icon_pos &&
+        ! cache_icon ( iter, maxwidth, maxheight ) )
+    {
+      pnd_log ( pndn_warning, "  Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
+    } else {
+
+      // trigger that we completed
+      SDL_Event e;
+      bzero ( &e, sizeof(SDL_Event) );
+      e.type = SDL_USEREVENT;
+      e.user.code = sdl_user_finishedicon;
+      SDL_PushEvent ( &e );
+
+      //pnd_log ( pndn_warning, "  Finished deferred load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
+      usleep ( pnd_conf_get_as_int_d ( g_conf, "minimenu.defer_icon_us", 50000 ) );
+
+    }
+
+    // next
+    iter = pnd_box_get_next ( iter );
+  } // while
+
+  return ( 0 );
+}