Code

Move app-specific logic and file operations up from the lower level.
authorjoncruz <joncruz@users.sourceforge.net>
Mon, 16 Feb 2009 23:56:03 +0000 (23:56 +0000)
committerjoncruz <joncruz@users.sourceforge.net>
Mon, 16 Feb 2009 23:56:03 +0000 (23:56 +0000)
src/dialogs/eek-preview.cpp
src/dialogs/eek-preview.h
src/dialogs/swatches.cpp

index b562c2af574bc21035cd02a165aa4660e229a864..e0d0fb4e2d98c145f44c51bd4c2d838bd0e9cb76 100644 (file)
@@ -42,7 +42,6 @@
 
 #include <gtk/gtk.h>
 #include "eek-preview.h"
-#include "path-prefix.h"
 
 #define PRIME_BUTTON_MAGIC_NUMBER 1
 
@@ -69,6 +68,14 @@ void eek_preview_set_color( EekPreview* preview, int r, int g, int b )
 }
 
 
+void eek_preview_set_pixbuf( EekPreview* preview, GdkPixbuf* pixbuf )
+{
+    preview->_previewPixbuf = pixbuf;
+
+    gtk_widget_queue_draw(GTK_WIDGET(preview));
+}
+
+
 GType eek_preview_get_type(void)
 {
     static GType preview_type = 0;
@@ -307,24 +314,13 @@ gboolean eek_preview_expose_event( GtkWidget* widget, GdkEventExpose* event )
             }
         }
 
-        if (preview->_isRemove){
+        if ( preview->_previewPixbuf ) {
             GtkDrawingArea* da = &(preview->drawing);
             GdkDrawable* drawable = (GdkDrawable*) (((GtkWidget*)da)->window);
-            gint w,h;
+            gint w = 0;
+            gint h = 0;
             gdk_drawable_get_size(drawable, &w, &h);
-            GError *error = NULL;
-            gchar *filepath = (gchar *) g_strdup_printf("%s/remove-color.png", INKSCAPE_PIXMAPDIR);
-            gsize bytesRead = 0;
-            gsize bytesWritten = 0;
-            gchar *localFilename = g_filename_from_utf8( filepath,
-                                                 -1,
-                                                 &bytesRead,
-                                                 &bytesWritten,
-                                                 &error);
-            GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file_at_scale(localFilename, w, h, FALSE, &error);
-            gdk_draw_pixbuf(drawable, 0, pixbuf, 0, 0, 0, 0, w, h, GDK_RGB_DITHER_NONE, 0, 0);
-            g_free(localFilename);
-            g_free(filepath);
+            gdk_draw_pixbuf( drawable, 0, preview->_previewPixbuf, 0, 0, 0, 0, w, h, GDK_RGB_DITHER_NONE, 0, 0 );
         }
 
 
@@ -655,13 +651,14 @@ static void eek_preview_init( EekPreview *preview )
     preview->_hot = FALSE;
     preview->_within = FALSE;
     preview->_takesFocus = FALSE;
-    preview->_isRemove = FALSE;
 
     preview->_prevstyle = PREVIEW_STYLE_ICON;
     preview->_view = VIEW_TYPE_LIST;
     preview->_size = PREVIEW_SIZE_SMALL;
     preview->_ratio = 100;
 
+    preview->_previewPixbuf = 0;
+
 /*
     GdkColor color = {0};
     color.red = (255 << 8) | 255;
index e01472f1e79e7106ae12239b607a8649cf305f3f..e4d935ae92395266a16e06c4d051eee6fb1af78b 100644 (file)
@@ -40,6 +40,7 @@
 #ifndef SEEN_EEK_PREVIEW_H
 #define SEEN_EEK_PREVIEW_H
 
+#include <gdk/gdkpixbuf.h>
 #include <gtk/gtkdrawingarea.h>
 
 G_BEGIN_DECLS
@@ -100,13 +101,13 @@ struct _EekPreview
     gboolean _hot;
     gboolean _within;
     gboolean _takesFocus;
-    gboolean _isRemove;
 
     PreviewStyle _prevstyle;
     ViewType _view;
     PreviewSize _size;
     guint _ratio;
     guint _linked;
+    GdkPixbuf* _previewPixbuf;
 };
 
 struct _EekPreviewClass
@@ -122,6 +123,7 @@ GtkWidget* eek_preview_new(void);
 
 void eek_preview_set_details( EekPreview* splat, PreviewStyle prevstyle, ViewType view, PreviewSize size, guint ratio );
 void eek_preview_set_color( EekPreview* splat, int r, int g, int b );
+void eek_preview_set_pixbuf( EekPreview* splat, GdkPixbuf* pixbuf );
 
 void eek_preview_set_linked( EekPreview* splat, LinkType link );
 LinkType eek_preview_get_linked( EekPreview* splat );
index 7ab5c099bd9874e95e3c8945f6ba8b194394d56c..4546efe132e9ef43298bb362646bc178e8611477 100644 (file)
@@ -577,7 +577,25 @@ Gtk::Widget* ColorItem::getPreview(PreviewStyle style, ViewType view, ::PreviewS
         Gtk::Widget* newBlot = Glib::wrap(eekWidget);
 
         eek_preview_set_color( preview, (def.getR() << 8) | def.getR(), (def.getG() << 8) | def.getG(), (def.getB() << 8) | def.getB());
-        preview->_isRemove = _isRemove;
+        if ( _isRemove ) {
+            GError *error = NULL;
+            gchar *filepath = (gchar *) g_strdup_printf("%s/remove-color.png", INKSCAPE_PIXMAPDIR);
+            gsize bytesRead = 0;
+            gsize bytesWritten = 0;
+            gchar *localFilename = g_filename_from_utf8( filepath,
+                                                 -1,
+                                                 &bytesRead,
+                                                 &bytesWritten,
+                                                 &error);
+            GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file(localFilename, &error);
+            if (!pixbuf) {
+                g_warning("Null pixbuf for %p [%s]", localFilename, localFilename );
+            }
+            g_free(localFilename);
+            g_free(filepath);
+
+            eek_preview_set_pixbuf( preview, pixbuf );
+        }
 
         eek_preview_set_details( preview, (::PreviewStyle)style, (::ViewType)view, (::PreviewSize)size, ratio );
         eek_preview_set_linked( preview, (LinkType)((_linkSrc ? PREVIEW_LINK_IN:0)