[gnome-maps] Add Utils.CreateActorFromImageFile



commit 0f76e2b8900e487c50d35e89c21721966458d707
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Fri Apr 12 03:33:23 2013 +0300

    Add Utils.CreateActorFromImageFile
    
    A utility function to do what Clutter.Texture used to do in the good old
    days.

 src/userLocation.js |   31 ++++++++-----------------------
 src/utils.js        |   24 ++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 23 deletions(-)
---
diff --git a/src/userLocation.js b/src/userLocation.js
index 486be5a..fc89cb1 100644
--- a/src/userLocation.js
+++ b/src/userLocation.js
@@ -19,8 +19,6 @@
  */
 
 const Clutter = imports.gi.Clutter;
-const Cogl = imports.gi.Cogl;
-const GdkPixbuf = imports.gi.GdkPixbuf;
 const Champlain = imports.gi.Champlain;
 const Geocode = imports.gi.GeocodeGlib;
 
@@ -45,28 +43,15 @@ const UserLocation = new Lang.Class({
         layer.remove_all();
 
         let locationMarker = new Champlain.CustomMarker();
-        try {
-            let pixbuf = GdkPixbuf.Pixbuf.new_from_file(Path.ICONS_DIR + "/pin.svg");
-            let image = new Clutter.Image();
-            image.set_data(pixbuf.get_pixels(),
-                           Cogl.PixelFormat.RGBA_8888,
-                           pixbuf.get_width(),
-                           pixbuf.get_height(),
-                           pixbuf.get_rowstride());
-
-            locationMarker.set_location(this.latitude, this.longitude);
-            locationMarker.set_reactive(false);
-            // FIXME: Using deprecated function here cause I failed to get the same result
-            //        with locationMarker.set_pivot_point(0.5, 0).
-            locationMarker.set_anchor_point_from_gravity(Clutter.Gravity.SOUTH);
-            let actor = new Clutter.Actor();
-            actor.set_content(image);
-            actor.set_size(pixbuf.get_width(), pixbuf.get_height());
-            locationMarker.add_actor(actor);
-        } catch(e) {
-            log("Failed to load image: " + e.message);
+        locationMarker.set_reactive(false);
+        locationMarker.set_location(this.latitude, this.longitude);
+        // FIXME: Using deprecated function here cause I failed to get the same result
+        //        with locationMarker.set_pivot_point(0.5, 0).
+        locationMarker.set_anchor_point_from_gravity(Clutter.Gravity.SOUTH);
+        let actor = Utils.CreateActorFromImageFile(Path.ICONS_DIR + "/pin.svg");
+        if (actor == null)
             return;
-        }
+        locationMarker.add_actor(actor);
 
         if (this.accuracy == 0) {
             layer.add_marker(locationMarker);
diff --git a/src/utils.js b/src/utils.js
index 7173229..76cdd6b 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -26,6 +26,9 @@ const Gio = imports.gi.Gio;
 const Gtk = imports.gi.Gtk;
 const Signals = imports.signals;
 const Geocode = imports.gi.GeocodeGlib;
+const GdkPixbuf = imports.gi.GdkPixbuf;
+const Clutter = imports.gi.Clutter;
+const Cogl = imports.gi.Cogl;
 
 let debugInit = false;
 let debugEnabled = false;
@@ -95,3 +98,24 @@ function getZoomLevelForAccuracy(accuracy) {
     else
         return 3;
 }
+
+function CreateActorFromImageFile(path) {
+    try {
+        let pixbuf = GdkPixbuf.Pixbuf.new_from_file(path);
+        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;
+    }
+}


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