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