~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/gfig/gfig-rectangle.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * This is a plug-in for the GIMP.
 
5
 *
 
6
 * Generates images containing vector type drawings.
 
7
 *
 
8
 * Copyright (C) 1997 Andy Thomas  alt@picnic.demon.co.uk
 
9
 *
 
10
 * This program is free software; you can redistribute it and/or modify
 
11
 * it under the terms of the GNU General Public License as published by
 
12
 * the Free Software Foundation; either version 2 of the License, or
 
13
 * (at your option) any later version.
 
14
 *
 
15
 * This program is distributed in the hope that it will be useful,
 
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 * GNU General Public License for more details.
 
19
 *
 
20
 * You should have received a copy of the GNU General Public License
 
21
 * along with this program; if not, write to the Free Software
 
22
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
23
 *
 
24
 */
 
25
 
 
26
#include "config.h"
 
27
 
 
28
#include <libgimp/gimp.h>
 
29
#include <libgimp/gimpui.h>
 
30
 
 
31
#include "gfig.h"
 
32
#include "gfig-dobject.h"
 
33
#include "gfig-rectangle.h"
 
34
 
 
35
#include "libgimp/stdplugins-intl.h"
 
36
 
 
37
static void        d_draw_rectangle   (GfigObject *obj);
 
38
static void        d_paint_rectangle  (GfigObject *obj);
 
39
static GfigObject *d_copy_rectangle   (GfigObject *obj);
 
40
 
 
41
static void        d_update_rectangle (GdkPoint   *pnt);
 
42
 
 
43
static gint
 
44
gfig_scale_x (gint x)
 
45
{
 
46
  if (!selvals.scaletoimage)
 
47
    return (gint) (x * (1 / scale_x_factor));
 
48
  else
 
49
    return x;
 
50
}
 
51
 
 
52
static gint
 
53
gfig_scale_y (gint y)
 
54
{
 
55
  if (!selvals.scaletoimage)
 
56
    return (gint) (y * (1 / scale_y_factor));
 
57
  else
 
58
    return y;
 
59
}
 
60
 
 
61
static void
 
62
d_draw_rectangle (GfigObject *obj)
 
63
{
 
64
  DobjPoints *first_pnt;
 
65
  DobjPoints *second_pnt;
 
66
  gint        xmin, ymin;
 
67
  gint        xmax, ymax;
 
68
 
 
69
  first_pnt = obj->points;
 
70
 
 
71
  if (!first_pnt)
 
72
    return; /* End-of-line */
 
73
 
 
74
  second_pnt = first_pnt->next;
 
75
 
 
76
  if (!second_pnt)
 
77
    {
 
78
      g_warning ("Internal error - rectangle no edge pnt");
 
79
    }
 
80
 
 
81
  draw_sqr (&first_pnt->pnt, obj == gfig_context->selected_obj);
 
82
  draw_sqr (&second_pnt->pnt, obj == gfig_context->selected_obj);
 
83
 
 
84
  xmin = MIN (gfig_scale_x (first_pnt->pnt.x),
 
85
              gfig_scale_x (second_pnt->pnt.x));
 
86
  ymin = MIN (gfig_scale_y (first_pnt->pnt.y),
 
87
              gfig_scale_y (second_pnt->pnt.y));
 
88
  xmax = MAX (gfig_scale_x (first_pnt->pnt.x),
 
89
              gfig_scale_x (second_pnt->pnt.x));
 
90
  ymax = MAX (gfig_scale_y (first_pnt->pnt.y),
 
91
              gfig_scale_y (second_pnt->pnt.y));
 
92
  gdk_draw_rectangle (gfig_context->preview->window,
 
93
                      gfig_gc,
 
94
                      FALSE,
 
95
                      xmin, ymin,
 
96
                      xmax - xmin, ymax - ymin);
 
97
}
 
98
 
 
99
static void
 
100
d_paint_rectangle (GfigObject *obj)
 
101
{
 
102
  DobjPoints *first_pnt;
 
103
  DobjPoints *second_pnt;
 
104
  gdouble     dpnts[4];
 
105
 
 
106
  g_assert (obj != NULL);
 
107
 
 
108
  /* Drawing rectangles is hard .
 
109
   * 1) select rectangle
 
110
   * 2) stroke it
 
111
   */
 
112
  first_pnt = obj->points;
 
113
 
 
114
  if (!first_pnt)
 
115
    return; /* End-of-line */
 
116
 
 
117
  second_pnt = first_pnt->next;
 
118
 
 
119
  if (!second_pnt)
 
120
    {
 
121
      g_error ("Internal error - rectangle no second pnt");
 
122
    }
 
123
 
 
124
  dpnts[0] = (gdouble) MIN (first_pnt->pnt.x, second_pnt->pnt.x);
 
125
  dpnts[1] = (gdouble) MIN (first_pnt->pnt.y, second_pnt->pnt.y);
 
126
  dpnts[2] = (gdouble) MAX (first_pnt->pnt.x, second_pnt->pnt.x);
 
127
  dpnts[3] = (gdouble) MAX (first_pnt->pnt.y, second_pnt->pnt.y);
 
128
 
 
129
  /* Scale before drawing */
 
130
  if (selvals.scaletoimage)
 
131
    scale_to_original_xy (&dpnts[0], 2);
 
132
  else
 
133
    scale_to_xy (&dpnts[0], 2);
 
134
 
 
135
  gimp_rect_select (gfig_context->image_id,
 
136
                    dpnts[0], dpnts[1],
 
137
                    dpnts[2] - dpnts[0],
 
138
                    dpnts[3] - dpnts[1],
 
139
                    selopt.type,
 
140
                    selopt.feather,
 
141
                    selopt.feather_radius);
 
142
 
 
143
  paint_layer_fill (dpnts[0], dpnts[1], dpnts[2], dpnts[3]);
 
144
 
 
145
  if (obj->style.paint_type == PAINT_BRUSH_TYPE)
 
146
    gimp_edit_stroke (gfig_context->drawable_id);
 
147
}
 
