champlain-label.c 38.4 KB
Newer Older
1 2
/*
 * Copyright (C) 2008 Pierre-Luc Beaudoin <pierre-luc@pierlux.com>
Jiří Techet's avatar
Jiří Techet committed
3
 * Copyright (C) 2011-2013 Jiri Techet <techet@gmail.com>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * 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-label
 * @short_description: A label to identify points of interest on a map
 *
 * Markers reprensent points of interest on a map. Markers need to be placed on
25
 * a layer (a #ChamplainMarkerLayer).  Layers have to be added to a #ChamplainView for
26 27 28 29
 * 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 markers position on the map
30
 * using #champlain_location_set_location.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
 *
 * Champlain has a default type of markers with text. To create one,
 * use #champlain_label_new_with_text.
 */

#include "config.h"

#include "champlain-label.h"

#include "champlain.h"
#include "champlain-defines.h"
#include "champlain-private.h"
#include "champlain-tile.h"

#include <clutter/clutter.h>
46
#include <gdk-pixbuf/gdk-pixbuf.h>
47 48 49 50 51 52 53
#include <glib.h>
#include <glib-object.h>
#include <cairo.h>
#include <math.h>
#include <string.h>

#define DEFAULT_FONT_NAME "Sans 11"
54 55
#define SLOPE -0.3
#define SCALING 0.65
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

static ClutterColor DEFAULT_COLOR = { 0x33, 0x33, 0x33, 0xff };
static ClutterColor DEFAULT_TEXT_COLOR = { 0xee, 0xee, 0xee, 0xff };

enum
{
  /* normal signals */
  LAST_SIGNAL
};

enum
{
  PROP_0,
  PROP_IMAGE,
  PROP_TEXT,
  PROP_USE_MARKUP,
  PROP_ALIGNMENT,
  PROP_ATTRIBUTES,
  PROP_ELLIPSIZE,
  PROP_COLOR,
  PROP_TEXT_COLOR,
  PROP_FONT_NAME,
  PROP_WRAP,
  PROP_WRAP_MODE,
  PROP_SINGLE_LINE_MODE,
81 82
  PROP_DRAW_BACKGROUND,
  PROP_DRAW_SHADOW
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
};

/* static guint champlain_label_signals[LAST_SIGNAL] = { 0, }; */

struct _ChamplainLabelPrivate
{
  gchar *text;
  ClutterActor *image;
  gboolean use_markup;
  PangoAlignment alignment;
  PangoAttrList *attributes;
  ClutterColor *color;
  ClutterColor *text_color;
  gchar *font_name;
  gboolean wrap;
  PangoWrapMode wrap_mode;
  gboolean single_line_mode;
  PangoEllipsizeMode ellipsize;
  gboolean draw_background;
102
  gboolean draw_shadow;
103 104

  guint redraw_id;
105 106 107
  gint total_width;
  gint total_height;
  gint point;
108 109
};

110
G_DEFINE_TYPE_WITH_PRIVATE (ChamplainLabel, champlain_label, CHAMPLAIN_TYPE_MARKER)
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

static void draw_label (ChamplainLabel *label);


