mirror of https://github.com/GNOME/gimp.git
let gimp_draw_tool_draw_corner() also handle north, south, east and west
2006-11-06 Sven Neumann <sven@gimp.org> * app/tools/gimpdrawtool.[ch]: let gimp_draw_tool_draw_corner() also handle north, south, east and west corners and allow for filled corners. * app/tools/gimprectangletool.c (gimp_rectangle_tool_draw): simplified.
This commit is contained in:
parent
194f268f89
commit
e192b27f6d
|
@ -1,3 +1,11 @@
|
|||
2006-11-06 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/tools/gimpdrawtool.[ch]: let gimp_draw_tool_draw_corner()
|
||||
also handle north, south, east and west corners and allow for
|
||||
filled corners.
|
||||
|
||||
* app/tools/gimprectangletool.c (gimp_rectangle_tool_draw): simplified.
|
||||
|
||||
2006-11-05 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/tools/gimpdrawtool.[ch]
|
||||
|
|
|
@ -351,8 +351,8 @@ gimp_draw_tool_set_transform (GimpDrawTool *draw_tool,
|
|||
* @display: a #GimpDisplay
|
||||
* @x1: start point X in image coordinates
|
||||
* @y1: start point Y in image coordinates
|
||||
* @x1: end point X in image coordinates
|
||||
* @y1: end point Y in image coordinates
|
||||
* @x2: end point X in image coordinates
|
||||
* @y2: end point Y in image coordinates
|
||||
*
|
||||
* Returns: the distance between the given points in display coordinates
|
||||
**/
|
||||
|
@ -385,8 +385,8 @@ gimp_draw_tool_calc_distance (GimpDrawTool *draw_tool,
|
|||
* @display: a #GimpDisplay
|
||||
* @x1: start point X in image coordinates
|
||||
* @y1: start point Y in image coordinates
|
||||
* @x1: end point X in image coordinates
|
||||
* @y1: end point Y in image coordinates
|
||||
* @x2: end point X in image coordinates
|
||||
* @y2: end point Y in image coordinates
|
||||
* @radius: distance in screen coordinates, not image coordinates
|
||||
*
|
||||
* The points are in image space coordinates.
|
||||
|
@ -423,8 +423,8 @@ gimp_draw_tool_in_radius (GimpDrawTool *draw_tool,
|
|||
* @draw_tool: the #GimpDrawTool
|
||||
* @x1: start point X in image coordinates
|
||||
* @y1: start point Y in image coordinates
|
||||
* @x1: end point X in image coordinates
|
||||
* @y1: end point Y in image coordinates
|
||||
* @x2: end point X in image coordinates
|
||||
* @y2: end point Y in image coordinates
|
||||
* @use_offsets: whether to use the image pixel offsets of the tool's display
|
||||
*
|
||||
* This function takes image space coordinates and transforms them to
|
||||
|
@ -466,8 +466,8 @@ gimp_draw_tool_draw_line (GimpDrawTool *draw_tool,
|
|||
* @draw_tool: the #GimpDrawTool
|
||||
* @x1: start point X in image coordinates
|
||||
* @y1: start point Y in image coordinates
|
||||
* @x1: end point X in image coordinates
|
||||
* @y1: end point Y in image coordinates
|
||||
* @x2: end point X in image coordinates
|
||||
* @y2: end point Y in image coordinates
|
||||
* @use_offsets: whether to use the image pixel offsets of the tool's display
|
||||
*
|
||||
* This function takes image space coordinates and transforms them to
|
||||
|
@ -812,68 +812,168 @@ gimp_draw_tool_draw_handle (GimpDrawTool *draw_tool,
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_draw_tool_draw_corner:
|
||||
* @draw_tool: the #GimpDrawTool
|
||||
* @filled: whether to fill the rectangle
|
||||
* @x1:
|
||||
* @y1:
|
||||
* @x2:
|
||||
* @y2:
|
||||
* @width: corner width
|
||||
* @height: corner height
|
||||
* @anchor: which corner to draw
|
||||
* @use_offsets: whether to use the image pixel offsets of the tool's display
|
||||
*
|
||||
* This function takes image space coordinates and transforms them to
|
||||
* screen window coordinates. It draws a corner into an already drawn
|
||||
* rectangle outline, taking care of not drawing over an already drawn line.
|
||||
**/
|
||||
void
|
||||
gimp_draw_tool_draw_corner (GimpDrawTool *draw_tool,
|
||||
gdouble x,
|
||||
gdouble y,
|
||||
gboolean filled,
|
||||
gdouble x1,
|
||||
gdouble y1,
|
||||
gdouble x2,
|
||||
gdouble y2,
|
||||
gint width,
|
||||
gint height,
|
||||
GtkAnchorType anchor,
|
||||
gboolean use_offsets)
|
||||
{
|
||||
GimpDisplayShell *shell;
|
||||
gint tx, ty;
|
||||
GimpCanvas *canvas;
|
||||
gint tx1, ty1;
|
||||
gint tx2, ty2;
|
||||
|
||||
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
|
||||
g_return_if_fail (width > 2 && height > 2);
|
||||
|
||||
shell = GIMP_DISPLAY_SHELL (draw_tool->display->shell);
|
||||
canvas = GIMP_CANVAS (shell->canvas);
|
||||
|
||||
gimp_display_shell_transform_xy (shell,
|
||||
x, y,
|
||||
&tx, &ty,
|
||||
use_offsets);
|
||||
gimp_display_shell_transform_xy (shell, x1, y1, &tx1, &ty1, use_offsets);
|
||||
gimp_display_shell_transform_xy (shell, x2, y2, &tx2, &ty2, use_offsets);
|
||||
|
||||
switch (anchor)
|
||||
if (filled)
|
||||
{
|
||||
case GTK_ANCHOR_NORTH_WEST:
|
||||
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
|
||||
tx + 1, ty + height - 1,
|
||||
tx + width - 1, ty + height - 1);
|
||||
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
|
||||
tx + width - 1, ty + 1,
|
||||
tx + width - 1, ty + height);
|
||||
break;
|
||||
switch (anchor)
|
||||
{
|
||||
case GTK_ANCHOR_CENTER:
|
||||
break;
|
||||
|
||||
case GTK_ANCHOR_NORTH_EAST:
|
||||
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
|
||||
tx - 2, ty + height - 1,
|
||||
tx - width, ty + height - 1);
|
||||
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
|
||||
tx - width, ty + 1,
|
||||
tx - width, ty + height);
|
||||
break;
|
||||
case GTK_ANCHOR_NORTH_WEST:
|
||||
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, TRUE,
|
||||
tx1 + 1, ty1 + 1,
|
||||
width - 1, height - 1);
|
||||
break;
|
||||
|
||||
case GTK_ANCHOR_SOUTH_WEST:
|
||||
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
|
||||
tx + 1, ty - height,
|
||||
tx + width - 1, ty - height);
|
||||
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
|
||||
tx + width - 1, ty - height,
|
||||
tx + width - 1, ty - 1);
|
||||
break;
|
||||
case GTK_ANCHOR_NORTH_EAST:
|
||||
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, TRUE,
|
||||
tx2 - width, ty1 + 1,
|
||||
width - 1, height - 1);
|
||||
break;
|
||||
|
||||
case GTK_ANCHOR_SOUTH_EAST:
|
||||
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
|
||||
tx - 2, ty - height,
|
||||
tx - width, ty - height);
|
||||
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
|
||||
tx - width, ty - height,
|
||||
tx - width, ty - 1);
|
||||
break;
|
||||
case GTK_ANCHOR_SOUTH_WEST:
|
||||
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, TRUE,
|
||||
tx1 + 1, ty2 - height,
|
||||
width - 1, height - 1);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
case GTK_ANCHOR_SOUTH_EAST:
|
||||
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, TRUE,
|
||||
tx2 - width, ty2 - height,
|
||||
width - 1, height - 1);
|
||||
break;
|
||||
|
||||
case GTK_ANCHOR_NORTH:
|
||||
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, TRUE,
|
||||
tx1 + 1, ty1 + 1,
|
||||
tx2 - tx1 - 2, height - 1);
|
||||
break;
|
||||
|
||||
case GTK_ANCHOR_SOUTH:
|
||||
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, TRUE,
|
||||
tx1 + 1, ty2 - height,
|
||||
tx2 - tx1 - 2, height - 1);
|
||||
break;
|
||||
|
||||
case GTK_ANCHOR_WEST:
|
||||
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, TRUE,
|
||||
tx1 + 1, ty1 + 1,
|
||||
width - 1, ty2 - ty1 - 2);
|
||||
break;
|
||||
|
||||
case GTK_ANCHOR_EAST:
|
||||
gimp_canvas_draw_rectangle (canvas, GIMP_CANVAS_STYLE_XOR, TRUE,
|
||||
tx2 + width, ty1 + 1,
|
||||
width - 1, ty2 - ty1 - 2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (anchor)
|
||||
{
|
||||
case GTK_ANCHOR_CENTER:
|
||||
break;
|
||||
|
||||
case GTK_ANCHOR_NORTH_WEST:
|
||||
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
|
||||
tx1 + 1, ty1 + height - 1,
|
||||
tx1 + width - 1, ty1 + height - 1);
|
||||
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
|
||||
tx1 + width - 1, ty1 + 1,
|
||||
tx1 + width - 1, ty1 + height);
|
||||
break;
|
||||
|
||||
case GTK_ANCHOR_NORTH_EAST:
|
||||
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
|
||||
tx2 - 2, ty1 + height - 1,
|
||||
tx2 - width, ty1 + height - 1);
|
||||
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
|
||||
tx2 - width, ty1 + 1,
|
||||
tx2 - width, ty1 + height);
|
||||
break;
|
||||
|
||||
case GTK_ANCHOR_SOUTH_WEST:
|
||||
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
|
||||
tx1 + 1, ty2 - height,
|
||||
tx1 + width - 1, ty2 - height);
|
||||
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
|
||||
tx1 + width - 1, ty2 - height,
|
||||
tx1 + width - 1, ty2 - 1);
|
||||
break;
|
||||
|
||||
case GTK_ANCHOR_SOUTH_EAST:
|
||||
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
|
||||
tx2 - 2, ty2 - height,
|
||||
tx2 - width, ty2 - height);
|
||||
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
|
||||
tx2 - width, ty2 - height,
|
||||
tx2 - width, ty2 - 1);
|
||||
break;
|
||||
|
||||
case GTK_ANCHOR_NORTH:
|
||||
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
|
||||
tx1 + 1, ty1 + height, tx2 - 1, ty1 + height);
|
||||
break;
|
||||
|
||||
case GTK_ANCHOR_SOUTH:
|
||||
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
|
||||
tx1 + 1, ty2 - height, tx2 - 1, ty2 - height);
|
||||
break;
|
||||
|
||||
case GTK_ANCHOR_WEST:
|
||||
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
|
||||
tx1 + width, ty1 + 1, tx1 + width, ty2 - 1);
|
||||
break;
|
||||
|
||||
case GTK_ANCHOR_EAST:
|
||||
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_XOR,
|
||||
tx2 - width, ty1 + 1, tx2 - width, ty2 - 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -161,8 +161,11 @@ void gimp_draw_tool_draw_handle (GimpDrawTool *draw_tool,
|
|||
GtkAnchorType anchor,
|
||||
gboolean use_offsets);
|
||||
void gimp_draw_tool_draw_corner (GimpDrawTool *draw_tool,
|
||||
gdouble x,
|
||||
gdouble y,
|
||||
gboolean filled,
|
||||
gdouble x1,
|
||||
gdouble y1,
|
||||
gdouble x2,
|
||||
gdouble y2,
|
||||
gint width,
|
||||
gint height,
|
||||
GtkAnchorType anchor,
|
||||
|
|
|
@ -1547,88 +1547,79 @@ gimp_rectangle_tool_draw (GimpDrawTool *draw_tool)
|
|||
private->y2 - private->y1,
|
||||
FALSE);
|
||||
|
||||
gimp_rectangle_tool_draw_guides (draw_tool);
|
||||
|
||||
if (gimp_tool_control_is_active (tool->control))
|
||||
{
|
||||
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (tool->display->shell);
|
||||
gdouble handle_w = private->dcw / SCALEFACTOR_X (shell);
|
||||
gdouble handle_h = private->dch / SCALEFACTOR_Y (shell);
|
||||
gdouble x1 = private->x1;
|
||||
gdouble x2 = private->x2;
|
||||
gdouble y1 = private->y1;
|
||||
gdouble y2 = private->y2;
|
||||
GtkAnchorType anchor;
|
||||
|
||||
switch (private->function)
|
||||
{
|
||||
case RECT_RESIZING_UPPER_LEFT:
|
||||
gimp_draw_tool_draw_corner (draw_tool,
|
||||
private->x1, private->y1,
|
||||
private->dcw, private->dch,
|
||||
GTK_ANCHOR_NORTH_WEST, FALSE);
|
||||
anchor = GTK_ANCHOR_NORTH_WEST;
|
||||
break;
|
||||
|
||||
case RECT_RESIZING_UPPER_RIGHT:
|
||||
gimp_draw_tool_draw_corner (draw_tool,
|
||||
private->x2, private->y1,
|
||||
private->dcw, private->dch,
|
||||
GTK_ANCHOR_NORTH_EAST, FALSE);
|
||||
anchor = GTK_ANCHOR_NORTH_EAST;
|
||||
break;
|
||||
|
||||
case RECT_RESIZING_LOWER_LEFT:
|
||||
gimp_draw_tool_draw_corner (draw_tool,
|
||||
private->x1, private->y2,
|
||||
private->dcw, private->dch,
|
||||
GTK_ANCHOR_SOUTH_WEST, FALSE);
|
||||
anchor = GTK_ANCHOR_SOUTH_WEST;
|
||||
break;
|
||||
|
||||
case RECT_RESIZING_LOWER_RIGHT:
|
||||
gimp_draw_tool_draw_corner (draw_tool,
|
||||
private->x2, private->y2,
|
||||
private->dcw, private->dch,
|
||||
GTK_ANCHOR_SOUTH_EAST, FALSE);
|
||||
anchor = GTK_ANCHOR_SOUTH_EAST;
|
||||
break;
|
||||
|
||||
case RECT_RESIZING_LEFT:
|
||||
x1 = x2 = private->x1 + handle_w;
|
||||
gimp_draw_tool_draw_line (draw_tool, x1, y1, x2, y2, FALSE);
|
||||
anchor = GTK_ANCHOR_WEST;
|
||||
break;
|
||||
|
||||
case RECT_RESIZING_RIGHT:
|
||||
x1 = x2 = private->x2 - handle_w;
|
||||
gimp_draw_tool_draw_line (draw_tool, x1, y1, x2, y2, FALSE);
|
||||
anchor = GTK_ANCHOR_EAST;
|
||||
break;
|
||||
|
||||
case RECT_RESIZING_TOP:
|
||||
y1 = y2 = private->y1 + handle_h;
|
||||
gimp_draw_tool_draw_line (draw_tool, x1, y1, x2, y2, FALSE);
|
||||
anchor = GTK_ANCHOR_NORTH;
|
||||
break;
|
||||
|
||||
case RECT_RESIZING_BOTTOM:
|
||||
y1 = y2 = private->y2 - handle_h;
|
||||
gimp_draw_tool_draw_line (draw_tool, x1, y1, x2, y2, FALSE);
|
||||
anchor = GTK_ANCHOR_SOUTH;
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
gimp_draw_tool_draw_corner (draw_tool, FALSE,
|
||||
private->x1, private->y1,
|
||||
private->x2, private->y2,
|
||||
private->dcw, private->dch,
|
||||
anchor, FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_draw_tool_draw_corner (draw_tool,
|
||||
gimp_draw_tool_draw_corner (draw_tool, FALSE,
|
||||
private->x1, private->y1,
|
||||
private->x2, private->y2,
|
||||
private->dcw, private->dch,
|
||||
GTK_ANCHOR_NORTH_WEST, FALSE);
|
||||
gimp_draw_tool_draw_corner (draw_tool,
|
||||
private->x2, private->y1,
|
||||
gimp_draw_tool_draw_corner (draw_tool, FALSE,
|
||||
private->x1, private->y1,
|
||||
private->x2, private->y2,
|
||||
private->dcw, private->dch,
|
||||
GTK_ANCHOR_NORTH_EAST, FALSE);
|
||||
gimp_draw_tool_draw_corner (draw_tool,
|
||||
private->x1, private->y2,
|
||||
gimp_draw_tool_draw_corner (draw_tool, FALSE,
|
||||
private->x1, private->y1,
|
||||
private->x2, private->y2,
|
||||
private->dcw, private->dch,
|
||||
GTK_ANCHOR_SOUTH_WEST, FALSE);
|
||||
gimp_draw_tool_draw_corner (draw_tool,
|
||||
gimp_draw_tool_draw_corner (draw_tool, FALSE,
|
||||
private->x1, private->y1,
|
||||
private->x2, private->y2,
|
||||
private->dcw, private->dch,
|
||||
GTK_ANCHOR_SOUTH_EAST, FALSE);
|
||||
}
|
||||
|
||||
gimp_rectangle_tool_draw_guides (draw_tool);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in New Issue