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

First attempt to update code for GTK4 #97

Draft
wants to merge 51 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
580150e
add clickable property and point-clicked signal to OsmGpsMapTrack
smartyg Aug 26, 2014
9245c81
add clickable property to OsmGpsMapPolygon
smartyg Aug 27, 2014
657908f
make tracks with the clickable property set clickable
smartyg Aug 27, 2014
9db095c
add clickable_track example to give a simple idea of the use of click…
smartyg Aug 27, 2014
5f2f199
add editable_clickable_track example for an impression of those two f…
smartyg Aug 27, 2014
b49ac08
emit the point-clicked signal also after a breaker has been clicked
smartyg Aug 27, 2014
5fa4f8b
also make polylines draw dots when the clickable property is set
smartyg Aug 27, 2014
57a5ad9
add highlight point and color property to the track type
smartyg Aug 17, 2014
34379cc
draw highlighted point with highlight color
smartyg Aug 27, 2014
b57d513
extend the clickable_track example to also highlight the clicked point
smartyg Aug 17, 2014
acd6c09
extend the editable_clickable_track example to also highlight the cli…
smartyg Aug 27, 2014
f200189
add callback functionality for the tile loader
smartyg Mar 17, 2022
a85bb4c
Use the alpha field from GdkRGBA instead of a separate one; remove th…
smartyg Aug 17, 2014
4bd5619
change the type of the color and highlight-color to GDK_TYPE_RGBA so …
smartyg Aug 27, 2014
669e073
Merge branch 'map-source-callback'
smartyg Mar 19, 2022
caaada6
update requirements
smartyg Apr 3, 2022
b219fee
it seems g_cclosure_marshal_VOID__INT is beter for the point-changed …
smartyg Apr 3, 2022
98589e2
fix error; g_value_get_pointer: assertion 'G_VALUE_HOLDS_POINTER (val…
smartyg Apr 3, 2022
1087ed2
Merge branch 'master' into gtk4
smartyg Apr 3, 2022
17f6644
compile with warnings for deprecated symbols
smartyg Jun 14, 2022
b02f24a
enable warnings for deprecated symbols for example programs
smartyg Jun 15, 2022
2af01ee
Merge branch 'gtk4-prepare' into gtk4
smartyg Jun 15, 2022
48986bf
replace gtk_widget_queue_draw_area with gtk_widget_queue_draw
smartyg Jun 19, 2022
0ee6145
switch to GtkEventControllerMotion for mouse movement events
smartyg Jun 19, 2022
98c3ac1
use gtk3 code to register eventController
smartyg Jun 19, 2022
3198151
temporarly disable draw motion (click-move) to drag the map around; T…
smartyg Jun 19, 2022
d6402ba
switch to GtkEventControllerScroll for scroll (zoom) events
smartyg Jun 19, 2022
0003baf
also remove old event registration
smartyg Jun 19, 2022
5065769
fix whitespaces
smartyg Jun 19, 2022
cea8c48
Fix: revert zoom direction
smartyg Jun 19, 2022
7e3a785
apparently gtk_widget_add_events is still needed with GtkEventController
smartyg Jun 20, 2022
e413e99
switch to GtkEventControllerKey for key press events
smartyg Jun 19, 2022
6602e3f
fix whitespaces
smartyg Jun 20, 2022
6eff0c9
fix: wrong parameter usage
smartyg Jun 20, 2022
9c65cd8
switch to GtkGestureMultiPress for (mouse) button click events
smartyg Jun 19, 2022
dc60f34
do not listen to configure-event, but use notify event
smartyg Jun 19, 2022
8efa699
fix the proper incovation of the configure function
smartyg Jun 20, 2022
8559c75
Merge branch 'gtk4-backport' into gtk4-test
smartyg Jun 20, 2022
d567ca4
little code cleaning/styling
smartyg Jun 20, 2022
10be152
one more code cleaning/styling
smartyg Jun 20, 2022
7953b7b
replace GtkGestureMultiPress with GtkGestureClick
smartyg Jun 20, 2022
141290b
update the window event controllers to GTK4 code
smartyg Jun 20, 2022
87f7c4c
update the draw and configure functions
smartyg Jun 20, 2022
5100b82
use gtk_event_controller_get_current_event_state instead of gtk_gestu…
smartyg Jun 20, 2022
cd26ed9
update osm_gps_map_get_event_location function as GdkEventButton is n…
smartyg Jun 20, 2022
9d89dd7
fix a few whitespaces
smartyg Jun 20, 2022
6e7458f
update function description of osm_gps_map_layer_button_press
smartyg Jun 20, 2022
9ff9359
osm-gps-map-track: introduce osm_gps_map_track_new_with_data function
smartyg Oct 9, 2022
e8cdab8
osm-gps-map-osd: update code in osm_gps_map_osd_button_press function
smartyg Oct 9, 2022
9ebd778
update pkgconfig file to gtk4
smartyg Oct 9, 2022
b92f059
look for gtk-4.0 gir file
smartyg Oct 9, 2022
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
6 changes: 3 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ AM_PROG_LIBTOOL
AM_SILENT_RULES([yes])

