[gnome-maps/wip/zoom-control] MapView: add a zoom control



commit fb566e55392f7c27ba5c3981f6d49af16c6fcfd3
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Tue Jun 18 17:02:16 2013 +0200

    MapView: add a zoom control
    
    Add a zoom control widget based on two buttons. WIP, needs styling.

 data/gnome-maps.css          |   23 ++++++++++++++++++
 src/Makefile-js.am           |    3 +-
 src/control.js               |   48 ++++++++++++++++++++++++++++++++++++++
 src/control.ui               |   53 ++++++++++++++++++++++++++++++++++++++++++
 src/gnome-maps.gresource.xml |    1 +
 src/mapView.js               |    7 +++++
 6 files changed, 134 insertions(+), 1 deletions(-)
---
diff --git a/data/gnome-maps.css b/data/gnome-maps.css
index 961e54b..9b22bf7 100644
--- a/data/gnome-maps.css
+++ b/data/gnome-maps.css
@@ -5,3 +5,26 @@
 .maps-sidebar:dir(rtl) {
     border-width: 0 1px 0 0;
 }
+
+.zoom-control {
+    background-color: rgba (0,0,0,0);
+}
+
+.zoom-control GdHeaderSimpleButton {
+    background-color: #333333;
+       color: #eeeeee;
+    font: bold;
+}
+.zoom-control GdHeaderSimpleButton:hover {
+    color: #ffffff;
+}
+
+#zoom-in-button {
+    border-top-left-radius: 7px;
+    border-top-right-radius: 7px;
+}
+
+#zoom-out-button {
+    border-bottom-left-radius: 7px;
+    border-bottom-right-radius: 7px;
+}
\ No newline at end of file
diff --git a/src/Makefile-js.am b/src/Makefile-js.am
index 3caf4bc..fc50682 100644
--- a/src/Makefile-js.am
+++ b/src/Makefile-js.am
@@ -7,7 +7,8 @@ dist_js_DATA = \
     mapView.js \
     path.js \
     sidebar.js \
-    utils.js \
+       utils.js \
+       control.js \
     userLocation.js \
     geoclue.js
 
diff --git a/src/control.js b/src/control.js
new file mode 100644
index 0000000..94359ef
--- /dev/null
+++ b/src/control.js
@@ -0,0 +1,48 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2011, 2012, 2013 Red Hat, Inc.
+ *
+ * GNOME Maps is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * GNOME Maps is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with GNOME Maps; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
+ */
+
+const Clutter = imports.gi.Clutter;
+const Gtk = imports.gi.Gtk;
+const GtkClutter = imports.gi.GtkClutter;
+
+const Lang = imports.lang;
+
+const Utils = imports.utils;
+
+const Zoom = new Lang.Class({
+       Name: 'Zoom',
+       Extends: GtkClutter.Actor,
+       
+    _init: function(mapView, props) {
+        GtkClutter.Actor.prototype._init.call(this, props);
+               let ui = Utils.getUIObject('control', ['zoom-control',
+                                                                                          'zoom-in-button',
+                                                                                          'zoom-out-button'
+                                                                                         ]);
+               
+        ui.zoomInButton.connect('clicked', mapView.zoom_in.bind(mapView));
+        ui.zoomOutButton.connect('clicked', mapView.zoom_out.bind(mapView));
+
+        this.contents = ui.zoomControl;
+
+    }
+});
diff --git a/src/control.ui b/src/control.ui
new file mode 100644
index 0000000..76a3537
--- /dev/null
+++ b/src/control.ui
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.6 -->
+  <object class="GtkImage" id="zoom-in-image">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="stock">gtk-zoom-in</property>
+    <property name="icon_size">0</property>
+  </object>
+  <object class="GtkImage" id="zoom-out-image">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="stock">gtk-zoom-out</property>
+  </object>
+  <object class="GtkButtonBox" id="zoom-control">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="orientation">vertical</property>
+    <property name="spacing">2</property>
+    <property name="layout_style">start</property>
+       <style>
+         <class name="maps-zoom-control" />
+       </style>
+    <child>
+      <object class="GtkButton" id="zoom-in-button">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="receives_default">True</property>
+        <property name="image">zoom-in-image</property>
+        <property name="image_position">bottom</property>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">0</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkButton" id="zoom-out-button">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="receives_default">True</property>
+        <property name="image">zoom-out-image</property>
+        <property name="image_position">bottom</property>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">1</property>
+      </packing>
+    </child>
+  </object>
+</interface>
diff --git a/src/gnome-maps.gresource.xml b/src/gnome-maps.gresource.xml
index 5916d8f..5920a92 100644
--- a/src/gnome-maps.gresource.xml
+++ b/src/gnome-maps.gresource.xml
@@ -3,6 +3,7 @@
   <gresource prefix="/org/gnome/maps">
     <file preprocess="xml-stripblanks">app-menu.ui</file>
     <file preprocess="xml-stripblanks">main-window.ui</file>
+    <file preprocess="xml-stripblanks">control.ui</file>
     <file alias="application.css">../data/gnome-maps.css</file>
   </gresource>
 </gresources>
diff --git a/src/mapView.js b/src/mapView.js
index 0bfe944..8e332a6 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -25,6 +25,7 @@ const Cogl = imports.gi.Cogl;
 const Gdk = imports.gi.Gdk;
 const GdkPixbuf = imports.gi.GdkPixbuf;
 const Gtk = imports.gi.Gtk;
+const GtkClutter = imports.gi.GtkClutter;
 const GtkChamplain = imports.gi.GtkChamplain;
 const Champlain = imports.gi.Champlain;
 const Geocode = imports.gi.GeocodeGlib;
@@ -39,6 +40,7 @@ const Path = imports.path;
 const MapLocation = imports.mapLocation;
 const UserLocation = imports.userLocation;
 const Geoclue = imports.geoclue;
+const Control = imports.control;
 const _ = imports.gettext.gettext;
 
 const MapType = {
@@ -77,6 +79,10 @@ const MapView = new Lang.Class({
         this._factory = Champlain.MapSourceFactory.dup_default();
         this.setMapType(MapType.STREET);
 
+        this.view.add_child(new Control.Zoom(this.view, {
+            x_align: Clutter.ActorAlign.END
+        }));
+        
         this._showUserLocation();
     },
 
@@ -186,5 +192,6 @@ const MapView = new Lang.Class({
     _onViewMoved: function() {
         this.emit('view-moved');
     }
+    
 });
 Signals.addSignalMethods(MapView.prototype);


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