[gtk+/gtk-style-context: 105/540] Add GtkSymbolicColor.



commit c31113e576cd2302d0b36cd668e31294373b6973
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Jun 25 19:29:51 2010 +0200

    Add GtkSymbolicColor.
    
    This is a small boxed struct used to store symbolic colors so they
    can be resolved at a later point.

 gtk/Makefile.am        |    2 +
 gtk/gtksymboliccolor.c |  153 ++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtksymboliccolor.h |   49 +++++++++++++++
 3 files changed, 204 insertions(+), 0 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 918e632..0d4de06 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -297,6 +297,7 @@ gtk_public_h_sources =          \
 	gtkstyleset.h		\
 	gtkstyle.h		\
 	gtkswitch.h		\
+	gtksymboliccolor.h	\
 	gtktable.h		\
 	gtktearoffmenuitem.h    \
 	gtktestutils.h		\
@@ -599,6 +600,7 @@ gtk_base_c_sources =            \
 	gtkstyleset.c		\
 	gtkstyle.c		\
 	gtkswitch.c		\
+	gtksymboliccolor.c	\
 	gtktable.c		\
 	gtktearoffmenuitem.c    \
 	gtktestutils.c		\
diff --git a/gtk/gtksymboliccolor.c b/gtk/gtksymboliccolor.c
new file mode 100644
index 0000000..7a8513d
--- /dev/null
+++ b/gtk/gtksymboliccolor.c
@@ -0,0 +1,153 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2010 Carlos Garnacho <carlosg gnome org>
+ *
+ * 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 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+#include "gtksymboliccolor.h"
+#include "gtkstyleset.h"
+#include "gtkintl.h"
+
+/* Symbolic colors */
+typedef enum {
+  COLOR_TYPE_LITERAL,
+  COLOR_TYPE_NAME,
+  COLOR_TYPE_SHADE,
+  COLOR_TYPE_MIX
+} ColorType;
+
+struct GtkSymbolicColor
+{
+  ColorType type;
+  guint ref_count;
+
+  union
+  {
+    GdkColor color;
+    gchar *name;
+
+    struct
+    {
+      GtkSymbolicColor *color;
+      gdouble factor;
+    } shade;
+
+    struct
+    {
+      GtkSymbolicColor *color1;
+      GtkSymbolicColor *color2;
+      gdouble factor;
+    } mix;
+  };
+};
+
+GtkSymbolicColor *
+gtk_symbolic_color_new_literal (GdkColor *color)
+{
+  GtkSymbolicColor *symbolic_color;
+
+  g_return_val_if_fail (color != NULL, NULL);
+
+  symbolic_color = g_slice_new0 (GtkSymbolicColor);
+  symbolic_color->type = COLOR_TYPE_LITERAL;
+  symbolic_color->color = *color;
+
+  return symbolic_color;
+}
+
+GtkSymbolicColor *
+gtk_symbolic_color_new_name (const gchar *name)
+{
+  GtkSymbolicColor *symbolic_color;
+
+  g_return_val_if_fail (name != NULL, NULL);
+
+  symbolic_color = g_slice_new0 (GtkSymbolicColor);
+  symbolic_color->type = COLOR_TYPE_NAME;
+  symbolic_color->name = g_strdup (name);
+
+  return symbolic_color;
+}
+
+GtkSymbolicColor *
+gtk_symbolic_color_new_shade (GtkSymbolicColor *color,
+                              gdouble           factor)
+{
+  GtkSymbolicColor *symbolic_color;
+
+  g_return_val_if_fail (color != NULL, NULL);
+
+  symbolic_color = g_slice_new0 (GtkSymbolicColor);
+  symbolic_color->type = COLOR_TYPE_SHADE;
+  symbolic_color->shade.color = gtk_symbolic_color_ref (color);
+  symbolic_color->shade.factor = CLAMP (factor, 0, 1);
+
+  return symbolic_color;
+}
+
+GtkSymbolicColor *
+gtk_symbolic_color_new_mix (GtkSymbolicColor *color1,
+                            GtkSymbolicColor *color2,
+                            gdouble           factor)
+{
+  GtkSymbolicColor *symbolic_color;
+
+  g_return_val_if_fail (color1 != NULL, NULL);
+  g_return_val_if_fail (color1 != NULL, NULL);
+
+  symbolic_color = g_slice_new0 (GtkSymbolicColor);
+  symbolic_color->type = COLOR_TYPE_MIX;
+  symbolic_color->mix.color1 = gtk_symbolic_color_ref (color1);
+  symbolic_color->mix.color2 = gtk_symbolic_color_ref (color2);
+  symbolic_color->mix.factor = CLAMP (factor, 0, 1);
+
+  return symbolic_color;
+}
+
+GtkSymbolicColor *
+gtk_symbolic_color_ref (GtkSymbolicColor *color)
+{
+  g_return_val_if_fail (color != NULL, NULL);
+
+  color->ref_count++;
+
+  return color;
+}
+
+void
+gtk_symbolic_color_unref (GtkSymbolicColor *color)
+{
+  g_return_if_fail (color != NULL);
+
+  color->ref_count--;
+}
+
+GType
+gtk_symbolic_color_get_type (void)
+{
+  static GType type = 0;
+
+  if (G_UNLIKELY (!type))
+    type = g_boxed_type_register_static (I_("GtkSymbolicColor"),
+					 (GBoxedCopyFunc) gtk_symbolic_color_ref,
+					 (GBoxedFreeFunc) gtk_symbolic_color_unref);
+
+  return type;
+}
+
+#define __GTK_SYMBOLIC_COLOR_C__
+#include "gtkaliasdef.c"
diff --git a/gtk/gtksymboliccolor.h b/gtk/gtksymboliccolor.h
new file mode 100644
index 0000000..e72cec1
--- /dev/null
+++ b/gtk/gtksymboliccolor.h
@@ -0,0 +1,49 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2010 Carlos Garnacho <carlosg gnome org>
+ *
+ * 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 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GTK_SYMBOLIC_COLOR_H__
+#define __GTK_SYMBOLIC_COLOR_H__
+
+#include <gdk.h>
+//#include "gtkstyleset.h"
+
+G_BEGIN_DECLS
+
+/* Dummy typedefs */
+typedef struct GtkSymbolicColor GtkSymbolicColor;
+typedef struct GtkSymbolicColorMap GtkSymbolicColorMap;
+
+#define GTK_TYPE_SYMBOLIC_COLOR (gtk_symbolic_color_get_type ())
+
+GType gtk_symbolic_color_get_type (void) G_GNUC_CONST;
+
+GtkSymbolicColor * gtk_symbolic_color_new_literal (GdkColor         *color);
+GtkSymbolicColor * gtk_symbolic_color_new_name    (const gchar      *name);
+GtkSymbolicColor * gtk_symbolic_color_new_shade   (GtkSymbolicColor *color,
+                                                   gdouble           factor);
+GtkSymbolicColor * gtk_symbolic_color_new_mix     (GtkSymbolicColor *color1,
+                                                   GtkSymbolicColor *color2,
+                                                   gdouble           factor);
+
+GtkSymbolicColor * gtk_symbolic_color_ref   (GtkSymbolicColor *color);
+void               gtk_symbolic_color_unref (GtkSymbolicColor *color);
+
+G_END_DECLS
+
+#endif /* __GTK_SYMBOLIC_COLOR_H__ */



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