gimp/plug-ins/gfig/gfig-ellipse.c

286 lines
6.8 KiB
C
Raw Normal View History

/*
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This is a plug-in for the GIMP.
*
* Generates images containing vector type drawings.
*
* Copyright (C) 1997 Andy Thomas alt@picnic.demon.co.uk
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (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
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include "config.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include "gfig.h"
#include "gfig-dobject.h"
#include "libgimp/stdplugins-intl.h"
static void d_draw_ellipse (GfigObject *obj);
static void d_paint_ellipse (GfigObject *obj);
static GfigObject *d_copy_ellipse (GfigObject *obj);
static void d_update_ellipse (GdkPoint *pnt);
static void
d_draw_ellipse (GfigObject * obj)
{
DobjPoints *center_pnt;
DobjPoints *edge_pnt;
gint bound_wx;
gint bound_wy;
gint top_x;
gint top_y;
center_pnt = obj->points;
if (!center_pnt)
return; /* End-of-line */
edge_pnt = center_pnt->next;
if (!edge_pnt)
{
g_warning ("Internal error - ellipse no edge pnt");
}
draw_sqr (&center_pnt->pnt, obj == gfig_context->selected_obj);
draw_sqr (&edge_pnt->pnt, obj == gfig_context->selected_obj);
bound_wx = abs (center_pnt->pnt.x - edge_pnt->pnt.x);
bound_wy = abs (center_pnt->pnt.y - edge_pnt->pnt.y);
if (edge_pnt->pnt.x > center_pnt->pnt.x)
top_x = 2 * center_pnt->pnt.x - edge_pnt->pnt.x;
else
top_x = edge_pnt->pnt.x;
if (edge_pnt->pnt.y > center_pnt->pnt.y)
top_y = 2 * center_pnt->pnt.y - edge_pnt->pnt.y;
else
top_y = edge_pnt->pnt.y;
gfig_draw_arc (center_pnt->pnt.x, center_pnt->pnt.y, bound_wx, bound_wy, 0, 360);
}
static void
d_paint_ellipse (GfigObject *obj)
{
DobjPoints *center_pnt;
DobjPoints *edge_pnt;
gint bound_wx;
gint bound_wy;
gint top_x;
gint top_y;
gdouble dpnts[4];
/* Drawing ellipse is hard .
* 1) select ellipse
* 2) stroke it
*/
g_assert (obj != NULL);
center_pnt = obj->points;
if (!center_pnt)
return; /* End-of-line */
edge_pnt = center_pnt->next;
if (!edge_pnt)
{
g_error ("Internal error - ellipse no edge pnt");
}
bound_wx = abs (center_pnt->pnt.x - edge_pnt->pnt.x)*2;
bound_wy = abs (center_pnt->pnt.y - edge_pnt->pnt.y)*2;
if (edge_pnt->pnt.x > center_pnt->pnt.x)
top_x = 2*center_pnt->pnt.x - edge_pnt->pnt.x;
else
top_x = edge_pnt->pnt.x;
if (edge_pnt->pnt.y > center_pnt->pnt.y)
top_y = 2*center_pnt->pnt.y - edge_pnt->pnt.y;
else
top_y = edge_pnt->pnt.y;
dpnts[0] = (gdouble)top_x;
dpnts[1] = (gdouble)top_y;
dpnts[2] = (gdouble)bound_wx;
dpnts[3] = (gdouble)bound_wy;
/* Scale before drawing */
if (selvals.scaletoimage)
scale_to_original_xy (&dpnts[0], 2);
else
scale_to_xy (&dpnts[0], 2);
gimp_ellipse_select (gfig_context->image_id,
dpnts[0], dpnts[1],
dpnts[2], dpnts[3],
selopt.type,
selopt.antia,
selopt.feather,
selopt.feather_radius);
paint_layer_fill (top_x, top_y, top_x + bound_wx, top_y + bound_wy);
if (obj->style.paint_type == PAINT_BRUSH_TYPE)
gimp_edit_stroke (gfig_context->drawable_id);
}
static GfigObject *
d_copy_ellipse (GfigObject * obj)
{
GfigObject *nc;
g_assert (obj->type == ELLIPSE);
nc = d_new_object (ELLIPSE, obj->points->pnt.x, obj->points->pnt.y);
nc->points->next = d_copy_dobjpoints (obj->points->next);
return nc;
}
void
Fix a bunch of warnings from Sparse: 2004-11-13 Manish Singh <yosh@gimp.org> Fix a bunch of warnings from Sparse: * app/actions/dockable-commands.c * app/actions/layers-actions.c * app/actions/view-commands.c * app/base/pixel-surround.c * app/config/gimpconfig-utils.c * app/config/gimpscanner.c * app/core/gimpbrushgenerated.c * app/core/gimpcontainer.c * app/core/gimpimage.c * app/dialogs/palette-import-dialog.c * app/file/gimprecentlist.c * app/plug-in/plug-in-params.c * app/text/gimptext-compat.c * app/text/gimptext-parasite.c * app/vectors/gimpbezierstroke.c * app/vectors/gimpstroke.c * app/widgets/gimpcellrendereraccel.c * app/widgets/gimpselectiondata.c * app/xcf/xcf.c * libgimp/gimp.c * libgimpthumb/gimpthumb-utils.c * libgimpthumb/gimpthumbnail.c * modules/cdisplay_proof.c * plug-ins/Lighting/lighting_ui.c * plug-ins/common/csource.c * plug-ins/common/glasstile.c * plug-ins/common/nova.c * plug-ins/common/pcx.c * plug-ins/common/pnm.c * plug-ins/common/randomize.c * plug-ins/common/screenshot.c * plug-ins/common/sel_gauss.c * plug-ins/common/spheredesigner.c * plug-ins/common/wind.c * plug-ins/gfig/gfig-dialog.c * plug-ins/gfig/gfig-dobject.c * plug-ins/gimpressionist/gimpressionist.c * plug-ins/ifscompose/ifscompose.c * plug-ins/print/gimp_main_window.c * plug-ins/print/print.c: Cleanup integer vs. pointer confusion. * app/base/temp-buf.c * app/dialogs/about-dialog.c * plug-ins/common/bumpmap.c * plug-ins/common/jigsaw.c * plug-ins/gfig/gfig-dobject.c: Cosmetic cleanups. * app/config/gimpconfig-deserialize.c * app/config/gimpconfig-path.c * app/config/gimpconfigwriter.c * app/core/gimpgradient.c * app/tools/gimpdrawtool.c * plug-ins/common/nlfilt.c * plug-ins/common/unsharp.c * plug-ins/common/zealouscrop.c: Define inline functions before they are used. * app/core/gimpdrawable-blend.c: PixelRegion definition was changed some time ago, but the initialization here didn't change. Fix it. * app/plug-in/plug-in-rc.c (plug_in_extra_deserialize): No need to assign token twice in a row. * libgimpbase/gimpdatafiles.c (gimp_datafiles_read_directories): No need to initialize file_data, since the code fills out all the fields. * plug-ins/common/CML_explorer.c * plug-ins/common/vpropagate.c: Declare function pointers fully. * plug-ins/common/grid.c (pix_composite): G_INLINE_FUNC isn't needed, we assume we can use the "inline" keyword always. * plug-ins/common/psd_save.c * plug-ins/common/vinvert.c * plug-ins/gfig/gfig-arc.c * plug-ins/gfig/gfig-bezier.c * plug-ins/gfig/gfig-circle.c * plug-ins/gfig/gfig-dialog.c * plug-ins/gfig/gfig-dobject.c * plug-ins/gfig/gfig-ellipse.c * plug-ins/gfig/gfig-line.c * plug-ins/gfig/gfig-poly.c * plug-ins/gfig/gfig-spiral.c * plug-ins/gfig/gfig-star.c * plug-ins/gfig/gfig.c * plug-ins/gimpressionist/orientmap.c * plug-ins/gimpressionist/placement.c * plug-ins/gimpressionist/sizemap.c * plug-ins/imagemap/imap_grid.c * plug-ins/imagemap/imap_main.c * plug-ins/imagemap/imap_preferences.c * plug-ins/imagemap/imap_settings.c * plug-ins/maze/maze.c * plug-ins/sel2path/curve.c * plug-ins/sel2path/fit.c * plug-ins/sel2path/pxl-outline.c * plug-ins/sel2path/spline.c * plug-ins/xjt/xjt.c: Functions with no args should be declared with (void). * plug-ins/common/retinex.c (MSRCR): Initialize max_preview to quiet the compiler.
2004-11-14 10:50:33 +08:00
d_ellipse_object_class_init (void)
{
GfigObjectClass *class = &dobj_class[ELLIPSE];
class->type = ELLIPSE;
class->name = "ELLIPSE";
class->drawfunc = d_draw_ellipse;
class->paintfunc = d_paint_ellipse;
class->copyfunc = d_copy_ellipse;
class->update = d_update_ellipse;
}
static void
d_update_ellipse (GdkPoint *pnt)
{
DobjPoints *center_pnt, *edge_pnt;
gint bound_wx;
gint bound_wy;
gint top_x;
gint top_y;
/* Undraw last one then draw new one */
center_pnt = obj_creating->points;
if (!center_pnt)
return; /* No points */
if ((edge_pnt = center_pnt->next))
{
/* Undraw current */
bound_wx = abs (center_pnt->pnt.x - edge_pnt->pnt.x) * 2;
bound_wy = abs (center_pnt->pnt.y - edge_pnt->pnt.y) * 2;
if (edge_pnt->pnt.x > center_pnt->pnt.x)
top_x = 2 * center_pnt->pnt.x - edge_pnt->pnt.x;
else
top_x = edge_pnt->pnt.x;
if (edge_pnt->pnt.y > center_pnt->pnt.y)
top_y = 2 * center_pnt->pnt.y - edge_pnt->pnt.y;
else
top_y = edge_pnt->pnt.y;
draw_circle (&edge_pnt->pnt, TRUE);
gdk_draw_arc (gfig_context->preview->window,
gfig_gc,
0,
top_x,
top_y,
bound_wx,
bound_wy,
0,
360 * 64);
edge_pnt->pnt = *pnt;
}
else
{
edge_pnt = new_dobjpoint (pnt->x, pnt->y);
center_pnt->next = edge_pnt;
}
draw_circle (&edge_pnt->pnt, TRUE);
bound_wx = abs (center_pnt->pnt.x - edge_pnt->pnt.x) * 2;
bound_wy = abs (center_pnt->pnt.y - edge_pnt->pnt.y) * 2;
if (edge_pnt->pnt.x > center_pnt->pnt.x)
top_x = 2 * center_pnt->pnt.x - edge_pnt->pnt.x;
else
top_x = edge_pnt->pnt.x;
if (edge_pnt->pnt.y > center_pnt->pnt.y)
top_y = 2 * center_pnt->pnt.y - edge_pnt->pnt.y;
else
top_y = edge_pnt->pnt.y;
gdk_draw_arc (gfig_context->preview->window,
gfig_gc,
0,
top_x,
top_y,
bound_wx,
bound_wy,
0,
360 * 64);
}
void
d_ellipse_start (GdkPoint *pnt,
gboolean shift_down)
{
obj_creating = d_new_object (ELLIPSE, pnt->x, pnt->y);
}
void
d_ellipse_end (GdkPoint *pnt,
gboolean shift_down)
{
/* Under contrl point */
if (!obj_creating->points->next)
{
/* No circle created */
free_one_obj (obj_creating);
}
else
{
draw_circle (pnt, TRUE);
add_to_all_obj (gfig_context->current_obj, obj_creating);
}
obj_creating = NULL;
}