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



commit fb385e7b26e370757e51a80beb017d86cba11cd3
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 c1b16a0..3bfb716 100644
--- a/src/userLocation.js
+++ b/src/userLocation.js
@@ -49,14 +49,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 ccd0a29..75ce6b7 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]