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 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867
|
/*
* Copyright (C) 2008 Pierre-Luc Beaudoin <pierre-luc@pierlux.com>
* Copyright (C) 2011-2013 Jiri Techet <techet@gmail.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-marker
* @short_description: Base class of libchamplain markers
*
* Markers represent points of interest on a map. Markers need to be
* placed on a layer (a #ChamplainMarkerLayer). Layers have to be added to a
* #champlainview for the markers to show on the map.
*
* A marker is nothing more than a regular #clutteractor. You can draw on
* it what ever you want. Set the marker's position
* on the map using #champlain_location_set_location. Don't forget to set the
* marker's pointer position using #clutter_actor_set_translation.
*
* This is a base class of all markers. libchamplain has a more evoluted
* type of markers with text and image support. See #ChamplainLabel for more details.
*/
#include "config.h"
#include "champlain-marker.h"
#include "champlain.h"
#include "champlain-defines.h"
#include "champlain-private.h"
#include "champlain-tile.h"
#include <clutter/clutter.h>
#include <glib.h>
#include <glib-object.h>
#include <cairo.h>
#include <math.h>
static ClutterColor SELECTED_COLOR = { 0x00, 0x33, 0xcc, 0xff };
static ClutterColor SELECTED_TEXT_COLOR = { 0xff, 0xff, 0xff, 0xff };
enum
{
/* normal signals */
BUTTON_PRESS_SIGNAL,
BUTTON_RELEASE_SIGNAL,
DRAG_MOTION_SIGNAL,
DRAG_FINISH_SIGNAL,
LAST_SIGNAL,
};
static guint signals[LAST_SIGNAL] = { 0, };
enum
{
PROP_0,
PROP_LONGITUDE,
PROP_LATITUDE,
PROP_SELECTED,
PROP_SELECTABLE,
PROP_DRAGGABLE,
};
/* static guint champlain_marker_signals[LAST_SIGNAL] = { 0, }; */
static void set_location (ChamplainLocation *location,
gdouble latitude,
gdouble longitude);
static gdouble get_latitude (ChamplainLocation *location);
static gdouble get_longitude (ChamplainLocation *location);
static void location_interface_init (ChamplainLocationIface *iface);
struct _ChamplainMarkerPrivate
{
gdouble lon;
gdouble lat;
gboolean selected;
gboolean selectable;
gboolean draggable;
gfloat click_x;
gfloat click_y;
gboolean moved;
};
G_DEFINE_TYPE_WITH_CODE (ChamplainMarker, champlain_marker, CLUTTER_TYPE_ACTOR,
G_ADD_PRIVATE (ChamplainMarker)
G_IMPLEMENT_INTERFACE (CHAMPLAIN_TYPE_LOCATION, location_interface_init))
/**
* champlain_marker_set_selection_color:
* @color: a #ClutterColor
*
* Changes the selection color, this is to ensure a better integration with
* the desktop, this is automatically done by GtkChamplainEmbed.
*
* Since: 0.10
*/
void
champlain_marker_set_selection_color (ClutterColor *color)
{
SELECTED_COLOR.red = color->red;
SELECTED_COLOR.green = color->green;
SELECTED_COLOR.blue = color->blue;
SELECTED_COLOR.alpha = color->alpha;
}
/**
* champlain_marker_get_selection_color:
*
* Gets the selection color.
*
* Returns: the selection color. Should not be freed.
*
* Since: 0.10
*/
const ClutterColor *
champlain_marker_get_selection_color ()
{
return &SELECTED_COLOR;
}
/**
* champlain_marker_set_selection_text_color:
* @color: a #ClutterColor
*
* Changes the selection text color, this is to ensure a better integration with
* the desktop, this is automatically done by GtkChamplainEmbed.
*
* Since: 0.10
*/
void
champlain_marker_set_selection_text_color (ClutterColor *color)
{
SELECTED_TEXT_COLOR.red = color->red;
SELECTED_TEXT_COLOR.green = color->green;
SELECTED_TEXT_COLOR.blue = color->blue;
SELECTED_TEXT_COLOR.alpha = color->alpha;
}
/**
* champlain_marker_get_selection_text_color:
*
* Gets the selection text color.
*
* Returns: the selection text color. Should not be freed.
*
* Since: 0.10
*/
const ClutterColor *
champlain_marker_get_selection_text_color ()
{
return &SELECTED_TEXT_COLOR;
}
static void
champlain_marker_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
ChamplainMarker *marker = CHAMPLAIN_MARKER (object);
ChamplainMarkerPrivate *priv = marker->priv;
switch (prop_id)
{
case PROP_LONGITUDE:
g_value_set_double (value, priv->lon);
break;
case PROP_LATITUDE:
g_value_set_double (value, priv->lat);
break;
case PROP_SELECTED:
g_value_set_boolean (value, priv->selected);
break;
case PROP_SELECTABLE:
g_value_set_boolean (value, priv->selectable);
break;
case PROP_DRAGGABLE:
g_value_set_boolean (value, priv->draggable);
break;
default:
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)
{
ChamplainMarker *marker = CHAMPLAIN_MARKER (object);
ChamplainMarkerPrivate *priv = marker->priv;
switch (prop_id)
{
case PROP_LONGITUDE:
{
gdouble lon = g_value_get_double (value);
set_location (CHAMPLAIN_LOCATION (marker), priv->lat, lon);
break;
}
case PROP_LATITUDE:
{
gdouble lat = g_value_get_double (value);
set_location (CHAMPLAIN_LOCATION (marker), lat, priv->lon);
break;
}
case PROP_SELECTED:
{
gboolean bvalue = g_value_get_boolean (value);
champlain_marker_set_selected (marker, bvalue);
break;
}
case PROP_SELECTABLE:
{
gboolean bvalue = g_value_get_boolean (value);
champlain_marker_set_selectable (marker, bvalue);
break;
}
case PROP_DRAGGABLE:
{
gboolean bvalue = g_value_get_boolean (value);
champlain_marker_set_draggable (marker, bvalue);
break;
}
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
set_location (ChamplainLocation *location,
gdouble latitude,
gdouble longitude)
{
g_return_if_fail (CHAMPLAIN_IS_MARKER (location));
ChamplainMarkerPrivate *priv = CHAMPLAIN_MARKER (location)->priv;
priv->lon = CLAMP (longitude, CHAMPLAIN_MIN_LONGITUDE, CHAMPLAIN_MAX_LONGITUDE);
priv->lat = CLAMP (latitude, CHAMPLAIN_MIN_LATITUDE, CHAMPLAIN_MAX_LATITUDE);
g_object_notify (G_OBJECT (location), "latitude");
g_object_notify (G_OBJECT (location), "longitude");
}
static gdouble
get_latitude (ChamplainLocation *location)
{
g_return_val_if_fail (CHAMPLAIN_IS_MARKER (location), 0.0);
ChamplainMarkerPrivate *priv = CHAMPLAIN_MARKER (location)->priv;
return priv->lat;
}
static gdouble
get_longitude (ChamplainLocation *location)
{
g_return_val_if_fail (CHAMPLAIN_IS_MARKER (location), 0.0);
ChamplainMarkerPrivate *priv = CHAMPLAIN_MARKER (location)->priv;
return priv->lon;
}
static void
location_interface_init (ChamplainLocationIface *iface)
{
iface->get_latitude = get_latitude;
iface->get_longitude = get_longitude;
iface->set_location = set_location;
}
static void
champlain_marker_dispose (GObject *object)
{
G_OBJECT_CLASS (champlain_marker_parent_class)->dispose (object);
}
static void
champlain_marker_finalize (GObject *object)
{
G_OBJECT_CLASS (champlain_marker_parent_class)->finalize (object);
}
static void
champlain_marker_class_init (ChamplainMarkerClass *marker_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (marker_class);
object_class->finalize = champlain_marker_finalize;
object_class->dispose = champlain_marker_dispose;
object_class->get_property = champlain_marker_get_property;
object_class->set_property = champlain_marker_set_property;
/**
* ChamplainMarker:selected:
*
* The selected state of the marker
*
* Since: 0.10
*/
g_object_class_install_property (object_class, PROP_SELECTED,
g_param_spec_boolean ("selected",
"Selected",
"The sighlighted state of the marker",
FALSE,
CHAMPLAIN_PARAM_READWRITE));
/**
* ChamplainMarker:selectable:
*
* The selectable state of the marker
*
* Since: 0.10
*/
g_object_class_install_property (object_class, PROP_SELECTABLE,
g_param_spec_boolean ("selectable",
"Selectable",
"The draggable state of the marker",
FALSE,
CHAMPLAIN_PARAM_READWRITE));
/**
* ChamplainMarker:draggable:
*
* The draggable state of the marker
*
* Since: 0.10
*/
g_object_class_install_property (object_class, PROP_DRAGGABLE,
g_param_spec_boolean ("draggable",
"Draggable",
"The draggable state of the marker",
FALSE,
CHAMPLAIN_PARAM_READWRITE));
/**
* ChamplainMarker::button-press:
* @self: a #ChamplainMarker
* @event: the underlying ClutterEvent
*
* Emitted when button is pressed.
*
* Since: 0.10
*/
signals[BUTTON_PRESS_SIGNAL] =
g_signal_new ("button-press",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
NULL,
G_TYPE_NONE,
1,
CLUTTER_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
/**
* ChamplainMarker::button-release:
* @self: a #ChamplainMarker
* @event: the underlying ClutterEvent
*
* Emitted when button is released. This signal is not emmitted at the end of dragging.
*
* Since: 0.10
*/
signals[BUTTON_RELEASE_SIGNAL] =
g_signal_new ("button-release",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
NULL,
G_TYPE_NONE,
1,
CLUTTER_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
/**
* ChamplainMarker::drag-motion:
* @self: a #ChamplainMarker
* @dx: by how much the marker has been moved in the x direction
* @dy: by how much the marker has been moved in the y direction
* @event: the underlying ClutterEvent
*
* Emmitted when the marker is dragged by mouse. dx and dy specify by how much
* the marker has been dragged since last time.
*
* Since: 0.10
*/
signals[DRAG_MOTION_SIGNAL] =
g_signal_new ("drag-motion",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
NULL,
G_TYPE_NONE,
3,
G_TYPE_DOUBLE, G_TYPE_DOUBLE, CLUTTER_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
/**
* ChamplainMarker::drag-finish:
* @self: a #ChamplainMarker
* @event: the underlying ClutterEvent
*
* Emitted when marker dragging ends (i.e. the button is released at the end
* of dragging).
*
* Since: 0.10
*/
signals[DRAG_FINISH_SIGNAL] =
g_signal_new ("drag-finish",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
NULL,
G_TYPE_NONE,
1,
CLUTTER_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
g_object_class_override_property (object_class,
PROP_LONGITUDE,
"longitude");
g_object_class_override_property (object_class,
PROP_LATITUDE,
"latitude");
}
/**
* champlain_marker_new:
*
* Creates an instance of #ChamplainMarker.
*
* Returns: a new #ChamplainMarker.
*
* Since: 0.12.4
*/
ClutterActor *
champlain_marker_new (void)
{
return CLUTTER_ACTOR (g_object_new (CHAMPLAIN_TYPE_MARKER, NULL));
}
static gboolean
motion_event_cb (ClutterActor *stage,
ClutterMotionEvent *event,
ChamplainMarker *marker)
{
ChamplainMarkerPrivate *priv = marker->priv;
gfloat x, y;
if (event->type != CLUTTER_MOTION)
return FALSE;
if (clutter_actor_transform_stage_point (CLUTTER_ACTOR (marker),
event->x,
event->y,
&x, &y))
{
g_signal_emit_by_name (marker, "drag-motion",
x - priv->click_x, y - priv->click_y, event);
priv->moved = TRUE;
}
return TRUE;
}
static gboolean
capture_release_event_cb (ClutterActor *stage,
ClutterButtonEvent *event,
ChamplainMarker *marker)
{
ChamplainMarkerPrivate *priv = marker->priv;
if ((event->type != CLUTTER_BUTTON_RELEASE) ||
(event->button != 1))
return FALSE;
g_signal_handlers_disconnect_by_func (stage,
motion_event_cb,
marker);
g_signal_handlers_disconnect_by_func (stage,
capture_release_event_cb,
marker);
if (priv->moved)
g_signal_emit_by_name (marker, "drag-finish", event);
else
g_signal_emit_by_name (marker, "button-release", event);
return TRUE;
}
static gboolean
button_release_event_cb (ClutterActor *actor,
ClutterButtonEvent *event,
ChamplainMarker *marker)
{
if ((event->type != CLUTTER_BUTTON_RELEASE) ||
(event->button != 1))
return FALSE;
g_signal_handlers_disconnect_by_func (marker,
button_release_event_cb,
marker);
g_signal_emit_by_name (marker, "button-release", event);
return TRUE;
}
static gboolean
button_press_event_cb (ClutterActor *actor,
ClutterEvent *event,
ChamplainMarker *marker)
{
ChamplainMarkerPrivate *priv = marker->priv;
ClutterButtonEvent *bevent = (ClutterButtonEvent *) event;
ClutterActor *stage = clutter_actor_get_stage (actor);
if (event->type != CLUTTER_BUTTON_PRESS ||
bevent->button != 1 ||
!stage)
{
return FALSE;
}
if (priv->draggable)
{
if (clutter_actor_transform_stage_point (actor, bevent->x, bevent->y,
&priv->click_x, &priv->click_y))
{
priv->moved = FALSE;
g_signal_connect (stage,
"captured-event",
G_CALLBACK (motion_event_cb),
marker);
g_signal_connect (stage,
"captured-event",
G_CALLBACK (capture_release_event_cb),
marker);
}
}
else
{
g_signal_connect (marker,
"button-release-event",
G_CALLBACK (button_release_event_cb),
marker);
}
if (priv->selectable)
champlain_marker_set_selected (marker, TRUE);
if (priv->selectable || priv->draggable)
{
ClutterActor *parent;
parent = clutter_actor_get_parent (CLUTTER_ACTOR (marker));
clutter_actor_set_child_above_sibling (parent, CLUTTER_ACTOR (marker), NULL);
}
g_signal_emit_by_name (marker, "button-press", event);
return TRUE;
}
static void
champlain_marker_init (ChamplainMarker *marker)
{
ChamplainMarkerPrivate *priv = champlain_marker_get_instance_private (marker);
marker->priv = priv;
priv->lat = 0;
priv->lon = 0;
priv->selected = FALSE;
priv->selectable = TRUE;
priv->draggable = FALSE;
clutter_actor_set_reactive (CLUTTER_ACTOR (marker), TRUE);
g_signal_connect (marker,
"button-press-event",
G_CALLBACK (button_press_event_cb),
marker);
}
/**
* champlain_marker_set_selected:
* @marker: a #ChamplainMarker
* @value: the selected state
*
* Sets the marker as selected or not. This will affect the "Selected" look
* of the marker.
*
* Since: 0.10
*/
void
champlain_marker_set_selected (ChamplainMarker *marker,
gboolean value)
{
g_return_if_fail (CHAMPLAIN_IS_MARKER (marker));
marker->priv->selected = value;
g_object_notify (G_OBJECT (marker), "selected");
}
/**
* champlain_marker_get_selected:
* @marker: a #ChamplainMarker
*
* Checks whether the marker is selected.
*
* Returns: the selected or not state of the marker.
*
* Since: 0.10
*/
gboolean
champlain_marker_get_selected (ChamplainMarker *marker)
{
g_return_val_if_fail (CHAMPLAIN_IS_MARKER (marker), FALSE);
return marker->priv->selected;
}
/**
* champlain_marker_set_selectable:
* @marker: a #ChamplainMarker
* @value: the selectable state
*
* Sets the marker as selectable or not.
*
* Since: 0.10
*/
void
champlain_marker_set_selectable (ChamplainMarker *marker,
gboolean value)
{
g_return_if_fail (CHAMPLAIN_IS_MARKER (marker));
marker->priv->selectable = value;
g_object_notify (G_OBJECT (marker), "selectable");
}
/**
* champlain_marker_get_selectable:
* @marker: a #ChamplainMarker
*
* Checks whether the marker is selectable.
*
* Returns: the selectable or not state of the marker.
*
* Since: 0.10
*/
gboolean
champlain_marker_get_selectable (ChamplainMarker *marker)
{
g_return_val_if_fail (CHAMPLAIN_IS_MARKER (marker), FALSE);
return marker->priv->selectable;
}
/**
* champlain_marker_set_draggable:
* @marker: a #ChamplainMarker
* @value: the draggable state
*
* Sets the marker as draggable or not.
*
* Since: 0.10
*/
void
champlain_marker_set_draggable (ChamplainMarker *marker,
gboolean value)
{
g_return_if_fail (CHAMPLAIN_IS_MARKER (marker));
marker->priv->draggable = value;
g_object_notify (G_OBJECT (marker), "draggable");
}
/**
* champlain_marker_get_draggable:
* @marker: a #ChamplainMarker
*
* Checks whether the marker is draggable.
*
* Returns: the draggable or not state of the marker.
*
* Since: 0.10
*/
gboolean
champlain_marker_get_draggable (ChamplainMarker *marker)
{
g_return_val_if_fail (CHAMPLAIN_IS_MARKER (marker), FALSE);
return marker->priv->draggable;
}
/**
* champlain_marker_animate_in:
* @marker: a #ChamplainMarker
*
* Animates the marker as if it were falling from the sky onto the map.
*
* Since: 0.10
*/
void
champlain_marker_animate_in (ChamplainMarker *marker)
{
champlain_marker_animate_in_with_delay (marker, 0);
}
/**
* champlain_marker_animate_in_with_delay :
* @marker: a #ChamplainMarker
* @delay: The delay in milliseconds
*
* Animates the marker as if it were falling from the sky onto the map after
* delay.
*
* Since: 0.10
*/
void
champlain_marker_animate_in_with_delay (ChamplainMarker *marker,
guint delay)
{
gfloat y;
g_return_if_fail (CHAMPLAIN_IS_MARKER (marker));
clutter_actor_show (CLUTTER_ACTOR (marker));
clutter_actor_set_opacity (CLUTTER_ACTOR (marker), 0);
clutter_actor_set_scale (CLUTTER_ACTOR (marker), 1.5, 1.5);
clutter_actor_get_position (CLUTTER_ACTOR (marker), NULL, &y);
clutter_actor_move_by (CLUTTER_ACTOR (marker), 0, -100);
clutter_actor_save_easing_state (CLUTTER_ACTOR (marker));
clutter_actor_set_easing_delay (CLUTTER_ACTOR (marker), delay);
clutter_actor_set_easing_mode (CLUTTER_ACTOR (marker), CLUTTER_EASE_OUT_BOUNCE);
clutter_actor_set_easing_duration (CLUTTER_ACTOR (marker), 1000);
clutter_actor_set_opacity (CLUTTER_ACTOR (marker), 255);
clutter_actor_set_scale (CLUTTER_ACTOR (marker), 1.0, 1.0);
clutter_actor_set_y (CLUTTER_ACTOR (marker), y);
clutter_actor_restore_easing_state (CLUTTER_ACTOR (marker));
}
/**
* champlain_marker_animate_out:
* @marker: a #ChamplainMarker
*
* Animates the marker as if it were drawn through the sky.
*
* Since: 0.10
*/
void
champlain_marker_animate_out (ChamplainMarker *marker)
{
champlain_marker_animate_out_with_delay (marker, 0);
}
static void
on_transition_stopped (ClutterActor *marker,
const gchar *transition_name,
gboolean is_finished)
{
clutter_actor_hide (marker);
clutter_actor_move_by (marker, 0, 100);
g_signal_handlers_disconnect_by_func (marker, on_transition_stopped, NULL);
}
/**
* champlain_marker_animate_out_with_delay :
* @marker: a #ChamplainMarker
* @delay: The delay in milliseconds
*
* Animates the marker as if it were drawn through the sky after
* delay.
*
* Since: 0.10
*/
void
champlain_marker_animate_out_with_delay (ChamplainMarker *marker,
guint delay)
{
gfloat y;
g_return_if_fail (CHAMPLAIN_IS_MARKER (marker));
clutter_actor_get_position (CLUTTER_ACTOR (marker), NULL, &y);
clutter_actor_set_opacity (CLUTTER_ACTOR (marker), 200);
clutter_actor_save_easing_state (CLUTTER_ACTOR (marker));
clutter_actor_set_easing_delay (CLUTTER_ACTOR (marker), delay);
clutter_actor_set_easing_mode (CLUTTER_ACTOR (marker), CLUTTER_EASE_IN_BACK);
clutter_actor_set_easing_duration (CLUTTER_ACTOR (marker), 750);
clutter_actor_set_opacity (CLUTTER_ACTOR (marker), 0);
clutter_actor_set_scale (CLUTTER_ACTOR (marker), 2.0, 2.0);
clutter_actor_set_y (CLUTTER_ACTOR (marker), y - 100);
clutter_actor_restore_easing_state (CLUTTER_ACTOR (marker));
g_signal_connect (CLUTTER_ACTOR (marker),
"transition-stopped::opacity",
G_CALLBACK (on_transition_stopped),
NULL);
}
|