190
190
static void champlain_view_dispose (GObject *object);
191
191
static void champlain_view_class_init (ChamplainViewClass *champlainViewClass);
192
192
static void champlain_view_init (ChamplainView *view);
193
static void viewport_x_changed_cb (GObject *gobject, GParamSpec *arg1,
193
static void viewport_pos_changed_cb (GObject *gobject, GParamSpec *arg1,
194
194
ChamplainView *view);
195
195
static void notify_marker_reposition_cb (ChamplainMarker *marker,
196
196
GParamSpec *arg1, ChamplainView *view);
715
722
polygons = priv->polygons;
716
723
while (polygons != NULL)
718
ChamplainPolygon *polygon;
720
polygon = CHAMPLAIN_POLYGON (polygons->data);
725
g_object_unref (G_OBJECT (polygons->data));
721
726
polygons = polygons->next;
722
g_object_unref (polygon);
723
priv->polygons = g_list_remove (polygons, polygon);
728
g_list_free (priv->polygons);
729
priv->polygons = NULL;
726
731
if (priv->goto_context != NULL)
727
732
champlain_view_stop_go_to (view);
973
1002
g_object_set (G_OBJECT (priv->viewport), "sync-adjustments", FALSE, NULL);
975
1004
g_signal_connect (priv->viewport, "notify::x-origin",
976
G_CALLBACK (viewport_x_changed_cb), view);
1005
G_CALLBACK (viewport_pos_changed_cb), view);
1006
g_signal_connect (priv->viewport, "notify::y-origin",
1007
G_CALLBACK (viewport_pos_changed_cb), view);
978
1009
/* Setup finger scroll */
979
1010
priv->finger_scroll = g_object_ref (tidy_finger_scroll_new (priv->scroll_mode));
996
1027
g_signal_connect (priv->finger_scroll, "button-press-event",
997
1028
G_CALLBACK (finger_scroll_button_press_cb), view);
1029
g_signal_connect_after (priv->finger_scroll, "button-release-event",
1030
G_CALLBACK (button_release_cb), view);
1032
clutter_stage_set_key_focus (CLUTTER_STAGE (clutter_stage_get_default()),
1033
priv->finger_scroll);
1034
g_signal_connect (priv->finger_scroll, "key-press-event",
1035
G_CALLBACK (finger_scroll_key_press_cb), view);
999
1037
/* Setup user_layers */
1000
1038
priv->user_layers = g_object_ref (clutter_group_new ());
1048
1086
if (priv->anchor.x - old_anchor.x != 0)
1050
ChamplainIntPoint diff;
1088
ChamplainFloatPoint diff;
1052
1090
diff.x = priv->anchor.x - old_anchor.x;
1053
1091
diff.y = priv->anchor.y - old_anchor.y;
1055
DEBUG("Relocating the viewport by %d, %d", diff.x, diff.y);
1093
DEBUG("Relocating the viewport by %f, %f", diff.x, diff.y);
1056
1094
tidy_viewport_set_origin (TIDY_VIEWPORT (priv->viewport),
1057
1095
rect.x - diff.x, rect.y - diff.y, 0);
1073
1111
g_object_notify (G_OBJECT (view), "latitude");
1115
* champlain_view_set_size:
1116
* @view: a #ChamplainView
1117
* @width: the width in pixels
1118
* @height: the height in pixels
1120
* Sets the size of the view. This function will most probably be deprecated in
1121
* future versions in favor of #clutter_actor_set_size. In the mean time, you need
1076
1126
//FIXME: move to an handler of actor size change
1078
1128
champlain_view_set_size (ChamplainView *view,
1136
1186
return FALSE; /* Propagate the event */
1190
scroll_to (ChamplainView *view,
1195
ChamplainViewPrivate *priv = view->priv;
1197
if (priv->scroll_mode == CHAMPLAIN_SCROLL_MODE_KINETIC)
1201
lat = champlain_map_source_get_latitude (priv->map_source, priv->zoom_level, y);
1202
lon = champlain_map_source_get_longitude (priv->map_source, priv->zoom_level, x);
1204
champlain_view_go_to_with_duration (view, lat, lon, 300);
1206
else if (priv->scroll_mode == CHAMPLAIN_SCROLL_MODE_PUSH)
1208
tidy_viewport_set_origin (TIDY_VIEWPORT (priv->viewport),
1209
x - priv->viewport_size.width / 2.0,
1210
y - priv->viewport_size.height / 2.0,
1215
/* These functions should be exposed in the next API break */
1217
champlain_view_scroll_left (ChamplainView* view)
1219
g_return_if_fail (CHAMPLAIN_IS_VIEW (view));
1222
ChamplainViewPrivate *priv = view->priv;
1224
x = champlain_map_source_get_x (priv->map_source, priv->zoom_level, priv->longitude);
1225
y = champlain_map_source_get_y (priv->map_source, priv->zoom_level, priv->latitude);
1227
x -= priv->viewport_size.width / 4.0;
1229
scroll_to (view, x, y);
1233
champlain_view_scroll_right (ChamplainView* view)
1235
g_return_if_fail (CHAMPLAIN_IS_VIEW (view));
1238
ChamplainViewPrivate *priv = view->priv;
1240
x = champlain_map_source_get_x (priv->map_source, priv->zoom_level, priv->longitude);
1241
y = champlain_map_source_get_y (priv->map_source, priv->zoom_level, priv->latitude);
1243
x += priv->viewport_size.width / 4.0;
1245
scroll_to (view, x, y);
1249
champlain_view_scroll_up (ChamplainView* view)
1251
g_return_if_fail (CHAMPLAIN_IS_VIEW (view));
1254
ChamplainViewPrivate *priv = view->priv;
1256
x = champlain_map_source_get_x (priv->map_source, priv->zoom_level, priv->longitude);
1257
y = champlain_map_source_get_y (priv->map_source, priv->zoom_level, priv->latitude);
1259
y -= priv->viewport_size.width / 4.0;
1261
scroll_to (view, x, y);
1265
champlain_view_scroll_down (ChamplainView* view)
1267
g_return_if_fail (CHAMPLAIN_IS_VIEW (view));
1270
ChamplainViewPrivate *priv = view->priv;
1272
x = champlain_map_source_get_x (priv->map_source, priv->zoom_level, priv->longitude);
1273
y = champlain_map_source_get_y (priv->map_source, priv->zoom_level, priv->latitude);
1275
y += priv->viewport_size.width / 4.0;
1277
scroll_to (view, x, y);
1282
finger_scroll_key_press_cb (ClutterActor *actor,
1283
ClutterKeyEvent *event,
1284
ChamplainView *view)
1287
switch (event->keyval)
1290
champlain_view_scroll_left (view);
1294
if (event->modifier_state & CLUTTER_CONTROL_MASK)
1295
champlain_view_zoom_in (view);
1297
champlain_view_scroll_up (view);
1300
case 65363: // Right
1301
champlain_view_scroll_right (view);
1305
if (event->modifier_state & CLUTTER_CONTROL_MASK)
1306
champlain_view_zoom_out (view);
1308
champlain_view_scroll_down (view);
1312
return FALSE; /* Propagate the event */
1314
return FALSE; /* Propagate the event */
1140
1318
* champlain_view_new:
1141
* Returns a new #ChamplainView ready to be used as a #ClutterActor.
1320
* Returns: a new #ChamplainView ready to be used as a #ClutterActor.
1228
1410
x = champlain_map_source_get_x (priv->map_source, priv->zoom_level, longitude);
1229
1411
y = champlain_map_source_get_y (priv->map_source, priv->zoom_level, latitude);
1413
DEBUG ("Centering on %f, %f (%d, %d)", latitude, longitude, x, y);
1231
1415
view_update_anchor (view, x, y);
1233
1417
x -= priv->anchor.x;
1318
1502
gdouble latitude,
1319
1503
gdouble longitude)
1507
duration = 500 * view->priv->zoom_level / 2.0;
1508
champlain_view_go_to_with_duration (view, latitude, longitude, duration);
1511
/* FIXME: make public after API freeze */
1513
champlain_view_go_to_with_duration (ChamplainView *view,
1516
guint duration) /* In ms */
1321
1518
g_return_if_fail (CHAMPLAIN_IS_VIEW (view));
1522
champlain_view_center_on (view, latitude, longitude);
1324
1526
GoToContext *ctx;
1326
1528
ChamplainViewPrivate *priv = view->priv;
1345
1547
* To have a nice animation, the duration should be longer if the zoom level
1346
1548
* is higher and if the points are far away
1348
duration = 500 * priv->zoom_level / 2.0;
1349
ctx->timeline = clutter_timeline_new_for_duration (duration);
1350
ctx->alpha = clutter_alpha_new_full (ctx->timeline, CLUTTER_ALPHA_SINE_INC, NULL,
1550
ctx->timeline = clutter_timeline_new (duration);
1551
ctx->alpha = clutter_alpha_new_full (ctx->timeline, CLUTTER_EASE_IN_OUT_CIRC);
1353
1553
g_signal_connect (ctx->timeline, "new-frame", G_CALLBACK (timeline_new_frame),
1533
1735
* champlain_view_get_coords_from_event:
1534
1736
* @view: a #ChamplainView
1535
1737
* @event: a #ClutterEvent
1536
* @latitude: a variable where to put the latitude of the event
1537
* @longitude: a variable where to put the longitude of the event
1738
* @lat: a variable where to put the latitude of the event
1739
* @lon: a variable where to put the longitude of the event
1539
* Returns the latitude, longitude coordinates for the given ClutterEvent.
1741
* Returns: the latitude, longitude coordinates for the given ClutterEvent.
1596
1798
* @view: a #ChamplainView
1597
1799
* @x: the x position in the view
1598
1800
* @y: the y position in the view
1599
* @latitude: a variable where to put the latitude of the event
1600
* @longitude: a variable where to put the longitude of the event
1801
* @lat: a variable where to put the latitude of the event
1802
* @lon: a variable where to put the longitude of the event
1602
* Returns the latitude, longitude coordinates for the given x, y position in
1804
* Returns: the latitude, longitude coordinates for the given x, y position in
1603
1805
* the view. Use if you get coordinates from GtkEvents for example.