148
 
 
149
static GfigObject *
 
150
d_copy_rectangle (GfigObject * obj)
 
151
{
 
152
  GfigObject *new_rectangle;
 
153
 
 
154
  g_assert (obj->type == RECTANGLE);
 
155
 
 
156
  new_rectangle = d_new_object (RECTANGLE,
 
157
                                obj->points->pnt.x, obj->points->pnt.y);
 
158
  new_rectangle->points->next = d_copy_dobjpoints (obj->points->next);
 
159
 
 
160
  return new_rectangle;
 
161
}
 
162
 
 
163
void
 
164
d_rectangle_object_class_init (void)
 
165
{
 
166
  GfigObjectClass *class = &dobj_class[RECTANGLE];
 
167
 
 
168
  class->type      = RECTANGLE;
 
169
  class->name      = "RECTANGLE";
 
170
  class->drawfunc  = d_draw_rectangle;
 
171
  class->paintfunc = d_paint_rectangle;
 
172
  class->copyfunc  = d_copy_rectangle;
 
173
  class->update    = d_update_rectangle;
 
174
}
 
175
 
 
176
static void
 
177
d_update_rectangle (GdkPoint *pnt)
 
178
{
 
179
  DobjPoints *first_pnt;
 
180
  DobjPoints *second_pnt;
 
181
  gint        xmin, ymin;
 
182
  gint        xmax, ymax;
 
183
 
 
184
  /* Undraw last one then draw new one */
 
185
  first_pnt = obj_creating->points;
 
186
 
 
187
  if (!first_pnt)
 
188
    return; /* No points */
 
189
 
 
190
  if ((second_pnt = first_pnt->next))
 
191
    {
 
192
      /* Undraw current */
 
193
      draw_circle (&second_pnt->pnt, TRUE);
 
194
 
 
195
      xmin = MIN (gfig_scale_x (first_pnt->pnt.x),
 
196
                  gfig_scale_x (second_pnt->pnt.x));
 
197
      ymin = MIN (gfig_scale_y (first_pnt->pnt.y),
 
198
                  gfig_scale_y (second_pnt->pnt.y));
 
199
      xmax = MAX (gfig_scale_x (first_pnt->pnt.x),
 
200
                  gfig_scale_x (second_pnt->pnt.x));
 
201
      ymax = MAX (gfig_scale_y (first_pnt->pnt.y),
 
202
                  gfig_scale_y (second_pnt->pnt.y));
 
203
      gdk_draw_rectangle (gfig_context->preview->window,
 
204
                          gfig_gc,
 
205
                          FALSE,
 
206
                          xmin, ymin, xmax - xmin, ymax - ymin);
 
207
      second_pnt->pnt.x = pnt->x;
 
208
      second_pnt->pnt.y = pnt->y;
 
209
    }
 
210
  else
 
211
    {
 
212
      second_pnt = new_dobjpoint (pnt->x, pnt->y);
 
213
      first_pnt->next = second_pnt;
 
214
    }
 
215
 
 
216
  draw_circle (&second_pnt->pnt, TRUE);
 
217
 
 
218
  xmin = MIN (gfig_scale_x (first_pnt->pnt.x),
 
219
              gfig_scale_x (second_pnt->pnt.x));
 
220
  ymin = MIN (gfig_scale_y (first_pnt->pnt.y),
 
221
              gfig_scale_y (second_pnt->pnt.y));
 
222
  xmax = MAX (gfig_scale_x (first_pnt->pnt.x),
 
223
              gfig_scale_x (second_pnt->pnt.x));
 
224
  ymax = MAX (gfig_scale_y (first_pnt->pnt.y),
 
225
              gfig_scale_y (second_pnt->pnt.y));
 
226
  gdk_draw_rectangle (gfig_context->preview->window,
 
227
                      gfig_gc, FALSE,
 
228
                      xmin, ymin, xmax - xmin, ymax - ymin);
 
229
}
 
230
 
 
231
void
 
232
d_rectangle_start (GdkPoint *pnt,
 
233
                   gboolean  shift_down)
 
234
{
 
235
  obj_creating = d_new_object (RECTANGLE, pnt->x, pnt->y);
 
236
}
 
237
 
 
238
void
 
239
d_rectangle_end (GdkPoint *pnt,
 
240
                 gboolean  shift_down)
 
241
{
 
242
  /* Under contrl point */
 
243
  if (!obj_creating->points->next)
 
244
    {
 
245
      /* No circle created */
 
246
      free_one_obj (obj_creating);
 
247
    }
 
248
  else
 
249
    {
 
250
      draw_circle (pnt, TRUE);
 
251
      add_to_all_obj (gfig_context->current_obj, obj_creating);
 
252
    }
 
253
 
 
254
  obj_creating = NULL;
 
255
}
 
256