[tbo] Added other images inclusion and library support
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tbo] Added other images inclusion and library support
- Date: Thu, 23 Jun 2011 11:54:29 +0000 (UTC)
commit ae7a6a9f49bc51a8eaccd409a95eb0307fff2ddb
Author: danigm <danigm wadobo com>
Date: Thu Jun 23 13:49:29 2011 +0200
Added other images inclusion and library support
Now it's not needed to have only svg files in libraries, now you can
use png, jpg, gif, etc.
src/dnd.c | 11 +++++++++--
src/tbo-files.c | 28 ++++++++++++++++++++++++++++
src/tbo-files.h | 3 +++
src/tbo-object-pixmap.c | 19 +++++++++++++++----
src/tbo-toolbar.c | 5 ++---
5 files changed, 57 insertions(+), 9 deletions(-)
---
diff --git a/src/dnd.c b/src/dnd.c
index 1864995..3e21702 100644
--- a/src/dnd.c
+++ b/src/dnd.c
@@ -23,6 +23,7 @@
#include "tbo-drawing.h"
#include "frame.h"
#include "tbo-object-svg.h"
+#include "tbo-object-pixmap.h"
#include "tbo-window.h"
static GtkWidget *DND_IMAGE = NULL;
@@ -60,15 +61,21 @@ drag_data_received_handl (GtkWidget *widget,
case TARGET_STRING:
_sdata = gtk_selection_data_get_data (selection_data);
+ TboObjectBase *image;
Frame *frame = tbo_drawing_get_current_frame (TBO_DRAWING (tbo->drawing));
adj = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (tbo->dw_scroll));
int rx = tbo_frame_get_base_x ((x + gtk_adjustment_get_value(adj)) / zoom);
adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (tbo->dw_scroll));
int ry = tbo_frame_get_base_y ((y + gtk_adjustment_get_value(adj)) / zoom);
- TboObjectSvg *svgimage = TBO_OBJECT_SVG (tbo_object_svg_new_with_params (rx, ry, 0, 0, (gchar*)_sdata));
+ if (tbo_files_is_svg_file ((gchar *)_sdata)) {
+ image = TBO_OBJECT_BASE (tbo_object_svg_new_with_params (rx, ry, 0, 0, (gchar*)_sdata));
+ } else {
+ image = TBO_OBJECT_BASE (tbo_object_pixmap_new_with_params (rx, ry, 0, 0, (gchar*)_sdata));
+ }
+
tbo_drawing_update (TBO_DRAWING (tbo->drawing));
- tbo_frame_add_obj (frame, TBO_OBJECT_BASE (svgimage));
+ tbo_frame_add_obj (frame, TBO_OBJECT_BASE (image));
dnd_success = TRUE;
break;
diff --git a/src/tbo-files.c b/src/tbo-files.c
index 32b3c2e..06b414e 100644
--- a/src/tbo-files.c
+++ b/src/tbo-files.c
@@ -82,9 +82,37 @@ tbo_files_expand_path (char *source, char *dest)
st = stat (dest, &filestat);
if (!st)
break;
+ else
+ snprintf (dest, 255, "%s", source);
i++;
}
tbo_files_free (possible_dirs);
}
+
+gboolean
+tbo_files_is_svg_file (char *source)
+{
+ gchar **paths;
+ gchar **ext;
+ gchar *lower_ext;
+ gboolean is_svg = FALSE;
+
+ paths = g_strsplit (source, ".", 0);
+
+ ext = paths;
+ while (*ext) ext++;
+ ext--;
+
+ lower_ext = g_ascii_strdown (*ext, -1);
+
+ if (strcmp (lower_ext, "svg") == 0) {
+ is_svg = TRUE;
+ }
+
+ g_strfreev (paths);
+ g_free (lower_ext);
+
+ return is_svg;
+}
diff --git a/src/tbo-files.h b/src/tbo-files.h
index 7870816..4fdb95f 100644
--- a/src/tbo-files.h
+++ b/src/tbo-files.h
@@ -20,9 +20,12 @@
#ifndef __TBO_FILES__
#define __TBO_FILES__
+#include <glib.h>
+
char **tbo_files_get_dirs ();
int tbo_files_prefix_len (char *str);
void tbo_files_free (char **files);
void tbo_files_expand_path (char *source, char *dest);
+gboolean tbo_files_is_svg_file (char *source);
#endif
diff --git a/src/tbo-object-pixmap.c b/src/tbo-object-pixmap.c
index 8735d53..346905b 100644
--- a/src/tbo-object-pixmap.c
+++ b/src/tbo-object-pixmap.c
@@ -20,6 +20,7 @@
#include <glib.h>
#include <string.h>
#include <cairo.h>
+#include <gdk/gdk.h>
#include <stdio.h>
#include "tbo-types.h"
#include "tbo-object-pixmap.h"
@@ -36,10 +37,20 @@ draw (TboObjectBase *self, Frame *frame, cairo_t *cr)
TboObjectPixmap *pixmap = TBO_OBJECT_PIXMAP (self);
int w, h;
cairo_surface_t *image;
+ GdkPixbuf *pixbuf;
+ GError *error = NULL;
+ char path[255];
- image = cairo_image_surface_create_from_png (pixmap->path->str);
- w = cairo_image_surface_get_width (image);
- h = cairo_image_surface_get_height (image);
+ tbo_files_expand_path (pixmap->path->str, path);
+ pixbuf = gdk_pixbuf_new_from_file (path, &error);
+
+ if (!pixbuf) {
+ g_warning ("There's a problem here: %s", error->message);
+ return;
+ }
+
+ w = gdk_pixbuf_get_width (pixbuf);
+ h = gdk_pixbuf_get_height (pixbuf);
if (!self->width) self->width = w;
if (!self->height) self->height = h;
@@ -57,7 +68,7 @@ draw (TboObjectBase *self, Frame *frame, cairo_t *cr)
cairo_transform (cr, &mx);
cairo_scale (cr, factorw, factorh);
- cairo_set_source_surface (cr, image, 0, 0);
+ gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
cairo_paint (cr);
cairo_scale (cr, 1/factorw, 1/factorh);
diff --git a/src/tbo-toolbar.c b/src/tbo-toolbar.c
index 71f44f0..8f63973 100644
--- a/src/tbo-toolbar.c
+++ b/src/tbo-toolbar.c
@@ -134,9 +134,8 @@ add_pix (GtkAction *action, TboWindow *tbo)
NULL);
filter = gtk_file_filter_new ();
- gtk_file_filter_set_name (filter, _("png"));
- gtk_file_filter_add_pattern (filter, "*.png");
- gtk_file_filter_add_pattern (filter, "*.PNG");
+ gtk_file_filter_set_name (filter, _("Image files"));
+ gtk_file_filter_add_pixbuf_formats (filter);
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, _("All files"));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]