static void gimp_perspective_clone_tool_modifier_key (GimpTool *tool, GdkModifierType key, gboolean press, GdkModifierType state, GimpDisplay *display) { GimpPerspectiveCloneTool *clone_tool = GIMP_PERSPECTIVE_CLONE_TOOL (tool); GimpPerspectiveCloneOptions *options; options = GIMP_PERSPECTIVE_CLONE_TOOL_GET_OPTIONS (tool); if (options->clone_mode == GIMP_PERSPECTIVE_CLONE_MODE_PAINT && key == gimp_get_toggle_behavior_mask ()) { if (press) { clone_tool->saved_precision = gimp_tool_control_get_precision (tool->control); gimp_tool_control_set_precision (tool->control, GIMP_CURSOR_PRECISION_PIXEL_CENTER); } else { gimp_tool_control_set_precision (tool->control, clone_tool->saved_precision); } } GIMP_TOOL_CLASS (parent_class)->modifier_key (tool, key, press, state, display); }
static void gimp_perspective_clone_tool_button_release (GimpTool *tool, const GimpCoords *coords, guint32 time, GdkModifierType state, GimpButtonReleaseType release_type, GimpDisplay *display) { GimpPerspectiveCloneTool *clone_tool = GIMP_PERSPECTIVE_CLONE_TOOL (tool); GimpPerspectiveCloneOptions *options; options = GIMP_PERSPECTIVE_CLONE_TOOL_GET_OPTIONS (tool); switch (options->clone_mode) { case GIMP_PERSPECTIVE_CLONE_MODE_ADJUST: gimp_tool_control_halt (tool->control); if (clone_tool->grab_widget) { gimp_tool_widget_button_release (clone_tool->grab_widget, coords, time, state, release_type); clone_tool->grab_widget = NULL; } break; case GIMP_PERSPECTIVE_CLONE_MODE_PAINT: GIMP_TOOL_CLASS (parent_class)->button_release (tool, coords, time, state, release_type, display); break; } }
static void gimp_perspective_clone_tool_constructed (GObject *object) { GimpPerspectiveCloneOptions *options; options = GIMP_PERSPECTIVE_CLONE_TOOL_GET_OPTIONS (object); G_OBJECT_CLASS (parent_class)->constructed (object); if (options->clone_mode == GIMP_PERSPECTIVE_CLONE_MODE_ADJUST) gimp_paint_tool_set_active (GIMP_PAINT_TOOL (object), FALSE); }
static void gimp_perspective_clone_tool_constructed (GObject *object) { GimpTool *tool = GIMP_TOOL (object); GimpPerspectiveCloneTool *clone_tool = GIMP_PERSPECTIVE_CLONE_TOOL (object); GimpPerspectiveCloneOptions *options; G_OBJECT_CLASS (parent_class)->constructed (object); options = GIMP_PERSPECTIVE_CLONE_TOOL_GET_OPTIONS (tool); g_signal_connect_object (options, "notify::clone-mode", G_CALLBACK (gimp_perspective_clone_tool_mode_notify), clone_tool, 0); gimp_perspective_clone_tool_mode_notify (options, NULL, clone_tool); }
static void gimp_perspective_clone_tool_motion (GimpTool *tool, const GimpCoords *coords, guint32 time, GdkModifierType state, GimpDisplay *display) { GimpPerspectiveCloneTool *clone_tool = GIMP_PERSPECTIVE_CLONE_TOOL (tool); GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool); GimpPerspectiveClone *clone = GIMP_PERSPECTIVE_CLONE (paint_tool->core); GimpPerspectiveCloneOptions *options; options = GIMP_PERSPECTIVE_CLONE_TOOL_GET_OPTIONS (tool); if (options->clone_mode == GIMP_PERSPECTIVE_CLONE_MODE_ADJUST) { if (clone_tool->grab_widget) { gimp_tool_widget_motion (clone_tool->grab_widget, coords, time, state); } } else if (options->clone_mode == GIMP_PERSPECTIVE_CLONE_MODE_PAINT) { gdouble nnx, nny; gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool)); GIMP_TOOL_CLASS (parent_class)->motion (tool, coords, time, state, display); /* Set the coordinates for the reference cross */ gimp_perspective_clone_get_source_point (clone, coords->x, coords->y, &nnx, &nny); clone_tool->src_x = floor (nnx); clone_tool->src_y = floor (nny); gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool)); } }
static void gimp_perspective_clone_tool_draw (GimpDrawTool *draw_tool) { GimpTool *tool = GIMP_TOOL (draw_tool); GimpPerspectiveCloneTool *clone_tool = GIMP_PERSPECTIVE_CLONE_TOOL (draw_tool); GimpPerspectiveClone *clone = GIMP_PERSPECTIVE_CLONE (GIMP_PAINT_TOOL (tool)->core); GimpSourceCore *source_core = GIMP_SOURCE_CORE (clone); GimpPerspectiveCloneOptions *options; GimpCanvasGroup *stroke_group; options = GIMP_PERSPECTIVE_CLONE_TOOL_GET_OPTIONS (tool); stroke_group = gimp_draw_tool_add_stroke_group (draw_tool); /* draw the bounding box */ 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_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); gimp_draw_tool_pop_group (draw_tool); /* draw the tool handles only when they can be used */ if (options->clone_mode == GIMP_PERSPECTIVE_CLONE_MODE_ADJUST) { gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_SQUARE, clone_tool->tx1, clone_tool->ty1, GIMP_TOOL_HANDLE_SIZE_LARGE, GIMP_TOOL_HANDLE_SIZE_LARGE, GIMP_HANDLE_ANCHOR_CENTER); gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_SQUARE, clone_tool->tx2, clone_tool->ty2, GIMP_TOOL_HANDLE_SIZE_LARGE, GIMP_TOOL_HANDLE_SIZE_LARGE, GIMP_HANDLE_ANCHOR_CENTER); gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_SQUARE, clone_tool->tx3, clone_tool->ty3, GIMP_TOOL_HANDLE_SIZE_LARGE, GIMP_TOOL_HANDLE_SIZE_LARGE, GIMP_HANDLE_ANCHOR_CENTER); gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_SQUARE, clone_tool->tx4, clone_tool->ty4, GIMP_TOOL_HANDLE_SIZE_LARGE, GIMP_TOOL_HANDLE_SIZE_LARGE, GIMP_HANDLE_ANCHOR_CENTER); } if (source_core->src_drawable && clone_tool->src_display) { GimpDisplay *tmp_display; tmp_display = draw_tool->display; draw_tool->display = clone_tool->src_display; gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_CROSS, clone_tool->src_x, clone_tool->src_y, GIMP_TOOL_HANDLE_SIZE_CROSS, GIMP_TOOL_HANDLE_SIZE_CROSS, GIMP_HANDLE_ANCHOR_CENTER); draw_tool->display = tmp_display; } GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool); }
static void gimp_perspective_clone_tool_oper_update (GimpTool *tool, const GimpCoords *coords, GdkModifierType state, gboolean proximity, GimpDisplay *display) { GimpPerspectiveCloneTool *clone_tool = GIMP_PERSPECTIVE_CLONE_TOOL (tool); GimpPerspectiveCloneOptions *options; options = GIMP_PERSPECTIVE_CLONE_TOOL_GET_OPTIONS (tool); if (options->clone_mode == GIMP_PERSPECTIVE_CLONE_MODE_ADJUST) { GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool); gdouble closest_dist; gdouble dist; clone_tool->function = TRANSFORM_HANDLE_NONE; if (display != tool->display) return; dist = gimp_draw_tool_calc_distance_square (draw_tool, display, coords->x, coords->y, clone_tool->tx1, clone_tool->ty1); closest_dist = dist; clone_tool->function = TRANSFORM_HANDLE_NW; dist = gimp_draw_tool_calc_distance_square (draw_tool, display, coords->x, coords->y, clone_tool->tx2, clone_tool->ty2); if (dist < closest_dist) { closest_dist = dist; clone_tool->function = TRANSFORM_HANDLE_NE; } dist = gimp_draw_tool_calc_distance_square (draw_tool, display, coords->x, coords->y, clone_tool->tx3, clone_tool->ty3); if (dist < closest_dist) { closest_dist = dist; clone_tool->function = TRANSFORM_HANDLE_SW; } dist = gimp_draw_tool_calc_distance_square (draw_tool, display, coords->x, coords->y, clone_tool->tx4, clone_tool->ty4); if (dist < closest_dist) { closest_dist = dist; clone_tool->function = TRANSFORM_HANDLE_SE; } } else { GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state, proximity, display); if (proximity) { GimpPaintCore *core = GIMP_PAINT_TOOL (tool)->core; GimpPerspectiveClone *clone = GIMP_PERSPECTIVE_CLONE (core); GimpSourceCore *source_core = GIMP_SOURCE_CORE (core); if (source_core->src_drawable == NULL) { gimp_tool_replace_status (tool, display, _("Ctrl-Click to set a clone source")); } else { gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool)); clone_tool->src_x = source_core->src_x; clone_tool->src_y = source_core->src_y; if (! source_core->first_stroke) { if (GIMP_SOURCE_OPTIONS (options)->align_mode == GIMP_SOURCE_ALIGN_YES) { gdouble nnx, nny; /* Set the coordinates for the reference cross */ gimp_perspective_clone_get_source_point (clone, coords->x, coords->y, &nnx, &nny); clone_tool->src_x = nnx; clone_tool->src_y = nny; } } gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool)); } } } }
static void gimp_perspective_clone_tool_cursor_update (GimpTool *tool, const GimpCoords *coords, GdkModifierType state, GimpDisplay *display) { GimpPerspectiveCloneTool *clone_tool = GIMP_PERSPECTIVE_CLONE_TOOL (tool); GimpPerspectiveCloneOptions *options; GimpImage *image; GimpToolClass *tool_class; GimpCursorType cursor = GIMP_CURSOR_MOUSE; GimpCursorModifier modifier = GIMP_CURSOR_MODIFIER_NONE; options = GIMP_PERSPECTIVE_CLONE_TOOL_GET_OPTIONS (tool); image = gimp_display_get_image (display); if (gimp_image_coords_in_active_pickable (image, coords, FALSE, TRUE)) { cursor = GIMP_CURSOR_MOUSE; } if (options->clone_mode == GIMP_PERSPECTIVE_CLONE_MODE_ADJUST) { /* perspective cursors */ cursor = gimp_tool_control_get_cursor (tool->control); switch (clone_tool->function) { case TRANSFORM_HANDLE_NW: cursor = GIMP_CURSOR_CORNER_TOP_LEFT; break; case TRANSFORM_HANDLE_NE: cursor = GIMP_CURSOR_CORNER_TOP_RIGHT; break; case TRANSFORM_HANDLE_SW: cursor = GIMP_CURSOR_CORNER_BOTTOM_LEFT; break; case TRANSFORM_HANDLE_SE: cursor = GIMP_CURSOR_CORNER_BOTTOM_RIGHT; break; default: cursor = GIMP_CURSOR_CROSSHAIR_SMALL; break; } } else { GdkModifierType extend_mask = gimp_get_extend_selection_mask (); GdkModifierType toggle_mask = gimp_get_toggle_behavior_mask (); if ((state & (toggle_mask | extend_mask)) == toggle_mask) { cursor = GIMP_CURSOR_CROSSHAIR_SMALL; } else if (! GIMP_SOURCE_CORE (GIMP_PAINT_TOOL (tool)->core)->src_drawable) { modifier = GIMP_CURSOR_MODIFIER_BAD; } } gimp_tool_control_set_cursor (tool->control, cursor); gimp_tool_control_set_cursor_modifier (tool->control, modifier); /* If we are in adjust mode, skip the GimpBrushClass when chaining up. * This ensures that the cursor will be set regardless of * GimpBrushTool::show_cursor (see bug #354933). */ if (options->clone_mode == GIMP_PERSPECTIVE_CLONE_MODE_ADJUST) tool_class = GIMP_TOOL_CLASS (g_type_class_peek_parent (parent_class)); else tool_class = GIMP_TOOL_CLASS (parent_class); tool_class->cursor_update (tool, coords, state, display); }
static void gimp_perspective_clone_tool_motion (GimpTool *tool, const GimpCoords *coords, guint32 time, GdkModifierType state, GimpDisplay *display) { GimpPerspectiveCloneTool *clone_tool = GIMP_PERSPECTIVE_CLONE_TOOL (tool); GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool); GimpPerspectiveClone *clone = GIMP_PERSPECTIVE_CLONE (paint_tool->core); GimpPerspectiveCloneOptions *options; options = GIMP_PERSPECTIVE_CLONE_TOOL_GET_OPTIONS (tool); if (options->clone_mode == GIMP_PERSPECTIVE_CLONE_MODE_ADJUST) { gdouble diff_x, diff_y; /* if we are creating, there is nothing to be done so exit. */ if (clone_tool->function == TRANSFORM_CREATING) return; gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool)); clone_tool->curx = coords->x; clone_tool->cury = coords->y; /* recalculate the tool's transformation matrix */ diff_x = clone_tool->curx - clone_tool->lastx; diff_y = clone_tool->cury - clone_tool->lasty; switch (clone_tool->function) { case TRANSFORM_HANDLE_NW: clone_tool->trans_info[X0] += diff_x; clone_tool->trans_info[Y0] += diff_y; break; case TRANSFORM_HANDLE_NE: clone_tool->trans_info[X1] += diff_x; clone_tool->trans_info[Y1] += diff_y; break; case TRANSFORM_HANDLE_SW: clone_tool->trans_info[X2] += diff_x; clone_tool->trans_info[Y2] += diff_y; break; case TRANSFORM_HANDLE_SE: clone_tool->trans_info[X3] += diff_x; clone_tool->trans_info[Y3] += diff_y; break; default: break; } gimp_perspective_clone_tool_recalc_matrix (clone_tool); clone_tool->lastx = clone_tool->curx; clone_tool->lasty = clone_tool->cury; gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool)); } else if (options->clone_mode == GIMP_PERSPECTIVE_CLONE_MODE_PAINT) { gdouble nnx, nny; gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool)); GIMP_TOOL_CLASS (parent_class)->motion (tool, coords, time, state, display); /* Set the coordinates for the reference cross */ gimp_perspective_clone_get_source_point (clone, coords->x, coords->y, &nnx, &nny); clone_tool->src_x = nnx; clone_tool->src_y = nny; gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool)); } }
static void gimp_perspective_clone_tool_button_press (GimpTool *tool, const GimpCoords *coords, guint32 time, GdkModifierType state, GimpButtonPressType press_type, GimpDisplay *display) { GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool); GimpPerspectiveCloneTool *clone_tool = GIMP_PERSPECTIVE_CLONE_TOOL (tool); GimpPerspectiveClone *clone = GIMP_PERSPECTIVE_CLONE (paint_tool->core); GimpSourceCore *source_core = GIMP_SOURCE_CORE (clone); GimpPerspectiveCloneOptions *options; options = GIMP_PERSPECTIVE_CLONE_TOOL_GET_OPTIONS (tool); switch (options->clone_mode) { case GIMP_PERSPECTIVE_CLONE_MODE_ADJUST: if (clone_tool->function == TRANSFORM_CREATING) gimp_perspective_clone_tool_oper_update (tool, coords, state, TRUE, display); clone_tool->lastx = coords->x; clone_tool->lasty = coords->y; gimp_tool_control_activate (tool->control); break; case GIMP_PERSPECTIVE_CLONE_MODE_PAINT: { GdkModifierType extend_mask = gimp_get_extend_selection_mask (); GdkModifierType toggle_mask = gimp_get_toggle_behavior_mask (); gdouble nnx, nny; gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool)); if ((state & (toggle_mask | extend_mask)) == toggle_mask) { source_core->set_source = TRUE; clone_tool->src_display = display; } else { source_core->set_source = FALSE; } GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state, press_type, display); /* Set the coordinates for the reference cross */ gimp_perspective_clone_get_source_point (clone, coords->x, coords->y, &nnx, &nny); clone_tool->src_x = nnx; clone_tool->src_y = nny; gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool)); } break; } }
static void gimp_perspective_clone_tool_draw (GimpDrawTool *draw_tool) { GimpTool *tool = GIMP_TOOL (draw_tool); GimpPerspectiveCloneTool *clone_tool = GIMP_PERSPECTIVE_CLONE_TOOL (draw_tool); GimpPerspectiveClone *clone = GIMP_PERSPECTIVE_CLONE (GIMP_PAINT_TOOL (tool)->core); GimpSourceCore *source_core = GIMP_SOURCE_CORE (clone); GimpPerspectiveCloneOptions *options; options = GIMP_PERSPECTIVE_CLONE_TOOL_GET_OPTIONS (tool); if (options->clone_mode == GIMP_PERSPECTIVE_CLONE_MODE_ADJUST) { if (clone_tool->widget) { GimpCanvasItem *item = gimp_tool_widget_get_item (clone_tool->widget); gimp_draw_tool_add_item (draw_tool, item); } } else { GimpCanvasGroup *stroke_group; stroke_group = gimp_draw_tool_add_stroke_group (draw_tool); /* draw the bounding box */ gimp_draw_tool_push_group (draw_tool, stroke_group); gimp_draw_tool_add_line (draw_tool, clone_tool->trans_info[X0], clone_tool->trans_info[Y0], clone_tool->trans_info[X1], clone_tool->trans_info[Y1]); gimp_draw_tool_add_line (draw_tool, clone_tool->trans_info[X1], clone_tool->trans_info[Y1], clone_tool->trans_info[X3], clone_tool->trans_info[Y3]); gimp_draw_tool_add_line (draw_tool, clone_tool->trans_info[X2], clone_tool->trans_info[Y2], clone_tool->trans_info[X3], clone_tool->trans_info[Y3]); gimp_draw_tool_add_line (draw_tool, clone_tool->trans_info[X2], clone_tool->trans_info[Y2], clone_tool->trans_info[X0], clone_tool->trans_info[Y0]); gimp_draw_tool_pop_group (draw_tool); } if (source_core->src_drawable && clone_tool->src_display) { GimpDisplay *tmp_display; tmp_display = draw_tool->display; draw_tool->display = clone_tool->src_display; gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_CROSS, clone_tool->src_x + 0.5, clone_tool->src_y + 0.5, GIMP_TOOL_HANDLE_SIZE_CROSS, GIMP_TOOL_HANDLE_SIZE_CROSS, GIMP_HANDLE_ANCHOR_CENTER); draw_tool->display = tmp_display; } GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool); }
static void gimp_perspective_clone_tool_oper_update (GimpTool *tool, const GimpCoords *coords, GdkModifierType state, gboolean proximity, GimpDisplay *display) { GimpPerspectiveCloneTool *clone_tool = GIMP_PERSPECTIVE_CLONE_TOOL (tool); GimpPerspectiveCloneOptions *options; options = GIMP_PERSPECTIVE_CLONE_TOOL_GET_OPTIONS (tool); if (options->clone_mode == GIMP_PERSPECTIVE_CLONE_MODE_ADJUST) { if (clone_tool->widget) { if (display == tool->display) { gimp_tool_widget_hover (clone_tool->widget, coords, state, proximity); } } } else { GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state, proximity, display); if (proximity) { GimpPaintCore *core = GIMP_PAINT_TOOL (tool)->core; GimpPerspectiveClone *clone = GIMP_PERSPECTIVE_CLONE (core); GimpSourceCore *source_core = GIMP_SOURCE_CORE (core); if (source_core->src_drawable == NULL) { gimp_tool_replace_status (tool, display, _("Ctrl-Click to set a clone source")); } else { gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool)); clone_tool->src_x = source_core->src_x; clone_tool->src_y = source_core->src_y; if (! source_core->first_stroke) { if (GIMP_SOURCE_OPTIONS (options)->align_mode == GIMP_SOURCE_ALIGN_YES) { gdouble nnx, nny; /* Set the coordinates for the reference cross */ gimp_perspective_clone_get_source_point (clone, coords->x, coords->y, &nnx, &nny); clone_tool->src_x = floor (nnx); clone_tool->src_y = floor (nny); } } gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool)); } } } }
static void gimp_perspective_clone_tool_button_press (GimpTool *tool, const GimpCoords *coords, guint32 time, GdkModifierType state, GimpButtonPressType press_type, GimpDisplay *display) { GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool); GimpPerspectiveCloneTool *clone_tool = GIMP_PERSPECTIVE_CLONE_TOOL (tool); GimpPerspectiveClone *clone = GIMP_PERSPECTIVE_CLONE (paint_tool->core); GimpSourceCore *source_core = GIMP_SOURCE_CORE (clone); GimpPerspectiveCloneOptions *options; options = GIMP_PERSPECTIVE_CLONE_TOOL_GET_OPTIONS (tool); if (options->clone_mode == GIMP_PERSPECTIVE_CLONE_MODE_ADJUST) { if (clone_tool->widget) { gimp_tool_widget_hover (clone_tool->widget, coords, state, TRUE); if (gimp_tool_widget_button_press (clone_tool->widget, coords, time, state, press_type)) { clone_tool->grab_widget = clone_tool->widget; } } gimp_tool_control_activate (tool->control); } else { GdkModifierType extend_mask = gimp_get_extend_selection_mask (); GdkModifierType toggle_mask = gimp_get_toggle_behavior_mask (); gdouble nnx, nny; gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool)); if ((state & (toggle_mask | extend_mask)) == toggle_mask) { source_core->set_source = TRUE; clone_tool->src_display = display; } else { source_core->set_source = FALSE; } GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state, press_type, display); /* Set the coordinates for the reference cross */ gimp_perspective_clone_get_source_point (clone, coords->x, coords->y, &nnx, &nny); clone_tool->src_x = floor (nnx); clone_tool->src_y = floor (nny); gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool)); } }