Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make tracks and polygons clickable and make track points highlightable #95

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion examples/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ OSMGPSMAP_LIBS = \
$(SOUP24_LIBS)

## Demo Application
noinst_PROGRAMS = mapviewer polygon editable_track
noinst_PROGRAMS = mapviewer polygon editable_track clickable_track editable_clickable_track

mapviewer_SOURCES = \
mapviewer.c
Expand Down Expand Up @@ -62,6 +62,36 @@ editable_track_LDADD = \
$(GTHREAD_LIBS) \
$(top_builddir)/src/libosmgpsmap-1.0.la

clickable_track_SOURCES = \
clickable_track.c

clickable_track_CFLAGS = \
-I$(top_srcdir)/src \
$(WARN_CFLAGS) \
$(DISABLE_DEPRECATED) \
$(OSMGPSMAP_CFLAGS) \
$(GTHREAD_CFLAGS)

clickable_track_LDADD = \
$(OSMGPSMAP_LIBS) \
$(GTHREAD_LIBS) \
$(top_builddir)/src/libosmgpsmap-1.0.la

editable_clickable_track_SOURCES = \
editable_clickable_track.c

editable_clickable_track_CFLAGS = \
-I$(top_srcdir)/src \
$(WARN_CFLAGS) \
$(DISABLE_DEPRECATED) \
$(OSMGPSMAP_CFLAGS) \
$(GTHREAD_CFLAGS)

editable_clickable_track_LDADD = \
$(OSMGPSMAP_LIBS) \
$(GTHREAD_LIBS) \
$(top_builddir)/src/libosmgpsmap-1.0.la

## Misc
EXTRA_DIST = poi.png mapviewer.ui mapviewer.js README

77 changes: 77 additions & 0 deletions examples/clickable_track.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*- */
/* vim:set et sw=4 ts=4 cino=t0,(0: */
/*
* clickable_track.c
* Copyright (C) Martijn Goedhart 2014 <goedhart.martijn@gmail.com>
*
* This 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; version 2.
*
* This program 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 this program; if not, see <http://www.gnu.org/licenses/>.
*/

#include <gtk/gtk.h>
#include "osm-gps-map.h"
#include "converter.h"

void point_clicked(OsmGpsMapTrack *osmgpsmaptrack, OsmGpsMapPoint *point, gpointer user_data);

void
point_clicked(OsmGpsMapTrack *osmgpsmaptrack, OsmGpsMapPoint *point, gpointer user_data)
{
printf("point at latitude: %.4f and longitude %.4f clicked\n", rad2deg(point->rlat), rad2deg(point->rlon));
osm_gps_map_track_set_highlight_point(osmgpsmaptrack, point);
}

int
main (int argc, char *argv[])
{
OsmGpsMap *map;
GtkWidget *window;

gtk_init(&argc, &argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Window");
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

map = g_object_new(OSM_TYPE_GPS_MAP, NULL);
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(map));

OsmGpsMapTrack* track = osm_gps_map_track_new();

OsmGpsMapPoint* p1, *p2, *p3, *p4;
p1 = osm_gps_map_point_new_radians(1.25663706, -0.488692191);
p2 = osm_gps_map_point_new_radians(1.06465084, -0.750491578);
p3 = osm_gps_map_point_new_radians(1.17245321, -0.685401453);
p4 = osm_gps_map_point_new_radians(1.04543154, -0.105454354);

osm_gps_map_track_add_point(track, p1);
osm_gps_map_track_add_point(track, p2);
osm_gps_map_track_add_point(track, p3);
osm_gps_map_track_add_point(track, p4);

osm_gps_map_point_free(p1);
osm_gps_map_point_free(p2);
osm_gps_map_point_free(p3);
osm_gps_map_point_free(p4);

g_object_set(track, "clickable", TRUE, NULL);
g_signal_connect(track, "point-clicked", G_CALLBACK(point_clicked), NULL);

osm_gps_map_track_add(map, track);

gtk_widget_show(GTK_WIDGET(map));
gtk_widget_show(window);

gtk_main();

return 0;
}
86 changes: 86 additions & 0 deletions examples/editable_clickable_track.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*- */
/* vim:set et sw=4 ts=4 cino=t0,(0: */
/*
* clickable_track.c
* Copyright (C) Martijn Goedhart 2014 <goedhart.martijn@gmail.com>
*
* This 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; version 2.
*
* This program 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 this program; if not, see <http://www.gnu.org/licenses/>.
*/