# Library dependencies
PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.16])
PKG_CHECK_MODULES(GTK, [gtk+-3.0 >= 3.0])
PKG_CHECK_MODULES(CAIRO, [cairo >= 1.8])
PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.66])
PKG_CHECK_MODULES(GTK, [gtk4 >= 4.6])
PKG_CHECK_MODULES(CAIRO, [cairo >= 1.14])
PKG_CHECK_MODULES(SOUP24, [libsoup-2.4 >= 2.42])

# The mapviewer demo also calls g_thread_init, so it needs to link against
Expand Down
33 changes: 32 additions & 1 deletion examples/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Process this file with automake to produce Makefile.in

OSMGPSMAP_CFLAGS = \
-DGDK_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED \
$(GLIB_CFLAGS) \
$(GTK_CFLAGS) \
$(CAIRO_CFLAGS) \
Expand All @@ -13,7 +14,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 +63,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 <[email protected]>
*
* 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 <[email protected]>
*
* 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;
}
2 changes: 1 addition & 1 deletion osmgpsmap-1.0.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ includedir=@includedir@
Name: @PACKAGE_NAME@
Description: Moving map widget using openstreet map data
Version: @PACKAGE_VERSION@
Requires: gtk+-3.0 libsoup-2.4 >= 2.42
Requires: gtk+-4.0 libsoup-2.4 >= 2.42
Libs: -L${libdir} -losmgpsmap-1.
Cflags: -I${includedir}/osmgpsmap-1.2
3 changes: 2 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ libosmgpsmap_1_0_la_CFLAGS = \
$(WARN_CFLAGS) \
$(DISABLE_DEPRECATED) \
$(OSMGPSMAP_CFLAGS) \
-DGDK_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED \
-DG_LOG_DOMAIN=\"OsmGpsMap\"

if OS_WIN32
Expand Down Expand Up @@ -83,7 +84,7 @@ if HAVE_INTROSPECTION
introspection_sources = $(sources_c) $(sources_public_h)

OsmGpsMap-1.0.gir: libosmgpsmap-1.0.la
OsmGpsMap_1_0_gir_INCLUDES = GObject-2.0 Gtk-3.0
OsmGpsMap_1_0_gir_INCLUDES = GObject-2.0 Gtk-4.0
OsmGpsMap_1_0_gir_CFLAGS = $(OSMGPSMAP_CFLAGS) -I$(srcdir) -I$(builddir)
OsmGpsMap_1_0_gir_LIBS = libosmgpsmap-1.0.la
OsmGpsMap_1_0_gir_FILES = $(introspection_sources)
Expand Down
4 changes: 2 additions & 2 deletions src/osm-gps-map-layer.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ osm_gps_map_layer_busy (OsmGpsMapLayer *self)
}

gboolean
osm_gps_map_layer_button_press (OsmGpsMapLayer *self, OsmGpsMap *map, GdkEventButton *event)
osm_gps_map_layer_button_press (OsmGpsMapLayer *self, OsmGpsMap *map, GtkGestureSingle *event, gint n_press, gdouble x, gdouble y, gpointer user_data)
{
return OSM_GPS_MAP_LAYER_GET_INTERFACE (self)->button_press (self, map, event);
return OSM_GPS_MAP_LAYER_GET_INTERFACE (self)->button_press (self, map, event, n_press, x, y, user_data);
}

