[gnome-maps] mapView: Use custom widget to embed ChamplainView
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps] mapView: Use custom widget to embed ChamplainView
- Date: Fri, 5 Apr 2013 10:44:49 +0000 (UTC)
commit 6cd094aa2b986cfde5ab3401614f40570fbdfd52
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Fri Apr 5 05:40:20 2013 +0300
mapView: Use custom widget to embed ChamplainView
We'll be needing to overlay a sidebar and a button with transparent
container for (un)revealing it. Trouble with GtkChamplain.Embed is that
its a native window and using Gtk.Overlay with (semi-)transparent widgets
over native windows is not supported[1].
We now create our own embedding widget for ChamplainView that has its own
actor with BinLayout put ChamplainView in it. Later we simply add overlay
widgets using GtkClutter into it.
co-author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
[1]
https://git.gnome.org/browse/gtk+/commit/?h=gtk-3-8&id=8c02e290c443f7f99d8b26855cef17ab66a5bad6
src/Makefile-js.am | 1 +
src/mainWindow.js | 8 ++-
src/mapView.js | 4 +-
src/mapViewEmbed.js | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 122 insertions(+), 6 deletions(-)
---
diff --git a/src/Makefile-js.am b/src/Makefile-js.am
index 2b0d22f..b2146c6 100644
--- a/src/Makefile-js.am
+++ b/src/Makefile-js.am
@@ -5,6 +5,7 @@ dist_js_DATA = \
mainWindow.js \
mainToolbar.js \
mapView.js \
+ mapViewEmbed.js \
path.js \
utils.js
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 67ccf7f..344a752 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -30,7 +30,7 @@ const Mainloop = imports.mainloop;
const Application = imports.application;
const MainToolbar = imports.mainToolbar;
-const MapView = imports.mapView;
+const MapViewEmbed = imports.mapViewEmbed;
const Utils = imports.utils;
const Config = imports.config;
@@ -93,8 +93,10 @@ const MainWindow = new Lang.Class({
this._toolbar = new MainToolbar.MainToolbar(this);
grid.add(this._toolbar.widget);
- this.mapView = new MapView.MapView();
- grid.add(this.mapView.widget);
+ this._embed = new MapViewEmbed.MapViewEmbed();
+ grid.add(this._embed);
+
+ this.mapView = this._embed.mapView;
grid.show_all();
},
diff --git a/src/mapView.js b/src/mapView.js
index 3513583..87993f7 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -22,7 +22,6 @@ const Gdk = imports.gi.Gdk;
const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
const Champlain = imports.gi.Champlain;
-const GtkChamplain = imports.gi.GtkChamplain;
const Geocode = imports.gi.GeocodeGlib;
const Lang = imports.lang;
@@ -44,8 +43,7 @@ const MapView = new Lang.Class({
Name: 'MapView',
_init: function(app) {
- this.widget = new GtkChamplain.Embed();
- this.actor = this.widget.get_view();
+ this.actor = new Champlain.View();
this._view = this.actor;
diff --git a/src/mapViewEmbed.js b/src/mapViewEmbed.js
new file mode 100644
index 0000000..6769c53
--- /dev/null
+++ b/src/mapViewEmbed.js
@@ -0,0 +1,115 @@
+/*
+ * 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: Cosimo Cecchi <cosimoc gnome org>
+ * Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ */
+
+const Gdk = imports.gi.Gdk;
+const GLib = imports.gi.GLib;
+const Gtk = imports.gi.Gtk;
+const Champlain = imports.gi.Champlain;
+const Clutter = imports.gi.Clutter;
+const Geocode = imports.gi.GeocodeGlib;
+const Gd = imports.gi.Gd;
+const GtkClutter = imports.gi.GtkClutter;
+const Properties = imports.properties;
+const MapView = imports.mapView;
+
+const Lang = imports.lang;
+const Mainloop = imports.mainloop;
+
+const Application = imports.application;
+const Utils = imports.utils;
+const _ = imports.gettext.gettext;
+
+const MapViewEmbed = new Lang.Class({
+ Name: 'MapViewEmbed',
+ Extends: GtkClutter.Embed,
+
+ _init: function() {
+ this.parent();
+
+ this._cursorHandOpen = Gdk.Cursor.new(Gdk.CursorType.HAND1);
+ this._cursorHandClosed = Gdk.Cursor.new(Gdk.CursorType.FLEUR);
+
+ this.mapView = new MapView.MapView();
+ this._layout = new Clutter.BinLayout();
+ this._actor = new Clutter.Actor({ layout_manager: this._layout,
+ x_expand: true,
+ y_expand: true });
+
+ this.mapView.actor.x_expand = true;
+ this.mapView.actor.y_expand = true;
+ this._actor.add_child(this.mapView.actor);
+
+ let stage = this.get_stage();
+ stage.add_actor(this._actor);
+
+ this.connect('button-press-event', Lang.bind(this, this._onButtonPress));
+ this.connect('button-release-event', Lang.bind(this, this._onButtonRelease));
+ },
+
+ vfunc_realize: function(params) {
+ this.parent(params);
+ this._updateViewStyle();
+ },
+
+ vfunc_style_updated: function(params) {
+ this.parent(params);
+ this._updateViewStyle();
+ },
+
+ vfunc_size_allocate: function(params) {
+ this.parent(params);
+
+ let allocation = this.get_allocation();
+
+ this.mapView.actor.set_size(allocation.width,
+ allocation.height);
+ },
+
+ _onButtonPress: function(event) {
+ this.get_window().set_cursor(this._cursorHandClosed);
+ return false;
+ },
+
+ _onButtonRelease: function() {
+ this.get_window().set_cursor(this._cursorHandOpen);
+ return false;
+ },
+
+ _updateViewStyle: function() {
+ function clutterColorFromRGBA(rgba) {
+ return new Clutter.Color({ red: rgba.red * 255,
+ green: rgba.green * 255,
+ blue: rgba.blue * 255,
+ alpha: rgba.alpha * 255 });
+ }
+
+ let context = this.get_style_context();
+ let rgba = context.get_color(Gtk.StateFlags.SELECTED);
+ let color = clutterColorFromRGBA(rgba);
+ Champlain.Marker.set_selection_text_color(color);
+
+ rgba = context.get_background_color(Gtk.StateFlags.SELECTED);
+ color = clutterColorFromRGBA(rgba);
+ Champlain.Marker.set_selection_color(color);
+
+ this.get_window().set_cursor(this._cursorHandOpen);
+ }
+});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]