grim/guifications3

moved gflib-ui to the new cmake module
cmake
2010-12-15, Gary Kramlich
47e19b83725e
moved gflib-ui to the new cmake module
/*
* Guifications - The end-all, be-all notification framework
* Copyright (C) 2003-2009 Gary Kramlich <grim@reaperworld.com>
*
* 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 3 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/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
#include <gflib/gf_intl.h>
#include <gflib-ui/gf_gc.h>
#define GF_GC_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), GF_TYPE_GC, GfGCPrivate))
/******************************************************************************
* Structs
*****************************************************************************/
typedef struct {
GfColormap *colormap;
gint clip_x_origin;
gint clip_y_origin;
gint ts_x_origin;
gint ts_y_origin;
} GfGCPrivate;
/******************************************************************************
* Enums
*****************************************************************************/
enum {
PROP_ZERO = 0,
PROP_COLORMAP,
PROP_LAST
};
/******************************************************************************
* Globals
*****************************************************************************/
static GfObjectClass *parent_class = NULL;
/******************************************************************************
* Object Stuff
*****************************************************************************/
static void
gf_gc_get_property(GObject *obj, guint param_id, GValue *value,
GParamSpec *pspec)
{
GfGC *gc = GF_GC(obj);
switch(param_id) {
case PROP_COLORMAP:
g_value_set_object(value, gf_gc_get_colormap(gc));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
break;
}
}
static void
gf_gc_set_property(GObject *obj, guint param_id, const GValue *value,
GParamSpec *pspec)
{
GfGC *gc = GF_GC(obj);
switch(param_id) {
case PROP_COLORMAP:
gf_gc_set_colormap(gc, g_value_get_object(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
break;
}
}
static void
gf_gc_finalize(GObject *obj) {
GfGCPrivate *priv = GF_GC_GET_PRIVATE(obj);
if(GF_IS_COLORMAP(priv->colormap))
g_object_unref(G_OBJECT(priv->colormap));
G_OBJECT_CLASS(parent_class)->finalize(obj);
}
static void
gf_gc_class_init(GfGCClass *klass) {
GObjectClass *obj_class = G_OBJECT_CLASS(klass);
GParamSpec *pspec;
parent_class = g_type_class_peek_parent(klass);
g_type_class_add_private(klass, sizeof(GfGCPrivate));
obj_class->finalize = gf_gc_finalize;
obj_class->get_property = gf_gc_get_property;
obj_class->set_property = gf_gc_set_property;
pspec = g_param_spec_object("colormap", P_("colormap"),
P_("The colormap for the gc"),
GF_TYPE_COLORMAP, G_PARAM_READWRITE);
g_object_class_install_property(obj_class, PROP_COLORMAP, pspec);
}
/******************************************************************************
* GfGC API
*****************************************************************************/
GType
gf_gc_get_gtype(void) {
static GType type = 0;
if(type == 0) {
static const GTypeInfo info = {
sizeof(GfGCClass),
NULL,
NULL,
(GClassInitFunc)gf_gc_class_init,
NULL,
NULL,
sizeof(GfGC),
0,
NULL,
NULL
};
type = g_type_register_static(GF_TYPE_OBJECT,
"GfGC",
&info, G_TYPE_FLAG_ABSTRACT);
}
return type;
}
/**
* gf_gc_new:
* @drawable : The #GfDrawable instance.
*
* Creates a new #GfGC from @drawable.
*
* Return Value: The new #GfGC.
*/
GfGC *
gf_gc_new(GfDrawable *drawable) {
g_return_val_if_fail(drawable, NULL);
return gf_gc_new_with_values(drawable, NULL, 0);
}
/**
* gf_gc_new_with_values:
* @drawable : The #GfDrawable instance.
* @values : The #GfGCValues.
* @mask : The #GfGCValuesMask.
*
* Creates a new #GfGC from @drawable using @values.
*
* Return Value: The new #GfGC.
*/
GfGC *
gf_gc_new_with_values(GfDrawable *drawable, GfGCValues *values,
GfGCValuesMask mask)
{
GfDrawableClass *klass = NULL;
GfGC *gc = NULL;
GfGCPrivate *priv = NULL;
g_return_val_if_fail(drawable, NULL);
klass = GF_DRAWABLE_GET_CLASS(drawable);
if(!klass)
return NULL;
if(!klass->create_gc)
return NULL;
gc = klass->create_gc(drawable, values, mask);
if(!gc)
return NULL;
priv = GF_GC_GET_PRIVATE(gc);
if(mask & GF_GC_CLIP_X_ORIGIN)
priv->clip_x_origin = values->clip_x_origin;
if(mask & GF_GC_CLIP_Y_ORIGIN)
priv->clip_y_origin = values->clip_y_origin;
if(mask & GF_GC_TS_X_ORIGIN)
priv->ts_x_origin = values->ts_x_origin;
if(mask & GF_GC_TS_Y_ORIGIN)
priv->ts_y_origin = values->ts_y_origin;
/* if the drawable didn't set the colormap on creation, set it now */
if(!GF_IS_COLORMAP(priv->colormap))
gf_gc_set_colormap(gc, gf_drawable_get_colormap(drawable));
return gc;
}
/**
* gf_gc_get_values:
* @gc : The #GfGC instance.
* @values : The return address for the #GfGCValues.
*
* Gets the #GfGCValues from @gc.
*/
void
gf_gc_get_values(GfGC *gc, GfGCValues *values) {
GfGCClass *klass;
g_return_if_fail(GF_IS_GC(gc));
g_return_if_fail(values);
klass = GF_GC_GET_CLASS(gc);
if(klass && klass->get_values)
klass->get_values(gc, values);
}
/**
* gf_gc_set_values:
* @gc : The #GfGC instance.
* @values : The #GfGCValues.
* @mask : The #GfGCValuesMask.
*
* Sets the #GfGCValues for @gc.
*/
void
gf_gc_set_values(GfGC *gc, GfGCValues *values, GfGCValuesMask mask) {
GfGCClass *klass = NULL;
GfGCPrivate *priv = NULL;
g_return_if_fail(GF_IS_GC(gc));
g_return_if_fail(values);
priv = GF_GC_GET_PRIVATE(gc);
if(mask & GF_GC_CLIP_X_ORIGIN)
priv->clip_x_origin = values->clip_x_origin;
if(mask & GF_GC_CLIP_Y_ORIGIN)
priv->clip_y_origin = values->clip_y_origin;
if(mask & GF_GC_TS_X_ORIGIN)
priv->ts_x_origin = values->ts_x_origin;
if(mask & GF_GC_TS_Y_ORIGIN)
priv->ts_y_origin = values->ts_y_origin;
klass = GF_GC_GET_CLASS(gc);
if(klass && klass->set_values)
klass->set_values(gc, values, mask);
}
/**
* gf_gc_set_foreground:
* @gc : The #GfGC instance.
* @color : The new foreground color.
*
* Sets the foreground color for @gc.
*/
void
gf_gc_set_foreground(GfGC *gc, const GfColor *color) {
GfGCValues values;
g_return_if_fail(GF_IS_GC(gc));
g_return_if_fail(color);
values.foreground = *color;
gf_gc_set_values(gc, &values, GF_GC_FOREGROUND);
}
/**
* gf_gc_set_background:
* @gc : The #GfGC instance.
* @color : The new background color.
*
* Sets the background color for @gc.
*/
void
gf_gc_set_background(GfGC *gc, const GfColor *color) {
GfGCValues values;
g_return_if_fail(GF_IS_GC(gc));
g_return_if_fail(color);
values.background = *color;
gf_gc_set_values(gc, &values, GF_GC_BACKGROUND);
}
/**
* gf_gc_set_font:
* @gc : The #GfGC instance.
* @font : The new font.
*
* Sets the font for @gc.
*/
void
gf_gc_set_font(GfGC *gc, const GfFont *font) {
GfGCValues values;
g_return_if_fail(GF_IS_GC(gc));
g_return_if_fail(font);
values.font = gf_font_copy(font);
gf_gc_set_values(gc, &values, GF_GC_FONT);
gf_font_free(values.font);
}
/**
* gf_gc_set_function:
* @gc : The #GfGC instance.
* @function : The new function.
*
* Sets the function for @gc.
*/
void
gf_gc_set_function(GfGC *gc, GfFunction function) {
GfGCValues values;
g_return_if_fail(GF_IS_GC(gc));
values.function = function;
gf_gc_set_values(gc, &values, GF_GC_FUNCTION);
}
/**
* gf_gc_set_fill:
* @gc : The #GfGC instance.
* @fill : The new fill.
*
* Sets the fill for @gc.
*/
void
gf_gc_set_fill(GfGC *gc, GfFill fill) {
GfGCValues values;
g_return_if_fail(GF_IS_GC(gc));
values.fill = fill;
gf_gc_set_values(gc, &values, GF_GC_FILL);
}
/**
* gf_gc_set_tile:
* @gc : The #GfGC instance.
* @tile : The new tile.
*
* Sets the tile for @gc.
*/
void
gf_gc_set_tile(GfGC *gc, GfDrawable *tile) {
GfGCValues values;
g_return_if_fail(GF_IS_GC(gc));
values.tile = tile;
gf_gc_set_values(gc, &values, GF_GC_TILE);
}
/**
* gf_gc_set_stipple:
* @gc : The #GfGC instance.
* @stipple : The new stipple.
*
* Sets the stiplle for @gc.
*/
void
gf_gc_set_stipple(GfGC *gc, GfDrawable *stipple) {
GfGCValues values;
g_return_if_fail(GF_IS_GC(gc));
values.stipple = stipple;
gf_gc_set_values(gc, &values, GF_GC_STIPPLE);
}
/**
* gf_gc_set_ts_origin:
* @gc : The #GfGC instance.
* @x : The x-coordinate.
* @y : The y-coordinate.
*
* Sets the tile/stipple origin for @gc.
*/
void
gf_gc_set_ts_origin(GfGC *gc, gint x, gint y) {
GfGCValues values;
g_return_if_fail(GF_IS_GC(gc));
values.ts_x_origin = x;
values.ts_y_origin = y;
gf_gc_set_values(gc, &values, GF_GC_TS_X_ORIGIN | GF_GC_TS_Y_ORIGIN);
}
/**
* gf_gc_set_clip_origin:
* @gc : The #GfGC instance.
* @x : The x-coordinate.
* @y : The y-coordinate.
*
* Sets the clip origin for @gc.
*/
void
gf_gc_set_clip_origin(GfGC *gc, gint x, gint y) {
GfGCValues values;
g_return_if_fail(GF_IS_GC(gc));
values.clip_x_origin = x;
values.clip_y_origin = y;
gf_gc_set_values(gc, &values, GF_GC_CLIP_X_ORIGIN | GF_GC_CLIP_Y_ORIGIN);
}
/**
* gf_gc_set_clip_mask:
* @gc : The #GfGC instance.
* @mask : The new clip mask.
*
* Sets the clip mask for @gc.
*/
void
gf_gc_set_clip_mask(GfGC *gc, GfDrawable *mask) {
GfGCValues values;
g_return_if_fail(GF_IS_GC(gc));
values.clip_mask = mask;
gf_gc_set_values(gc, &values, GF_GC_CLIP_MASK);
}
/**
* gf_gc_set_subwindow:
* @gc : The #GfGC instance.
* @mode : The new subwindow mode.
*
* Sets the subwindow mode for @gc.
*/
void
gf_gc_set_subwindow(GfGC *gc, GfSubwindowMode mode) {
GfGCValues values;
g_return_if_fail(GF_IS_GC(gc));
values.subwindow_mode = mode;
gf_gc_set_values(gc, &values, GF_GC_SUBWINDOW);
}
/**
* gf_gc_set_exposures:
* @gc : The #GfGC instance.
* @exposures : The new exposures.
*
* Sets exposures for @gc.
*/
void
gf_gc_set_exposures(GfGC *gc, gboolean exposures) {
GfGCValues values;
g_return_if_fail(GF_IS_GC(gc));
values.exposures = exposures;
gf_gc_set_values(gc, &values, GF_GC_EXPOSURES);
}
/**
* gf_gc_set_line_attributes:
* @gc : The #GfGC instance.
* @line_width : The new line width.
* @line_style : The new line style.
* @cap_style : The new cap style.
* @join_style : The new join style.
*
* Sets the line attributes for @gc.
*/
void
gf_gc_set_line_attributes(GfGC *gc, gint line_width, GfLineStyle line_style,
GfCapStyle cap_style, GfJoinStyle join_style)
{
GfGCValues values;
g_return_if_fail(GF_IS_GC(gc));
values.line_width = line_width;
values.line_style = line_style;
values.cap_style = cap_style;
values.join_style = join_style;
gf_gc_set_values(gc, &values, GF_GC_LINE_WIDTH | GF_GC_LINE_STYLE |
GF_GC_CAP_STYLE | GF_GC_JOIN_STYLE);
}
/**
* gf_gc_set_colormap:
* @gc : The #GfGC instance.
* @colormap : The new colormap.
*
* Sets the colormap for @gc.
*/
void
gf_gc_set_colormap(GfGC *gc, GfColormap *colormap) {
GfGCPrivate *priv = NULL;
g_return_if_fail(GF_IS_GC(gc));
g_return_if_fail(GF_IS_COLORMAP(colormap));
priv = GF_GC_GET_PRIVATE(gc);
if(colormap != priv->colormap) {
if(GF_IS_COLORMAP(priv->colormap))
g_object_unref(G_OBJECT(priv->colormap));
priv->colormap = colormap;
g_object_ref(G_OBJECT(priv->colormap));
g_object_notify(G_OBJECT(gc), "colormap");
}
}
/**
* gf_gc_get_colormap:
* @gc : The #GfGC instance.
*
* Gets the colormap for @gc.
*
* Return Value: The colormap for @gc.
*/
GfColormap *
gf_gc_get_colormap(const GfGC *gc) {
GfGCPrivate *priv = NULL;
g_return_val_if_fail(GF_IS_GC(gc), NULL);
priv = GF_GC_GET_PRIVATE(gc);
return priv->colormap;
}
/******************************************************************************
* GfCapStyle API
*****************************************************************************/
GType
gf_cap_style_get_gtype() {
static GType type = 0;
if(type == 0) {
static const GEnumValue values[] = {
{ GF_CAP_NOT_LAST, N_("Cap Not Last"), N_("Cap Not Last") },
{ GF_CAP_BUTT, N_("Cap Butt"), N_("Cap Butt") },
{ GF_CAP_ROUND, N_("Cap Round"), N_("Cap Round") },
{ GF_CAP_PROJECTING, N_("Cap Projecting"), N_("Cap Projecting") },
{ 0, NULL, NULL },
};
type = g_enum_register_static("GfCapStyle", values);
}
return type;
}
/******************************************************************************
* GfFill API
*****************************************************************************/
GType
gf_fill_get_gtype() {
static GType type = 0;
if(type == 0) {
static const GEnumValue values[] = {
{ GF_SOLID, N_("Solid"), N_("Solid") },
{ GF_TILED, N_("Tiled"), N_("Tiled") },
{ GF_STIPPLED, N_("Stippled"), N_("Stippled") },
{
GF_OPAQUE_STIPPLED,
N_("Opaque Stippled"),
N_("Opaque Stippled")
},
{ 0, NULL, NULL },
};
type = g_enum_register_static("GfFill", values);
}
return type;
}
/******************************************************************************
* GfFunction API
*****************************************************************************/
GType
gf_function_get_gtype() {
static GType type = 0;
if(type == 0) {
static const GEnumValue values[] = {
{ GF_COPY, N_("Copy"), N_("Copy") },
{ GF_INVERT, N_("Invert"), N_("Invert") },
{ GF_XOR, N_("XOR"), N_("XOR") },
{ GF_CLEAR, N_("Clear"), N_("Clear") },
{ GF_AND, N_("AND"), N_("AND") },
{ GF_AND_REVERSE, N_("AND Reverse"), N_("AND Reverse") },
{ GF_AND_INVERT, N_("AND Invert"), N_("AND Invert") },
{ GF_NOOP, N_("NOOP"), N_("NOOP") },
{ GF_OR, N_("OR"), N_("OR") },
{ GF_EQUIV, N_("EQUIV"), N_("EQUIV") },
{ GF_OR_REVERSE, N_("OR Reverse"), N_("OR Reverse") },
{ GF_COPY_INVERT, N_("Copy Invert"), N_("Copy Invert") },
{ GF_OR_INVERT, N_("OR Invert"), N_("OR Invert") },
{ GF_NAND, N_("NAND"), N_("NAND") },
{ GF_NOR, N_("NOR"), N_("NOR") },
{ GF_SET, N_("Set"), N_("Set") },
{ 0, NULL, NULL },
};
type = g_enum_register_static("GfFunction", values);
}
return type;
}
/******************************************************************************
* GfJoinStyle API
*****************************************************************************/
GType
gf_join_style_get_gtype() {
static GType type = 0;
if(type == 0) {
static const GEnumValue values[] = {
{ GF_JOIN_MITER, N_("Join Miter"), N_("Join Miter") },
{ GF_JOIN_ROUND, N_("Join Round"), N_("Join Round") },
{ GF_JOIN_BEVEL, N_("Bevel"), N_("Bevel") },
{ 0, NULL, NULL },
};
type = g_enum_register_static("GfJoinStyle", values);
}
return type;
}
/******************************************************************************
* GfLineStyle API
*****************************************************************************/
GType
gf_line_style_get_gtype() {
static GType type = 0;
if(type == 0) {
static const GEnumValue values[] = {
{ GF_LINE_SOLID, N_("Solid"), N_("Solid") },
{ GF_LINE_ON_OFF_DASH, N_("On Off Dash"), N_("On Off Dash") },
{ GF_LINE_DOUBLE_DASH, N_("Double Dash"), N_("Double Dash") },
{ 0, NULL, NULL },
};
type = g_enum_register_static("GfLineStyle", values);
}
return type;
}
/******************************************************************************
* GfSubwindowMode API
*****************************************************************************/
GType
gf_subwindow_mode_get_gtype() {
static GType type = 0;
if(type == 0) {
static const GEnumValue values[] = {
{
GF_CLIP_BY_CHILDREN,
N_("Clip By Children"),
N_("Clip By Children")
},
{
GF_INCLUDE_INFERIORS,
N_("Include Inferiors"),
N_("Include Inferiors") },
{ 0, NULL, NULL },
};
type = g_enum_register_static("GfSubwindowMode", values);
}
return type;
}
/******************************************************************************
* GfGCValuesMask API
*****************************************************************************/
GType
gf_gc_values_maks_get_gtype() {
static GType type = 0;
if(type == 0) {
static const GEnumValue values[] = {
{ GF_GC_FOREGROUND, N_("Foreground"), N_("Foreground") },
{ GF_GC_BACKGROUND, N_("Background"), N_("Background") },
{ GF_GC_FONT, N_("Font"), N_("Font") },
{ GF_GC_FUNCTION, N_("Function"), N_("Function") },
{ GF_GC_FILL, N_("Fill"), N_("Fill") },
{ GF_GC_TILE, N_("Tile"), N_("Tile") },
{ GF_GC_STIPPLE, N_("Stipple"), N_("Stipple") },
{ GF_GC_CLIP_MASK, N_("Clip Mask"), N_("Clip Mask") },
{ GF_GC_SUBWINDOW, N_("Sub Window"), N_("Sub Window") },
{ GF_GC_TS_X_ORIGIN, N_("TS X Origin"), N_("TS X Origin") },
{ GF_GC_TS_Y_ORIGIN, N_("TS Y Origin"), N_("TS Y Origin") },
{ GF_GC_CLIP_X_ORIGIN, N_("Clip X Origin"), N_("Clip X Origin") },
{ GF_GC_CLIP_Y_ORIGIN, N_("Clip Y Origin"), N_("Clip Y Origin") },
{ GF_GC_EXPOSURES, N_("Exposures"), N_("Exposures") },
{ GF_GC_LINE_WIDTH, N_("Line Width"), N_("Line Width") },
{ GF_GC_LINE_STYLE, N_("Line Style"), N_("Line Style") },
{ GF_GC_CAP_STYLE, N_("Cap Style"), N_("Cap Style") },
{ GF_GC_JOIN_STYLE, N_("Join Style"), N_("Join Style") },
{ 0, NULL, NULL },
};
type = g_enum_register_static("GfGCValuesMask", values);
}
return type;
}
/******************************************************************************
* GfGCValues API
*****************************************************************************/
static GfGCValues *
gf_gc_values_copy(const GfGCValues *values) {
GfGCValues *v = g_new0(GfGCValues, 1);
*v = *values;
if(v->font)
v->font = gf_font_copy(values->font);
return v;
}
static void
gf_gc_values_free(GfGCValues *values) {
gf_font_free(values->font);
g_free(values);
}
GType
gf_gc_values_get_gtype() {
static GType type = 0;
if(type == 0) {
type =
g_boxed_type_register_static("GfGCValues",
(GBoxedCopyFunc)gf_gc_values_copy,
(GBoxedFreeFunc)gf_gc_values_free);
}
return type;
}