2003-10-19 17:44:46 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2007-06-06 16:44:52 +08:00
|
|
|
* This is a plug-in for GIMP.
|
2003-10-19 17:44:46 +08:00
|
|
|
*
|
|
|
|
* Generates images containing vector type drawings.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1997 Andy Thomas alt@picnic.demon.co.uk
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2003-10-19 17:44:46 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-10-19 17:44:46 +08:00
|
|
|
* (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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2004-10-27 14:43:52 +08:00
|
|
|
*
|
2003-10-19 17:44:46 +08:00
|
|
|
*/
|
|
|
|
|
2003-10-24 21:28:46 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2003-10-19 17:44:46 +08:00
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
|
|
|
|
|
|
|
#include "gfig.h"
|
2004-07-08 01:52:16 +08:00
|
|
|
#include "gfig-dobject.h"
|
2003-10-24 21:28:46 +08:00
|
|
|
#include "gfig-line.h"
|
2004-10-28 02:47:08 +08:00
|
|
|
#include "gfig-dialog.h"
|
2006-10-31 05:36:08 +08:00
|
|
|
#include "gfig-poly.h"
|
2003-10-19 17:44:46 +08:00
|
|
|
|
2003-10-24 21:28:46 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
|
|
|
|
|
|
|
static gint poly_num_sides = 3; /* Default to three sided object */
|
2003-10-19 17:44:46 +08:00
|
|
|
|
2012-02-17 00:56:52 +08:00
|
|
|
static void d_draw_poly (GfigObject *obj,
|
|
|
|
cairo_t *cr);
|
2004-12-05 01:33:54 +08:00
|
|
|
static GfigObject *d_copy_poly (GfigObject *obj);
|
|
|
|
|
|
|
|
static void d_update_poly (GdkPoint *pnt);
|
2003-10-19 17:44:46 +08:00
|
|
|
|
2004-10-28 02:47:08 +08:00
|
|
|
void
|
2004-11-12 09:54:02 +08:00
|
|
|
tool_options_poly (GtkWidget *notebook)
|
2003-10-19 17:44:46 +08:00
|
|
|
{
|
2004-10-28 02:47:08 +08:00
|
|
|
GtkWidget *sides;
|
|
|
|
|
|
|
|
sides = num_sides_widget (_("Regular Polygon Number of Sides"),
|
|
|
|
&poly_num_sides, NULL, 3, 200);
|
2004-11-12 09:54:02 +08:00
|
|
|
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), sides, NULL);
|
2003-10-19 17:44:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-17 00:56:52 +08:00
|
|
|
d_draw_poly (GfigObject *obj,
|
|
|
|
cairo_t *cr)
|
2003-10-19 17:44:46 +08:00
|
|
|
{
|
2004-10-28 02:47:08 +08:00
|
|
|
DobjPoints *center_pnt;
|
|
|
|
DobjPoints *radius_pnt;
|
|
|
|
gint16 shift_x;
|
|
|
|
gint16 shift_y;
|
|
|
|
gdouble ang_grid;
|
|
|
|
gdouble ang_loop;
|
|
|
|
gdouble radius;
|
|
|
|
gdouble offset_angle;
|
|
|
|
gint loop;
|
2005-12-31 01:50:19 +08:00
|
|
|
GdkPoint start_pnt = { 0, 0 };
|
|
|
|
GdkPoint first_pnt = { 0, 0 };
|
2004-10-28 02:47:08 +08:00
|
|
|
gboolean do_line = FALSE;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
|
|
|
center_pnt = obj->points;
|
|
|
|
|
|
|
|
if (!center_pnt)
|
|
|
|
return; /* End-of-line */
|
|
|
|
|
|
|
|
/* First point is the center */
|
|
|
|
/* Just draw a control point around it */
|
|
|
|
|
2012-02-17 00:56:52 +08:00
|
|
|
draw_sqr (¢er_pnt->pnt, obj == gfig_context->selected_obj, cr);
|
2003-10-19 17:44:46 +08:00
|
|
|
|
|
|
|
/* Next point defines the radius */
|
|
|
|
radius_pnt = center_pnt->next; /* this defines the vertices */
|
|
|
|
|
|
|
|
if (!radius_pnt)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
g_warning ("Internal error in polygon - no vertice point \n");
|
|
|
|
#endif /* DEBUG */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Other control point */
|
2012-02-17 00:56:52 +08:00
|
|
|
if (obj == obj_creating)
|
|
|
|
draw_circle (&radius_pnt->pnt, TRUE, cr);
|
|
|
|
else
|
|
|
|
draw_sqr (&radius_pnt->pnt, obj == gfig_context->selected_obj, cr);
|
2003-10-19 17:44:46 +08:00
|
|
|
|
|
|
|
/* Have center and radius - draw polygon */
|
|
|
|
|
|
|
|
shift_x = radius_pnt->pnt.x - center_pnt->pnt.x;
|
|
|
|
shift_y = radius_pnt->pnt.y - center_pnt->pnt.y;
|
|
|
|
|
|
|
|
radius = sqrt ((shift_x*shift_x) + (shift_y*shift_y));
|
|
|
|
|
|
|
|
/* Lines */
|
|
|
|
ang_grid = 2 * G_PI / (gdouble) obj->type_data;
|
|
|
|
offset_angle = atan2 (shift_y, shift_x);
|
|
|
|
|
|
|
|
for (loop = 0 ; loop < obj->type_data ; loop++)
|
|
|
|
{
|
2004-10-30 23:25:07 +08:00
|
|
|
gdouble lx, ly;
|
2003-10-19 17:44:46 +08:00
|
|
|
GdkPoint calc_pnt;
|
|
|
|
|
|
|
|
ang_loop = (gdouble)loop * ang_grid + offset_angle;
|
2004-10-27 14:43:52 +08:00
|
|
|
|
2003-10-19 17:44:46 +08:00
|
|
|
lx = radius * cos (ang_loop);
|
|
|
|
ly = radius * sin (ang_loop);
|
|
|
|
|
|
|
|
calc_pnt.x = RINT (lx + center_pnt->pnt.x);
|
|
|
|
calc_pnt.y = RINT (ly + center_pnt->pnt.y);
|
|
|
|
|
|
|
|
if (do_line)
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
2003-10-19 17:44:46 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
/* Miss out points that come to the same location */
|
|
|
|
if (calc_pnt.x == start_pnt.x && calc_pnt.y == start_pnt.y)
|
|
|
|
continue;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
2012-02-17 00:56:52 +08:00
|
|
|
gfig_draw_line (calc_pnt.x, calc_pnt.y, start_pnt.x, start_pnt.y, cr);
|
2004-07-05 04:50:25 +08:00
|
|
|
}
|
2003-10-19 17:44:46 +08:00
|
|
|
else
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
do_line = TRUE;
|
|
|
|
first_pnt = calc_pnt;
|
|
|
|
}
|
2003-10-20 05:03:21 +08:00
|
|
|
start_pnt = calc_pnt;
|
2003-10-19 17:44:46 +08:00
|
|
|
}
|
|
|
|
|
2012-02-17 00:56:52 +08:00
|
|
|
gfig_draw_line (first_pnt.x, first_pnt.y, start_pnt.x, start_pnt.y, cr);
|
2003-10-19 17:44:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-11-16 22:10:20 +08:00
|
|
|
d_paint_poly (GfigObject *obj)
|
2003-10-19 17:44:46 +08:00
|
|
|
{
|
|
|
|
/* first point center */
|
|
|
|
/* Next point is radius */
|
2004-10-28 02:47:08 +08:00
|
|
|
gdouble *line_pnts;
|
2012-02-17 00:57:05 +08:00
|
|
|
gint seg_count;
|
2004-10-28 02:47:08 +08:00
|
|
|
gint i = 0;
|
|
|
|
DobjPoints *center_pnt;
|
|
|
|
DobjPoints *radius_pnt;
|
|
|
|
gint16 shift_x;
|
|
|
|
gint16 shift_y;
|
|
|
|
gdouble ang_grid;
|
|
|
|
gdouble ang_loop;
|
|
|
|
gdouble radius;
|
|
|
|
gdouble offset_angle;
|
|
|
|
gint loop;
|
2005-12-31 01:50:19 +08:00
|
|
|
GdkPoint first_pnt = { 0, 0 };
|
|
|
|
GdkPoint last_pnt = { 0, 0 };
|
2004-10-28 02:47:08 +08:00
|
|
|
gboolean first = TRUE;
|
2004-12-29 09:16:20 +08:00
|
|
|
gdouble *min_max;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
|
|
|
g_assert (obj != NULL);
|
|
|
|
|
|
|
|
/* count - add one to close polygon */
|
|
|
|
seg_count = obj->type_data + 1;
|
|
|
|
|
|
|
|
center_pnt = obj->points;
|
|
|
|
|
|
|
|
if (!center_pnt || !seg_count || !center_pnt->next)
|
|
|
|
return; /* no-line */
|
|
|
|
|
|
|
|
line_pnts = g_new0 (gdouble, 2 * seg_count + 1);
|
2004-12-29 09:16:20 +08:00
|
|
|
min_max = g_new (gdouble, 4);
|
2004-10-27 14:43:52 +08:00
|
|
|
|
2003-10-19 17:44:46 +08:00
|
|
|
/* Go around all the points drawing a line from one to the next */
|
|
|
|
|
|
|
|
radius_pnt = center_pnt->next; /* this defines the vetices */
|
|
|
|
|
|
|
|
/* Have center and radius - get lines */
|
|
|
|
shift_x = radius_pnt->pnt.x - center_pnt->pnt.x;
|
|
|
|
shift_y = radius_pnt->pnt.y - center_pnt->pnt.y;
|
|
|
|
|
|
|
|
radius = sqrt ((shift_x*shift_x) + (shift_y*shift_y));
|
|
|
|
|
|
|
|
/* Lines */
|
2004-10-30 23:25:07 +08:00
|
|
|
ang_grid = 2.0 * G_PI/(gdouble) obj->type_data;
|
2003-10-19 17:44:46 +08:00
|
|
|
offset_angle = atan2 (shift_y, shift_x);
|
|
|
|
|
|
|
|
for (loop = 0 ; loop < obj->type_data ; loop++)
|
|
|
|
{
|
2004-12-29 09:16:20 +08:00
|
|
|
gdouble lx, ly;
|
2003-10-19 17:44:46 +08:00
|
|
|
GdkPoint calc_pnt;
|
2004-10-27 14:43:52 +08:00
|
|
|
|
2003-10-19 17:44:46 +08:00
|
|
|
ang_loop = (gdouble)loop * ang_grid + offset_angle;
|
2004-10-27 14:43:52 +08:00
|
|
|
|
2003-10-19 17:44:46 +08:00
|
|
|
lx = radius * cos (ang_loop);
|
|
|
|
ly = radius * sin (ang_loop);
|
|
|
|
|
|
|
|
calc_pnt.x = RINT (lx + center_pnt->pnt.x);
|
|
|
|
calc_pnt.y = RINT (ly + center_pnt->pnt.y);
|
|
|
|
|
|
|
|
/* Miss out duped pnts */
|
|
|
|
if (!first)
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
if (calc_pnt.x == last_pnt.x && calc_pnt.y == last_pnt.y)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2003-10-19 17:44:46 +08:00
|
|
|
|
2003-10-20 05:03:21 +08:00
|
|
|
line_pnts[i++] = calc_pnt.x;
|
|
|
|
line_pnts[i++] = calc_pnt.y;
|
|
|
|
last_pnt = calc_pnt;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
|
|
|
if (first)
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
first_pnt = calc_pnt;
|
|
|
|
first = FALSE;
|
2004-12-29 09:16:20 +08:00
|
|
|
min_max[0] = min_max[2] = calc_pnt.x;
|
|
|
|
min_max[1] = min_max[3] = calc_pnt.y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
min_max[0] = MIN (min_max[0], calc_pnt.x);
|
|
|
|
min_max[1] = MIN (min_max[1], calc_pnt.y);
|
|
|
|
min_max[2] = MAX (min_max[2], calc_pnt.x);
|
|
|
|
min_max[3] = MAX (min_max[3], calc_pnt.y);
|
2004-07-05 04:50:25 +08:00
|
|
|
}
|
2003-10-19 17:44:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
line_pnts[i++] = first_pnt.x;
|
|
|
|
line_pnts[i++] = first_pnt.y;
|
|
|
|
|
|
|
|
/* Scale before drawing */
|
|
|
|
if (selvals.scaletoimage)
|
2005-12-31 01:50:19 +08:00
|
|
|
{/* FIXME scale xmax and al. */
|
2004-12-29 09:16:20 +08:00
|
|
|
scale_to_original_xy (&line_pnts[0], i/2);
|
|
|
|
scale_to_original_xy (min_max, 2);
|
|
|
|
}
|
2003-10-19 17:44:46 +08:00
|
|
|
else
|
2004-12-29 09:16:20 +08:00
|
|
|
{
|
|
|
|
scale_to_xy (&line_pnts[0], i/2);
|
|
|
|
scale_to_xy (min_max, 2);
|
|
|
|
}
|
2003-10-19 17:44:46 +08:00
|
|
|
|
2004-07-10 06:09:40 +08:00
|
|
|
|
2012-03-25 21:03:37 +08:00
|
|
|
if (gfig_context_get_current_style ()->fill_type != FILL_NONE)
|
|
|
|
{
|
|
|
|
gimp_context_push ();
|
|
|
|
gimp_context_set_antialias (selopt.antia);
|
|
|
|
gimp_context_set_feather (selopt.feather);
|
|
|
|
gimp_context_set_feather_radius (selopt.feather_radius, selopt.feather_radius);
|
2019-08-17 17:27:37 +08:00
|
|
|
gimp_image_select_polygon (gfig_context->image,
|
2012-03-25 21:03:37 +08:00
|
|
|
selopt.type,
|
|
|
|
i, line_pnts);
|
|
|
|
gimp_context_pop ();
|
|
|
|
|
|
|
|
paint_layer_fill (min_max[0], min_max[1], min_max[2], min_max[3]);
|
2019-08-17 17:27:37 +08:00
|
|
|
gimp_selection_none (gfig_context->image);
|
2012-03-25 21:03:37 +08:00
|
|
|
}
|
2004-07-10 06:09:40 +08:00
|
|
|
|
2004-11-17 06:45:35 +08:00
|
|
|
if (obj->style.paint_type == PAINT_BRUSH_TYPE)
|
2019-08-17 17:27:37 +08:00
|
|
|
gfig_paint (selvals.brshtype, gfig_context->drawable, i, line_pnts);
|
2003-10-19 17:44:46 +08:00
|
|
|
|
|
|
|
g_free (line_pnts);
|
2004-12-29 09:16:20 +08:00
|
|
|
g_free (min_max);
|
2003-10-19 17:44:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-11-16 22:10:20 +08:00
|
|
|
d_poly2lines (GfigObject *obj)
|
2003-10-19 17:44:46 +08:00
|
|
|
{
|
|
|
|
/* first point center */
|
|
|
|
/* Next point is radius */
|
2004-10-28 02:47:08 +08:00
|
|
|
DobjPoints *center_pnt;
|
|
|
|
DobjPoints *radius_pnt;
|
|
|
|
gint16 shift_x;
|
|
|
|
gint16 shift_y;
|
|
|
|
gdouble ang_grid;
|
|
|
|
gdouble ang_loop;
|
|
|
|
gdouble radius;
|
|
|
|
gdouble offset_angle;
|
|
|
|
gint loop;
|
2005-12-31 01:50:19 +08:00
|
|
|
GdkPoint first_pnt = { 0, 0 };
|
|
|
|
GdkPoint last_pnt = { 0, 0 };
|
2004-10-28 02:47:08 +08:00
|
|
|
gboolean first = TRUE;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
|
|
|
g_assert (obj != NULL);
|
|
|
|
|
|
|
|
center_pnt = obj->points;
|
|
|
|
|
|
|
|
if (!center_pnt)
|
|
|
|
return; /* no-line */
|
|
|
|
|
|
|
|
/* NULL out these points free later */
|
|
|
|
obj->points = NULL;
|
|
|
|
|
|
|
|
/* Go around all the points creating line points */
|
|
|
|
|
|
|
|
radius_pnt = center_pnt->next; /* this defines the vertices */
|
|
|
|
|
|
|
|
/* Have center and radius - get lines */
|
|
|
|
shift_x = radius_pnt->pnt.x - center_pnt->pnt.x;
|
|
|
|
shift_y = radius_pnt->pnt.y - center_pnt->pnt.y;
|
|
|
|
|
|
|
|
radius = sqrt ((shift_x*shift_x) + (shift_y*shift_y));
|
|
|
|
|
|
|
|
/* Lines */
|
2004-10-30 23:25:07 +08:00
|
|
|
ang_grid = 2.0 * G_PI / (gdouble) obj->type_data;
|
2003-10-19 17:44:46 +08:00
|
|
|
offset_angle = atan2 (shift_y, shift_x);
|
|
|
|
|
|
|
|
for (loop = 0 ; loop < obj->type_data ; loop++)
|
|
|
|
{
|
|
|
|
gdouble lx, ly;
|
|
|
|
GdkPoint calc_pnt;
|
2004-10-27 14:43:52 +08:00
|
|
|
|
2003-10-19 17:44:46 +08:00
|
|
|
ang_loop = (gdouble)loop * ang_grid + offset_angle;
|
2004-10-27 14:43:52 +08:00
|
|
|
|
2003-10-19 17:44:46 +08:00
|
|
|
lx = radius * cos (ang_loop);
|
|
|
|
ly = radius * sin (ang_loop);
|
|
|
|
|
|
|
|
calc_pnt.x = RINT (lx + center_pnt->pnt.x);
|
|
|
|
calc_pnt.y = RINT (ly + center_pnt->pnt.y);
|
|
|
|
|
|
|
|
if (!first)
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
if (calc_pnt.x == last_pnt.x && calc_pnt.y == last_pnt.y)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2003-10-19 17:44:46 +08:00
|
|
|
|
|
|
|
d_pnt_add_line (obj, calc_pnt.x, calc_pnt.y, 0);
|
|
|
|
|
2003-10-20 05:03:21 +08:00
|
|
|
last_pnt = calc_pnt;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
|
|
|
if (first)
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
first_pnt = calc_pnt;
|
|
|
|
first = FALSE;
|
|
|
|
}
|
2003-10-19 17:44:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
d_pnt_add_line (obj, first_pnt.x, first_pnt.y, 0);
|
|
|
|
/* Free old pnts */
|
|
|
|
d_delete_dobjpoints (center_pnt);
|
|
|
|
|
|
|
|
/* hey we're a line now */
|
|
|
|
obj->type = LINE;
|
2004-07-07 03:32:55 +08:00
|
|
|
obj->class = &dobj_class[LINE];
|
2003-10-19 17:44:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-11-16 22:10:20 +08:00
|
|
|
d_star2lines (GfigObject *obj)
|
2003-10-19 17:44:46 +08:00
|
|
|
{
|
|
|
|
/* first point center */
|
|
|
|
/* Next point is radius */
|
2004-10-28 02:47:08 +08:00
|
|
|
DobjPoints *center_pnt;
|
|
|
|
DobjPoints *outer_radius_pnt;
|
|
|
|
DobjPoints *inner_radius_pnt;
|
|
|
|
gint16 shift_x;
|
|
|
|
gint16 shift_y;
|
|
|
|
gdouble ang_grid;
|
|
|
|
gdouble ang_loop;
|
|
|
|
gdouble outer_radius;
|
|
|
|
gdouble inner_radius;
|
|
|
|
gdouble offset_angle;
|
|
|
|
gint loop;
|
2005-12-31 01:50:19 +08:00
|
|
|
GdkPoint first_pnt = { 0, 0 };
|
|
|
|
GdkPoint last_pnt = { 0, 0 };
|
2004-10-28 02:47:08 +08:00
|
|
|
gboolean first = TRUE;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
|
|
|
g_assert (obj != NULL);
|
|
|
|
|
|
|
|
center_pnt = obj->points;
|
|
|
|
|
|
|
|
if (!center_pnt)
|
|
|
|
return; /* no-line */
|
|
|
|
|
|
|
|
/* NULL out these points free later */
|
|
|
|
obj->points = NULL;
|
|
|
|
|
|
|
|
/* Go around all the points creating line points */
|
|
|
|
/* Next point defines the radius */
|
|
|
|
outer_radius_pnt = center_pnt->next; /* this defines the vetices */
|
|
|
|
|
|
|
|
if (!outer_radius_pnt)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
g_warning ("Internal error in star - no outer vertice point \n");
|
|
|
|
#endif /* DEBUG */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
inner_radius_pnt = outer_radius_pnt->next; /* this defines the vetices */
|
|
|
|
|
|
|
|
if (!inner_radius_pnt)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
g_warning ("Internal error in star - no inner vertice point \n");
|
|
|
|
#endif /* DEBUG */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
shift_x = outer_radius_pnt->pnt.x - center_pnt->pnt.x;
|
|
|
|
shift_y = outer_radius_pnt->pnt.y - center_pnt->pnt.y;
|
|
|
|
|
|
|
|
outer_radius = sqrt ((shift_x*shift_x) + (shift_y*shift_y));
|
|
|
|
|
|
|
|
/* Lines */
|
2004-10-30 23:25:07 +08:00
|
|
|
ang_grid = 2.0 * G_PI / (2.0 * (gdouble) obj->type_data);
|
2003-10-19 17:44:46 +08:00
|
|
|
offset_angle = atan2 (shift_y, shift_x);
|
|
|
|
|
|
|
|
shift_x = inner_radius_pnt->pnt.x - center_pnt->pnt.x;
|
|
|
|
shift_y = inner_radius_pnt->pnt.y - center_pnt->pnt.y;
|
|
|
|
|
2004-10-30 23:25:07 +08:00
|
|
|
inner_radius = sqrt ((shift_x * shift_x) + (shift_y * shift_y));
|
2003-10-19 17:44:46 +08:00
|
|
|
|
2004-10-30 23:25:07 +08:00
|
|
|
for (loop = 0 ; loop < 2 * obj->type_data ; loop++)
|
2003-10-19 17:44:46 +08:00
|
|
|
{
|
2004-10-30 23:25:07 +08:00
|
|
|
gdouble lx, ly;
|
2003-10-19 17:44:46 +08:00
|
|
|
GdkPoint calc_pnt;
|
2004-10-27 14:43:52 +08:00
|
|
|
|
2003-10-19 17:44:46 +08:00
|
|
|
ang_loop = (gdouble)loop * ang_grid + offset_angle;
|
|
|
|
|
2004-10-30 23:25:07 +08:00
|
|
|
if (loop % 2)
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
lx = inner_radius * cos (ang_loop);
|
|
|
|
ly = inner_radius * sin (ang_loop);
|
|
|
|
}
|
2003-10-19 17:44:46 +08:00
|
|
|
else
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
lx = outer_radius * cos (ang_loop);
|
|
|
|
ly = outer_radius * sin (ang_loop);
|
|
|
|
}
|
2003-10-19 17:44:46 +08:00
|
|
|
|
|
|
|
calc_pnt.x = RINT (lx + center_pnt->pnt.x);
|
|
|
|
calc_pnt.y = RINT (ly + center_pnt->pnt.y);
|
|
|
|
|
|
|
|
if (!first)
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
if (calc_pnt.x == last_pnt.x && calc_pnt.y == last_pnt.y)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2003-10-19 17:44:46 +08:00
|
|
|
|
|
|
|
d_pnt_add_line (obj, calc_pnt.x, calc_pnt.y, 0);
|
|
|
|
|
2003-10-20 05:03:21 +08:00
|
|
|
last_pnt = calc_pnt;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
|
|
|
if (first)
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
first_pnt = calc_pnt;
|
|
|
|
first = FALSE;
|
|
|
|
}
|
2003-10-19 17:44:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
d_pnt_add_line (obj, first_pnt.x, first_pnt.y, 0);
|
|
|
|
/* Free old pnts */
|
|
|
|
d_delete_dobjpoints (center_pnt);
|
|
|
|
|
|
|
|
/* hey we're a line now */
|
|
|
|
obj->type = LINE;
|
2004-07-07 03:32:55 +08:00
|
|
|
obj->class = &dobj_class[LINE];
|
2003-10-19 17:44:46 +08:00
|
|
|
}
|
|
|
|
|
2004-11-16 22:10:20 +08:00
|
|
|
static GfigObject *
|
|
|
|
d_copy_poly (GfigObject *obj)
|
2003-10-19 17:44:46 +08:00
|
|
|
{
|
2004-11-16 22:10:20 +08:00
|
|
|
GfigObject *np;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
|
|
|
g_assert (obj->type == POLY);
|
|
|
|
|
2004-07-08 01:52:16 +08:00
|
|
|
np = d_new_object (POLY, obj->points->pnt.x, obj->points->pnt.y);
|
2003-10-19 17:44:46 +08:00
|
|
|
np->points->next = d_copy_dobjpoints (obj->points->next);
|
|
|
|
np->type_data = obj->type_data;
|
|
|
|
|
|
|
|
return np;
|
|
|
|
}
|
|
|
|
|
2004-07-07 03:32:55 +08:00
|
|
|
void
|
2004-11-14 10:50:33 +08:00
|
|
|
d_poly_object_class_init (void)
|
2004-07-07 03:32:55 +08:00
|
|
|
{
|
2004-11-16 22:10:20 +08:00
|
|
|
GfigObjectClass *class = &dobj_class[POLY];
|
2004-07-07 03:32:55 +08:00
|
|
|
|
|
|
|
class->type = POLY;
|
2004-11-28 23:44:18 +08:00
|
|
|
class->name = "POLY";
|
2004-07-07 03:32:55 +08:00
|
|
|
class->drawfunc = d_draw_poly;
|
|
|
|
class->paintfunc = d_paint_poly;
|
|
|
|
class->copyfunc = d_copy_poly;
|
2004-12-05 01:33:54 +08:00
|
|
|
class->update = d_update_poly;
|
2003-10-19 17:44:46 +08:00
|
|
|
}
|
|
|
|
|
2004-12-05 01:33:54 +08:00
|
|
|
static void
|
2003-10-19 17:44:46 +08:00
|
|
|
d_update_poly (GdkPoint *pnt)
|
|
|
|
{
|
2004-10-28 02:47:08 +08:00
|
|
|
DobjPoints *center_pnt;
|
|
|
|
DobjPoints *edge_pnt;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
|
|
|
center_pnt = obj_creating->points;
|
2004-10-27 14:43:52 +08:00
|
|
|
|
2003-10-19 17:44:46 +08:00
|
|
|
if (!center_pnt)
|
|
|
|
return; /* No points */
|
|
|
|
|
|
|
|
if ((edge_pnt = center_pnt->next))
|
|
|
|
{
|
2003-10-24 21:28:46 +08:00
|
|
|
edge_pnt->pnt = *pnt;
|
2003-10-19 17:44:46 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d_pnt_add_line (obj_creating, pnt->x, pnt->y, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
d_poly_start (GdkPoint *pnt,
|
2004-11-16 22:10:20 +08:00
|
|
|
gboolean shift_down)
|
2003-10-19 17:44:46 +08:00
|
|
|
{
|
2004-07-08 01:52:16 +08:00
|
|
|
obj_creating = d_new_object (POLY, pnt->x, pnt->y);
|
2003-10-19 17:44:46 +08:00
|
|
|
obj_creating->type_data = poly_num_sides;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-02-05 08:08:21 +08:00
|
|
|
d_poly_end (GimpGfig *gfig,
|
|
|
|
GdkPoint *pnt,
|
2004-11-16 22:10:20 +08:00
|
|
|
gboolean shift_down)
|
2003-10-19 17:44:46 +08:00
|
|
|
{
|
2023-02-05 08:08:21 +08:00
|
|
|
add_to_all_obj (gfig, gfig_context->current_obj, obj_creating);
|
2003-10-19 17:44:46 +08:00
|
|
|
obj_creating = NULL;
|
|
|
|
}
|