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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://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
|
|
|
|
2003-07-11 00:01:45 +08:00
|
|
|
#include "base/boundary.h"
|
|
|
|
|
2003-09-16 05:12:10 +08:00
|
|
|
#include "core/gimpimage.h"
|
|
|
|
|
2003-09-13 00:44:10 +08:00
|
|
|
#include "vectors/gimpanchor.h"
|
2003-09-12 02:02:39 +08:00
|
|
|
#include "vectors/gimpstroke.h"
|
|
|
|
#include "vectors/gimpvectors.h"
|
|
|
|
|
2003-11-11 03:35:56 +08:00
|
|
|
#include "display/gimpcanvas.h"
|
2010-09-23 04:19:28 +08:00
|
|
|
#include "display/gimpcanvashandle.h"
|
|
|
|
#include "display/gimpcanvasline.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"
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
2001-11-01 05:20:09 +08:00
|
|
|
#include "display/gimpdisplayshell.h"
|
2003-01-04 02:01:30 +08:00
|
|
|
#include "display/gimpdisplayshell-transform.h"
|
2001-05-10 06:34:59 +08:00
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "gimpdrawtool.h"
|
2001-02-27 13:21:12 +08:00
|
|
|
|
|
|
|
|
2010-04-22 22:45:44 +08:00
|
|
|
static void gimp_draw_tool_dispose (GObject *object);
|
|
|
|
|
2008-11-22 05:07:48 +08:00
|
|
|
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);
|
2001-11-16 05:17:36 +08:00
|
|
|
|
2008-11-22 05:07:48 +08:00
|
|
|
static void gimp_draw_tool_draw (GimpDrawTool *draw_tool);
|
2010-09-23 04:19:28 +08:00
|
|
|
static void gimp_draw_tool_undraw (GimpDrawTool *draw_tool);
|
2008-11-22 05:07:48 +08:00
|
|
|
static void gimp_draw_tool_real_draw (GimpDrawTool *draw_tool);
|
|
|
|
|
2001-11-16 05:17:36 +08:00
|
|
|
static inline void gimp_draw_tool_shift_to_north_west
|
2008-11-22 05:07:48 +08:00
|
|
|
(gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gint handle_width,
|
|
|
|
gint handle_height,
|
|
|
|
GtkAnchorType anchor,
|
|
|
|
gdouble *shifted_x,
|
|
|
|
gdouble *shifted_y);
|
2001-11-16 05:17:36 +08:00
|
|
|
static inline void gimp_draw_tool_shift_to_center
|
2008-11-22 05:07:48 +08:00
|
|
|
(gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gint handle_width,
|
|
|
|
gint handle_height,
|
|
|
|
GtkAnchorType anchor,
|
|
|
|
gdouble *shifted_x,
|
|
|
|
gdouble *shifted_y);
|
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);
|
|
|
|
|
|
|
|
object_class->dispose = gimp_draw_tool_dispose;
|
2001-02-28 03:18:01 +08:00
|
|
|
|
2006-06-19 03:58:49 +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;
|
2001-11-20 22:20:17 +08:00
|
|
|
|
2006-06-19 03:58:49 +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;
|
2002-02-07 19:33:01 +08:00
|
|
|
|
2001-11-12 22:45:58 +08:00
|
|
|
draw_tool->paused_count = 0;
|
2007-01-22 03:54:57 +08:00
|
|
|
draw_tool->is_drawn = FALSE;
|
2001-02-28 03:18:01 +08:00
|
|
|
}
|
|
|
|
|
2010-04-22 22:45:44 +08:00
|
|
|
static void
|
|
|
|
gimp_draw_tool_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
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:
|
2010-09-23 04:19:28 +08:00
|
|
|
if (! draw_tool->use_cairo)
|
|
|
|
gimp_draw_tool_pause (draw_tool);
|
2001-02-28 03:18:01 +08:00
|
|
|
break;
|
|
|
|
|
2006-05-22 05:12:01 +08:00
|
|
|
case GIMP_TOOL_ACTION_RESUME:
|
2010-09-23 04:19:28 +08:00
|
|
|
if (! draw_tool->use_cairo)
|
|
|
|
gimp_draw_tool_resume (draw_tool);
|
2001-02-28 03:18:01 +08:00
|
|
|
break;
|
|
|
|
|
2006-05-22 05:12:01 +08:00
|
|
|
case GIMP_TOOL_ACTION_HALT:
|
2001-02-28 03:18:01 +08:00
|
|
|
gimp_draw_tool_stop (draw_tool);
|
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2002-02-19 01:00:09 +08:00
|
|
|
static void
|
|
|
|
gimp_draw_tool_draw (GimpDrawTool *draw_tool)
|
|
|
|
{
|
2010-09-22 21:31:17 +08:00
|
|
|
if (draw_tool->paused_count == 0 &&
|
2010-03-20 04:08:41 +08:00
|
|
|
draw_tool->display)
|
2003-07-11 00:01:45 +08:00
|
|
|
{
|
2010-09-23 04:19:28 +08:00
|
|
|
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);
|
|
|
|
}
|
2007-01-22 03:54:57 +08:00
|
|
|
|
2010-09-23 04:19:28 +08:00
|
|
|
draw_tool->is_drawn = FALSE;
|
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)
|
|
|
|
{
|
2008-11-22 05:43:43 +08:00
|
|
|
/* the default implementation does nothing */
|
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));
|
2002-02-03 20:10:23 +08:00
|
|
|
|
2002-02-07 19:33:01 +08:00
|
|
|
gimp_draw_tool_stop (draw_tool);
|
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));
|
|
|
|
|
2010-09-23 04:19:28 +08:00
|
|
|
gimp_draw_tool_undraw (draw_tool);
|
2002-02-07 19:33:01 +08:00
|
|
|
|
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));
|
|
|
|
|
2010-09-23 04:19:28 +08:00
|
|
|
gimp_draw_tool_undraw (draw_tool);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
|
|
|
draw_tool->paused_count++;
|
|
|
|
}
|
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
|
|
|
|
2010-04-22 23:17:02 +08:00
|
|
|
gimp_draw_tool_draw (draw_tool);
|
2001-02-27 13:21:12 +08:00
|
|
|
}
|
|
|
|
|
2007-01-22 03:54:57 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-09-23 04:19:28 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
gimp_display_shell_transform_xy_f (shell, x1, y1, &tx1, &ty1, FALSE);
|
|
|
|
gimp_display_shell_transform_xy_f (shell, x2, y2, &tx2, &ty2, FALSE);
|
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
|
|
|
}
|
|
|
|
|
2006-07-10 15:21:09 +08:00
|
|
|
/**
|
|
|
|
* 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
|
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
|
|
|
* @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
|
|
|
|
**/
|
2001-11-12 22:45:58 +08:00
|
|
|
gboolean
|
|
|
|
gimp_draw_tool_in_radius (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,
|
|
|
|
gint radius)
|
|
|
|
{
|
2007-03-30 17:41:18 +08:00
|
|
|
return (gimp_draw_tool_calc_distance_square (draw_tool, display,
|
|
|
|
x1, y1, x2, y2) < SQR (radius));
|
2001-11-12 22:45:58 +08:00
|
|
|
}
|
|
|
|
|
2006-07-10 15:21:09 +08:00
|
|
|
/**
|
|
|
|
* gimp_draw_tool_draw_line:
|
|
|
|
* @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
|
|
|
* @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.
|
|
|
|
**/
|
2001-11-12 22:45:58 +08:00
|
|
|
void
|
|
|
|
gimp_draw_tool_draw_line (GimpDrawTool *draw_tool,
|
|
|
|
gdouble x1,
|
|
|
|
gdouble y1,
|
|
|
|
gdouble x2,
|
|
|
|
gdouble y2,
|
|
|
|
gboolean use_offsets)
|
|
|
|
{
|
|
|
|
GimpDisplayShell *shell;
|
2008-03-06 00:37:43 +08:00
|
|
|
gdouble tx1, ty1;
|
|
|
|
gdouble tx2, ty2;
|
2001-11-12 22:45:58 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
|
2010-09-23 04:19:28 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-10-05 01:56:39 +08:00
|
|
|
shell = gimp_display_get_shell (draw_tool->display);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2008-03-06 00:37:43 +08:00
|
|
|
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);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2003-11-11 03:35:56 +08:00
|
|
|
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
|
2008-03-06 00:37:43 +08:00
|
|
|
PROJ_ROUND (tx1), PROJ_ROUND (ty1),
|
|
|
|
PROJ_ROUND (tx2), PROJ_ROUND (ty2));
|
2001-11-12 22:45:58 +08:00
|
|
|
}
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2006-07-10 15:21:09 +08:00
|
|
|
/**
|
|
|
|
* gimp_draw_tool_draw_dashed_line:
|
|
|
|
* @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
|
|
|
* @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.
|
|
|
|
**/
|
2003-09-03 00:13:48 +08:00
|
|
|
void
|
|
|
|
gimp_draw_tool_draw_dashed_line (GimpDrawTool *draw_tool,
|
|
|
|
gdouble x1,
|
|
|
|
gdouble y1,
|
|
|
|
gdouble x2,
|
|
|
|
gdouble y2,
|
|
|
|
gboolean use_offsets)
|
|
|
|
{
|
2003-11-11 03:35:56 +08:00
|
|
|
GimpDisplayShell *shell;
|
2008-03-06 00:37:43 +08:00
|
|
|
gdouble tx1, ty1;
|
|
|
|
gdouble tx2, ty2;
|
2003-09-03 00:13:48 +08:00
|
|
|
|
2003-11-11 03:35:56 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
|
2009-10-05 01:56:39 +08:00
|
|
|
shell = gimp_display_get_shell (draw_tool->display);
|
2003-09-03 00:13:48 +08:00
|
|
|
|
2008-03-06 00:37:43 +08:00
|
|
|
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);
|
2003-09-03 00:13:48 +08:00
|
|
|
|
2003-11-11 03:35:56 +08:00
|
|
|
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas),
|
|
|
|
GIMP_CANVAS_STYLE_XOR_DASHED,
|
2008-03-06 00:37:43 +08:00
|
|
|
PROJ_ROUND (tx1), PROJ_ROUND (ty1),
|
|
|
|
PROJ_ROUND (tx2), PROJ_ROUND (ty2));
|
2003-09-03 00:13:48 +08:00
|
|
|
}
|
|
|
|
|
2008-08-05 18:11:07 +08:00
|
|
|
/**
|
|
|
|
* 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));
|
|
|
|
|
2009-10-05 01:56:39 +08:00
|
|
|
shell = gimp_display_get_shell (draw_tool->display);
|
2008-08-05 18:11:07 +08:00
|
|
|
|
|
|
|
x1 = 0;
|
|
|
|
y1 = 0;
|
|
|
|
|
2009-10-09 17:02:51 +08:00
|
|
|
gdk_drawable_get_size (gtk_widget_get_window (shell->canvas), &x2, &y2);
|
2008-08-05 18:11:07 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2006-07-10 15:21:09 +08:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
**/
|
2001-02-27 13:21:12 +08:00
|
|
|
void
|
2001-11-12 22:45:58 +08:00
|
|
|
gimp_draw_tool_draw_rectangle (GimpDrawTool *draw_tool,
|
|
|
|
gboolean filled,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble width,
|
|
|
|
gdouble height,
|
|
|
|
gboolean use_offsets)
|
2001-02-27 13:21:12 +08:00
|
|
|
{
|
2001-11-12 22:45:58 +08:00
|
|
|
GimpDisplayShell *shell;
|
2008-03-06 00:37:43 +08:00
|
|
|
gdouble tx1, ty1;
|
|
|
|
gdouble tx2, ty2;
|
2003-05-06 02:45:58 +08:00
|
|
|
guint w, h;
|
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-09-23 04:19:28 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-10-05 01:56:39 +08:00
|
|
|
shell = gimp_display_get_shell (draw_tool->display);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2008-03-06 00:37:43 +08:00
|
|
|
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);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2007-10-30 01:17:14 +08:00
|
|
|
tx1 = CLAMP (tx1, -1, shell->disp_width + 1);
|
2003-05-26 07:23:34 +08:00
|
|
|
ty1 = CLAMP (ty1, -1, shell->disp_height + 1);
|
2007-10-30 01:17:14 +08:00
|
|
|
tx2 = CLAMP (tx2, -1, shell->disp_width + 1);
|
2003-05-26 07:23:34 +08:00
|
|
|
ty2 = CLAMP (ty2, -1, shell->disp_height + 1);
|
|
|
|
|
2003-05-06 02:45:58 +08:00
|
|
|
tx2 -= tx1;
|
|
|
|
ty2 -= ty1;
|
2008-03-06 00:37:43 +08:00
|
|
|
w = PROJ_ROUND (MAX (0.0, tx2));
|
|
|
|
h = PROJ_ROUND (MAX (0.0, ty2));
|
2003-05-06 02:45:58 +08:00
|
|
|
|
2010-02-22 06:36:25 +08:00
|
|
|
if (w > 0 && h > 0)
|
2010-02-22 03:41:48 +08:00
|
|
|
{
|
2010-02-22 06:36:25 +08:00
|
|
|
if (! filled)
|
|
|
|
{
|
|
|
|
w--;
|
|
|
|
h--;
|
|
|
|
}
|
2010-02-22 03:41:48 +08:00
|
|
|
|
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);
|
|
|
|
}
|
2001-11-12 22:45:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2008-03-06 00:37:43 +08:00
|
|
|
gdouble tx1, ty1;
|
|
|
|
gdouble tx2, ty2;
|
2003-05-06 02:45:58 +08:00
|
|
|
guint w, h;
|
2001-11-12 22:45:58 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
|
2009-10-05 01:56:39 +08:00
|
|
|
shell = gimp_display_get_shell (draw_tool->display);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2008-03-06 00:37:43 +08:00
|
|
|
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);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2003-05-06 02:45:58 +08:00
|
|
|
tx2 -= tx1;
|
|
|
|
ty2 -= ty1;
|
2008-03-06 00:37:43 +08:00
|
|
|
w = PROJ_ROUND (MAX (0.0, tx2));
|
|
|
|
h = PROJ_ROUND (MAX (0.0, ty2));
|
2003-05-06 02:45:58 +08:00
|
|
|
|
|
|
|
if (w > 0 && h > 0)
|
|
|
|
{
|
2010-02-22 06:36:25 +08:00
|
|
|
if (! filled)
|
|
|
|
{
|
|
|
|
w--;
|
|
|
|
h--;
|
|
|
|
}
|
|
|
|
|
2003-05-06 02:45:58 +08:00
|
|
|
if (w != 1 && h != 1)
|
2003-11-11 03:35:56 +08:00
|
|
|
{
|
|
|
|
gimp_canvas_draw_arc (GIMP_CANVAS (shell->canvas),
|
|
|
|
GIMP_CANVAS_STYLE_XOR,
|
|
|
|
filled,
|
2008-03-06 00:37:43 +08:00
|
|
|
PROJ_ROUND (tx1), PROJ_ROUND (ty1),
|
2010-02-22 03:41:48 +08:00
|
|
|
w, h,
|
2003-11-11 03:35:56 +08:00
|
|
|
angle1, angle2);
|
|
|
|
}
|
2003-05-06 02:45:58 +08:00
|
|
|
else
|
2003-11-11 03:35:56 +08:00
|
|
|
{
|
|
|
|
/* work around the problem of an 1xN or Nx1 arc not being shown
|
2008-03-06 00:37:43 +08:00
|
|
|
* properly
|
|
|
|
*/
|
2003-11-11 03:35:56 +08:00
|
|
|
gimp_canvas_draw_rectangle (GIMP_CANVAS (shell->canvas),
|
|
|
|
GIMP_CANVAS_STYLE_XOR,
|
|
|
|
filled,
|
2008-03-06 00:37:43 +08:00
|
|
|
PROJ_ROUND (tx1), PROJ_ROUND (ty1),
|
2010-02-22 03:41:48 +08:00
|
|
|
w, h);
|
2003-11-11 03:35:56 +08:00
|
|
|
}
|
2003-05-06 02:45:58 +08:00
|
|
|
}
|
2001-11-12 22:45:58 +08:00
|
|
|
}
|
|
|
|
|
2010-09-20 06:13:32 +08:00
|
|
|
static void
|
2001-11-16 05:17:36 +08:00
|
|
|
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)
|
2001-11-12 22:45:58 +08:00
|
|
|
{
|
2010-09-20 06:13:32 +08:00
|
|
|
GimpDisplayShell *shell = gimp_display_get_shell (draw_tool->display);
|
2001-11-12 22:45:58 +08:00
|
|
|
gdouble tx, ty;
|
|
|
|
|
2002-06-27 06:16:59 +08:00
|
|
|
gimp_display_shell_transform_xy_f (shell,
|
|
|
|
x, y,
|
|
|
|
&tx, &ty,
|
|
|
|
use_offsets);
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2001-11-16 05:17:36 +08:00
|
|
|
gimp_draw_tool_shift_to_north_west (tx, ty,
|
|
|
|
width, height,
|
|
|
|
anchor,
|
|
|
|
&tx, &ty);
|
|
|
|
|
2006-06-06 05:39:23 +08:00
|
|
|
if (! filled)
|
2001-11-16 05:17:36 +08:00
|
|
|
{
|
2006-06-06 05:39:23 +08:00
|
|
|
width -= 1;
|
|
|
|
height -= 1;
|
2001-11-16 05:17:36 +08:00
|
|
|
}
|
|
|
|
|
2003-11-11 03:35:56 +08:00
|
|
|
gimp_canvas_draw_rectangle (GIMP_CANVAS (shell->canvas),
|
|
|
|
GIMP_CANVAS_STYLE_XOR,
|
|
|
|
filled,
|
2004-03-21 05:59:41 +08:00
|
|
|
PROJ_ROUND (tx), PROJ_ROUND (ty),
|
2003-11-11 03:35:56 +08:00
|
|
|
width, height);
|
2001-02-27 22:14:13 +08:00
|
|
|
}
|
2001-04-07 22:55:39 +08:00
|
|
|
|
2001-11-12 22:45:58 +08:00
|
|
|
void
|
2001-11-16 05:17:36 +08:00
|
|
|
gimp_draw_tool_draw_arc_by_anchor (GimpDrawTool *draw_tool,
|
|
|
|
gboolean filled,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
2006-11-07 19:09:51 +08:00
|
|
|
gint width,
|
|
|
|
gint height,
|
2001-11-16 05:17:36 +08:00
|
|
|
gint angle1,
|
|
|
|
gint angle2,
|
|
|
|
GtkAnchorType anchor,
|
|
|
|
gboolean use_offsets)
|
2001-11-12 22:45:58 +08:00
|
|
|
{
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
gdouble tx, ty;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
|
2009-10-05 01:56:39 +08:00
|
|
|
shell = gimp_display_get_shell (draw_tool->display);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2002-06-27 06:16:59 +08:00
|
|
|
gimp_display_shell_transform_xy_f (shell,
|
|
|
|
x, y,
|
|
|
|
&tx, &ty,
|
|
|
|
use_offsets);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2001-11-16 05:17:36 +08:00
|
|
|
gimp_draw_tool_shift_to_north_west (tx, ty,
|
2006-11-07 19:09:51 +08:00
|
|
|
width, height,
|
2001-11-16 05:17:36 +08:00
|
|
|
anchor,
|
|
|
|
&tx, &ty);
|
|
|
|
|
2006-06-06 05:39:23 +08:00
|
|
|
if (! filled)
|
2001-11-16 05:17:36 +08:00
|
|
|
{
|
2006-11-07 19:09:51 +08:00
|
|
|
width -= 1;
|
|
|
|
height -= 1;
|
2001-11-16 05:17:36 +08:00
|
|
|
}
|
|
|
|
|
2003-11-11 03:35:56 +08:00
|
|
|
gimp_canvas_draw_arc (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
|
|
|
|
filled,
|
2004-03-21 05:59:41 +08:00
|
|
|
PROJ_ROUND (tx), PROJ_ROUND (ty),
|
2006-11-07 19:09:51 +08:00
|
|
|
width, height,
|
2003-11-11 03:35:56 +08:00
|
|
|
angle1, angle2);
|
2001-11-12 22:45:58 +08:00
|
|
|
}
|
2001-04-07 22:55:39 +08:00
|
|
|
|
2010-09-20 06:13:32 +08:00
|
|
|
static void
|
2001-11-16 05:17:36 +08:00
|
|
|
gimp_draw_tool_draw_cross_by_anchor (GimpDrawTool *draw_tool,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GtkAnchorType anchor,
|
|
|
|
gboolean use_offsets)
|
2001-04-07 22:55:39 +08:00
|
|
|
{
|
2010-09-20 06:13:32 +08:00
|
|
|
GimpDisplayShell *shell = gimp_display_get_shell (draw_tool->display);
|
2001-11-12 22:45:58 +08:00
|
|
|
gdouble tx, ty;
|
|
|
|
|
2002-06-27 06:16:59 +08:00
|
|
|
gimp_display_shell_transform_xy_f (shell,
|
|
|
|
x, y,
|
|
|
|
&tx, &ty,
|
|
|
|
use_offsets);
|
2001-04-07 22:55:39 +08:00
|
|
|
|
2001-11-16 05:17:36 +08:00
|
|
|
gimp_draw_tool_shift_to_center (tx, ty,
|
|
|
|
width, height,
|
|
|
|
anchor,
|
|
|
|
&tx, &ty);
|
|
|
|
|
2003-11-11 03:35:56 +08:00
|
|
|
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
|
2007-10-30 01:17:14 +08:00
|
|
|
PROJ_ROUND (tx),
|
|
|
|
PROJ_ROUND (ty) - (height >> 1),
|
|
|
|
PROJ_ROUND (tx),
|
|
|
|
PROJ_ROUND (ty) + ((height + 1) >> 1));
|
2003-11-11 03:35:56 +08:00
|
|
|
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
|
2007-10-30 01:17:14 +08:00
|
|
|
PROJ_ROUND (tx) - (width >> 1),
|
|
|
|
PROJ_ROUND (ty),
|
|
|
|
PROJ_ROUND (tx) + ((width + 1) >> 1),
|
|
|
|
PROJ_ROUND (ty));
|
2001-11-12 22:45:58 +08:00
|
|
|
}
|
2001-04-07 22:55:39 +08:00
|
|
|
|
2001-11-12 22:45:58 +08:00
|
|
|
void
|
2003-07-11 00:01:45 +08:00
|
|
|
gimp_draw_tool_draw_handle (GimpDrawTool *draw_tool,
|
2001-11-12 22:45:58 +08:00
|
|
|
GimpHandleType type,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
2001-11-16 05:17:36 +08:00
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GtkAnchorType anchor,
|
2001-11-12 22:45:58 +08:00
|
|
|
gboolean use_offsets)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
2001-04-07 22:55:39 +08:00
|
|
|
|
2010-09-23 04:19:28 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-11-12 22:45:58 +08:00
|
|
|
switch (type)
|
2001-11-01 05:20:09 +08:00
|
|
|
{
|
2001-11-12 22:45:58 +08:00
|
|
|
case GIMP_HANDLE_SQUARE:
|
2001-11-16 05:17:36 +08:00
|
|
|
gimp_draw_tool_draw_rectangle_by_anchor (draw_tool,
|
|
|
|
FALSE,
|
2001-11-12 22:45:58 +08:00
|
|
|
x, y,
|
2001-11-16 05:17:36 +08:00
|
|
|
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,
|
2001-11-12 22:45:58 +08:00
|
|
|
use_offsets);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_HANDLE_CIRCLE:
|
2001-11-16 05:17:36 +08:00
|
|
|
gimp_draw_tool_draw_arc_by_anchor (draw_tool,
|
|
|
|
FALSE,
|
|
|
|
x, y,
|
2006-11-07 19:09:51 +08:00
|
|
|
width,
|
|
|
|
height,
|
2001-11-16 05:17:36 +08:00
|
|
|
0, 360 * 64,
|
|
|
|
anchor,
|
|
|
|
use_offsets);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_HANDLE_FILLED_CIRCLE:
|
|
|
|
gimp_draw_tool_draw_arc_by_anchor (draw_tool,
|
|
|
|
TRUE,
|
2001-11-12 22:45:58 +08:00
|
|
|
x, y,
|
2006-11-07 19:09:51 +08:00
|
|
|
width,
|
|
|
|
height,
|
2001-11-12 22:45:58 +08:00
|
|
|
0, 360 * 64,
|
2001-11-16 05:17:36 +08:00
|
|
|
anchor,
|
2001-11-12 22:45:58 +08:00
|
|
|
use_offsets);
|
|
|
|
break;
|
|
|
|
|
2001-11-16 05:17:36 +08:00
|
|
|
case GIMP_HANDLE_CROSS:
|
|
|
|
gimp_draw_tool_draw_cross_by_anchor (draw_tool,
|
|
|
|
x, y,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
anchor,
|
|
|
|
use_offsets);
|
|
|
|
break;
|
|
|
|
|
2001-11-12 22:45:58 +08:00
|
|
|
default:
|
2004-05-12 16:13:33 +08:00
|
|
|
g_warning ("%s: invalid handle type %d", G_STRFUNC, type);
|
2001-11-12 22:45:58 +08:00
|
|
|
break;
|
2001-11-01 05:20:09 +08:00
|
|
|
}
|
2001-04-07 22:55:39 +08:00
|
|
|
}
|
|
|
|
|
2006-11-07 00:31:11 +08:00
|
|
|
/**
|
|
|
|
* gimp_draw_tool_draw_corner:
|
|
|
|
* @draw_tool: the #GimpDrawTool
|
2006-11-07 01:09:07 +08:00
|
|
|
* @highlight:
|
2007-11-04 22:10:56 +08:00
|
|
|
* @put_outside: whether to put the handles on the outside of the rectangle
|
2006-11-07 00:31:11 +08:00
|
|
|
* @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.
|
|
|
|
**/
|
2006-11-06 16:16:31 +08:00
|
|
|
void
|
|
|
|
gimp_draw_tool_draw_corner (GimpDrawTool *draw_tool,
|
2006-11-07 01:09:07 +08:00
|
|
|
gboolean highlight,
|
2007-11-04 22:10:56 +08:00
|
|
|
gboolean put_outside,
|
2006-11-07 00:31:11 +08:00
|
|
|
gdouble x1,
|
|
|
|
gdouble y1,
|
|
|
|
gdouble x2,
|
|
|
|
gdouble y2,
|
2006-11-06 16:16:31 +08:00
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GtkAnchorType anchor,
|
|
|
|
gboolean use_offsets)
|
|
|
|
{
|
|
|
|
GimpDisplayShell *shell;
|
2006-11-07 00:31:11 +08:00
|
|
|
GimpCanvas *canvas;
|
|
|
|
gint tx1, ty1;
|
|
|
|
gint tx2, ty2;
|
2007-07-01 02:13:41 +08:00
|
|
|
gint tw, th;
|
|
|
|
gint top_and_bottom_handle_x_offset;
|
|
|
|
gint left_and_right_handle_y_offset;
|
2006-11-06 16:16:31 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
|
2009-10-05 01:56:39 +08:00
|
|
|
shell = gimp_display_get_shell (draw_tool->display);
|
2006-11-07 00:31:11 +08:00
|
|
|
canvas = GIMP_CANVAS (shell->canvas);
|
2006-11-06 16:16:31 +08:00
|
|
|
|
2006-11-07 00:31:11 +08:00
|
|
|
gimp_display_shell_transform_xy (shell, x1, y1, &tx1, &ty1, use_offsets);
|
|
|
|
gimp_display_shell_transform_xy (shell, x2, y2, &tx2, &ty2, use_offsets);
|
2006-11-06 16:16:31 +08:00
|
|
|
|
2007-07-01 02:13:41 +08:00
|
|
|
tw = tx2 - tx1;
|
|
|
|
th = ty2 - ty1;
|
|
|
|
|
2007-11-07 06:04:18 +08:00
|
|
|
if ((! put_outside && (tw <= width || th <= height)) ||
|
2007-11-04 22:10:56 +08:00
|
|
|
width <= 2 || height <= 2)
|
2006-11-07 19:09:51 +08:00
|
|
|
return;
|
|
|
|
|
2007-07-01 02:13:41 +08:00
|
|
|
top_and_bottom_handle_x_offset = (tw - width) / 2;
|
|
|
|
left_and_right_handle_y_offset = (th - height) / 2;
|
|
|
|
|
2006-11-07 01:09:07 +08:00
|
|
|
switch (anchor)
|
2006-11-06 16:16:31 +08:00
|
|
|
{
|
2006-11-07 01:09:07 +08:00
|
|
|
case GTK_ANCHOR_CENTER:
|
|
|
|
break;
|
2006-11-07 00:31:11 +08:00
|
|
|
|
2006-11-07 01:09:07 +08:00
|
|
|
case GTK_ANCHOR_NORTH_WEST:
|
2007-11-04 22:10:56 +08:00
|
|
|
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);
|
|
|
|
}
|
2006-11-07 01:09:07 +08:00
|
|
|
break;
|
2006-11-07 00:31:11 +08:00
|
|
|
|
2006-11-07 01:09:07 +08:00
|
|
|
case GTK_ANCHOR_NORTH_EAST:
|
2007-11-04 22:10:56 +08:00
|
|
|
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);
|
|
|
|
}
|
2006-11-07 01:09:07 +08:00
|
|
|
break;
|
2006-11-07 00:31:11 +08:00
|
|
|
|
2006-11-07 01:09:07 +08:00
|
|
|
case GTK_ANCHOR_SOUTH_WEST:
|
2007-11-04 22:10:56 +08:00
|
|
|
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);
|
|
|
|
}
|
2006-11-07 01:09:07 +08:00
|
|
|
break;
|
2006-11-07 00:31:11 +08:00
|
|
|
|
2006-11-07 01:09:07 +08:00
|
|
|
case GTK_ANCHOR_SOUTH_EAST:
|
2007-11-04 22:10:56 +08:00
|
|
|
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);
|
|
|
|
}
|
2006-11-07 01:09:07 +08:00
|
|
|
break;
|
2006-11-07 00:31:11 +08:00
|
|
|
|
2006-11-07 01:09:07 +08:00
|
|
|
case GTK_ANCHOR_NORTH:
|
2007-11-04 22:10:56 +08:00
|
|
|
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);
|
|
|
|
}
|
2006-11-07 01:09:07 +08:00
|
|
|
break;
|
2006-11-07 00:31:11 +08:00
|
|
|
|
2006-11-07 01:09:07 +08:00
|
|
|
case GTK_ANCHOR_SOUTH:
|
2007-11-04 22:10:56 +08:00
|
|
|
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);
|
|
|
|
}
|
2006-11-07 01:09:07 +08:00
|
|
|
break;
|
2006-11-07 00:31:11 +08:00
|
|
|
|
2006-11-07 01:09:07 +08:00
|
|
|
case GTK_ANCHOR_WEST:
|
2007-11-04 22:10:56 +08:00
|
|
|
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);
|
|
|
|
}
|
2006-11-07 01:09:07 +08:00
|
|
|
break;
|
2006-11-07 00:31:11 +08:00
|
|
|
|
2006-11-07 01:09:07 +08:00
|
|
|
case GTK_ANCHOR_EAST:
|
2007-11-04 22:10:56 +08:00
|
|
|
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);
|
|
|
|
}
|
2006-11-07 01:09:07 +08:00
|
|
|
break;
|
2006-11-07 00:31:11 +08:00
|
|
|
}
|
2006-11-07 01:09:07 +08:00
|
|
|
|
2006-11-07 19:09:51 +08:00
|
|
|
if (! highlight)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (anchor)
|
2006-11-07 00:31:11 +08:00
|
|
|
{
|
2006-11-07 19:09:51 +08:00
|
|
|
case GTK_ANCHOR_NORTH_WEST:
|
2007-11-04 22:10:56 +08:00
|
|
|
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);
|
|
|
|
}
|
2006-11-07 19:09:51 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_ANCHOR_NORTH_EAST:
|
2007-11-04 22:10:56 +08:00
|
|
|
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);
|
|
|
|
}
|
2006-11-07 19:09:51 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_ANCHOR_SOUTH_WEST:
|
2007-11-04 22:10:56 +08:00
|
|
|
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);
|
|
|
|
}
|
2006-11-07 19:09:51 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_ANCHOR_SOUTH_EAST:
|
2007-11-04 22:10:56 +08:00
|
|
|
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);
|
|
|
|
}
|
2006-11-07 19:09:51 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_ANCHOR_NORTH:
|
2007-11-04 22:10:56 +08:00
|
|
|
if (put_outside)
|
|
|
|
{
|
|
|
|
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, FALSE,
|
2007-11-07 06:04:18 +08:00
|
|
|
tx1 + top_and_bottom_handle_x_offset + 1,
|
2007-11-04 22:10:56 +08:00
|
|
|
ty1 - height + 2,
|
2007-11-07 06:04:18 +08:00
|
|
|
width - 3, height - 3);
|
2007-11-04 22:10:56 +08:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
2006-11-07 19:09:51 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_ANCHOR_SOUTH:
|
2007-11-04 22:10:56 +08:00
|
|
|
if (put_outside)
|
|
|
|
{
|
|
|
|
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, FALSE,
|
2007-11-07 06:04:18 +08:00
|
|
|
tx1 + top_and_bottom_handle_x_offset + 1,
|
2007-11-04 22:10:56 +08:00
|
|
|
ty2,
|
2007-11-07 06:04:18 +08:00
|
|
|
width - 3, height - 3);
|
2007-11-04 22:10:56 +08:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
2006-11-07 19:09:51 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_ANCHOR_WEST:
|
2007-11-04 22:10:56 +08:00
|
|
|
if (put_outside)
|
|
|
|
{
|
|
|
|
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, FALSE,
|
|
|
|
tx1 - width + 2,
|
2007-11-07 06:04:18 +08:00
|
|
|
ty1 + left_and_right_handle_y_offset + 1,
|
|
|
|
width - 3, height - 3);
|
2007-11-04 22:10:56 +08:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
2006-11-07 19:09:51 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_ANCHOR_EAST:
|
2007-11-04 22:10:56 +08:00
|
|
|
if (put_outside)
|
|
|
|
{
|
|
|
|
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, FALSE,
|
|
|
|
tx2,
|
2007-11-07 06:04:18 +08:00
|
|
|
ty1 + left_and_right_handle_y_offset + 1,
|
|
|
|
width - 3, height - 3);
|
2007-11-04 22:10:56 +08:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
2006-11-07 19:09:51 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2006-11-06 16:16:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-22 03:01:58 +08:00
|
|
|
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)
|
2008-11-22 03:01:58 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-10-05 01:56:39 +08:00
|
|
|
shell = gimp_display_get_shell (draw_tool->display);
|
2008-11-22 03:01:58 +08:00
|
|
|
|
|
|
|
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));
|
|
|
|
|
2010-09-23 06:40:32 +08:00
|
|
|
if (points == NULL || n_points < 2)
|
2008-11-22 03:01:58 +08:00
|
|
|
return;
|
|
|
|
|
2010-09-23 06:40:32 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-10-05 01:56:39 +08:00
|
|
|
shell = gimp_display_get_shell (draw_tool->display);
|
2008-11-22 03:01:58 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2009-10-05 01:56:39 +08:00
|
|
|
shell = gimp_display_get_shell (draw_tool->display);
|
2008-11-22 03:01:58 +08:00
|
|
|
|
|
|
|
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
|
2010-03-07 08:15:04 +08:00
|
|
|
gimp_draw_tool_draw_text_cursor (GimpDrawTool *draw_tool,
|
|
|
|
PangoRectangle *cursor,
|
|
|
|
gboolean overwrite,
|
|
|
|
gboolean use_offsets)
|
2008-11-22 03:01:58 +08:00
|
|
|
{
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
gdouble tx1, ty1;
|
|
|
|
gdouble tx2, ty2;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
|
|
|
|
2009-10-05 01:56:39 +08:00
|
|
|
shell = gimp_display_get_shell (draw_tool->display);
|
2008-11-22 03:01:58 +08:00
|
|
|
|
|
|
|
gimp_display_shell_transform_xy_f (shell,
|
2010-03-07 08:15:04 +08:00
|
|
|
cursor->x, cursor->y,
|
2008-11-22 03:01:58 +08:00
|
|
|
&tx1, &ty1,
|
|
|
|
use_offsets);
|
|
|
|
|
2009-06-25 19:22:25 +08:00
|
|
|
if (overwrite)
|
|
|
|
{
|
2010-03-07 08:15:04 +08:00
|
|
|
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);
|
|
|
|
|
2009-06-25 19:22:25 +08:00
|
|
|
gimp_canvas_draw_rectangle (GIMP_CANVAS (shell->canvas),
|
|
|
|
GIMP_CANVAS_STYLE_XOR, FALSE,
|
2010-03-07 08:15:04 +08:00
|
|
|
x, y,
|
|
|
|
width, height);
|
2009-06-25 19:22:25 +08:00
|
|
|
gimp_canvas_draw_rectangle (GIMP_CANVAS (shell->canvas),
|
|
|
|
GIMP_CANVAS_STYLE_XOR, FALSE,
|
2010-03-07 08:15:04 +08:00
|
|
|
x + 1, y + 1,
|
|
|
|
width - 2, height - 2);
|
2009-06-25 19:22:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-03-07 08:15:04 +08:00
|
|
|
gimp_display_shell_transform_xy_f (shell,
|
|
|
|
cursor->x,
|
|
|
|
cursor->y + cursor->height,
|
|
|
|
&tx2, &ty2,
|
|
|
|
use_offsets);
|
|
|
|
|
2009-06-25 19:22:25 +08:00
|
|
|
/* 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);
|
|
|
|
}
|
2008-11-22 03:01:58 +08:00
|
|
|
}
|
|
|
|
|
2001-11-16 05:17:36 +08:00
|
|
|
gboolean
|
|
|
|
gimp_draw_tool_on_handle (GimpDrawTool *draw_tool,
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display,
|
2001-11-16 05:17:36 +08:00
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
GimpHandleType type,
|
|
|
|
gdouble handle_x,
|
|
|
|
gdouble handle_y,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GtkAnchorType anchor,
|
|
|
|
gboolean use_offsets)
|
|
|
|
{
|
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
|
|
|
|
|
|
|
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);
|
2001-11-16 05:17:36 +08:00
|
|
|
|
|
|
|
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)
|
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;
|
|
|
|
}
|
2001-04-07 22:55:39 +08:00
|
|
|
|
2003-09-13 00:44:10 +08:00
|
|
|
gboolean
|
2005-08-01 00:05:06 +08:00
|
|
|
gimp_draw_tool_on_vectors_handle (GimpDrawTool *draw_tool,
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display,
|
2005-08-01 00:05:06 +08:00
|
|
|
GimpVectors *vectors,
|
|
|
|
const GimpCoords *coord,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GimpAnchorType preferred,
|
|
|
|
gboolean exclusive,
|
|
|
|
GimpAnchor **ret_anchor,
|
|
|
|
GimpStroke **ret_stroke)
|
2003-09-13 00:44:10 +08:00
|
|
|
{
|
|
|
|
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);
|
2006-03-29 01:55:52 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DISPLAY (display), FALSE);
|
2003-09-13 00:44:10 +08:00
|
|
|
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)))
|
|
|
|
{
|
2008-07-22 03:22:27 +08:00
|
|
|
GList *anchor_list = gimp_stroke_get_draw_anchors (stroke);
|
|
|
|
GList *list;
|
2003-09-13 00:44:10 +08:00
|
|
|
|
2008-07-22 03:22:27 +08:00
|
|
|
anchor_list = g_list_concat (gimp_stroke_get_draw_anchors (stroke),
|
|
|
|
gimp_stroke_get_draw_controls (stroke));
|
2003-09-13 00:44:10 +08:00
|
|
|
|
2008-07-22 03:22:27 +08:00
|
|
|
for (list = anchor_list; list; list = g_list_next (list))
|
2003-09-13 00:44:10 +08:00
|
|
|
{
|
2008-07-22 03:22:27 +08:00
|
|
|
dx = coord->x - GIMP_ANCHOR (list->data)->position.x;
|
|
|
|
dy = coord->y - GIMP_ANCHOR (list->data)->position.y;
|
2003-09-13 00:44:10 +08:00
|
|
|
|
|
|
|
if (mindist < 0 || mindist > dx * dx + dy * dy)
|
|
|
|
{
|
|
|
|
mindist = dx * dx + dy * dy;
|
2008-07-22 03:22:27 +08:00
|
|
|
anchor = GIMP_ANCHOR (list->data);
|
|
|
|
|
2003-09-13 00:44:10 +08:00
|
|
|
if (ret_stroke)
|
|
|
|
*ret_stroke = stroke;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((pref_mindist < 0 || pref_mindist > dx * dx + dy * dy) &&
|
2008-07-22 03:22:27 +08:00
|
|
|
GIMP_ANCHOR (list->data)->type == preferred)
|
2003-09-13 00:44:10 +08:00
|
|
|
{
|
|
|
|
pref_mindist = dx * dx + dy * dy;
|
2008-07-22 03:22:27 +08:00
|
|
|
pref_anchor = GIMP_ANCHOR (list->data);
|
2003-09-13 00:44:10 +08:00
|
|
|
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 &&
|
2006-03-29 01:55:52 +08:00
|
|
|
gimp_draw_tool_on_handle (draw_tool, display,
|
2003-09-13 00:44:10 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
if (pref_anchor && gimp_draw_tool_on_handle (draw_tool, display,
|
2003-09-13 00:44:10 +08:00
|
|
|
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;
|
|
|
|
}
|
2003-09-18 05:49:45 +08:00
|
|
|
else if (!exclusive && anchor &&
|
2006-03-29 01:55:52 +08:00
|
|
|
gimp_draw_tool_on_handle (draw_tool, display,
|
2003-09-18 05:49:45 +08:00
|
|
|
coord->x,
|
|
|
|
coord->y,
|
|
|
|
GIMP_HANDLE_CIRCLE,
|
|
|
|
anchor->position.x,
|
|
|
|
anchor->position.y,
|
|
|
|
width, height,
|
|
|
|
GTK_ANCHOR_CENTER,
|
|
|
|
FALSE))
|
2003-09-13 00:44:10 +08:00
|
|
|
{
|
|
|
|
if (ret_anchor)
|
|
|
|
*ret_anchor = anchor;
|
|
|
|
|
|
|
|
/* *ret_stroke already set correctly. */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-09-18 05:49:45 +08:00
|
|
|
if (ret_anchor)
|
|
|
|
*ret_anchor = NULL;
|
|
|
|
if (ret_stroke)
|
|
|
|
*ret_stroke = NULL;
|
2004-03-10 20:45:11 +08:00
|
|
|
|
2003-09-13 00:44:10 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2005-08-01 00:05:06 +08:00
|
|
|
gimp_draw_tool_on_vectors_curve (GimpDrawTool *draw_tool,
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display,
|
2005-08-01 00:05:06 +08:00
|
|
|
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)
|
2003-09-13 00:44:10 +08:00
|
|
|
{
|
|
|
|
GimpStroke *stroke = NULL;
|
|
|
|
GimpAnchor *segment_start;
|
2003-09-18 21:20:40 +08:00
|
|
|
GimpAnchor *segment_end;
|
2006-04-03 02:19:48 +08:00
|
|
|
GimpCoords min_coords = GIMP_COORDS_DEFAULT_VALUES;
|
|
|
|
GimpCoords cur_coords;
|
2003-09-13 00:44:10 +08:00
|
|
|
gdouble min_dist, cur_dist, cur_pos;
|
|
|
|
|
|
|
|
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);
|
2003-09-13 00:44:10 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), FALSE);
|
|
|
|
g_return_val_if_fail (coord != NULL, FALSE);
|
|
|
|
|
|
|
|
if (ret_coords) *ret_coords = *coord;
|
2003-09-16 05:12:10 +08:00
|
|
|
if (ret_pos) *ret_pos = -1.0;
|
2003-09-13 00:44:10 +08:00
|
|
|
if (ret_segment_start) *ret_segment_start = NULL;
|
2003-09-18 21:20:40 +08:00
|
|
|
if (ret_segment_start) *ret_segment_end = NULL;
|
2003-09-13 00:44:10 +08:00
|
|
|
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,
|
2006-04-12 20:49:29 +08:00
|
|
|
&cur_coords,
|
2003-09-13 00:44:10 +08:00
|
|
|
&segment_start,
|
2003-09-18 21:20:40 +08:00
|
|
|
&segment_end,
|
2003-09-13 00:44:10 +08:00
|
|
|
&cur_pos);
|
|
|
|
|
2003-09-29 19:48:15 +08:00
|
|
|
if (cur_dist >= 0 && (min_dist < 0 || cur_dist < min_dist))
|
2003-09-13 00:44:10 +08:00
|
|
|
{
|
|
|
|
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;
|
2003-09-18 21:20:40 +08:00
|
|
|
if (ret_segment_end) *ret_segment_end = segment_end;
|
2003-09-13 00:44:10 +08:00
|
|
|
if (ret_stroke) *ret_stroke = stroke;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (min_dist >= 0 &&
|
2006-03-29 01:55:52 +08:00
|
|
|
gimp_draw_tool_on_handle (draw_tool, display,
|
2003-09-13 00:44:10 +08:00
|
|
|
coord->x,
|
|
|
|
coord->y,
|
|
|
|
GIMP_HANDLE_CIRCLE,
|
|
|
|
min_coords.x,
|
|
|
|
min_coords.y,
|
|
|
|
width, height,
|
|
|
|
GTK_ANCHOR_CENTER,
|
|
|
|
FALSE))
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-09-16 05:12:10 +08:00
|
|
|
gboolean
|
2005-08-01 00:05:06 +08:00
|
|
|
gimp_draw_tool_on_vectors (GimpDrawTool *draw_tool,
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display,
|
2005-08-01 00:05:06 +08:00
|
|
|
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)
|
2003-09-16 05:12:10 +08:00
|
|
|
{
|
2009-08-02 05:07:07 +08:00
|
|
|
GList *all_vectors;
|
2003-09-16 05:12:10 +08:00
|
|
|
GList *list;
|
|
|
|
|
2003-09-18 21:20:40 +08:00
|
|
|
if (ret_coords) *ret_coords = *coords;
|
|
|
|
if (ret_pos) *ret_pos = -1.0;
|
2003-09-16 06:41:25 +08:00
|
|
|
if (ret_segment_start) *ret_segment_start = NULL;
|
2003-09-18 21:20:40 +08:00
|
|
|
if (ret_segment_end) *ret_segment_end = NULL;
|
|
|
|
if (ret_stroke) *ret_stroke = NULL;
|
|
|
|
if (ret_vectors) *ret_vectors = NULL;
|
2003-09-16 05:12:10 +08:00
|
|
|
|
2009-10-07 01:20:44 +08:00
|
|
|
all_vectors = gimp_image_get_vectors_list (gimp_display_get_image (display));
|
2009-08-02 05:07:07 +08:00
|
|
|
|
|
|
|
for (list = all_vectors; list; list = g_list_next (list))
|
2003-09-16 05:12:10 +08:00
|
|
|
{
|
2004-03-10 20:45:11 +08:00
|
|
|
GimpVectors *vectors = list->data;
|
2003-09-16 05:12:10 +08:00
|
|
|
|
|
|
|
if (! gimp_item_get_visible (GIMP_ITEM (vectors)))
|
|
|
|
continue;
|
|
|
|
|
2004-03-10 20:45:11 +08:00
|
|
|
if (gimp_draw_tool_on_vectors_curve (draw_tool,
|
2006-03-29 01:55:52 +08:00
|
|
|
display,
|
2004-03-10 20:45:11 +08:00
|
|
|
vectors, coords,
|
|
|
|
width, height,
|
|
|
|
ret_coords,
|
|
|
|
ret_pos,
|
|
|
|
ret_segment_start,
|
|
|
|
ret_segment_end,
|
|
|
|
ret_stroke))
|
2003-09-16 05:12:10 +08:00
|
|
|
{
|
|
|
|
if (ret_vectors)
|
|
|
|
*ret_vectors = vectors;
|
|
|
|
|
2009-08-02 05:07:07 +08:00
|
|
|
g_list_free (all_vectors);
|
|
|
|
|
2003-09-16 05:12:10 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-02 05:07:07 +08:00
|
|
|
g_list_free (all_vectors);
|
|
|
|
|
2003-09-16 05:12:10 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|