[libchamplain] Make ChamplainLabel shadow optional



commit a64f8a8f9a0f2d0640be468c8192f366c133f27f
Author: Jiří Techet <techet gmail com>
Date:   Wed Oct 15 21:38:02 2014 +0200

    Make ChamplainLabel shadow optional
    
    Thanks to Chris Mayo for providing the patch.

 champlain/champlain-label.c              |   93 +++++++++++++++++++++++++----
 champlain/champlain-label.h              |    3 +
 docs/reference/libchamplain-sections.txt |    2 +
 3 files changed, 85 insertions(+), 13 deletions(-)
---
diff --git a/champlain/champlain-label.c b/champlain/champlain-label.c
index 0f15422..4deeb75 100644
--- a/champlain/champlain-label.c
+++ b/champlain/champlain-label.c
@@ -79,7 +79,8 @@ enum
   PROP_WRAP,
   PROP_WRAP_MODE,
   PROP_SINGLE_LINE_MODE,
-  PROP_DRAW_BACKGROUND
+  PROP_DRAW_BACKGROUND,
+  PROP_DRAW_SHADOW
 };
 
 /* static guint champlain_label_signals[LAST_SIGNAL] = { 0, }; */
@@ -99,6 +100,7 @@ struct _ChamplainLabelPrivate
   gboolean single_line_mode;
   PangoEllipsizeMode ellipsize;
   gboolean draw_background;
+  gboolean draw_shadow;
 
   guint redraw_id;
   gint total_width;
@@ -164,6 +166,10 @@ champlain_label_get_property (GObject *object,
       g_value_set_boolean (value, priv->draw_background);
       break;
 
+    case PROP_DRAW_SHADOW:
+      g_value_set_boolean (value, priv->draw_shadow);
+      break;
+
     case PROP_ELLIPSIZE:
       g_value_set_enum (value, priv->ellipsize);
       break;
@@ -232,6 +238,10 @@ champlain_label_set_property (GObject *object,
       champlain_label_set_draw_background (label, g_value_get_boolean (value));
       break;
 
+    case PROP_DRAW_SHADOW:
+      champlain_label_set_draw_shadow (label, g_value_get_boolean (value));
+      break;
+
     case PROP_SINGLE_LINE_MODE:
       champlain_label_set_single_line_mode (label, g_value_get_boolean (value));
       break;
@@ -511,6 +521,20 @@ champlain_label_class_init (ChamplainLabelClass *klass)
           TRUE, 
           CHAMPLAIN_PARAM_READWRITE));
 
+/**
+   * 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));
+
   /**
    * ChamplainLabel:single-line-mode:
    *
@@ -737,17 +761,20 @@ draw_label (ChamplainLabel *label)
       clutter_content_invalidate (canvas);
       g_object_unref (canvas);
       
-      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);
+      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);
+        }
     }
           
   if (text_actor != NULL && background != NULL)
@@ -837,6 +864,7 @@ champlain_label_init (ChamplainLabel *label)
   priv->single_line_mode = TRUE;
   priv->ellipsize = PANGO_ELLIPSIZE_NONE;
   priv->draw_background = TRUE;
+  priv->draw_shadow = TRUE;
   priv->redraw_id = 0;
   priv->total_width = 0;
   priv->total_height = 0;
@@ -1332,6 +1360,26 @@ champlain_label_set_draw_background (ChamplainLabel *label,
 
 
 /**
+ * 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);
+}
+
+/**
  * champlain_label_get_image:
  * @label: a #ChamplainLabel
  *
@@ -1546,7 +1594,7 @@ champlain_label_get_single_line_mode (ChamplainLabel *label)
  *
  * Checks whether the label has a background.
  *
- * Returns: if the label's has a background.
+ * Returns: if the label has a background.
  *
  * Since: 0.10
  */
@@ -1560,6 +1608,25 @@ champlain_label_get_draw_background (ChamplainLabel *label)
 
 
 /**
+ * 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;
+}
+
+
+/**
  * champlain_label_get_attributes:
  * @label: a #ChamplainLabel
  *
diff --git a/champlain/champlain-label.h b/champlain/champlain-label.h
index c820326..6ff2eb6 100644
--- a/champlain/champlain-label.h
+++ b/champlain/champlain-label.h
@@ -116,6 +116,8 @@ void champlain_label_set_ellipsize (ChamplainLabel *label,
     PangoEllipsizeMode mode);
 void champlain_label_set_draw_background (ChamplainLabel *label,
     gboolean background);
+void champlain_label_set_draw_shadow (ChamplainLabel *label,
+    gboolean shadow);
 
 gboolean champlain_label_get_use_markup (ChamplainLabel *label);
 const gchar *champlain_label_get_text (ChamplainLabel *label);
@@ -129,6 +131,7 @@ PangoWrapMode champlain_label_get_wrap_mode (ChamplainLabel *label);
 PangoEllipsizeMode champlain_label_get_ellipsize (ChamplainLabel *label);
 gboolean champlain_label_get_single_line_mode (ChamplainLabel *label);
 gboolean champlain_label_get_draw_background (ChamplainLabel *label);
+gboolean champlain_label_get_draw_shadow (ChamplainLabel *label);
 PangoAttrList *champlain_label_get_attributes (ChamplainLabel *label);
 
 
diff --git a/docs/reference/libchamplain-sections.txt b/docs/reference/libchamplain-sections.txt
index 87b473d..b917986 100644
--- a/docs/reference/libchamplain-sections.txt
+++ b/docs/reference/libchamplain-sections.txt
@@ -58,6 +58,7 @@ champlain_label_set_attributes
 champlain_label_set_single_line_mode
 champlain_label_set_ellipsize
 champlain_label_set_draw_background
+champlain_label_set_draw_shadow
 champlain_label_get_use_markup
 champlain_label_get_text
 champlain_label_get_image
@@ -71,6 +72,7 @@ champlain_label_get_ellipsize
 champlain_label_get_single_line_mode
 champlain_label_get_draw_background
 champlain_label_get_attributes
+champlain_label_get_draw_shadow
 <SUBSECTION Standard>
 CHAMPLAIN_LABEL
 CHAMPLAIN_IS_LABEL


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]