#include <gtk/gtk.h>
#include "osm-gps-map.h"
#include "converter.h"

void point_clicked(OsmGpsMapTrack *osmgpsmaptrack, OsmGpsMapPoint *point, gpointer user_data);
void point_changed(OsmGpsMapTrack *osmgpsmaptrack, gpointer user_data);

void
point_clicked(OsmGpsMapTrack *osmgpsmaptrack, OsmGpsMapPoint *point, gpointer user_data)
{
printf("point at latitude: %.4f and longitude %.4f clicked\n", rad2deg(point->rlat), rad2deg(point->rlon));
osm_gps_map_track_set_highlight_point(osmgpsmaptrack, point);
}

void
point_changed(OsmGpsMapTrack *osmgpsmaptrack, gpointer user_data)
{
printf("point has changed\n");
}

int
main (int argc, char *argv[])
{
OsmGpsMap *map;
GtkWidget *window;

gtk_init(&argc, &argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Window");
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

map = g_object_new(OSM_TYPE_GPS_MAP, NULL);
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(map));

OsmGpsMapTrack* track = osm_gps_map_track_new();

OsmGpsMapPoint* p1, *p2, *p3, *p4;
p1 = osm_gps_map_point_new_radians(1.25663706, -0.488692191);
p2 = osm_gps_map_point_new_radians(1.06465084, -0.750491578);
p3 = osm_gps_map_point_new_radians(1.17245321, -0.685401453);
p4 = osm_gps_map_point_new_radians(1.04543154, -0.105454354);

osm_gps_map_track_add_point(track, p1);
osm_gps_map_track_add_point(track, p2);
osm_gps_map_track_add_point(track, p3);
osm_gps_map_track_add_point(track, p4);

osm_gps_map_point_free(p1);
osm_gps_map_point_free(p2);
osm_gps_map_point_free(p3);
osm_gps_map_point_free(p4);

g_object_set(track, "clickable", TRUE, NULL);
g_object_set(track, "editable", TRUE, NULL);
g_signal_connect(track, "point-clicked", G_CALLBACK(point_clicked), NULL);
g_signal_connect(track, "point-changed", G_CALLBACK(point_changed), NULL);

osm_gps_map_track_add(map, track);

gtk_widget_show(GTK_WIDGET(map));
gtk_widget_show(window);

gtk_main();

return 0;
}
15 changes: 15 additions & 0 deletions src/osm-gps-map-polygon.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum
PROP_SHADED,
PROP_EDITABLE,
PROP_SHADE_ALPHA,
PROP_CLICKABLE,
PROP_BREAKABLE
};

Expand All @@ -38,6 +39,7 @@ struct _OsmGpsMapPolygonPrivate
gboolean visible;
gboolean editable;
gboolean shaded;
gboolean clickable;
gfloat shade_alpha;
gboolean breakable;
};
Expand Down Expand Up @@ -74,6 +76,9 @@ osm_gps_map_polygon_get_property (GObject *object,
case PROP_SHADE_ALPHA:
g_value_set_float(value, priv->shade_alpha);
break;
case PROP_CLICKABLE:
g_value_set_boolean(value, priv->clickable);
break;
case PROP_BREAKABLE:
g_value_set_boolean(value, priv->breakable);
break;
Expand Down Expand Up @@ -107,6 +112,9 @@ osm_gps_map_polygon_set_property (GObject *object,
case PROP_SHADE_ALPHA:
priv->shade_alpha = g_value_get_float(value);
break;
case PROP_CLICKABLE:
priv->clickable = g_value_get_boolean(value);
break;
case PROP_BREAKABLE:
priv->breakable = g_value_get_boolean(value);
break;
Expand Down Expand Up @@ -191,6 +199,13 @@ osm_gps_map_polygon_class_init (OsmGpsMapPolygonClass *klass)
TRUE,
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));

g_object_class_install_property (object_class,
PROP_CLICKABLE,
g_param_spec_boolean ("clickable",
"clickable",
"should this polygon be clickable",
FALSE,
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
}

static void
Expand Down
Loading