app: fix GimpSourceTool's source position drawing for other displays

by adding the source outline's canvas item to the source display
directly. Poking in GimpDrawTool internals is gone and generally not
possible any longer since GimpCanvasItem based drawing.
This commit is contained in:
Michael Natterer 2011-05-04 23:25:55 +02:00
parent c4097d4ff4
commit 91550117c7
4 changed files with 133 additions and 52 deletions

View File

@ -37,6 +37,8 @@
#include "paint/gimpbrushcore.h"
#include "paint/gimppaintoptions.h"
#include "display/gimpcanvashandle.h"
#include "display/gimpcanvaspath.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
@ -277,25 +279,34 @@ gimp_brush_tool_options_notify (GimpTool *tool,
static void
gimp_brush_tool_draw (GimpDrawTool *draw_tool)
{
GimpBrushTool *brush_tool = GIMP_BRUSH_TOOL (draw_tool);
GimpBrushTool *brush_tool = GIMP_BRUSH_TOOL (draw_tool);
GimpCanvasItem *item;
GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool);
if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (draw_tool)))
return;
gimp_brush_tool_draw_brush (brush_tool,
brush_tool->brush_x, brush_tool->brush_y,
! brush_tool->show_cursor);
item = gimp_brush_tool_create_outline (brush_tool,
draw_tool->display,
brush_tool->brush_x,
brush_tool->brush_y,
! brush_tool->show_cursor);
if (item)
{
gimp_draw_tool_add_item (draw_tool, item);
g_object_unref (item);
}
}
void
gimp_brush_tool_draw_brush (GimpBrushTool *brush_tool,
gdouble x,
gdouble y,
gboolean draw_fallback)
GimpCanvasItem *
gimp_brush_tool_create_outline (GimpBrushTool *brush_tool,
GimpDisplay *display,
gdouble x,
gdouble y,
gboolean draw_fallback)
{
GimpDrawTool *draw_tool;
GimpBrushCore *brush_core;
GimpPaintOptions *options;
GimpDisplayShell *shell;
@ -303,18 +314,18 @@ gimp_brush_tool_draw_brush (GimpBrushTool *brush_tool,
gint width = 0;
gint height = 0;
g_return_if_fail (GIMP_IS_BRUSH_TOOL (brush_tool));
g_return_val_if_fail (GIMP_IS_BRUSH_TOOL (brush_tool), NULL);
g_return_val_if_fail (GIMP_IS_DISPLAY (display), NULL);
if (! brush_tool->draw_brush)
return;
return NULL;
draw_tool = GIMP_DRAW_TOOL (brush_tool);
brush_core = GIMP_BRUSH_CORE (GIMP_PAINT_TOOL (brush_tool)->core);
options = GIMP_PAINT_TOOL_GET_OPTIONS (brush_tool);
shell = gimp_display_get_shell (draw_tool->display);
shell = gimp_display_get_shell (display);
if (! brush_core->main_brush || ! brush_core->dynamics)
return;
return NULL;
if (brush_core->scale > 0.0)
boundary = gimp_brush_transform_boundary (brush_core->main_brush,
@ -345,14 +356,19 @@ gimp_brush_tool_draw_brush (GimpBrushTool *brush_tool,
#undef EPSILON
}
gimp_draw_tool_add_path (draw_tool, boundary, x, y);
return gimp_canvas_path_new (shell, boundary, x, y, FALSE, FALSE);
}
else if (draw_fallback)
{
gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_CROSS,
x, y,
5, 5, GIMP_HANDLE_ANCHOR_CENTER);
return gimp_canvas_handle_new (shell,
GIMP_HANDLE_CROSS,
GIMP_HANDLE_ANCHOR_CENTER,
x, y,
GIMP_TOOL_HANDLE_SIZE_SMALL,
GIMP_TOOL_HANDLE_SIZE_SMALL);
}
return NULL;
}
static void

View File

@ -48,12 +48,13 @@ struct _GimpBrushToolClass
};
GType gimp_brush_tool_get_type (void) G_GNUC_CONST;
GType gimp_brush_tool_get_type (void) G_GNUC_CONST;
void gimp_brush_tool_draw_brush (GimpBrushTool *brush_tool,
gdouble x,
gdouble y,
gboolean draw_fallback);
GimpCanvasItem * gimp_brush_tool_create_outline (GimpBrushTool *brush_tool,
GimpDisplay *display,
gdouble x,
gdouble y,
gboolean draw_fallback);
#endif /* __GIMP_BRUSH_TOOL_H__ */

View File

