2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2003-09-28 04:00:50 +00:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2004-08-26 14:20:30 +00:00
|
|
|
* gimpviewrenderervectors.c
|
2003-09-28 04:00:50 +00:00
|
|
|
* Copyright (C) 2003 Michael Natterer <mitch@gimp.org>
|
2003-09-28 04:04:17 +00:00
|
|
|
* Simon Budig <simon@gimp.org>
|
2003-09-28 04:00:50 +00:00
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2003-09-28 04:00:50 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-09-28 04:00:50 +00:00
|
|
|
* (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
|
2009-01-17 22:28:01 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-09-28 04:00:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-10-09 20:24:04 +00:00
|
|
|
#include <gegl.h>
|
2003-09-28 04:00:50 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2007-03-09 13:00:01 +00:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2003-09-28 04:00:50 +00:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "widgets-types.h"
|
|
|
|
|
2003-09-29 16:35:30 +00:00
|
|
|
#include "core/gimpimage.h"
|
|
|
|
#include "core/gimpitem.h"
|
|
|
|
|
2003-09-29 11:48:15 +00:00
|
|
|
#include "vectors/gimpstroke.h"
|
2003-09-29 16:35:30 +00:00
|
|
|
#include "vectors/gimpvectors.h"
|
2003-09-28 04:00:50 +00:00
|
|
|
|
2004-08-26 14:20:30 +00:00
|
|
|
#include "gimpviewrenderervectors.h"
|
2003-09-28 04:00:50 +00:00
|
|
|
|
|
|
|
|
2004-08-26 14:20:30 +00:00
|
|
|
static void gimp_view_renderer_vectors_draw (GimpViewRenderer *renderer,
|
|
|
|
GtkWidget *widget,
|
2007-11-04 19:14:32 +00:00
|
|
|
cairo_t *cr,
|
2007-11-04 20:30:38 +00:00
|
|
|
const GdkRectangle *area);
|
2003-09-28 04:00:50 +00:00
|
|
|
|
|
|
|
|
2005-12-19 22:37:49 +00:00
|
|
|
G_DEFINE_TYPE (GimpViewRendererVectors, gimp_view_renderer_vectors,
|
2006-05-15 09:46:31 +00:00
|
|
|
GIMP_TYPE_VIEW_RENDERER)
|
2003-09-28 04:00:50 +00:00
|
|
|
|
2005-12-19 22:37:49 +00:00
|
|
|
#define parent_class gimp_view_renderer_vectors_parent_class
|
2003-09-28 04:00:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
2004-08-26 14:20:30 +00:00
|
|
|
gimp_view_renderer_vectors_class_init (GimpViewRendererVectorsClass *klass)
|
2003-09-28 04:00:50 +00:00
|
|
|
{
|
2004-09-09 11:58:49 +00:00
|
|
|
GimpViewRendererClass *renderer_class = GIMP_VIEW_RENDERER_CLASS (klass);
|
2003-09-28 04:00:50 +00:00
|
|
|
|
2004-08-26 14:20:30 +00:00
|
|
|
renderer_class->draw = gimp_view_renderer_vectors_draw;
|
2003-09-28 04:00:50 +00:00
|
|
|
}
|
|
|
|
|
2005-12-19 22:37:49 +00:00
|
|
|
static void
|
|
|
|
gimp_view_renderer_vectors_init (GimpViewRendererVectors *renderer)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-09-28 04:00:50 +00:00
|
|
|
static void
|
2004-08-26 14:20:30 +00:00
|
|
|
gimp_view_renderer_vectors_draw (GimpViewRenderer *renderer,
|
|
|
|
GtkWidget *widget,
|
2007-11-04 19:14:32 +00:00
|
|
|
cairo_t *cr,
|
2007-11-04 20:30:38 +00:00
|
|
|
const GdkRectangle *area)
|
2003-09-28 04:00:50 +00:00
|
|
|
{
|
2010-09-16 21:36:51 +02:00
|
|
|
GtkStyle *style = gtk_widget_get_style (widget);
|
|
|
|
GimpVectors *vectors = GIMP_VECTORS (renderer->viewable);
|
|
|
|
const GimpBezierDesc *desc;
|
2003-09-29 13:35:59 +00:00
|
|
|
|
2008-06-28 15:50:27 +00:00
|
|
|
gdk_cairo_set_source_color (cr, &style->white);
|
2003-09-29 23:14:28 +00:00
|
|
|
|
2008-11-21 21:15:29 +00:00
|
|
|
cairo_translate (cr,
|
|
|
|
area->x + (area->width - renderer->width) / 2,
|
|
|
|
area->y + (area->height - renderer->height) / 2);
|
2008-05-12 21:47:07 +00:00
|
|
|
cairo_rectangle (cr, 0, 0, renderer->width, renderer->height);
|
2007-11-13 14:27:29 +00:00
|
|
|
cairo_clip_preserve (cr);
|
2007-11-04 19:14:32 +00:00
|
|
|
cairo_fill (cr);
|
2003-09-29 13:35:59 +00:00
|
|
|
|
2010-09-16 21:36:51 +02:00
|
|
|
desc = gimp_vectors_get_bezier (vectors);
|
2003-09-29 11:48:15 +00:00
|
|
|
|
2010-09-16 21:36:51 +02:00
|
|
|
if (desc)
|
2008-05-12 21:47:07 +00:00
|
|
|
{
|
2008-10-15 23:04:40 +00:00
|
|
|
gdouble xscale;
|
|
|
|
gdouble yscale;
|
|
|
|
|
|
|
|
xscale = ((gdouble) renderer->width /
|
2008-11-03 00:09:01 +00:00
|
|
|
(gdouble) gimp_item_get_width (GIMP_ITEM (vectors)));
|
2008-10-15 23:04:40 +00:00
|
|
|
yscale = ((gdouble) renderer->height /
|
2008-11-03 00:09:01 +00:00
|
|
|
(gdouble) gimp_item_get_height (GIMP_ITEM (vectors)));
|
2008-10-15 23:04:40 +00:00
|
|
|
|
|
|
|
cairo_scale (cr, xscale, yscale);
|
|
|
|
|
|
|
|
/* determine line width */
|
|
|
|
xscale = yscale = 0.5;
|
|
|
|
cairo_device_to_user_distance (cr, &xscale, &yscale);
|
|
|
|
|
|
|
|
cairo_set_line_width (cr, MAX (xscale, yscale));
|
|
|
|
gdk_cairo_set_source_color (cr, &style->black);
|
|
|
|
|
2010-09-16 21:36:51 +02:00
|
|
|
cairo_append_path (cr, (cairo_path_t *) desc);
|
2008-05-12 21:47:07 +00:00
|
|
|
cairo_stroke (cr);
|
2003-09-28 04:00:50 +00:00
|
|
|
}
|
|
|
|
}
|