G_DEFINE_TYPE (ChamplainMarker, champlain_marker, CLUTTER_TYPE_GROUP);
static void
-champlain_marker_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+champlain_marker_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- ChamplainMarker *marker = CHAMPLAIN_MARKER(object);
+ ChamplainMarker *marker = CHAMPLAIN_MARKER (object);
ChamplainMarkerPrivate *priv = CHAMPLAIN_MARKER_GET_PRIVATE (marker);
- switch(prop_id)
+ switch (prop_id)
{
case PROP_LONGITUDE:
- g_value_set_double(value, priv->lon);
+ g_value_set_double (value, priv->lon);
break;
case PROP_LATITUDE:
- g_value_set_double(value, priv->lat);
+ g_value_set_double (value, priv->lat);
break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
-champlain_marker_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+champlain_marker_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- ChamplainMarker *marker = CHAMPLAIN_MARKER(object);
+ ChamplainMarker *marker = CHAMPLAIN_MARKER (object);
ChamplainMarkerPrivate *priv = CHAMPLAIN_MARKER_GET_PRIVATE (marker);
- switch(prop_id)
+ switch (prop_id)
{
case PROP_LONGITUDE:
{
- gdouble lon = g_value_get_double(value);
- champlain_marker_set_position(marker, lon, priv->lat);
+ gdouble lon = g_value_get_double (value);
+ champlain_marker_set_position (marker, lon, priv->lat);
break;
}
case PROP_LATITUDE:
{
- gdouble lat = g_value_get_double(value);
- champlain_marker_set_position(marker, priv->lon, lat);
+ gdouble lat = g_value_get_double (value);
+ champlain_marker_set_position (marker, priv->lon, lat);
break;
}
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
*
* Since: 0.2
*/
- g_object_class_install_property(object_class, PROP_LONGITUDE,
- g_param_spec_double("longitude",
+ g_object_class_install_property (object_class, PROP_LONGITUDE,
+ g_param_spec_double ("longitude",
"Longitude",
"The longitude coordonate of the marker",
-180.0f,
*
* Since: 0.2
*/
- g_object_class_install_property(object_class, PROP_LATITUDE,
- g_param_spec_double("latitude",
+ g_object_class_install_property (object_class, PROP_LATITUDE,
+ g_param_spec_double ("latitude",
"Latitude",
"The latitude coordonate of the marker",
-90.0f,
void
champlain_marker_set_position (ChamplainMarker *champlainMarker, gdouble latitude, gdouble longitude)
{
- g_return_if_fail(CHAMPLAIN_IS_MARKER(champlainMarker));
+ g_return_if_fail (CHAMPLAIN_IS_MARKER (champlainMarker));
ChamplainMarkerPrivate *priv = CHAMPLAIN_MARKER_GET_PRIVATE (champlainMarker);
priv->lon = longitude;
priv->lat = latitude;
- g_object_notify(G_OBJECT(champlainMarker), "latitude");
- g_object_notify(G_OBJECT(champlainMarker), "longitude");
+ g_object_notify (G_OBJECT (champlainMarker), "latitude");
+ g_object_notify (G_OBJECT (champlainMarker), "longitude");
}
/**
ClutterColor *text_color,
ClutterColor *marker_color)
{
- ChamplainMarker *champlainMarker = CHAMPLAIN_MARKER(champlain_marker_new ());
+ ChamplainMarker *champlainMarker = CHAMPLAIN_MARKER (champlain_marker_new ());
ClutterColor default_text_color = { 0x22, 022, 0x22, 0xFF },
default_marker_color = { 0x2A, 0xB1, 0x26, 0xEE },
darker_color;
clutter_actor_set_position (actor, padding, padding / 2.0);
text_width = clutter_actor_get_width (actor) + 2 * padding;
text_height = clutter_actor_get_height (actor)+ padding;
- clutter_label_set_color (CLUTTER_LABEL(actor), text_color);
- clutter_container_add_actor (CLUTTER_CONTAINER(champlainMarker), actor);
+ clutter_label_set_color (CLUTTER_LABEL (actor), text_color);
+ clutter_container_add_actor (CLUTTER_CONTAINER (champlainMarker), actor);
point = (text_height + 2 * padding) / 4.0;
cairo_destroy (cr);
- clutter_container_add_actor (CLUTTER_CONTAINER(champlainMarker), bg);
+ clutter_container_add_actor (CLUTTER_CONTAINER (champlainMarker), bg);
clutter_actor_raise (actor, bg);
- clutter_actor_set_anchor_point (CLUTTER_ACTOR(champlainMarker), 0, text_height + point);
+ clutter_actor_set_anchor_point (CLUTTER_ACTOR (champlainMarker), 0, text_height + point);
return CLUTTER_ACTOR (champlainMarker);
}
* champlain_marker_new_with_image:
* @filename: The filename of the image.
* @error: Return location for an error.
- *
- * Returns a new #ChamplainMarker with a drawn marker containing the given image.
+ *
+ * Returns a new #ChamplainMarker with a drawn marker containing the given
+ * image.
*
*/
ClutterActor *
-champlain_marker_new_with_image(const gchar *filename, GError **error)
+champlain_marker_new_with_image (const gchar *filename, GError **error)
{
- if (filename == NULL)
- return NULL;
+ if (filename == NULL)
+ return NULL;
+
+ ChamplainMarker *champlainMarker = CHAMPLAIN_MARKER (champlain_marker_new ());
+ ClutterActor *actor = clutter_texture_new_from_file (filename, error);
- ChamplainMarker *champlainMarker = CHAMPLAIN_MARKER(champlain_marker_new ());
- ClutterActor *actor = clutter_texture_new_from_file(filename, error);
+ if (actor == NULL){
+ g_object_unref (G_OBJECT (champlainMarker));
+ return NULL;
+ }
- if (actor == NULL){
- g_object_unref(G_OBJECT(champlainMarker));
- return NULL;
- }
+ clutter_container_add_actor (CLUTTER_CONTAINER (champlainMarker), actor);
- clutter_container_add_actor (CLUTTER_CONTAINER(champlainMarker), actor);
-
- return CLUTTER_ACTOR (champlainMarker);
+ return CLUTTER_ACTOR (champlainMarker);
}
/**
* @anchor_y: Y coordinate of the anchor point.
* @error: Return location for an error.
*
- * Returns a new #ChamplainMarker with a drawn marker containing the given image.
+ * Returns a new #ChamplainMarker with a drawn marker containing the given
+ * image.
*
*/
ClutterActor *
-champlain_marker_new_with_image_full(const gchar *filename, gint width, gint height, gint anchor_x, gint anchor_y, GError **error)
+champlain_marker_new_with_image_full (const gchar *filename,
+ gint width,
+ gint height,
+ gint anchor_x,
+ gint anchor_y,
+ GError **error)
{
- if(filename == NULL)
- return NULL;
+ if (filename == NULL)
+ return NULL;
- ChamplainMarker *champlainMarker = CHAMPLAIN_MARKER(champlain_marker_new());
- ClutterActor *actor = clutter_texture_new_from_file(filename, error);
+ ChamplainMarker *champlainMarker = CHAMPLAIN_MARKER (champlain_marker_new ());
+ ClutterActor *actor = clutter_texture_new_from_file (filename, error);
- if(actor == NULL){
- g_object_unref(G_OBJECT(champlainMarker));
- return NULL;
- }
+ if (actor == NULL)
+ {
+ g_object_unref (G_OBJECT (champlainMarker));
+ return NULL;
+ }
- clutter_actor_set_size(actor, width, height);
+ clutter_actor_set_size (actor, width, height);
- clutter_container_add_actor(CLUTTER_CONTAINER(champlainMarker), actor);
- clutter_actor_set_anchor_point(CLUTTER_ACTOR(champlainMarker), anchor_x, anchor_y);
+ clutter_container_add_actor (CLUTTER_CONTAINER (champlainMarker), actor);
+ clutter_actor_set_anchor_point (CLUTTER_ACTOR (champlainMarker), anchor_x,
+ anchor_y);
- return CLUTTER_ACTOR(champlainMarker);
+ return CLUTTER_ACTOR (champlainMarker);
}
* offline mode).
*
* The button-press-event and button-release-event signals are emitted each
- * time a mouse button is pressed on the @view. Coordinates can be converted with
- * #champlain_view_get_coords_from_event.
+ * time a mouse button is pressed on the @view. Coordinates can be converted
+ * with #champlain_view_get_coords_from_event.
*/
#include "config.h"
#define PADDING 10
//static guint signals[LAST_SIGNAL] = { 0, };
-#define CHAMPLAIN_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), CHAMPLAIN_TYPE_VIEW, ChamplainViewPrivate))
+#define GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CHAMPLAIN_TYPE_VIEW, ChamplainViewPrivate))
+
struct _ChamplainViewPrivate
{
ClutterActor *stage;
ChamplainMapSource map_source;
- gint zoom_level; // only used when the zoom-level property is set before map is created
+ gint zoom_level; /* Only used when the zoom-level property is set before map
+ * is created */
- // Represents the (lat, lon) at the center of the viewport
+ /* Represents the (lat, lon) at the center of the viewport */
gdouble longitude;
gdouble latitude;
G_DEFINE_TYPE (ChamplainView, champlain_view, CLUTTER_TYPE_GROUP);
-static gdouble viewport_get_current_longitude(ChamplainViewPrivate *priv);
-static gdouble viewport_get_current_latitude(ChamplainViewPrivate *priv);
-static gdouble viewport_get_longitude_at(ChamplainViewPrivate *priv, gint x);
-static gdouble viewport_get_latitude_at(ChamplainViewPrivate *priv, gint y);
-static gboolean scroll_event (ClutterActor *actor, ClutterScrollEvent *event, ChamplainView *view);
+static gdouble viewport_get_current_longitude (ChamplainViewPrivate *priv);
+static gdouble viewport_get_current_latitude (ChamplainViewPrivate *priv);
+static gdouble viewport_get_longitude_at (ChamplainViewPrivate *priv, gint x);
+static gdouble viewport_get_latitude_at (ChamplainViewPrivate *priv, gint y);
+static gboolean scroll_event (ClutterActor *actor, ClutterScrollEvent *event,
+ ChamplainView *view);
static void marker_reposition_cb (ChamplainMarker *marker, ChamplainView *view);
static void layer_reposition_cb (ClutterActor *layer, ChamplainView *view);
static void marker_reposition (ChamplainView *view);
-static void create_initial_map(ChamplainView *view);
-static void resize_viewport(ChamplainView *view);
-static void champlain_view_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
-static void champlain_view_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
+static void create_initial_map (ChamplainView *view);
+static void resize_viewport (ChamplainView *view);
+static void champlain_view_get_property (GObject *object, guint prop_id,
+ GValue *value, GParamSpec *pspec);
+static void champlain_view_set_property (GObject *object, guint prop_id,
+ const GValue *value, GParamSpec *pspec);
static void champlain_view_finalize (GObject *object);
static void champlain_view_class_init (ChamplainViewClass *champlainViewClass);
static void champlain_view_init (ChamplainView *view);
-static void viewport_x_changed_cb(GObject *gobject, GParamSpec *arg1, ChamplainView *view);
-static void notify_marker_reposition_cb(ChamplainMarker *marker, GParamSpec *arg1, ChamplainView *view);
-static void layer_add_marker_cb (ClutterGroup *layer, ChamplainMarker *marker, ChamplainView *view);
-static void connect_marker_notify_cb (ChamplainMarker *marker, ChamplainView *view);
+static void viewport_x_changed_cb (GObject *gobject, GParamSpec *arg1,
+ ChamplainView *view);
+static void notify_marker_reposition_cb (ChamplainMarker *marker,
+ GParamSpec *arg1, ChamplainView *view);
+static void layer_add_marker_cb (ClutterGroup *layer, ChamplainMarker *marker,
+ ChamplainView *view);
+static void connect_marker_notify_cb (ChamplainMarker *marker,
+ ChamplainView *view);
static gboolean finger_scroll_button_press_cb (ClutterActor *actor,
ClutterButtonEvent *event, ChamplainView *view);
static void update_license (ChamplainView *view);
static void license_set_position (ChamplainView *view);
static gdouble
-viewport_get_longitude_at(ChamplainViewPrivate *priv, gint x)
+viewport_get_longitude_at (ChamplainViewPrivate *priv, gint x)
{
if (!priv->map)
return 0.0;
- return priv->map->x_to_longitude(priv->map, x, priv->map->current_level->level);
+ return priv->map->x_to_longitude (priv->map, x,
+ priv->map->current_level->level);
}
static gdouble
-viewport_get_current_longitude(ChamplainViewPrivate *priv)
+viewport_get_current_longitude (ChamplainViewPrivate *priv)
{
if (!priv->map)
return 0.0;
- return viewport_get_longitude_at(priv,
- priv->map->current_level->anchor.x + priv->viewport_size.x + priv->viewport_size.width / 2.0);
+ return viewport_get_longitude_at (priv, priv->map->current_level->anchor.x +
+ priv->viewport_size.x + priv->viewport_size.width / 2.0);
}
static gdouble
-viewport_get_latitude_at(ChamplainViewPrivate *priv, gint y)
+viewport_get_latitude_at (ChamplainViewPrivate *priv, gint y)
{
if (!priv->map)
return 0.0;
- return priv->map->y_to_latitude(priv->map, y, priv->map->current_level->level);
+ return priv->map->y_to_latitude (priv->map, y,
+ priv->map->current_level->level);
}
static gdouble
-viewport_get_current_latitude(ChamplainViewPrivate *priv)
+viewport_get_current_latitude (ChamplainViewPrivate *priv)
{
if (!priv->map)
return 0.0;
- return viewport_get_latitude_at(priv,
- priv->map->current_level->anchor.y + priv->viewport_size.y + priv->viewport_size.height / 2.0);
+ return viewport_get_latitude_at (priv,
+ priv->map->current_level->anchor.y + priv->viewport_size.y +
+ priv->viewport_size.height / 2.0);
}
static gboolean
scroll_event (ClutterActor *actor, ClutterScrollEvent *event, ChamplainView *view)
{
- ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
+ ChamplainViewPrivate *priv = GET_PRIVATE (view);
ClutterActor *group = priv->map->current_level->group;
gboolean success = FALSE;
// Keep the lon, lat where the mouse is
- gdouble lon = viewport_get_longitude_at(priv,
+ gdouble lon = viewport_get_longitude_at (priv,
priv->viewport_size.x + event->x + priv->map->current_level->anchor.x);
- gdouble lat = viewport_get_latitude_at(priv,
+ gdouble lat = viewport_get_latitude_at (priv,
priv->viewport_size.y + event->y + priv->map->current_level->anchor.y);
// How far was it from the center of the viewport (in px)
gint y_diff = priv->viewport_size.height / 2 - event->y;
if (event->direction == CLUTTER_SCROLL_UP)
- success = map_zoom_in(priv->map);
- else if (event->direction == CLUTTER_SCROLL_DOWN)
- success = map_zoom_out(priv->map);
+ success = map_zoom_in (priv->map);
+ else if (event->direction == CLUTTER_SCROLL_DOWN)
+ success = map_zoom_out (priv->map);
if (success)
{
- // Get the new x,y in the new zoom level
- gint x2 = priv->map->longitude_to_x(priv->map, lon, priv->map->current_level->level);
- gint y2 = priv->map->latitude_to_y(priv->map, lat, priv->map->current_level->level);
- // Get the new lon,lat of these new x,y minus the distance from the viewport center
- gdouble lon2 = priv->map->x_to_longitude(priv->map, x2 + x_diff, priv->map->current_level->level);
- gdouble lat2 = priv->map->y_to_latitude(priv->map, y2 + y_diff, priv->map->current_level->level);
-
- resize_viewport(view);
- clutter_container_remove_actor (CLUTTER_CONTAINER (priv->map_layer), group);
- clutter_container_add_actor (CLUTTER_CONTAINER (priv->map_layer), priv->map->current_level->group);
- champlain_view_center_on(view, lat2, lon2);
-
- g_object_notify(G_OBJECT(view), "zoom-level");
+ /* Get the new x,y in the new zoom level */
+ gint x2 = priv->map->longitude_to_x (priv->map, lon,
+ priv->map->current_level->level);
+ gint y2 = priv->map->latitude_to_y (priv->map, lat,
+ priv->map->current_level->level);
+ /* Get the new lon,lat of these new x,y minus the distance from the
+ * viewport center */
+ gdouble lon2 = priv->map->x_to_longitude (priv->map, x2 + x_diff,
+ priv->map->current_level->level);
+ gdouble lat2 = priv->map->y_to_latitude (priv->map, y2 + y_diff,
+ priv->map->current_level->level);
+
+ resize_viewport (view);
+ clutter_container_remove_actor (CLUTTER_CONTAINER (priv->map_layer),
+ group);
+ clutter_container_add_actor (CLUTTER_CONTAINER (priv->map_layer),
+ priv->map->current_level->group);
+ champlain_view_center_on (view, lat2, lon2);
+
+ g_object_notify (G_OBJECT (view), "zoom-level");
}
-
+
return success;
}
static void
-marker_reposition_cb (ChamplainMarker *marker, ChamplainView *view)
+marker_reposition_cb (ChamplainMarker *marker,
+ ChamplainView *view)
{
- ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
+ ChamplainViewPrivate *priv = GET_PRIVATE (view);
ChamplainMarkerPrivate *marker_priv = CHAMPLAIN_MARKER_GET_PRIVATE (marker);
gint x, y;
- if(priv->map)
+ if (priv->map)
{
- x = priv->map->longitude_to_x(priv->map, marker_priv->lon, priv->map->current_level->level);
- y = priv->map->latitude_to_y(priv->map, marker_priv->lat, priv->map->current_level->level);
+ x = priv->map->longitude_to_x (priv->map, marker_priv->lon, priv->map->current_level->level);
+ y = priv->map->latitude_to_y (priv->map, marker_priv->lat, priv->map->current_level->level);
- clutter_actor_set_position(CLUTTER_ACTOR(marker),
+ clutter_actor_set_position (CLUTTER_ACTOR (marker),
x - priv->map->current_level->anchor.x,
y - priv->map->current_level->anchor.y);
}
}
static void
-notify_marker_reposition_cb(ChamplainMarker *marker, GParamSpec *arg1, ChamplainView *view)
+notify_marker_reposition_cb (ChamplainMarker *marker,
+ GParamSpec *arg1,
+ ChamplainView *view)
{
- marker_reposition_cb(marker, view);
+ marker_reposition_cb (marker, view);
}
static void
-layer_add_marker_cb (ClutterGroup *layer, ChamplainMarker *marker, ChamplainView *view)
+layer_add_marker_cb (ClutterGroup *layer,
+ ChamplainMarker *marker,
+ ChamplainView *view)
{
- g_signal_connect (marker,
- "notify::longitude",
- G_CALLBACK (notify_marker_reposition_cb),
- view);
- marker_reposition(view);
+ g_signal_connect (marker, "notify::longitude",
+ G_CALLBACK (notify_marker_reposition_cb), view);
+
+ marker_reposition (view);
}
static void
-connect_marker_notify_cb (ChamplainMarker *marker, ChamplainView *view)
+connect_marker_notify_cb (ChamplainMarker *marker,
+ ChamplainView *view)
{
- g_signal_connect (marker,
- "notify::longitude",
- G_CALLBACK (notify_marker_reposition_cb),
- view);
+ g_signal_connect (marker, "notify::longitude",
+ G_CALLBACK (notify_marker_reposition_cb), view);
}
static void
-layer_reposition_cb (ClutterActor *layer, ChamplainView *view)
+layer_reposition_cb (ClutterActor *layer,
+ ChamplainView *view)
{
- clutter_container_foreach(CLUTTER_CONTAINER(layer), CLUTTER_CALLBACK(marker_reposition_cb), view);
+ clutter_container_foreach (CLUTTER_CONTAINER (layer),
+ CLUTTER_CALLBACK (marker_reposition_cb), view);
}
static void
marker_reposition (ChamplainView *view)
{
- ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
- clutter_container_foreach(CLUTTER_CONTAINER(priv->user_layers), CLUTTER_CALLBACK(layer_reposition_cb), view);
+ ChamplainViewPrivate *priv = GET_PRIVATE (view);
+ clutter_container_foreach (CLUTTER_CONTAINER (priv->user_layers),
+ CLUTTER_CALLBACK (layer_reposition_cb), view);
}
static void
-create_initial_map(ChamplainView *view)
+create_initial_map (ChamplainView *view)
{
- ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
- priv->map = map_new(priv->map_source);
- map_load_level(priv->map, priv->zoom_level);
- clutter_container_add_actor (CLUTTER_CONTAINER (priv->map_layer), priv->map->current_level->group);
+ ChamplainViewPrivate *priv = GET_PRIVATE (view);
+ priv->map = map_new (priv->map_source);
+ map_load_level (priv->map, priv->zoom_level);
+ clutter_container_add_actor (CLUTTER_CONTAINER (priv->map_layer),
+ priv->map->current_level->group);
- marker_reposition(view);
+ marker_reposition (view);
update_license (view);
- g_object_notify(G_OBJECT(view), "zoom-level");
- g_object_notify(G_OBJECT(view), "map-source");
+ g_object_notify (G_OBJECT (view), "zoom-level");
+ g_object_notify (G_OBJECT (view), "map-source");
}
static void
license_set_position (ChamplainView *view)
{
- ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
+ ChamplainViewPrivate *priv = GET_PRIVATE (view);
guint width, height;
if (!priv->license_actor)
return;
clutter_actor_get_size (priv->license_actor, &width, &height);
- clutter_actor_set_position (priv->license_actor, priv->viewport_size.width - PADDING - width, priv->viewport_size.height - PADDING - height);
+ clutter_actor_set_position (priv->license_actor, priv->viewport_size.width -
+ PADDING - width, priv->viewport_size.height - PADDING - height);
}
-
+
static void
-resize_viewport(ChamplainView *view)
+resize_viewport (ChamplainView *view)
{
gdouble lower, upper;
gboolean center = FALSE;
TidyAdjustment *hadjust, *vadjust;
- ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
+ ChamplainViewPrivate *priv = GET_PRIVATE (view);
- if(!priv->map)
+ if (!priv->map)
{
- create_initial_map(view);
+ create_initial_map (view);
center = TRUE;
}
clutter_actor_set_size (priv->finger_scroll, priv->viewport_size.width, priv->viewport_size.height);
- tidy_scrollable_get_adjustments (TIDY_SCROLLABLE (priv->viewport), &hadjust, &vadjust);
+ tidy_scrollable_get_adjustments (TIDY_SCROLLABLE (priv->viewport), &hadjust,
+ &vadjust);
if (priv->map->current_level->level < 8)
{
lower = -priv->viewport_size.width / 2.0;
- upper = zoom_level_get_width(priv->map->current_level) - priv->viewport_size.width / 2.0;
+ upper = zoom_level_get_width (priv->map->current_level) -
+ priv->viewport_size.width / 2.0;
}
else
{
upper = G_MAXINT16;
}
g_object_set (hadjust, "lower", lower, "upper", upper,
- "step-increment", 1.0, "elastic", TRUE, NULL);
+ "step-increment", 1.0, "elastic", TRUE, NULL);
if (priv->map->current_level->level < 8)
{
lower = -priv->viewport_size.height / 2.0;
- upper = zoom_level_get_height(priv->map->current_level) - priv->viewport_size.height / 2.0;
+ upper = zoom_level_get_height (priv->map->current_level) -
+ priv->viewport_size.height / 2.0;
}
else
{
if (center)
{
- champlain_view_center_on(view, priv->latitude, priv->longitude);
+ champlain_view_center_on (view, priv->latitude, priv->longitude);
}
}
static void
-champlain_view_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+champlain_view_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- ChamplainView *view = CHAMPLAIN_VIEW(object);
- ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
+ ChamplainView *view = CHAMPLAIN_VIEW (object);
+ ChamplainViewPrivate *priv = GET_PRIVATE (view);
- switch(prop_id)
+ switch (prop_id)
{
case PROP_LONGITUDE:
- g_value_set_double(value, viewport_get_current_longitude(priv));
+ g_value_set_double (value, viewport_get_current_longitude (priv));
break;
case PROP_LATITUDE:
- g_value_set_double(value, viewport_get_current_latitude(priv));
+ g_value_set_double (value, viewport_get_current_latitude (priv));
break;
case PROP_ZOOM_LEVEL:
{
if (priv->map)
{
- g_value_set_int(value, priv->map->current_level->level);
+ g_value_set_int (value, priv->map->current_level->level);
}
else
{
- g_value_set_int(value, 0);
+ g_value_set_int (value, 0);
}
break;
}
case PROP_MAP_SOURCE:
- g_value_set_int(value, priv->map_source);
+ g_value_set_int (value, priv->map_source);
break;
case PROP_OFFLINE:
- g_value_set_boolean(value, priv->offline);
+ g_value_set_boolean (value, priv->offline);
break;
case PROP_DECEL_RATE:
{
gdouble decel;
g_object_get (priv->finger_scroll, "decel-rate", decel, NULL);
- g_value_set_double(value, decel);
+ g_value_set_double (value, decel);
break;
}
case PROP_KEEP_CENTER_ON_RESIZE:
- g_value_set_boolean(value, priv->keep_center_on_resize);
+ g_value_set_boolean (value, priv->keep_center_on_resize);
break;
case PROP_SHOW_LICENSE:
- g_value_set_boolean(value, priv->show_license);
+ g_value_set_boolean (value, priv->show_license);
break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
-champlain_view_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+champlain_view_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
- ChamplainView *view = CHAMPLAIN_VIEW(object);
- ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
+ ChamplainView *view = CHAMPLAIN_VIEW (object);
+ ChamplainViewPrivate *priv = GET_PRIVATE (view);
- switch(prop_id)
+ switch (prop_id)
{
case PROP_LONGITUDE:
{
}
case PROP_ZOOM_LEVEL:
{
- gint level = g_value_get_int(value);
+ gint level = g_value_get_int (value);
if (priv->map)
{
if (level != priv->map->current_level->level)
{
ClutterActor *group = priv->map->current_level->group;
- if (map_zoom_to(priv->map, level))
+ if (map_zoom_to (priv->map, level))
{
- resize_viewport(view);
+ resize_viewport (view);
clutter_container_remove_actor (CLUTTER_CONTAINER (priv->map_layer), group);
clutter_container_add_actor (CLUTTER_CONTAINER (priv->map_layer), priv->map->current_level->group);
- champlain_view_center_on(view, priv->latitude, priv->longitude);
+ champlain_view_center_on (view, priv->latitude, priv->longitude);
}
}
}
}
case PROP_MAP_SOURCE:
{
- ChamplainMapSource source = g_value_get_int(value);
+ ChamplainMapSource source = g_value_get_int (value);
if (priv->map_source != source)
{
priv->map_source = source;
if (priv->map) {
guint currentLevel = priv->map->current_level->level;
- map_free(priv->map);
- priv->map = map_new(priv->map_source);
+ map_free (priv->map);
+ priv->map = map_new (priv->map_source);
// Keep same zoom level if the new map supports it
if (currentLevel > priv->map->zoom_levels)
{
currentLevel = priv->map->zoom_levels;
- g_object_notify(G_OBJECT(view), "zoom-level");
+ g_object_notify (G_OBJECT (view), "zoom-level");
}
- map_load_level(priv->map, currentLevel);
+ map_load_level (priv->map, currentLevel);
map_load_visible_tiles (priv->map, priv->viewport_size, priv->offline);
clutter_container_add_actor (CLUTTER_CONTAINER (priv->map_layer), priv->map->current_level->group);
update_license (view);
marker_reposition (view);
- champlain_view_center_on(view, priv->latitude, priv->longitude);
+ champlain_view_center_on (view, priv->latitude, priv->longitude);
}
}
break;
}
case PROP_OFFLINE:
- priv->offline = g_value_get_boolean(value);
+ priv->offline = g_value_get_boolean (value);
break;
case PROP_DECEL_RATE:
{
- gdouble decel = g_value_get_double(value);
+ gdouble decel = g_value_get_double (value);
g_object_set (priv->finger_scroll, "decel-rate", decel, NULL);
break;
}
case PROP_KEEP_CENTER_ON_RESIZE:
- priv->keep_center_on_resize = g_value_get_boolean(value);
+ priv->keep_center_on_resize = g_value_get_boolean (value);
break;
case PROP_SHOW_LICENSE:
- priv->show_license = g_value_get_boolean(value);
+ priv->show_license = g_value_get_boolean (value);
update_license (view);
break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
champlain_view_finalize (GObject *object)
{
//ChamplainView *view = CHAMPLAIN_VIEW (object);
- //ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
+ //ChamplainViewPrivate *priv = GET_PRIVATE (view);
G_OBJECT_CLASS (champlain_view_parent_class)->finalize (object);
}
*
* Since: 0.1
*/
- g_object_class_install_property(object_class, PROP_LONGITUDE,
- g_param_spec_float("longitude",
+ g_object_class_install_property (object_class, PROP_LONGITUDE,
+ g_param_spec_float ("longitude",
"Longitude",
"The longitude coordonate of the map",
-180.0f,
*
* Since: 0.1
*/
- g_object_class_install_property(object_class, PROP_LATITUDE,
- g_param_spec_float("latitude",
+ g_object_class_install_property (object_class, PROP_LATITUDE,
+ g_param_spec_float ("latitude",
"Latitude",
"The latitude coordonate of the map",
-90.0f,
*
* Since: 0.1
*/
- g_object_class_install_property(object_class, PROP_ZOOM_LEVEL,
- g_param_spec_int("zoom-level",
+ g_object_class_install_property (object_class, PROP_ZOOM_LEVEL,
+ g_param_spec_int ("zoom-level",
"Zoom level",
"The level of zoom of the map",
0,
*
* Since: 0.2
*/
- g_object_class_install_property(object_class, PROP_MAP_SOURCE,
- g_param_spec_int("map-source",
+ g_object_class_install_property (object_class, PROP_MAP_SOURCE,
+ g_param_spec_int ("map-source",
"Map source",
"The map source being displayed",
0,
*
* Since: 0.2
*/
- g_object_class_install_property(object_class, PROP_OFFLINE,
- g_param_spec_boolean("offline",
+ g_object_class_install_property (object_class, PROP_OFFLINE,
+ g_param_spec_boolean ("offline",
"Offline Mode",
"If viewer is in offline mode.",
FALSE,
static void
champlain_view_init (ChamplainView *view)
{
- ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
+ ChamplainViewPrivate *priv = GET_PRIVATE (view);
priv->map_source = CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP;
priv->zoom_level = 3;
}
static void
-viewport_x_changed_cb(GObject *gobject, GParamSpec *arg1, ChamplainView *view)
+viewport_x_changed_cb (GObject *gobject, GParamSpec *arg1, ChamplainView *view)
{
- ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
+ ChamplainViewPrivate *priv = GET_PRIVATE (view);
ChamplainPoint rect;
- tidy_viewport_get_origin(TIDY_VIEWPORT(priv->viewport), &rect.x, &rect.y, NULL);
+ tidy_viewport_get_origin (TIDY_VIEWPORT (priv->viewport), &rect.x, &rect.y, NULL);
if (rect.x == priv->viewport_size.x &&
rect.y == priv->viewport_size.y)
map_load_visible_tiles (priv->map, priv->viewport_size, priv->offline);
- g_object_notify(G_OBJECT(view), "longitude");
- g_object_notify(G_OBJECT(view), "latitude");
+ g_object_notify (G_OBJECT (view), "longitude");
+ g_object_notify (G_OBJECT (view), "latitude");
}
void
champlain_view_set_size (ChamplainView *view, guint width, guint height)
{
- g_return_if_fail(CHAMPLAIN_IS_VIEW(view));
+ g_return_if_fail (CHAMPLAIN_IS_VIEW (view));
- ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
+ ChamplainViewPrivate *priv = GET_PRIVATE (view);
gdouble lat, lon;
lat = priv->latitude;
resize_viewport (view);
if (priv->keep_center_on_resize)
- champlain_view_center_on(view, lat, lon);
+ champlain_view_center_on (view, lat, lon);
else
map_load_visible_tiles (priv->map, priv->viewport_size, priv->offline);
}
static void
update_license (ChamplainView *view)
{
- ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
+ ChamplainViewPrivate *priv = GET_PRIVATE (view);
if (priv->license_actor)
clutter_container_remove_actor (CLUTTER_CONTAINER (priv->stage), priv->license_actor);
finger_scroll_button_press_cb (ClutterActor *actor,
ClutterButtonEvent *event,
ChamplainView *view)
-{
- ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
+{
+ ChamplainViewPrivate *priv = GET_PRIVATE (view);
if (event->button == 1 && event->click_count == 2)
{
ClutterActor *group = priv->map->current_level->group;
// Keep the lon, lat where the mouse is
- gdouble lon = viewport_get_longitude_at(priv,
+ gdouble lon = viewport_get_longitude_at (priv,
priv->viewport_size.x + event->x + priv->map->current_level->anchor.x);
- gdouble lat = viewport_get_latitude_at(priv,
+ gdouble lat = viewport_get_latitude_at (priv,
priv->viewport_size.y + event->y + priv->map->current_level->anchor.y);
-
+
// How far was it from the center of the viewport (in px)
gint x_diff = priv->viewport_size.width / 2 - event->x;
gint y_diff = priv->viewport_size.height / 2 - event->y;
if (map_zoom_in (priv->map))
{
// Get the new x,y in the new zoom level
- gint x2 = priv->map->longitude_to_x(priv->map, lon, priv->map->current_level->level);
- gint y2 = priv->map->latitude_to_y(priv->map, lat, priv->map->current_level->level);
+ gint x2 = priv->map->longitude_to_x (priv->map, lon, priv->map->current_level->level);
+ gint y2 = priv->map->latitude_to_y (priv->map, lat, priv->map->current_level->level);
// Get the new lon,lat of these new x,y minus the distance from the viewport center
- gdouble lon2 = priv->map->x_to_longitude(priv->map, x2 + x_diff, priv->map->current_level->level);
- gdouble lat2 = priv->map->y_to_latitude(priv->map, y2 + y_diff, priv->map->current_level->level);
+ gdouble lon2 = priv->map->x_to_longitude (priv->map, x2 + x_diff, priv->map->current_level->level);
+ gdouble lat2 = priv->map->y_to_latitude (priv->map, y2 + y_diff, priv->map->current_level->level);
- resize_viewport(view);
+ resize_viewport (view);
clutter_container_remove_actor (CLUTTER_CONTAINER (priv->map_layer), group);
clutter_container_add_actor (CLUTTER_CONTAINER (priv->map_layer), priv->map->current_level->group);
- champlain_view_center_on(view, lat2, lon2);
+ champlain_view_center_on (view, lat2, lon2);
- g_object_notify(G_OBJECT(view), "zoom-level");
+ g_object_notify (G_OBJECT (view), "zoom-level");
}
champlain_view_center_on (view, lat, lon);
return TRUE;
ChamplainView *view;
view = CHAMPLAIN_VIEW (g_object_new (CHAMPLAIN_TYPE_VIEW, NULL));
- ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
+ ChamplainViewPrivate *priv = GET_PRIVATE (view);
priv->stage = clutter_group_new ();
// Setup finger scroll
TidyFingerScrollMode tidy_mode;
- switch(mode)
+ switch (mode)
{
case CHAMPLAIN_VIEW_MODE_PUSH:
tidy_mode = TIDY_FINGER_SCROLL_MODE_PUSH;
break;
}
- priv->finger_scroll = tidy_finger_scroll_new(mode);
+ priv->finger_scroll = tidy_finger_scroll_new (mode);
g_signal_connect (priv->finger_scroll,
"scroll-event",
clutter_container_add_actor (CLUTTER_CONTAINER (view), priv->stage);
// Map Layer
- priv->map_layer = clutter_group_new();
- clutter_actor_show(priv->map_layer);
+ priv->map_layer = clutter_group_new ();
+ clutter_actor_show (priv->map_layer);
clutter_container_add_actor (CLUTTER_CONTAINER (priv->viewport), priv->map_layer);
g_signal_connect (priv->finger_scroll,
view);
// Setup user_layers
- priv->user_layers = clutter_group_new();
- clutter_actor_show(priv->user_layers);
+ priv->user_layers = clutter_group_new ();
+ clutter_actor_show (priv->user_layers);
clutter_container_add_actor (CLUTTER_CONTAINER (priv->viewport), priv->user_layers);
- clutter_actor_raise(priv->user_layers, priv->map_layer);
+ clutter_actor_raise (priv->user_layers, priv->map_layer);
return CLUTTER_ACTOR (view);
}
void
champlain_view_center_on (ChamplainView *view, gdouble latitude, gdouble longitude)
{
- g_return_if_fail(CHAMPLAIN_IS_VIEW(view));
+ g_return_if_fail (CHAMPLAIN_IS_VIEW (view));
- ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
+ ChamplainViewPrivate *priv = GET_PRIVATE (view);
priv->longitude = longitude;
priv->latitude = latitude;
- if(!priv->map)
+ if (!priv->map)
return;
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);
+ 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;
if (priv->map->current_level->level >= 8) {
if ( anchor->y < 0 )
anchor->y = 0;
- gdouble max = zoom_level_get_width(priv->map->current_level) - (G_MAXINT16 / 2);
+ gdouble max = zoom_level_get_width (priv->map->current_level) - (G_MAXINT16 / 2);
if (anchor->x > max)
anchor->x = max;
if (anchor->y > max)
guint i;
for (i = 0; i < priv->map->current_level->tiles->len; i++)
{
- Tile *tile = g_ptr_array_index(priv->map->current_level->tiles, i);
+ Tile *tile = g_ptr_array_index (priv->map->current_level->tiles, i);
if (!tile->loading)
- tile_set_position(priv->map, tile);
+ tile_set_position (priv->map, tile);
}
- tidy_viewport_set_origin(TIDY_VIEWPORT(priv->viewport),
+ tidy_viewport_set_origin (TIDY_VIEWPORT (priv->viewport),
x - priv->viewport_size.width / 2.0,
y - priv->viewport_size.height / 2.0,
0);
- g_object_notify(G_OBJECT(view), "longitude");
- g_object_notify(G_OBJECT(view), "latitude");
+ g_object_notify (G_OBJECT (view), "longitude");
+ g_object_notify (G_OBJECT (view), "latitude");
map_load_visible_tiles (priv->map, priv->viewport_size, priv->offline);
marker_reposition (view);
void
champlain_view_zoom_in (ChamplainView *view)
{
- g_return_if_fail(CHAMPLAIN_IS_VIEW(view));
+ g_return_if_fail (CHAMPLAIN_IS_VIEW (view));
- ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
+ ChamplainViewPrivate *priv = GET_PRIVATE (view);
ClutterActor *group = priv->map->current_level->group;
- if(map_zoom_in(priv->map))
+ if (map_zoom_in (priv->map))
{
- resize_viewport(view);
+ resize_viewport (view);
clutter_container_remove_actor (CLUTTER_CONTAINER (priv->map_layer), group);
clutter_container_add_actor (CLUTTER_CONTAINER (priv->map_layer), priv->map->current_level->group);
- champlain_view_center_on(view, priv->latitude, priv->longitude);
+ champlain_view_center_on (view, priv->latitude, priv->longitude);
- g_object_notify(G_OBJECT(view), "zoom-level");
+ g_object_notify (G_OBJECT (view), "zoom-level");
}
}
void
champlain_view_zoom_out (ChamplainView *view)
{
- g_return_if_fail(CHAMPLAIN_IS_VIEW(view));
+ g_return_if_fail (CHAMPLAIN_IS_VIEW (view));
- ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
+ ChamplainViewPrivate *priv = GET_PRIVATE (view);
ClutterActor *group = priv->map->current_level->group;
- if(map_zoom_out(priv->map))
+ if (map_zoom_out (priv->map))
{
- resize_viewport(view);
+ resize_viewport (view);
clutter_container_remove_actor (CLUTTER_CONTAINER (priv->map_layer), group);
clutter_container_add_actor (CLUTTER_CONTAINER (priv->map_layer), priv->map->current_level->group);
- champlain_view_center_on(view, priv->latitude, priv->longitude);
+ champlain_view_center_on (view, priv->latitude, priv->longitude);
- g_object_notify(G_OBJECT(view), "zoom-level");
+ g_object_notify (G_OBJECT (view), "zoom-level");
}
}
void
champlain_view_add_layer (ChamplainView *view, ClutterActor *layer)
{
- g_return_if_fail(CHAMPLAIN_IS_VIEW(view));
- g_return_if_fail(CLUTTER_IS_ACTOR(layer));
+ g_return_if_fail (CHAMPLAIN_IS_VIEW (view));
+ g_return_if_fail (CLUTTER_IS_ACTOR (layer));
- ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
- clutter_container_add(CLUTTER_CONTAINER(priv->user_layers), layer, NULL);
- clutter_actor_raise_top(layer);
+ ChamplainViewPrivate *priv = GET_PRIVATE (view);
+ clutter_container_add (CLUTTER_CONTAINER (priv->user_layers), layer, NULL);
+ clutter_actor_raise_top (layer);
- if(priv->map)
- marker_reposition(view);
+ if (priv->map)
+ marker_reposition (view);
g_signal_connect_after (layer,
"add",
G_CALLBACK (layer_add_marker_cb),
view);
- clutter_container_foreach(CLUTTER_CONTAINER(layer), CLUTTER_CALLBACK(connect_marker_notify_cb), view);
+ clutter_container_foreach (CLUTTER_CONTAINER (layer), CLUTTER_CALLBACK (connect_marker_notify_cb), view);
}
/**
gdouble *latitude,
gdouble *longitude)
{
- 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
+ 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);
+ ChamplainViewPrivate *priv = GET_PRIVATE (view);
guint x, y;
switch (clutter_event_type (event))