2003-09-28 12:00:50 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimppreviewrenderervectors.c
|
|
|
|
* 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
|
|
|
*
|
|
|
|
* 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 2 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "widgets-types.h"
|
|
|
|
|
|
|
|
#include "vectors/gimpvectors.h"
|
2003-09-29 19:48:15 +08:00
|
|
|
#include "vectors/gimpstroke.h"
|
2003-09-28 12:00:50 +08:00
|
|
|
|
|
|
|
#include "gimppreviewrenderervectors.h"
|
|
|
|
|
|
|
|
|
|
|
|
static void gimp_preview_renderer_vectors_class_init (GimpPreviewRendererVectorsClass *klass);
|
|
|
|
|
2003-09-29 21:35:59 +08:00
|
|
|
static void gimp_preview_renderer_vectors_draw (GimpPreviewRenderer *renderer,
|
|
|
|
GdkWindow *window,
|
|
|
|
GtkWidget *widget,
|
|
|
|
const GdkRectangle *draw_area,
|
|
|
|
const GdkRectangle *expose_area);
|
2003-09-28 12:00:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
static GimpPreviewRendererClass *parent_class = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
GType
|
|
|
|
gimp_preview_renderer_vectors_get_type (void)
|
|
|
|
{
|
|
|
|
static GType renderer_type = 0;
|
|
|
|
|
|
|
|
if (! renderer_type)
|
|
|
|
{
|
|
|
|
static const GTypeInfo renderer_info =
|
|
|
|
{
|
|
|
|
sizeof (GimpPreviewRendererVectorsClass),
|
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
|
|
|
(GClassInitFunc) gimp_preview_renderer_vectors_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpPreviewRendererVectors),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
NULL, /* instance_init */
|
|
|
|
};
|
|
|
|
|
|
|
|
renderer_type = g_type_register_static (GIMP_TYPE_PREVIEW_RENDERER,
|
|
|
|
"GimpPreviewRendererVectors",
|
|
|
|
&renderer_info, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return renderer_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_preview_renderer_vectors_class_init (GimpPreviewRendererVectorsClass *klass)
|
|
|
|
{
|
|
|
|
GimpPreviewRendererClass *renderer_class;
|
|
|
|
|
|
|
|
renderer_class = GIMP_PREVIEW_RENDERER_CLASS (klass);
|
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
2003-09-29 21:35:59 +08:00
|
|
|
renderer_class->draw = gimp_preview_renderer_vectors_draw;
|
2003-09-28 12:00:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-09-29 21:35:59 +08:00
|
|
|
gimp_preview_renderer_vectors_draw (GimpPreviewRenderer *renderer,
|
|
|
|
GdkWindow *window,
|
|
|
|
GtkWidget *widget,
|
|
|
|
const GdkRectangle *draw_area,
|
|
|
|
const GdkRectangle *expose_area)
|
2003-09-28 12:00:50 +08:00
|
|
|
{
|
2003-09-29 21:35:59 +08:00
|
|
|
GimpVectors *vectors;
|
|
|
|
GimpStroke *stroke;
|
|
|
|
GdkRectangle rect;
|
|
|
|
GArray *coordinates;
|
|
|
|
GdkPoint *points;
|
|
|
|
gboolean closed;
|
|
|
|
gint i;
|
|
|
|
gint x, y;
|
|
|
|
gdouble xscale, yscale;
|
|
|
|
|
|
|
|
if (! gdk_rectangle_intersect ((GdkRectangle *) draw_area,
|
|
|
|
(GdkRectangle *) expose_area, &rect))
|
|
|
|
return;
|
|
|
|
|
|
|
|
gdk_draw_rectangle (window, widget->style->white_gc, TRUE,
|
|
|
|
rect.x, rect.y, rect.width, rect.height);
|
|
|
|
|
2003-09-29 19:48:15 +08:00
|
|
|
vectors = GIMP_VECTORS (renderer->viewable);
|
|
|
|
|
2003-09-29 21:35:59 +08:00
|
|
|
xscale = (gdouble) GIMP_ITEM (vectors)->width / (gdouble) renderer->width;
|
|
|
|
yscale = (gdouble) GIMP_ITEM (vectors)->height / (gdouble) renderer->height;
|
|
|
|
|
|
|
|
gdk_gc_set_clip_rectangle (widget->style->black_gc, &rect);
|
2003-09-29 19:48:15 +08:00
|
|
|
|
2003-09-29 21:35:59 +08:00
|
|
|
x = draw_area->x + renderer->border_width;
|
|
|
|
y = draw_area->y + renderer->border_width;
|
2003-09-29 19:48:15 +08:00
|
|
|
|
|
|
|
for (stroke = gimp_vectors_stroke_get_next (vectors, NULL);
|
|
|
|
stroke != NULL;
|
|
|
|
stroke = gimp_vectors_stroke_get_next (vectors, stroke))
|
2003-09-28 12:00:50 +08:00
|
|
|
{
|
2003-09-29 21:35:59 +08:00
|
|
|
coordinates = gimp_stroke_interpolate (stroke,
|
|
|
|
MIN (xscale, yscale), &closed);
|
2003-09-29 19:48:15 +08:00
|
|
|
points = g_new (GdkPoint, coordinates->len);
|
|
|
|
|
2003-09-29 21:35:59 +08:00
|
|
|
for (i = 0; i < coordinates->len; i++)
|
2003-09-29 19:48:15 +08:00
|
|
|
{
|
2003-09-29 21:35:59 +08:00
|
|
|
GimpCoords *coords = &(g_array_index (coordinates, GimpCoords, i));
|
|
|
|
|
|
|
|
points[i].x = x + ROUND (coords->x / xscale);
|
|
|
|
points[i].y = y + ROUND (coords->y / yscale);
|
2003-09-29 19:48:15 +08:00
|
|
|
}
|
2003-09-29 21:35:59 +08:00
|
|
|
|
|
|
|
gdk_draw_lines (window, widget->style->black_gc,
|
2003-09-29 19:48:15 +08:00
|
|
|
points, coordinates->len);
|
|
|
|
|
|
|
|
g_array_free (coordinates, TRUE);
|
|
|
|
g_free (points);
|
2003-09-28 12:00:50 +08:00
|
|
|
}
|
2003-09-29 21:35:59 +08:00
|
|
|
|
|
|
|
gdk_gc_set_clip_rectangle (widget->style->black_gc, NULL);
|
2003-09-28 12:00:50 +08:00
|
|
|
}
|