Code

Fixing preview/swatch sizes.
authorjoncruz <joncruz@users.sourceforge.net>
Mon, 18 Feb 2008 09:25:27 +0000 (09:25 +0000)
committerjoncruz <joncruz@users.sourceforge.net>
Mon, 18 Feb 2008 09:25:27 +0000 (09:25 +0000)
src/dialogs/eek-preview.cpp
src/dialogs/eek-preview.h
src/dialogs/swatches.cpp
src/inkscape-stock.cpp
src/ui/widget/panel.cpp
src/ui/widget/panel.h
src/widgets/icon.cpp
src/widgets/icon.h

index 41149177752c3396bdcb146e9df4be3df6df771c..1716a7cd65be1257a3e3b7fd559fb5d908dc1de0 100644 (file)
@@ -90,6 +90,54 @@ GType eek_preview_get_type(void)
     return preview_type;
 }
 
+static guint trackCount = 0;
+static guint* trackSizes = 0;
+static GtkIconSize* trackKeys = 0;
+
+void eek_preview_set_size_mappings( guint count, GtkIconSize const* sizes )
+{
+    gint width = 0;
+    gint height = 0;
+    gint smallest = 512;
+    gint largest = 0;
+    guint i = 0;
+    guint delta = 0;
+
+    for ( i = 0; i < count; ++i ) {
+        gboolean worked = gtk_icon_size_lookup( sizes[i], &width, &height );
+        if ( worked ) {
+            if ( width < smallest ) {
+                smallest = width;
+            }
+            if ( width > largest ) {
+                largest = width;
+            }
+        }
+    }
+
+    smallest = (smallest * 3) / 4;
+
+    delta = largest - smallest;
+
+    if ( trackSizes ) {
+        g_free(trackSizes);
+        trackSizes = 0;
+    }
+    if ( trackKeys ) {
+        g_free(trackKeys);
+        trackKeys = 0;
+    }
+
+    trackCount = count;
+    trackSizes = g_new(guint, count);
+    trackKeys = g_new(GtkIconSize, count);
+    for ( i = 0; i < count; ++i ) {
+        guint val = smallest + ( (i * delta) / (count-1) );
+        trackKeys[i] = sizes[i];
+        trackSizes[i] = val;
+    }
+}
+
 GtkWidget* eek_preview_area_new(void)
 {
     return NULL;
@@ -100,10 +148,25 @@ static void eek_preview_size_request( GtkWidget* widget, GtkRequisition* req )
     gint width = 0;
     gint height = 0;
     EekPreview* preview = EEK_PREVIEW(widget);
-    gboolean worked = gtk_icon_size_lookup( preview->_size, &width, &height );
-    if ( !worked ) {
-        width = 16;
-        height = 16;
+    gboolean tracked = TRUE;
+    guint i = 0;
+
+    for ( i = 0; i < trackCount; ++i ) {
+        tracked = (trackKeys[i] == preview->_size);
+        if ( tracked ) {
+            width = trackSizes[i];
+            height = width;
+            break;
+        }
+    }
+
+    if ( !tracked ) {
+        gboolean worked = gtk_icon_size_lookup( preview->_size, &width, &height );
+        if ( !worked ) {
+            width = 16;
+            height = 16;
+            g_warning("Size not found [%d]", preview->_size);
+        }
     }
     if ( preview->_view == VIEW_TYPE_LIST ) {
         width *= 3;
index 114be8742a65171b1634a9920b1014c06a5f38ab..ff2fb78f30aa81a4b78cec45b7aeb356d4f22792 100644 (file)
@@ -117,6 +117,8 @@ LinkType eek_preview_get_linked( EekPreview* splat );
 gboolean eek_preview_get_focus_on_click( EekPreview* preview );
 void eek_preview_set_focus_on_click( EekPreview* preview, gboolean focus_on_click );
 
+void eek_preview_set_size_mappings( guint count, GtkIconSize const* sizes );
+
 G_END_DECLS
 
 
index 52178e53a7f356f256ab4d1cfe1f3a23651dc5ef..709bce25a06f92193b9b4932ce44f27f9448cbd8 100644 (file)
@@ -511,10 +511,10 @@ Gtk::Widget* ColorItem::getPreview(PreviewStyle style, ViewType view, Inkscape::
         lbl->set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
         widget = lbl;
     } else {
-        Glib::ustring blank("          ");
-        if ( size == Inkscape::ICON_SIZE_MENU || size == Inkscape::ICON_SIZE_DECORATION ) {
-            blank = " ";
-        }
+//         Glib::ustring blank("          ");
+//         if ( size == Inkscape::ICON_SIZE_MENU || size == Inkscape::ICON_SIZE_DECORATION ) {
+//             blank = " ";
+//         }
 
         GtkWidget* eekWidget = eek_preview_new();
         EekPreview * preview = EEK_PREVIEW(eekWidget);
index 16bf883d0816fe7055550b77d59b91ee86aa05ca..107d246b4f7c496b77a5cd7da4b0a0dbe99f8c9c 100644 (file)
@@ -23,6 +23,8 @@
 
 #include "gtk/gtkiconfactory.h"
 
+#include "widgets/icon.h"
+#include "ui/widget/panel.h"
 
 void
 inkscape_gtk_stock_init() {
@@ -31,6 +33,12 @@ inkscape_gtk_stock_init() {
     if (stock_initialized)
         return;
 
+    // Ensure icon internal sizes get set up:
+    sp_icon_get_phys_size(GTK_ICON_SIZE_MENU);
+
+    // And also prepare the swatches.
+    Inkscape::UI::Widget::Panel::prep();
+
     GtkIconFactory *icon_factory = gtk_icon_factory_new();
     /* todo: Should we simply remove this file now that we're no longer
      * calling gtk_icon_factory_add here? */
index a591e76640acd8ec51b69f63d4c79327079483c9..9b9b20530249db5940a12209a7d88014ce889457 100644 (file)
@@ -27,6 +27,7 @@
 #include "prefs-utils.h"
 #include "desktop-handles.h"
 #include "inkscape.h"
+#include "dialogs/eek-preview.h"
 
 namespace Inkscape {
 namespace UI {
@@ -37,6 +38,19 @@ static const int PANEL_SETTING_MODE = 1;
 static const int PANEL_SETTING_WRAP = 2;
 static const int PANEL_SETTING_NEXTFREE = 3;
 
+
+void Panel::prep() {
+    GtkIconSize sizes[] = {
+        static_cast<GtkIconSize>(Inkscape::ICON_SIZE_DECORATION),
+        GTK_ICON_SIZE_MENU,
+        GTK_ICON_SIZE_SMALL_TOOLBAR,
+        GTK_ICON_SIZE_BUTTON,
+        GTK_ICON_SIZE_DND, // Not used by options, but included to make the last size larger
+        GTK_ICON_SIZE_DIALOG
+    };
+    eek_preview_set_size_mappings( G_N_ELEMENTS(sizes), sizes );
+}
+
 /**
  *    Construct a Panel
  */
index 40760a4a2658e431d16b855cdc128690d6b1649a..1062ee58eecd7c4711de9149aa05c2c113d71015 100644 (file)
@@ -38,8 +38,10 @@ namespace Widget {
 class Panel : public Gtk::VBox {
 
 public:
+    static void prep();
+
     virtual ~Panel();
-    Panel(Glib::ustring const &label = "", gchar const *prefs_path = 0, 
+    Panel(Glib::ustring const &label = "", gchar const *prefs_path = 0,
           int verb_num = 0, Glib::ustring const &apply_label = "",
           bool menu_desired = false);
 
@@ -57,7 +59,7 @@ public:
 
     virtual void setDesktop(SPDesktop *desktop);
     SPDesktop *getDesktop() { return _desktop; }
-    
+
     /** Signal accessors */
     virtual sigc::signal<void, int> &signalResponse();
     virtual sigc::signal<void> &signalPresent();
index 03a39acb62a9d58681355b55fb9fefa30e539e24..8c582da83ca4ef1e4befdcf8547d60ab4accb7db 100644 (file)
@@ -59,8 +59,6 @@ static guchar *sp_icon_image_load_svg(gchar const *name, unsigned lsize, unsigne
 
 static guchar *sp_icon_image_load(SPIcon *icon, gchar const *name);
 
-static int sp_icon_get_phys_size(int size);
-
 static void sp_icon_overlay_pixels( guchar *px, int width, int height, int stride,
                                     unsigned r, unsigned g, unsigned b );
 
@@ -397,7 +395,7 @@ static void injectCustomSize()
 
 }
 
-static int sp_icon_get_phys_size(int size)
+int sp_icon_get_phys_size(int size)
 {
     static bool init = false;
     static int lastSys[Inkscape::ICON_SIZE_DECORATION + 1];
@@ -542,7 +540,7 @@ static void sp_icon_paint(SPIcon *icon, GdkRectangle const *area)
 }
 
 static guchar *
-sp_icon_image_load_pixmap(gchar const *name, unsigned lsize, unsigned psize)
+sp_icon_image_load_pixmap(gchar const *name, unsigned /*lsize*/, unsigned psize)
 {
     gchar *path;
     guchar *px;
@@ -762,7 +760,7 @@ static guchar *get_cached_pixels(Glib::ustring const &key) {
 }
 
 static guchar *load_svg_pixels(gchar const *name,
-                               unsigned lsize, unsigned psize)
+                               unsigned /*lsize*/, unsigned psize)
 {
     SPDocument *doc = NULL;
     NRArenaItem *root = NULL;
@@ -949,7 +947,7 @@ static void addPreRender( Inkscape::IconSize lsize, gchar const *name )
     pendingRenders.push(preRenderItem(lsize, name));
 }
 
-gboolean icon_prerender_task(gpointer data) {
+gboolean icon_prerender_task(gpointer /*data*/) {
     if (!pendingRenders.empty()) {
         preRenderItem single=pendingRenders.front();
         pendingRenders.pop();
index 55112c0aeeadb7338b0d8d69c541441b69823d38..45ab822235eadf6ddac970a58c4bad9aac8389fc 100644 (file)
@@ -48,5 +48,7 @@ GtkWidget *sp_icon_new( Inkscape::IconSize size, const gchar *name );
 Gtk::Widget *sp_icon_get_icon( const Glib::ustring &oid, Inkscape::IconSize size = Inkscape::ICON_SIZE_BUTTON );
 
 void sp_icon_fetch_pixbuf( SPIcon *icon );
+int sp_icon_get_phys_size(int size);
+
 
 #endif // SEEN_SP_ICON_H