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)
This commit is contained in:
Michael Natterer 2010-10-04 14:03:37 +02:00
parent 64d9d76722
commit b693269060
11 changed files with 336 additions and 358 deletions

View File

@ -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,

View File

@ -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);
}
/**

View File

@ -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,

View File

@ -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,
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_push_group (draw_tool, stroke_group);
gimp_draw_tool_add_lines (draw_tool,
priv->points, priv->n_points,
FALSE);
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,
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_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_draw_tool_pop_group (draw_tool);
}
}

View File

@ -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,
measure->x[0],
measure->y[0],
measure->x[i],
measure->y[i]);
gimp_draw_tool_push_group (draw_tool, stroke_group);
gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (stroke_group), item);
gimp_draw_tool_remove_item (draw_tool, item);
gimp_draw_tool_add_line (draw_tool,
measure->x[0],
measure->y[0],
measure->x[i],
measure->y[i]);
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,
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_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_draw_tool_pop_group (draw_tool);
}
}
}

View File

@ -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,
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);
gimp_draw_tool_push_group (draw_tool, stroke_group);
item = 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);
gimp_draw_tool_add_line (draw_tool,
clone_tool->tx1, clone_tool->ty1,
clone_tool->tx2, clone_tool->ty2);
gimp_draw_tool_add_line (draw_tool,
clone_tool->tx2, clone_tool->ty2,
clone_tool->tx4, clone_tool->ty4);
gimp_draw_tool_add_line (draw_tool,
clone_tool->tx3, clone_tool->ty3,
clone_tool->tx4, clone_tool->ty4);
gimp_draw_tool_add_line (draw_tool,
clone_tool->tx3, clone_tool->ty3,
clone_tool->tx1, clone_tool->ty1);
item = 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,
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,

View File

@ -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,15 +289,17 @@ 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)
{
gint x1, y1, x2, y2;
gdouble radius;
gint square_size;
GimpCanvasItem *item;
gint x1, y1, x2, y2;
gdouble radius;
gint square_size;
g_object_get (rect_sel_tool,
"x1", &x1,
@ -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,
x1, y1,
square_size, square_size,
G_PI / 2.0, G_PI / 2.0);
stroke_group =
GIMP_CANVAS_GROUP (gimp_draw_tool_add_stroke_group (draw_tool));
gimp_draw_tool_add_arc (draw_tool, FALSE,
x2 - square_size, y1,
square_size, square_size,
0.0, G_PI / 2.0);
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,
x2 - square_size, y2 - square_size,
square_size, square_size,
G_PI * 1.5, G_PI / 2.0);
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,
x1, y2 - square_size,
square_size, square_size,
G_PI, G_PI / 2.0);
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);
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

View File

@ -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_rectangle_tool_draw_guides (draw_tool, GIMP_CANVAS_GROUP (stroke_group));
gimp_draw_tool_push_group (draw_tool, stroke_group);
item = gimp_draw_tool_add_rectangle (draw_tool, FALSE,
pub_x1,
pub_y1,
pub_x2 - pub_x1,
pub_y2 - pub_y1);
gimp_rectangle_tool_draw_guides (draw_tool);
gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (stroke_group), item);
gimp_draw_tool_remove_item (draw_tool, item);
gimp_draw_tool_add_rectangle (draw_tool, FALSE,
pub_x1,
pub_y1,
pub_x2 - pub_x1,
pub_y2 - pub_y1);
gimp_draw_tool_pop_group (draw_tool);
switch (private->function)
{
@ -1774,101 +1775,95 @@ 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,
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);
gimp_draw_tool_push_group (draw_tool, stroke_group);
item = 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);
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_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_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_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);
item = 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,
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,
! gimp_tool_control_is_active (tool->control),
private->narrow_mode,
pub_x1, pub_y1,
pub_x2, pub_y2,
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_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,
pub_x2, pub_y2,
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_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,
! gimp_tool_control_is_active (tool->control),
private->narrow_mode,
pub_x1, pub_y1,
pub_x2, pub_y2,
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_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,
pub_x2, pub_y2,
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_draw_tool_pop_group (draw_tool);
break;
default:
item = gimp_draw_tool_add_corner (draw_tool,
! gimp_tool_control_is_active (tool->control),
private->narrow_mode,
pub_x1, pub_y1,
pub_x2, pub_y2,
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_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,
pub_x2, pub_y2,
private->corner_handle_w,
private->corner_handle_h,
gimp_rectangle_tool_get_anchor (private));
if (gimp_tool_control_is_active (tool->control))
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,
x1, (y1 + y2) / 2,
x2, (y1 + y2) / 2);
gimp_canvas_group_add_item (stroke_group, item);
gimp_draw_tool_remove_item (draw_tool, item);
gimp_draw_tool_add_line (draw_tool,
x1, (y1 + y2) / 2,
x2, (y1 + y2) / 2);
item = 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);
gimp_draw_tool_add_line (draw_tool,
(x1 + x2) / 2, y1,
(x1 + x2) / 2, y2);
break;
case GIMP_RECTANGLE_GUIDE_THIRDS:
item = 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);
gimp_draw_tool_add_line (draw_tool,
x1, (2 * y1 + y2) / 3,
x2, (2 * y1 + y2) / 3);
gimp_draw_tool_add_line (draw_tool,
x1, (y1 + 2 * y2) / 3,
x2, (y1 + 2 * y2) / 3);
item = 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,
(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,
(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);
gimp_draw_tool_add_line (draw_tool,
(2 * x1 + x2) / 3, y1,
(2 * x1 + x2) / 3, y2);
gimp_draw_tool_add_line (draw_tool,
(x1 + 2 * x2) / 3, y1,
(x1 + 2 * x2) / 3, y2);
break;
case GIMP_RECTANGLE_GUIDE_FIFTHS:
item = 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);
gimp_draw_tool_add_line (draw_tool,
x1, y1 + (y2 - y1) / 5,
x2, y1 + (y2 - y1) / 5);
gimp_draw_tool_add_line (draw_tool,
x1, y1 + 2 * (y2 - y1) / 5,
x2, y1 + 2 * (y2 - y1) / 5);
gimp_draw_tool_add_line (draw_tool,
x1, y1 + 3 * (y2 - y1) / 5,
x2, y1 + 3 * (y2 - y1) / 5);
gimp_draw_tool_add_line (draw_tool,
x1, y1 + 4 * (y2 - y1) / 5,
x2, y1 + 4 * (y2 - y1) / 5);
item = 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,
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,
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,
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);
item = gimp_draw_tool_add_line (draw_tool,
x1 + 2 * (x2 - x1) / 5, y1,
x1 + 2 * (x2 - x1) / 5, 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,
x1 + 3 * (x2 - x1) / 5, y1,
x1 + 3 * (x2 - x1) / 5, 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,
x1 + 4 * (x2 - x1) / 5, y1,
x1 + 4 * (x2 - x1) / 5, y2);
gimp_draw_tool_add_line (draw_tool,
x1 + (x2 - x1) / 5, y1,
x1 + (x2 - x1) / 5, y2);
gimp_draw_tool_add_line (draw_tool,
x1 + 2 * (x2 - x1) / 5, y1,
x1 + 2 * (x2 - x1) / 5, y2);
gimp_draw_tool_add_line (draw_tool,
x1 + 3 * (x2 - x1) / 5, y1,
x1 + 3 * (x2 - x1) / 5, y2);
gimp_draw_tool_add_line (draw_tool,
x1 + 4 * (x2 - x1) / 5, y1,
x1 + 4 * (x2 - x1) / 5, y2);
break;
case GIMP_RECTANGLE_GUIDE_GOLDEN:
item = gimp_draw_tool_add_line (draw_tool,
x1,
(2 * y1 + (1 + SQRT5) * y2) / (3 + SQRT5),
x2,
(2 * y1 + (1 + SQRT5) * y2) / (3 + SQRT5));
gimp_canvas_group_add_item (stroke_group, item);
gimp_draw_tool_remove_item (draw_tool, item);
gimp_draw_tool_add_line (draw_tool,
x1,
(2 * y1 + (1 + SQRT5) * y2) / (3 + SQRT5),
x2,
(2 * y1 + (1 + SQRT5) * y2) / (3 + SQRT5));
gimp_draw_tool_add_line (draw_tool,
x1,
((1 + SQRT5) * y1 + 2 * y2) / (3 + SQRT5),
x2,
((1 + SQRT5) * y1 + 2 * y2) / (3 + SQRT5));
item = gimp_draw_tool_add_line (draw_tool,
x1,
((1 + SQRT5) * y1 + 2 * y2) / (3 + SQRT5),
x2,
((1 + SQRT5) * y1 + 2 * y2) / (3 + SQRT5));
gimp_canvas_group_add_item (stroke_group, item);
gimp_draw_tool_remove_item (draw_tool, item);
item = gimp_draw_tool_add_line (draw_tool,
(2 * x1 + (1 + SQRT5) * x2) / (3 + SQRT5),
y1,
(2 * x1 + (1 + SQRT5) * x2) / (3 + SQRT5),
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,
((1 + SQRT5) * x1 + 2 * x2) / (3 + SQRT5),
y1,
((1 + SQRT5) * x1 + 2 * x2) / (3 + SQRT5),
y2);
gimp_canvas_group_add_item (stroke_group, item);
gimp_draw_tool_remove_item (draw_tool, item);
gimp_draw_tool_add_line (draw_tool,
(2 * x1 + (1 + SQRT5) * x2) / (3 + SQRT5),
y1,
(2 * x1 + (1 + SQRT5) * x2) / (3 + SQRT5),
y2);
gimp_draw_tool_add_line (draw_tool,
((1 + SQRT5) * x1 + 2 * x2) / (3 + SQRT5),
y1,
((1 + SQRT5) * x1 + 2 * x2) / (3 + SQRT5),
y2);
break;
/* This code implements the method of diagonals discovered by
@ -2015,38 +1966,24 @@ gimp_rectangle_tool_draw_guides (GimpDrawTool *draw_tool,
const gdouble square_side = MIN (x2 - x1, y2 - y1);
/* diagonal from the top-left edge */
item = gimp_draw_tool_add_line (draw_tool,
x1, y1,
x1 + square_side, y1 + square_side);
gimp_canvas_group_add_item (stroke_group, item);
gimp_draw_tool_remove_item (draw_tool, item);
gimp_draw_tool_add_line (draw_tool,
x1, y1,
x1 + square_side, y1 + square_side);
/* diagonal from the top-right edge */
item = gimp_draw_tool_add_line (draw_tool,
x2, y1,
x2 - square_side, y1 + square_side);
gimp_canvas_group_add_item (stroke_group, item);
gimp_draw_tool_remove_item (draw_tool, item);
gimp_draw_tool_add_line (draw_tool,
x2, y1,
x2 - square_side, y1 + square_side);
/* If user selected a square, we cannot draw from bottom points
* as we would erase the guides drawn from the top points
*/
if ((x1 + square_side != x2) || (y1 + square_side != y2))
{
/* diagonal from the bottom-left edge */
item = gimp_draw_tool_add_line (draw_tool,
x1, y2,
x1 + square_side, y2 - square_side);
gimp_canvas_group_add_item (stroke_group, item);
gimp_draw_tool_remove_item (draw_tool, item);
/* diagonal from the bottom-left edge */
gimp_draw_tool_add_line (draw_tool,
x1, y2,
x1 + square_side, y2 - square_side);
/* diagonal from the bottom-right edge */
item = gimp_draw_tool_add_line (draw_tool,
x2, y2,
x2 - square_side, y2 - square_side);
gimp_canvas_group_add_item (stroke_group, item);
gimp_draw_tool_remove_item (draw_tool, item);
}
/* diagonal from the bottom-right edge */
gimp_draw_tool_add_line (draw_tool,
x2, y2,
x2 - square_side, y2 - square_side);
}
break;
}

