gimpviewrenderervectors.c 3.43 KB
Newer Older
1
/* GIMP - The GNU Image Manipulation Program
2 3
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
4
 * gimpviewrenderervectors.c
5
 * Copyright (C) 2003 Michael Natterer <mitch@gimp.org>
6
 *                    Simon Budig <simon@gimp.org>
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation; either version 3 of the License, or
11 12 13 14 15 16 17 18
 * (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
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20 21 22 23
 */

#include "config.h"

24
#include <gegl.h>
25 26
#include <gtk/gtk.h>

27
#include "libgimpmath/gimpmath.h"
28 29 30 31
#include "libgimpwidgets/gimpwidgets.h"

#include "widgets-types.h"

32 33 34
#include "core/gimpimage.h"
#include "core/gimpitem.h"

35
#include "vectors/gimpstroke.h"
36
#include "vectors/gimpvectors.h"
37

38
#include "gimpviewrenderervectors.h"
39 40


41 42 43 44 45
static void   gimp_view_renderer_vectors_draw (GimpViewRenderer *renderer,
                                               GtkWidget        *widget,
                                               cairo_t          *cr,
                                               gint              available_width,
                                               gint              available_height);
46 47


48
G_DEFINE_TYPE (GimpViewRendererVectors, gimp_view_renderer_vectors,
49
               GIMP_TYPE_VIEW_RENDERER)
50

51
#define parent_class gimp_view_renderer_vectors_parent_class
52 53 54


static void
55
gimp_view_renderer_vectors_class_init (GimpViewRendererVectorsClass *klass)
56
{
57
  GimpViewRendererClass *renderer_class = GIMP_VIEW_RENDERER_CLASS (klass);
58

59
  renderer_class->draw = gimp_view_renderer_vectors_draw;
60 61
}

62 63 64 65 66
static void
gimp_view_renderer_vectors_init (GimpViewRendererVectors *renderer)
{
}

67
static void
68 69 70 71 72
gimp_view_renderer_vectors_draw (GimpViewRenderer *renderer,
                                 GtkWidget        *widget,
                                 cairo_t          *cr,
                                 gint              available_width,
                                 gint              available_height)
73
{
74 75
  GimpVectors          *vectors = GIMP_VECTORS (renderer->viewable);
  const GimpBezierDesc *desc;
76

77
  cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
78

79
  cairo_translate (cr,
80 81
                   (available_width  - renderer->width)  / 2,
                   (available_height - renderer->height) / 2);
82
  cairo_rectangle (cr, 0, 0, renderer->width, renderer->height);
83
  cairo_clip_preserve (cr);
84
  cairo_fill (cr);
85

86
  desc = gimp_vectors_get_bezier (vectors);
87

88
  if (desc)
89
    {
Sven Neumann's avatar
Sven Neumann committed
90 91 92 93
      gdouble xscale;
      gdouble yscale;

      xscale = ((gdouble) renderer->width /
94
                (gdouble) gimp_item_get_width  (GIMP_ITEM (vectors)));
Sven Neumann's avatar
Sven Neumann committed
95
      yscale = ((gdouble) renderer->height /
96
                (gdouble) gimp_item_get_height (GIMP_ITEM (vectors)));
Sven Neumann's avatar
Sven Neumann committed
97 98 99 100 101 102 103 104

      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));
105
      cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
Sven Neumann's avatar
Sven Neumann committed
106

107
      cairo_append_path (cr, (cairo_path_t *) desc);
108
      cairo_stroke (cr);
109 110
    }
}