Commit b6932690 authored by Michael Natterer's avatar Michael Natterer 😴

app: simplify creating of stroke and fill groups a lot

- add gimp_draw_tool_push_group()/pop_group() which manage a stack
  of groups; all items automatically get added to the stack's top group
- use push_group()/pop_group() all over the place, which saves a lot
  of code in most cases
- return GimpCanvasGroup not GimpCanvasItem pointers from
  gimp_draw_tool_add_stroke_group() and fill_group()

Unrelated:

- add GipmCanvasGroup parameter to gimp_rectangle_tool_draw()
- put rect select's round corners into the stroke group to
  avoid ugly overdrawing (the mis-alignment of arcs becomes
  very visible now however, will fix that soon)
parent 64d9d767
......@@ -85,6 +85,7 @@ static void gimp_crop_tool_cursor_update (GimpTool
const GimpCoords *coords,
GdkModifierType state,
GimpDisplay *display);
static void gimp_crop_tool_draw (GimpDrawTool *draw_tool);
static gboolean gimp_crop_tool_execute (GimpRectangleTool *rectangle,
gint x,
gint y,
......@@ -154,7 +155,7 @@ gimp_crop_tool_class_init (GimpCropToolClass *klass)
tool_class->oper_update = gimp_rectangle_tool_oper_update;
tool_class->cursor_update = gimp_crop_tool_cursor_update;
draw_tool_class->draw = gimp_rectangle_tool_draw;
draw_tool_class->draw = gimp_crop_tool_draw;
}
static void
......@@ -302,6 +303,12 @@ gimp_crop_tool_cursor_update (GimpTool *tool,
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
}
static void
gimp_crop_tool_draw (GimpDrawTool *draw_tool)
{
gimp_rectangle_tool_draw (draw_tool, NULL);
}
static gboolean
gimp_crop_tool_execute (GimpRectangleTool *rectangle,
gint x,
......
......@@ -198,6 +198,17 @@ gimp_draw_tool_draw (GimpDrawTool *draw_tool)
GIMP_DRAW_TOOL_GET_CLASS (draw_tool)->draw (draw_tool);
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);
}
if (draw_tool->item)
{
gimp_display_shell_add_item (shell, draw_tool->item);
......@@ -343,13 +354,20 @@ void
gimp_draw_tool_add_item (GimpDrawTool *draw_tool,
GimpCanvasItem *item)
{
GimpCanvasGroup *group;
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
if (! draw_tool->item)
draw_tool->item = gimp_canvas_group_new (gimp_display_get_shell (draw_tool->display));
gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (draw_tool->item), item);
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);
}
void
......@@ -363,7 +381,7 @@ gimp_draw_tool_remove_item (GimpDrawTool *draw_tool,
gimp_canvas_group_remove_item (GIMP_CANVAS_GROUP (draw_tool->item), item);
}
GimpCanvasItem *
GimpCanvasGroup *
gimp_draw_tool_add_stroke_group (GimpDrawTool *draw_tool)
{
GimpCanvasItem *item;
......@@ -376,10 +394,10 @@ gimp_draw_tool_add_stroke_group (GimpDrawTool *draw_tool)
gimp_draw_tool_add_item (draw_tool, item);
g_object_unref (item);
return item;
return GIMP_CANVAS_GROUP (item);
}
GimpCanvasItem *
GimpCanvasGroup *
gimp_draw_tool_add_fill_group (GimpDrawTool *draw_tool)
{
GimpCanvasItem *item;
......@@ -392,7 +410,27 @@ gimp_draw_tool_add_fill_group (GimpDrawTool *draw_tool)
gimp_draw_tool_add_item (draw_tool, item);
g_object_unref (item);
return item;
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);
}
/**
......
......@@ -43,6 +43,7 @@ struct _GimpDrawTool
gint paused_count; /* count to keep track of multiple pauses */
GimpCanvasItem *item;
GList *group_stack;
};
struct _GimpDrawToolClass
......@@ -84,8 +85,12 @@ void gimp_draw_tool_add_item (GimpDrawTool *draw_too
void gimp_draw_tool_remove_item (GimpDrawTool *draw_tool,
GimpCanvasItem *item);
GimpCanvasItem * gimp_draw_tool_add_stroke_group (GimpDrawTool *draw_tool);
GimpCanvasItem * gimp_draw_tool_add_fill_group (GimpDrawTool *draw_tool);
GimpCanvasGroup* gimp_draw_tool_add_stroke_group (GimpDrawTool *draw_tool);
GimpCanvasGroup* gimp_draw_tool_add_fill_group (GimpDrawTool *draw_tool);
void gimp_draw_tool_push_group (GimpDrawTool *draw_tool,
GimpCanvasGroup *group);
void gimp_draw_tool_pop_group (GimpDrawTool *draw_tool);
GimpCanvasItem * gimp_draw_tool_add_line (GimpDrawTool *draw_tool,
gdouble x1,
......
......@@ -1529,8 +1529,7 @@ gimp_free_select_tool_draw (GimpDrawTool *draw_tool)
GimpFreeSelectTool *fst = GIMP_FREE_SELECT_TOOL (draw_tool);
GimpFreeSelectToolPrivate *priv = GET_PRIVATE (fst);
GimpTool *tool = GIMP_TOOL (draw_tool);
GimpCanvasItem *stroke_group;
GimpCanvasItem *item;
GimpCanvasGroup *stroke_group;
gboolean hovering_first_point = FALSE;
gboolean handles_wants_to_show = FALSE;
GimpCoords coords = { priv->last_coords.x,
......@@ -1547,15 +1546,11 @@ gimp_free_select_tool_draw (GimpDrawTool *draw_tool)
stroke_group = gimp_draw_tool_add_stroke_group (draw_tool);
item = gimp_draw_tool_add_lines (draw_tool,
gimp_draw_tool_push_group (draw_tool, stroke_group);
gimp_draw_tool_add_lines (draw_tool,
priv->points, priv->n_points,
FALSE);
if (item)
{
gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (stroke_group), item);
gimp_draw_tool_remove_item (draw_tool, item);
}
gimp_draw_tool_pop_group (draw_tool);
/* We always show the handle for the first point, even with button1
* down, since releasing the button on the first point will close
......@@ -1616,14 +1611,13 @@ gimp_free_select_tool_draw (GimpDrawTool *draw_tool)
{
GimpVector2 last = priv->points[priv->n_points - 1];
item = gimp_draw_tool_add_line (draw_tool,
gimp_draw_tool_push_group (draw_tool, stroke_group);
gimp_draw_tool_add_line (draw_tool,
last.x,
last.y,
priv->pending_point.x,
priv->pending_point.y);
gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (stroke_group), item);
gimp_draw_tool_remove_item (draw_tool, item);
gimp_draw_tool_pop_group (draw_tool);
}
}
......
......@@ -655,8 +655,7 @@ gimp_measure_tool_draw (GimpDrawTool *draw_tool)
{
GimpMeasureTool *measure = GIMP_MEASURE_TOOL (draw_tool);
GimpTool *tool = GIMP_TOOL (draw_tool);
GimpCanvasItem *stroke_group;
GimpCanvasItem *item;
GimpCanvasGroup *stroke_group;
gint i;
gint draw_arc = 0;
......@@ -687,14 +686,15 @@ gimp_measure_tool_draw (GimpDrawTool *draw_tool)
if (i > 0)
{
item = gimp_draw_tool_add_line (draw_tool,
gimp_draw_tool_push_group (draw_tool, stroke_group);
gimp_draw_tool_add_line (draw_tool,
measure->x[0],
measure->y[0],
measure->x[i],
measure->y[i]);
gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (stroke_group), item);
gimp_draw_tool_remove_item (draw_tool, item);
gimp_draw_tool_pop_group (draw_tool);
/* only draw the arc if the lines are long enough */
if (gimp_draw_tool_calc_distance (draw_tool, tool->display,
......@@ -721,6 +721,10 @@ gimp_measure_tool_draw (GimpDrawTool *draw_tool)
if (angle2 != 0.0)
{
GimpCanvasItem *item;
gimp_draw_tool_push_group (draw_tool, stroke_group);
item = gimp_draw_tool_add_handle (draw_tool,
GIMP_HANDLE_CIRCLE,
measure->x[0],
......@@ -732,9 +736,6 @@ gimp_measure_tool_draw (GimpDrawTool *draw_tool)
gimp_canvas_handle_set_angles (GIMP_CANVAS_HANDLE (item),
angle1, angle2);
gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (stroke_group), item);
gimp_draw_tool_remove_item (draw_tool, item);
if (measure->num_points == 2)
{
GimpDisplayShell *shell;
......@@ -746,17 +747,16 @@ gimp_measure_tool_draw (GimpDrawTool *draw_tool)
target = FUNSCALEX (shell, (TARGET >> 1));
arc_radius = FUNSCALEX (shell, ARC_RADIUS);
item = gimp_draw_tool_add_line (draw_tool,
gimp_draw_tool_add_line (draw_tool,
measure->x[0],
measure->y[0],
(measure->x[1] >= measure->x[0] ?
measure->x[0] + arc_radius + target :
measure->x[0] - arc_radius - target),
measure->y[0]);
gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (stroke_group), item);
gimp_draw_tool_remove_item (draw_tool, item);
}
gimp_draw_tool_pop_group (draw_tool);
}
}
}
......
......@@ -747,35 +747,27 @@ gimp_perspective_clone_tool_draw (GimpDrawTool *draw_tool)
if (clone_tool->use_handles)
{
GimpCanvasItem *stroke_group;
GimpCanvasItem *item;
GimpCanvasGroup *stroke_group;
stroke_group = gimp_draw_tool_add_stroke_group (draw_tool);
/* draw the bounding box */
item = gimp_draw_tool_add_line (draw_tool,
gimp_draw_tool_push_group (draw_tool, stroke_group);
gimp_draw_tool_add_line (draw_tool,
clone_tool->tx1, clone_tool->ty1,
clone_tool->tx2, clone_tool->ty2);
gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (stroke_group), item);
gimp_draw_tool_remove_item (draw_tool, item);
item = gimp_draw_tool_add_line (draw_tool,
gimp_draw_tool_add_line (draw_tool,
clone_tool->tx2, clone_tool->ty2,
clone_tool->tx4, clone_tool->ty4);
gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (stroke_group), item);
gimp_draw_tool_remove_item (draw_tool, item);
item = gimp_draw_tool_add_line (draw_tool,
gimp_draw_tool_add_line (draw_tool,
clone_tool->tx3, clone_tool->ty3,
clone_tool->tx4, clone_tool->ty4);
gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (stroke_group), item);
gimp_draw_tool_remove_item (draw_tool, item);
item = gimp_draw_tool_add_line (draw_tool,
gimp_draw_tool_add_line (draw_tool,
clone_tool->tx3, clone_tool->ty3,
clone_tool->tx1, clone_tool->ty1);
gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (stroke_group), item);
gimp_draw_tool_remove_item (draw_tool, item);
gimp_draw_tool_pop_group (draw_tool);
/* draw the tool handles */
gimp_draw_tool_add_handle (draw_tool,
......
......@@ -41,6 +41,7 @@
#include "widgets/gimpviewabledialog.h"
#include "widgets/gimpwidgets-utils.h"
#include "display/gimpcanvasgroup.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "display/gimpdisplayshell-transform.h"
......@@ -288,12 +289,14 @@ gimp_rectangle_select_tool_draw (GimpDrawTool *draw_tool)
{
GimpRectangleSelectTool *rect_sel_tool;
GimpRectangleSelectToolPrivate *priv;
GimpCanvasGroup *stroke_group = NULL;
rect_sel_tool = GIMP_RECTANGLE_SELECT_TOOL (draw_tool);
priv = GIMP_RECTANGLE_SELECT_TOOL_GET_PRIVATE (rect_sel_tool);
if (priv->round_corners)
{
GimpCanvasItem *item;
gint x1, y1, x2, y2;
gdouble radius;
gint square_size;
......@@ -310,28 +313,39 @@ gimp_rectangle_select_tool_draw (GimpDrawTool *draw_tool)
square_size = (int) (radius * 2);
gimp_draw_tool_add_arc (draw_tool, FALSE,
stroke_group =
GIMP_CANVAS_GROUP (gimp_draw_tool_add_stroke_group (draw_tool));
item = gimp_draw_tool_add_arc (draw_tool, FALSE,
x1, y1,
square_size, square_size,
G_PI / 2.0, G_PI / 2.0);
gimp_canvas_group_add_item (stroke_group, item);
gimp_draw_tool_remove_item (draw_tool, item);
gimp_draw_tool_add_arc (draw_tool, FALSE,
item = gimp_draw_tool_add_arc (draw_tool, FALSE,
x2 - square_size, y1,
square_size, square_size,
0.0, G_PI / 2.0);
gimp_canvas_group_add_item (stroke_group, item);
gimp_draw_tool_remove_item (draw_tool, item);
gimp_draw_tool_add_arc (draw_tool, FALSE,
item = gimp_draw_tool_add_arc (draw_tool, FALSE,
x2 - square_size, y2 - square_size,
square_size, square_size,
G_PI * 1.5, G_PI / 2.0);
gimp_canvas_group_add_item (stroke_group, item);
gimp_draw_tool_remove_item (draw_tool, item);
gimp_draw_tool_add_arc (draw_tool, FALSE,
item = gimp_draw_tool_add_arc (draw_tool, FALSE,
x1, y2 - square_size,
square_size, square_size,
G_PI, G_PI / 2.0);
gimp_canvas_group_add_item (stroke_group, item);
gimp_draw_tool_remove_item (draw_tool, item);
}
gimp_rectangle_tool_draw (draw_tool);
gimp_rectangle_tool_draw (draw_tool, stroke_group);
}
static gboolean
......
......@@ -213,8 +213,7 @@ static GimpRectangleToolPrivate *
static void gimp_rectangle_tool_start (GimpRectangleTool *rect_tool,
GimpDisplay *display);
static void gimp_rectangle_tool_halt (GimpRectangleTool *rect_tool);
static void gimp_rectangle_tool_draw_guides (GimpDrawTool *draw_tool,
GimpCanvasGroup *stroke_group);
static void gimp_rectangle_tool_draw_guides (GimpDrawTool *draw_tool);
static void gimp_rectangle_tool_update_options (GimpRectangleTool *rect_tool,
GimpDisplay *display);
......@@ -1719,15 +1718,15 @@ gimp_rectangle_tool_cursor_update (GimpTool *tool,
}
void
gimp_rectangle_tool_draw (GimpDrawTool *draw_tool)
gimp_rectangle_tool_draw (GimpDrawTool *draw_tool,
GimpCanvasGroup *stroke_group)
{
GimpTool *tool;
GimpRectangleToolPrivate *private;
GimpCanvasItem *stroke_group;
GimpCanvasItem *item;
gdouble pub_x1, pub_y1, pub_x2, pub_y2;
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (draw_tool));
g_return_if_fail (stroke_group == NULL || GIMP_IS_CANVAS_GROUP (stroke_group));
tool = GIMP_TOOL (draw_tool);
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
......@@ -1738,18 +1737,20 @@ gimp_rectangle_tool_draw (GimpDrawTool *draw_tool)
if (private->function == GIMP_RECTANGLE_TOOL_INACTIVE)
return;
stroke_group = gimp_draw_tool_add_stroke_group (draw_tool);
if (! stroke_group)
stroke_group = GIMP_CANVAS_GROUP (gimp_draw_tool_add_stroke_group (draw_tool));
gimp_draw_tool_push_group (draw_tool, stroke_group);
gimp_rectangle_tool_draw_guides (draw_tool, GIMP_CANVAS_GROUP (stroke_group));
gimp_rectangle_tool_draw_guides (draw_tool);
item = gimp_draw_tool_add_rectangle (draw_tool, FALSE,
gimp_draw_tool_add_rectangle (draw_tool, FALSE,
pub_x1,
pub_y1,
pub_x2 - pub_x1,
pub_y2 - pub_y1);
gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (stroke_group), item);
gimp_draw_tool_remove_item (draw_tool, item);
gimp_draw_tool_pop_group (draw_tool);
switch (private->function)
{
......@@ -1774,46 +1775,42 @@ gimp_rectangle_tool_draw (GimpDrawTool *draw_tool)
case GIMP_RECTANGLE_TOOL_DEAD:
case GIMP_RECTANGLE_TOOL_CREATING:
item = gimp_draw_tool_add_corner (draw_tool, FALSE, private->narrow_mode,
gimp_draw_tool_push_group (draw_tool, stroke_group);
gimp_draw_tool_add_corner (draw_tool, FALSE, private->narrow_mode,
pub_x1, pub_y1,
pub_x2, pub_y2,
private->corner_handle_w,
private->corner_handle_h,
GTK_ANCHOR_NORTH_WEST);
gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (stroke_group), item);
gimp_draw_tool_remove_item (draw_tool, item);
item = gimp_draw_tool_add_corner (draw_tool, FALSE, private->narrow_mode,
gimp_draw_tool_add_corner (draw_tool, FALSE, private->narrow_mode,
pub_x1, pub_y1,
pub_x2, pub_y2,
private->corner_handle_w,
private->corner_handle_h,
GTK_ANCHOR_NORTH_EAST);
gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (stroke_group), item);
gimp_draw_tool_remove_item (draw_tool, item);
item = gimp_draw_tool_add_corner (draw_tool, FALSE, private->narrow_mode,
gimp_draw_tool_add_corner (draw_tool, FALSE, private->narrow_mode,
pub_x1, pub_y1,
pub_x2, pub_y2,
private->corner_handle_w,
private->corner_handle_h,
GTK_ANCHOR_SOUTH_WEST);
gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (stroke_group), item);
gimp_draw_tool_remove_item (draw_tool, item);
item = gimp_draw_tool_add_corner (draw_tool, FALSE, private->narrow_mode,
gimp_draw_tool_add_corner (draw_tool, FALSE, private->narrow_mode,
pub_x1, pub_y1,
pub_x2, pub_y2,
private->corner_handle_w,
private->corner_handle_h,
GTK_ANCHOR_SOUTH_EAST);
gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (stroke_group), item);
gimp_draw_tool_remove_item (draw_tool, item);
gimp_draw_tool_pop_group (draw_tool);
break;
case GIMP_RECTANGLE_TOOL_RESIZING_TOP:
case GIMP_RECTANGLE_TOOL_RESIZING_BOTTOM:
item = gimp_draw_tool_add_corner (draw_tool,
if (gimp_tool_control_is_active (tool->control))
gimp_draw_tool_push_group (draw_tool, stroke_group);
gimp_draw_tool_add_corner (draw_tool,
! gimp_tool_control_is_active (tool->control),
private->narrow_mode,
pub_x1, pub_y1,
......@@ -1821,16 +1818,17 @@ gimp_rectangle_tool_draw (GimpDrawTool *draw_tool)
private->top_and_bottom_handle_w,
private->corner_handle_h,
gimp_rectangle_tool_get_anchor (private));
if (gimp_tool_control_is_active (tool->control))
{
gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (stroke_group), item);
gimp_draw_tool_remove_item (draw_tool, item);
}
gimp_draw_tool_pop_group (draw_tool);
break;
case GIMP_RECTANGLE_TOOL_RESIZING_LEFT:
case GIMP_RECTANGLE_TOOL_RESIZING_RIGHT:
item = gimp_draw_tool_add_corner (draw_tool,
if (gimp_tool_control_is_active (tool->control))
gimp_draw_tool_push_group (draw_tool, stroke_group);
gimp_draw_tool_add_corner (draw_tool,
! gimp_tool_control_is_active (tool->control),
private->narrow_mode,
pub_x1, pub_y1,
......@@ -1838,15 +1836,16 @@ gimp_rectangle_tool_draw (GimpDrawTool *draw_tool)
private->corner_handle_w,
private->left_and_right_handle_h,
gimp_rectangle_tool_get_anchor (private));
if (gimp_tool_control_is_active (tool->control))
{
gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (stroke_group), item);
gimp_draw_tool_remove_item (draw_tool, item);
}
gimp_draw_tool_pop_group (draw_tool);
break;
default:
item = gimp_draw_tool_add_corner (draw_tool,
if (gimp_tool_control_is_active (tool->control))
gimp_draw_tool_push_group (draw_tool, stroke_group);
gimp_draw_tool_add_corner (draw_tool,
! gimp_tool_control_is_active (tool->control),
private->narrow_mode,
pub_x1, pub_y1,
......@@ -1854,21 +1853,17 @@ gimp_rectangle_tool_draw (GimpDrawTool *draw_tool)
private->corner_handle_w,
private->corner_handle_h,
gimp_rectangle_tool_get_anchor (private));
if (gimp_tool_control_is_active (tool->control))
{
gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (stroke_group), item);
gimp_draw_tool_remove_item (draw_tool, item);
}
gimp_draw_tool_pop_group (draw_tool);
break;
}
}
static void
gimp_rectangle_tool_draw_guides (GimpDrawTool *draw_tool,
GimpCanvasGroup *stroke_group)
gimp_rectangle_tool_draw_guides (GimpDrawTool *draw_tool)
{
GimpTool *tool = GIMP_TOOL (draw_tool);
GimpCanvasItem *item;
gdouble x1, y1;
gdouble x2, y2;
......@@ -1883,125 +1878,81 @@ gimp_rectangle_tool_draw_guides (GimpDrawTool *draw_tool,
break;
case GIMP_RECTANGLE_GUIDE_CENTER_LINES:
item = gimp_draw_tool_add_line (draw_tool,
gimp_draw_tool_add_line (draw_tool,
x1, (y1 + y2) / 2,
x2, (y1 + y2) / 2);
gimp_canvas_group_add_item (stroke_group, item);
gimp_draw_tool_remove_item (draw_tool, item);
item = gimp_draw_tool_add_line (draw_tool,
gimp_draw_tool_add_line (draw_tool,
(x1 + x2) / 2, y1,
(x1 + x2) / 2, y2);
gimp_canvas_group_add_item (stroke_group, item);
gimp_draw_tool_remove_item (draw_tool, item);
break;
case GIMP_RECTANGLE_GUIDE_THIRDS:
item = gimp_draw_tool_add_line (draw_tool,
gimp_draw_tool_add_line (draw_tool,
x1, (2 * y1 + y2) / 3,
x2, (2 * y1 + y2) / 3);
gimp_canvas_group_add_item (stroke_group, item);
gimp_draw_tool_remove_item (draw_tool, item);
item = gimp_draw_tool_add_line (draw_tool,
gimp_draw_tool_add_line (draw_tool,
x1, (y1 + 2 * y2) / 3,
x2, (y1 + 2 * y2) / 3);
gimp_canvas_group_add_item (stroke_group, item);
gimp_draw_tool_remove_item (draw_tool, item);
item = gimp_draw_tool_add_line (draw_tool,
gimp_draw_tool_add_line (draw_tool,
(2 * x1 + x2) / 3, y1,
(2 * x1 + x2) / 3, y2);
gimp_canvas_group_add_item (stroke_group, item);
gimp_draw_tool_remove_item (draw_tool, item);
item = gimp_draw_tool_add_line (draw_tool,
gimp_draw_tool_add_line (draw_tool,
(x1 + 2 * x2) / 3, y1,
(x1 + 2 * x2) / 3, y2);
gimp_canvas_group_add_item (stroke_group, item);
gimp_draw_tool_remove_item (draw_tool, item);
break;
case GIMP_RECTANGLE_GUIDE_FIFTHS:
item = gimp_draw_tool_add_line (draw_tool,
gimp_draw_tool_add_line (draw_tool,
x1, y1 + (y2 - y1) / 5,
x2, y1 + (y2 - y1) / 5);
gimp_canvas_group_add_item (stroke_group, item);
gimp_draw_tool_remove_item (draw_tool, item);
item = gimp_draw_tool_add_line (draw_tool,
gimp_draw_tool_add_line (draw_tool,
x1, y1 + 2 * (y2 - y1) / 5,
x2, y1 + 2 * (y2 - y1) / 5);
gimp_canvas_group_add_item (stroke_group, item);
gimp_draw_tool_remove_item (draw_tool, item);
item = gimp_draw_tool_add_line (draw_tool,
gimp_draw_tool_add_line (draw_tool,
x1, y1 + 3 * (y2 - y1) / 5,
x2, y1 + 3 * (y2 - y1) / 5);
gimp_canvas_group_add_item (stroke_group, item);
gimp_draw_tool_remove_item (draw_tool, item);
item = gimp_draw_tool_add_line (draw_tool,
gimp_draw_tool_add_line (draw_tool,
x1, y1 + 4 * (y2 - y1) / 5,
x2, y1 + 4 * (y2 - y1) / 5);
gimp_canvas_group_add_item (stroke_group, item);
gimp_draw_tool_remove_item (draw_tool, item);
item = gimp_draw_tool_add_line (draw_tool,
gimp_draw_tool_add_line (draw_tool,
x1 + (x2 - x1) / 5, y1,
x1 + (x2 - x1) / 5, y2);
gimp_canvas_group_add_item (stroke_group, item);
gimp_draw_tool_remove_item (draw_tool, item);