View File

@ -120,7 +120,8 @@ void gimp_rectangle_tool_cursor_update (GimpTool *to
const GimpCoords *coords,
GdkModifierType state,
GimpDisplay *display);
void gimp_rectangle_tool_draw (GimpDrawTool *draw);
void gimp_rectangle_tool_draw (GimpDrawTool *draw,
GimpCanvasGroup *stroke_group);
gboolean gimp_rectangle_tool_execute (GimpRectangleTool *rect_tool);
void gimp_rectangle_tool_cancel (GimpRectangleTool *rect_tool);
void gimp_rectangle_tool_set_constraint (GimpRectangleTool *rectangle,

View File

@ -783,7 +783,7 @@ gimp_text_tool_draw (GimpDrawTool *draw_tool)
"narrow-mode", TRUE,
NULL);
gimp_rectangle_tool_draw (draw_tool);
gimp_rectangle_tool_draw (draw_tool, NULL);
if (! text_tool->text ||
! text_tool->layer ||
@ -823,7 +823,7 @@ gimp_text_tool_draw_selection (GimpDrawTool *draw_tool)
{
GimpTextTool *text_tool = GIMP_TEXT_TOOL (draw_tool);
GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer);
GimpCanvasItem *fill_group;
GimpCanvasGroup *fill_group;
PangoLayout *layout;
gint offset_x;
gint offset_y;
@ -850,6 +850,8 @@ gimp_text_tool_draw_selection (GimpDrawTool *draw_tool)
iter = pango_layout_get_iter (layout);
gimp_draw_tool_push_group (draw_tool, fill_group);
do
{
if (! pango_layout_iter_get_run (iter))
@ -859,9 +861,8 @@ gimp_text_tool_draw_selection (GimpDrawTool *draw_tool)
if (i >= min && i < max)
{
GimpCanvasItem *item;
PangoRectangle rect;
gint ytop, ybottom;
PangoRectangle rect;
gint ytop, ybottom;
pango_layout_iter_get_char_extents (iter, &rect);
pango_layout_iter_get_line_yrange (iter, &ytop, &ybottom);
@ -876,16 +877,15 @@ gimp_text_tool_draw_selection (GimpDrawTool *draw_tool)
rect.x += offset_x;
rect.y += offset_y;
item = gimp_draw_tool_add_rectangle (draw_tool, TRUE,
rect.x, rect.y,
rect.width, rect.height);
gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (fill_group), item);
gimp_draw_tool_remove_item (draw_tool, item);
gimp_draw_tool_add_rectangle (draw_tool, TRUE,
rect.x, rect.y,
rect.width, rect.height);
}
}
while (pango_layout_iter_next_char (iter));
gimp_draw_tool_pop_group (draw_tool);
pango_layout_iter_free (iter);
}

