[gnome-maps] Implement ChamplainExportable interface for markers



commit 625b5458993a74a9b32b52a8166250697d9b42b2
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Sat Jan 9 10:40:51 2016 +0100

    Implement ChamplainExportable interface for markers
    
    This cycle we added a way to export the ChamplainView
    to a cairo surface. This is meant as way of creating PNG
    images of our map. As well as a way to facilitate printing
    of the map view.
    
    The cairo_view_to_surface function will go through each
    ChamplainLayer added to the view and check if it implements
    ChamplainExportable, and add it to the final surface if
    it does. The ChamplainMarkerLayer will only export surface
    if the markers within implements ChamplainExportable.
    Let's make it so.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=760352

 src/mapMarker.js          |   58 +++++++++++++++++++++++++++++++++++++++++++++
 src/placeMarker.js        |    3 +-
 src/turnPointMarker.js    |    2 +-
 src/userLocationMarker.js |    5 +--
 src/utils.js              |   31 ------------------------
 5 files changed, 62 insertions(+), 37 deletions(-)
---
diff --git a/src/mapMarker.js b/src/mapMarker.js
index 520cda7..81fe37e 100644
--- a/src/mapMarker.js
+++ b/src/mapMarker.js
@@ -19,7 +19,9 @@
  * Author: Damián Nohales <damiannohales gmail com>
  */
 
+const Cairo = imports.cairo;
 const Champlain = imports.gi.Champlain;
+const Clutter = imports.gi.Clutter;
 const Gdk = imports.gi.Gdk;
 const GObject = imports.gi.GObject;
 const Gtk = imports.gi.Gtk;
