[gnome-control-center] datetime: Move pixbuf loading out of the draw signal handler
- From: Kalev Lember <klember src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] datetime: Move pixbuf loading out of the draw signal handler
- Date: Mon, 19 Aug 2013 16:43:12 +0000 (UTC)
commit fd4df35093ff9ff4b728d406d7004845d4245fb4
Author: Kalev Lember <kalevlember gmail com>
Date: Sun Aug 18 15:00:00 2013 +0200
datetime: Move pixbuf loading out of the draw signal handler
This moves the timezone location marker image loading code to init()
where most of other resources are loaded, making the draw callback
smaller and easier to read. As a plus, it also avoids needless
allocations during each time the map is drawn.
https://bugzilla.gnome.org/show_bug.cgi?id=706253
panels/datetime/cc-timezone-map.c | 33 ++++++++++++++++-----------------
1 files changed, 16 insertions(+), 17 deletions(-)
---
diff --git a/panels/datetime/cc-timezone-map.c b/panels/datetime/cc-timezone-map.c
index 153200c..424f07e 100644
--- a/panels/datetime/cc-timezone-map.c
+++ b/panels/datetime/cc-timezone-map.c
@@ -54,6 +54,7 @@ struct _CcTimezoneMapPrivate
GdkPixbuf *background;
GdkPixbuf *color_map;
+ GdkPixbuf *pin;
guchar *visible_map_pixels;
gint visible_map_rowstride;
@@ -152,6 +153,7 @@ cc_timezone_map_dispose (GObject *object)
g_clear_object (&priv->orig_background_dim);
g_clear_object (&priv->orig_color_map);
g_clear_object (&priv->background);
+ g_clear_object (&priv->pin);
if (priv->color_map)
{
@@ -317,7 +319,7 @@ cc_timezone_map_draw (GtkWidget *widget,
cairo_t *cr)
{
CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (widget)->priv;
- GdkPixbuf *hilight, *orig_hilight, *pin;
+ GdkPixbuf *hilight, *orig_hilight;
GtkAllocation alloc;
gchar *file;
GError *err = NULL;
@@ -363,15 +365,6 @@ cc_timezone_map_draw (GtkWidget *widget,
g_object_unref (orig_hilight);
}
- /* load pin icon */
- pin = gdk_pixbuf_new_from_resource (DATETIME_RESOURCE_PATH "/pin.png", &err);
-
- if (err)
- {
- g_warning ("Could not load pin icon: %s", err->message);
- g_clear_error (&err);
- }
-
if (priv->location)
{
pointx = convert_longtitude_to_x (priv->location->longitude, alloc.width);
@@ -380,18 +373,15 @@ cc_timezone_map_draw (GtkWidget *widget,
pointx = CLAMP (floor (pointx), 0, alloc.width);
pointy = CLAMP (floor (pointy), 0, alloc.height);
- if (pin)
+ if (priv->pin)
{
- gdk_cairo_set_source_pixbuf (cr, pin, pointx - PIN_HOT_POINT_X, pointy - PIN_HOT_POINT_Y);
+ gdk_cairo_set_source_pixbuf (cr, priv->pin,
+ pointx - PIN_HOT_POINT_X,
+ pointy - PIN_HOT_POINT_Y);
cairo_paint (cr);
}
}
- if (pin)
- {
- g_object_unref (pin);
- }
-
return TRUE;
}
@@ -603,6 +593,15 @@ cc_timezone_map_init (CcTimezoneMap *self)
g_clear_error (&err);
}
+ priv->pin = gdk_pixbuf_new_from_resource (DATETIME_RESOURCE_PATH "/pin.png",
+ &err);
+ if (!priv->pin)
+ {
+ g_warning ("Could not load pin icon: %s",
+ (err) ? err->message : "Unknown error");
+ g_clear_error (&err);
+ }
+
priv->tzdb = tz_load_db ();
g_signal_connect (self, "button-press-event", G_CALLBACK (button_press_event),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]