Commit 5faf644b authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

added new function gimp_cairo_checkerboard_create() and renamed

2007-12-12  Sven Neumann  <sven@gimp.org>

	* libgimpwidgets/gimpcairo-utils.[ch]: added new function
	gimp_cairo_checkerboard_create() and renamed
	gimp_cairo_create_surface_from_pixbuf() to
	gimp_cairo_surface_create_from_pixbuf().

	* libgimpwidgets/gimpcellrenderercolor.c
	(gimp_cell_renderer_color_render): use Cairo utils here.

	* app/widgets/gimpviewrenderer.c (gimp_view_renderer_create_pattern):
	changed accordingly.

	* libgimpwidgets/gimpwidgets.def: updated.

svn path=/trunk/; revision=24340
parent a44fa674
2007-12-12 Sven Neumann <sven@gimp.org>
* libgimpwidgets/gimpcairo-utils.[ch]: added new function
gimp_cairo_checkerboard_create() and renamed
gimp_cairo_create_surface_from_pixbuf() to
gimp_cairo_surface_create_from_pixbuf().
* libgimpwidgets/gimpcellrenderercolor.c
(gimp_cell_renderer_color_render): use Cairo utils here.
* app/widgets/gimpviewrenderer.c (gimp_view_renderer_create_pattern):
changed accordingly.
* libgimpwidgets/gimpwidgets.def: updated.
2007-12-12 Sven Neumann <sven@gimp.org>
* app/widgets/Makefile.am
......
......@@ -1098,7 +1098,7 @@ gimp_view_renderer_create_pattern (GimpViewRenderer *renderer,
{
cairo_surface_t *surface;
surface = gimp_cairo_create_surface_from_pixbuf (pixbuf);
surface = gimp_cairo_surface_create_from_pixbuf (pixbuf);
g_object_unref (pixbuf);
......
......@@ -25,6 +25,7 @@
#include <cairo.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpcolor/gimpcolor.h"
#include "gimpcairo-utils.h"
......@@ -45,11 +46,63 @@ void
gimp_cairo_set_source_color (cairo_t *cr,
GimpRGB *color)
{
g_return_if_fail (cr != NULL);
g_return_if_fail (color != NULL);
cairo_set_source_rgba (cr, color->r, color->g, color->b, color->a);
}
/**
* gimp_cairo_create_surface_from_pixbuf:
* gimp_cairo_checkerboard_create:
* @cr: Cairo context
* @size: check size
*
* Create a repeating checkerboard pattern.
*
* Return value: a new Cairo pattern that can be used as a source on @cr.
*
* Since: GIMP 2.6
**/
cairo_pattern_t *
gimp_cairo_checkerboard_create (cairo_t *cr,
gint size)
{
cairo_t *context;
cairo_surface_t *surface;
cairo_pattern_t *pattern;
g_return_val_if_fail (cr != NULL, NULL);
g_return_val_if_fail (size > 0, NULL);
surface = cairo_surface_create_similar (cairo_get_target (cr),
CAIRO_CONTENT_COLOR,
2 * size, 2 * size);
context = cairo_create (surface);
cairo_set_source_rgb (context,
GIMP_CHECK_LIGHT, GIMP_CHECK_LIGHT, GIMP_CHECK_LIGHT);
cairo_rectangle (context, 0, 0, size, size);
cairo_rectangle (context, size, size, size, size);
cairo_fill (context);
cairo_set_source_rgb (context,
GIMP_CHECK_DARK, GIMP_CHECK_DARK, GIMP_CHECK_DARK);
cairo_rectangle (context, 0, size, size, size);
cairo_rectangle (context, size, 0, size, size);
cairo_fill (context);
cairo_destroy (context);
pattern = cairo_pattern_create_for_surface (surface);
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
cairo_surface_destroy (surface);
return pattern;
}
/**
* gimp_cairo_surface_create_from_pixbuf:
* @pixbuf: a GdkPixbuf
*
* Create a Cairo image surface from a GdkPixbuf.
......@@ -60,7 +113,7 @@ gimp_cairo_set_source_color (cairo_t *cr,
* Since: GIMP 2.6
**/
cairo_surface_t *
gimp_cairo_create_surface_from_pixbuf (GdkPixbuf *pixbuf)
gimp_cairo_surface_create_from_pixbuf (GdkPixbuf *pixbuf)
{
cairo_surface_t *surface;
cairo_format_t format;
......
......@@ -26,7 +26,9 @@
void gimp_cairo_set_source_color (cairo_t *cr,
GimpRGB *color);
cairo_surface_t * gimp_cairo_create_surface_from_pixbuf (GdkPixbuf *pixbuf);
cairo_pattern_t * gimp_cairo_checkerboard_create (cairo_t *cr,
gint size);
cairo_surface_t * gimp_cairo_surface_create_from_pixbuf (GdkPixbuf *pixbuf);
/* some useful macros for writing directly to a Cairo surface */
......
......@@ -29,6 +29,7 @@
#include "gimpwidgetstypes.h"
#include "gimpcairo-utils.h"
#include "gimpcellrenderercolor.h"
......@@ -67,9 +68,6 @@ static void gimp_cell_renderer_color_render (GtkCellRenderer *cell,
GdkRectangle *expose_area,
GtkCellRendererState flags);
static void gimp_cairo_set_checkerboard (cairo_t *cr,
gint size);
G_DEFINE_TYPE (GimpCellRendererColor, gimp_cell_renderer_color,
......@@ -252,19 +250,20 @@ gimp_cell_renderer_color_render (GtkCellRenderer *cell,
if (color->opaque && color->color.a != 1.0)
{
cairo_pattern_t *pattern;
cairo_move_to (cr, rect.x + 1, rect.y + rect.height - 1);
cairo_line_to (cr, rect.x + rect.width - 1, rect.y + rect.height - 1);
cairo_line_to (cr, rect.x + rect.width - 1, rect.y + 1);
cairo_close_path (cr);
gimp_cairo_set_checkerboard (cr, GIMP_CHECK_SIZE_SM);
pattern = gimp_cairo_checkerboard_create (cr, GIMP_CHECK_SIZE_SM);
cairo_set_source (cr, pattern);
cairo_pattern_destroy (pattern);
cairo_fill_preserve (cr);
cairo_set_source_rgba (cr,
color->color.r,
color->color.g,
color->color.b,
color->color.a);
gimp_cairo_set_source_color (cr, &color->color);
cairo_fill (cr);
}
......@@ -293,48 +292,6 @@ gimp_cell_renderer_color_render (GtkCellRenderer *cell,
}
}
/**
* gimp_cairo_set_checkerboard:
* @size:
* @light:
* @dark:
*
* Sets a repeating checkerboard as the source pattern within @cr.
**/
static void
gimp_cairo_set_checkerboard (cairo_t *cr,
gint size)
{
cairo_t *context;
cairo_surface_t *surface;
cairo_pattern_t *pattern;
surface = cairo_surface_create_similar (cairo_get_target (cr),
CAIRO_CONTENT_COLOR,
2 * size, 2 * size);
context = cairo_create (surface);
cairo_set_source_rgb (context,
GIMP_CHECK_LIGHT, GIMP_CHECK_LIGHT, GIMP_CHECK_LIGHT);
cairo_rectangle (context, 0, 0, size, size);
cairo_rectangle (context, size, size, size, size);
cairo_fill (context);
cairo_set_source_rgb (context,
GIMP_CHECK_DARK, GIMP_CHECK_DARK, GIMP_CHECK_DARK);
cairo_rectangle (context, 0, size, size, size);
cairo_rectangle (context, size, 0, size, size);
cairo_fill (context);
cairo_destroy (context);
pattern = cairo_pattern_create_for_surface (surface);
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
cairo_set_source (cr, pattern);
cairo_pattern_destroy (pattern);
}
/**
* gimp_cell_renderer_color_new:
*
......
......@@ -8,8 +8,9 @@ EXPORTS
gimp_button_extended_clicked
gimp_button_get_type
gimp_button_new
gimp_cairo_create_surface_from_pixbuf
gimp_cairo_checkerboard_create
gimp_cairo_set_source_color
gimp_cairo_surface_create_from_pixbuf
gimp_cell_renderer_color_get_type
gimp_cell_renderer_color_new
gimp_cell_renderer_toggle_clicked
......
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