~ubuntu-branches/ubuntu/vivid/gimp/vivid

« back to all changes in this revision

Viewing changes to app/widgets/gimpviewrenderervectors.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach
  • Date: 2012-05-08 18:50:03 UTC
  • mto: (1.1.26) (0.5.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 71.
  • Revision ID: package-import@ubuntu.com-20120508185003-tltkvbaysf8d2426
ImportĀ upstreamĀ versionĀ 2.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 * Copyright (C) 2003 Michael Natterer <mitch@gimp.org>
6
6
 *                    Simon Budig <simon@gimp.org>
7
7
 *
8
 
 * This program is free software; you can redistribute it and/or modify
 
8
 * This program is free software: you can redistribute it and/or modify
9
9
 * it under the terms of the GNU General Public License as published by
10
 
 * the Free Software Foundation; either version 2 of the License, or
 
10
 * the Free Software Foundation; either version 3 of the License, or
11
11
 * (at your option) any later version.
12
12
 *
13
13
 * This program is distributed in the hope that it will be useful,
16
16
 * GNU General Public License for more details.
17
17
 *
18
18
 * You should have received a copy of the GNU General Public License
19
 
 * along with this program; if not, write to the Free Software
20
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
20
 */
22
21
 
23
22
#include "config.h"
24
23
 
 
24
#include <gegl.h>
25
25
#include <gtk/gtk.h>
26
26
 
27
27
#include "libgimpmath/gimpmath.h"
38
38
#include "gimpviewrenderervectors.h"
39
39
 
40
40
 
41
 
static void   gimp_view_renderer_vectors_draw (GimpViewRenderer   *renderer,
42
 
                                               GtkWidget          *widget,
43
 
                                               cairo_t            *cr,
44
 
                                               const GdkRectangle *area);
 
41
static void   gimp_view_renderer_vectors_draw (GimpViewRenderer *renderer,
 
42
                                               GtkWidget        *widget,
 
43
                                               cairo_t          *cr,
 
44
                                               gint              available_width,
 
45
                                               gint              available_height);
45
46
 
46
47
 
47
48
G_DEFINE_TYPE (GimpViewRendererVectors, gimp_view_renderer_vectors,
64
65
}
65
66
 
66
67
static void
67
 
gimp_view_renderer_vectors_draw (GimpViewRenderer   *renderer,
68
 
                                 GtkWidget          *widget,
69
 
                                 cairo_t            *cr,
70
 
                                 const GdkRectangle *area)
 
68
gimp_view_renderer_vectors_draw (GimpViewRenderer *renderer,
 
69
                                 GtkWidget        *widget,
 
70
                                 cairo_t          *cr,
 
71
                                 gint              available_width,
 
72
                                 gint              available_height)
71
73
{
72
 
  GtkStyle       *style   = gtk_widget_get_style (widget);
73
 
  GimpVectors    *vectors = GIMP_VECTORS (renderer->viewable);
74
 
  GimpBezierDesc *bezdesc;
75
 
  gdouble         xscale;
76
 
  gdouble         yscale;
77
 
  gint            x, y;
 
74
  GtkStyle             *style   = gtk_widget_get_style (widget);
 
75
  GimpVectors          *vectors = GIMP_VECTORS (renderer->viewable);
 
76
  const GimpBezierDesc *desc;
78
77
 
79
78
  gdk_cairo_set_source_color (cr, &style->white);
80
79
 
81
 
  x = area->x + (area->width  - renderer->width)  / 2;
82
 
  y = area->y + (area->height - renderer->height) / 2;
83
 
 
84
 
  cairo_translate (cr, x, y);
 
80
  cairo_translate (cr,
 
81
                   (available_width  - renderer->width)  / 2,
 
82
                   (available_height - renderer->height) / 2);
85
83
  cairo_rectangle (cr, 0, 0, renderer->width, renderer->height);
86
84
  cairo_clip_preserve (cr);
87
85
  cairo_fill (cr);
88
86
 
89
 
  xscale = (gdouble) renderer->width / (gdouble) gimp_item_width  (GIMP_ITEM (vectors));
90
 
  yscale = (gdouble) renderer->height / (gdouble) gimp_item_height (GIMP_ITEM (vectors));
91
 
  cairo_scale (cr, xscale, yscale);
92
 
 
93
 
  /* determine line width */
94
 
  xscale = yscale = 0.5;
95
 
  cairo_device_to_user_distance (cr, &xscale, &yscale);
96
 
 
97
 
  cairo_set_line_width (cr, MAX (xscale, yscale));
98
 
  gdk_cairo_set_source_color (cr, &style->black);
99
 
 
100
 
  bezdesc = gimp_vectors_make_bezier (vectors);
101
 
 
102
 
  if (bezdesc)
 
87
  desc = gimp_vectors_get_bezier (vectors);
 
88
 
 
89
  if (desc)
103
90
    {
104
 
      cairo_append_path (cr, (cairo_path_t *) bezdesc);
 
91
      gdouble xscale;
 
92
      gdouble yscale;
 
93
 
 
94
      xscale = ((gdouble) renderer->width /
 
95
                (gdouble) gimp_item_get_width  (GIMP_ITEM (vectors)));
 
96
      yscale = ((gdouble) renderer->height /
 
97
                (gdouble) gimp_item_get_height (GIMP_ITEM (vectors)));
 
98
 
 
99
      cairo_scale (cr, xscale, yscale);
 
100
 
 
101
      /* determine line width */
 
102
      xscale = yscale = 0.5;
 
103
      cairo_device_to_user_distance (cr, &xscale, &yscale);
 
104
 
 
105
      cairo_set_line_width (cr, MAX (xscale, yscale));
 
106
      gdk_cairo_set_source_color (cr, &style->black);
 
107
 
 
108
      cairo_append_path (cr, (cairo_path_t *) desc);
105
109
      cairo_stroke (cr);
106
 
      g_free (bezdesc->data);
107
 
      g_free (bezdesc);
108
110
    }
109
111
}