Commit 11302aa1 authored by Marcus Lundblad's avatar Marcus Lundblad
Browse files

Start converting ShumateView into a GtkWidget

Remove Clutter and make ShumateView a GTK widget.
Currently does no rendering. Some of the demos run
(with no output), the rest currently disabled from build.
parent 76614452
......@@ -24,8 +24,7 @@
static gboolean
draw_center (ClutterCanvas *canvas,
cairo_t *cr,
draw_center (cairo_t *cr,
int width,
int height)
{
......@@ -47,8 +46,7 @@ draw_center (ClutterCanvas *canvas,
static gboolean
draw_circle (ClutterCanvas *canvas,
cairo_t *cr,
draw_circle (cairo_t *cr,
int width,
int height)
{
......@@ -69,7 +67,7 @@ draw_circle (ClutterCanvas *canvas,
/* The marker is drawn with cairo. It is composed of 1 static filled circle
* and 1 stroked circle animated as an echo.
*/
static ClutterActor *
static ShumateMarker *
create_marker ()
{
ClutterActor *marker;
......
......@@ -18,39 +18,39 @@
*/
#include <shumate/shumate.h>
#include <gtk/gtk.h>
static ClutterActor *stage;
static GtkWidget *window;
static ClutterActor *
create_actor ()
static ShumateView *
create_view ()
{
ClutterActor *actor;
ShumateView *view;
/* Create the map view */
actor = shumate_view_new ();
clutter_actor_set_size (CLUTTER_ACTOR (actor), 800, 600);
clutter_actor_add_child (stage, actor);
view = shumate_view_new ();
gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (view));
shumate_view_set_zoom_level (SHUMATE_VIEW (actor), 12);
shumate_view_center_on (SHUMATE_VIEW (actor), 45.466, -73.75);
shumate_view_set_zoom_level (view, 12);
shumate_view_center_on (view, 45.466, -73.75);
return actor;
return view;
}
static gboolean
callback (void *data)
{
static ClutterActor *actor = NULL;
static ShumateView *view = NULL;
if (!actor)
if (!view)
{
actor = create_actor();
view = create_view();
}
else
{
clutter_actor_destroy (actor);
actor = NULL;
gtk_widget_destroy (GTK_WIDGET (view));
view = NULL;
}
return TRUE;
......@@ -60,17 +60,16 @@ callback (void *data)
int
main (int argc, char *argv[])
{
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
return 1;
gtk_init ();
stage = clutter_stage_new ();
clutter_actor_set_size (stage, 800, 600);
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request (GTK_WIDGET (window), 800, 600);
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
g_timeout_add (100, (GSourceFunc) callback, NULL);
clutter_actor_show (stage);
clutter_main ();
gtk_widget_show (window);
gtk_main ();
return 0;
}
......@@ -18,54 +18,28 @@
*/
using GLib;
using Clutter;
using Gtk;
using Shumate;
public class Launcher : GLib.Object
{
private const int PADDING = 10;
private Shumate.View view;
private Clutter.Stage stage;
private Gtk.Window window;
public Launcher ()
{
float width, total_width = 0;
stage = new Clutter.Stage ();
stage.title = "Shumate Vala Example";
stage.set_size (800, 600);
window = new Gtk.Window ();
window.title = "Shumate Vala Example";
window.default_width = 800;
window.default_height = 600;
/* Create the map view */
view = new Shumate.View ();
view.set_size (800, 600);
stage.add_child (view);
/* Create the buttons */
var buttons = new Clutter.Actor ();
buttons.set_position (PADDING, PADDING);
var button = make_button ("Zoom in");
buttons.add_child (button);
button.reactive = true;
button.get_size (out width, null);
total_width += width + PADDING;
button.button_release_event.connect ((event) => {
view.zoom_in ();
return true;
});
button = make_button ("Zoom out");
buttons.add_child (button);
button.reactive = true;
button.set_position (total_width, 0);
button.get_size (out width, null);
total_width += width + PADDING;
button.button_release_event.connect ((event) => {
view.zoom_out ();
return true;
});
stage.add_child (buttons);
//view.set_size_request (800, 600);
window.add (view);
/* Create the markers and marker layer */
var layer = new DemoLayer ();
......@@ -83,56 +57,18 @@ public class Launcher : GLib.Object
public void show ()
{
stage.show ();
window.show ();
}
private bool button_release_cb (Clutter.ButtonEvent event)
{
double lat, lon;
if (event.button != 1 || event.click_count > 1)
return false;
lat = view.y_to_latitude (event.y);
lon = view.x_to_longitude (event.x);
GLib.print ("Map clicked at %f, %f \n", lat, lon);
return true;
}
public Clutter.Actor make_button (string text)
{
Clutter.Color white = { 0xff, 0xff, 0xff, 0xff };
Clutter.Color black = { 0x00, 0x00, 0x00, 0xff };
float width, height;
var button = new Clutter.Actor ();
var button_bg = new Clutter.Actor ();
button_bg.set_background_color (white);
button.add_child (button_bg);
button_bg.opacity = 0xcc;
var button_text = new Clutter.Text.full ("Sans 10", text, black);
button.add_child (button_text);
button_text.get_size (out width, out height);
button_bg.set_size (width + PADDING * 2, height + PADDING * 2);
button_bg.set_position (0, 0);
button_text.set_position (PADDING, PADDING);
return button;
}
public static int main (string[] args)
{
if (Clutter.init (ref args) != InitError.SUCCESS)
if (Gtk.init (ref args) != InitError.SUCCESS)
return 1;
var launcher = new Launcher ();
launcher.show ();
Clutter.main ();
Gtk.main ();
return 0;
}
}
......
......@@ -17,23 +17,22 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include <shumate/shumate.h>
#include "markers.h"
#define PADDING 10
static gboolean
map_view_button_release_cb (G_GNUC_UNUSED ClutterActor *actor,
ClutterButtonEvent *event,
map_view_button_release_cb (G_GNUC_UNUSED GtkWidget *widget,
GdkEvent *event,
ShumateView *view)
{
gdouble lat, lon;
if (event->button != 1 || event->click_count > 1)
return FALSE;
lon = shumate_view_x_to_longitude (view, event->x);
lat = shumate_view_y_to_latitude (view, event->y);
lon = shumate_view_x_to_longitude (view, event->button.x);
lat = shumate_view_y_to_latitude (view, event->button.y);
g_print ("Map clicked at %f, %f \n", lat, lon);
......@@ -42,8 +41,8 @@ map_view_button_release_cb (G_GNUC_UNUSED ClutterActor *actor,
static gboolean
zoom_in (G_GNUC_UNUSED ClutterActor *actor,
G_GNUC_UNUSED ClutterButtonEvent *event,
zoom_in (G_GNUC_UNUSED GtkWidget *widget,
G_GNUC_UNUSED GdkEventButton *event,
ShumateView *view)
{
shumate_view_zoom_in (view);
......@@ -52,8 +51,8 @@ zoom_in (G_GNUC_UNUSED ClutterActor *actor,
static gboolean
zoom_out (G_GNUC_UNUSED ClutterActor *actor,
G_GNUC_UNUSED ClutterButtonEvent *event,
zoom_out (G_GNUC_UNUSED GtkWidget *widget,
G_GNUC_UNUSED GdkEventButton *event,
ShumateView *view)
{
shumate_view_zoom_out (view);
......@@ -61,147 +60,41 @@ zoom_out (G_GNUC_UNUSED ClutterActor *actor,
}
static ClutterActor *
make_button (char *text)
{
ClutterActor *button, *button_bg, *button_text;
ClutterColor white = { 0xff, 0xff, 0xff, 0xff };
ClutterColor black = { 0x00, 0x00, 0x00, 0xff };
gfloat width, height;
button = clutter_actor_new ();
button_bg = clutter_actor_new ();
clutter_actor_set_background_color (button_bg, &white);
clutter_actor_add_child (button, button_bg);
clutter_actor_set_opacity (button_bg, 0xcc);
button_text = clutter_text_new_full ("Sans 10", text, &black);
clutter_actor_add_child (button, button_text);
clutter_actor_get_size (button_text, &width, &height);
clutter_actor_set_size (button_bg, width + PADDING * 2, height + PADDING * 2);
clutter_actor_set_position (button_bg, 0, 0);
clutter_actor_set_position (button_text, PADDING, PADDING);
return button;
}
#define TILE_SQUARE_SIZE 64
static gboolean
draw_background_tile (ClutterCanvas *canvas,
cairo_t *cr,
int width,
int height)
{
cairo_pattern_t *pat;
gint no_of_squares_x = width / TILE_SQUARE_SIZE;
gint no_of_squares_y = height / TILE_SQUARE_SIZE;
gint row, column;
/* Create the background tile */
pat = cairo_pattern_create_linear (width / 2.0, 0.0, width, height / 2.0);
cairo_pattern_add_color_stop_rgb (pat, 0, 0.662, 0.662, 0.662);
cairo_set_source (cr, pat);
cairo_rectangle (cr, 0, 0, width, height);
cairo_fill (cr);
cairo_pattern_destroy (pat);
/* Filling the tile */
cairo_set_source_rgb (cr, 0.811, 0.811, 0.811);
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
for (row = 0; row < no_of_squares_y; ++row)
{
for (column = 0; column < no_of_squares_x; column++)
{
/* drawing square alternatively */
if ((row % 2 == 0 && column % 2 == 0) ||
(row % 2 != 0 && column % 2 != 0))
cairo_rectangle (cr,
column * TILE_SQUARE_SIZE,
row * TILE_SQUARE_SIZE,
TILE_SQUARE_SIZE,
TILE_SQUARE_SIZE);
}
cairo_fill (cr);
}
cairo_stroke (cr);
return TRUE;
}
int
main (int argc,
char *argv[])
{
ClutterActor *actor, *stage, *buttons, *button;
GtkWidget *window;
ShumateView *view;
ShumateMarkerLayer *layer;
ShumatePathLayer *path;
gfloat width, total_width = 0;
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
return 1;
gtk_init ();
stage = clutter_stage_new ();
clutter_actor_set_size (stage, 800, 600);
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request (window, 800, 600);
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
/* Create the map view */
actor = shumate_view_new ();
clutter_actor_set_size (CLUTTER_ACTOR (actor), 800, 600);
clutter_actor_add_child (stage, actor);
/* Create the buttons */
buttons = clutter_actor_new ();
clutter_actor_set_position (buttons, PADDING, PADDING);
button = make_button ("Zoom in");
clutter_actor_add_child (buttons, button);
clutter_actor_set_reactive (button, TRUE);
clutter_actor_get_size (button, &width, NULL);
total_width += width + PADDING;
g_signal_connect (button, "button-release-event",
G_CALLBACK (zoom_in),
actor);
button = make_button ("Zoom out");
clutter_actor_add_child (buttons, button);
clutter_actor_set_reactive (button, TRUE);
clutter_actor_set_position (button, total_width, 0);
clutter_actor_get_size (button, &width, NULL);
g_signal_connect (button, "button-release-event",
G_CALLBACK (zoom_out),
actor);
clutter_actor_add_child (stage, buttons);
ClutterContent *canvas;
canvas = clutter_canvas_new ();
clutter_canvas_set_size (CLUTTER_CANVAS (canvas), 512, 256);
g_signal_connect (canvas, "draw", G_CALLBACK (draw_background_tile), NULL);
clutter_content_invalidate (canvas);
shumate_view_set_background_pattern (SHUMATE_VIEW (actor), canvas);
view = shumate_view_new ();
gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (view));
/* Create the markers and marker layer */
layer = create_marker_layer (SHUMATE_VIEW (actor), &path);
shumate_view_add_layer (SHUMATE_VIEW (actor), SHUMATE_LAYER (layer));
layer = create_marker_layer (view, &path);
shumate_view_add_layer (view, SHUMATE_LAYER (layer));
/* Connect to the click event */
clutter_actor_set_reactive (actor, TRUE);
g_signal_connect (actor, "button-release-event",
G_CALLBACK (map_view_button_release_cb),
actor);
g_signal_connect (G_OBJECT (view), "button-press-event",
G_CALLBACK (map_view_button_release_cb), view);
/* Finish initialising the map view */
g_object_set (G_OBJECT (actor), "zoom-level", 12,
g_object_set (G_OBJECT (view), "zoom-level", 12,
"kinetic-mode", TRUE, NULL);
shumate_view_center_on (SHUMATE_VIEW (actor), 45.466, -73.75);
shumate_view_center_on (view, 45.466, -73.75);
clutter_actor_show (stage);
clutter_main ();
gtk_widget_show (window);
gtk_widget_show (GTK_WIDGET (view));
gtk_main ();
return 0;
}
......@@ -30,93 +30,39 @@
* export GI_TYPELIB_PATH=$GI_TYPELIB_PATH:/usr/local/lib/girepository-1.0/
*/
const Lang = imports.lang;
const Clutter = imports.gi.Clutter;
const Shumate = imports.gi.Shumate;
Clutter.init (null);
const PADDING = 10;
function make_button (text)
{
let white = new Clutter.Color ({red:0xff, blue:0xff, green:0xff, alpha:0xff});
let black = new Clutter.Color ({red:0x00, blue:0x00, green:0x00, alpha:0xff});
imports.gi.versions.Gtk = '4.0';
imports.gi.versions.Gdk = '4.0';
let button = new Clutter.Actor ();
let button_bg = new Clutter.Actor ();
button_bg.set_background_color (white)
button.add_child (button_bg);
button.set_opacity (0xcc);
const Gdk = imports.gi.Gdk;
const Gtk = imports.gi.Gtk;
const Shumate = imports.gi.Shumate;
let button_text = new Clutter.Text ({font_name:"Sans 10", text:text, color:black});
button.add_child (button_text);
Gtk.init ();
let [width, height] = button_text.get_size();
button_bg.set_size (width + PADDING * 2, height + PADDING * 2);
button_bg.set_position (0, 0);
button_text.set_position (PADDING, PADDING);
return button;
}
function map_view_button_release_cb (actor, event)
function map_view_button_release_cb (event)
{
// FIXME: it does not print and GLib.printf does not work.
if (event.button != 1 || event.click_count > 1)
return false;
let lat = view.y_to_latitude (event.y);
let lon = view.x_to_longitude (event.x);
let lat = view.y_to_latitude (event.button.y);
let lon = view.x_to_longitude (event.button.x);
log ("Map clicked at %f, %f \n", lat, lon);
return true;
}
let stage = new Clutter.Stage ();
stage.title = "Shumate Javascript Example";
stage.set_size (800, 600);
let window = new Gtk.Window (Gtk.Window.TOPLEVEL);
window.title = "Shumate Javascript Example";
window.set_size_request (800, 600);
/* Create the map view */
let view = new Shumate.View();
view.set_size (800, 600);
stage.add_actor (view);
window.add (view);
/* Create the buttons */
let buttons = new Clutter.Actor ();
let total_width = 0;
buttons.set_position (PADDING, PADDING);
let button = make_button ("Zoom in");
buttons.add_child (button);
button.set_reactive (true);
let width = button.width;
total_width += width + PADDING;
button.connect ("button-release-event", Lang.bind (view,
function (actor, event)
{
view.zoom_in ();
return true;
}));
let button = make_button ("Zoom out");
buttons.add_child (button);
button.set_reactive (true);
button.set_position (total_width, 0);
let width = button.width;
total_width += width + PADDING;
button.connect ("button-release-event", Lang.bind (view,
function (actor, event)
{
view.zoom_out ();
return true;
}));
stage.add_child (buttons);
/* Create the markers and marker layer */
let orange= Clutter.Color.new(0xf3,0x94,0x07,0xbb);
......@@ -128,17 +74,14 @@ marker.set_reactive(true);
layer.show();
view.add_layer(layer);
/* Connect to the click event */
view.set_reactive (true);
view.connect ("button-release-event", Lang.bind (view,
map_view_button_release_cb));
view.connect('button-pressed-event', (w, event) => map_view_button_release_cb (event));
/* Finish initialising the map view */
view.zoom_level = 12;
view.kinetic_mode = true;
view.center_on (45.466, -73.75);
stage.connect ("destroy", Clutter.main_quit);
window.connect ("destroy", Gtk.main_quit);
stage.show ();
Clutter.main ();
window.show ();
Gtk.main ();
......@@ -24,14 +24,12 @@
ShumateMarkerLayer *
create_marker_layer (G_GNUC_UNUSED ShumateView *view, ShumatePathLayer **path)
{
ClutterActor *marker;
ShumateMarker *marker;
ShumateMarkerLayer *layer;
ClutterActor *layer_actor;
ClutterColor orange = { 0xf3, 0x94, 0x07, 0xbb };
GdkRGBA orange = { 0.95, 0.6, 0.03, 0.75 };
*path = shumate_path_layer_new ();
layer = shumate_marker_layer_new_full (SHUMATE_SELECTION_SINGLE);
layer_actor = CLUTTER_ACTOR (layer);
marker = shumate_label_new_with_text ("Montréal\n<span size=\"xx-small\">Québec</span>",
"Serif 14", NULL, NULL);
......@@ -71,6 +69,5 @@ create_marker_layer (G_GNUC_UNUSED ShumateView *view, ShumatePathLayer **path)
shumate_marker_layer_set_all_markers_draggable (layer);
clutter_actor_show (layer_actor);
return layer;
}
libshumate_demos = [
['minimal', 'minimal.c'],
['launcher', ['launcher.c', 'markers.c']],
['animated-marker', 'animated-marker.c'],
['polygons', 'polygons.c'],
['url-marker', 'url-marker.c'],
['create_destroy_test', 'create-destroy-test.c'],
]
......
......@@ -17,27 +17,28 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <gtk/gtk.h>