2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-02-27 13:21:12 +08:00
|
|
|
* Copyright (C) 1995-2001 Spencer Kimball, Peter Mattis, and others
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-02-27 13:21:12 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-02-27 13:21:12 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2001-02-27 13:21:12 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2007-05-30 19:49:14 +08:00
|
|
|
#include <string.h>
|
2007-05-30 19:56:52 +08:00
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2001-02-27 13:21:12 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2007-03-09 21:00:01 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2002-05-03 20:45:22 +08:00
|
|
|
#include "tools-types.h"
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2011-03-28 08:18:00 +08:00
|
|
|
#include "core/gimpdrawable.h"
|
2003-09-16 05:12:10 +08:00
|
|
|
#include "core/gimpimage.h"
|
|
|
|
|
2003-11-11 03:35:56 +08:00
|
|
|
#include "display/gimpcanvas.h"
|
2010-09-25 00:42:36 +08:00
|
|
|
#include "display/gimpcanvasarc.h"
|
2010-09-24 05:39:16 +08:00
|
|
|
#include "display/gimpcanvasboundary.h"
|
2010-09-25 23:20:08 +08:00
|
|
|
#include "display/gimpcanvasgroup.h"
|
2010-09-23 20:52:07 +08:00
|
|
|
#include "display/gimpcanvasguide.h"
|
2010-09-23 04:19:28 +08:00
|
|
|
#include "display/gimpcanvashandle.h"
|
2010-11-09 18:32:40 +08:00
|
|
|
#include "display/gimpcanvasitem-utils.h"
|
2010-09-23 04:19:28 +08:00
|
|
|
#include "display/gimpcanvasline.h"
|
2010-10-03 08:26:40 +08:00
|
|
|
#include "display/gimpcanvaspen.h"
|
2010-09-23 06:00:07 +08:00
|
|
|
#include "display/gimpcanvaspolygon.h"
|
2010-09-23 04:19:28 +08:00
|
|
|
#include "display/gimpcanvasrectangle.h"
|
2010-09-30 08:03:16 +08:00
|
|
|
#include "display/gimpcanvassamplepoint.h"
|
2010-09-25 02:35:14 +08:00
|
|
|
#include "display/gimpcanvastextcursor.h"
|
2011-03-28 08:18:00 +08:00
|
|
|
#include "display/gimpcanvastransformpreview.h"
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
2001-11-01 05:20:09 +08:00
|
|
|
#include "display/gimpdisplayshell.h"
|
2010-09-30 04:12:01 +08:00
|
|
|
#include "display/gimpdisplayshell-items.h"
|
2003-01-04 02:01:30 +08:00
|
|
|
#include "display/gimpdisplayshell-transform.h"
|
2017-06-27 01:50:31 +08:00
|
|
|
#include "display/gimptoolwidget.h"
|
2001-05-10 06:34:59 +08:00
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "gimpdrawtool.h"
|
2017-06-27 02:37:51 +08:00
|
|
|
#include "gimptoolcontrol.h"
|
2001-02-27 13:21:12 +08:00
|
|
|
|
|
|
|
|
2012-10-06 06:03:47 +08:00
|
|
|
#define DRAW_TIMEOUT 4
|
|
|
|
#define USE_TIMEOUT 1
|
|
|
|
#define MINIMUM_DRAW_INTERVAL 50000 /* 50000 microseconds == 20 fps */
|
2010-10-12 04:27:32 +08:00
|
|
|
|
|
|
|
|
2017-06-27 02:49:14 +08:00
|
|
|
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 gboolean gimp_draw_tool_key_press (GimpTool *tool,
|
|
|
|
GdkEventKey *kevent,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static gboolean gimp_draw_tool_key_release (GimpTool *tool,
|
|
|
|
GdkEventKey *kevent,
|
|
|
|
GimpDisplay *display);
|
2017-06-27 03:03:09 +08:00
|
|
|
static void gimp_draw_tool_modifier_key (GimpTool *tool,
|
|
|
|
GdkModifierType key,
|
|
|
|
gboolean press,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_draw_tool_active_modifier_key
|
|
|
|
(GimpTool *tool,
|
|
|
|
GdkModifierType key,
|
|
|
|
gboolean press,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display);
|
2017-06-27 02:49:14 +08:00
|
|
|
static void gimp_draw_tool_oper_update (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
gboolean proximity,
|
|
|
|
GimpDisplay *display);
|
2017-06-28 04:41:25 +08:00
|
|
|
static void gimp_draw_tool_cursor_update (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display);
|
2017-06-27 02:49:14 +08:00
|
|
|
|
|
|
|
static void gimp_draw_tool_widget_status (GimpToolWidget *widget,
|
|
|
|
const gchar *status,
|
|
|
|
GimpTool *tool);
|
|
|
|
static void gimp_draw_tool_widget_status_coords
|
|
|
|
(GimpToolWidget *widget,
|
|
|
|
const gchar *title,
|
|
|
|
gdouble x,
|
|
|
|
const gchar *separator,
|
|
|
|
gdouble y,
|
|
|
|
const gchar *help,
|
|
|
|
GimpTool *tool);
|
2019-01-13 16:38:19 +08:00
|
|
|
static void gimp_draw_tool_widget_message
|
|
|
|
(GimpToolWidget *widget,
|
|
|
|
const gchar *message,
|
|
|
|
GimpTool *tool);
|
2017-06-27 02:37:51 +08:00
|
|
|
static void gimp_draw_tool_widget_snap_offsets
|
2017-06-27 02:49:14 +08:00
|
|
|
(GimpToolWidget *widget,
|
|
|
|
gint offset_x,
|
|
|
|
gint offset_y,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GimpTool *tool);
|
2017-06-27 02:37:51 +08:00
|
|
|
|
2017-06-27 02:49:14 +08:00
|
|
|
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);
|
2008-11-22 05:07:48 +08:00
|
|
|
|
2004-11-14 10:50:33 +08:00
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
G_DEFINE_TYPE (GimpDrawTool, gimp_draw_tool, GIMP_TYPE_TOOL)
|
2004-11-14 10:50:33 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
#define parent_class gimp_draw_tool_parent_class
|
2004-11-14 10:50:33 +08:00
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_draw_tool_class_init (GimpDrawToolClass *klass)
|
|
|
|
{
|
2010-04-22 22:45:44 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
|
|
|
|
|
2017-06-27 03:03:09 +08:00
|
|
|
object_class->dispose = gimp_draw_tool_dispose;
|
2001-02-28 03:18:01 +08:00
|
|
|
|
2017-06-27 03:03:09 +08:00
|
|
|
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;
|
|
|
|
tool_class->key_press = gimp_draw_tool_key_press;
|
|
|
|
tool_class->key_release = gimp_draw_tool_key_release;
|
|
|
|
tool_class->modifier_key = gimp_draw_tool_modifier_key;
|
|
|
|
tool_class->active_modifier_key = gimp_draw_tool_active_modifier_key;
|
|
|
|
tool_class->oper_update = gimp_draw_tool_oper_update;
|
2017-06-28 04:41:25 +08:00
|
|
|
tool_class->cursor_update = gimp_draw_tool_cursor_update;
|
2001-11-20 22:20:17 +08:00
|
|
|
|
2017-06-27 03:03:09 +08:00
|
|
|
klass->draw = gimp_draw_tool_real_draw;
|
2001-02-27 13:21:12 +08:00
|
|
|
}
|
|
|
|
|
2001-02-27 22:14:13 +08:00
|
|
|
static void
|
2001-11-12 22:45:58 +08:00
|
|
|
gimp_draw_tool_init (GimpDrawTool *draw_tool)
|
2001-02-27 22:14:13 +08:00
|
|
|
{
|
2006-03-29 01:55:52 +08:00
|
|
|
draw_tool->display = NULL;
|
2001-11-12 22:45:58 +08:00
|
|
|
draw_tool->paused_count = 0;
|
2011-11-17 04:32:29 +08:00
|
|
|
draw_tool->preview = NULL;
|
2010-09-25 23:20:08 +08:00
|
|
|
draw_tool->item = NULL;
|
2001-02-28 03:18:01 +08:00
|
|
|
}
|
|
|
|
|
2010-04-22 22:45:44 +08:00
|
|
|
static void
|
|
|
|
gimp_draw_tool_dispose (GObject *object)
|
|
|
|
{
|
2010-10-12 04:27:32 +08:00
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (object);
|
|
|
|
|
|
|
|
if (draw_tool->draw_timeout)
|
|
|
|
{
|
|
|
|
g_source_remove (draw_tool->draw_timeout);
|
|
|
|
draw_tool->draw_timeout = 0;
|
|
|
|
}
|
|
|
|
|
2017-06-27 03:47:54 +08:00
|
|
|
gimp_draw_tool_set_widget (draw_tool, NULL);
|
|
|
|
gimp_draw_tool_set_default_status (draw_tool, NULL);
|
|
|
|
|
2010-04-22 22:45:44 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2006-06-19 03:58:49 +08:00
|
|
|
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)
|
|
|
|
{
|
2009-10-07 01:20:44 +08:00
|
|
|
if (image && gimp_display_get_image (draw_tool->display) == image)
|
2006-06-19 03:58:49 +08:00
|
|
|
display = draw_tool->display;
|
|
|
|
|
|
|
|
/* NULL image means any display */
|
|
|
|
if (! image)
|
|
|
|
display = draw_tool->display;
|
|
|
|
}
|
|
|
|
|
|
|
|
return display;
|
|
|
|
}
|
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
static void
|
2002-02-19 01:00:09 +08:00
|
|
|
gimp_draw_tool_control (GimpTool *tool,
|
2006-04-12 20:49:29 +08:00
|
|
|
GimpToolAction action,
|
|
|
|
GimpDisplay *display)
|
2001-02-28 03:18:01 +08:00
|
|
|
{
|
2003-11-11 03:35:56 +08:00
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
2001-02-28 03:18:01 +08:00
|
|
|
|
|
|
|
switch (action)
|
|
|
|
{
|
2006-05-22 05:12:01 +08:00
|
|
|
case GIMP_TOOL_ACTION_PAUSE:
|
|
|
|
case GIMP_TOOL_ACTION_RESUME:
|
2001-02-28 03:18:01 +08:00
|
|
|
break;
|
|
|
|
|
2006-05-22 05:12:01 +08:00
|
|
|
case GIMP_TOOL_ACTION_HALT:
|
2011-04-01 17:01:36 +08:00
|
|
|
if (gimp_draw_tool_is_active (draw_tool))
|
|
|
|
gimp_draw_tool_stop (draw_tool);
|
2017-06-27 01:50:31 +08:00
|
|
|
gimp_draw_tool_set_widget (draw_tool, NULL);
|
2001-02-28 03:18:01 +08:00
|
|
|
break;
|
2014-04-05 04:34:26 +08:00
|
|
|
|
|
|
|
case GIMP_TOOL_ACTION_COMMIT:
|
|
|
|
break;
|
2001-02-28 03:18:01 +08:00
|
|
|
}
|
2001-08-14 22:53:55 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
|
2001-02-28 03:18:01 +08:00
|
|
|
}
|
|
|
|
|
2017-06-27 02:13:51 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_draw_tool_key_press (GimpTool *tool,
|
|
|
|
GdkEventKey *kevent,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
|
|
|
|
|
|
|
if (draw_tool->widget && display == draw_tool->display)
|
|
|
|
{
|
|
|
|
return gimp_tool_widget_key_press (draw_tool->widget, kevent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return GIMP_TOOL_CLASS (parent_class)->key_press (tool, kevent, display);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_draw_tool_key_release (GimpTool *tool,
|
|
|
|
GdkEventKey *kevent,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
|
|
|
|
|
|
|
if (draw_tool->widget && display == draw_tool->display)
|
|
|
|
{
|
|
|
|
return gimp_tool_widget_key_release (draw_tool->widget, kevent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return GIMP_TOOL_CLASS (parent_class)->key_release (tool, kevent, display);
|
|
|
|
}
|
|
|
|
|
2017-06-27 03:03:09 +08:00
|
|
|
static void
|
|
|
|
gimp_draw_tool_modifier_key (GimpTool *tool,
|
|
|
|
GdkModifierType key,
|
|
|
|
gboolean press,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
|
|
|
|
|
|
|
if (draw_tool->widget && display == draw_tool->display)
|
|
|
|
{
|
|
|
|
gimp_tool_widget_hover_modifier (draw_tool->widget, key, press, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->modifier_key (tool, key, press, state,
|
|
|
|
display);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_draw_tool_active_modifier_key (GimpTool *tool,
|
|
|
|
GdkModifierType key,
|
|
|
|
gboolean press,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
|
|
|
|
|
|
|
if (draw_tool->widget && display == draw_tool->display)
|
|
|
|
{
|
|
|
|
gimp_tool_widget_motion_modifier (draw_tool->widget, key, press, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->active_modifier_key (tool, key, press, state,
|
|
|
|
display);
|
|
|
|
}
|
|
|
|
|
2017-06-27 02:29:42 +08:00
|
|
|
static void
|
|
|
|
gimp_draw_tool_oper_update (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
gboolean proximity,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
|
|
|
|
|
|
|
if (draw_tool->widget && display == draw_tool->display)
|
|
|
|
{
|
|
|
|
gimp_tool_widget_hover (draw_tool->widget, coords, state, proximity);
|
|
|
|
}
|
2017-06-27 03:47:54 +08:00
|
|
|
else if (proximity && draw_tool->default_status)
|
|
|
|
{
|
|
|
|
gimp_tool_replace_status (tool, display, "%s", draw_tool->default_status);
|
|
|
|
}
|
|
|
|
else if (! proximity)
|
|
|
|
{
|
|
|
|
gimp_tool_pop_status (tool, display);
|
|
|
|
}
|
2017-06-27 02:29:42 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state,
|
|
|
|
proximity, display);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-28 04:41:25 +08:00
|
|
|
static void
|
|
|
|
gimp_draw_tool_cursor_update (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
|
|
|
|
|
|
|
if (draw_tool->widget && display == draw_tool->display)
|
|
|
|
{
|
|
|
|
GimpCursorType cursor;
|
|
|
|
GimpToolCursorType tool_cursor;
|
|
|
|
GimpCursorModifier modifier;
|
|
|
|
|
|
|
|
cursor = gimp_tool_control_get_cursor (tool->control);
|
|
|
|
tool_cursor = gimp_tool_control_get_tool_cursor (tool->control);
|
|
|
|
modifier = gimp_tool_control_get_cursor_modifier (tool->control);
|
|
|
|
|
|
|
|
if (gimp_tool_widget_get_cursor (draw_tool->widget, coords, state,
|
|
|
|
&cursor, &tool_cursor, &modifier))
|
|
|
|
{
|
|
|
|
gimp_tool_set_cursor (tool, display,
|
|
|
|
cursor, tool_cursor, modifier);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state,
|
|
|
|
display);
|
|
|
|
}
|
|
|
|
|
2017-06-27 02:49:14 +08:00
|
|
|
static void
|
2019-01-13 16:24:14 +08:00
|
|
|
gimp_draw_tool_widget_status (GimpToolWidget *widget,
|
2017-06-27 02:49:14 +08:00
|
|
|
const gchar *status,
|
|
|
|
GimpTool *tool)
|
|
|
|
{
|
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
|
|
|
|
2019-01-13 20:53:12 +08:00
|
|
|
if (gimp_draw_tool_is_active (draw_tool))
|
2017-06-27 02:49:14 +08:00
|
|
|
{
|
2019-01-13 20:53:12 +08:00
|
|
|
if (status)
|
|
|
|
gimp_tool_replace_status (tool, draw_tool->display, "%s", status);
|
|
|
|
else
|
|
|
|
gimp_tool_pop_status (tool, draw_tool->display);
|
2017-06-27 02:49:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-01-13 16:24:14 +08:00
|
|
|
gimp_draw_tool_widget_status_coords (GimpToolWidget *widget,
|
2017-06-27 02:49:14 +08:00
|
|
|
const gchar *title,
|
|
|
|
gdouble x,
|
|
|
|
const gchar *separator,
|
|
|
|
gdouble y,
|
|
|
|
const gchar *help,
|
|
|
|
GimpTool *tool)
|
|
|
|
{
|
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
|
|
|
|
2019-01-13 20:53:12 +08:00
|
|
|
if (gimp_draw_tool_is_active (draw_tool))
|
|
|
|
{
|
|
|
|
gimp_tool_pop_status (tool, draw_tool->display);
|
|
|
|
gimp_tool_push_status_coords (tool, draw_tool->display,
|
|
|
|
gimp_tool_control_get_precision (
|
|
|
|
tool->control),
|
|
|
|
title, x, separator, y, help);
|
|
|
|
}
|
2017-06-27 02:49:14 +08:00
|
|
|
}
|
|
|
|
|
2019-01-13 16:38:19 +08:00
|
|
|
static void
|
|
|
|
gimp_draw_tool_widget_message (GimpToolWidget *widget,
|
|
|
|
const gchar *message,
|
|
|
|
GimpTool *tool)
|
|
|
|
{
|
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
|
|
|
|
2019-01-13 20:53:12 +08:00
|
|
|
if (gimp_draw_tool_is_active (draw_tool))
|
|
|
|
gimp_tool_message_literal (tool, draw_tool->display, message);
|
2019-01-13 16:38:19 +08:00
|
|
|
}
|
|
|
|
|
2017-06-27 02:37:51 +08:00
|
|
|
static void
|
|
|
|
gimp_draw_tool_widget_snap_offsets (GimpToolWidget *widget,
|
|
|
|
gint offset_x,
|
|
|
|
gint offset_y,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GimpTool *tool)
|
|
|
|
{
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
|
|
|
offset_x, offset_y,
|
|
|
|
width, height);
|
|
|
|
}
|
|
|
|
|
2010-10-12 04:27:32 +08:00
|
|
|
#ifdef USE_TIMEOUT
|
|
|
|
static gboolean
|
|
|
|
gimp_draw_tool_draw_timeout (GimpDrawTool *draw_tool)
|
|
|
|
{
|
2012-10-06 22:39:14 +08:00
|
|
|
guint64 now = g_get_monotonic_time ();
|
|
|
|
|
|
|
|
/* keep the timeout running if the last drawing just happened */
|
|
|
|
if ((now - draw_tool->last_draw_time) <= MINIMUM_DRAW_INTERVAL)
|
2013-04-29 06:03:20 +08:00
|
|
|
return TRUE;
|
2012-10-06 22:39:14 +08:00
|
|
|
|
2010-10-12 04:27:32 +08:00
|
|
|
draw_tool->draw_timeout = 0;
|
|
|
|
|
|
|
|
gimp_draw_tool_draw (draw_tool);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-02-19 01:00:09 +08:00
|
|
|
static void
|
|
|
|
gimp_draw_tool_draw (GimpDrawTool *draw_tool)
|
|
|
|
{
|
2012-10-05 02:42:13 +08:00
|
|
|
guint64 now = g_get_monotonic_time ();
|
|
|
|
|
2010-10-12 04:27:32 +08:00
|
|
|
if (draw_tool->display &&
|
|
|
|
draw_tool->paused_count == 0 &&
|
2012-10-05 02:42:13 +08:00
|
|
|
(! draw_tool->draw_timeout ||
|
|
|
|
(now - draw_tool->last_draw_time) > MINIMUM_DRAW_INTERVAL))
|
2003-07-11 00:01:45 +08:00
|
|
|
{
|
2011-11-17 04:32:29 +08:00
|
|
|
GimpDisplayShell *shell = gimp_display_get_shell (draw_tool->display);
|
|
|
|
|
2012-10-05 02:42:13 +08:00
|
|
|
if (draw_tool->draw_timeout)
|
|
|
|
{
|
|
|
|
g_source_remove (draw_tool->draw_timeout);
|
|
|
|
draw_tool->draw_timeout = 0;
|
|
|
|
}
|
|
|
|
|
2010-10-05 05:31:25 +08:00
|
|
|
gimp_draw_tool_undraw (draw_tool);
|
2010-09-25 03:14:49 +08:00
|
|
|
|
|
|
|
GIMP_DRAW_TOOL_GET_CLASS (draw_tool)->draw (draw_tool);
|
|
|
|
|
2010-10-04 20:03:37 +08:00
|
|
|
if (draw_tool->group_stack)
|
|
|
|
{
|
|
|
|
g_warning ("%s: draw_tool->group_stack not empty after calling "
|
|
|
|
"GimpDrawTool::draw() of %s",
|
|
|
|
G_STRFUNC,
|
|
|
|
g_type_name (G_TYPE_FROM_INSTANCE (draw_tool)));
|
|
|
|
|
|
|
|
while (draw_tool->group_stack)
|
|
|
|
gimp_draw_tool_pop_group (draw_tool);
|
|
|
|
}
|
|
|
|
|
2011-11-17 04:32:29 +08:00
|
|
|
if (draw_tool->preview)
|
|
|
|
gimp_display_shell_add_preview_item (shell, draw_tool->preview);
|
2010-10-05 05:31:25 +08:00
|
|
|
|
2011-11-17 04:32:29 +08:00
|
|
|
if (draw_tool->item)
|
|
|
|
gimp_display_shell_add_tool_item (shell, draw_tool->item);
|
2012-10-05 02:42:13 +08:00
|
|
|
|
2014-06-03 02:45:31 +08:00
|
|
|
draw_tool->last_draw_time = g_get_monotonic_time ();
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
g_printerr ("drawing tool stuff took %f seconds\n",
|
|
|
|
(draw_tool->last_draw_time - now) / 1000000.0);
|
|
|
|
#endif
|
2010-09-23 04:19:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_draw_tool_undraw (GimpDrawTool *draw_tool)
|
|
|
|
{
|
2011-11-17 04:32:29 +08:00
|
|
|
if (draw_tool->display)
|
2010-09-23 04:19:28 +08:00
|
|
|
{
|
2010-09-30 04:12:01 +08:00
|
|
|
GimpDisplayShell *shell = gimp_display_get_shell (draw_tool->display);
|
|
|
|
|
2011-11-17 04:32:29 +08:00
|
|
|
if (draw_tool->preview)
|
|
|
|
{
|
|
|
|
gimp_display_shell_remove_preview_item (shell, draw_tool->preview);
|
2017-07-16 00:38:01 +08:00
|
|
|
g_clear_object (&draw_tool->preview);
|
2011-11-17 04:32:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (draw_tool->item)
|
|
|
|
{
|
|
|
|
gimp_display_shell_remove_tool_item (shell, draw_tool->item);
|
2017-07-16 00:38:01 +08:00
|
|
|
g_clear_object (&draw_tool->item);
|
2011-11-17 04:32:29 +08:00
|
|
|
}
|
2003-07-11 00:01:45 +08:00
|
|
|
}
|
2002-02-19 01:00:09 +08:00
|
|
|
}
|
|
|
|
|
2003-09-12 02:02:39 +08:00
|
|
|
static void
|
|
|
|
gimp_draw_tool_real_draw (GimpDrawTool *draw_tool)
|
|
|
|
{
|
2017-06-27 01:50:31 +08:00
|
|
|
if (draw_tool->widget)
|
|
|
|
{
|
|
|
|
GimpCanvasItem *item = gimp_tool_widget_get_item (draw_tool->widget);
|
|
|
|
|
|
|
|
gimp_draw_tool_add_item (draw_tool, item);
|
|
|
|
}
|
2003-09-12 02:02:39 +08:00
|
|
|
}
|
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
void
|
2001-11-12 22:45:58 +08:00
|
|
|
gimp_draw_tool_start (GimpDrawTool *draw_tool,
|
2006-04-12 20:49:29 +08:00
|
|
|
GimpDisplay *display)
|
2001-02-27 13:21:12 +08:00
|
|
|
{
|
2001-11-12 22:45:58 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
2006-03-29 01:55:52 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY (display));
|
2011-04-01 17:01:36 +08:00
|
|
|
g_return_if_fail (gimp_draw_tool_is_active (draw_tool) == FALSE);
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
draw_tool->display = display;
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2002-02-19 01:00:09 +08:00
|
|
|
gimp_draw_tool_draw (draw_tool);
|
2001-02-27 13:21:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-11-12 22:45:58 +08:00
|
|
|
gimp_draw_tool_stop (GimpDrawTool *draw_tool)
|
2001-02-27 13:21:12 +08:00
|
|
|
{
|
2001-11-12 22:45:58 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
2011-04-01 17:01:36 +08:00
|
|
|
g_return_if_fail (gimp_draw_tool_is_active (draw_tool) == TRUE);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2010-09-23 04:19:28 +08:00
|
|
|
gimp_draw_tool_undraw (draw_tool);
|
2002-02-07 19:33:01 +08:00
|
|
|
|
2010-10-12 04:27:32 +08:00
|
|
|
if (draw_tool->draw_timeout)
|
|
|
|
{
|
|
|
|
g_source_remove (draw_tool->draw_timeout);
|
|
|
|
draw_tool->draw_timeout = 0;
|
|
|
|
}
|
|
|
|
|
2012-10-05 02:42:13 +08:00
|
|
|
draw_tool->last_draw_time = 0;
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
draw_tool->display = NULL;
|
2001-02-27 13:21:12 +08:00
|
|
|
}
|
|
|
|
|
2003-06-28 00:05:05 +08:00
|
|
|
gboolean
|
|
|
|
gimp_draw_tool_is_active (GimpDrawTool *draw_tool)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), FALSE);
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
return draw_tool->display != NULL;
|
2003-06-28 00:05:05 +08:00
|
|
|
}
|
|
|
|
|
2001-11-12 22:45:58 +08:00
|
|
|
void
|
|
|
|
gimp_draw_tool_pause (GimpDrawTool *draw_tool)
|
|
|
|
{
|
2001-11-22 21:01:26 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
|
2001-11-12 22:45:58 +08:00
|
|
|
draw_tool->paused_count++;
|
2010-10-12 04:27:32 +08:00
|
|
|
|
|
|
|
if (draw_tool->draw_timeout)
|
|
|
|
{
|
|
|
|
g_source_remove (draw_tool->draw_timeout);
|
|
|
|
draw_tool->draw_timeout = 0;
|
|
|
|
}
|
2001-11-12 22:45:58 +08:00
|
|
|
}
|
2001-02-27 13:21:12 +08:00
|
|
|
|
|
|
|
void
|
2001-11-12 22:45:58 +08:00
|
|
|
gimp_draw_tool_resume (GimpDrawTool *draw_tool)
|
2001-02-27 13:21:12 +08:00
|
|
|
{
|
2001-11-12 22:45:58 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
2010-04-22 23:17:02 +08:00
|
|
|
g_return_if_fail (draw_tool->paused_count > 0);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2010-04-22 23:17:02 +08:00
|
|
|
draw_tool->paused_count--;
|
2001-02-28 03:18:01 +08:00
|
|
|
|
2012-10-06 06:27:49 +08:00
|
|
|
if (draw_tool->paused_count == 0)
|
|
|
|
{
|
2010-10-12 04:27:32 +08:00
|
|
|
#ifdef USE_TIMEOUT
|
2012-11-08 06:21:13 +08:00
|
|
|
/* Don't install the timeout if the draw tool isn't active, so
|
|
|
|
* suspend()/resume() can always be called, and have no side
|
|
|
|
* effect on an inactive tool. See bug #687851.
|
|
|
|
*/
|
|
|
|
if (gimp_draw_tool_is_active (draw_tool) && ! draw_tool->draw_timeout)
|
|
|
|
{
|
|
|
|
draw_tool->draw_timeout =
|
|
|
|
gdk_threads_add_timeout_full (G_PRIORITY_HIGH_IDLE,
|
|
|
|
DRAW_TIMEOUT,
|
|
|
|
(GSourceFunc) gimp_draw_tool_draw_timeout,
|
|
|
|
draw_tool, NULL);
|
|
|
|
}
|
2010-10-12 04:27:32 +08:00
|
|
|
#endif
|
2012-10-06 06:27:49 +08:00
|
|
|
|
|
|
|
/* call draw() anyway, it will do nothing if the timeout is
|
|
|
|
* running, but will additionally check the drawing times to
|
|
|
|
* ensure the minimum framerate
|
|
|
|
*/
|
|
|
|
gimp_draw_tool_draw (draw_tool);
|
|
|
|
}
|
2001-02-27 13:21:12 +08:00
|
|
|
}
|
|
|
|
|
2006-07-10 15:21:09 +08:00
|
|
|
/**
|
|
|
|
* 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
|
2006-11-07 00:31:11 +08:00
|
|
|
* @x2: end point X in image coordinates
|
|
|
|
* @y2: end point Y in image coordinates
|
2006-07-10 15:21:09 +08:00
|
|
|
*
|
2007-03-30 17:41:18 +08:00
|
|
|
* If you just need to compare distances, consider to use
|
|
|
|
* gimp_draw_tool_calc_distance_square() instead.
|
|
|
|
*
|
2006-07-10 15:21:09 +08:00
|
|
|
* Returns: the distance between the given points in display coordinates
|
|
|
|
**/
|
2001-11-12 22:45:58 +08:00
|
|
|
gdouble
|
|
|
|
gimp_draw_tool_calc_distance (GimpDrawTool *draw_tool,
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display,
|
2001-11-12 22:45:58 +08:00
|
|
|
gdouble x1,
|
|
|
|
gdouble y1,
|
|
|
|
gdouble x2,
|
|
|
|
gdouble y2)
|
2007-03-30 17:41:18 +08:00
|
|
|
{
|
|
|
|
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
|
2007-03-30 17:41:18 +08:00
|
|
|
**/
|
|
|
|
gdouble
|
|
|
|
gimp_draw_tool_calc_distance_square (GimpDrawTool *draw_tool,
|
|
|
|
GimpDisplay *display,
|
|
|
|
gdouble x1,
|
|
|
|
gdouble y1,
|
|
|
|
gdouble x2,
|
|
|
|
gdouble y2)
|
2001-11-12 22:45:58 +08:00
|
|
|
{
|
2002-06-27 06:16:59 +08:00
|
|
|
GimpDisplayShell *shell;
|
|
|
|
gdouble tx1, ty1;
|
|
|
|
gdouble tx2, ty2;
|
2001-11-12 22:45:58 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), 0.0);
|
2006-03-29 01:55:52 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DISPLAY (display), 0.0);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2009-10-05 01:56:39 +08:00
|
|
|
shell = gimp_display_get_shell (display);
|
2002-06-27 06:16:59 +08:00
|
|
|
|
2010-09-23 16:50:39 +08:00
|
|
|
gimp_display_shell_transform_xy_f (shell, x1, y1, &tx1, &ty1);
|
|
|
|
gimp_display_shell_transform_xy_f (shell, x2, y2, &tx2, &ty2);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2007-03-30 17:41:18 +08:00
|
|
|
return SQR (tx2 - tx1) + SQR (ty2 - ty1);
|
2001-11-12 22:45:58 +08:00
|
|
|
}
|
|
|
|
|
2017-06-27 01:50:31 +08:00
|
|
|
void
|
|
|
|
gimp_draw_tool_set_widget (GimpDrawTool *draw_tool,
|
|
|
|
GimpToolWidget *widget)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
g_return_if_fail (widget == NULL || GIMP_IS_TOOL_WIDGET (widget));
|
|
|
|
|
|
|
|
if (widget == draw_tool->widget)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (draw_tool->widget)
|
|
|
|
{
|
2018-06-02 13:45:37 +08:00
|
|
|
gimp_tool_widget_set_focus (draw_tool->widget, FALSE);
|
|
|
|
|
2017-06-27 02:49:14 +08:00
|
|
|
g_signal_handlers_disconnect_by_func (draw_tool->widget,
|
|
|
|
gimp_draw_tool_widget_status,
|
|
|
|
draw_tool);
|
|
|
|
g_signal_handlers_disconnect_by_func (draw_tool->widget,
|
|
|
|
gimp_draw_tool_widget_status_coords,
|
|
|
|
draw_tool);
|
2019-01-13 16:38:19 +08:00
|
|
|
g_signal_handlers_disconnect_by_func (draw_tool->widget,
|
|
|
|
gimp_draw_tool_widget_message,
|
|
|
|
draw_tool);
|
2017-06-27 02:37:51 +08:00
|
|
|
g_signal_handlers_disconnect_by_func (draw_tool->widget,
|
|
|
|
gimp_draw_tool_widget_snap_offsets,
|
|
|
|
draw_tool);
|
|
|
|
|
2017-06-27 01:50:31 +08:00
|
|
|
if (gimp_draw_tool_is_active (draw_tool))
|
|
|
|
{
|
|
|
|
GimpCanvasItem *item = gimp_tool_widget_get_item (draw_tool->widget);
|
|
|
|
|
|
|
|
gimp_draw_tool_remove_item (draw_tool, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (draw_tool->widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
draw_tool->widget = widget;
|
|
|
|
|
|
|
|
if (draw_tool->widget)
|
|
|
|
{
|
|
|
|
g_object_ref (draw_tool->widget);
|
|
|
|
|
|
|
|
if (gimp_draw_tool_is_active (draw_tool))
|
|
|
|
{
|
|
|
|
GimpCanvasItem *item = gimp_tool_widget_get_item (draw_tool->widget);
|
|
|
|
|
|
|
|
gimp_draw_tool_add_item (draw_tool, item);
|
|
|
|
}
|
2017-06-27 02:37:51 +08:00
|
|
|
|
2017-06-27 02:49:14 +08:00
|
|
|
g_signal_connect (draw_tool->widget, "status",
|
|
|
|
G_CALLBACK (gimp_draw_tool_widget_status),
|
|
|
|
draw_tool);
|
|
|
|
g_signal_connect (draw_tool->widget, "status-coords",
|
|
|
|
G_CALLBACK (gimp_draw_tool_widget_status_coords),
|
|
|
|
draw_tool);
|
2019-01-13 16:38:19 +08:00
|
|
|
g_signal_connect (draw_tool->widget, "message",
|
|
|
|
G_CALLBACK (gimp_draw_tool_widget_message),
|
|
|
|
draw_tool);
|
2017-06-27 02:37:51 +08:00
|
|
|
g_signal_connect (draw_tool->widget, "snap-offsets",
|
|
|
|
G_CALLBACK (gimp_draw_tool_widget_snap_offsets),
|
|
|
|
draw_tool);
|
2018-06-02 13:45:37 +08:00
|
|
|
|
|
|
|
gimp_tool_widget_set_focus (draw_tool->widget, TRUE);
|
2017-06-27 01:50:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-27 03:47:54 +08:00
|
|
|
void
|
|
|
|
gimp_draw_tool_set_default_status (GimpDrawTool *draw_tool,
|
|
|
|
const gchar *status)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
|
|
|
|
if (draw_tool->default_status)
|
|
|
|
g_free (draw_tool->default_status);
|
|
|
|
|
|
|
|
draw_tool->default_status = g_strdup (status);
|
|
|
|
}
|
|
|
|
|
2011-11-17 04:32:29 +08:00
|
|
|
void
|
|
|
|
gimp_draw_tool_add_preview (GimpDrawTool *draw_tool,
|
|
|
|
GimpCanvasItem *item)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
|
|
|
|
|
|
|
|
if (! draw_tool->preview)
|
|
|
|
draw_tool->preview =
|
|
|
|
gimp_canvas_group_new (gimp_display_get_shell (draw_tool->display));
|
|
|
|
|
|
|
|
gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (draw_tool->preview), item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_draw_tool_remove_preview (GimpDrawTool *draw_tool,
|
|
|
|
GimpCanvasItem *item)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
|
|
|
|
g_return_if_fail (draw_tool->preview != NULL);
|
|
|
|
|
|
|
|
gimp_canvas_group_remove_item (GIMP_CANVAS_GROUP (draw_tool->preview), item);
|
|
|
|
}
|
|
|
|
|
2010-09-26 01:02:22 +08:00
|
|
|
void
|
|
|
|
gimp_draw_tool_add_item (GimpDrawTool *draw_tool,
|
|
|
|
GimpCanvasItem *item)
|
|
|
|
{
|
2010-10-04 20:03:37 +08:00
|
|
|
GimpCanvasGroup *group;
|
|
|
|
|
2010-09-26 01:02:22 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
2010-09-26 06:30:09 +08:00
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
|
2010-09-26 01:02:22 +08:00
|
|
|
|
|
|
|
if (! draw_tool->item)
|
2011-11-17 04:32:29 +08:00
|
|
|
draw_tool->item =
|
|
|
|
gimp_canvas_group_new (gimp_display_get_shell (draw_tool->display));
|
2010-09-26 01:02:22 +08:00
|
|
|
|
2010-10-04 20:03:37 +08:00
|
|
|
group = GIMP_CANVAS_GROUP (draw_tool->item);
|
|
|
|
|
|
|
|
if (draw_tool->group_stack)
|
|
|
|
group = draw_tool->group_stack->data;
|
|
|
|
|
|
|
|
gimp_canvas_group_add_item (group, item);
|
2010-09-26 01:02:22 +08:00
|
|
|
}
|
|
|
|
|
2010-09-26 20:15:47 +08:00
|
|
|
void
|
|
|
|
gimp_draw_tool_remove_item (GimpDrawTool *draw_tool,
|
|
|
|
GimpCanvasItem *item)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
|
|
|
|
g_return_if_fail (draw_tool->item != NULL);
|
|
|
|
|
|
|
|
gimp_canvas_group_remove_item (GIMP_CANVAS_GROUP (draw_tool->item), item);
|
|
|
|
}
|
|
|
|
|
2010-10-04 20:03:37 +08:00
|
|
|
GimpCanvasGroup *
|
2010-10-01 20:24:46 +08:00
|
|
|
gimp_draw_tool_add_stroke_group (GimpDrawTool *draw_tool)
|
|
|
|
{
|
|
|
|
GimpCanvasItem *item;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), NULL);
|
|
|
|
|
|
|
|
item = gimp_canvas_group_new (gimp_display_get_shell (draw_tool->display));
|
|
|
|
gimp_canvas_group_set_group_stroking (GIMP_CANVAS_GROUP (item), TRUE);
|
|
|
|
|
|
|
|
gimp_draw_tool_add_item (draw_tool, item);
|
|
|
|
g_object_unref (item);
|
|
|
|
|
2010-10-04 20:03:37 +08:00
|
|
|
return GIMP_CANVAS_GROUP (item);
|
2010-10-01 20:24:46 +08:00
|
|
|
}
|
|
|
|
|
2010-10-04 20:03:37 +08:00
|
|
|
GimpCanvasGroup *
|
2010-10-01 20:24:46 +08:00
|
|
|
gimp_draw_tool_add_fill_group (GimpDrawTool *draw_tool)
|
|
|
|
{
|
|
|
|
GimpCanvasItem *item;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), NULL);
|
|
|
|
|
|
|
|
item = gimp_canvas_group_new (gimp_display_get_shell (draw_tool->display));
|
|
|
|
gimp_canvas_group_set_group_filling (GIMP_CANVAS_GROUP (item), TRUE);
|
|
|
|
|
|
|
|
gimp_draw_tool_add_item (draw_tool, item);
|
|
|
|
g_object_unref (item);
|
|
|
|
|
2010-10-04 20:03:37 +08:00
|
|
|
return GIMP_CANVAS_GROUP (item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_draw_tool_push_group (GimpDrawTool *draw_tool,
|
|
|
|
GimpCanvasGroup *group)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
g_return_if_fail (GIMP_IS_CANVAS_GROUP (group));
|
|
|
|
|
|
|
|
draw_tool->group_stack = g_list_prepend (draw_tool->group_stack, group);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_draw_tool_pop_group (GimpDrawTool *draw_tool)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
g_return_if_fail (draw_tool->group_stack != NULL);
|
|
|
|
|
|
|
|
draw_tool->group_stack = g_list_remove (draw_tool->group_stack,
|
|
|
|
draw_tool->group_stack->data);
|
2010-10-01 20:24:46 +08:00
|
|
|
}
|
|
|
|
|
2006-07-10 15:21:09 +08:00
|
|
|
/**
|
2010-09-26 01:02:22 +08:00
|
|
|
* gimp_draw_tool_add_line:
|
2006-07-10 15:21:09 +08:00
|
|
|
* @draw_tool: the #GimpDrawTool
|
|
|
|
* @x1: start point X in image coordinates
|
|
|
|
* @y1: start point Y in image coordinates
|
2006-11-07 00:31:11 +08:00
|
|
|
* @x2: end point X in image coordinates
|
|
|
|
* @y2: end point Y in image coordinates
|
2006-07-10 15:21:09 +08:00
|
|
|
*
|
|
|
|
* This function takes image space coordinates and transforms them to
|
|
|
|
* screen window coordinates, then draws a line between the resulting
|
|
|
|
* coordindates.
|
|
|
|
**/
|
2010-09-25 23:52:56 +08:00
|
|
|
GimpCanvasItem *
|
2010-09-26 01:02:22 +08:00
|
|
|
gimp_draw_tool_add_line (GimpDrawTool *draw_tool,
|
|
|
|
gdouble x1,
|
|
|
|
gdouble y1,
|
|
|
|
gdouble x2,
|
|
|
|
gdouble y2)
|
2001-11-12 22:45:58 +08:00
|
|
|
{
|
2010-09-25 01:08:19 +08:00
|
|
|
GimpCanvasItem *item;
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2010-09-25 23:52:56 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), NULL);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2010-10-01 20:13:45 +08:00
|
|
|
item = gimp_canvas_line_new (gimp_display_get_shell (draw_tool->display),
|
|
|
|
x1, y1, x2, y2);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2010-09-25 17:19:00 +08:00
|
|
|
gimp_draw_tool_add_item (draw_tool, item);
|
|
|
|
g_object_unref (item);
|
2010-09-25 23:52:56 +08:00
|
|
|
|
|
|
|
return item;
|
2001-11-12 22:45:58 +08:00
|
|
|
}
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2008-08-05 18:11:07 +08:00
|
|
|
/**
|
2010-10-05 04:02:12 +08:00
|
|
|
* gimp_draw_tool_add_guide:
|
2008-08-05 18:11:07 +08:00
|
|
|
* @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.
|
|
|
|
**/
|
2010-09-25 23:52:56 +08:00
|
|
|
GimpCanvasItem *
|
2010-09-30 08:03:16 +08:00
|
|
|
gimp_draw_tool_add_guide (GimpDrawTool *draw_tool,
|
|
|
|
GimpOrientationType orientation,
|
2010-10-04 04:14:40 +08:00
|
|
|
gint position,
|
2016-02-04 02:38:32 +08:00
|
|
|
GimpGuideStyle style)
|
2008-08-05 18:11:07 +08:00
|
|
|
{
|
2010-09-24 08:11:04 +08:00
|
|
|
GimpCanvasItem *item;
|
2008-08-05 18:11:07 +08:00
|
|
|
|
2010-09-25 23:52:56 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), NULL);
|
2008-08-05 18:11:07 +08:00
|
|
|
|
2010-10-01 20:13:45 +08:00
|
|
|
item = gimp_canvas_guide_new (gimp_display_get_shell (draw_tool->display),
|
2015-12-15 09:54:04 +08:00
|
|
|
orientation, position,
|
2016-02-04 02:38:32 +08:00
|
|
|
style);
|
2008-08-05 18:11:07 +08:00
|
|
|
|
2010-09-25 17:19:00 +08:00
|
|
|
gimp_draw_tool_add_item (draw_tool, item);
|
|
|
|
g_object_unref (item);
|
2010-09-25 23:52:56 +08:00
|
|
|
|
|
|
|
return item;
|
2008-08-05 18:11:07 +08:00
|
|
|
}
|
|
|
|
|
2010-09-30 08:03:16 +08:00
|
|
|
/**
|
2010-10-05 04:02:12 +08:00
|
|
|
* gimp_draw_tool_add_crosshair:
|
|
|
|
* @draw_tool: the #GimpDrawTool
|
|
|
|
* @position_x: the position of the vertical guide line in image coordinates
|
|
|
|
* @position_y: the position of the horizontal guide line in image coordinates
|
|
|
|
*
|
|
|
|
* This function draws two crossing guide lines across the canvas.
|
|
|
|
**/
|
|
|
|
GimpCanvasItem *
|
|
|
|
gimp_draw_tool_add_crosshair (GimpDrawTool *draw_tool,
|
|
|
|
gint position_x,
|
|
|
|
gint position_y)
|
|
|
|
{
|
|
|
|
GimpCanvasGroup *group;
|
|
|
|
|
|
|
|
group = gimp_draw_tool_add_stroke_group (draw_tool);
|
|
|
|
|
|
|
|
gimp_draw_tool_push_group (draw_tool, group);
|
|
|
|
gimp_draw_tool_add_guide (draw_tool,
|
2015-12-15 09:54:04 +08:00
|
|
|
GIMP_ORIENTATION_VERTICAL, position_x,
|
2016-02-04 02:38:32 +08:00
|
|
|
GIMP_GUIDE_STYLE_NONE);
|
2010-10-05 04:02:12 +08:00
|
|
|
gimp_draw_tool_add_guide (draw_tool,
|
2015-12-15 09:54:04 +08:00
|
|
|
GIMP_ORIENTATION_HORIZONTAL, position_y,
|
2016-02-04 02:38:32 +08:00
|
|
|
GIMP_GUIDE_STYLE_NONE);
|
2010-10-05 04:02:12 +08:00
|
|
|
gimp_draw_tool_pop_group (draw_tool);
|
|
|
|
|
|
|
|
return GIMP_CANVAS_ITEM (group);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_draw_tool_add_sample_point:
|
2010-09-30 08:03:16 +08:00
|
|
|
* @draw_tool: the #GimpDrawTool
|
|
|
|
* @x: X position of the sample point
|
|
|
|
* @y: Y position of the sample point
|
|
|
|
* @index: Index of the sample point
|
|
|
|
*
|
|
|
|
* This function draws a sample point
|
|
|
|
**/
|
|
|
|
GimpCanvasItem *
|
|
|
|
gimp_draw_tool_add_sample_point (GimpDrawTool *draw_tool,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint index)
|
|
|
|
{
|
|
|
|
GimpCanvasItem *item;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), NULL);
|
|
|
|
|
2010-10-01 20:13:45 +08:00
|
|
|
item = gimp_canvas_sample_point_new (gimp_display_get_shell (draw_tool->display),
|
2010-10-04 04:14:40 +08:00
|
|
|
x, y, index, TRUE);
|
2010-09-30 08:03:16 +08:00
|
|
|
|
|
|
|
gimp_draw_tool_add_item (draw_tool, item);
|
|
|
|
g_object_unref (item);
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2006-07-10 15:21:09 +08:00
|
|
|
/**
|
2010-09-26 01:02:22 +08:00
|
|
|
* gimp_draw_tool_add_rectangle:
|
2006-07-10 15:21:09 +08:00
|
|
|
* @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
|
|
|
|
*
|
|
|
|
* This function takes image space coordinates and transforms them to
|
|
|
|
* screen window coordinates, then draws the resulting rectangle.
|
|
|
|
**/
|
2010-09-25 23:52:56 +08:00
|
|
|
GimpCanvasItem *
|
2010-09-26 01:02:22 +08:00
|
|
|
gimp_draw_tool_add_rectangle (GimpDrawTool *draw_tool,
|
|
|
|
gboolean filled,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble width,
|
|
|
|
gdouble height)
|
2001-02-27 13:21:12 +08:00
|
|
|
{
|
2010-09-25 02:40:02 +08:00
|
|
|
GimpCanvasItem *item;
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2010-09-25 23:52:56 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), NULL);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2010-10-01 20:13:45 +08:00
|
|
|
item = gimp_canvas_rectangle_new (gimp_display_get_shell (draw_tool->display),
|
|
|
|
x, y, width, height, filled);
|
2010-02-22 03:41:48 +08:00
|
|
|
|
2010-09-25 17:19:00 +08:00
|
|
|
gimp_draw_tool_add_item (draw_tool, item);
|
|
|
|
g_object_unref (item);
|
2010-09-25 23:52:56 +08:00
|
|
|
|
|
|
|
return item;
|
2001-11-12 22:45:58 +08:00
|
|
|
}
|
|
|
|
|
2010-09-25 23:52:56 +08:00
|
|
|
GimpCanvasItem *
|
2010-09-26 01:02:22 +08:00
|
|
|
gimp_draw_tool_add_arc (GimpDrawTool *draw_tool,
|
|
|
|
gboolean filled,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble width,
|
|
|
|
gdouble height,
|
|
|
|
gdouble start_angle,
|
|
|
|
gdouble slice_angle)
|
2001-11-12 22:45:58 +08:00
|
|
|
{
|
2010-09-25 01:08:19 +08:00
|
|
|
GimpCanvasItem *item;
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2010-09-25 23:52:56 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), NULL);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2010-10-01 20:13:45 +08:00
|
|
|
item = gimp_canvas_arc_new (gimp_display_get_shell (draw_tool->display),
|
|
|
|
x + width / 2.0,
|
2010-09-25 01:08:19 +08:00
|
|
|
y + height / 2.0,
|
|
|
|
width / 2.0,
|
|
|
|
height / 2.0,
|
2010-09-25 23:35:40 +08:00
|
|
|
start_angle,
|
|
|
|
slice_angle,
|
2010-10-04 19:58:29 +08:00
|
|
|
filled);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2010-09-25 17:19:00 +08:00
|
|
|
gimp_draw_tool_add_item (draw_tool, item);
|
|
|
|
g_object_unref (item);
|
2010-09-25 23:52:56 +08:00
|
|
|
|
|
|
|
return item;
|
2001-02-27 22:14:13 +08:00
|
|
|
}
|
2001-04-07 22:55:39 +08:00
|
|
|
|
2010-09-25 23:52:56 +08:00
|
|
|
GimpCanvasItem *
|
2010-10-18 18:50:17 +08:00
|
|
|
gimp_draw_tool_add_handle (GimpDrawTool *draw_tool,
|
|
|
|
GimpHandleType type,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GimpHandleAnchor anchor)
|
2001-11-12 22:45:58 +08:00
|
|
|
{
|
2010-09-25 01:08:19 +08:00
|
|
|
GimpCanvasItem *item;
|
2001-11-16 05:17:36 +08:00
|
|
|
|
2010-09-25 23:52:56 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), NULL);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2010-10-01 20:13:45 +08:00
|
|
|
item = gimp_canvas_handle_new (gimp_display_get_shell (draw_tool->display),
|
|
|
|
type, anchor, x, y, width, height);
|
2001-11-16 05:17:36 +08:00
|
|
|
|
2010-09-25 17:19:00 +08:00
|
|
|
gimp_draw_tool_add_item (draw_tool, item);
|
|
|
|
g_object_unref (item);
|
2010-09-25 23:52:56 +08:00
|
|
|
|
|
|
|
return item;
|
2001-04-07 22:55:39 +08:00
|
|
|
}
|
|
|
|
|
2010-09-25 23:52:56 +08:00
|
|
|
GimpCanvasItem *
|
2010-09-26 01:02:22 +08:00
|
|
|
gimp_draw_tool_add_lines (GimpDrawTool *draw_tool,
|
|
|
|
const GimpVector2 *points,
|
|
|
|
gint n_points,
|
2017-06-20 03:53:49 +08:00
|
|
|
GimpMatrix3 *transform,
|
2010-09-26 01:02:22 +08:00
|
|
|
gboolean filled)
|
2008-11-22 03:01:58 +08:00
|
|
|
{
|
2010-09-24 08:11:04 +08:00
|
|
|
GimpCanvasItem *item;
|
2008-11-22 03:01:58 +08:00
|
|
|
|
2010-09-25 23:52:56 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), NULL);
|
2008-11-22 03:01:58 +08:00
|
|
|
|
2010-09-23 06:00:07 +08:00
|
|
|
if (points == NULL || n_points < 2)
|
2010-09-25 23:52:56 +08:00
|
|
|
return NULL;
|
2008-11-22 03:01:58 +08:00
|
|
|
|
2010-10-01 20:13:45 +08:00
|
|
|
item = gimp_canvas_polygon_new (gimp_display_get_shell (draw_tool->display),
|
2017-06-20 03:53:49 +08:00
|
|
|
points, n_points, transform, filled);
|
2008-11-22 03:01:58 +08:00
|
|
|
|
2010-09-25 17:19:00 +08:00
|
|
|
gimp_draw_tool_add_item (draw_tool, item);
|
|
|
|
g_object_unref (item);
|
2010-09-25 23:52:56 +08:00
|
|
|
|
|
|
|
return item;
|
2008-11-22 03:01:58 +08:00
|
|
|
}
|
|
|
|
|
2010-09-25 23:52:56 +08:00
|
|
|
GimpCanvasItem *
|
2010-09-26 01:02:22 +08:00
|
|
|
gimp_draw_tool_add_strokes (GimpDrawTool *draw_tool,
|
|
|
|
const GimpCoords *points,
|
|
|
|
gint n_points,
|
2017-06-20 03:53:49 +08:00
|
|
|
GimpMatrix3 *transform,
|
2010-09-26 01:02:22 +08:00
|
|
|
gboolean filled)
|
2008-11-22 03:01:58 +08:00
|
|
|
{
|
2010-09-24 08:11:04 +08:00
|
|
|
GimpCanvasItem *item;
|
2008-11-22 03:01:58 +08:00
|
|
|
|
2010-09-25 23:52:56 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), NULL);
|
2008-11-22 03:01:58 +08:00
|
|
|
|
2010-09-23 06:40:32 +08:00
|
|
|
if (points == NULL || n_points < 2)
|
2010-09-25 23:52:56 +08:00
|
|
|
return NULL;
|
2008-11-22 03:01:58 +08:00
|
|
|
|
2010-10-01 20:13:45 +08:00
|
|
|
item = gimp_canvas_polygon_new_from_coords (gimp_display_get_shell (draw_tool->display),
|
2017-06-20 03:53:49 +08:00
|
|
|
points, n_points, transform, filled);
|
2008-11-22 03:01:58 +08:00
|
|
|
|
2010-09-25 17:19:00 +08:00
|
|
|
gimp_draw_tool_add_item (draw_tool, item);
|
|
|
|
g_object_unref (item);
|
2010-09-25 23:52:56 +08:00
|
|
|
|
|
|
|
return item;
|
2008-11-22 03:01:58 +08:00
|
|
|
}
|
|
|
|
|
2010-10-07 20:10:57 +08:00
|
|
|
GimpCanvasItem *
|
2010-10-03 08:26:40 +08:00
|
|
|
gimp_draw_tool_add_pen (GimpDrawTool *draw_tool,
|
|
|
|
const GimpVector2 *points,
|
|
|
|
gint n_points,
|
|
|
|
GimpContext *context,
|
|
|
|
GimpActiveColor color,
|
|
|
|
gint width)
|
|
|
|
{
|
|
|
|
GimpCanvasItem *item;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), NULL);
|
|
|
|
|
|
|
|
if (points == NULL || n_points < 2)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
item = gimp_canvas_pen_new (gimp_display_get_shell (draw_tool->display),
|
|
|
|
points, n_points, context, color, width);
|
|
|
|
|
|
|
|
gimp_draw_tool_add_item (draw_tool, item);
|
|
|
|
g_object_unref (item);
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2008-11-22 03:01:58 +08:00
|
|
|
/**
|
2010-09-26 01:02:22 +08:00
|
|
|
* gimp_draw_tool_add_boundary:
|
2008-11-22 03:01:58 +08:00
|
|
|
* @draw_tool: a #GimpDrawTool
|
|
|
|
* @bound_segs: the sorted brush outline
|
|
|
|
* @n_bound_segs: the number of segments in @bound_segs
|
2010-10-10 04:00:19 +08:00
|
|
|
* @matrix: transform matrix for the boundary
|
2008-11-22 03:01:58 +08:00
|
|
|
* @offset_x: x offset
|
|
|
|
* @offset_y: y offset
|
|
|
|
*
|
|
|
|
* 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) .
|
|
|
|
*/
|
2010-09-25 23:52:56 +08:00
|
|
|
GimpCanvasItem *
|
2012-03-19 22:04:20 +08:00
|
|
|
gimp_draw_tool_add_boundary (GimpDrawTool *draw_tool,
|
|
|
|
const GimpBoundSeg *bound_segs,
|
|
|
|
gint n_bound_segs,
|
|
|
|
GimpMatrix3 *transform,
|
|
|
|
gdouble offset_x,
|
|
|
|
gdouble offset_y)
|
2008-11-22 03:01:58 +08:00
|
|
|
{
|
2010-09-25 01:08:19 +08:00
|
|
|
GimpCanvasItem *item;
|
2008-11-22 03:01:58 +08:00
|
|
|
|
2010-09-25 23:52:56 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), NULL);
|
|
|
|
g_return_val_if_fail (n_bound_segs > 0, NULL);
|
|
|
|
g_return_val_if_fail (bound_segs != NULL, NULL);
|
2008-11-22 03:01:58 +08:00
|
|
|
|
2010-10-01 20:13:45 +08:00
|
|
|
item = gimp_canvas_boundary_new (gimp_display_get_shell (draw_tool->display),
|
|
|
|
bound_segs, n_bound_segs,
|
2010-10-10 04:00:19 +08:00
|
|
|
transform,
|
2010-09-25 01:08:19 +08:00
|
|
|
offset_x, offset_y);
|
2008-11-22 03:01:58 +08:00
|
|
|
|
2010-09-25 17:19:00 +08:00
|
|
|
gimp_draw_tool_add_item (draw_tool, item);
|
|
|
|
g_object_unref (item);
|
2010-09-25 23:52:56 +08:00
|
|
|
|
|
|
|
return item;
|
2008-11-22 03:01:58 +08:00
|
|
|
}
|
|
|
|
|
2010-09-25 23:52:56 +08:00
|
|
|
GimpCanvasItem *
|
2018-07-29 12:57:38 +08:00
|
|
|
gimp_draw_tool_add_text_cursor (GimpDrawTool *draw_tool,
|
|
|
|
PangoRectangle *cursor,
|
|
|
|
gboolean overwrite,
|
|
|
|
GimpTextDirection direction)
|
2008-11-22 03:01:58 +08:00
|
|
|
{
|
2010-09-25 02:40:02 +08:00
|
|
|
GimpCanvasItem *item;
|
2008-11-22 03:01:58 +08:00
|
|
|
|
2010-09-25 23:52:56 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), NULL);
|
2008-11-22 03:01:58 +08:00
|
|
|
|
2010-10-01 20:13:45 +08:00
|
|
|
item = gimp_canvas_text_cursor_new (gimp_display_get_shell (draw_tool->display),
|
2018-07-29 12:57:38 +08:00
|
|
|
cursor, overwrite, direction);
|
2010-09-25 02:35:14 +08:00
|
|
|
|
2010-09-25 17:19:00 +08:00
|
|
|
gimp_draw_tool_add_item (draw_tool, item);
|
2011-03-28 08:18:00 +08:00
|
|
|
g_object_unref (item);
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpCanvasItem *
|
|
|
|
gimp_draw_tool_add_transform_preview (GimpDrawTool *draw_tool,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
const GimpMatrix3 *transform,
|
|
|
|
gdouble x1,
|
|
|
|
gdouble y1,
|
|
|
|
gdouble x2,
|
2017-11-15 00:19:42 +08:00
|
|
|
gdouble y2)
|
2011-03-28 08:18:00 +08:00
|
|
|
{
|
|
|
|
GimpCanvasItem *item;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
|
|
|
|
g_return_val_if_fail (transform != NULL, NULL);
|
|
|
|
|
|
|
|
item = gimp_canvas_transform_preview_new (gimp_display_get_shell (draw_tool->display),
|
|
|
|
drawable, transform,
|
2017-11-15 00:19:42 +08:00
|
|
|
x1, y1, x2, y2);
|
2011-03-28 08:18:00 +08:00
|
|
|
|
2011-11-17 04:32:29 +08:00
|
|
|
gimp_draw_tool_add_preview (draw_tool, item);
|
2010-09-25 17:19:00 +08:00
|
|
|
g_object_unref (item);
|
2010-09-25 23:52:56 +08:00
|
|
|
|
|
|
|
return item;
|
2008-11-22 03:01:58 +08:00
|
|
|
}
|
|
|
|
|
2001-11-16 05:17:36 +08:00
|
|
|
gboolean
|
2010-10-18 18:50:17 +08:00
|
|
|
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,
|
|
|
|
GimpHandleAnchor anchor)
|
2001-11-16 05:17:36 +08:00
|
|
|
{
|
2002-06-27 06:16:59 +08:00
|
|
|
GimpDisplayShell *shell;
|
|
|
|
gdouble tx, ty;
|
|
|
|
gdouble handle_tx, handle_ty;
|
2001-11-16 05:17:36 +08:00
|
|
|
|
2002-02-21 19:01:12 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), FALSE);
|
2006-03-29 01:55:52 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DISPLAY (display), FALSE);
|
2001-11-16 05:17:36 +08:00
|
|
|
|
2009-10-05 01:56:39 +08:00
|
|
|
shell = gimp_display_get_shell (display);
|
2002-06-27 06:16:59 +08:00
|
|
|
|
2013-04-25 06:29:58 +08:00
|
|
|
gimp_display_shell_zoom_xy_f (shell,
|
|
|
|
x, y,
|
|
|
|
&tx, &ty);
|
|
|
|
gimp_display_shell_zoom_xy_f (shell,
|
|
|
|
handle_x, handle_y,
|
|
|
|
&handle_tx, &handle_ty);
|
2013-04-20 21:30:23 +08:00
|
|
|
|
2001-11-16 05:17:36 +08:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GIMP_HANDLE_SQUARE:
|
|
|
|
case GIMP_HANDLE_FILLED_SQUARE:
|
|
|
|
case GIMP_HANDLE_CROSS:
|
2014-11-19 06:06:43 +08:00
|
|
|
case GIMP_HANDLE_CROSSHAIR:
|
2010-11-09 18:32:40 +08:00
|
|
|
gimp_canvas_item_shift_to_north_west (anchor,
|
|
|
|
handle_tx, handle_ty,
|
|
|
|
width, height,
|
|
|
|
&handle_tx, &handle_ty);
|
2001-11-16 05:17:36 +08:00
|
|
|
|
|
|
|
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:
|
2010-11-09 18:32:40 +08:00
|
|
|
gimp_canvas_item_shift_to_center (anchor,
|
|
|
|
handle_tx, handle_ty,
|
|
|
|
width, height,
|
|
|
|
&handle_tx, &handle_ty);
|
2001-11-16 05:17:36 +08:00
|
|
|
|
|
|
|
/* FIXME */
|
|
|
|
if (width != height)
|
2001-11-22 22:28:39 +08:00
|
|
|
width = (width + height) / 2;
|
|
|
|
|
|
|
|
width /= 2;
|
2001-11-16 05:17:36 +08:00
|
|
|
|
|
|
|
return ((SQR (handle_tx - tx) + SQR (handle_ty - ty)) < SQR (width));
|
|
|
|
|
|
|
|
default:
|
2004-05-12 16:13:33 +08:00
|
|
|
g_warning ("%s: invalid handle type %d", G_STRFUNC, type);
|
2001-11-16 05:17:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|