@ -31,7 +31,9 @@
#include "widgets/gimpwidgets-utils.h"
#include "display/gimpcanvashandle.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell-items.h"
#include "gimpsourcetool.h"
#include "gimptoolcontrol.h"
@ -74,6 +76,9 @@ static void gimp_source_tool_oper_update (GimpTool *tool,
static void gimp_source_tool_draw (GimpDrawTool *draw_tool);
static void gimp_source_tool_set_src_display (GimpSourceTool *source_tool,
GimpDisplay *display);
G_DEFINE_TYPE (GimpSourceTool, gimp_source_tool, GIMP_TYPE_BRUSH_TOOL)
@ -150,7 +155,7 @@ gimp_source_tool_control (GimpTool *tool,
break;
case GIMP_TOOL_ACTION_HALT:
source_tool->src_display = NULL;
gimp_source_tool_set_src_display (source_tool, NULL);
g_object_set (GIMP_PAINT_TOOL (tool)->core,
"src-drawable", NULL,
NULL);
@ -178,7 +183,7 @@ gimp_source_tool_button_press (GimpTool *tool,
{
source->set_source = TRUE;
source_tool->src_display = display;
gimp_source_tool_set_src_display (source_tool, display);
}
else
{
@ -360,32 +365,88 @@ gimp_source_tool_draw (GimpDrawTool *draw_tool)
source = GIMP_SOURCE_CORE (GIMP_PAINT_TOOL (draw_tool)->core);
GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool);
if (options->use_source && source->src_drawable && source_tool->src_display)
{
GimpDisplay *tmp_display = draw_tool->display;
gint off_x;
gint off_y;
GimpDisplayShell *src_shell;
gint off_x;
gint off_y;
draw_tool->display = source_tool->src_display;
src_shell = gimp_display_get_shell (source_tool->src_display);
gimp_item_get_offset (GIMP_ITEM (source->src_drawable), &off_x, &off_y);
if (source_tool->src_outline)
{
gimp_display_shell_remove_item (src_shell,
source_tool->src_outline);
source_tool->src_outline = NULL;
}
if (source_tool->show_source_outline)
gimp_brush_tool_draw_brush (GIMP_BRUSH_TOOL (source_tool),
{
source_tool->src_outline =
gimp_brush_tool_create_outline (GIMP_BRUSH_TOOL (source_tool),
source_tool->src_display,
source_tool->src_x + off_x,
source_tool->src_y + off_y,
FALSE);
gimp_display_shell_add_item (src_shell,
source_tool->src_outline);
g_object_unref (source_tool->src_outline);
}
if (! source_tool->src_handle)
{
source_tool->src_handle =
gimp_canvas_handle_new (src_shell,
GIMP_HANDLE_CROSS,
GIMP_HANDLE_ANCHOR_CENTER,
source_tool->src_x + off_x,
source_tool->src_y + off_y,
FALSE);
gimp_draw_tool_add_handle (draw_tool,
GIMP_HANDLE_CROSS,
source_tool->src_x + off_x,
source_tool->src_y + off_y,
GIMP_TOOL_HANDLE_SIZE_CROSS,
GIMP_TOOL_HANDLE_SIZE_CROSS,
GIMP_HANDLE_ANCHOR_CENTER);
draw_tool->display = tmp_display;
GIMP_TOOL_HANDLE_SIZE_CROSS,
GIMP_TOOL_HANDLE_SIZE_CROSS);
gimp_display_shell_add_item (src_shell,
source_tool->src_handle);
g_object_unref (source_tool->src_handle);
}
else
{
gimp_canvas_handle_set_position (source_tool->src_handle,
source_tool->src_x + off_x,
source_tool->src_y + off_y);
}
}
}
static void
gimp_source_tool_set_src_display (GimpSourceTool *source_tool,
GimpDisplay *display)
{
if (source_tool->src_display != display)
{
if (source_tool->src_display)
{
GimpDisplayShell *src_shell;
src_shell = gimp_display_get_shell (source_tool->src_display);
if (source_tool->src_handle)
{
gimp_display_shell_remove_item (src_shell,
source_tool->src_handle);
source_tool->src_handle = NULL;
}
if (source_tool->src_outline)
{
gimp_display_shell_remove_item (src_shell,
source_tool->src_outline);
source_tool->src_outline = NULL;
}
}
source_tool->src_display = display;
}
GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool);
}

View File

@ -37,17 +37,20 @@ typedef struct _GimpSourceToolClass GimpSourceToolClass;
struct _GimpSourceTool
{
GimpBrushTool parent_instance;
GimpBrushTool parent_instance;
GimpDisplay *src_display;
gint src_x;
gint src_y;
GimpDisplay *src_display;
gint src_x;
gint src_y;
gboolean show_source_outline;
gboolean show_source_outline;
const gchar *status_paint;
const gchar *status_set_source;
const gchar *status_set_source_ctrl;
GimpCanvasItem *src_handle;
GimpCanvasItem *src_outline;
const gchar *status_paint;
const gchar *status_set_source;
const gchar *status_set_source_ctrl;
};
struct _GimpSourceToolClass