[metacity] libmetacity: add meta-color.[c/h]



commit 310a209df3bfa37ebcd6c1388ce488fd956983bb
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Wed Jan 27 21:59:01 2016 +0200

    libmetacity: add meta-color.[c/h]

 libmetacity/Makefile.am  |    2 +
 libmetacity/meta-color.c |  105 ++++++++++++++++++++++++++++++++++++++++++++++
 libmetacity/meta-color.h |   44 +++++++++++++++++++
 libmetacity/meta-hsla.h  |    3 +
 src/ui/draw-workspace.c  |   29 +++----------
 src/ui/theme-private.h   |    7 ---
 src/ui/theme.c           |   77 ++++------------------------------
 7 files changed, 169 insertions(+), 98 deletions(-)
---
diff --git a/libmetacity/Makefile.am b/libmetacity/Makefile.am
index 117c410..8f89d6a 100644
--- a/libmetacity/Makefile.am
+++ b/libmetacity/Makefile.am
@@ -3,6 +3,8 @@ NULL =
 noinst_LTLIBRARIES = libmetacity.la
 
 libmetacity_la_SOURCES = \
+       meta-color.c \
+       meta-color.h \
        meta-hsla.c \
        meta-hsla.h \
        meta-theme.c \
diff --git a/libmetacity/meta-color.c b/libmetacity/meta-color.c
new file mode 100644
index 0000000..17fe213
--- /dev/null
+++ b/libmetacity/meta-color.c
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2001 Havoc Pennington
+ * Copyright (C) 2016 Alberts Muktupāvels
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "meta-hsla.h"
+#include "meta-color.h"
+
+#define LIGHTNESS_MULT 1.3
+#define DARKNESS_MULT 0.7
+
+/**
+ * meta_color_shade:
+ * @source: #GdkRGBA color
+ * @factor: amount to scale saturation and lightness
+ * @destination: (out): location to store #GdkRGBA color
+ *
+ * Takes a @source color, scales saturation and lightness by @factor and
+ * sets @destionation to the resulting color.
+ */
+void
+meta_color_shade (const GdkRGBA *source,
+                  const gdouble  factor,
+                  GdkRGBA       *destination)
+{
+  MetaHSLA hsla;
+
+  meta_hsla_from_rgba (&hsla, source);
+  meta_hsla_shade (&hsla, factor, &hsla);
+  meta_hsla_to_rgba (&hsla, destination);
+}
+
+/**
+ * meta_color_get_background_color:
+ * @context: a #GtkStyleContext
+ * @state: state to retrieve the color for
+ * @color: (out): location to store the background color
+ *
+ * Gets the background color for a given state.
+ */
+void
+meta_color_get_background_color (GtkStyleContext *context,
+                                 GtkStateFlags    state,
+                                 GdkRGBA         *color)
+{
+  GdkRGBA *tmp;
+
+  g_return_if_fail (color != NULL);
+  g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
+
+  gtk_style_context_get (context, state, "background-color", &tmp, NULL);
+
+  *color = *tmp;
+
+  gdk_rgba_free (tmp);
+}
+
+/**
+ * meta_color_get_light_color:
+ * @context: a #GtkStyleContext
+ * @state: state to retrieve the color for
+ * @color: (out): location to store the light color
+ *
+ * Gets the light color of background color for a given state.
+ */
+void
+meta_color_get_light_color (GtkStyleContext *context,
+                            GtkStateFlags    state,
+                            GdkRGBA         *color)
+{
+  meta_color_get_background_color (context, state, color);
+  meta_color_shade (color, LIGHTNESS_MULT, color);
+}
+
+/**
+ * meta_color_get_dark_color:
+ * @context: a #GtkStyleContext
+ * @state: state to retrieve the color for
+ * @color: (out): location to store the dark color
+ *
+ * Gets the dark color of background color for a given state.
+ */
+void
+meta_color_get_dark_color (GtkStyleContext *context,
+                           GtkStateFlags    state,
+                           GdkRGBA         *color)
+{
+  meta_color_get_background_color (context, state, color);
+  meta_color_shade (color, DARKNESS_MULT, color);
+}
diff --git a/libmetacity/meta-color.h b/libmetacity/meta-color.h
new file mode 100644
index 0000000..effeb18
--- /dev/null
+++ b/libmetacity/meta-color.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2001 Havoc Pennington
+ * Copyright (C) 2016 Alberts Muktupāvels
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef META_COLOR_H
+#define META_COLOR_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+void meta_color_shade                (const GdkRGBA   *source,
+                                      const gdouble    factor,
+                                      GdkRGBA         *destination);
+
+void meta_color_get_background_color (GtkStyleContext *context,
+                                      GtkStateFlags    state,
+                                      GdkRGBA         *color);
+
+void meta_color_get_light_color      (GtkStyleContext *context,
+                                      GtkStateFlags    state,
+                                      GdkRGBA         *color);
+
+void meta_color_get_dark_color       (GtkStyleContext *context,
+                                      GtkStateFlags    state,
+                                      GdkRGBA         *color);
+
+G_END_DECLS
+
+#endif
diff --git a/libmetacity/meta-hsla.h b/libmetacity/meta-hsla.h
index 07959c2..b0f4bcc 100644
--- a/libmetacity/meta-hsla.h
+++ b/libmetacity/meta-hsla.h
@@ -31,12 +31,15 @@ typedef struct
   gdouble alpha;
 } MetaHSLA;
 
