Commit 5f1b0666 authored by James Westman's avatar James Westman Committed by Marcus Lundblad
Browse files

demos: Delete all demos except minimal

The plan is to have a single demo instead of a bunch of small ones. This
will make it easier to test and maintain a high-quality demo application.
parent 9adab0a8
/*
* Copyright (C) 2008 Pierre-Luc Beaudoin <pierre-luc@pierlux.com>
* Copyright (C) 2019 Marcus Lundblad <ml@update.uu.se>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <shumate/shumate.h>
#include <math.h>
#define MARKER_SIZE 10
static gboolean
draw_center (cairo_t *cr,
int width,
int height)
{
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
cairo_paint(cr);
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
/* Draw the circle */
cairo_set_source_rgb (cr, 0, 0, 0);
cairo_arc (cr, MARKER_SIZE / 2.0, MARKER_SIZE / 2.0, MARKER_SIZE / 2.0, 0, 2 * M_PI);
cairo_close_path (cr);
/* Fill the circle */
cairo_set_source_rgba (cr, 0.1, 0.1, 0.9, 1.0);
cairo_fill (cr);
return TRUE;
}
static gboolean
draw_circle (cairo_t *cr,
int width,
int height)
{
/* Draw the circle */
cairo_set_source_rgb (cr, 0, 0, 0);
cairo_arc (cr, MARKER_SIZE, MARKER_SIZE, 0.9 * MARKER_SIZE, 0, 2 * M_PI);
cairo_close_path (cr);
/* Stroke the circle */
cairo_set_line_width (cr, 2.0);
cairo_set_source_rgba (cr, 0.1, 0.1, 0.7, 1.0);
cairo_stroke (cr);
return TRUE;
}
/* The marker is drawn with cairo. It is composed of 1 static filled circle
* and 1 stroked circle animated as an echo.
*/
static ShumateMarker *
create_marker ()
{
ClutterActor *marker;
ClutterActor *bg;
ClutterContent *canvas;
ClutterTransition *transition;
/* Create the marker */
marker = shumate_marker_new ();
/* Static filled circle ----------------------------------------------- */
canvas = clutter_canvas_new ();
clutter_canvas_set_size (CLUTTER_CANVAS (canvas), MARKER_SIZE, MARKER_SIZE);
g_signal_connect (canvas, "draw", G_CALLBACK (draw_center), NULL);
bg = clutter_actor_new ();
clutter_actor_set_size (bg, MARKER_SIZE, MARKER_SIZE);
clutter_actor_set_content (bg, canvas);
clutter_content_invalidate (canvas);
g_object_unref (canvas);
/* Add the circle to the marker */
clutter_actor_add_child (marker, bg);
clutter_actor_set_position (bg, -0.5 * MARKER_SIZE, -0.5 * MARKER_SIZE);
/* Echo circle -------------------------------------------------------- */
canvas = clutter_canvas_new ();
clutter_canvas_set_size (CLUTTER_CANVAS (canvas), 2 * MARKER_SIZE, 2 * MARKER_SIZE);
g_signal_connect (canvas, "draw", G_CALLBACK (draw_circle), NULL);
bg = clutter_actor_new ();
clutter_actor_set_size (bg, 2 * MARKER_SIZE, 2 * MARKER_SIZE);
clutter_actor_set_content (bg, canvas);
clutter_content_invalidate (canvas);
g_object_unref (canvas);
/* Add the circle to the marker */
clutter_actor_add_child (marker, bg);
clutter_actor_set_pivot_point (bg, 0.5, 0.5);
clutter_actor_set_position (bg, -MARKER_SIZE, -MARKER_SIZE);
transition = clutter_property_transition_new ("opacity");
clutter_actor_set_easing_mode (bg, CLUTTER_EASE_OUT_SINE);
clutter_timeline_set_duration (CLUTTER_TIMELINE (transition), 1000);
clutter_timeline_set_repeat_count (CLUTTER_TIMELINE (transition), -1);
clutter_transition_set_from (transition, G_TYPE_UINT, 255);
clutter_transition_set_to (transition, G_TYPE_UINT, 0);
clutter_actor_add_transition (bg, "animate-opacity", transition);
transition = clutter_property_transition_new ("scale-x");
clutter_actor_set_easing_mode (bg, CLUTTER_EASE_OUT_SINE);
clutter_timeline_set_duration (CLUTTER_TIMELINE (transition), 1000);
clutter_timeline_set_repeat_count (CLUTTER_TIMELINE (transition), -1);
clutter_transition_set_from (transition, G_TYPE_FLOAT, 0.5);
clutter_transition_set_to (transition, G_TYPE_FLOAT, 2.0);
clutter_actor_add_transition (bg, "animate-scale-x", transition);
transition = clutter_property_transition_new ("scale-y");
clutter_actor_set_easing_mode (bg, CLUTTER_EASE_OUT_SINE);
clutter_timeline_set_duration (CLUTTER_TIMELINE (transition), 1000);
clutter_timeline_set_repeat_count (CLUTTER_TIMELINE (transition), -1);
clutter_transition_set_from (transition, G_TYPE_FLOAT, 0.5);
clutter_transition_set_to (transition, G_TYPE_FLOAT, 2.0);
clutter_actor_add_transition (bg, "animate-scale-y", transition);
return marker;
}
double lat = 45.466;
double lon = -73.75;
typedef struct
{
ShumateView *view;
ShumateMarker *marker;
} GpsCallbackData;
static gboolean
gps_callback (GpsCallbackData *data)
{
lat += 0.005;
lon += 0.005;
shumate_view_center_on (data->view, lat, lon);
shumate_location_set_location (SHUMATE_LOCATION (data->marker), lat, lon);
return TRUE;
}
int
main (int argc, char *argv[])
{
ClutterActor *actor, *marker, *stage;
ShumateMarkerLayer *layer;
GpsCallbackData callback_data;
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
return 1;
stage = clutter_stage_new ();
clutter_actor_set_size (stage, 800, 600);
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_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 marker layer */
layer = shumate_marker_layer_new_full (SHUMATE_SELECTION_SINGLE);
clutter_actor_show (CLUTTER_ACTOR (layer));
shumate_view_add_layer (SHUMATE_VIEW (actor), SHUMATE_LAYER (layer));
/* Create a marker */
marker = create_marker ();
shumate_marker_layer_add_marker (layer, SHUMATE_MARKER (marker));
/* Finish initialising the map view */
g_object_set (G_OBJECT (actor), "zoom-level", 12,
"kinetic-mode", TRUE, NULL);
shumate_view_center_on (SHUMATE_VIEW (actor), lat, lon);
/* Create callback that updates the map periodically */
callback_data.view = SHUMATE_VIEW (actor);
callback_data.marker = SHUMATE_MARKER (marker);
g_timeout_add (1000, (GSourceFunc) gps_callback, &callback_data);
clutter_actor_show (stage);
clutter_main ();
return 0;
}
/*
* Copyright (C) 2010-2013 Jiri Techet <techet@gmail.com>
* Copyright (C) 2019 Marcus Lundblad <ml@update.uu.se>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <shumate/shumate.h>
#include <gtk/gtk.h>
static GtkWidget *view = NULL;
static gboolean
callback (GtkWidget *parent)
{
if (!view)
{
ShumateViewport *viewport;
/* Create the map view */
view = GTK_WIDGET (shumate_view_new ());
gtk_widget_insert_after (view, parent, NULL);
viewport = shumate_view_get_viewport (SHUMATE_VIEW (view));
shumate_viewport_set_zoom_level (viewport, 12);
shumate_location_set_location (SHUMATE_LOCATION (viewport), 45.466, -73.75);
}
else
g_clear_pointer (&view, gtk_widget_unparent);
return G_SOURCE_CONTINUE;
}
static gboolean
on_close_request (GtkWindow *window,
gpointer user_data)
{
g_source_remove (GPOINTER_TO_UINT (user_data));
return FALSE;
}
static void
activate (GtkApplication *app,
gpointer user_data)
{
GtkWidget *grid;
guint timeout_id;
GtkWindow *window = GTK_WINDOW (gtk_application_window_new (app));
gtk_window_set_title (window, "Window");
gtk_window_set_default_size (window, 800, 600);
grid = gtk_grid_new ();
gtk_window_set_child (window, grid);
gtk_window_present (window);
timeout_id = g_timeout_add (100, G_SOURCE_FUNC (callback), grid);
g_signal_connect (window, "close-request", G_CALLBACK (on_close_request), GUINT_TO_POINTER (timeout_id));
}
int
main (int argc, char *argv[])
{
g_autoptr(GtkApplication) app = NULL;
app = gtk_application_new ("org.shumate.example", G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
return g_application_run (G_APPLICATION (app), argc, argv);
}
libchamplain_demo_data = [
'emblem-favorite.png',
'emblem-generic.png',
'emblem-important.png',
'emblem-new.png',
]
custom_target(
'libchamplain-demo-data',
input: libchamplain_demo_data,
output: libchamplain_demo_data,
command: ['cp', '@INPUT@', '@OUTDIR@'],
build_by_default: true,
)
\ No newline at end of file
#!/usr/bin/env python
# To run this example, you need to set the GI_TYPELIB_PATH environment
# variable to point to the gir directory:
#
# export GI_TYPELIB_PATH=$GI_TYPELIB_PATH:/usr/local/lib/girepository-1.0/
import gi
gi.require_version('GtkChamplain', '0.12')
gi.require_version('GtkClutter', '1.0')
from gi.repository import GtkClutter
from gi.repository import Gtk, Gdk, GtkChamplain
class KeyboardMapping:
def __init__(self):
GtkClutter.init([])
window = Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
window.connect("destroy", Gtk.main_quit)
window.connect("key-press-event", self.on_key_press)
self.widget = GtkChamplain.Embed()
self.widget.set_size_request(640, 480)
self.view = self.widget.get_view()
self.view.set_horizontal_wrap(True)
window.add(self.widget)
window.show_all()
def on_key_press(self, widget, ev):
deltax = self.widget.get_allocation().width / 4
deltay = self.widget.get_allocation().height / 4
if ev.keyval == Gdk.KEY_Left:
self.scroll(-deltax, 0)
elif ev.keyval == Gdk.KEY_Right:
self.scroll(deltax, 0)
elif ev.keyval == Gdk.KEY_Up:
self.scroll(0, -deltay)
elif ev.keyval == Gdk.KEY_Down:
self.scroll(0, deltay)
elif ev.keyval == Gdk.KEY_plus or ev.keyval == Gdk.KEY_KP_Add:
self.view.zoom_in()
elif ev.keyval == Gdk.KEY_minus or ev.keyval == Gdk.KEY_KP_Subtract:
self.view.zoom_out()
else:
return False
return True
def scroll(self, deltax, deltay):
lat = self.view.get_center_latitude()
lon = self.view.get_center_longitude()
x = self.view.longitude_to_x(lon) + deltax
y = self.view.latitude_to_y(lat) + deltay
lon = self.view.x_to_longitude(x)
lat = self.view.y_to_latitude(y)
self.view.center_on(lat, lon)
#self.view.go_to(lat, lon)
if __name__ == "__main__":
KeyboardMapping()
Gtk.main()
/*
* Copyright (C) 2008 Pierre-Luc Beaudoin <pierre-luc@pierlux.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <gtk/gtk.h>
#include <champlain/champlain.h>
#include <champlain-gtk/champlain-gtk.h>
#include <clutter-gtk/clutter-gtk.h>
#include <markers.h>
#define N_COLS 2
#define COL_ID 0
#define COL_NAME 1
static ChamplainPathLayer *path_layer;
static ChamplainPathLayer *path;
static gboolean destroying = FALSE;
/*
* Terminate the main loop.
*/
static void
on_destroy (GtkWidget *widget, gpointer data)
{
destroying = TRUE;
gtk_main_quit ();
}
static void
toggle_layer (GtkToggleButton *widget,
ClutterActor *layer)
{
if (gtk_toggle_button_get_active (widget))
{
champlain_path_layer_set_visible (path_layer, TRUE);
champlain_path_layer_set_visible (path, TRUE);
champlain_marker_layer_animate_in_all_markers (CHAMPLAIN_MARKER_LAYER (layer));
}
else
{
champlain_path_layer_set_visible (path_layer, FALSE);
champlain_path_layer_set_visible (path, FALSE);
champlain_marker_layer_animate_out_all_markers (CHAMPLAIN_MARKER_LAYER (layer));
}
}
static gboolean
mouse_click_cb (ClutterActor *actor, ClutterButtonEvent *event, ChamplainView *view)
{
double lat, lon;
lon = champlain_view_x_to_longitude (view, event->x);
lat = champlain_view_y_to_latitude (view, event->y);
g_print ("Mouse click at: %f %f\n", lat, lon);
return TRUE;
}
static void
map_source_changed (GtkWidget *widget,
ChamplainView *view)
{
char *id;
ChamplainMapSource *source;
GtkTreeIter iter;
GtkTreeModel *model;
if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter))
return;
model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
gtk_tree_model_get (model, &iter, COL_ID, &id, -1);
ChamplainMapSourceFactory *factory = champlain_map_source_factory_dup_default ();
source = champlain_map_source_factory_create_cached_source (factory, id);
g_object_set (G_OBJECT (view), "map-source", source, NULL);
g_object_unref (factory);
}
static void
zoom_changed (GtkSpinButton *spinbutton,
ChamplainView *view)
{
int zoom = gtk_spin_button_get_value_as_int (spinbutton);
g_object_set (G_OBJECT (view), "zoom-level", zoom, NULL);
}
static void
map_zoom_changed (ChamplainView *view,
GParamSpec *gobject,
GtkSpinButton *spinbutton)
{
int zoom;
g_object_get (G_OBJECT (view), "zoom-level", &zoom, NULL);
gtk_spin_button_set_value (spinbutton, zoom);
}
static void
view_state_changed (ChamplainView *view,
GParamSpec *gobject,
GtkImage *image)
{
ChamplainState state;
if (destroying)
return;
g_object_get (G_OBJECT (view), "state", &state, NULL);
if (state == CHAMPLAIN_STATE_LOADING)
{
gtk_image_set_from_icon_name (image, "edit-find", GTK_ICON_SIZE_BUTTON);
}
else
{
gtk_image_clear (image);
}
}
static void
zoom_in (GtkWidget *widget,
ChamplainView *view)
{
champlain_view_zoom_in (view);
}
static void
zoom_out (GtkWidget *widget,
ChamplainView *view)
{
champlain_view_zoom_out (view);
}
static void
toggle_wrap (GtkWidget *widget,
ChamplainView *view)
{
gboolean wrap;
wrap = champlain_view_get_horizontal_wrap (view);
champlain_view_set_horizontal_wrap (view, !wrap);
}
static void
build_combo_box (GtkComboBox *box)
{
ChamplainMapSourceFactory *factory;
GSList *sources, *iter;
GtkTreeStore *store;
GtkTreeIter parent;
GtkCellRenderer *cell;
store = gtk_tree_store_new (N_COLS, G_TYPE_STRING, /* id */
G_TYPE_STRING, /* name */
-1);
factory = champlain_map_source_factory_dup_default ();
sources = champlain_map_source_factory_get_registered (factory);
iter = sources;
while (iter != NULL)
{
ChamplainMapSourceDesc *desc = CHAMPLAIN_MAP_SOURCE_DESC (iter->data);
const char *id = champlain_map_source_desc_get_id (desc);
const char *name = champlain_map_source_desc_get_name (desc);
gtk_tree_store_append (store, &parent, NULL);
gtk_tree_store_set (store, &parent, COL_ID, id,
COL_NAME, name, -1);
iter = g_slist_next (iter);
}
g_slist_free (sources);
g_object_unref (factory);
gtk_combo_box_set_model (box, GTK_TREE_MODEL (store));
cell = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (box), cell, FALSE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (box), cell,
"text", COL_NAME, NULL);
}
static void
append_point (ChamplainPathLayer *layer, double lon, double lat)
{
ChamplainCoordinate *coord;
coord = champlain_coordinate_new_full (lon, lat);
champlain_path_layer_add_node (layer, CHAMPLAIN_LOCATION (coord));
}
static void
export_png (GtkButton *button,
ChamplainView *view)
{
cairo_surface_t *surface;
GdkPixbuf *pixbuf;
GFileOutputStream *os;
GFile *file;
int width, height;
if (champlain_view_get_state (view) != CHAMPLAIN_STATE_DONE)
return;
surface = champlain_view_to_surface (view, TRUE);
if (!surface)
return;
width = cairo_image_surface_get_width (surface);
height = cairo_image_surface_get_height (surface);
pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, width, height);
if (!pixbuf)
return;