gimp/app/tools/gimpdrawtool.c

2103 lines
70 KiB
C
Raw Normal View History

/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995-2001 Spencer Kimball, Peter Mattis, and others
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <string.h>
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpmath/gimpmath.h"
devel-docs/Makefile.am new file documenting the core's include policy. 2002-05-03 Michael Natterer <mitch@gimp.org> * devel-docs/Makefile.am * devel-docs/includes.txt: new file documenting the core's include policy. * HACKING: mention it here. * libgimptool/gimptooltypes.h: removed GimpToolOptions here. * app/core/core-types.h: and added it here. This is a temp hack needed because GimpToolInfo needs to know the GimpToolOptions type. * libgimpproxy/gimpproxytypes.h: regenerated. * libgimptool/gimptoolmodule.h: don't include gimptooltypes.h here... * libgimptool/gimptoolmodule.c: ...but here. * app/config/gimpconfig-params.c: include "libgimpbase/gimpbase.h" entirely, not single files from it. * app/core/gimp.c * app/core/gimpcontext.c * app/core/gimpcoreconfig.c * app/core/gimpdatafactory.c * app/core/gimpdocuments.c * app/core/gimpdrawable-blend.c * app/core/gimpdrawable-bucket-fill.c * app/core/gimpdrawable-offset.c * app/core/gimpdrawable-transform.c * app/core/gimpdrawable.c * app/core/gimpedit.c * app/core/gimpimage-convert.c * app/core/gimpimage-crop.c * app/core/gimpimage-duplicate.c * app/core/gimpimage-guides.c * app/core/gimpimage-mask.c * app/core/gimpimage-merge.c * app/core/gimpimage-new.c * app/core/gimpimage-projection.c * app/core/gimpimage-qmask.c * app/core/gimpimage-resize.c * app/core/gimpimage-scale.c * app/core/gimpimage.c * app/core/gimpitem.c * app/core/gimpmodules.c * app/core/gimppaintinfo.c * app/core/gimpparasite.c * app/core/gimppreviewcache.c * app/core/gimptoolinfo.c * app/core/gimpunit.c: include "core-types.h" and no other types file. * app/display/gimpdisplay.c * app/display/gimpdisplayshell-callbacks.c * app/display/gimpdisplayshell.c: include "tools/tools-types.h" instead of "libgimptool/gimptooltypes.h", warn about inclusion on "gui/gui-types.h" * app/file/file-open.c * app/file/file-save.c: don't include "libgimptool/gimptooltypes.h". * app/gui/about-dialog.c * app/gui/brush-select.c * app/gui/brushes-commands.c * app/gui/color-select.c * app/gui/data-commands.c * app/gui/device-status-dialog.c * app/gui/dialogs.c * app/gui/gradients-commands.c * app/gui/help-commands.c * app/gui/info-window.c * app/gui/palettes-commands.c * app/gui/patterns-commands.c * app/gui/resize-dialog.c * app/gui/tips-dialog.c * app/gui/tool-options-dialog.c: include "gui-types.h" and no other types file. * app/paint/gimpairbrush.c * app/paint/gimpclone.c * app/paint/gimpconvolve.c * app/paint/gimpdodgeburn.c * app/paint/gimperaser.c * app/paint/gimppaintbrush.c * app/paint/gimppaintcore-stroke.c * app/paint/gimppaintcore.c * app/paint/gimppaintoptions.c * app/paint/gimppencil.c * app/paint/gimpsmudge.c * app/paint/paint.c: include "paint-types.h" and no other types file. * app/pdb/pdb-types.h: don't include "libgimptool/gimptooltypes.h". * app/plug-in/plug-in-progress.c: warn about inclusion of "display/display-types.h" * app/tools/tools-types.h: include "libgimptool/gimptooltypes.h". * app/tools/gimpairbrushtool.c * app/tools/gimpbezierselecttool.c * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpbucketfilltool.c * app/tools/gimpbycolorselecttool.c * app/tools/gimpclonetool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcolorpickertool.c * app/tools/gimpconvolvetool.c * app/tools/gimpcroptool.c * app/tools/gimpcurvestool.c * app/tools/gimpdodgeburntool.c * app/tools/gimpdrawtool.c * app/tools/gimpeditselectiontool.c * app/tools/gimpellipseselecttool.c * app/tools/gimperasertool.c * app/tools/gimpfliptool.c * app/tools/gimpfreeselecttool.c * app/tools/gimpfuzzyselecttool.c * app/tools/gimphistogramtool.c * app/tools/gimphuesaturationtool.c * app/tools/gimpinktool.c * app/tools/gimplevelstool.c * app/tools/gimpmagnifytool.c * app/tools/gimpmeasuretool.c * app/tools/gimpmovetool.c * app/tools/gimppaintbrushtool.c * app/tools/gimppainttool.c * app/tools/gimppathtool.c * app/tools/gimppenciltool.c * app/tools/gimpperspectivetool.c * app/tools/gimpposterizetool.c * app/tools/gimprectselecttool.c * app/tools/gimprotatetool.c * app/tools/gimpscaletool.c * app/tools/gimpselectiontool.c * app/tools/gimpsheartool.c * app/tools/gimpsmudgetool.c * app/tools/gimptexttool.c * app/tools/gimpthresholdtool.c * app/tools/gimptoolcontrol.c * app/tools/gimptoolcontrol.h * app/tools/gimptransformtool.c * app/tools/gimpvectortool.c * app/tools/tools.c: include "tools-types.h" and no other types file, warn about inclusion of "gui/gui-types.h". * app/widgets/gimpcolorpanel.c * app/widgets/gimptoolbox-color-area.c: warn about inclusion of "gui/gui-types.h". * app/xcf/xcf-load.c * app/xcf/xcf.c: don't include "libgimptool/gimptooltypes.h". Split tool-safe-mode up in two files, one including libgimpproxy, one libgimp. * plug-ins/tools/Makefile.am * plug-ins/tools/tool-safe-mode-plug-in.[ch]: new files including libgimp/ stuff only. * plug-ins/tools/tool-safe-mode.[ch]: include libgimpproxy/ and libgimptool/ but don't include libgimp/ because of conflicting declarations. Unrelated: * app/tools/gimpclonetool.c: create the clone core so we don't crash. * app/gui/file-open-dialog.c: changed the way we create previews so that only out-of-date previews are created on a click in the preview area. Unconditional creation can still be forced by <Ctrl>+click. Changed the tooltip to document this.
2002-05-03 20:45:22 +08:00
#include "tools-types.h"
#include "base/boundary.h"
#include "core/gimpimage.h"
#include "vectors/gimpanchor.h"
#include "vectors/gimpstroke.h"
#include "vectors/gimpvectors.h"
#include "display/gimpcanvas.h"
#include "display/gimpcanvashandle.h"
#include "display/gimpcanvasline.h"
2010-09-23 06:00:07 +08:00
#include "display/gimpcanvaspolygon.h"
#include "display/gimpcanvasrectangle.h"
#include "display/gimpdisplay.h"
2001-11-01 05:20:09 +08:00
#include "display/gimpdisplayshell.h"
#include "display/gimpdisplayshell-transform.h"
#include "gimpdrawtool.h"
static void gimp_draw_tool_dispose (GObject *object);
static gboolean gimp_draw_tool_has_display (GimpTool *tool,
GimpDisplay *display);
static GimpDisplay * gimp_draw_tool_has_image (GimpTool *tool,
GimpImage *image);
static void gimp_draw_tool_control (GimpTool *tool,
GimpToolAction action,
GimpDisplay *display);
static void gimp_draw_tool_draw (GimpDrawTool *draw_tool);
static void gimp_draw_tool_undraw (GimpDrawTool *draw_tool);
static void gimp_draw_tool_real_draw (GimpDrawTool *draw_tool);
static inline void gimp_draw_tool_shift_to_north_west
(gdouble x,
gdouble y,
gint handle_width,
gint handle_height,
GtkAnchorType anchor,
gdouble *shifted_x,
gdouble *shifted_y);
static inline void gimp_draw_tool_shift_to_center
(gdouble x,
gdouble y,
gint handle_width,
gint handle_height,
GtkAnchorType anchor,
gdouble *shifted_x,
gdouble *shifted_y);
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
G_DEFINE_TYPE (GimpDrawTool, gimp_draw_tool, GIMP_TYPE_TOOL)
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
#define parent_class gimp_draw_tool_parent_class
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
static void
gimp_draw_tool_class_init (GimpDrawToolClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
object_class->dispose = gimp_draw_tool_dispose;
tool_class->has_display = gimp_draw_tool_has_display;
tool_class->has_image = gimp_draw_tool_has_image;
tool_class->control = gimp_draw_tool_control;
klass->draw = gimp_draw_tool_real_draw;
}
static void
gimp_draw_tool_init (GimpDrawTool *draw_tool)
{
draw_tool->display = NULL;
made the gimp_object_get_memsize() debugging output configurable by a 2002-02-06 Michael Natterer <mitch@gimp.org> * app/core/gimpobject.c: made the gimp_object_get_memsize() debugging output configurable by a global "gimp_debug_memsize" boolean. * app/display/gimpdisplay.c: removed duplicated prototype. * app/display/gimpdisplayshell.[ch]: renamed the various cursor functions to be more consistent and shorter. Compress window title updates by adding a "gboolean title_dirty" and updating the title in gimp_display_shell_flush(). Added "%m" (memory size) to the possible title string substitutions. * app/display/gimpdisplay-foreach.c * app/display/gimpdisplayshell-handlers.c * app/tools/gimpfuzzyselecttool.c * app/tools/gimptool.c: changed accordingly. * app/display/gimpdisplayshell-callbacks.c: forgot to grab the pointer when dragging guides from the rulers. Coincidentially, this also fixes the buggy offset between guide and mouse pointer... Cleaned up the main tool event callback a but more. * app/widgets/gimppreview.c * app/gui/commands.c: set the new global "gimp_debug_memsize" toggle to TRUE while calling gimp_object_get_memsize(). * app/gui/preferences-dialog.c: added a image title example containing the new "%m" feature. * docs/gimprc-1.3.5.in: document "%m" in the manpage. * app/tools/gimpbezierselecttool.c: reordered some statements. * app/tools/gimpdrawtool.[ch]: store the GimpDisplay passed to gimp_draw_tool_start() in draw_tool->gdisp and use it for coordinate transfomration. This way we can paint on a display which is not tool->gdisp. * app/tools/gimppainttool.c: changed the gimp_draw_tool_foo() calls needed to make the straight_line preview work in a way that does not interfere with paint_tool subclasses which want to do their own drawing (like the clone tool). Also changed the paint_tools PRETRACE_PAINT and POSTTRACE_PAINT flags usage in a way that subclasses can use them without major hackery: don't simply wrap gimp_display_flush_now() with PRETRACE/POSTTRACE calls, but wrap the actual painting calls, so subclasses are able to do useful things with paint_tool->*_coords. * app/tools/gimpclonetool.c: removed poking around in draw_tool internals and simply suspend()/resume() it in PRETRACE_PAINT/POSTTRACE_PAINT to get the clone_src indicator drawn correctly.
2002-02-07 19:33:01 +08:00
draw_tool->paused_count = 0;
draw_tool->is_drawn = FALSE;
}
static void
gimp_draw_tool_dispose (GObject *object)
{
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static gboolean
gimp_draw_tool_has_display (GimpTool *tool,
GimpDisplay *display)
{
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
return (display == draw_tool->display ||
GIMP_TOOL_CLASS (parent_class)->has_display (tool, display));
}
static GimpDisplay *
gimp_draw_tool_has_image (GimpTool *tool,
GimpImage *image)
{
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
GimpDisplay *display;
display = GIMP_TOOL_CLASS (parent_class)->has_image (tool, image);
if (! display && draw_tool->display)
{
if (image && gimp_display_get_image (draw_tool->display) == image)
display = draw_tool->display;
/* NULL image means any display */
if (! image)
display = draw_tool->display;
}
return display;
}
static void
gimp_draw_tool_control (GimpTool *tool,
GimpToolAction action,
GimpDisplay *display)
{
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
switch (action)
{
case GIMP_TOOL_ACTION_PAUSE:
if (! draw_tool->use_cairo)
gimp_draw_tool_pause (draw_tool);
break;
case GIMP_TOOL_ACTION_RESUME:
if (! draw_tool->use_cairo)
gimp_draw_tool_resume (draw_tool);
break;
case GIMP_TOOL_ACTION_HALT:
gimp_draw_tool_stop (draw_tool);
break;
}
an evil temp_hack which lets GimpContext managing the active display 2001-08-14 Michael Natterer <mitch@gimp.org> * app/gdisplay.h: an evil temp_hack which lets GimpContext managing the active display withoug including "gdisplay.h". Will go away as soon ad context properties are registered dynamically. * app/module_db.c: cleaned up the object code in preparation of moving it to core/. * app/path.c: connect to GimpImage's * app/core/gimpobject.[ch]: derive it from GObject, not from GtkObject any more (yeah :-) * app/core/*.c: #include <glib-object.h> instead of <gtk/gtk.h>, removed some remaining GtkObject-isms. (left in a few #include <gtk/gtk.h> where bigger changes are needed to get rid of the UI dependency). * app/core/core-types.h: #include <gdk-pixbuf/gdk-pixbuf.h> here temporarily. * app/core/gimp.c (gimp_create_display): unref the image after creating it's first display. * app/core/gimpbrush.[ch]: disabled the parts of the code which depend on GimpPaintTool. * app/core/gimpbrushgenerated.c * app/core/gimpbrushpipe.c: changed accordingly. * app/core/gimpcontext.[ch]: evil hack (see above) to manage the active display without including "gdisplay.h" * app/core/gimpimage-mask.[ch]: pass a context to gimage_mask_stroke() and get the current tool's PDB string from there. * app/core/gimpedit.c: changed accordingly. * app/core/gimpimage.c: use gimp_image_update() instead of gdisplays_update_full(). * app/gui/color-area.c * app/gui/colormap-dialog.c * app/gui/dialogs-constructors.c * app/gui/edit-commands.c * app/gui/image-commands.c * app/gui/toolbox.c: changed accordingly (don't use Gtk methods on GObjects). * app/gui/menus.c: fix some const warnings by explicit casting. * app/tools/*.[ch]: ported all tools to GObject, some minor cleanup while i was on it. * app/widgets/gimpdialogfactory.[ch]: ported to GObject. * app/widgets/gimplayerlistview.h: added FOO_GET_CLASS() macro. * tools/pdbgen/app.pl: added a "widgets_eek" hack like "tools_eek" which inserts #include "widgets/widgets-types.h" before ordinary includes. * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/edit.pdb * app/pdb/brush_select_cmds.c * app/pdb/edit_cmds.c: changed according to the stuff above.
2001-08-14 22:53:55 +08:00
GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
}
static void
gimp_draw_tool_draw (GimpDrawTool *draw_tool)
{
if (draw_tool->paused_count == 0 &&
draw_tool->display)
{
if (draw_tool->use_cairo)
{
GimpDisplayShell *shell = gimp_display_get_shell (draw_tool->display);
GdkWindow *window = gtk_widget_get_window (shell->canvas);
GList *list;
if (draw_tool->items)
{
g_list_foreach (draw_tool->items, (GFunc) g_object_unref, NULL);
g_list_free (draw_tool->items);
draw_tool->items = NULL;
}
GIMP_DRAW_TOOL_GET_CLASS (draw_tool)->draw (draw_tool);
for (list = draw_tool->items; list; list = g_list_next (list))
{
GimpCanvasItem *item = list->data;
GdkRegion *region;
region = gimp_canvas_item_get_extents (item, shell);
gdk_window_invalidate_region (window, region, TRUE);
gdk_region_destroy (region);
}
}
else
{
GIMP_DRAW_TOOL_GET_CLASS (draw_tool)->draw (draw_tool);
}
draw_tool->is_drawn = TRUE;
}
}
static void
gimp_draw_tool_undraw (GimpDrawTool *draw_tool)
{
if (draw_tool->paused_count == 0 &&
draw_tool->display)
{
if (draw_tool->use_cairo)
{
GimpDisplayShell *shell = gimp_display_get_shell (draw_tool->display);
GdkWindow *window = gtk_widget_get_window (shell->canvas);
GList *list;
for (list = draw_tool->items; list; list = g_list_next (list))
{
GimpCanvasItem *item = list->data;
GdkRegion *region;
region = gimp_canvas_item_get_extents (item, shell);
gdk_window_invalidate_region (window, region, TRUE);
gdk_region_destroy (region);
}
if (draw_tool->items)
{
g_list_foreach (draw_tool->items, (GFunc) g_object_unref, NULL);
g_list_free (draw_tool->items);
draw_tool->items = NULL;
}
}
else
{
GIMP_DRAW_TOOL_GET_CLASS (draw_tool)->draw (draw_tool);
}
draw_tool->is_drawn = FALSE;
}
}
static void
gimp_draw_tool_real_draw (GimpDrawTool *draw_tool)
{
/* the default implementation does nothing */
}
void
gimp_draw_tool_start (GimpDrawTool *draw_tool,
GimpDisplay *display)
{
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
g_return_if_fail (GIMP_IS_DISPLAY (display));
app/display/Makefile.am app/display/display-types.h new widget derived 2002-02-03 Michael Natterer <mitch@gimp.org> * app/display/Makefile.am * app/display/display-types.h * app/display/gimpstatusbar.[ch]: new widget derived from GtkStatusbar. Contains the coordinates display, a progress bar which is also used for status message display and a cancel button. Added a simplified API for pushing/popping messages which takes a string as context_id and does the conversion to guint internally on each call. * app/display/gimpdisplayshell.[ch]: removed the status bar code. * app/display/gimpdisplayshell-callbacks.c * app/display/gimpdisplayshell-handlers.c * app/display/gimpdisplayshell-scale.c * app/gui/view-commands.c * app/gimpprogress.c: changed accordingly. Removed knowledge about GimpDisplayShell from tools: * app/tools/gimptool.[ch]: added gimp_tool_push_status() and gimp_tool_pop_status() so tools don't need to fiddle with display details. * app/tools/gimpdrawtool.[ch]: pass a GimpDisplay instead of a GdkWindow to gimp_draw_tool_start() (the window passed was always gdisp->shell->canvas->window). * app/tools/gimpbezierselecttool.c * app/tools/gimpblendtool.[ch] * app/tools/gimpclonetool.c * app/tools/gimpcolorpickertool.c * app/tools/gimpcroptool.[ch] * app/tools/gimpeditselectiontool.c * app/tools/gimpfreeselecttool.c * app/tools/gimpfuzzyselecttool.c * app/tools/gimpiscissorstool.c * app/tools/gimpmagnifytool.c * app/tools/gimpmeasuretool.[ch] * app/tools/gimpmovetool.c * app/tools/gimppainttool.[ch] * app/tools/gimppathtool.c * app/tools/gimprectselecttool.[ch] * app/tools/gimptransformtool.c: changed accordingly: - pass GimpDisplay to gimp_draw_tool_start(). - use GimpTool's new status push/pop functions. - removed the statusbar context_id from all tool structs. * app/gui/dialogs-constructors.[ch]: a bit cleanup in preparation of dockable editor dialogs.
2002-02-03 20:10:23 +08:00
made the gimp_object_get_memsize() debugging output configurable by a 2002-02-06 Michael Natterer <mitch@gimp.org> * app/core/gimpobject.c: made the gimp_object_get_memsize() debugging output configurable by a global "gimp_debug_memsize" boolean. * app/display/gimpdisplay.c: removed duplicated prototype. * app/display/gimpdisplayshell.[ch]: renamed the various cursor functions to be more consistent and shorter. Compress window title updates by adding a "gboolean title_dirty" and updating the title in gimp_display_shell_flush(). Added "%m" (memory size) to the possible title string substitutions. * app/display/gimpdisplay-foreach.c * app/display/gimpdisplayshell-handlers.c * app/tools/gimpfuzzyselecttool.c * app/tools/gimptool.c: changed accordingly. * app/display/gimpdisplayshell-callbacks.c: forgot to grab the pointer when dragging guides from the rulers. Coincidentially, this also fixes the buggy offset between guide and mouse pointer... Cleaned up the main tool event callback a but more. * app/widgets/gimppreview.c * app/gui/commands.c: set the new global "gimp_debug_memsize" toggle to TRUE while calling gimp_object_get_memsize(). * app/gui/preferences-dialog.c: added a image title example containing the new "%m" feature. * docs/gimprc-1.3.5.in: document "%m" in the manpage. * app/tools/gimpbezierselecttool.c: reordered some statements. * app/tools/gimpdrawtool.[ch]: store the GimpDisplay passed to gimp_draw_tool_start() in draw_tool->gdisp and use it for coordinate transfomration. This way we can paint on a display which is not tool->gdisp. * app/tools/gimppainttool.c: changed the gimp_draw_tool_foo() calls needed to make the straight_line preview work in a way that does not interfere with paint_tool subclasses which want to do their own drawing (like the clone tool). Also changed the paint_tools PRETRACE_PAINT and POSTTRACE_PAINT flags usage in a way that subclasses can use them without major hackery: don't simply wrap gimp_display_flush_now() with PRETRACE/POSTTRACE calls, but wrap the actual painting calls, so subclasses are able to do useful things with paint_tool->*_coords. * app/tools/gimpclonetool.c: removed poking around in draw_tool internals and simply suspend()/resume() it in PRETRACE_PAINT/POSTTRACE_PAINT to get the clone_src indicator drawn correctly.
2002-02-07 19:33:01 +08:00
gimp_draw_tool_stop (draw_tool);
draw_tool->display = display;
gimp_draw_tool_draw (draw_tool);
}
void
gimp_draw_tool_stop (GimpDrawTool *draw_tool)
{
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
gimp_draw_tool_undraw (draw_tool);
made the gimp_object_get_memsize() debugging output configurable by a 2002-02-06 Michael Natterer <mitch@gimp.org> * app/core/gimpobject.c: made the gimp_object_get_memsize() debugging output configurable by a global "gimp_debug_memsize" boolean. * app/display/gimpdisplay.c: removed duplicated prototype. * app/display/gimpdisplayshell.[ch]: renamed the various cursor functions to be more consistent and shorter. Compress window title updates by adding a "gboolean title_dirty" and updating the title in gimp_display_shell_flush(). Added "%m" (memory size) to the possible title string substitutions. * app/display/gimpdisplay-foreach.c * app/display/gimpdisplayshell-handlers.c * app/tools/gimpfuzzyselecttool.c * app/tools/gimptool.c: changed accordingly. * app/display/gimpdisplayshell-callbacks.c: forgot to grab the pointer when dragging guides from the rulers. Coincidentially, this also fixes the buggy offset between guide and mouse pointer... Cleaned up the main tool event callback a but more. * app/widgets/gimppreview.c * app/gui/commands.c: set the new global "gimp_debug_memsize" toggle to TRUE while calling gimp_object_get_memsize(). * app/gui/preferences-dialog.c: added a image title example containing the new "%m" feature. * docs/gimprc-1.3.5.in: document "%m" in the manpage. * app/tools/gimpbezierselecttool.c: reordered some statements. * app/tools/gimpdrawtool.[ch]: store the GimpDisplay passed to gimp_draw_tool_start() in draw_tool->gdisp and use it for coordinate transfomration. This way we can paint on a display which is not tool->gdisp. * app/tools/gimppainttool.c: changed the gimp_draw_tool_foo() calls needed to make the straight_line preview work in a way that does not interfere with paint_tool subclasses which want to do their own drawing (like the clone tool). Also changed the paint_tools PRETRACE_PAINT and POSTTRACE_PAINT flags usage in a way that subclasses can use them without major hackery: don't simply wrap gimp_display_flush_now() with PRETRACE/POSTTRACE calls, but wrap the actual painting calls, so subclasses are able to do useful things with paint_tool->*_coords. * app/tools/gimpclonetool.c: removed poking around in draw_tool internals and simply suspend()/resume() it in PRETRACE_PAINT/POSTTRACE_PAINT to get the clone_src indicator drawn correctly.
2002-02-07 19:33:01 +08:00
draw_tool->display = NULL;
}
gboolean
gimp_draw_tool_is_active (GimpDrawTool *draw_tool)
{
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), FALSE);
return draw_tool->display != NULL;
}
void
gimp_draw_tool_pause (GimpDrawTool *draw_tool)
{
use "gimp-item-data" instead of "user_data" as data key when attaching 2001-11-22 Michael Natterer <mitch@gimp.org> * libgimpwidgets/gimpwidgets.[ch]: use "gimp-item-data" instead of "user_data" as data key when attaching values to radio buttons or menu items. (For backward compat, attach "user_data" additionally, but don't use it to _get_data()). Added gimp_radio_group_set_active() which works like gimp_options_menu_set_history() and sets the active item by attached "gimp-item-data" value. * app/gui/brush-select.c * app/gui/file-new-dialog.c * app/gui/info-window.c * app/gui/preferences-dialog.c * app/gui/resolution-calibrate-dialog.c * app/tools/gimpbucketfilltool.c * app/tools/gimpselectiontool.c * app/tools/paint_options.c * app/tools/selection_options.c * app/widgets/gimplayerlistview.c: removed all kinds of "user_data" stuff and evil hacks to find a radio button by the value it represents (simply call gimp_radio_group_set_active()). * app/tools/gimpdrawtool.c: added a g_return_if_fail(). * app/tools/gimpfliptool.c: don't set draw_tool_class->draw to NULL, * app/tools/gimptransformtool.[ch]: fixed some stuff i broke when removing the old "interactive" boolean (there is no non-interactive transform tool any more). Put the info_dialog pointer and the old_trans_info array into the GimpTransformTool instance. Added gimp_transform_tool_info_dialog_connect(). Don't include any subclasses any more. * app/tools/gimpperspectivetool.c * app/tools/gimprotatetool.c * app/tools/gimpscaletool.c * app/tools/gimpsheartool.c: use gimp_transform_tool_info_dialog_connect() to create and connect the info dialogs' action_area.
2001-11-22 21:01:26 +08:00
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
gimp_draw_tool_undraw (draw_tool);
draw_tool->paused_count++;
}
void
gimp_draw_tool_resume (GimpDrawTool *draw_tool)
{
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
g_return_if_fail (draw_tool->paused_count > 0);
draw_tool->paused_count--;
gimp_draw_tool_draw (draw_tool);
}
gboolean
gimp_draw_tool_is_drawn (GimpDrawTool *draw_tool)
{
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), FALSE);
return draw_tool->is_drawn;
}
void
gimp_draw_tool_draw_items (GimpDrawTool *draw_tool,
cairo_t *cr)
{
GimpDisplayShell *shell;
GdkWindow *window;
GList *list;
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
g_return_if_fail (cr != NULL);
if (! gimp_draw_tool_is_active (draw_tool) ||
! gimp_draw_tool_is_drawn (draw_tool))
return;
shell = gimp_display_get_shell (draw_tool->display);
window = gtk_widget_get_window (shell->canvas);
for (list = draw_tool->items; list; list = g_list_next (list))
{
GimpCanvasItem *item = list->data;
gimp_canvas_item_draw (item, shell, cr);
}
}
/**
* gimp_draw_tool_calc_distance:
* @draw_tool: a #GimpDrawTool
* @display: a #GimpDisplay
* @x1: start point X in image coordinates
* @y1: start point Y in image coordinates
* @x2: end point X in image coordinates
* @y2: end point Y in image coordinates
*
* If you just need to compare distances, consider to use
* gimp_draw_tool_calc_distance_square() instead.
*
* Returns: the distance between the given points in display coordinates
**/
gdouble
gimp_draw_tool_calc_distance (GimpDrawTool *draw_tool,
GimpDisplay *display,
gdouble x1,
gdouble y1,
gdouble x2,
gdouble y2)
{
return sqrt (gimp_draw_tool_calc_distance_square (draw_tool, display,
x1, y1, x2, y2));
}
/**
* gimp_draw_tool_calc_distance_square:
* @draw_tool: a #GimpDrawTool
* @display: a #GimpDisplay
* @x1: start point X in image coordinates
* @y1: start point Y in image coordinates
* @x2: end point X in image coordinates
* @y2: end point Y in image coordinates
*
* This function is more effective than gimp_draw_tool_calc_distance()
* as it doesn't perform a sqrt(). Use this if you just need to compare
* distances.
*
* Returns: the square of the distance between the given points in
2010-03-21 05:25:16 +08:00
* display coordinates
**/
gdouble
gimp_draw_tool_calc_distance_square (GimpDrawTool *draw_tool,
GimpDisplay *display,
gdouble x1,
gdouble y1,
gdouble x2,
gdouble y2)
{
removed gdisp->scale, gdisp->dot_for_dot, the scaling marcos and the 2002-06-27 Michael Natterer <mitch@gimp.org> * app/display/gimpdisplay.[ch]: removed gdisp->scale, gdisp->dot_for_dot, the scaling marcos and the gdisplay_[un]transform[_f]() functions. * app/display/gimpdisplayshell.[ch]: added them here. Named the transform functions gimp_display_shell_[un]transform_xy[_f](). Made the gimp_display_shell_[un]transform_coords() functions copy all values of the GimpCoords struct, not just x and y. * app/display/gimpstatusbar.[ch]: keep a pointer to GimpDisplayShell, not GimpDisplay. * app/display/gimpdisplayshell-callbacks.c * app/display/gimpdisplayshell-render.c * app/display/gimpdisplayshell-scale.c * app/display/gimpdisplayshell-scroll.c * app/display/gimpdisplayshell-selection.c * app/display/gimpnavigationview.c * app/gui/image-commands.c * app/gui/info-window.c * app/gui/select-commands.c * app/gui/view-commands.c * app/tools/gimpbezierselecttool.c * app/tools/gimpcroptool.c * app/tools/gimpdrawtool.c * app/tools/gimpeditselectiontool.c * app/tools/gimpmagnifytool.c * app/tools/gimpmeasuretool.c * app/tools/gimpmovetool.c * app/tools/gimppainttool.c * app/tools/gimppathtool.c * app/tools/gimprotatetool.c * app/tools/gimpscaletool.c * app/tools/gimpvectortool.c: changed accordingly. * app/gui/layers-commands.c: if(gimage->selection_mask) is always TRUE, use if(!gimp_image_mask_is_empty(gimage)) instead. * app/tools/gimpfuzzyselecttool.[ch]: moved global variables to the object struct.
2002-06-27 06:16:59 +08:00
GimpDisplayShell *shell;
gdouble tx1, ty1;
gdouble tx2, ty2;
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), 0.0);
g_return_val_if_fail (GIMP_IS_DISPLAY (display), 0.0);
shell = gimp_display_get_shell (display);
removed gdisp->scale, gdisp->dot_for_dot, the scaling marcos and the 2002-06-27 Michael Natterer <mitch@gimp.org> * app/display/gimpdisplay.[ch]: removed gdisp->scale, gdisp->dot_for_dot, the scaling marcos and the gdisplay_[un]transform[_f]() functions. * app/display/gimpdisplayshell.[ch]: added them here. Named the transform functions gimp_display_shell_[un]transform_xy[_f](). Made the gimp_display_shell_[un]transform_coords() functions copy all values of the GimpCoords struct, not just x and y. * app/display/gimpstatusbar.[ch]: keep a pointer to GimpDisplayShell, not GimpDisplay. * app/display/gimpdisplayshell-callbacks.c * app/display/gimpdisplayshell-render.c * app/display/gimpdisplayshell-scale.c * app/display/gimpdisplayshell-scroll.c * app/display/gimpdisplayshell-selection.c * app/display/gimpnavigationview.c * app/gui/image-commands.c * app/gui/info-window.c * app/gui/select-commands.c * app/gui/view-commands.c * app/tools/gimpbezierselecttool.c * app/tools/gimpcroptool.c * app/tools/gimpdrawtool.c * app/tools/gimpeditselectiontool.c * app/tools/gimpmagnifytool.c * app/tools/gimpmeasuretool.c * app/tools/gimpmovetool.c * app/tools/gimppainttool.c * app/tools/gimppathtool.c * app/tools/gimprotatetool.c * app/tools/gimpscaletool.c * app/tools/gimpvectortool.c: changed accordingly. * app/gui/layers-commands.c: if(gimage->selection_mask) is always TRUE, use if(!gimp_image_mask_is_empty(gimage)) instead. * app/tools/gimpfuzzyselecttool.[ch]: moved global variables to the object struct.
2002-06-27 06:16:59 +08:00
gimp_display_shell_transform_xy_f (shell, x1, y1, &tx1, &ty1, FALSE);
gimp_display_shell_transform_xy_f (shell, x2, y2, &tx2, &ty2, FALSE);
return SQR (tx2 - tx1) + SQR (ty2 - ty1);
}
/**
* gimp_draw_tool_in_radius:
* @draw_tool: a #GimpDrawTool
* @display: a #GimpDisplay
* @x1: start point X in image coordinates
* @y1: start point Y in image coordinates
* @x2: end point X in image coordinates
* @y2: end point Y in image coordinates
* @radius: distance in screen coordinates, not image coordinates
*
* The points are in image space coordinates.
*
* Returns: %TRUE if the points are within radius of each other,
* %FALSE otherwise
**/
gboolean
gimp_draw_tool_in_radius (GimpDrawTool *draw_tool,
GimpDisplay *display,
gdouble x1,
gdouble y1,
gdouble x2,
gdouble y2,
gint radius)
{
return (gimp_draw_tool_calc_distance_square (draw_tool, display,
x1, y1, x2, y2) < SQR (radius));
}
/**
* gimp_draw_tool_draw_line:
* @draw_tool: the #GimpDrawTool
* @x1: start point X in image coordinates
* @y1: start point Y in image coordinates
* @x2: end point X in image coordinates
* @y2: end point Y in image coordinates
* @use_offsets: whether to use the image pixel offsets of the tool's display
*
* This function takes image space coordinates and transforms them to
* screen window coordinates, then draws a line between the resulting
* coordindates.
**/
void
gimp_draw_tool_draw_line (GimpDrawTool *draw_tool,
gdouble x1,
gdouble y1,
gdouble x2,
gdouble y2,
gboolean use_offsets)
{
GimpDisplayShell *shell;
gdouble tx1, ty1;
gdouble tx2, ty2;
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
if (draw_tool->use_cairo)
{
GimpCanvasItem *item;
item = gimp_canvas_line_new (x1, y1, x2, y2);
draw_tool->items = g_list_append (draw_tool->items, item);
return;
}
shell = gimp_display_get_shell (draw_tool->display);
gimp_display_shell_transform_xy_f (shell,
x1, y1,
&tx1, &ty1,
use_offsets);
gimp_display_shell_transform_xy_f (shell,
x2, y2,
&tx2, &ty2,
use_offsets);
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
PROJ_ROUND (tx1), PROJ_ROUND (ty1),
PROJ_ROUND (tx2), PROJ_ROUND (ty2));
}
/**
* gimp_draw_tool_draw_dashed_line:
* @draw_tool: the #GimpDrawTool
* @x1: start point X in image coordinates
* @y1: start point Y in image coordinates
* @x2: end point X in image coordinates
* @y2: end point Y in image coordinates
* @use_offsets: whether to use the image pixel offsets of the tool's display
*
* This function takes image space coordinates and transforms them to
* screen window coordinates, then draws a dashed line between the
* resulting coordindates.
**/
void
gimp_draw_tool_draw_dashed_line (GimpDrawTool *draw_tool,
gdouble x1,
gdouble y1,
gdouble x2,
gdouble y2,
gboolean use_offsets)
{
GimpDisplayShell *shell;
gdouble tx1, ty1;
gdouble tx2, ty2;
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
shell = gimp_display_get_shell (draw_tool->display);
gimp_display_shell_transform_xy_f (shell,
x1, y1,
&tx1, &ty1,
use_offsets);
gimp_display_shell_transform_xy_f (shell,
x2, y2,
&tx2, &ty2,
use_offsets);
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas),
GIMP_CANVAS_STYLE_XOR_DASHED,
PROJ_ROUND (tx1), PROJ_ROUND (ty1),
PROJ_ROUND (tx2), PROJ_ROUND (ty2));
}
/**
* gimp_draw_tool_draw_guide:
* @draw_tool: the #GimpDrawTool
* @orientation: the orientation of the guide line
* @position: the position of the guide line in image coordinates
*
* This function draws a guide line across the canvas.
**/
void
gimp_draw_tool_draw_guide_line (GimpDrawTool *draw_tool,
GimpOrientationType orientation,
gint position)
{
GimpDisplayShell *shell;
gint x1, y1, x2, y2;
gint x, y;
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
shell = gimp_display_get_shell (draw_tool->display);
x1 = 0;
y1 = 0;
gdk_drawable_get_size (gtk_widget_get_window (shell->canvas), &x2, &y2);
switch (orientation)
{
case GIMP_ORIENTATION_HORIZONTAL:
gimp_display_shell_transform_xy (shell, 0, position, &x, &y, FALSE);
y1 = y2 = y;
break;
case GIMP_ORIENTATION_VERTICAL:
gimp_display_shell_transform_xy (shell, position, 0, &x, &y, FALSE);
x1 = x2 = x;
break;
case GIMP_ORIENTATION_UNKNOWN:
return;
}
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
x1, y1, x2, y2);
}
/**
* gimp_draw_tool_draw_rectangle:
* @draw_tool: the #GimpDrawTool
* @filled: whether to fill the rectangle
* @x: horizontal image coordinate
* @y: vertical image coordinate
* @width: width in image coordinates
* @height: height in image coordinates
* @use_offsets: whether to use the image pixel offsets of the tool's display
*
* This function takes image space coordinates and transforms them to
* screen window coordinates, then draws the resulting rectangle.
**/
void
gimp_draw_tool_draw_rectangle (GimpDrawTool *draw_tool,
gboolean filled,
gdouble x,
gdouble y,
gdouble width,
gdouble height,
gboolean use_offsets)
{
GimpDisplayShell *shell;
gdouble tx1, ty1;
gdouble tx2, ty2;
guint w, h;
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
if (draw_tool->use_cairo)
{
GimpCanvasItem *item;
item = gimp_canvas_rectangle_new (x, y, width, height, filled);
draw_tool->items = g_list_append (draw_tool->items, item);
return;
}
shell = gimp_display_get_shell (draw_tool->display);
gimp_display_shell_transform_xy_f (shell,
MIN (x, x + width), MIN (y, y + height),
&tx1, &ty1,
use_offsets);
gimp_display_shell_transform_xy_f (shell,
MAX (x, x + width), MAX (y, y + height),
&tx2, &ty2,
use_offsets);
tx1 = CLAMP (tx1, -1, shell->disp_width + 1);
ty1 = CLAMP (ty1, -1, shell->disp_height + 1);
tx2 = CLAMP (tx2, -1, shell->disp_width + 1);
ty2 = CLAMP (ty2, -1, shell->disp_height + 1);
tx2 -= tx1;
ty2 -= ty1;
w = PROJ_ROUND (MAX (0.0, tx2));
h = PROJ_ROUND (MAX (0.0, ty2));
2010-02-22 06:36:25 +08:00
if (w > 0 && h > 0)
{
2010-02-22 06:36:25 +08:00
if (! filled)
{
w--;
h--;
}
2010-02-22 06:36:25 +08:00
gimp_canvas_draw_rectangle (GIMP_CANVAS (shell->canvas),
GIMP_CANVAS_STYLE_XOR,
filled,
PROJ_ROUND (tx1), PROJ_ROUND (ty1),
w, h);
}
}
void
gimp_draw_tool_draw_arc (GimpDrawTool *draw_tool,
gboolean filled,
gdouble x,
gdouble y,
gdouble width,
gdouble height,
gint angle1,
gint angle2,
gboolean use_offsets)
{
GimpDisplayShell *shell;
gdouble tx1, ty1;
gdouble tx2, ty2;
guint w, h;
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
shell = gimp_display_get_shell (draw_tool->display);
gimp_display_shell_transform_xy_f (shell,
MIN (x, x + width), MIN (y, y + height),
&tx1, &ty1,
use_offsets);
gimp_display_shell_transform_xy_f (shell,
MAX (x, x + width), MAX (y, y + height),
&tx2, &ty2,
use_offsets);
tx2 -= tx1;
ty2 -= ty1;
w = PROJ_ROUND (MAX (0.0, tx2));
h = PROJ_ROUND (MAX (0.0, ty2));
if (w > 0 && h > 0)
{
2010-02-22 06:36:25 +08:00
if (! filled)
{
w--;
h--;
}
if (w != 1 && h != 1)
{
gimp_canvas_draw_arc (GIMP_CANVAS (shell->canvas),
GIMP_CANVAS_STYLE_XOR,
filled,
PROJ_ROUND (tx1), PROJ_ROUND (ty1),
w, h,
angle1, angle2);
}
else
{
/* work around the problem of an 1xN or Nx1 arc not being shown
* properly
*/
gimp_canvas_draw_rectangle (GIMP_CANVAS (shell->canvas),
GIMP_CANVAS_STYLE_XOR,
filled,
PROJ_ROUND (tx1), PROJ_ROUND (ty1),
w, h);
}
}
}
static void
gimp_draw_tool_draw_rectangle_by_anchor (GimpDrawTool *draw_tool,
gboolean filled,
gdouble x,
gdouble y,
gint width,
gint height,
GtkAnchorType anchor,
gboolean use_offsets)
{
GimpDisplayShell *shell = gimp_display_get_shell (draw_tool->display);
gdouble tx, ty;
removed gdisp->scale, gdisp->dot_for_dot, the scaling marcos and the 2002-06-27 Michael Natterer <mitch@gimp.org> * app/display/gimpdisplay.[ch]: removed gdisp->scale, gdisp->dot_for_dot, the scaling marcos and the gdisplay_[un]transform[_f]() functions. * app/display/gimpdisplayshell.[ch]: added them here. Named the transform functions gimp_display_shell_[un]transform_xy[_f](). Made the gimp_display_shell_[un]transform_coords() functions copy all values of the GimpCoords struct, not just x and y. * app/display/gimpstatusbar.[ch]: keep a pointer to GimpDisplayShell, not GimpDisplay. * app/display/gimpdisplayshell-callbacks.c * app/display/gimpdisplayshell-render.c * app/display/gimpdisplayshell-scale.c * app/display/gimpdisplayshell-scroll.c * app/display/gimpdisplayshell-selection.c * app/display/gimpnavigationview.c * app/gui/image-commands.c * app/gui/info-window.c * app/gui/select-commands.c * app/gui/view-commands.c * app/tools/gimpbezierselecttool.c * app/tools/gimpcroptool.c * app/tools/gimpdrawtool.c * app/tools/gimpeditselectiontool.c * app/tools/gimpmagnifytool.c * app/tools/gimpmeasuretool.c * app/tools/gimpmovetool.c * app/tools/gimppainttool.c * app/tools/gimppathtool.c * app/tools/gimprotatetool.c * app/tools/gimpscaletool.c * app/tools/gimpvectortool.c: changed accordingly. * app/gui/layers-commands.c: if(gimage->selection_mask) is always TRUE, use if(!gimp_image_mask_is_empty(gimage)) instead. * app/tools/gimpfuzzyselecttool.[ch]: moved global variables to the object struct.
2002-06-27 06:16:59 +08:00
gimp_display_shell_transform_xy_f (shell,
x, y,
&tx, &ty,
use_offsets);
gimp_draw_tool_shift_to_north_west (tx, ty,
width, height,
anchor,
&tx, &ty);
if (! filled)
{
width -= 1;
height -= 1;
}
gimp_canvas_draw_rectangle (GIMP_CANVAS (shell->canvas),
GIMP_CANVAS_STYLE_XOR,
filled,
PROJ_ROUND (tx), PROJ_ROUND (ty),
width, height);
}
void
gimp_draw_tool_draw_arc_by_anchor (GimpDrawTool *draw_tool,
gboolean filled,
gdouble x,
gdouble y,
gint width,
gint height,
gint angle1,
gint angle2,
GtkAnchorType anchor,
gboolean use_offsets)
{
GimpDisplayShell *shell;
gdouble tx, ty;
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
shell = gimp_display_get_shell (draw_tool->display);
removed gdisp->scale, gdisp->dot_for_dot, the scaling marcos and the 2002-06-27 Michael Natterer <mitch@gimp.org> * app/display/gimpdisplay.[ch]: removed gdisp->scale, gdisp->dot_for_dot, the scaling marcos and the gdisplay_[un]transform[_f]() functions. * app/display/gimpdisplayshell.[ch]: added them here. Named the transform functions gimp_display_shell_[un]transform_xy[_f](). Made the gimp_display_shell_[un]transform_coords() functions copy all values of the GimpCoords struct, not just x and y. * app/display/gimpstatusbar.[ch]: keep a pointer to GimpDisplayShell, not GimpDisplay. * app/display/gimpdisplayshell-callbacks.c * app/display/gimpdisplayshell-render.c * app/display/gimpdisplayshell-scale.c * app/display/gimpdisplayshell-scroll.c * app/display/gimpdisplayshell-selection.c * app/display/gimpnavigationview.c * app/gui/image-commands.c * app/gui/info-window.c * app/gui/select-commands.c * app/gui/view-commands.c * app/tools/gimpbezierselecttool.c * app/tools/gimpcroptool.c * app/tools/gimpdrawtool.c * app/tools/gimpeditselectiontool.c * app/tools/gimpmagnifytool.c * app/tools/gimpmeasuretool.c * app/tools/gimpmovetool.c * app/tools/gimppainttool.c * app/tools/gimppathtool.c * app/tools/gimprotatetool.c * app/tools/gimpscaletool.c * app/tools/gimpvectortool.c: changed accordingly. * app/gui/layers-commands.c: if(gimage->selection_mask) is always TRUE, use if(!gimp_image_mask_is_empty(gimage)) instead. * app/tools/gimpfuzzyselecttool.[ch]: moved global variables to the object struct.
2002-06-27 06:16:59 +08:00
gimp_display_shell_transform_xy_f (shell,
x, y,
&tx, &ty,
use_offsets);
gimp_draw_tool_shift_to_north_west (tx, ty,
width, height,
anchor,
&tx, &ty);
if (! filled)
{
width -= 1;
height -= 1;
}
gimp_canvas_draw_arc (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
filled,
PROJ_ROUND (tx), PROJ_ROUND (ty),
width, height,
angle1, angle2);
}
static void
gimp_draw_tool_draw_cross_by_anchor (GimpDrawTool *draw_tool,
gdouble x,
gdouble y,
gint width,
gint height,
GtkAnchorType anchor,
gboolean use_offsets)
{
GimpDisplayShell *shell = gimp_display_get_shell (draw_tool->display);
gdouble tx, ty;
removed gdisp->scale, gdisp->dot_for_dot, the scaling marcos and the 2002-06-27 Michael Natterer <mitch@gimp.org> * app/display/gimpdisplay.[ch]: removed gdisp->scale, gdisp->dot_for_dot, the scaling marcos and the gdisplay_[un]transform[_f]() functions. * app/display/gimpdisplayshell.[ch]: added them here. Named the transform functions gimp_display_shell_[un]transform_xy[_f](). Made the gimp_display_shell_[un]transform_coords() functions copy all values of the GimpCoords struct, not just x and y. * app/display/gimpstatusbar.[ch]: keep a pointer to GimpDisplayShell, not GimpDisplay. * app/display/gimpdisplayshell-callbacks.c * app/display/gimpdisplayshell-render.c * app/display/gimpdisplayshell-scale.c * app/display/gimpdisplayshell-scroll.c * app/display/gimpdisplayshell-selection.c * app/display/gimpnavigationview.c * app/gui/image-commands.c * app/gui/info-window.c * app/gui/select-commands.c * app/gui/view-commands.c * app/tools/gimpbezierselecttool.c * app/tools/gimpcroptool.c * app/tools/gimpdrawtool.c * app/tools/gimpeditselectiontool.c * app/tools/gimpmagnifytool.c * app/tools/gimpmeasuretool.c * app/tools/gimpmovetool.c * app/tools/gimppainttool.c * app/tools/gimppathtool.c * app/tools/gimprotatetool.c * app/tools/gimpscaletool.c * app/tools/gimpvectortool.c: changed accordingly. * app/gui/layers-commands.c: if(gimage->selection_mask) is always TRUE, use if(!gimp_image_mask_is_empty(gimage)) instead. * app/tools/gimpfuzzyselecttool.[ch]: moved global variables to the object struct.
2002-06-27 06:16:59 +08:00
gimp_display_shell_transform_xy_f (shell,
x, y,
&tx, &ty,
use_offsets);
gimp_draw_tool_shift_to_center (tx, ty,
width, height,
anchor,
&tx, &ty);
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
PROJ_ROUND (tx),
PROJ_ROUND (ty) - (height >> 1),
PROJ_ROUND (tx),
PROJ_ROUND (ty) + ((height + 1) >> 1));
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
PROJ_ROUND (tx) - (width >> 1),
PROJ_ROUND (ty),
PROJ_ROUND (tx) + ((width + 1) >> 1),
PROJ_ROUND (ty));
}
void
gimp_draw_tool_draw_handle (GimpDrawTool *draw_tool,
GimpHandleType type,
gdouble x,
gdouble y,
gint width,
gint height,
GtkAnchorType anchor,
gboolean use_offsets)
{
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
if (draw_tool->use_cairo)
{
GimpCanvasItem *item;
item = gimp_canvas_handle_new (type, anchor, x, y, width, height);
draw_tool->items = g_list_append (draw_tool->items, item);
return;
}
switch (type)
2001-11-01 05:20:09 +08:00
{
case GIMP_HANDLE_SQUARE:
gimp_draw_tool_draw_rectangle_by_anchor (draw_tool,
FALSE,
x, y,
width,
height,
anchor,
use_offsets);
break;
case GIMP_HANDLE_FILLED_SQUARE:
gimp_draw_tool_draw_rectangle_by_anchor (draw_tool,
TRUE,
x, y,
width,
height,
anchor,
use_offsets);
break;
case GIMP_HANDLE_CIRCLE:
gimp_draw_tool_draw_arc_by_anchor (draw_tool,
FALSE,
x, y,
width,
height,
0, 360 * 64,
anchor,
use_offsets);
break;
case GIMP_HANDLE_FILLED_CIRCLE:
gimp_draw_tool_draw_arc_by_anchor (draw_tool,
TRUE,
x, y,
width,
height,
0, 360 * 64,
anchor,
use_offsets);
break;
case GIMP_HANDLE_CROSS:
gimp_draw_tool_draw_cross_by_anchor (draw_tool,
x, y,
width,
height,
anchor,
use_offsets);
break;
default:
g_warning ("%s: invalid handle type %d", G_STRFUNC, type);
break;
2001-11-01 05:20:09 +08:00
}
}
/**
* gimp_draw_tool_draw_corner:
* @draw_tool: the #GimpDrawTool
* @highlight:
* @put_outside: whether to put the handles on the outside of the rectangle
* @x1:
* @y1:
* @x2:
* @y2:
* @width: corner width
* @height: corner height
* @anchor: which corner to draw
* @use_offsets: whether to use the image pixel offsets of the tool's display
*
* This function takes image space coordinates and transforms them to
* screen window coordinates. It draws a corner into an already drawn
* rectangle outline, taking care of not drawing over an already drawn line.
**/
void
gimp_draw_tool_draw_corner (GimpDrawTool *draw_tool,
gboolean highlight,
gboolean put_outside,
gdouble x1,
gdouble y1,
gdouble x2,
gdouble y2,
gint width,
gint height,
GtkAnchorType anchor,
gboolean use_offsets)
{
GimpDisplayShell *shell;
GimpCanvas *canvas;
gint tx1, ty1;
gint tx2, ty2;
gint tw, th;
gint top_and_bottom_handle_x_offset;
gint left_and_right_handle_y_offset;
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
shell = gimp_display_get_shell (draw_tool->display);
canvas = GIMP_CANVAS (shell->canvas);
gimp_display_shell_transform_xy (shell, x1, y1, &tx1, &ty1, use_offsets);
gimp_display_shell_transform_xy (shell, x2, y2, &tx2, &ty2, use_offsets);
tw = tx2 - tx1;
th = ty2 - ty1;
if ((! put_outside && (tw <= width || th <= height)) ||
width <= 2 || height <= 2)
return;
top_and_bottom_handle_x_offset = (tw - width) / 2;
left_and_right_handle_y_offset = (th - height) / 2;
switch (anchor)
{
case GTK_ANCHOR_CENTER:
break;
case GTK_ANCHOR_NORTH_WEST:
if (put_outside)
{
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1 - 1, ty1,
tx1 - width + 1, ty1);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1 - width + 1, ty1,
tx1 - width + 1, ty1 - height + 1);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1 - width + 1, ty1 - height + 1,
tx1, ty1 - height + 1);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1, ty1 - height + 1,
tx1, ty1);
}
else
{
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1 + 1, ty1 + height - 1,
tx1 + width - 1, ty1 + height - 1);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1 + width - 1, ty1 + 1,
tx1 + width - 1, ty1 + height);
}
break;
case GTK_ANCHOR_NORTH_EAST:
if (put_outside)
{
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx2, ty1,
tx2 + width - 2, ty1);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx2 + width - 2, ty1,
tx2 + width - 2, ty1 - height + 1);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx2 + width - 2, ty1 - height + 1,
tx2 - 1, ty1 - height + 1);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx2 - 1, ty1 - height + 1,
tx2 - 1, ty1);
}
else
{
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx2 - 2, ty1 + height - 1,
tx2 - width, ty1 + height - 1);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx2 - width, ty1 + 1,
tx2 - width, ty1 + height);
}
break;
case GTK_ANCHOR_SOUTH_WEST:
if (put_outside)
{
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1 - 1, ty2 - 1,
tx1 - width + 1, ty2 - 1);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1 - width + 1, ty2 - 1,
tx1 - width + 1, ty2 + height - 2);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1 - width + 1, ty2 + height - 2,
tx1, ty2 + height - 2);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1, ty2 + height - 2,
tx1, ty2 - 1);
}
else
{
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1 + 1, ty2 - height,
tx1 + width - 1, ty2 - height);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1 + width - 1, ty2 - height,
tx1 + width - 1, ty2 - 1);
}
break;
case GTK_ANCHOR_SOUTH_EAST:
if (put_outside)
{
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx2, ty2 - 1,
tx2 + width - 2, ty2 - 1);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx2 + width - 2, ty2 - 1,
tx2 + width - 2, ty2 + height - 2);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx2 + width - 2, ty2 + height - 2,
tx2 - 1, ty2 + height - 2);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx2 - 1, ty2 + height - 2,
tx2 - 1, ty2 - 1);
}
else
{
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx2 - 2, ty2 - height,
tx2 - width, ty2 - height);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx2 - width, ty2 - height,
tx2 - width, ty2 - 1);
}
break;
case GTK_ANCHOR_NORTH:
if (put_outside)
{
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1, ty1 - 1,
tx1, ty1 - height + 1);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1, ty1 - height + 1,
tx2 - 1, ty1 - height + 1);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx2 - 1, ty1 - height + 1,
tx2 - 1, ty1);
}
else
{
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1 + 1, ty1 + height - 1,
tx2 - 1, ty1 + height - 1);
}
break;
case GTK_ANCHOR_SOUTH:
if (put_outside)
{
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1, ty2,
tx1, ty2 + height - 2);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1, ty2 + height - 2,
tx2 - 1, ty2 + height - 2);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx2 - 1, ty2 + height - 2,
tx2 - 1, ty2 - 1);
}
else
{
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1 + 1, ty2 - height,
tx2 - 1, ty2 - height);
}
break;
case GTK_ANCHOR_WEST:
if (put_outside)
{
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1 - 1, ty1,
tx1 - width + 1, ty1);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1 - width + 1, ty1,
tx1 - width + 1, ty2 - 1);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1 - width + 1, ty2 - 1,
tx1, ty2 - 1);
}
else
{
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1 + width - 1, ty1 + 1,
tx1 + width - 1, ty2 - 1);
}
break;
case GTK_ANCHOR_EAST:
if (put_outside)
{
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx2, ty1,
tx2 + width - 2, ty1);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx2 + width - 2, ty1,
tx2 + width - 2, ty2 - 1);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx2 + width - 2, ty2 - 1,
tx2 - 1, ty2 - 1);
}
else
{
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx2 - width, ty1 + 1,
tx2 - width, ty2 - 1);
}
break;
}
if (! highlight)
return;
switch (anchor)
{
case GTK_ANCHOR_NORTH_WEST:
if (put_outside)
{
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, FALSE,
tx1 - width + 2, ty1 - height + 2,
width - 3, height - 3);
}
else
{
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, FALSE,
tx1 + 1, ty1 + 1,
width - 3, height - 3);
}
break;
case GTK_ANCHOR_NORTH_EAST:
if (put_outside)
{
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, FALSE,
tx2, ty1 - height + 2,
width - 3, height - 3);
}
else
{
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, FALSE,
tx2 - width + 1, ty1 + 1,
width - 3, height - 3);
}
break;
case GTK_ANCHOR_SOUTH_WEST:
if (put_outside)
{
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, FALSE,
tx1 - width + 2, ty2,
width - 3, height - 3);
}
else
{
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, FALSE,
tx1 + 1, ty2 - height + 1,
width - 3, height - 3);
}
break;
case GTK_ANCHOR_SOUTH_EAST:
if (put_outside)
{
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, FALSE,
tx2, ty2,
width - 3, height - 3);
}
else
{
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, FALSE,
tx2 - width + 1, ty2 - height + 1,
width - 3, height - 3);
}
break;
case GTK_ANCHOR_NORTH:
if (put_outside)
{
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, FALSE,
tx1 + top_and_bottom_handle_x_offset + 1,
ty1 - height + 2,
width - 3, height - 3);
}
else
{
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, FALSE,
tx1 + top_and_bottom_handle_x_offset,
ty1 + 1,
width, height - 3);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1 + top_and_bottom_handle_x_offset + 1,
ty1 + 2,
tx1 + top_and_bottom_handle_x_offset + 1,
ty1 + height - 2);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1 + top_and_bottom_handle_x_offset + width - 1,
ty1 + 2,
tx1 + top_and_bottom_handle_x_offset + width - 1,
ty1 + height - 2);
}
break;
case GTK_ANCHOR_SOUTH:
if (put_outside)
{
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, FALSE,
tx1 + top_and_bottom_handle_x_offset + 1,
ty2,
width - 3, height - 3);
}
else
{
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, FALSE,
tx1 + top_and_bottom_handle_x_offset,
ty2 - height + 1,
width, height - 3);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1 + top_and_bottom_handle_x_offset + 1,
ty2 - 3,
tx1 + top_and_bottom_handle_x_offset + 1,
ty2 - height + 1);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1 + top_and_bottom_handle_x_offset + width - 1,
ty2 - 3,
tx1 + top_and_bottom_handle_x_offset + width - 1,
ty2 - height + 1);
}
break;
case GTK_ANCHOR_WEST:
if (put_outside)
{
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, FALSE,
tx1 - width + 2,
ty1 + left_and_right_handle_y_offset + 1,
width - 3, height - 3);
}
else
{
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, FALSE,
tx1 + 1,
ty1 + left_and_right_handle_y_offset,
width - 3, height);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1 + 2,
ty1 + left_and_right_handle_y_offset + 1,
tx1 + width - 2,
ty1 + left_and_right_handle_y_offset + 1);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx1 + 2,
ty1 + left_and_right_handle_y_offset + height - 1,
tx1 + width - 2,
ty1 + left_and_right_handle_y_offset + height - 1);
}
break;
case GTK_ANCHOR_EAST:
if (put_outside)
{
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, FALSE,
tx2,
ty1 + left_and_right_handle_y_offset + 1,
width - 3, height - 3);
}
else
{
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, FALSE,
tx2 - width + 1,
ty1 + left_and_right_handle_y_offset,
width - 3, height);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx2 - 3,
ty1 + left_and_right_handle_y_offset + 1,
tx2 - width + 1,
ty1 + left_and_right_handle_y_offset + 1);
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
tx2 - 3,
ty1 + left_and_right_handle_y_offset + height - 1,
tx2 - width + 1,
ty1 + left_and_right_handle_y_offset + height - 1);
}
break;
default:
break;
}
}
void
gimp_draw_tool_draw_lines (GimpDrawTool *draw_tool,
const GimpVector2 *points,
gint n_points,
gboolean filled,
gboolean use_offsets)
{
GimpDisplayShell *shell;
GdkPoint *coords;
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
2010-09-23 06:00:07 +08:00
if (points == NULL || n_points < 2)
return;
2010-09-23 06:00:07 +08:00
if (draw_tool->use_cairo)
{
GimpCanvasItem *item;
item = gimp_canvas_polygon_new (points, n_points, filled);
draw_tool->items = g_list_append (draw_tool->items, item);
return;
}
shell = gimp_display_get_shell (draw_tool->display);
coords = g_new (GdkPoint, n_points);
gimp_display_shell_transform_points (shell,
points, coords, n_points, use_offsets);
if (filled)
{
gimp_canvas_draw_polygon (GIMP_CANVAS (shell->canvas),
GIMP_CANVAS_STYLE_XOR,
TRUE, coords, n_points);
}
else
{
gimp_canvas_draw_lines (GIMP_CANVAS (shell->canvas),
GIMP_CANVAS_STYLE_XOR,
coords, n_points);
}
g_free (coords);
}
void
gimp_draw_tool_draw_strokes (GimpDrawTool *draw_tool,
const GimpCoords *points,
gint n_points,
gboolean filled,
gboolean use_offsets)
{
GimpDisplayShell *shell;
GdkPoint *coords;
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
if (points == NULL || n_points < 2)
return;
if (draw_tool->use_cairo)
{
GimpCanvasItem *item;
item = gimp_canvas_polygon_new_from_coords (points, n_points, filled);
draw_tool->items = g_list_append (draw_tool->items, item);
return;
}
shell = gimp_display_get_shell (draw_tool->display);
coords = g_new (GdkPoint, n_points);
gimp_display_shell_transform_coords (shell,
points, coords, n_points, use_offsets);
if (filled)
{
gimp_canvas_draw_polygon (GIMP_CANVAS (shell->canvas),
GIMP_CANVAS_STYLE_XOR,
TRUE, coords, n_points);
}
else
{
gimp_canvas_draw_lines (GIMP_CANVAS (shell->canvas),
GIMP_CANVAS_STYLE_XOR,
coords, n_points);
}
g_free (coords);
}
/**
* gimp_draw_tool_draw_boundary:
* @draw_tool: a #GimpDrawTool
* @bound_segs: the sorted brush outline
* @n_bound_segs: the number of segments in @bound_segs
* @offset_x: x offset
* @offset_y: y offset
* @use_offsets: whether to use offsets
*
* Draw the boundary of the brush that @draw_tool uses. The boundary
* should be sorted with sort_boundary(), and @n_bound_segs should
* include the sentinel segments inserted by sort_boundary() that
* indicate the end of connected segment sequences (groups) .
*/
void
gimp_draw_tool_draw_boundary (GimpDrawTool *draw_tool,
const BoundSeg *bound_segs,
gint n_bound_segs,
gdouble offset_x,
gdouble offset_y,
gboolean use_offsets)
{
GimpDisplayShell *shell;
GdkPoint *gdk_points;
gint n_gdk_points;
gint xmax, ymax;
gdouble x, y;
gint i;
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
g_return_if_fail (n_bound_segs > 0);
g_return_if_fail (bound_segs != NULL);
shell = gimp_display_get_shell (draw_tool->display);
gdk_points = g_new0 (GdkPoint, n_bound_segs + 1);
n_gdk_points = 0;
xmax = shell->disp_width + 1;
ymax = shell->disp_height + 1;
/* The sorted boundary has sentinel segments inserted at the end of
* each group.
*/
for (i = 0; i < n_bound_segs; i++)
{
if (bound_segs[i].x1 == -1 &&
bound_segs[i].y1 == -1 &&
bound_segs[i].x2 == -1 &&
bound_segs[i].y2 == -1)
{
/* Group ends */
gimp_canvas_draw_lines (GIMP_CANVAS (shell->canvas),
GIMP_CANVAS_STYLE_XOR_DOTTED,
gdk_points, n_gdk_points);
n_gdk_points = 0;
continue;
}
if (n_gdk_points == 0)
{
gimp_display_shell_transform_xy_f (shell,
bound_segs[i].x1 + offset_x,
bound_segs[i].y1 + offset_y,
&x, &y,
use_offsets);
gdk_points[0].x = PROJ_ROUND (CLAMP (x, -1, xmax));
gdk_points[0].y = PROJ_ROUND (CLAMP (y, -1, ymax));
/* If this segment is a closing segment && the segments lie inside
* the region, OR if this is an opening segment and the segments
* lie outside the region...
* we need to transform it by one display pixel
*/
if (! bound_segs[i].open)
{
/* If it is vertical */
if (bound_segs[i].x1 == bound_segs[i].x2)
{
gdk_points[0].x -= 1;
}
else
{
gdk_points[0].y -= 1;
}
}
n_gdk_points++;
}
g_assert (n_gdk_points < n_bound_segs + 1);
gimp_display_shell_transform_xy_f (shell,
bound_segs[i].x2 + offset_x,
bound_segs[i].y2 + offset_y,
&x, &y,
use_offsets);
gdk_points[n_gdk_points].x = PROJ_ROUND (CLAMP (x, -1, xmax));
gdk_points[n_gdk_points].y = PROJ_ROUND (CLAMP (y, -1, ymax));
/* If this segment is a closing segment && the segments lie inside
* the region, OR if this is an opening segment and the segments
* lie outside the region...
* we need to transform it by one display pixel
*/
if (! bound_segs[i].open)
{
/* If it is vertical */
if (bound_segs[i].x1 == bound_segs[i].x2)
{
gdk_points[n_gdk_points ].x -= 1;
gdk_points[n_gdk_points - 1].x -= 1;
}
else
{
gdk_points[n_gdk_points ].y -= 1;
gdk_points[n_gdk_points - 1].y -= 1;
}
}
n_gdk_points++;
}
g_free (gdk_points);
}
void
gimp_draw_tool_draw_text_cursor (GimpDrawTool *draw_tool,
PangoRectangle *cursor,
gboolean overwrite,
gboolean use_offsets)
{
GimpDisplayShell *shell;
gdouble tx1, ty1;
gdouble tx2, ty2;
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
shell = gimp_display_get_shell (draw_tool->display);
gimp_display_shell_transform_xy_f (shell,
cursor->x, cursor->y,
&tx1, &ty1,
use_offsets);
if (overwrite)
{
gint x, y;
gint width, height;
gimp_display_shell_transform_xy_f (shell,
cursor->x + cursor->width,
cursor->y + cursor->height,
&tx2, &ty2,
use_offsets);
x = PROJ_ROUND (tx1);
y = PROJ_ROUND (ty1);
width = PROJ_ROUND (tx2 - tx1);
height = PROJ_ROUND (ty2 - ty1);
gimp_canvas_draw_rectangle (GIMP_CANVAS (shell->canvas),
GIMP_CANVAS_STYLE_XOR, FALSE,
x, y,
width, height);
gimp_canvas_draw_rectangle (GIMP_CANVAS (shell->canvas),
GIMP_CANVAS_STYLE_XOR, FALSE,
x + 1, y + 1,
width - 2, height - 2);
}
else
{
gimp_display_shell_transform_xy_f (shell,
cursor->x,
cursor->y + cursor->height,
&tx2, &ty2,
use_offsets);
/* vertical line */
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas),
GIMP_CANVAS_STYLE_XOR,
PROJ_ROUND (tx1), PROJ_ROUND (ty1) + 2,
PROJ_ROUND (tx2), PROJ_ROUND (ty2) - 2);
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas),
GIMP_CANVAS_STYLE_XOR,
PROJ_ROUND (tx1) - 1, PROJ_ROUND (ty1) + 2,
PROJ_ROUND (tx2) - 1, PROJ_ROUND (ty2) - 2);
/* top serif */
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas),
GIMP_CANVAS_STYLE_XOR,
PROJ_ROUND (tx1) - 3, PROJ_ROUND (ty1),
PROJ_ROUND (tx1) + 3, PROJ_ROUND (ty1));
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas),
GIMP_CANVAS_STYLE_XOR,
PROJ_ROUND (tx1) - 3, PROJ_ROUND (ty1) + 1,
PROJ_ROUND (tx1) + 3, PROJ_ROUND (ty1) + 1);
/* bottom serif */
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas),
GIMP_CANVAS_STYLE_XOR,
PROJ_ROUND (tx2) - 3, PROJ_ROUND (ty2) - 1,
PROJ_ROUND (tx2) + 3, PROJ_ROUND (ty2) - 1);
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas),
GIMP_CANVAS_STYLE_XOR,
PROJ_ROUND (tx2) - 3, PROJ_ROUND (ty2) - 2,
PROJ_ROUND (tx2) + 3, PROJ_ROUND (ty2) - 2);
}
}
gboolean
gimp_draw_tool_on_handle (GimpDrawTool *draw_tool,
GimpDisplay *display,
gdouble x,
gdouble y,
GimpHandleType type,
gdouble handle_x,
gdouble handle_y,
gint width,
gint height,
GtkAnchorType anchor,
gboolean use_offsets)
{
removed gdisp->scale, gdisp->dot_for_dot, the scaling marcos and the 2002-06-27 Michael Natterer <mitch@gimp.org> * app/display/gimpdisplay.[ch]: removed gdisp->scale, gdisp->dot_for_dot, the scaling marcos and the gdisplay_[un]transform[_f]() functions. * app/display/gimpdisplayshell.[ch]: added them here. Named the transform functions gimp_display_shell_[un]transform_xy[_f](). Made the gimp_display_shell_[un]transform_coords() functions copy all values of the GimpCoords struct, not just x and y. * app/display/gimpstatusbar.[ch]: keep a pointer to GimpDisplayShell, not GimpDisplay. * app/display/gimpdisplayshell-callbacks.c * app/display/gimpdisplayshell-render.c * app/display/gimpdisplayshell-scale.c * app/display/gimpdisplayshell-scroll.c * app/display/gimpdisplayshell-selection.c * app/display/gimpnavigationview.c * app/gui/image-commands.c * app/gui/info-window.c * app/gui/select-commands.c * app/gui/view-commands.c * app/tools/gimpbezierselecttool.c * app/tools/gimpcroptool.c * app/tools/gimpdrawtool.c * app/tools/gimpeditselectiontool.c * app/tools/gimpmagnifytool.c * app/tools/gimpmeasuretool.c * app/tools/gimpmovetool.c * app/tools/gimppainttool.c * app/tools/gimppathtool.c * app/tools/gimprotatetool.c * app/tools/gimpscaletool.c * app/tools/gimpvectortool.c: changed accordingly. * app/gui/layers-commands.c: if(gimage->selection_mask) is always TRUE, use if(!gimp_image_mask_is_empty(gimage)) instead. * app/tools/gimpfuzzyselecttool.[ch]: moved global variables to the object struct.
2002-06-27 06:16:59 +08:00
GimpDisplayShell *shell;
gdouble tx, ty;
gdouble handle_tx, handle_ty;
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), FALSE);
g_return_val_if_fail (GIMP_IS_DISPLAY (display), FALSE);
shell = gimp_display_get_shell (display);
removed gdisp->scale, gdisp->dot_for_dot, the scaling marcos and the 2002-06-27 Michael Natterer <mitch@gimp.org> * app/display/gimpdisplay.[ch]: removed gdisp->scale, gdisp->dot_for_dot, the scaling marcos and the gdisplay_[un]transform[_f]() functions. * app/display/gimpdisplayshell.[ch]: added them here. Named the transform functions gimp_display_shell_[un]transform_xy[_f](). Made the gimp_display_shell_[un]transform_coords() functions copy all values of the GimpCoords struct, not just x and y. * app/display/gimpstatusbar.[ch]: keep a pointer to GimpDisplayShell, not GimpDisplay. * app/display/gimpdisplayshell-callbacks.c * app/display/gimpdisplayshell-render.c * app/display/gimpdisplayshell-scale.c * app/display/gimpdisplayshell-scroll.c * app/display/gimpdisplayshell-selection.c * app/display/gimpnavigationview.c * app/gui/image-commands.c * app/gui/info-window.c * app/gui/select-commands.c * app/gui/view-commands.c * app/tools/gimpbezierselecttool.c * app/tools/gimpcroptool.c * app/tools/gimpdrawtool.c * app/tools/gimpeditselectiontool.c * app/tools/gimpmagnifytool.c * app/tools/gimpmeasuretool.c * app/tools/gimpmovetool.c * app/tools/gimppainttool.c * app/tools/gimppathtool.c * app/tools/gimprotatetool.c * app/tools/gimpscaletool.c * app/tools/gimpvectortool.c: changed accordingly. * app/gui/layers-commands.c: if(gimage->selection_mask) is always TRUE, use if(!gimp_image_mask_is_empty(gimage)) instead. * app/tools/gimpfuzzyselecttool.[ch]: moved global variables to the object struct.
2002-06-27 06:16:59 +08:00
gimp_display_shell_transform_xy_f (shell,
x, y,
&tx, &ty,
use_offsets);
gimp_display_shell_transform_xy_f (shell,
handle_x, handle_y,
&handle_tx, &handle_ty,
use_offsets);
switch (type)
{
case GIMP_HANDLE_SQUARE:
case GIMP_HANDLE_FILLED_SQUARE:
case GIMP_HANDLE_CROSS:
gimp_draw_tool_shift_to_north_west (handle_tx, handle_ty,
width, height,
anchor,
&handle_tx, &handle_ty);
return (tx == CLAMP (tx, handle_tx, handle_tx + width) &&
ty == CLAMP (ty, handle_ty, handle_ty + height));
case GIMP_HANDLE_CIRCLE:
case GIMP_HANDLE_FILLED_CIRCLE:
gimp_draw_tool_shift_to_center (handle_tx, handle_ty,
width, height,
anchor,
&handle_tx, &handle_ty);
/* FIXME */
if (width != height)
width = (width + height) / 2;
width /= 2;
return ((SQR (handle_tx - tx) + SQR (handle_ty - ty)) < SQR (width));
default:
g_warning ("%s: invalid handle type %d", G_STRFUNC, type);
break;
}
return FALSE;
}
gboolean
gimp_draw_tool_on_vectors_handle (GimpDrawTool *draw_tool,
GimpDisplay *display,
GimpVectors *vectors,
const GimpCoords *coord,
gint width,
gint height,
GimpAnchorType preferred,
gboolean exclusive,
GimpAnchor **ret_anchor,
GimpStroke **ret_stroke)
{
GimpStroke *stroke = NULL;
GimpStroke *pref_stroke = NULL;
GimpAnchor *anchor = NULL;
GimpAnchor *pref_anchor = NULL;
gdouble dx, dy;
gdouble pref_mindist = -1;
gdouble mindist = -1;
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), FALSE);
g_return_val_if_fail (GIMP_IS_DISPLAY (display), FALSE);
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), FALSE);
g_return_val_if_fail (coord != NULL, FALSE);
if (ret_anchor) *ret_anchor = NULL;
if (ret_stroke) *ret_stroke = NULL;
while ((stroke = gimp_vectors_stroke_get_next (vectors, stroke)))
{
GList *anchor_list = gimp_stroke_get_draw_anchors (stroke);
GList *list;
anchor_list = g_list_concat (gimp_stroke_get_draw_anchors (stroke),
gimp_stroke_get_draw_controls (stroke));
for (list = anchor_list; list; list = g_list_next (list))
{
dx = coord->x - GIMP_ANCHOR (list->data)->position.x;
dy = coord->y - GIMP_ANCHOR (list->data)->position.y;
if (mindist < 0 || mindist > dx * dx + dy * dy)
{
mindist = dx * dx + dy * dy;
anchor = GIMP_ANCHOR (list->data);
if (ret_stroke)
*ret_stroke = stroke;
}
if ((pref_mindist < 0 || pref_mindist > dx * dx + dy * dy) &&
GIMP_ANCHOR (list->data)->type == preferred)
{
pref_mindist = dx * dx + dy * dy;
pref_anchor = GIMP_ANCHOR (list->data);
pref_stroke = stroke;
}
}
g_list_free (anchor_list);
}
/* If the data passed into ret_anchor is a preferred anchor, return it. */
if (ret_anchor && *ret_anchor &&
gimp_draw_tool_on_handle (draw_tool, display,
coord->x,
coord->y,
GIMP_HANDLE_CIRCLE,
(*ret_anchor)->position.x,
(*ret_anchor)->position.y,
width, height,
GTK_ANCHOR_CENTER,
FALSE) &&
(*ret_anchor)->type == preferred)
{
if (ret_stroke) *ret_stroke = pref_stroke;
return TRUE;
}
if (pref_anchor && gimp_draw_tool_on_handle (draw_tool, display,
coord->x,
coord->y,
GIMP_HANDLE_CIRCLE,
pref_anchor->position.x,
pref_anchor->position.y,
width, height,
GTK_ANCHOR_CENTER,
FALSE))
{
if (ret_anchor) *ret_anchor = pref_anchor;
if (ret_stroke) *ret_stroke = pref_stroke;
return TRUE;
}
else if (!exclusive && anchor &&
gimp_draw_tool_on_handle (draw_tool, display,
coord->x,
coord->y,
GIMP_HANDLE_CIRCLE,
anchor->position.x,
anchor->position.y,
width, height,
GTK_ANCHOR_CENTER,
FALSE))
{
if (ret_anchor)
*ret_anchor = anchor;
/* *ret_stroke already set correctly. */
return TRUE;
}
if (ret_anchor)
*ret_anchor = NULL;
if (ret_stroke)
*ret_stroke = NULL;
return FALSE;
}
gboolean
gimp_draw_tool_on_vectors_curve (GimpDrawTool *draw_tool,
GimpDisplay *display,
GimpVectors *vectors,
const GimpCoords *coord,
gint width,
gint height,
GimpCoords *ret_coords,
gdouble *ret_pos,
GimpAnchor **ret_segment_start,
GimpAnchor **ret_segment_end,
GimpStroke **ret_stroke)
{
GimpStroke *stroke = NULL;
GimpAnchor *segment_start;
GimpAnchor *segment_end;
GimpCoords min_coords = GIMP_COORDS_DEFAULT_VALUES;
GimpCoords cur_coords;
gdouble min_dist, cur_dist, cur_pos;
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), FALSE);
g_return_val_if_fail (GIMP_IS_DISPLAY (display), FALSE);
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), FALSE);
g_return_val_if_fail (coord != NULL, FALSE);
if (ret_coords) *ret_coords = *coord;
if (ret_pos) *ret_pos = -1.0;
if (ret_segment_start) *ret_segment_start = NULL;
if (ret_segment_start) *ret_segment_end = NULL;
if (ret_stroke) *ret_stroke = NULL;
min_dist = -1.0;
while ((stroke = gimp_vectors_stroke_get_next (vectors, stroke)))
{
cur_dist = gimp_stroke_nearest_point_get (stroke, coord, 1.0,
&cur_coords,
&segment_start,
&segment_end,
&cur_pos);
if (cur_dist >= 0 && (min_dist < 0 || cur_dist < min_dist))
{
min_dist = cur_dist;
min_coords = cur_coords;
if (ret_coords) *ret_coords = cur_coords;
if (ret_pos) *ret_pos = cur_pos;
if (ret_segment_start) *ret_segment_start = segment_start;
if (ret_segment_end) *ret_segment_end = segment_end;
if (ret_stroke) *ret_stroke = stroke;
}
}
if (min_dist >= 0 &&
gimp_draw_tool_on_handle (draw_tool, display,
coord->x,
coord->y,
GIMP_HANDLE_CIRCLE,
min_coords.x,
min_coords.y,
width, height,
GTK_ANCHOR_CENTER,
FALSE))
{
return TRUE;
}
return FALSE;
}
gboolean
gimp_draw_tool_on_vectors (GimpDrawTool *draw_tool,
GimpDisplay *display,
const GimpCoords *coords,
gint width,
gint height,
GimpCoords *ret_coords,
gdouble *ret_pos,
GimpAnchor **ret_segment_start,
GimpAnchor **ret_segment_end,
GimpStroke **ret_stroke,
GimpVectors **ret_vectors)
{
GList *all_vectors;
GList *list;
if (ret_coords) *ret_coords = *coords;
if (ret_pos) *ret_pos = -1.0;
if (ret_segment_start) *ret_segment_start = NULL;
if (ret_segment_end) *ret_segment_end = NULL;
if (ret_stroke) *ret_stroke = NULL;
if (ret_vectors) *ret_vectors = NULL;
all_vectors = gimp_image_get_vectors_list (gimp_display_get_image (display));
for (list = all_vectors; list; list = g_list_next (list))
{
GimpVectors *vectors = list->data;
if (! gimp_item_get_visible (GIMP_ITEM (vectors)))
continue;
if (gimp_draw_tool_on_vectors_curve (draw_tool,
display,
vectors, coords,
width, height,
ret_coords,
ret_pos,
ret_segment_start,
ret_segment_end,
ret_stroke))
{
if (ret_vectors)
*ret_vectors = vectors;
g_list_free (all_vectors);
return TRUE;
}
}
g_list_free (all_vectors);
return FALSE;
}
/* private functions */
static inline void
gimp_draw_tool_shift_to_north_west (gdouble x,
gdouble y,
gint handle_width,
gint handle_height,
GtkAnchorType anchor,
gdouble *shifted_x,
gdouble *shifted_y)
{
switch (anchor)
{
case GTK_ANCHOR_CENTER:
x -= (handle_width >> 1);
y -= (handle_height >> 1);
break;
case GTK_ANCHOR_NORTH:
x -= (handle_width >> 1);
break;
case GTK_ANCHOR_NORTH_WEST:
/* nothing, this is the default */
break;
case GTK_ANCHOR_NORTH_EAST:
x -= handle_width;
break;
case GTK_ANCHOR_SOUTH:
x -= (handle_width >> 1);
y -= handle_height;
break;
case GTK_ANCHOR_SOUTH_WEST:
y -= handle_height;
break;
case GTK_ANCHOR_SOUTH_EAST:
x -= handle_width;
y -= handle_height;
break;
case GTK_ANCHOR_WEST:
y -= (handle_height >> 1);
break;
case GTK_ANCHOR_EAST:
x -= handle_width;
y -= (handle_height >> 1);
break;
default:
break;
}
if (shifted_x)
*shifted_x = x;
if (shifted_y)
*shifted_y = y;
}
static inline void
gimp_draw_tool_shift_to_center (gdouble x,
gdouble y,
gint handle_width,
gint handle_height,
GtkAnchorType anchor,
gdouble *shifted_x,
gdouble *shifted_y)
{
switch (anchor)
{
case GTK_ANCHOR_CENTER:
/* nothing, this is the default */
break;
case GTK_ANCHOR_NORTH:
y += (handle_height >> 1);
break;
case GTK_ANCHOR_NORTH_WEST:
x += (handle_width >> 1);
y += (handle_height >> 1);
break;
case GTK_ANCHOR_NORTH_EAST:
x -= (handle_width >> 1);
y += (handle_height >> 1);
break;
case GTK_ANCHOR_SOUTH:
y -= (handle_height >> 1);
break;
case GTK_ANCHOR_SOUTH_WEST:
x += (handle_width >> 1);
y -= (handle_height >> 1);
break;
case GTK_ANCHOR_SOUTH_EAST:
x -= (handle_width >> 1);
y -= (handle_height >> 1);
break;
case GTK_ANCHOR_WEST:
x += (handle_width >> 1);
break;
case GTK_ANCHOR_EAST:
x -= (handle_width >> 1);
break;
default:
break;
}
if (shifted_x)
*shifted_x = x;
if (shifted_y)
*shifted_y = y;
}