grim/guifications3
Clone
Summary
Browse
Changes
Graph
start of converting gflib-ui/tests/testcolor.c to gtester
2010-12-20, Gary Kramlich
59b11e0f9116
start of converting gflib-ui/tests/testcolor.c to gtester
refs #674
/*
* 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-ui/gf_drawable.h>
/******************************************************************************
* Structs
*****************************************************************************/
/******************************************************************************
* Globals
*****************************************************************************/
static
GfObjectClass
*
parent_class
=
NULL
;
/******************************************************************************
* Object Stuff
*****************************************************************************/
static
void
gf_drawable_class_init
(
GfDrawableClass
*
klass
)
{
parent_class
=
g_type_class_peek_parent
(
klass
);
}
/******************************************************************************
* Drawable API
*****************************************************************************/
GType
gf_drawable_get_gtype
(
void
)
{
static
GType
type
=
0
;
if
(
type
==
0
)
{
static
const
GTypeInfo
info
=
{
sizeof
(
GfDrawableClass
),
NULL
,
NULL
,
(
GClassInitFunc
)
gf_drawable_class_init
,
NULL
,
NULL
,
sizeof
(
GfDrawable
),
0
,
NULL
,
};
type
=
g_type_register_static
(
GF_TYPE_OBJECT
,
"GfDrawable"
,
&
info
,
G_TYPE_FLAG_ABSTRACT
);
}
return
type
;
}
/**
* gf_drawable_get_size:
* @drawable : The #GfDrawable instance.
* @width : The return address for the width of @drawable.
* @height : The return address for the height of @drawable.
*
* Gets the size of @drawable.
*/
void
gf_drawable_get_size
(
const
GfDrawable
*
drawable
,
gint
*
width
,
gint
*
height
)
{
GfDrawableClass
*
klass
;
g_return_if_fail
(
GF_IS_DRAWABLE
(
drawable
));
klass
=
GF_DRAWABLE_GET_CLASS
(
drawable
);
if
(
klass
&&
klass
->
get_size
)
klass
->
get_size
(
drawable
,
width
,
height
);
}
/**
* gf_drawable_get_depth:
* @drawable : The #GfDrawable instance.
*
* Gets the color depth of @drawable.
*
* Return Value: The color depth of @drawable.
*/
gint
gf_drawable_get_depth
(
const
GfDrawable
*
drawable
)
{
GfDrawableClass
*
klass
;
g_return_val_if_fail
(
GF_IS_DRAWABLE
(
drawable
),
-1
);
klass
=
GF_DRAWABLE_GET_CLASS
(
drawable
);
if
(
klass
&&
klass
->
get_depth
)
return
klass
->
get_depth
(
drawable
);
return
-1
;
}
/**
* gf_drawable_get_colormap:
* @drawable : The #GfDrawable instance.
*
* Gets the #GfColormap for @drawable.
*
* Return Value: The #GfColormap for @drawable.
*/
GfColormap
*
gf_drawable_get_colormap
(
const
GfDrawable
*
drawable
)
{
GfDrawableClass
*
klass
;
g_return_val_if_fail
(
GF_IS_DRAWABLE
(
drawable
),
NULL
);
klass
=
GF_DRAWABLE_GET_CLASS
(
drawable
);
if
(
klass
&&
klass
->
get_colormap
)
return
klass
->
get_colormap
(
drawable
);
return
NULL
;
}
/**
* gf_drawable_set_colormap:
* @drawable : The #GfDrawable instance.
* @colormap : The #GfColormap instance.
*
* Sets the colormap of @drawable.
*/
void
gf_drawable_set_colormap
(
GfDrawable
*
drawable
,
GfColormap
*
colormap
)
{
GfDrawableClass
*
klass
;
g_return_if_fail
(
GF_IS_DRAWABLE
(
drawable
));
klass
=
GF_DRAWABLE_GET_CLASS
(
drawable
);
if
(
klass
&&
klass
->
set_colormap
)
klass
->
set_colormap
(
drawable
,
colormap
);
}
/******************************************************************************
* Drawing API
*****************************************************************************/
/**
* gf_draw_point;
* @drawable : The #GfDrawable instance.
* @gc : The #GfGC instance.
* @x : The x-coordinate.
* @y : The y-coordinate.
*
* Draws a point at @x, @y on @drawable.
*/
void
gf_draw_point
(
GfDrawable
*
drawable
,
GfGC
*
gc
,
gint
x
,
gint
y
)
{
GfDrawableClass
*
klass
;
g_return_if_fail
(
GF_IS_DRAWABLE
(
drawable
));
g_return_if_fail
(
GF_IS_GC
(
gc
));
klass
=
GF_DRAWABLE_GET_CLASS
(
drawable
);
if
(
klass
&&
klass
->
draw_points
)
{
GfPoint
point
;
point
.
x
=
x
;
point
.
y
=
y
;
klass
->
draw_points
(
drawable
,
gc
,
&
point
,
1
);
}
}
/**
* gf_draw_line:
* @drawable : The #GfDrawable instance.
* @gc : The #GfGC instance.
* @x1 : The starting x-coordinate.
* @y1 : The starting y-coordinate.
* @x2 : The ending x-coordinate.
* @y2 : The ending y-coordinate.
*
* Draws a line on @drawable.
*/
void
gf_draw_line
(
GfDrawable
*
drawable
,
GfGC
*
gc
,
gint
x1
,
gint
y1
,
gint
x2
,
gint
y2
)
{
GfDrawableClass
*
klass
;
g_return_if_fail
(
GF_IS_DRAWABLE
(
drawable
));
g_return_if_fail
(
GF_IS_GC
(
gc
));
klass
=
GF_DRAWABLE_GET_CLASS
(
drawable
);
if
(
klass
&&
klass
->
draw_segments
)
{
GfSegment
segment
;
segment
.
x1
=
x1
;
segment
.
y1
=
y1
;
segment
.
x2
=
x2
;
segment
.
y2
=
y2
;
klass
->
draw_segments
(
drawable
,
gc
,
&
segment
,
1
);
}
}
/**
* gf_draw_rectangle:
* @drawable : The #GfDrawable instance.
* @gc : The #GfGC instance.
* @filled : Whether or not to fill the rectangle.
* @x : The x-coordinate of the rectangle.
* @y : The y-coordinate of the rectangle.
* @width : The width of the rectangle.
* @height : The height of the rectangle.
*
* Draws a rectangle on @drawable.
*/
void
gf_draw_rectangle
(
GfDrawable
*
drawable
,
GfGC
*
gc
,
gboolean
filled
,
gint
x
,
gint
y
,
gint
width
,
gint
height
)
{
GfDrawableClass
*
klass
;
g_return_if_fail
(
GF_IS_DRAWABLE
(
drawable
));
g_return_if_fail
(
GF_IS_GC
(
gc
));
klass
=
GF_DRAWABLE_GET_CLASS
(
drawable
);
if
(
klass
&&
klass
->
draw_rectangle
)
{
if
(
width
<
0
||
height
<
0
)
{
gint
w
,
h
;
gf_drawable_get_size
(
drawable
,
&
w
,
&
h
);
if
(
width
<
0
)
width
=
w
;
if
(
height
<
0
)
height
=
h
;
}
klass
->
draw_rectangle
(
drawable
,
gc
,
filled
,
x
,
y
,
width
,
height
);
}
}
/**
* gf_draw_arc:
* @drawable : The #GfDrawable instance.
* @gc : The #GfGC instance.
* @filled : Whether or not to fill the arc.
* @x : The x-coordinate of the arc.
* @y : The y-coordinate of the arc.
* @width : The width of the arc.
* @height : The height of the arc.
* @angle1 : The starting angle.
* @angle2 : The ending angle.
*
* Draws an arc on @drawable.
*/
void
gf_draw_arc
(
GfDrawable
*
drawable
,
GfGC
*
gc
,
gboolean
filled
,
gint
x
,
gint
y
,
gint
width
,
gint
height
,
gint
angle1
,
gint
angle2
)
{
GfDrawableClass
*
klass
;
g_return_if_fail
(
GF_IS_DRAWABLE
(
drawable
));
g_return_if_fail
(
GF_IS_GC
(
gc
));
klass
=
GF_DRAWABLE_GET_CLASS
(
drawable
);
if
(
klass
&&
klass
->
draw_arc
)
{
if
(
width
<
0
||
height
<
0
)
{
gint
w
,
h
;
gf_drawable_get_size
(
drawable
,
&
w
,
&
h
);
if
(
width
<
0
)
width
=
w
;
if
(
height
<
0
)
height
=
h
;
}
klass
->
draw_arc
(
drawable
,
gc
,
filled
,
x
,
y
,
width
,
height
,
angle1
,
angle2
);
}
}
/**
* gf_draw_polygon:
* @drawable : The #GfDrawable instance.
* @gc : The #GfGC instance.
* @filled : Whether or not to fill the polygon.
* @points : The #GfPoint's in the polygon.
* @npoints : The number of @points.
*
* Draws a polygon on @drawable.
*/
void
gf_draw_polygon
(
GfDrawable
*
drawable
,
GfGC
*
gc
,
gboolean
filled
,
GfPoint
*
points
,
gint
npoints
)
{
GfDrawableClass
*
klass
;
g_return_if_fail
(
GF_IS_DRAWABLE
(
drawable
));
g_return_if_fail
(
GF_IS_GC
(
gc
));
klass
=
GF_DRAWABLE_GET_CLASS
(
drawable
);
if
(
klass
&&
klass
->
draw_polygon
)
klass
->
draw_polygon
(
drawable
,
gc
,
filled
,
points
,
npoints
);
}
/**
* gf_draw_text:
* @drawable : The #GfDrawable instance.
* @font : The #GfFont instance.
* @gc : The #GfGC instance.
* @x : The x-coordinate for the text.
* @y : The y-coordinate for the text.
* @text : The text to draw.
* @text_len : The length of @text.
*
* Draws @text on @drawable.
*/
void
gf_draw_text
(
GfDrawable
*
drawable
,
const
GfFont
*
font
,
GfGC
*
gc
,
gint
x
,
gint
y
,
const
gchar
*
text
,
gint
text_len
)
{
GfDrawableClass
*
klass
;
g_return_if_fail
(
GF_IS_DRAWABLE
(
drawable
));
g_return_if_fail
(
font
);
g_return_if_fail
(
GF_IS_GC
(
gc
));
g_return_if_fail
(
text
);
klass
=
GF_DRAWABLE_GET_CLASS
(
drawable
);
if
(
klass
&&
klass
->
draw_text
)
klass
->
draw_text
(
drawable
,
font
,
gc
,
x
,
y
,
text
,
text_len
);
}
/**
* gf_draw_drawable:
* @drawable : The #GfDrawable instance.
* @gc : The #GfGC instance.
* @src : The #GfDrawable to draw from.
* @xsrc : The x-coordinate of @src.
* @ysrc : The y-coordinate of @src.
* @xdest : The x-coordinate for @drawable.
* @ydest : The y-coordinate for @drawable.
* @width : The width of @src to draw.
* @height : The height of @src to draw.
*
* Draws @src to @drawable.
*/
void
gf_draw_drawable
(
GfDrawable
*
drawable
,
GfGC
*
gc
,
GfDrawable
*
src
,
gint
xsrc
,
gint
ysrc
,
gint
xdest
,
gint
ydest
,
gint
width
,
gint
height
)
{
GfDrawableClass
*
klass
;
g_return_if_fail
(
GF_IS_DRAWABLE
(
drawable
));
g_return_if_fail
(
GF_IS_GC
(
gc
));
g_return_if_fail
(
GF_IS_DRAWABLE
(
src
));
klass
=
GF_DRAWABLE_GET_CLASS
(
drawable
);
if
(
klass
&&
klass
->
draw_drawable
)
klass
->
draw_drawable
(
drawable
,
gc
,
src
,
xsrc
,
ysrc
,
xdest
,
ydest
,
width
,
height
);
}
/**
* gf_draw_points:
* @drawable : The #GfDrawable instance.
* @gc : The #GfGC instance.
* @points : An array of #GfPoint's.
* @npoints : The number of @points.
*
* Draws a number of points on @drawable.
*/
void
gf_draw_points
(
GfDrawable
*
drawable
,
GfGC
*
gc
,
GfPoint
*
points
,
gint
npoints
)
{
GfDrawableClass
*
klass
;
g_return_if_fail
(
GF_IS_DRAWABLE
(
drawable
));
g_return_if_fail
(
GF_IS_GC
(
gc
));
g_return_if_fail
(
points
);
g_return_if_fail
(
npoints
>=
0
);
if
(
npoints
==
0
)
return
;
klass
=
GF_DRAWABLE_GET_CLASS
(
drawable
);
if
(
klass
&&
klass
->
draw_points
)
klass
->
draw_points
(
drawable
,
gc
,
points
,
npoints
);
}
/**
* gf_draw_segments:
* @drawable : The #GfDrawable instance.
* @gc : The #GfGC instance.
* @segs : An array of #GfSegment's.
* @nsegs : The number of @segs.
*
* Draws a number of segments on @drawable.
*/
void
gf_draw_segments
(
GfDrawable
*
drawable
,
GfGC
*
gc
,
GfSegment
*
segs
,
gint
nsegs
)
{
GfDrawableClass
*
klass
;
g_return_if_fail
(
GF_IS_DRAWABLE
(
drawable
));
g_return_if_fail
(
GF_IS_GC
(
gc
));
g_return_if_fail
(
segs
);
g_return_if_fail
(
nsegs
>=
0
);
if
(
nsegs
==
0
)
return
;
klass
=
GF_DRAWABLE_GET_CLASS
(
drawable
);
if
(
klass
&&
klass
->
draw_segments
)
klass
->
draw_segments
(
drawable
,
gc
,
segs
,
nsegs
);
}
/**
* gf_draw_lines:
* @drawable : The #GfDrawable instance.
* @gc : The #GfGC instance.
* @points : An array of #GfPoint's.
* @npoints : The number of @points.
*
* Draws a number of connected lines on @drawable.
*/
void
gf_draw_lines
(
GfDrawable
*
drawable
,
GfGC
*
gc
,
GfPoint
*
points
,
gint
npoints
)
{
GfDrawableClass
*
klass
;
g_return_if_fail
(
GF_IS_DRAWABLE
(
drawable
));
g_return_if_fail
(
GF_IS_GC
(
gc
));
g_return_if_fail
(
points
);
g_return_if_fail
(
npoints
>=
0
);
if
(
npoints
==
0
)
return
;
klass
=
GF_DRAWABLE_GET_CLASS
(
drawable
);
if
(
klass
&&
klass
->
draw_lines
)
klass
->
draw_lines
(
drawable
,
gc
,
points
,
npoints
);
}