static GimpBlendToolPoint gimp_blend_tool_get_point_under_cursor (GimpBlendTool *blend_tool) { GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (blend_tool); gdouble dist; if (!draw_tool->display) return POINT_NONE; /* Check the points in the reverse order of drawing */ /* Check end point */ dist = gimp_draw_tool_calc_distance_square (draw_tool, draw_tool->display, blend_tool->mouse_x, blend_tool->mouse_y, blend_tool->end_x, blend_tool->end_y); if (dist < POINT_GRAB_THRESHOLD_SQ) return POINT_END; /* Check start point */ dist = gimp_draw_tool_calc_distance_square (draw_tool, draw_tool->display, blend_tool->mouse_x, blend_tool->mouse_y, blend_tool->start_x, blend_tool->start_y); if (dist < POINT_GRAB_THRESHOLD_SQ) return POINT_START; /* No point found */ return POINT_NONE; }
static void gimp_blend_tool_update_item_hilight (GimpBlendTool *blend_tool) { GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (blend_tool); if (gimp_draw_tool_is_active (draw_tool)) { GimpBlendToolPoint hilight_point; gboolean start_visible, end_visible; /* Calculate handle visibility */ if (blend_tool->grabbed_point) { start_visible = FALSE; end_visible = FALSE; } else { gdouble dist; dist = gimp_draw_tool_calc_distance_square (draw_tool, draw_tool->display, blend_tool->mouse_x, blend_tool->mouse_y, blend_tool->start_x, blend_tool->start_y); start_visible = dist < FULL_HANDLE_THRESHOLD_SQ; dist = gimp_draw_tool_calc_distance_square (draw_tool, draw_tool->display, blend_tool->mouse_x, blend_tool->mouse_y, blend_tool->end_x, blend_tool->end_y); end_visible = dist < FULL_HANDLE_THRESHOLD_SQ; } gimp_canvas_item_set_visible (blend_tool->start_handle_circle, start_visible); gimp_canvas_item_set_visible (blend_tool->end_handle_circle, end_visible); /* Update hilights */ if (blend_tool->grabbed_point) hilight_point = blend_tool->grabbed_point; else hilight_point = gimp_blend_tool_get_point_under_cursor (blend_tool); gimp_canvas_item_set_highlight (blend_tool->start_handle_circle, hilight_point == POINT_START); gimp_canvas_item_set_highlight (blend_tool->start_handle_cross, hilight_point == POINT_START); gimp_canvas_item_set_highlight (blend_tool->end_handle_circle, hilight_point == POINT_END); gimp_canvas_item_set_highlight (blend_tool->end_handle_cross, hilight_point == POINT_END); } }
/** * gimp_draw_tool_calc_distance: * @draw_tool: a #GimpDrawTool * @display: a #GimpDisplay * @x1: start point X in image coordinates * @y1: start point Y in image coordinates * @x2: end point X in image coordinates * @y2: end point Y in image coordinates * * If you just need to compare distances, consider to use * gimp_draw_tool_calc_distance_square() instead. * * Returns: the distance between the given points in display coordinates **/ gdouble gimp_draw_tool_calc_distance (GimpDrawTool *draw_tool, GimpDisplay *display, gdouble x1, gdouble y1, gdouble x2, gdouble y2) { return sqrt (gimp_draw_tool_calc_distance_square (draw_tool, display, x1, y1, x2, y2)); }
static gint gimp_cage_tool_is_on_handle (GimpCageTool *ct, GimpDrawTool *draw_tool, GimpDisplay *display, gdouble x, gdouble y, gint handle_size) { GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct); GimpCageConfig *config = ct->config; gdouble dist = G_MAXDOUBLE; gint i; GimpVector2 cage_point; guint n_cage_vertices; g_return_val_if_fail (GIMP_IS_CAGE_TOOL (ct), -1); n_cage_vertices = gimp_cage_config_get_n_points (config); if (n_cage_vertices == 0) return -1; for (i = 0; i < n_cage_vertices; i++) { cage_point = gimp_cage_config_get_point_coordinate (config, options->cage_mode, i); cage_point.x += ct->offset_x; cage_point.y += ct->offset_y; dist = gimp_draw_tool_calc_distance_square (GIMP_DRAW_TOOL (draw_tool), display, x, y, cage_point.x, cage_point.y); if (dist <= SQR (handle_size / 2)) return i; } return -1; }
static void gimp_blend_tool_draw (GimpDrawTool *draw_tool) { GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (draw_tool); GimpCanvasItem *start_handle_cross, *end_handle_cross; gimp_draw_tool_add_line (draw_tool, blend_tool->start_x, blend_tool->start_y, blend_tool->end_x, blend_tool->end_y); start_handle_cross = gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_CROSS, blend_tool->start_x, blend_tool->start_y, HANDLE_CROSS_DIAMETER, HANDLE_CROSS_DIAMETER, GIMP_HANDLE_ANCHOR_CENTER); end_handle_cross = gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_CROSS, blend_tool->end_x, blend_tool->end_y, HANDLE_CROSS_DIAMETER, HANDLE_CROSS_DIAMETER, GIMP_HANDLE_ANCHOR_CENTER); GimpBlendToolPoint hilight_point; gboolean start_visible, end_visible; /* Calculate handle visibility */ if (blend_tool->grabbed_point) { start_visible = FALSE; end_visible = FALSE; } else { gdouble dist; dist = gimp_draw_tool_calc_distance_square (draw_tool, draw_tool->display, blend_tool->mouse_x, blend_tool->mouse_y, blend_tool->start_x, blend_tool->start_y); start_visible = dist < FULL_HANDLE_THRESHOLD_SQ; dist = gimp_draw_tool_calc_distance_square (draw_tool, draw_tool->display, blend_tool->mouse_x, blend_tool->mouse_y, blend_tool->end_x, blend_tool->end_y); end_visible = dist < FULL_HANDLE_THRESHOLD_SQ; } /* Update hilights */ if (blend_tool->grabbed_point) hilight_point = blend_tool->grabbed_point; else hilight_point = gimp_blend_tool_get_point_under_cursor (blend_tool); if (start_visible) { GimpCanvasItem *start_handle_circle; start_handle_circle = gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_CIRCLE, blend_tool->start_x, blend_tool->start_y, HANDLE_DIAMETER, HANDLE_DIAMETER, GIMP_HANDLE_ANCHOR_CENTER); gimp_canvas_item_set_highlight (start_handle_circle, hilight_point == POINT_START); } if (end_visible) { GimpCanvasItem *end_handle_circle; end_handle_circle = gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_CIRCLE, blend_tool->end_x, blend_tool->end_y, HANDLE_DIAMETER, HANDLE_DIAMETER, GIMP_HANDLE_ANCHOR_CENTER); gimp_canvas_item_set_highlight (end_handle_circle, hilight_point == POINT_END); } gimp_canvas_item_set_highlight (start_handle_cross, hilight_point == POINT_START); gimp_canvas_item_set_highlight (end_handle_cross, hilight_point == POINT_END); }
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_blend_tool_update_item_hilight (GimpBlendTool *blend_tool) { GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (blend_tool); if (gimp_draw_tool_is_active (draw_tool)) { GimpBlendToolPoint hilight_point; gboolean start_visible, end_visible; gint start_diameter, end_diameter; /* Calculate handle visibility */ if (blend_tool->grabbed_point) { start_visible = FALSE; end_visible = FALSE; } else { gdouble dist; dist = gimp_draw_tool_calc_distance_square (draw_tool, draw_tool->display, blend_tool->mouse_x, blend_tool->mouse_y, blend_tool->start_x, blend_tool->start_y); start_diameter = calc_handle_diameter (dist); start_visible = start_diameter > 2; dist = gimp_draw_tool_calc_distance_square (draw_tool, draw_tool->display, blend_tool->mouse_x, blend_tool->mouse_y, blend_tool->end_x, blend_tool->end_y); end_diameter = calc_handle_diameter (dist); end_visible = end_diameter > 2; } gimp_canvas_item_set_visible (blend_tool->start_handle_circle, start_visible); gimp_canvas_item_set_visible (blend_tool->end_handle_circle, end_visible); /* Update hilights */ if (blend_tool->grabbed_point) hilight_point = blend_tool->grabbed_point; else hilight_point = gimp_blend_tool_get_point_under_cursor (blend_tool); if (start_visible) { gimp_canvas_item_begin_change (blend_tool->start_handle_circle); g_object_set (blend_tool->start_handle_circle, "width", start_diameter, "height", start_diameter, NULL); gimp_canvas_item_end_change (blend_tool->start_handle_circle); } if (end_visible) { gimp_canvas_item_begin_change (blend_tool->end_handle_circle); g_object_set (blend_tool->end_handle_circle, "width", end_diameter, "height", end_diameter, NULL); gimp_canvas_item_end_change (blend_tool->end_handle_circle); } gimp_canvas_item_set_highlight (blend_tool->start_handle_circle, hilight_point == POINT_START); gimp_canvas_item_set_highlight (blend_tool->start_handle_cross, hilight_point == POINT_START); gimp_canvas_item_set_highlight (blend_tool->end_handle_circle, hilight_point == POINT_END); gimp_canvas_item_set_highlight (blend_tool->end_handle_cross, hilight_point == POINT_END); } }