static void
champlain_label_get_property (GObject *object,
    guint prop_id,
    GValue *value,
    GParamSpec *pspec)
{
  ChamplainLabelPrivate *priv = CHAMPLAIN_LABEL (object)->priv;

  switch (prop_id)
    {
    case PROP_TEXT:
      g_value_set_string (value, priv->text);
      break;

    case PROP_IMAGE:
      g_value_set_object (value, priv->image);
      break;

    case PROP_USE_MARKUP:
      g_value_set_boolean (value, priv->use_markup);
      break;

    case PROP_ALIGNMENT:
      g_value_set_enum (value, priv->alignment);
      break;

    case PROP_COLOR:
      clutter_value_set_color (value, priv->color);
      break;

    case PROP_TEXT_COLOR:
      clutter_value_set_color (value, priv->text_color);
      break;

    case PROP_FONT_NAME:
      g_value_set_string (value, priv->font_name);
      break;

    case PROP_WRAP:
      g_value_set_boolean (value, priv->wrap);
      break;

    case PROP_WRAP_MODE:
      g_value_set_enum (value, priv->wrap_mode);
      break;

    case PROP_DRAW_BACKGROUND:
      g_value_set_boolean (value, priv->draw_background);
      break;

165 166 167 168
    case PROP_DRAW_SHADOW:
      g_value_set_boolean (value, priv->draw_shadow);
      break;

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
    case PROP_ELLIPSIZE:
      g_value_set_enum (value, priv->ellipsize);
      break;

    case PROP_SINGLE_LINE_MODE:
      g_value_set_enum (value, priv->single_line_mode);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}


static void
champlain_label_set_property (GObject *object,
    guint prop_id,
    const GValue *value,
    GParamSpec *pspec)
{
  ChamplainLabel *label = CHAMPLAIN_LABEL (object);

  switch (prop_id)
    {
    case PROP_TEXT:
      champlain_label_set_text (label, g_value_get_string (value));
      break;

    case PROP_IMAGE:
      champlain_label_set_image (label, g_value_get_object (value));
      break;

    case PROP_USE_MARKUP:
      champlain_label_set_use_markup (label, g_value_get_boolean (value));
      break;

    case PROP_ALIGNMENT:
      champlain_label_set_alignment (label, g_value_get_enum (value));
      break;

    case PROP_COLOR:
      champlain_label_set_color (label, clutter_value_get_color (value));
      break;

    case PROP_TEXT_COLOR:
      champlain_label_set_text_color (label, clutter_value_get_color (value));
      break;

    case PROP_FONT_NAME:
      champlain_label_set_font_name (label, g_value_get_string (value));
      break;

    case PROP_WRAP:
      champlain_label_set_wrap (label, g_value_get_boolean (value));
      break;

    case PROP_WRAP_MODE:
      champlain_label_set_wrap_mode (label, g_value_get_enum (value));
      break;

    case PROP_ELLIPSIZE:
      champlain_label_set_ellipsize (label, g_value_get_enum (value));
      break;

    case PROP_DRAW_BACKGROUND:
      champlain_label_set_draw_background (label, g_value_get_boolean (value));
      break;

237 238 239 240
    case PROP_DRAW_SHADOW:
      champlain_label_set_draw_shadow (label, g_value_get_boolean (value));
      break;

241 242 243 244 245 246 247 248 249 250
    case PROP_SINGLE_LINE_MODE:
      champlain_label_set_single_line_mode (label, g_value_get_boolean (value));
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}


251 252 253
#define RADIUS 10
#define PADDING (RADIUS / 2)

254
static void
Jiří Techet's avatar
Jiří Techet committed
255
pick (ClutterActor *self,
256 257
    const ClutterColor *color)
{
258
  ChamplainLabelPrivate *priv = CHAMPLAIN_LABEL (self)->priv;
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
  gfloat width, height;

  if (!clutter_actor_should_pick_paint (self))
    return;

  width = priv->total_width;
  height = priv->total_height;

  cogl_path_new ();

  cogl_set_source_color4ub (color->red,
      color->green,
      color->blue,
      color->alpha);

  cogl_path_move_to (RADIUS, 0);
  cogl_path_line_to (width - RADIUS, 0);
  cogl_path_arc (width - RADIUS, RADIUS, RADIUS, RADIUS, -90, 0);
  cogl_path_line_to (width, height - RADIUS);
  cogl_path_arc (width - RADIUS, height - RADIUS, RADIUS, RADIUS, 0, 90);
  cogl_path_line_to (RADIUS, height);
  cogl_path_arc (RADIUS, height - RADIUS, RADIUS, RADIUS, 90, 180);
  cogl_path_line_to (0, RADIUS);
  cogl_path_arc (RADIUS, RADIUS, RADIUS, RADIUS, 180, 270);
  cogl_path_close ();
  cogl_path_fill ();
285 286 287
}


288 289 290 291 292 293 294
static void
champlain_label_dispose (GObject *object)
{
  ChamplainLabelPrivate *priv = CHAMPLAIN_LABEL (object)->priv;

  if (priv->image)
    {
295
      clutter_actor_destroy (priv->image);
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
      priv->image = NULL;
    }

  if (priv->attributes)
    {
      pango_attr_list_unref (priv->attributes);
      priv->attributes = NULL;
    }

  G_OBJECT_CLASS (champlain_label_parent_class)->dispose (object);
}


static void
champlain_label_finalize (GObject *object)
{
  ChamplainLabelPrivate *priv = CHAMPLAIN_LABEL (object)->priv;

  if (priv->text)
    {
      g_free (priv->text);
      priv->text = NULL;
    }

  if (priv->font_name)
    {
      g_free (priv->font_name);
      priv->font_name = NULL;
    }

  if (priv->color)
    {
      clutter_color_free (priv->color);
      priv->color = NULL;
    }

  if (priv->text_color)
    {
      clutter_color_free (priv->text_color);
      priv->text_color = NULL;
    }

  if (priv->redraw_id)
    {
      g_source_remove (priv->redraw_id);
      priv->redraw_id = 0;
    }

  G_OBJECT_CLASS (champlain_label_parent_class)->finalize (object);
}


static void
349
champlain_label_class_init (ChamplainLabelClass *klass)
350
{
351 352
  ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
Jiří Techet's avatar
Jiří Techet committed
353

354 355 356 357 358
  object_class->finalize = champlain_label_finalize;
  object_class->dispose = champlain_label_dispose;
  object_class->get_property = champlain_label_get_property;
  object_class->set_property = champlain_label_set_property;

359 360
  actor_class->pick = pick;

361 362 363 364 365
  /**
   * ChamplainLabel:text:
   *
   * The text of the label
   *
Jiří Techet's avatar
Jiří Techet committed
366
   * Since: 0.10
367 368
   */
  g_object_class_install_property (object_class, PROP_TEXT,
369 370 371 372 373
      g_param_spec_string ("text", 
          "Text", 
          "The text of the label",
          "", 
          CHAMPLAIN_PARAM_READWRITE));
374 375 376 377 378 379

  /**
   * ChamplainLabel:image:
   *
   * The image of the label
   *
Jiří Techet's avatar
Jiří Techet committed
380
   * Since: 0.10
381 382
   */
  g_object_class_install_property (object_class, PROP_IMAGE,
383 384 385 386 387
      g_param_spec_object ("image", 
          "Image", 
          "The image of the label",
          CLUTTER_TYPE_ACTOR, 
          CHAMPLAIN_PARAM_READWRITE));
388 389 390 391 392 393

  /**
   * ChamplainLabel:use-markup:
   *
   * If the label's text uses markup
   *
Jiří Techet's avatar
Jiří Techet committed
394
   * Since: 0.10
395 396
   */
  g_object_class_install_property (object_class, PROP_USE_MARKUP,
397 398 399 400 401
      g_param_spec_boolean ("use-markup", 
          "Use Markup", 
          "The text uses markup",
          FALSE, 
          CHAMPLAIN_PARAM_READWRITE));
402 403 404 405 406 407

  /**
   * ChamplainLabel:alignment:
   *
   * The label's alignment
   *
Jiří Techet's avatar
Jiří Techet committed
408
   * Since: 0.10
409 410
   */
  g_object_class_install_property (object_class, PROP_ALIGNMENT,
411 412 413 414 415 416
      g_param_spec_enum ("alignment", 
          "Alignment", 
          "The label's alignment",
          PANGO_TYPE_ALIGNMENT, 
          PANGO_ALIGN_LEFT, 
          CHAMPLAIN_PARAM_READWRITE));
417 418 419 420 421 422

  /**
   * ChamplainLabel:color:
   *
   * The label's color
   *
Jiří Techet's avatar
Jiří Techet committed
423
   * Since: 0.10
424 425
   */
  g_object_class_install_property (object_class, PROP_COLOR,
426 427 428 429 430
      clutter_param_spec_color ("color", 
          "Color", 
          "The label's color",
          &DEFAULT_COLOR, 
          CHAMPLAIN_PARAM_READWRITE));
431 432 433 434 435 436

  /**
   * ChamplainLabel:text-color:
   *
   * The label's text color
   *
Jiří Techet's avatar
Jiří Techet committed
437
   * Since: 0.10
438 439
   */
  g_object_class_install_property (object_class, PROP_TEXT_COLOR,
440 441 442 443 444
      clutter_param_spec_color ("text-color", 
          "Text Color", 
          "The label's text color",
          &DEFAULT_TEXT_COLOR, 
          CHAMPLAIN_PARAM_READWRITE));
445 446 447 448 449 450

  /**
   * ChamplainLabel:font-name:
   *
   * The label's text font name
   *
Jiří Techet's avatar
Jiří Techet committed
451
   * Since: 0.10
452 453
   */
  g_object_class_install_property (object_class, PROP_FONT_NAME,
454 455 456 457 458
      g_param_spec_string ("font-name", 
          "Font Name", 
          "The label's text font name",
          "Sans 11", 
          CHAMPLAIN_PARAM_READWRITE));
459 460 461 462 463 464

  /**
   * ChamplainLabel:wrap:
   *
   * If the label's text wrap is set
   *
Jiří Techet's avatar
Jiří Techet committed
465
   * Since: 0.10
466 467
   */
  g_object_class_install_property (object_class, PROP_WRAP,
468 469 470 471 472
      g_param_spec_boolean ("wrap", 
          "Wrap", 
          "The label's text wrap",
          FALSE, 
          CHAMPLAIN_PARAM_READWRITE));
473 474 475 476 477 478

  /**
   * ChamplainLabel:wrap-mode:
   *
   * The label's text wrap mode
   *
Jiří Techet's avatar
Jiří Techet committed
479
   * Since: 0.10
480 481
   */
  g_object_class_install_property (object_class, PROP_WRAP_MODE,
482 483 484 485 486 487
      g_param_spec_enum ("wrap-mode", 
          "Wrap Mode", 
          "The label's text wrap mode",
          PANGO_TYPE_WRAP_MODE, 
          PANGO_WRAP_WORD, 
          CHAMPLAIN_PARAM_READWRITE));
488 489 490 491 492 493

  /**
   * ChamplainLabel:ellipsize:
   *
   * The label's ellipsize mode
   *
Jiří Techet's avatar
Jiří Techet committed
494
   * Since: 0.10
495 496
   */
  g_object_class_install_property (object_class, PROP_ELLIPSIZE,
497 498 499 500 501 502
      g_param_spec_enum ("ellipsize", 
          "Ellipsize Mode", 
          "The label's text ellipsize mode",
          PANGO_TYPE_ELLIPSIZE_MODE, 
          PANGO_ELLIPSIZE_NONE, 
          CHAMPLAIN_PARAM_READWRITE));
503 504 505 506 507 508

  /**
   * ChamplainLabel:draw-background:
   *
   * If the label has a background
   *
Jiří Techet's avatar
Jiří Techet committed
509
   * Since: 0.10
510 511
   */
  g_object_class_install_property (object_class, PROP_DRAW_BACKGROUND,
512 513 514 515 516
      g_param_spec_boolean ("draw-background", 
          "Draw Background", 
          "The label has a background",
          TRUE, 
          CHAMPLAIN_PARAM_READWRITE));
517

518 519 520 521 522 523 524 525 526 527 528 529 530 531
/**
   * ChamplainLabel:draw-shadow:
   *
   * If the label background has a shadow
   *
   * Since: 0.12.10
   */
  g_object_class_install_property (object_class, PROP_DRAW_SHADOW,
      g_param_spec_boolean ("draw-shadow", 
          "Draw Shadow", 
          "The label background has a shadow",
          TRUE, 
          CHAMPLAIN_PARAM_READWRITE));

532 533 534 535 536
  /**
   * ChamplainLabel:single-line-mode:
   *
   * If the label is in single line mode
   *
Jiří Techet's avatar
Jiří Techet committed
537
   * Since: 0.10
538 539
   */
  g_object_class_install_property (object_class, PROP_SINGLE_LINE_MODE,
540 541 542 543 544
      g_param_spec_boolean ("single-line-mode", 
          "Single Line Mode", 
          "The label's single line mode",
          TRUE, 
          CHAMPLAIN_PARAM_READWRITE));
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
}


static void
draw_box (cairo_t *cr,
    gint width,
    gint height,
    gint point,
    gboolean mirror)
{
  if (mirror)
    {
      cairo_move_to (cr, RADIUS, 0);
      cairo_line_to (cr, width - RADIUS, 0);
      cairo_arc (cr, width - RADIUS, RADIUS, RADIUS - 1, 3 * M_PI / 2.0, 0);
      cairo_line_to (cr, width, height - RADIUS);
      cairo_arc (cr, width - RADIUS, height - RADIUS, RADIUS - 1, 0, M_PI / 2.0);
      cairo_line_to (cr, point, height);
      cairo_line_to (cr, 0, height + point);
      cairo_arc (cr, RADIUS, RADIUS, RADIUS - 1, M_PI, 3 * M_PI / 2.0);
      cairo_close_path (cr);
    }
  else
    {
      cairo_move_to (cr, RADIUS, 0);
      cairo_line_to (cr, width - RADIUS, 0);
      cairo_arc (cr, width - RADIUS, RADIUS, RADIUS - 1, 3 * M_PI / 2.0, 0);
      cairo_line_to (cr, width, height + point);
      cairo_line_to (cr, width - point, height);
      cairo_line_to (cr, RADIUS, height);
      cairo_arc (cr, RADIUS, height - RADIUS, RADIUS - 1, M_PI / 2.0, M_PI);
      cairo_line_to (cr, 0, RADIUS);
      cairo_arc (cr, RADIUS, RADIUS, RADIUS - 1, M_PI, 3 * M_PI / 2.0);
      cairo_close_path (cr);
    }
}


583 584
static gint
get_shadow_slope_width (ChamplainLabel *label)
585 586 587
{
  ChamplainLabelPrivate *priv = label->priv;
  gint x;
588
  
589
  if (priv->alignment == PANGO_ALIGN_LEFT)
590
    x = -40 * SLOPE;
591
  else
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
    x = -58 * SLOPE;
    
  return x;
}


static gboolean
draw_shadow (ClutterCanvas *canvas,
    cairo_t *cr,
    int width,
    int height,
    ChamplainLabel *label)
{
  ChamplainLabelPrivate *priv = label->priv;
  gint x;
  cairo_matrix_t matrix;
608

609
  x = get_shadow_slope_width (label);
610

611
  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
Jiří Techet's avatar
Jiří Techet committed
612
  cairo_paint (cr);
613 614
  cairo_set_operator (cr, CAIRO_OPERATOR_OVER);

615 616
  cairo_matrix_init (&matrix,
      1, 0,
617
      SLOPE, SCALING,
618 619 620
      x, 0);
  cairo_set_matrix (cr, &matrix);

621
  draw_box (cr, width - x, height - priv->point, priv->point, priv->alignment == PANGO_ALIGN_LEFT);
622 623 624 625

  cairo_set_source_rgba (cr, 0, 0, 0, 0.15);
  cairo_fill (cr);

626
  return TRUE;
627 628 629
}


630 631 632 633 634 635
static gboolean
draw_background (ClutterCanvas *canvas,
    cairo_t *cr,
    int width,
    int height,
    ChamplainLabel *label)
636 637 638
{
  ChamplainLabelPrivate *priv = label->priv;
  ChamplainMarker *marker = CHAMPLAIN_MARKER (label);
639
  const ClutterColor *color;
640 641
  ClutterColor darker_color;

642
  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
Jiří Techet's avatar
Jiří Techet committed
643
  cairo_paint (cr);
644 645
  cairo_set_operator (cr, CAIRO_OPERATOR_OVER);

646
  /* If selected, add the selection color to the marker's color */
647
  if (champlain_marker_get_selected (marker))
648
    color = champlain_marker_get_selection_color ();
649 650 651
  else
    color = priv->color;

652
  draw_box (cr, width, height - priv->point, priv->point, priv->alignment == PANGO_ALIGN_LEFT);
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669

  clutter_color_darken (color, &darker_color);

  cairo_set_source_rgba (cr,
      color->red / 255.0,
      color->green / 255.0,
      color->blue / 255.0,
      color->alpha / 255.0);
  cairo_fill_preserve (cr);

  cairo_set_line_width (cr, 1.0);
  cairo_set_source_rgba (cr,
      darker_color.red / 255.0,
      darker_color.green / 255.0,
      darker_color.blue / 255.0,
      darker_color.alpha / 255.0);
  cairo_stroke (cr);
670 671
  
  return TRUE;
672 673 674 675 676 677 678 679
}


static void
draw_label (ChamplainLabel *label)
{
  ChamplainLabelPrivate *priv = label->priv;
  ChamplainMarker *marker = CHAMPLAIN_MARKER (label);
680 681 682 683 684 685 686 687 688
  gint height = 0;
  gint total_width = 0, total_height = 0;
  ClutterActor *text_actor, *shadow, *background;
  
  text_actor = NULL;
  shadow = NULL;
  background = NULL;
  
  clutter_actor_remove_all_children (CLUTTER_ACTOR (label));
689
  
690 691 692 693 694
  if (priv->image != NULL)
    {
      clutter_actor_set_position (priv->image, PADDING, PADDING);
      total_width = clutter_actor_get_width (priv->image) + 2 * PADDING;
      total_height = clutter_actor_get_height (priv->image) + 2 * PADDING;
695
      clutter_actor_add_child (CLUTTER_ACTOR (label), priv->image);
696 697 698 699 700
    }

  if (priv->text != NULL && strlen (priv->text) > 0)
    {
      ClutterText *text;
701 702
      
      text_actor = clutter_text_new_with_text (priv->font_name, priv->text);
703

704
      text = CLUTTER_TEXT (text_actor);
705 706 707 708 709 710 711 712 713
      clutter_text_set_font_name (text, priv->font_name);
      clutter_text_set_text (text, priv->text);
      clutter_text_set_line_alignment (text, priv->alignment);
      clutter_text_set_line_wrap (text, priv->wrap);
      clutter_text_set_line_wrap_mode (text, priv->wrap_mode);
      clutter_text_set_ellipsize (text, priv->ellipsize);
      clutter_text_set_attributes (text, priv->attributes);
      clutter_text_set_use_markup (text, priv->use_markup);

714
      height = clutter_actor_get_height (text_actor);
715 716
      if (priv->image != NULL)
        {
717 718
          clutter_actor_set_position (text_actor, total_width, (total_height - height) / 2.0);
          total_width += clutter_actor_get_width (text_actor) + 2 * PADDING;
719 720 721
        }
      else
        {
722 723
          clutter_actor_set_position (text_actor, 2 * PADDING, PADDING);
          total_width += clutter_actor_get_width (text_actor) + 4 * PADDING;
724 725 726
        }

      height += 2 * PADDING;
727
      total_height = MAX (total_height, height);
728

729
      clutter_text_set_color (text,
730
          (champlain_marker_get_selected (marker) ? champlain_marker_get_selection_text_color () : priv->text_color));
731
      clutter_actor_add_child (CLUTTER_ACTOR (label), text_actor);
732
    }
733 734
    
  if (text_actor == NULL && priv->image == NULL)
735 736 737 738
    {
      total_width = 6 * PADDING;
      total_height = 6 * PADDING;
    }
739
    
740
  priv->point = (total_height + 2 * PADDING) / 4.0;
741 742
  priv->total_width = total_width;
  priv->total_height = total_height;
743

744 745 746 747 748 749 750
  if (priv->draw_background)
    {
      ClutterContent *canvas;
      
      canvas = clutter_canvas_new ();
      clutter_canvas_set_size (CLUTTER_CANVAS (canvas), total_width, total_height + priv->point);
      g_signal_connect (canvas, "draw", G_CALLBACK (draw_background), label);
751 752 753 754
      background = clutter_actor_new ();
      clutter_actor_set_size (background, total_width, total_height + priv->point);
      clutter_actor_set_content (background, canvas);
      clutter_actor_add_child (CLUTTER_ACTOR (label), background);
755 756 757
      clutter_content_invalidate (canvas);
      g_object_unref (canvas);
      
758 759 760 761 762 763 764 765 766 767 768 769 770 771
      if (priv->draw_shadow)
        {
          canvas = clutter_canvas_new ();
          clutter_canvas_set_size (CLUTTER_CANVAS (canvas), total_width + get_shadow_slope_width (label), total_height + priv->point);
          g_signal_connect (canvas, "draw", G_CALLBACK (draw_shadow), label);

          shadow = clutter_actor_new ();
          clutter_actor_set_size (shadow, total_width + get_shadow_slope_width (label), total_height + priv->point);
          clutter_actor_set_content (shadow, canvas);
          clutter_actor_add_child (CLUTTER_ACTOR (label), shadow);
          clutter_actor_set_position (shadow, 0, total_height / 2.0);
          clutter_content_invalidate (canvas);
          g_object_unref (canvas);
        }
772 773
    }
          
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790
  if (text_actor != NULL && background != NULL)
    clutter_actor_set_child_above_sibling (CLUTTER_ACTOR (label), text_actor, background);
  if (priv->image != NULL && background != NULL)
    clutter_actor_set_child_above_sibling (CLUTTER_ACTOR (label), priv->image, background);
        
  if (priv->draw_background)
    {
      if (priv->alignment == PANGO_ALIGN_RIGHT)
        clutter_actor_set_translation (CLUTTER_ACTOR (label), -total_width, -total_height - priv->point, 0);
      else
        clutter_actor_set_translation (CLUTTER_ACTOR (label), 0, -total_height - priv->point, 0);
    }
  else if (priv->image != NULL)
    clutter_actor_set_translation (CLUTTER_ACTOR (label), -clutter_actor_get_width (priv->image) / 2.0 - PADDING,
        -clutter_actor_get_height (priv->image) / 2.0 - PADDING, 0);
  else if (text_actor != NULL)
    clutter_actor_set_translation (CLUTTER_ACTOR (label), 0, -clutter_actor_get_height (text_actor) / 2.0, 0);
791 792 793 794 795 796 797 798
}


static gboolean
redraw_on_idle (gpointer gobject)
{
  ChamplainLabel *label = CHAMPLAIN_LABEL (gobject);

799
  draw_label (label);
800 801 802 803 804
  label->priv->redraw_id = 0;
  return FALSE;
}


805
/*
806 807 808 809 810 811 812 813
 * champlain_label_queue_redraw:
 * @label: a #ChamplainLabel
 *
 * Queue a redraw of the label as soon as possible. This function should not
 * be used unless you are subclassing ChamplainLabel and adding new properties
 * that affect the aspect of the label.  When they change, call this function
 * to update the label.
 *
Jiří Techet's avatar
Jiří Techet committed
814
 * Since: 0.10
815
 */
816
static void
817 818 819 820 821 822 823
champlain_label_queue_redraw (ChamplainLabel *label)
{
  ChamplainLabelPrivate *priv = label->priv;

  if (!priv->redraw_id)
    {
      priv->redraw_id =
824
        g_idle_add_full (CLUTTER_PRIORITY_REDRAW,
825 826 827 828 829 830 831 832
            (GSourceFunc) redraw_on_idle,
            g_object_ref (label),
            (GDestroyNotify) g_object_unref);
    }
}


static void
833
notify_selected (GObject *gobject,
834 835 836 837 838 839 840 841 842 843
    G_GNUC_UNUSED GParamSpec *pspec,
    G_GNUC_UNUSED gpointer user_data)
{
  champlain_label_queue_redraw (CHAMPLAIN_LABEL (gobject));
}


static void
champlain_label_init (ChamplainLabel *label)
{
844
  ChamplainLabelPrivate *priv = champlain_label_get_instance_private (label);
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860

  label->priv = priv;

  priv->text = NULL;
  priv->image = NULL;
  priv->use_markup = FALSE;
  priv->alignment = PANGO_ALIGN_LEFT;
  priv->attributes = NULL;
  priv->color = clutter_color_copy (&DEFAULT_COLOR);
  priv->text_color = clutter_color_copy (&DEFAULT_TEXT_COLOR);
  priv->font_name = g_strdup (DEFAULT_FONT_NAME);
  priv->wrap = FALSE;
  priv->wrap_mode = PANGO_WRAP_WORD;
  priv->single_line_mode = TRUE;
  priv->ellipsize = PANGO_ELLIPSIZE_NONE;
  priv->draw_background = TRUE;
861
  priv->draw_shadow = TRUE;
862
  priv->redraw_id = 0;
863 864
  priv->total_width = 0;
  priv->total_height = 0;
865

866
  g_signal_connect (label, "notify::selected", G_CALLBACK (notify_selected), NULL);
867
  champlain_label_queue_redraw (label);
868 869 870 871 872 873 874 875 876 877
}


/**
 * champlain_label_new:
 *
 * Creates a new instance of #ChamplainLabel.
 *
 * Returns: a new #ChamplainLabel ready to be used as a #ClutterActor.
 *
Jiří Techet's avatar
Jiří Techet committed
878
 * Since: 0.10
879 880 881 882 883 884 885 886 887 888
 */
ClutterActor *
champlain_label_new (void)
{
  return CLUTTER_ACTOR (g_object_new (CHAMPLAIN_TYPE_LABEL, NULL));
}


/**
 * champlain_label_new_with_text:
889
 * @text: the text of the label
890 891 892 893 894 895 896 897
 * @font: (allow-none): the font to use to draw the text, for example "Courrier Bold 11", can be NULL
 * @text_color: (allow-none): a #ClutterColor, the color of the text, can be NULL
 * @label_color: (allow-none): a #ClutterColor, the color of the label, can be NULL
 *
 * Creates a new instance of #ChamplainLabel with text value.
 *
 * Returns: a new #ChamplainLabel with a drawn label containing the given text.
 *
Jiří Techet's avatar
Jiří Techet committed
898
 * Since: 0.10
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924
 */
ClutterActor *
champlain_label_new_with_text (const gchar *text,
    const gchar *font,
    ClutterColor *text_color,
    ClutterColor *label_color)
{
  ChamplainLabel *label = CHAMPLAIN_LABEL (champlain_label_new ());

  champlain_label_set_text (label, text);

  if (font != NULL)
    champlain_label_set_font_name (label, font);

  if (text_color != NULL)
    champlain_label_set_text_color (label, text_color);

  if (label_color != NULL)
    champlain_label_set_color (label, label_color);

  return CLUTTER_ACTOR (label);
}


/**
 * champlain_label_new_with_image:
925
 * @actor: The image as a @ClutterActor.
926 927 928 929 930 931
 *
 * Creates a new instance of #ChamplainLabel with image.
 *
 * Returns: a new #ChamplainLabel with a drawn label containing the given
 * image.
 *
Jiří Techet's avatar
Jiří Techet committed
932
 * Since: 0.10
933 934 935 936 937 938 939
 */
ClutterActor *
champlain_label_new_with_image (ClutterActor *actor)
{
  ChamplainLabel *label = CHAMPLAIN_LABEL (champlain_label_new ());

  if (actor != NULL)
940
    champlain_label_set_image (label, actor);
941 942 943 944 945 946 947 948 949 950 951 952 953 954 955

  return CLUTTER_ACTOR (label);
}


/**
 * champlain_label_new_from_file:
 * @filename: The filename of the image.
 * @error: Return location for an error.
 *
 * Creates a new instance of #ChamplainLabel with image loaded from file.
 *
 * Returns: a new #ChamplainLabel with a drawn label containing the given
 * image.
 *
Jiří Techet's avatar
Jiří Techet committed
956
 * Since: 0.10
957 958 959 960 961
 */
ClutterActor *
champlain_label_new_from_file (const gchar *filename,
    GError **error)
{
962 963 964 965 966 967 968
  ChamplainLabel *label = CHAMPLAIN_LABEL (champlain_label_new ());
  
  ClutterActor *actor;
  GdkPixbuf *pixbuf;
  ClutterContent *content;
  gfloat width, height;
  
969
  if (filename == NULL)
970
    return CLUTTER_ACTOR (label);
971

972 973
  pixbuf = gdk_pixbuf_new_from_file (filename, error);
  if (pixbuf == NULL)
974
    return CLUTTER_ACTOR (label);
975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995
    
  content = clutter_image_new ();
  clutter_image_set_data (CLUTTER_IMAGE (content),
                          gdk_pixbuf_get_pixels (pixbuf),
                          gdk_pixbuf_get_has_alpha (pixbuf)
                            ? COGL_PIXEL_FORMAT_RGBA_8888
                            : COGL_PIXEL_FORMAT_RGB_888,
                          gdk_pixbuf_get_width (pixbuf),
                          gdk_pixbuf_get_height (pixbuf),
                          gdk_pixbuf_get_rowstride (pixbuf),
                          error);
  g_object_unref (pixbuf);

  actor = clutter_actor_new ();
  clutter_content_get_preferred_size (content, &width, &height);
  clutter_actor_set_size (actor, width, height);
  clutter_actor_set_content (actor, content);
  clutter_content_invalidate (content);
  g_object_unref (content);
  
  champlain_label_set_image (label, actor);
996 997 998 999 1000 1001 1002

  return CLUTTER_ACTOR (label);
}


/**
 * champlain_label_new_full:
1003 1004
 * @text: The text of the label
 * @actor: The image as a @ClutterActor
1005 1006 1007 1008 1009 1010
 *
 * Creates a new instance of #ChamplainLabel consisting of a custom #ClutterActor.
 *
 * Returns: a new #ChamplainLabel with a drawn label containing the given
 * image.
 *
Jiří Techet's avatar
Jiří Techet committed
1011
 * Since: 0.10
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
 */
ClutterActor *
champlain_label_new_full (const gchar *text,
    ClutterActor *actor)
{
  ChamplainLabel *label = CHAMPLAIN_LABEL (champlain_label_new ());

  if (actor != NULL)
    {
      champlain_label_set_image (label, actor);
    }
  champlain_label_set_text (label, text);

  return CLUTTER_ACTOR (label);
}


/**
 * champlain_label_set_text:
1031 1032
 * @label: a #ChamplainLabel
 * @text: The new text of the label
1033 1034 1035
 *
 * Sets the label's text.
 *
Jiří Techet's avatar
Jiří Techet committed
1036
 * Since: 0.10
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
 */
void
champlain_label_set_text (ChamplainLabel *label,
    const gchar *text)
{
  g_return_if_fail (CHAMPLAIN_IS_LABEL (label));

  ChamplainLabelPrivate *priv = label->priv;

  if (priv->text != NULL)
    g_free (priv->text);

  priv->text = g_strdup (text);
1050
  g_object_notify (G_OBJECT (label), "text");
1051 1052 1053 1054 1055 1056
  champlain_label_queue_redraw (label);
}


/**
 * champlain_label_set_image:
1057
 * @label: a #ChamplainLabel
1058 1059 1060 1061
 * @image: (allow-none): The image as a @ClutterActor or NULL to remove the current image.
 *
 * Sets the label's image.
 *
Jiří Techet's avatar
Jiří Techet committed
1062
 * Since: 0.10
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089
 */
void
champlain_label_set_image (ChamplainLabel *label,
    ClutterActor *image)
{
  g_return_if_fail (CHAMPLAIN_IS_LABEL (label));

  ChamplainLabelPrivate *priv = label->priv;

  if (priv->image != NULL)
    clutter_actor_destroy (priv->image);

  if (image != NULL)
    {
      g_return_if_fail (CLUTTER_IS_ACTOR (image));
      priv->image = g_object_ref (image);
    }
  else
    priv->image = image;

  g_object_notify (G_OBJECT (label), "image");
  champlain_label_queue_redraw (label);
}


/**
 * champlain_label_set_use_markup:
1090
 * @label: a #ChamplainLabel
1091 1092 1093 1094
 * @use_markup: The value
 *
 * Sets if the label's text uses markup.
 *
Jiří Techet's avatar
Jiří Techet committed
1095
 * Since: 0.10
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110
 */
void
champlain_label_set_use_markup (ChamplainLabel *label,
    gboolean markup)
{
  g_return_if_fail (CHAMPLAIN_IS_LABEL (label));

  label->priv->use_markup = markup;
  g_object_notify (G_OBJECT (label), "use-markup");
  champlain_label_queue_redraw (label);
}


/**
 * champlain_label_set_alignment:
1111
 * @label: a #ChamplainLabel
1112 1113
 * @alignment: The label's alignment
 *
1114
 * Sets the label's text alignment.
1115
 *
Jiří Techet's avatar
Jiří Techet committed
1116
 * Since: 0.10
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131
 */
void
champlain_label_set_alignment (ChamplainLabel *label,
    PangoAlignment alignment)
{
  g_return_if_fail (CHAMPLAIN_IS_LABEL (label));

  label->priv->alignment = alignment;
  g_object_notify (G_OBJECT (label), "alignment");
  champlain_label_queue_redraw (label);
}


/**
 * champlain_label_set_color:
1132
 * @label: a #ChamplainLabel
1133 1134 1135
 * @color: (allow-none): The label's background color or NULL to reset the background to the
 *         default color. The color parameter is copied.
 *
1136
 * Sets the label's background color.
1137
 *
Jiří Techet's avatar
Jiří Techet committed
1138
 * Since: 0.10
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161
 */
void
champlain_label_set_color (ChamplainLabel *label,
    const ClutterColor *color)
{
  g_return_if_fail (CHAMPLAIN_IS_LABEL (label));

  ChamplainLabelPrivate *priv = label->priv;

  if (priv->color != NULL)
    clutter_color_free (priv->color);

  if (color == NULL)
    color = &DEFAULT_COLOR;

  priv->color = clutter_color_copy (color);
  g_object_notify (G_OBJECT (label), "color");
  champlain_label_queue_redraw (label);
}


/**
 * champlain_label_set_text_color:
1162
 * @label: a #ChamplainLabel
1163 1164 1165
 * @color: (allow-none): The label's text color or NULL to reset the text to the default
 *         color. The color parameter is copied.
 *
1166
 * Sets the label's text color.
1167
 *
Jiří Techet's avatar
Jiří Techet committed
1168
 * Since: 0.10
1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191
 */
void
champlain_label_set_text_color (ChamplainLabel *label,
    const ClutterColor *color)
{
  g_return_if_fail (CHAMPLAIN_IS_LABEL (label));

  ChamplainLabelPrivate *priv = label->priv;

  if (priv->text_color != NULL)
    clutter_color_free (priv->text_color);

  if (color == NULL)
    color = &DEFAULT_TEXT_COLOR;

  priv->text_color = clutter_color_copy (color);
  g_object_notify (G_OBJECT (label), "text-color");
  champlain_label_queue_redraw (label);
}


/**
 * champlain_label_set_font_name:
1192
 * @label: a #ChamplainLabel
1193 1194 1195
 * @font_name: (allow-none): The label's font name or NULL to reset the font to the default
 *             value.
 *
1196
 * Sets the label's font name such as "Sans 12".
1197
 *
Jiří Techet's avatar
Jiří Techet committed
1198
 * Since: 0.10
1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221
 */
void
champlain_label_set_font_name (ChamplainLabel *label,
    const gchar *font_name)
{
  g_return_if_fail (CHAMPLAIN_IS_LABEL (label));

  ChamplainLabelPrivate *priv = label->priv;

  if (priv->font_name != NULL)
    g_free (priv->font_name);

  if (font_name == NULL)
    font_name = DEFAULT_FONT_NAME;

  priv->font_name = g_strdup (font_name);
  g_object_notify (G_OBJECT (label), "font-name");
  champlain_label_queue_redraw (label);
}


/**
 * champlain_label_set_wrap:
1222
 * @label: a #ChamplainLabel
1223 1224
 * @wrap: The label's wrap.
 *
1225
 * Sets if the label's text wrap.
1226
 *
Jiří Techet's avatar
Jiří Techet committed
1227
 * Since: 0.10
1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242
 */
void
champlain_label_set_wrap (ChamplainLabel *label,
    gboolean wrap)
{
  g_return_if_fail (CHAMPLAIN_IS_LABEL (label));

  label->priv->wrap = wrap;
  g_object_notify (G_OBJECT (label), "wrap");
  champlain_label_queue_redraw (label);
}


/**
 * champlain_label_set_wrap_mode:
1243 1244
 * @label: a #ChamplainLabel
 * @wrap_mode: The label's wrap mode.
1245
 *
1246
 * Sets the label's text wrap mode.
1247
 *
Jiří Techet's avatar
Jiří Techet committed
1248
 * Since: 0.10
1249 1250 1251 1252 1253 1254 1255 1256
 */
void
champlain_label_set_wrap_mode (ChamplainLabel *label,
    PangoWrapMode wrap_mode)
{
  g_return_if_fail (CHAMPLAIN_IS_LABEL (label));

  label->priv->wrap_mode = wrap_mode;
1257
  g_object_notify (G_OBJECT (label), "wrap-mode");
1258 1259 1260 1261 1262 1263
  champlain_label_queue_redraw (label);
}


/**
 * champlain_label_set_attributes:
1264
 * @label: a #ChamplainLabel
1265 1266
 * @list: The label's text attributes.
 *
1267
 * Sets the label's text attributes.
1268
 *
Jiří Techet's avatar
Jiří Techet committed
1269
 * Since: 0.10
1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293
 */
void
champlain_label_set_attributes (ChamplainLabel *label,
    PangoAttrList *attributes)
{
  g_return_if_fail (CHAMPLAIN_IS_LABEL (label));

  ChamplainLabelPrivate *priv = label->priv;

  if (attributes)
    pango_attr_list_ref (attributes);

  if (priv->attributes)
    pango_attr_list_unref (priv->attributes);

  priv->attributes = attributes;

  g_object_notify (G_OBJECT (label), "attributes");
  champlain_label_queue_redraw (label);
}


/**
 * champlain_label_set_ellipsize:
1294
 * @label: a #ChamplainLabel
1295 1296
 * @mode: The label's ellipsize mode.
 *
1297
 * Sets the label's text ellipsize mode.
1298
 *
Jiří Techet's avatar
Jiří Techet committed
1299
 * Since: 0.10
1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314
 */
void
champlain_label_set_ellipsize (ChamplainLabel *label,
    PangoEllipsizeMode ellipsize)
{
  g_return_if_fail (CHAMPLAIN_IS_LABEL (label));

  label->priv->ellipsize = ellipsize;
  g_object_notify (G_OBJECT (label), "ellipsize");
  champlain_label_queue_redraw (label);
}


/**
 * champlain_label_set_single_line_mode:
1315
 * @label: a #ChamplainLabel
1316 1317
 * @mode: The label's single line mode
 *
1318
 * Sets if the label's text is on a single line.
1319
 *
Jiří Techet's avatar
Jiří Techet committed
1320
 * Since: 0.10
1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336
 */
void
champlain_label_set_single_line_mode (ChamplainLabel *label,
    gboolean mode)
{
  g_return_if_fail (CHAMPLAIN_IS_LABEL (label));

  label->priv->single_line_mode = mode;

  g_object_notify (G_OBJECT (label), "single-line-mode");
  champlain_label_queue_redraw (label);
}


/**
 * champlain_label_set_draw_background:
1337
 * @label: a #ChamplainLabel
1338 1339
 * @background: value.
 *
1340
 * Sets if the label has a background.
1341
 *
Jiří Techet's avatar
Jiří Techet committed
1342
 * Since: 0.10
1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355
 */
void
champlain_label_set_draw_background (ChamplainLabel *label,
    gboolean background)
{
  g_return_if_fail (CHAMPLAIN_IS_LABEL (label));

  label->priv->draw_background = background;
  g_object_notify (G_OBJECT (label), "draw-background");
  champlain_label_queue_redraw (label);
}


1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375
/**
 * champlain_label_set_draw_shadow:
 * @label: a #ChamplainLabel
 * @shadow: value.
 *
 * Sets if the label's background has a shadow.
 *
 * Since: 0.12.10
 */
void
champlain_label_set_draw_shadow (ChamplainLabel *label,
    gboolean shadow)
{
  g_return_if_fail (CHAMPLAIN_IS_LABEL (label));

  label->priv->draw_shadow = shadow;
  g_object_notify (G_OBJECT (label), "draw-shadow");
  champlain_label_queue_redraw (label);
}

1376 1377
/**
 * champlain_label_get_image:
1378
 * @label: a #ChamplainLabel
1379 1380 1381 1382 1383
 *
 * Get the label's image.
 *
 * Returns: (transfer none): the label's image.
 *
Jiří Techet's avatar
Jiří Techet committed
1384
 * Since: 0.10
1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396
 */
ClutterActor *
champlain_label_get_image (ChamplainLabel *label)
{
  g_return_val_if_fail (CHAMPLAIN_IS_LABEL (label), NULL);

  return label->priv->image;
}


/**
 * champlain_label_get_use_markup:
1397
 * @label: a #ChamplainLabel
1398 1399 1400 1401 1402
 *
 * Check whether the label uses markup.
 *
 * Returns: if the label's text contains markup.
 *
Jiří Techet's avatar
Jiří Techet committed
1403
 * Since: 0.10
1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415
 */
gboolean
champlain_label_get_use_markup (ChamplainLabel *label)
{
  g_return_val_if_fail (CHAMPLAIN_IS_LABEL (label), FALSE);

  return label->priv->use_markup;
}


/**
 * champlain_label_get_text:
1416
 * @label: a #ChamplainLabel
1417 1418 1419 1420 1421
 *
 * Get the label's text.
 *
 * Returns: the label's text.
 *
Jiří Techet's avatar
Jiří Techet committed
1422
 * Since: 0.10
1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434
 */
const gchar *
champlain_label_get_text (ChamplainLabel *label)
{
  g_return_val_if_fail (CHAMPLAIN_IS_LABEL (label), FALSE);

  return label->priv->text;
}


/**
 * champlain_label_get_alignment:
1435
 * @label: a #ChamplainLabel
1436 1437 1438 1439 1440
 *
 * Get the label's text alignment.
 *
 * Returns: the label's text alignment.
 *
Jiří Techet's avatar
Jiří Techet committed
1441
 * Since: 0.10
1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453
 */
PangoAlignment
champlain_label_get_alignment (ChamplainLabel *label)
{
  g_return_val_if_fail (CHAMPLAIN_IS_LABEL (label), FALSE);

  return label->priv->alignment;
}


/**
 * champlain_label_get_color:
1454
 * @label: a #ChamplainLabel
1455
 *
1456
 * Gets the label's background color.
1457
 *
1458
 * Returns: the label's background color.
1459
 *
Jiří Techet's avatar
Jiří Techet committed
1460
 * Since: 0.10
1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472
 */
ClutterColor *
champlain_label_get_color (ChamplainLabel *label)
{
  g_return_val_if_fail (CHAMPLAIN_IS_LABEL (label), NULL);

  return label->priv->color;
}


/**
 * champlain_label_get_text_color:
1473
 * @label: a #ChamplainLabel
1474 1475 1476 1477 1478
 *
 * Gets the label's text color.
 *
 * Returns: the label's text color.
 *
Jiří Techet's avatar
Jiří Techet committed
1479
 * Since: 0.10
1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491
 */
ClutterColor *
champlain_label_get_text_color (ChamplainLabel *label)
{
  g_return_val_if_fail (CHAMPLAIN_IS_LABEL (label), NULL);

  return label->priv->text_color;
}


/**
 * champlain_label_get_font_name:
1492
 * @label: a #ChamplainLabel
1493 1494 1495 1496 1497
 *
 * Gets the label's font name.
 *
 * Returns: the label's font name.
 *
Jiří Techet's avatar
Jiří Techet committed
1498
 * Since: 0.10
1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510
 */
const gchar *
champlain_label_get_font_name (ChamplainLabel *label)
{
  g_return_val_if_fail (CHAMPLAIN_IS_LABEL (label), FALSE);

  return label->priv->font_name;
}


/**
 * champlain_label_get_wrap:
1511
 * @label: a #ChamplainLabel
1512
 *
1513
 * Checks whether the label text wraps.
1514 1515 1516
 *
 * Returns: if the label's text wraps.
 *
Jiří Techet's avatar
Jiří Techet committed
1517
 * Since: 0.10
1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529
 */
gboolean
champlain_label_get_wrap (ChamplainLabel *label)
{
  g_return_val_if_fail (CHAMPLAIN_IS_LABEL (label), FALSE);

  return label->priv->wrap;
}


/**
 * champlain_label_get_wrap_mode:
1530
 * @label: a #ChamplainLabel
1531
 *
1532
 * Gets the label's text wrap mode.
1533 1534 1535
 *
 * Returns: the label's text wrap mode.
 *
Jiří Techet's avatar
Jiří Techet committed
1536
 * Since: 0.10
1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548
 */
PangoWrapMode
champlain_label_get_wrap_mode (ChamplainLabel *label)
{
  g_return_val_if_fail (CHAMPLAIN_IS_LABEL (label), FALSE);

  return label->priv->wrap_mode;
}


/**
 * champlain_label_get_ellipsize:
1549
 * @label: a #ChamplainLabel
1550
 *
1551
 * Gets the label's text ellipsize mode.
1552 1553 1554
 *
 * Returns: the label's text ellipsize mode.
 *
Jiří Techet's avatar
Jiří Techet committed
1555
 * Since: 0.10
1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567
 */
PangoEllipsizeMode
champlain_label_get_ellipsize (ChamplainLabel *label)
{
  g_return_val_if_fail (CHAMPLAIN_IS_LABEL (label), FALSE);

  return label->priv->ellipsize;
}


/**
 * champlain_label_get_single_line_mode:
1568
 * @label: a #ChamplainLabel
1569 1570 1571 1572 1573
 *
 * Checks the label's single line mode.
 *
 * Returns: the label's text single line mode.
 *
Jiří Techet's avatar
Jiří Techet committed
1574
 * Since: 0.10
1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586
 */
gboolean
champlain_label_get_single_line_mode (ChamplainLabel *label)
{
  g_return_val_if_fail (CHAMPLAIN_IS_LABEL (label), FALSE);

  return label->priv->single_line_mode;
}


/**
 * champlain_label_get_draw_background:
1587
 * @label: a #ChamplainLabel
1588 1589 1590
 *
 * Checks whether the label has a background.
 *
1591
 * Returns: if the label has a background.
1592
 *
Jiří Techet's avatar
Jiří Techet committed
1593
 * Since: 0.10
1594 1595 1596 1597 1598 1599 1600 1601
 */
gboolean
champlain_label_get_draw_background (ChamplainLabel *label)
{
  g_return_val_if_fail (CHAMPLAIN_IS_LABEL (label), FALSE);

  return label->priv->draw_background;
}
1602 1603


1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622
/**
 * champlain_label_get_draw_shadow:
 * @label: a #ChamplainLabel
 *
 * Checks whether the label's background has a shadow.
 *
 * Returns: if the label's background has a shadow.
 *
 * Since: 0.12.10
 */
gboolean
champlain_label_get_draw_shadow (ChamplainLabel *label)
{
  g_return_val_if_fail (CHAMPLAIN_IS_LABEL (label), FALSE);

  return label->priv->draw_shadow;
}


1623 1624
/**
 * champlain_label_get_attributes:
1625
 * @label: a #ChamplainLabel
1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639
 *
 * Gets the label's text attributes.
 *
 * Returns: the label's text attributes.
 *
 * Since: 0.10
 */
PangoAttrList *
champlain_label_get_attributes (ChamplainLabel *label)
{
  g_return_val_if_fail (CHAMPLAIN_IS_LABEL (label), NULL);

  return label->priv->attributes;
}