View File

@ -781,14 +781,16 @@ gimp_transform_tool_draw (GimpDrawTool *draw_tool)
GimpTool *tool = GIMP_TOOL (draw_tool);
GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (draw_tool);
GimpImage *image = gimp_display_get_image (tool->display);
GimpCanvasItem *stroke_group;
GimpCanvasItem *item;
gdouble z1, z2, z3, z4;
stroke_group = gimp_draw_tool_add_stroke_group (draw_tool);
if (tr_tool->use_grid)
{
GimpCanvasGroup *stroke_group;
stroke_group = gimp_draw_tool_add_stroke_group (draw_tool);
gimp_draw_tool_push_group (draw_tool, stroke_group);
/* We test if the transformed polygon is convex.
* if z1 and z2 have the same sign as well as z3 and z4
* the polygon is convex.
@ -814,41 +816,29 @@ gimp_transform_tool_draw (GimpDrawTool *draw_tool)
for (i = 0, gci = 0; i < k; i++, gci += 4)
{
item = gimp_draw_tool_add_line (draw_tool,
tr_tool->tgrid_coords[gci],
tr_tool->tgrid_coords[gci + 1],
tr_tool->tgrid_coords[gci + 2],
tr_tool->tgrid_coords[gci + 3]);
gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (stroke_group), item);
gimp_draw_tool_remove_item (draw_tool, item);
gimp_draw_tool_add_line (draw_tool,
tr_tool->tgrid_coords[gci],
tr_tool->tgrid_coords[gci + 1],
tr_tool->tgrid_coords[gci + 2],
tr_tool->tgrid_coords[gci + 3]);
}
}
/* draw the bounding box */
item = gimp_draw_tool_add_line (draw_tool,
tr_tool->tx1, tr_tool->ty1,
tr_tool->tx2, tr_tool->ty2);
gimp_canvas_group_add_item (GIMP_CANVAS_GROUP (stroke_group), item);
gimp_draw_tool_remove_item (draw_tool, item);
gimp_draw_tool_add_line (draw_tool,
tr_tool->tx1, tr_tool->ty1,
tr_tool->tx2, tr_tool->ty2);
gimp_draw_tool_add_line (draw_tool,
tr_tool->tx2, tr_tool->ty2,
tr_tool->tx4, tr_tool->ty4);
gimp_draw_tool_add_line (draw_tool,
tr_tool->tx3, tr_tool->ty3,
tr_tool->tx4, tr_tool->ty4);
gimp_draw_tool_add_line (draw_tool,
tr_tool->tx3, tr_tool->ty3,
tr_tool->tx1, tr_tool->ty1);
item = gimp_draw_tool_add_line (draw_tool,
tr_tool->tx2, tr_tool->ty2,
tr_tool->tx4, tr_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,
tr_tool->tx3, tr_tool->ty3,
tr_tool->tx4, tr_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,
tr_tool->tx3, tr_tool->ty3,
tr_tool->tx1, tr_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);
}
gimp_transform_tool_handles_recalc (tr_tool, tool->display);