mirror of https://github.com/GNOME/gimp.git
app: port GimpBlendTool to pause()/resume()-less drawing
Instead, keep around the created GimpCanvasItems, and update them when the blend coordiates change. Add setters to GipmCanvasLine and GimpCanvasHandle which take care of calling begin_change() and end_change() on the items around the change, so thes invalidate properly.
This commit is contained in:
parent
1c0fe73da4
commit
aa5d2f8082
|
@ -402,6 +402,23 @@ gimp_canvas_handle_new (GimpDisplayShell *shell,
|
|||
NULL);
|
||||
}
|
||||
|
||||
void
|
||||
gimp_canvas_handle_set_position (GimpCanvasHandle *handle,
|
||||
gdouble x,
|
||||
gdouble y)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_CANVAS_HANDLE (handle));
|
||||
|
||||
gimp_canvas_item_begin_change (GIMP_CANVAS_ITEM (handle));
|
||||
|
||||
g_object_set (handle,
|
||||
"x", x,
|
||||
"y", y,
|
||||
NULL);
|
||||
|
||||
gimp_canvas_item_end_change (GIMP_CANVAS_ITEM (handle));
|
||||
}
|
||||
|
||||
void
|
||||
gimp_canvas_handle_set_angles (GimpCanvasHandle *handle,
|
||||
gdouble start_angle,
|
||||
|
@ -409,8 +426,12 @@ gimp_canvas_handle_set_angles (GimpCanvasHandle *handle,
|
|||
{
|
||||
g_return_if_fail (GIMP_IS_CANVAS_HANDLE (handle));
|
||||
|
||||
gimp_canvas_item_begin_change (GIMP_CANVAS_ITEM (handle));
|
||||
|
||||
g_object_set (handle,
|
||||
"start-angle", start_angle,
|
||||
"slice-angle", slice_angle,
|
||||
NULL);
|
||||
|
||||
gimp_canvas_item_end_change (GIMP_CANVAS_ITEM (handle));
|
||||
}
|
||||
|
|
|
@ -47,18 +47,22 @@ struct _GimpCanvasHandleClass
|
|||
};
|
||||
|
||||
|
||||
GType gimp_canvas_handle_get_type (void) G_GNUC_CONST;
|
||||
GType gimp_canvas_handle_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GimpCanvasItem * gimp_canvas_handle_new (GimpDisplayShell *shell,
|
||||
GimpHandleType type,
|
||||
GimpHandleAnchor anchor,
|
||||
gdouble x,
|
||||
gdouble y,
|
||||
gint width,
|
||||
gint height);
|
||||
void gimp_canvas_handle_set_angles (GimpCanvasHandle *handle,
|
||||
gdouble start_handle,
|
||||
gdouble slice_handle);
|
||||
GimpCanvasItem * gimp_canvas_handle_new (GimpDisplayShell *shell,
|
||||
GimpHandleType type,
|
||||
GimpHandleAnchor anchor,
|
||||
gdouble x,
|
||||
gdouble y,
|
||||
gint width,
|
||||
gint height);
|
||||
|
||||
void gimp_canvas_handle_set_position (GimpCanvasHandle *handle,
|
||||
gdouble x,
|
||||
gdouble y);
|
||||
void gimp_canvas_handle_set_angles (GimpCanvasHandle *handle,
|
||||
gdouble start_handle,
|
||||
gdouble slice_handle);
|
||||
|
||||
|
||||
#endif /* __GIMP_CANVAS_HANDLE_H__ */
|
||||
|
|
|
@ -267,3 +267,24 @@ gimp_canvas_line_new (GimpDisplayShell *shell,
|
|||
"y2", y2,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void
|
||||
gimp_canvas_line_set (GimpCanvasLine *line,
|
||||
gdouble x1,
|
||||
gdouble y1,
|
||||
gdouble x2,
|
||||
gdouble y2)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_CANVAS_LINE (line));
|
||||
|
||||
gimp_canvas_item_begin_change (GIMP_CANVAS_ITEM (line));
|
||||
|
||||
g_object_set (line,
|
||||
"x1", x1,
|
||||
"y1", y1,
|
||||
"x2", x2,
|
||||
"y2", y2,
|
||||
NULL);
|
||||
|
||||
gimp_canvas_item_end_change (GIMP_CANVAS_ITEM (line));
|
||||
}
|
||||
|
|
|
@ -55,5 +55,11 @@ GimpCanvasItem * gimp_canvas_line_new (GimpDisplayShell *shell,
|
|||
gdouble x2,
|
||||
gdouble y2);
|
||||
|
||||
void gimp_canvas_line_set (GimpCanvasLine *line,
|
||||
gdouble x1,
|
||||
gdouble y1,
|
||||
gdouble x2,
|
||||
gdouble y2);
|
||||
|
||||
|
||||
#endif /* __GIMP_CANVAS_LINE_H__ */
|
||||
|
|
|
@ -37,6 +37,8 @@
|
|||
#include "widgets/gimphelp-ids.h"
|
||||
#include "widgets/gimpwidgets-utils.h"
|
||||
|
||||
#include "display/gimpcanvashandle.h"
|
||||
#include "display/gimpcanvasline.h"
|
||||
#include "display/gimpdisplay.h"
|
||||
|
||||
#include "gimpblendoptions.h"
|
||||
|
@ -79,6 +81,7 @@ static void gimp_blend_tool_cursor_update (GimpTool *tool,
|
|||
GimpDisplay *display);
|
||||
|
||||
static void gimp_blend_tool_draw (GimpDrawTool *draw_tool);
|
||||
static void gimp_blend_tool_update_items (GimpBlendTool *blend_tool);
|
||||
|
||||
static void gimp_blend_tool_push_status (GimpBlendTool *blend_tool,
|
||||
GdkModifierType state,
|
||||
|
@ -279,8 +282,6 @@ gimp_blend_tool_motion (GimpTool *tool,
|
|||
{
|
||||
GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool);
|
||||
|
||||
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
||||
|
||||
blend_tool->mouse_x = coords->x;
|
||||
blend_tool->mouse_y = coords->y;
|
||||
|
||||
|
@ -312,10 +313,10 @@ gimp_blend_tool_motion (GimpTool *tool,
|
|||
gimp_tool_pop_status (tool, display);
|
||||
gimp_blend_tool_push_status (blend_tool, state, display);
|
||||
|
||||
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
||||
|
||||
blend_tool->last_x = coords->x;
|
||||
blend_tool->last_y = coords->y;
|
||||
|
||||
gimp_blend_tool_update_items (blend_tool);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -329,8 +330,6 @@ gimp_blend_tool_active_modifier_key (GimpTool *tool,
|
|||
|
||||
if (key == GDK_CONTROL_MASK)
|
||||
{
|
||||
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
||||
|
||||
blend_tool->end_x = blend_tool->mouse_x;
|
||||
blend_tool->end_y = blend_tool->mouse_y;
|
||||
|
||||
|
@ -345,7 +344,7 @@ gimp_blend_tool_active_modifier_key (GimpTool *tool,
|
|||
gimp_tool_pop_status (tool, display);
|
||||
gimp_blend_tool_push_status (blend_tool, state, display);
|
||||
|
||||
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
||||
gimp_blend_tool_update_items (blend_tool);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -376,30 +375,49 @@ gimp_blend_tool_draw (GimpDrawTool *draw_tool)
|
|||
{
|
||||
GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (draw_tool);
|
||||
|
||||
/* Draw the line between the start and end coords */
|
||||
gimp_draw_tool_add_line (draw_tool,
|
||||
blend_tool->start_x,
|
||||
blend_tool->start_y,
|
||||
blend_tool->end_x,
|
||||
blend_tool->end_y);
|
||||
|
||||
/* Draw start target */
|
||||
gimp_draw_tool_add_handle (draw_tool,
|
||||
GIMP_HANDLE_CROSS,
|
||||
blend_tool->start_handle =
|
||||
gimp_draw_tool_add_handle (draw_tool,
|
||||
GIMP_HANDLE_CROSS,
|
||||
blend_tool->start_x,
|
||||
blend_tool->start_y,
|
||||
GIMP_TOOL_HANDLE_SIZE_CROSS,
|
||||
GIMP_TOOL_HANDLE_SIZE_CROSS,
|
||||
GIMP_HANDLE_ANCHOR_CENTER);
|
||||
|
||||
/* Draw the line between the start and end coords */
|
||||
blend_tool->line =
|
||||
gimp_draw_tool_add_line (draw_tool,
|
||||
blend_tool->start_x,
|
||||
blend_tool->start_y,
|
||||
GIMP_TOOL_HANDLE_SIZE_CROSS,
|
||||
GIMP_TOOL_HANDLE_SIZE_CROSS,
|
||||
GIMP_HANDLE_ANCHOR_CENTER);
|
||||
blend_tool->end_x,
|
||||
blend_tool->end_y);
|
||||
|
||||
/* Draw end target */
|
||||
gimp_draw_tool_add_handle (draw_tool,
|
||||
GIMP_HANDLE_CROSS,
|
||||
blend_tool->end_x,
|
||||
blend_tool->end_y,
|
||||
GIMP_TOOL_HANDLE_SIZE_CROSS,
|
||||
GIMP_TOOL_HANDLE_SIZE_CROSS,
|
||||
GIMP_HANDLE_ANCHOR_CENTER);
|
||||
blend_tool->end_handle =
|
||||
gimp_draw_tool_add_handle (draw_tool,
|
||||
GIMP_HANDLE_CROSS,
|
||||
blend_tool->end_x,
|
||||
blend_tool->end_y,
|
||||
GIMP_TOOL_HANDLE_SIZE_CROSS,
|
||||
GIMP_TOOL_HANDLE_SIZE_CROSS,
|
||||
GIMP_HANDLE_ANCHOR_CENTER);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_blend_tool_update_items (GimpBlendTool *blend_tool)
|
||||
{
|
||||
if (gimp_draw_tool_is_active (GIMP_DRAW_TOOL (blend_tool)))
|
||||
{
|
||||
gimp_canvas_line_set (GIMP_CANVAS_LINE (blend_tool->line),
|
||||
blend_tool->start_x,
|
||||
blend_tool->start_y,
|
||||
blend_tool->end_x,
|
||||
blend_tool->end_y);
|
||||
gimp_canvas_handle_set_position (GIMP_CANVAS_HANDLE (blend_tool->end_handle),
|
||||
blend_tool->end_x,
|
||||
blend_tool->end_y);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -37,17 +37,21 @@ typedef struct _GimpBlendToolClass GimpBlendToolClass;
|
|||
|
||||
struct _GimpBlendTool
|
||||
{
|
||||
GimpDrawTool parent_instance;
|
||||
GimpDrawTool parent_instance;
|
||||
|
||||
gdouble start_x; /* starting x coord */
|
||||
gdouble start_y; /* starting y coord */
|
||||
gdouble end_x; /* ending x coord */
|
||||
gdouble end_y; /* ending y coord */
|
||||
gdouble start_x; /* starting x coord */
|
||||
gdouble start_y; /* starting y coord */
|
||||
gdouble end_x; /* ending x coord */
|
||||
gdouble end_y; /* ending y coord */
|
||||
|
||||
gdouble last_x; /* last x coord */
|
||||
gdouble last_y; /* last y coord */
|
||||
gdouble mouse_x; /* pointer x coord */
|
||||
gdouble mouse_y; /* pointer y coord */
|
||||
gdouble last_x; /* last x coord */
|
||||
gdouble last_y; /* last y coord */
|
||||
gdouble mouse_x; /* pointer x coord */
|
||||
gdouble mouse_y; /* pointer y coord */
|
||||
|
||||
GimpCanvasItem *start_handle;
|
||||
GimpCanvasItem *line;
|
||||
GimpCanvasItem *end_handle;
|
||||
};
|
||||
|
||||
struct _GimpBlendToolClass
|
||||
|
|
Loading…
Reference in New Issue