+G_GNUC_INTERNAL
 void meta_hsla_from_rgba (MetaHSLA       *hsla,
                           const GdkRGBA  *rgba);
 
+G_GNUC_INTERNAL
 void meta_hsla_to_rgba   (const MetaHSLA *hsla,
                           GdkRGBA        *rgba);
 
+G_GNUC_INTERNAL
 void meta_hsla_shade     (const MetaHSLA *source,
                           const gdouble   factor,
                           MetaHSLA       *destination);
diff --git a/src/ui/draw-workspace.c b/src/ui/draw-workspace.c
index ba29209..cad156c 100644
--- a/src/ui/draw-workspace.c
+++ b/src/ui/draw-workspace.c
@@ -23,6 +23,10 @@
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "config.h"
+
+#include <libmetacity/meta-color.h>
+
 #include "draw-workspace.h"
 #include "theme-private.h"
 
@@ -64,25 +68,6 @@ get_window_rect (const WnckWindowDisplayInfo *win,
 }
 
 static void
-get_background_color (GtkStyleContext *context,
-                      GtkStateFlags    state,
-                      GdkRGBA         *color)
-{
-  GdkRGBA *c;
-
-  g_return_if_fail (color != NULL);
-  g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
-
-  gtk_style_context_get (context,
-                         state,
-                         "background-color", &c,
-                         NULL);
-
-  *color = *c;
-  gdk_rgba_free (c);
-}
-
-static void
 draw_window (GtkWidget                   *widget,
              cairo_t                     *cr,
              const WnckWindowDisplayInfo *win,
@@ -104,9 +89,9 @@ draw_window (GtkWidget                   *widget,
 
   style = gtk_widget_get_style_context (widget);
   if (is_active)
-    meta_gtk_style_get_light_color (style, state, &color);
+    meta_color_get_light_color (style, state, &color);
   else
-    get_background_color (style, state, &color);
+    meta_color_get_background_color (style, state, &color);
   gdk_cairo_set_source_rgba (cr, &color);
 
   cairo_rectangle (cr,
@@ -213,7 +198,7 @@ wnck_draw_workspace (GtkWidget                   *widget,
     {
       GdkRGBA color;
 
-      meta_gtk_style_get_dark_color (style,state, &color);
+      meta_color_get_dark_color (style,state, &color);
       gdk_cairo_set_source_rgba (cr, &color);
 
       cairo_rectangle (cr, x, y, width, height);
diff --git a/src/ui/theme-private.h b/src/ui/theme-private.h
index 490bc33..66df5a5 100644
--- a/src/ui/theme-private.h
+++ b/src/ui/theme-private.h
@@ -863,13 +863,6 @@ PangoFontDescription  *meta_gtk_widget_get_font_desc           (GtkWidget
 int                    meta_pango_font_desc_get_text_height    (const PangoFontDescription  *font_desc,
                                                                 PangoContext                *context);
 
-void                   meta_gtk_style_get_light_color          (GtkStyleContext             *style,
-                                                                GtkStateFlags                state,
-                                                                GdkRGBA                     *color);
-void                   meta_gtk_style_get_dark_color           (GtkStyleContext             *style,
-                                                                GtkStateFlags                state,
-                                                                GdkRGBA                     *color);
-
 guint                  meta_theme_earliest_version_with_button (MetaButtonType               type);
 
 #define META_THEME_ALLOWS(theme, feature) (theme->format_version >= feature)
diff --git a/src/ui/theme.c b/src/ui/theme.c
index f90605b..946e73d 100644
--- a/src/ui/theme.c
+++ b/src/ui/theme.c
@@ -55,7 +55,7 @@
 #include "util.h"
 #include "gradient.h"
 #include <gtk/gtk.h>
-#include <libmetacity/meta-hsla.h>
+#include <libmetacity/meta-color.h>
 #include <string.h>
 #include <stdlib.h>
 #define __USE_XOPEN
@@ -1683,67 +1683,6 @@ meta_color_spec_new_gtk (MetaGtkColorComponent component,
 }
 
 static void
-get_background_color (GtkStyleContext *context,
-                      GtkStateFlags    state,
-                      GdkRGBA         *color)
-{
-  GdkRGBA *c;
-
-  g_return_if_fail (color != NULL);
-  g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
-
-  gtk_style_context_get (context,
-                         state,
-                         "background-color", &c,
-                         NULL);
-
-  *color = *c;
-  gdk_rgba_free (c);
-}
-
-/**
- * Takes a colour "a", scales the lightness and saturation by a certain amount,
- * and sets "b" to the resulting colour.
- * gtkstyle.c cut-and-pastage.
- *
- * \param a  the starting colour
- * \param b  [out] the resulting colour
- * \param k  amount to scale lightness and saturation by
- */
-static void
-gtk_style_shade (GdkRGBA *a,
-                 GdkRGBA *b,
-                 gdouble  k)
-{
-  MetaHSLA hsla;
-
-  meta_hsla_from_rgba (&hsla, a);
-  meta_hsla_shade (&hsla, k, &hsla);
-  meta_hsla_to_rgba (&hsla, b);
-}
-
-/* Based on set_color() in gtkstyle.c */
-#define LIGHTNESS_MULT 1.3
-#define DARKNESS_MULT  0.7
-void
-meta_gtk_style_get_light_color (GtkStyleContext *style,
-                                GtkStateFlags    state,
-                                GdkRGBA         *color)
-{
-  get_background_color (style, state, color);
-  gtk_style_shade (color, color, LIGHTNESS_MULT);
-}
-
-void
-meta_gtk_style_get_dark_color (GtkStyleContext *style,
-                               GtkStateFlags    state,
-                               GdkRGBA         *color)
-{
-  get_background_color (style, state, color);
-  gtk_style_shade (color, color, DARKNESS_MULT);
-}
-
-static void
 meta_set_color_from_style (GdkRGBA               *color,
                            GtkStyleContext       *context,
                            GtkStateFlags          state,
@@ -1757,7 +1696,7 @@ meta_set_color_from_style (GdkRGBA               *color,
     {
     case META_GTK_COLOR_BG:
     case META_GTK_COLOR_BASE:
-      get_background_color (context, state, color);
+      meta_color_get_background_color (context, state, color);
       break;
     case META_GTK_COLOR_FG:
     case META_GTK_COLOR_TEXT:
@@ -1772,18 +1711,18 @@ meta_set_color_from_style (GdkRGBA               *color,
       color->blue = (color->blue + other.blue) / 2;
       break;
     case META_GTK_COLOR_MID:
-      meta_gtk_style_get_light_color (context, state, color);
-      meta_gtk_style_get_dark_color (context, state, &other);
+      meta_color_get_light_color (context, state, color);
+      meta_color_get_dark_color (context, state, &other);
 
       color->red = (color->red + other.red) / 2;
       color->green = (color->green + other.green) / 2;
       color->blue = (color->blue + other.blue) / 2;
       break;
     case META_GTK_COLOR_LIGHT:
-      meta_gtk_style_get_light_color (context, state, color);
+      meta_color_get_light_color (context, state, color);
       break;
     case META_GTK_COLOR_DARK:
-      meta_gtk_style_get_dark_color (context, state, color);
+      meta_color_get_dark_color (context, state, color);
       break;
     case META_GTK_COLOR_LAST:
     default:
@@ -1849,8 +1788,8 @@ meta_color_spec_render (MetaColorSpec *spec,
         meta_color_spec_render (spec->data.shade.base, context,
                                 &spec->data.shade.color);
 
-        gtk_style_shade (&spec->data.shade.color,
-                         &spec->data.shade.color, spec->data.shade.factor);
+        meta_color_shade (&spec->data.shade.color, spec->data.shade.factor,
+                          &spec->data.shade.color);
 
         *color = spec->data.shade.color;
       }


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