10 changes: 7 additions & 3 deletions src/osm-gps-map-layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct _OsmGpsMapLayerIface {
void (*render) (OsmGpsMapLayer *self, OsmGpsMap *map);
void (*draw) (OsmGpsMapLayer *self, OsmGpsMap *map, cairo_t *cr);
gboolean (*busy) (OsmGpsMapLayer *self);
gboolean (*button_press) (OsmGpsMapLayer *self, OsmGpsMap *map, GdkEventButton *event);
gboolean (*button_press) (OsmGpsMapLayer *self, OsmGpsMap *map, GtkGestureSingle *event, gint n_press, gdouble x, gdouble y, gpointer user_data);
};

/**
Expand Down Expand Up @@ -99,14 +99,18 @@ gboolean osm_gps_map_layer_busy (OsmGpsMapLayer *self);
* osm_gps_map_layer_button_press:
* @self: (in): a #OsmGpsMapLayer object
* @map: (in): a #OsmGpsMap widget
* @event: (in): a #GdkEventButton event
* @event: (in): a GtkGestureSingle event
* @n_press: (in): How many touch/button presses happened with this one.
* @x: (in): The X coordinate, in widget allocation coordinates.
* @y: (in): The Y coordinate, in widget allocation coordinates.
* @user_data: (in): pointer to user data
*
* Handle button event
*
* Returns: whether even had been handled
* Since: 0.6.0
**/
gboolean osm_gps_map_layer_button_press (OsmGpsMapLayer *self, OsmGpsMap *map, GdkEventButton *event);
gboolean osm_gps_map_layer_button_press (OsmGpsMapLayer *self, OsmGpsMap *map, GtkGestureSingle *event, gint n_press, gdouble x, gdouble y, gpointer user_data);

G_END_DECLS

Expand Down
12 changes: 7 additions & 5 deletions src/osm-gps-map-osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ G_DEFINE_TYPE_WITH_CODE (OsmGpsMapOsd, osm_gps_map_osd, G_TYPE_OBJECT,
static void osm_gps_map_osd_render (OsmGpsMapLayer *osd, OsmGpsMap *map);
static void osm_gps_map_osd_draw (OsmGpsMapLayer *osd, OsmGpsMap *map, cairo_t *cr);
static gboolean osm_gps_map_osd_busy (OsmGpsMapLayer *osd);
static gboolean osm_gps_map_osd_button_press (OsmGpsMapLayer *osd, OsmGpsMap *map, GdkEventButton *event);
static gboolean osm_gps_map_osd_button_press (OsmGpsMapLayer *osd, OsmGpsMap *map, GtkGestureSingle *event, gint n_press, gdouble x_axis, gdouble y_axis, gpointer user_data);

static void scale_render (OsmGpsMapOsd *self, OsmGpsMap *map);
static void scale_draw (OsmGpsMapOsd *self, GtkAllocation *allocation, cairo_t *cr);
Expand Down Expand Up @@ -538,23 +538,25 @@ osm_gps_map_osd_busy (OsmGpsMapLayer *osd)
static gboolean
osm_gps_map_osd_button_press (OsmGpsMapLayer *osd,
OsmGpsMap *map,
GdkEventButton *event)
GtkGestureSingle *event, gint n_press, gdouble x_axis, gdouble y_axis, gpointer user_data)
{
gboolean handled = FALSE;
OsdControlPress_t but = OSD_NONE;
OsmGpsMapOsd *self;
OsmGpsMapOsdPrivate *priv;
GtkAllocation allocation;
guint state;

g_return_val_if_fail(OSM_GPS_MAP_IS_OSD(osd), FALSE);

self = OSM_GPS_MAP_OSD(osd);
priv = self->priv;
state = gtk_gesture_single_get_current_button (event);
gtk_widget_get_allocation(GTK_WIDGET(map), &allocation);

if ((event->button == 1) && (event->type == GDK_BUTTON_PRESS)) {
gint mx = event->x - priv->osd_x;
gint my = event->y - priv->osd_y;
if (state == 1) {
gint mx = (int)(x_axis) - priv->osd_x;
gint my = (int)(y_axis) - priv->osd_y;

if(priv->osd_x < 0)
mx -= (allocation.width - priv->osd_w);
Expand Down
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