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