From a45f0039c6c9d32eea06bd20b62822fa7bfca7c7 Mon Sep 17 00:00:00 2001 From: joncruz Date: Mon, 16 Feb 2009 23:56:03 +0000 Subject: [PATCH] Move app-specific logic and file operations up from the lower level. --- src/dialogs/eek-preview.cpp | 31 ++++++++++++++----------------- src/dialogs/eek-preview.h | 4 +++- src/dialogs/swatches.cpp | 20 +++++++++++++++++++- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/dialogs/eek-preview.cpp b/src/dialogs/eek-preview.cpp index b562c2af5..e0d0fb4e2 100644 --- a/src/dialogs/eek-preview.cpp +++ b/src/dialogs/eek-preview.cpp @@ -42,7 +42,6 @@ #include #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; diff --git a/src/dialogs/eek-preview.h b/src/dialogs/eek-preview.h index e01472f1e..e4d935ae9 100644 --- a/src/dialogs/eek-preview.h +++ b/src/dialogs/eek-preview.h @@ -40,6 +40,7 @@ #ifndef SEEN_EEK_PREVIEW_H #define SEEN_EEK_PREVIEW_H +#include #include 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 ); diff --git a/src/dialogs/swatches.cpp b/src/dialogs/swatches.cpp index 7ab5c099b..4546efe13 100644 --- a/src/dialogs/swatches.cpp +++ b/src/dialogs/swatches.cpp @@ -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) -- 2.30.2