Commit 7094213d authored by Carlos Garnacho's avatar Carlos Garnacho
Browse files

Add GtkSymbolicColor.

This is a small boxed struct used to store symbolic colors so they
can be resolved at a later point.
parent d748ea98
......@@ -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 \
......
/* 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"
/* 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__ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment