[gnome-maps/wip/osrm-routing: 3/21] MapLocation: Use bubble.svg for the search result marker



commit 806e08744b5bcd80688c9469035c32b1ad1d9fc3
Author: Jussi Kukkonen <jku goto fi>
Date:   Thu Apr 18 22:06:53 2013 +0300

    MapLocation: Use bubble.svg for the search result marker
    
    Also change the utility function to return an image instead
    of widget: this is more useful for the MapLocation case.

 src/mapLocation.js  |   32 ++++++++++++++++++++++++++++----
 src/userLocation.js |   17 +++++++++++------
 src/utils.js        |    9 ++-------
 3 files changed, 41 insertions(+), 17 deletions(-)
---
diff --git a/src/mapLocation.js b/src/mapLocation.js
index 48677f5..151094c 100644
--- a/src/mapLocation.js
+++ b/src/mapLocation.js
@@ -84,10 +84,34 @@ const MapLocation = new Lang.Class({
     },
 
     show: function(layer) {
-        let marker = new Champlain.Label();
-        marker.set_text(this.description);
-        marker.set_location(this.latitude, this.longitude);
-        layer.add_marker(marker);
+        let image = Utils.loadImageFromFile(Path.ICONS_DIR + "/bubble.svg");
+        let bubble = new Champlain.CustomMarker({ content: image });
+
+        bubble.set_location(this.latitude, this.longitude);
+        bubble.connect('notify::width', Lang.bind(this,
+            function() {
+                bubble.set_translation(-(Math.floor(bubble.get_width() / 2)),
+                                       -bubble.get_height(),
+                                       0);
+            }));
+
+        let layout = new Clutter.BoxLayout({ orientation: Clutter.Orientation.VERTICAL,
+                                             spacing: 6 });
+        let box = new Clutter.Actor({ layout_manager: layout,
+                                      margin_top: 6,
+                                      margin_bottom: 18,
+                                      margin_left: 12,
+                                      margin_right: 12  });
+        bubble.add_child(box);
+
+        let text = new Clutter.Text({ text: this.description });
+        text.set_color(new Clutter.Color({ red: 255,
+                                           blue: 255,
+                                           green: 255,
+                                           alpha: 255 }));
+        box.add_child(text);
+
+        layer.add_marker (bubble);
         log("Added marker at " + this.latitude + ", " + this.longitude);
     },
 
diff --git a/src/userLocation.js b/src/userLocation.js
index fd9419a..50c038d 100644
--- a/src/userLocation.js
+++ b/src/userLocation.js
@@ -48,14 +48,19 @@ const UserLocation = new Lang.Class({
                                                      -this._locationMarker.get_height(),
                                                      0);
             }));
-        let pin_actor = Utils.CreateActorFromImageFile(Path.ICONS_DIR + "/pin.svg");
-        if (pin_actor == null)
-            return;
-        let bubbleActor = Utils.CreateActorFromImageFile(Path.ICONS_DIR + "/bubble.svg");
-        if (bubbleActor == null)
-            return;
+
+        let image = Utils.loadImageFromFile(Path.ICONS_DIR + "/pin.svg");
+        let pin_actor = new Clutter.Actor({ content: image });
+        [has_size, w, h] = image.get_preferred_size(image);
+        pin_actor.set_size (w, h);
+
+        image = Utils.loadImageFromFile(Path.ICONS_DIR + "/bubble.svg");
+        let bubbleActor = new Clutter.Actor({ content: image });
+        [has_size, w, h] = image.get_preferred_size(image);
+        bubbleActor.set_size (w, h);
         bubbleActor.set_x_expand(true);
         bubbleActor.set_y_expand(true);
+
         let text = _("%s\nPosition Accuracy: %s").format (this.description,
                                                           Utils.getDescriptionForAccuracy(this.accuracy));
         let textActor = new Clutter.Text({ text: text });
diff --git a/src/utils.js b/src/utils.js
index 09df902..9c01412 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -117,7 +117,7 @@ function getDescriptionForAccuracy(accuracy) {
     }
 }
 
-function CreateActorFromImageFile(path) {
+function loadImageFromFile(path) {
     try {
         let pixbuf = GdkPixbuf.Pixbuf.new_from_file(path);
         let image = new Clutter.Image();
@@ -126,12 +126,7 @@ function CreateActorFromImageFile(path) {
                        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;
+        return image;
     } 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]