/** * gimp_draw_tool_calc_distance_square: * @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 * * This function is more effective than gimp_draw_tool_calc_distance() * as it doesn't perform a sqrt(). Use this if you just need to compare * distances. * * Returns: the square of the distance between the given points in * display coordinates **/ gdouble gimp_draw_tool_calc_distance_square (GimpDrawTool *draw_tool, GimpDisplay *display, gdouble x1, gdouble y1, gdouble x2, gdouble y2) { GimpDisplayShell *shell; gdouble tx1, ty1; gdouble tx2, ty2; g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), 0.0); g_return_val_if_fail (GIMP_IS_DISPLAY (display), 0.0); shell = gimp_display_get_shell (display); gimp_display_shell_transform_xy_f (shell, x1, y1, &tx1, &ty1); gimp_display_shell_transform_xy_f (shell, x2, y2, &tx2, &ty2); return SQR (tx2 - tx1) + SQR (ty2 - ty1); }
static void gimp_display_paint_area (GimpDisplay *display, gint x, gint y, gint w, gint h) { GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (display->shell); gint x1, y1, x2, y2; gdouble x1_f, y1_f, x2_f, y2_f; /* Bounds check */ x1 = CLAMP (x, 0, display->image->width); y1 = CLAMP (y, 0, display->image->height); x2 = CLAMP (x + w, 0, display->image->width); y2 = CLAMP (y + h, 0, display->image->height); x = x1; y = y1; w = (x2 - x1); h = (y2 - y1); /* display the area */ gimp_display_shell_transform_xy_f (shell, x, y, &x1_f, &y1_f, FALSE); gimp_display_shell_transform_xy_f (shell, x + w, y + h, &x2_f, &y2_f, FALSE); /* make sure to expose a superset of the transformed sub-pixel expose * area, not a subset. bug #126942. --mitch * * also acommodate for spill introduced by potential box filtering. * (bug #474509). --simon */ x1 = floor (x1_f - 0.5); y1 = floor (y1_f - 0.5); x2 = ceil (x2_f + 0.5); y2 = ceil (y2_f + 0.5); gimp_display_shell_expose_area (shell, x1, y1, x2 - x1, y2 - y1); }
/** * gimp_display_shell_scale_to: * @shell: * @scale: * @viewport_x: * @viewport_y: * * Zooms. The display offsets are adjusted so that the point specified * by @x and @y doesn't change it's position on screen. **/ static void gimp_display_shell_scale_to (GimpDisplayShell *shell, gdouble scale, gdouble viewport_x, gdouble viewport_y) { gdouble image_x, image_y; gdouble new_viewport_x, new_viewport_y; g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); if (! shell->display) return; /* freeze the active tool */ gimp_display_shell_pause (shell); gimp_display_shell_untransform_xy_f (shell, viewport_x, viewport_y, &image_x, &image_y); /* Note that we never come here if we need to resize_windows_on_zoom */ gimp_display_shell_scale_by_values (shell, scale, shell->offset_x, shell->offset_y, FALSE); gimp_display_shell_transform_xy_f (shell, image_x, image_y, &new_viewport_x, &new_viewport_y); gimp_display_shell_scroll (shell, new_viewport_x - viewport_x, new_viewport_y - viewport_y); /* re-enable the active tool */ gimp_display_shell_resume (shell); }
void gimp_display_shell_transform_bounds (const GimpDisplayShell *shell, gdouble x1, gdouble y1, gdouble x2, gdouble y2, gdouble *nx1, gdouble *ny1, gdouble *nx2, gdouble *ny2) { g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); g_return_if_fail (nx1 != NULL); g_return_if_fail (ny1 != NULL); g_return_if_fail (nx2 != NULL); g_return_if_fail (ny2 != NULL); if (shell->rotate_transform) { gdouble tx1, ty1; gdouble tx2, ty2; gdouble tx3, ty3; gdouble tx4, ty4; gimp_display_shell_transform_xy_f (shell, x1, y1, &tx1, &ty1); gimp_display_shell_transform_xy_f (shell, x1, y2, &tx2, &ty2); gimp_display_shell_transform_xy_f (shell, x2, y1, &tx3, &ty3); gimp_display_shell_transform_xy_f (shell, x2, y2, &tx4, &ty4); *nx1 = MIN4 (tx1, tx2, tx3, tx4); *ny1 = MIN4 (ty1, ty2, ty3, ty4); *nx2 = MAX4 (tx1, tx2, tx3, tx4); *ny2 = MAX4 (ty1, ty2, ty3, ty4); } else { gimp_display_shell_transform_xy_f (shell, x1, y1, nx1, ny1); gimp_display_shell_transform_xy_f (shell, x2, y2, nx2, ny2); } }
gboolean gimp_draw_tool_on_handle (GimpDrawTool *draw_tool, GimpDisplay *display, gdouble x, gdouble y, GimpHandleType type, gdouble handle_x, gdouble handle_y, gint width, gint height, GimpHandleAnchor anchor) { GimpDisplayShell *shell; gdouble tx, ty; gdouble handle_tx, handle_ty; g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), FALSE); g_return_val_if_fail (GIMP_IS_DISPLAY (display), FALSE); shell = gimp_display_get_shell (display); gimp_display_shell_transform_xy_f (shell, x, y, &tx, &ty); gimp_display_shell_transform_xy_f (shell, handle_x, handle_y, &handle_tx, &handle_ty); switch (type) { case GIMP_HANDLE_SQUARE: case GIMP_HANDLE_FILLED_SQUARE: case GIMP_HANDLE_CROSS: gimp_canvas_item_shift_to_north_west (anchor, handle_tx, handle_ty, width, height, &handle_tx, &handle_ty); return (tx == CLAMP (tx, handle_tx, handle_tx + width) && ty == CLAMP (ty, handle_ty, handle_ty + height)); case GIMP_HANDLE_CIRCLE: case GIMP_HANDLE_FILLED_CIRCLE: gimp_canvas_item_shift_to_center (anchor, handle_tx, handle_ty, width, height, &handle_tx, &handle_ty); /* FIXME */ if (width != height) width = (width + height) / 2; width /= 2; return ((SQR (handle_tx - tx) + SQR (handle_ty - ty)) < SQR (width)); default: g_warning ("%s: invalid handle type %d", G_STRFUNC, type); break; } return FALSE; }