1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
|
/*
* Copyright (C) 2008 Pierre-Luc Beaudoin <pierre-luc@pierlux.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* SECTION:champlain-layer
* @short_description: A container for #ChamplainMarker
*
* A ChamplainLayer is little more than a #ClutterContainer. It keeps the
* markers ordered so that they display correctly.
*
* Use #clutter_container_add to add markers to the layer and
* #clutter_container_remove to remove them.
*/
#include "config.h"
#include "champlain-layer.h"
#include "champlain-defines.h"
#include "champlain-base-marker.h"
#include <clutter/clutter.h>
#include <glib.h>
G_DEFINE_TYPE (ChamplainLayer, champlain_layer, CLUTTER_TYPE_GROUP)
#define GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), CHAMPLAIN_TYPE_LAYER, ChamplainLayerPrivate))
enum
{
PROP_0
};
typedef struct _ChamplainLayerPrivate ChamplainLayerPrivate;
struct _ChamplainLayerPrivate {
gpointer spacer;
};
static void layer_add_cb (ClutterGroup *layer,
ClutterActor *marker,
gpointer data);
static void layer_remove_cb (ClutterGroup *layer,
ClutterActor *marker,
gpointer data);
static void
champlain_layer_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
//ChamplainLayer *self = CHAMPLAIN_LAYER (object);
switch (property_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
champlain_layer_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
//ChamplainLayer *self = CHAMPLAIN_LAYER (object);
switch (property_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
champlain_layer_class_init (ChamplainLayerClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (ChamplainLayerPrivate));
object_class->get_property = champlain_layer_get_property;
object_class->set_property = champlain_layer_set_property;
}
static void
champlain_layer_init (ChamplainLayer *self)
{
g_signal_connect_after (G_OBJECT (self), "actor-added",
G_CALLBACK (layer_add_cb), NULL);
g_signal_connect_after (G_OBJECT (self), "actor-removed",
G_CALLBACK (layer_remove_cb), NULL);
}
/* This callback serves to keep the markers ordered by their latitude.
* Markers that are up north on the map should be lowered in the list so that
* they are drawn the first. This is to make the illusion of a semi-3d plane
* where the most north you are, the farther you are.
*/
static void
reorder_marker (ClutterGroup *layer,
ChamplainBaseMarker *marker)
{
GList* markers = clutter_container_get_children (CLUTTER_CONTAINER(layer));
GList* it;
gdouble y, tmp_y, low_y;
ChamplainBaseMarker *lowest = NULL;
g_object_get (G_OBJECT (marker), "latitude", &y, NULL);
y = 90 - y;
low_y = G_MAXDOUBLE;
for (it = markers; it != NULL; it = it->next)
{
ChamplainBaseMarker *prev_marker = (ChamplainBaseMarker*) it->data;
if (prev_marker == (ChamplainBaseMarker*) marker)
continue;
g_object_get(G_OBJECT(prev_marker), "latitude", &tmp_y, NULL);
tmp_y = 90 - tmp_y;
if (y < tmp_y && tmp_y < low_y)
{
lowest = prev_marker;
low_y = tmp_y;
}
}
if (lowest)
clutter_container_lower_child (CLUTTER_CONTAINER(layer),
CLUTTER_ACTOR (marker), CLUTTER_ACTOR (lowest));
g_list_free (markers);
}
static void
marker_position_notify (GObject *gobject,
GParamSpec *pspec,
gpointer user_data)
{
reorder_marker (CLUTTER_GROUP (user_data), CHAMPLAIN_BASE_MARKER (gobject));
}
static void
layer_add_cb (ClutterGroup *layer,
ClutterActor *actor,
gpointer data)
{
ChamplainBaseMarker *marker = CHAMPLAIN_BASE_MARKER (actor);
reorder_marker (layer, marker);
g_signal_connect (G_OBJECT (marker), "notify::latitude",
G_CALLBACK (marker_position_notify), layer);
}
static void
layer_remove_cb (ClutterGroup *layer,
ClutterActor *actor,
gpointer data)
{
g_signal_handlers_disconnect_by_func (G_OBJECT (actor),
G_CALLBACK (marker_position_notify), layer);
}
/**
* champlain_layer_new:
*
* Returns: a new #ChamplainLayer ready to be used as a #ClutterContainer for the markers.
*
* Since: 0.2.2
*/
ChamplainLayer *
champlain_layer_new ()
{
return g_object_new (CHAMPLAIN_TYPE_LAYER, NULL);
}
/**
* champlain_layer_add_marker:
* @layer: a #ChamplainLayer
* @marker: a #ChamplainBaseMarker
*
* Adds the marker to the layer.
*
* Since: 0.4
*/
void
champlain_layer_add_marker (ChamplainLayer *layer,
ChamplainBaseMarker *marker)
{
g_return_if_fail (CHAMPLAIN_IS_LAYER (layer));
g_return_if_fail (CHAMPLAIN_IS_BASE_MARKER (marker));
clutter_container_add (CLUTTER_CONTAINER (layer), CLUTTER_ACTOR (marker), NULL);
}
/**
* champlain_layer_remove_marker:
* @layer: a #ChamplainLayer
* @marker: a #ChamplainBaseMarker
*
* Removes the marker from the layer.
*
* Since: 0.4
*/
void
champlain_layer_remove_marker (ChamplainLayer *layer,
ChamplainBaseMarker *marker)
{
g_return_if_fail (CHAMPLAIN_IS_LAYER (layer));
g_return_if_fail (CHAMPLAIN_IS_BASE_MARKER (marker));
clutter_container_remove (CLUTTER_CONTAINER (layer), CLUTTER_ACTOR (marker), NULL);
}
/**
* champlain_layer_show:
* @layer: a #ChamplainLayer
*
* Makes the layer and its markers visible.
*
* Since: 0.4
*/
void
champlain_layer_show (ChamplainLayer *layer)
{
g_return_if_fail (CHAMPLAIN_IS_LAYER (layer));
clutter_actor_show (CLUTTER_ACTOR (layer));
}
/**
* champlain_layer_hide:
* @layer: a #ChamplainLayer
*
* Makes the layer and its markers invisible.
*
* Since: 0.4
*/
void
champlain_layer_hide (ChamplainLayer *layer)
{
g_return_if_fail (CHAMPLAIN_IS_LAYER (layer));
clutter_actor_hide (CLUTTER_ACTOR (layer));
}
/**
* champlain_layer_animate_in_all_markers:
* @layer: a #ChamplainLayer
*
* Fade in all markers with an animation
*
* Since: 0.4
*/
void
champlain_layer_animate_in_all_markers (ChamplainLayer *layer)
{
GList *children, *child;
guint delay = 0;
g_return_if_fail (CHAMPLAIN_IS_LAYER (layer));
children = clutter_container_get_children (CLUTTER_CONTAINER (layer));
for (child = children; child != NULL; child = g_list_next (child))
{
champlain_base_marker_animate_in_with_delay (CHAMPLAIN_BASE_MARKER (child->data),
delay);
delay += 50;
}
g_list_free (children);
}
/**
* champlain_layer_animate_out_all_markers:
* @layer: a #ChamplainLayer
*
* Fade out all markers with an animation
*
* Since: 0.4
*/
void
champlain_layer_animate_out_all_markers (ChamplainLayer *layer)
{
GList *children, *child;
guint delay = 0;
g_return_if_fail (CHAMPLAIN_IS_LAYER (layer));
children = clutter_container_get_children (CLUTTER_CONTAINER (layer));
for (child = children; child != NULL; child = g_list_next (child))
{
champlain_base_marker_animate_out_with_delay (CHAMPLAIN_BASE_MARKER (child->data),
delay);
delay += 50;
}
g_list_free (children);
}
/**
* champlain_layer_show_all_markers:
* @layer: a #ChamplainLayer
*
* Calls clutter_actor_show on all markers
*
* Since: 0.4
*/
void
champlain_layer_show_all_markers (ChamplainLayer *layer)
{
GList *children, *child;
g_return_if_fail (CHAMPLAIN_IS_LAYER (layer));
children = clutter_container_get_children (CLUTTER_CONTAINER (layer));
for (child = children; child != NULL; child = g_list_next (child))
{
clutter_actor_show (CLUTTER_ACTOR (child->data));
}
g_list_free (children);
}
/**
* champlain_layer_hide_all_markers:
* @layer: a #ChamplainLayer
*
* Calls clutter_actor_hide on all markers
*
* Since: 0.4
*/
void
champlain_layer_hide_all_markers (ChamplainLayer *layer)
{
GList *children, *child;
g_return_if_fail (CHAMPLAIN_IS_LAYER (layer));
children = clutter_container_get_children (CLUTTER_CONTAINER (layer));
for (child = children; child != NULL; child = g_list_next (child))
{
clutter_actor_hide (CLUTTER_ACTOR (child->data));
}
g_list_free (children);
}
|