return;
}
- gdouble x, y;
+ gint x, y;
x = priv->map->longitude_to_x(priv->map, longitude, priv->map->current_level->level);
y = priv->map->latitude_to_y(priv->map, latitude, priv->map->current_level->level);
ChamplainPoint* anchor = &priv->map->current_level->anchor;
clutter_container_foreach(CLUTTER_CONTAINER(layer), CLUTTER_CALLBACK(connect_marker_notify_cb), view);
}
+
+gboolean
+champlain_view_get_coords_from_event (ChamplainView *view, ClutterEvent *event, gdouble *lat, gdouble *lon)
+{
+ g_return_val_if_fail(CHAMPLAIN_IS_VIEW(view), FALSE);
+ g_return_val_if_fail(event, FALSE); // Apparently there isn't a more precise test
+
+ ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
+ guint x, y;
+
+ switch (clutter_event_type (event))
+ {
+ case CLUTTER_BUTTON_PRESS:
+ case CLUTTER_BUTTON_RELEASE:
+ {
+ ClutterButtonEvent *e = (ClutterButtonEvent*) event;
+ x = e->x;
+ y = e->y;
+ }
+ break;
+ case CLUTTER_SCROLL:
+ {
+ ClutterScrollEvent *e = (ClutterScrollEvent*) event;
+ x = e->x;
+ y = e->y;
+ }
+ break;
+ case CLUTTER_MOTION:
+ {
+ ClutterMotionEvent *e = (ClutterMotionEvent*) event;
+ x = e->x;
+ y = e->y;
+ }
+ break;
+ case CLUTTER_ENTER:
+ case CLUTTER_LEAVE:
+ {
+ ClutterCrossingEvent *e = (ClutterCrossingEvent*) event;
+ x = e->x;
+ y = e->y;
+ }
+ break;
+ default:
+ return FALSE;
+ }
+ if (lat)
+ *lat = viewport_get_latitude_at(priv, priv->viewport_size.y + y + priv->map->current_level->anchor.y);
+ if (lon)
+ *lon = viewport_get_longitude_at(priv, priv->viewport_size.x + x + priv->map->current_level->anchor.x);
+ return TRUE;
+}
static gboolean
montreal_click (ClutterActor *actor,
- ClutterEvent *event,
- gpointer user_data)
-{ g_print("Montreal was clicked!\n");
+ ClutterButtonEvent *event,
+ ChamplainView * view)
+{
+ g_print("Montreal was clicked!\n");
+ gdouble lat, lon;
+ if (champlain_view_get_coords_from_event (view, event, &lat, &lon))
+ g_print("%f, %f \n", lat, lon);
return TRUE;
}
static ClutterActor*
-create_marker_layer ()
+create_marker_layer (ChamplainView *view)
{
ClutterActor *layer, *marker;
g_signal_connect_after (marker,
"button-release-event",
G_CALLBACK (montreal_click),
- NULL);
+ view);
marker = champlain_marker_new_with_label("New York", "Sans 25", &white, NULL);
champlain_marker_set_position(CHAMPLAIN_MARKER(marker), 40.77, -73.98);
champlain_view_set_size (CHAMPLAIN_VIEW (actor), 800, 600);
- g_object_set(G_OBJECT(actor), "zoom-level", 5, NULL);
- layer = create_marker_layer();
+ layer = create_marker_layer(actor);
champlain_view_add_layer(CHAMPLAIN_VIEW (actor), layer);
clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor);
+ g_object_set (G_OBJECT (actor), "zoom-level", 12, NULL);
champlain_view_center_on(CHAMPLAIN_VIEW(actor), 45.466, -73.75);
clutter_actor_show (stage);