2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This is a plug-in for the GIMP.
6
* Generates images containing vector type drawings.
8
* Copyright (C) 1997 Andy Thomas alt@picnic.demon.co.uk
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.
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.
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.
28
#include <libgimp/gimp.h>
29
#include <libgimp/gimpui.h>
32
#include "gfig-dobject.h"
33
#include "gfig-rectangle.h"
35
#include "libgimp/stdplugins-intl.h"
37
static void d_draw_rectangle (GfigObject *obj);
38
static void d_paint_rectangle (GfigObject *obj);
39
static GfigObject *d_copy_rectangle (GfigObject *obj);
41
static void d_update_rectangle (GdkPoint *pnt);
46
if (!selvals.scaletoimage)
47
return (gint) (x * (1 / scale_x_factor));
55
if (!selvals.scaletoimage)
56
return (gint) (y * (1 / scale_y_factor));
62
d_draw_rectangle (GfigObject *obj)
64
DobjPoints *first_pnt;
65
DobjPoints *second_pnt;
69
first_pnt = obj->points;
72
return; /* End-of-line */
74
second_pnt = first_pnt->next;
78
g_warning ("Internal error - rectangle no edge pnt");
81
draw_sqr (&first_pnt->pnt, obj == gfig_context->selected_obj);
82
draw_sqr (&second_pnt->pnt, obj == gfig_context->selected_obj);
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,
96
xmax - xmin, ymax - ymin);
100
d_paint_rectangle (GfigObject *obj)
102
DobjPoints *first_pnt;
103
DobjPoints *second_pnt;
106
g_assert (obj != NULL);
108
/* Drawing rectangles is hard .
109
* 1) select rectangle
112
first_pnt = obj->points;
115
return; /* End-of-line */
117
second_pnt = first_pnt->next;
121
g_error ("Internal error - rectangle no second pnt");
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);
129
/* Scale before drawing */
130
if (selvals.scaletoimage)
131
scale_to_original_xy (&dpnts[0], 2);
133
scale_to_xy (&dpnts[0], 2);
135
gimp_rect_select (gfig_context->image_id,
141
selopt.feather_radius);
143
paint_layer_fill (dpnts[0], dpnts[1], dpnts[2], dpnts[3]);
145
if (obj->style.paint_type == PAINT_BRUSH_TYPE)
146
gimp_edit_stroke (gfig_context->drawable_id);
150
d_copy_rectangle (GfigObject * obj)
152
GfigObject *new_rectangle;
154
g_assert (obj->type == RECTANGLE);
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);
160
return new_rectangle;
164
d_rectangle_object_class_init (void)
166
GfigObjectClass *class = &dobj_class[RECTANGLE];
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;
177
d_update_rectangle (GdkPoint *pnt)
179
DobjPoints *first_pnt;
180
DobjPoints *second_pnt;
184
/* Undraw last one then draw new one */
185
first_pnt = obj_creating->points;
188
return; /* No points */
190
if ((second_pnt = first_pnt->next))
193
draw_circle (&second_pnt->pnt, TRUE);
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,
206
xmin, ymin, xmax - xmin, ymax - ymin);
207
second_pnt->pnt.x = pnt->x;
208
second_pnt->pnt.y = pnt->y;
212
second_pnt = new_dobjpoint (pnt->x, pnt->y);
213
first_pnt->next = second_pnt;
216
draw_circle (&second_pnt->pnt, TRUE);
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,
228
xmin, ymin, xmax - xmin, ymax - ymin);
232
d_rectangle_start (GdkPoint *pnt,
235
obj_creating = d_new_object (RECTANGLE, pnt->x, pnt->y);
239
d_rectangle_end (GdkPoint *pnt,
242
/* Under contrl point */
243
if (!obj_creating->points->next)
245
/* No circle created */
246
free_one_obj (obj_creating);
250
draw_circle (pnt, TRUE);
251
add_to_all_obj (gfig_context->current_obj, obj_creating);