[telegnome] Port from GdkDrawable to Cairo
- From: Colin Watson <cjwatson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [telegnome] Port from GdkDrawable to Cairo
- Date: Tue, 2 Feb 2016 12:55:56 +0000 (UTC)
commit 6bb4fe467e24cb38350e9a92fd78918173df4938
Author: Colin Watson <cjwatson debian org>
Date: Tue Feb 2 12:53:24 2016 +0000
Port from GdkDrawable to Cairo
* src/pixpack.c (tg_pixpack_init): Remove priv->scaled_pixbuf.
(tg_pixpack_destroy): Likewise.
(tg_pixpack_paint): Likewise. Use Cairo functions for clipping,
scaling, and painting.
* configure.ac (PKG_CHECK_MODULES): Add cairo.
NEWS | 1 +
configure.ac | 2 +-
src/pixpack.c | 32 +++++++++++++++-----------------
3 files changed, 17 insertions(+), 18 deletions(-)
---
diff --git a/NEWS b/NEWS
index e8dc70c..747a8b3 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ Changes in TeleGNOME 0.2.1
* Port from gtk_timeout_* to GLib equivalents.
* Port from GtkCList to GtkTreeView and friends.
* Port to new (as of GTK+ 2.4) GtkToolbar API.
+ * Port from GdkDrawable to Cairo.
Changes in TeleGNOME 0.2.0
==========================
diff --git a/configure.ac b/configure.ac
index 8299330..3f8ce1c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,7 +23,7 @@ AC_PROG_INSTALL
AC_DEFINE_UNQUOTED([SYSCONFDIR], "$sysconfdir", [System configuration directory.])
AM_PATH_GLIB_2_0([2.44.0], [], [AC_MSG_ERROR([GLib >= 2.44.0 is required])], [gobject gio])
-PKG_CHECK_MODULES([TELEGNOME], [gtk+-2.0 >= 2.20 gdk-pixbuf-2.0 >= 2.26 dconf uuid])
+PKG_CHECK_MODULES([TELEGNOME], [gtk+-2.0 >= 2.20 gdk-pixbuf-2.0 >= 2.26 cairo dconf uuid])
AC_ARG_VAR([XMLLINT], [the xmllint program])
AC_PATH_PROG([XMLLINT], [xmllint])
diff --git a/src/pixpack.c b/src/pixpack.c
index f328e40..9e3a9fb 100644
--- a/src/pixpack.c
+++ b/src/pixpack.c
@@ -20,11 +20,13 @@
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
*/
+
+#include <cairo.h>
+
#include "pixpack.h"
struct _TgPixPackPrivate {
GdkPixbuf *pixbuf;
- GdkPixbuf *scaled_pixbuf;
gboolean is_resize;
gboolean autosize;
@@ -96,7 +98,6 @@ tg_pixpack_init(TgPixPack *pixpack)
priv = g_new0(TgPixPackPrivate, 1);
priv->pixbuf = NULL;
- priv->scaled_pixbuf = NULL;
priv->is_resize = FALSE;
priv->autosize = FALSE;
pixpack->private_data = priv;
@@ -129,8 +130,6 @@ tg_pixpack_destroy(GtkObject *object)
if (private) {
if (private->pixbuf)
g_clear_object(&private->pixbuf);
- if (private->scaled_pixbuf)
- g_clear_object(&private->scaled_pixbuf);
g_clear_pointer(&pixpack->private_data, g_free);
}
@@ -206,6 +205,7 @@ tg_pixpack_paint(TgPixPack* pixpack, GdkRectangle *area)
GtkWidget *widget;
TgPixPackPrivate *private;
GdkWindow *window;
+ cairo_t *cr;
g_return_if_fail(pixpack != NULL);
g_return_if_fail(TG_IS_PIXPACK(pixpack));
@@ -214,8 +214,8 @@ tg_pixpack_paint(TgPixPack* pixpack, GdkRectangle *area)
private = pixpack->private_data;
if (!private->is_resize) {
- area->height = gdk_pixbuf_get_height(private->scaled_pixbuf);
- area->width = gdk_pixbuf_get_width(private->scaled_pixbuf);
+ area->height = gdk_pixbuf_get_height(private->pixbuf);
+ area->width = gdk_pixbuf_get_width(private->pixbuf);
area->x = 0;
area->y = 0;
}
@@ -226,21 +226,19 @@ tg_pixpack_paint(TgPixPack* pixpack, GdkRectangle *area)
window = gtk_widget_get_window(widget);
gdk_window_clear_area(window, area->x, area->y, area->width, area->height);
- gdk_gc_set_clip_rectangle(gtk_widget_get_style(widget)->black_gc, area);
if (NULL == private->pixbuf)
return;
- if (private->scaled_pixbuf)
- g_object_unref(private->scaled_pixbuf);
-
- private->scaled_pixbuf = gdk_pixbuf_scale_simple(private->pixbuf,
- area->width, area->height,
- GDK_INTERP_BILINEAR);
- gdk_pixbuf_render_to_drawable(private->scaled_pixbuf, window,
- gtk_widget_get_style(widget)->black_gc, 0, 0,
- area->x, area->y, area->width, area->height,
- GDK_RGB_DITHER_MAX, 1, 1);
+ cr = gdk_cairo_create(GDK_DRAWABLE(window));
+ gdk_cairo_set_source_pixbuf(cr, private->pixbuf, 0, 0);
+ cairo_rectangle(cr, area->x, area->y, area->width, area->height);
+ cairo_clip(cr);
+ cairo_scale(cr,
+ area->width / gdk_pixbuf_get_width(private->pixbuf),
+ area->height / gdk_pixbuf_get_height(private->pixbuf));
+ cairo_paint(cr);
+ cairo_destroy(cr);
private->is_resize = FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]