@@ -32,6 +34,7 @@ const Utils = imports.utils;
 const MapMarker = new Lang.Class({
     Name: 'MapMarker',
     Extends: Champlain.Marker,
+    Implements: [Champlain.Exportable],
     Abstract: true,
     Signals: {
         'gone-to': { }
@@ -67,6 +70,61 @@ const MapMarker = new Lang.Class({
                            GObject.BindingFlags.DEFAULT);
     },
 
+    get surface() {
+        return this._surface;
+    },
+
+    set surface(v) {
+        this._surface = v;
+    },
+
+    vfunc_get_surface: function() {
+        return this._surface;
+    },
+
+    vfunc_set_surface: function(surface) {
+        this._surface = surface;
+    },
+
+    _actorFromIconName: function(name, size, color) {
+        try {
+            let theme = Gtk.IconTheme.get_default();
+            let pixbuf;
+
+            if (color) {
+                let info = theme.lookup_icon(name, size, 0);
+                pixbuf = info.load_symbolic(color, null, null, null,
+                                            null, null)[0];
+            } else {
+                pixbuf = theme.load_icon(name, size, 0);
+            }
+
+            let canvas = new Clutter.Canvas({ width: pixbuf.get_width(),
+                                              height: pixbuf.get_height() });
+
+            canvas.connect('draw', (function(canvas, cr) {
+                cr.setOperator(Cairo.Operator.CLEAR);
+                cr.paint();
+                cr.setOperator(Cairo.Operator.OVER);
+
+                Gdk.cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
+                cr.paint();
+
+                this._surface = cr.getTarget();
+            }).bind(this));
+
+            let actor = new Clutter.Actor();
+            actor.set_content(canvas);
+            actor.set_size(pixbuf.get_width(), pixbuf.get_height());
+            canvas.invalidate();
+
+            return actor;
+        } catch (e) {
+            Utils.debug('Failed to load image: %s'.format(e.message));
+            return null;
+        }
+    },
+
     _onButtonPress: function(marker, event) {
         // Zoom in on marker on double-click
         if (event.get_click_count() > 1) {
diff --git a/src/placeMarker.js b/src/placeMarker.js
index c5033ef..3083b53 100644
--- a/src/placeMarker.js
+++ b/src/placeMarker.js
@@ -23,7 +23,6 @@ const Lang = imports.lang;
 
 const MapMarker = imports.mapMarker;
 const PlaceBubble = imports.placeBubble;
-const Utils = imports.utils;
 
 const PlaceMarker = new Lang.Class({
     Name: 'PlaceMarker',
@@ -32,7 +31,7 @@ const PlaceMarker = new Lang.Class({
     _init: function(params) {
         this.parent(params);
 
-        this.add_actor(Utils.CreateActorFromIconName('mark-location', 32));
+        this.add_actor(this._actorFromIconName('mark-location', 32));
     },
 
     get anchor() {
diff --git a/src/turnPointMarker.js b/src/turnPointMarker.js
index 077bb62..e4d7d86 100644
--- a/src/turnPointMarker.js
+++ b/src/turnPointMarker.js
@@ -55,7 +55,7 @@ const TurnPointMarker = new Lang.Class({
             this.connect('drag-finish', (function() {
                 this._onMarkerDrag();
             }).bind(this));
-            actor = Utils.CreateActorFromIconName(this._turnPoint.iconName, 0);
+            actor = this._actorFromIconName(this._turnPoint.iconName, 0);
         } else {
             // A GNOMEish blue color
             let color = new Gdk.RGBA({ red: 33   / 255,
diff --git a/src/userLocationMarker.js b/src/userLocationMarker.js
index 155599f..0db4906 100644
--- a/src/userLocationMarker.js
+++ b/src/userLocationMarker.js
@@ -25,7 +25,6 @@ const Lang = imports.lang;
 
 const MapMarker = imports.mapMarker;
 const UserLocationBubble = imports.userLocationBubble;
-const Utils = imports.utils;
 
 const AccuracyCircleMarker = new Lang.Class({
     Name: 'AccuracyCircleMarker',
@@ -71,12 +70,12 @@ const UserLocationMarker = new Lang.Class({
         this.parent(params);
 
         if (this.place.location.heading > -1) {
-            let actor = Utils.CreateActorFromIconName('user-location-compass', 0);
+            let actor = this._actorFromIconName('user-location-compass', 0);
             actor.set_pivot_point(0.5, 0.5);
             actor.set_rotation_angle(Clutter.RotateAxis.Z_AXIS, this.place.location.heading);
             this.add_actor(actor);
         } else {
-            this.add_actor(Utils.CreateActorFromIconName('user-location', 0));
+            this.add_actor(this._actorFromIconName('user-location', 0));
         }
 
         if (this.place.location.accuracy > 0) {
diff --git a/src/utils.js b/src/utils.js
index c67a594..9ace1e2 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -20,8 +20,6 @@
  *         Zeeshan Ali (Khattak) <zeeshanak gnome org>
  */
 
-const Clutter = imports.gi.Clutter;
-const Cogl = imports.gi.Cogl;
 const GLib = imports.gi.GLib;
 const Gdk = imports.gi.Gdk;
 const GdkPixbuf = imports.gi.GdkPixbuf;
@@ -164,35 +162,6 @@ function activateAction(appId, action, parameter, timestamp) {
                           });
 }
 
-function CreateActorFromIconName(name, size, color) {
-    try {
-        let theme = Gtk.IconTheme.get_default();
-        let pixbuf;
-
-        if (color) {
-            let info = theme.lookup_icon(name, size, 0);
-            pixbuf = info.load_symbolic(color, null, null, null, null, null)[0];
-        } else
-            pixbuf = theme.load_icon(name, size, 0);
-
-        let image = new Clutter.Image();
-        image.set_data(pixbuf.get_pixels(),
-                       Cogl.PixelFormat.RGBA_8888,
-                       pixbuf.get_width(),
-                       pixbuf.get_height(),
-                       pixbuf.get_rowstride());
-
-        let actor = new Clutter.Actor();
-        actor.set_content(image);
-        actor.set_size(pixbuf.get_width(), pixbuf.get_height());
-
-        return actor;
-    } catch(e) {
-        log("Failed to load image: " + e.message);
-        return null;
-    }
-}
-
 function dashedToCamelCase(name) {
     return name.replace(/(-.)/g, function(x) {
         return x[1].toUpperCase();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]