static GimpValueArray * image_grid_get_style_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GimpValueArray *args, GError **error) { gboolean success = TRUE; GimpValueArray *return_vals; GimpImage *image; gint32 style = 0; image = gimp_value_get_image (gimp_value_array_index (args, 0), gimp); if (success) { GimpGrid *grid = gimp_image_get_grid (image); if (grid) g_object_get (grid, "style", &style, NULL); else success = FALSE; } return_vals = gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); if (success) g_value_set_enum (gimp_value_array_index (return_vals, 1), style); return return_vals; }
static GimpValueArray * image_grid_set_foreground_color_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GimpValueArray *args, GError **error) { gboolean success = TRUE; GimpImage *image; GimpRGB fgcolor; image = gimp_value_get_image (gimp_value_array_index (args, 0), gimp); gimp_value_get_rgb (gimp_value_array_index (args, 1), &fgcolor); if (success) { GimpGrid *grid = gimp_image_get_grid (image); if (grid) g_object_set (grid, "fgcolor", &fgcolor, NULL); else success = FALSE; } return gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); }
static GValueArray * image_grid_set_spacing_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GValueArray *args, GError **error) { gboolean success = TRUE; GimpImage *image; gdouble xspacing; gdouble yspacing; image = gimp_value_get_image (&args->values[0], gimp); xspacing = g_value_get_double (&args->values[1]); yspacing = g_value_get_double (&args->values[2]); if (success) { GimpGrid *grid = gimp_image_get_grid (image); if (grid) g_object_set (grid, "xspacing", xspacing, "yspacing", yspacing, NULL); else success = FALSE; } return gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); }
static GimpValueArray * image_grid_set_offset_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GimpValueArray *args, GError **error) { gboolean success = TRUE; GimpImage *image; gdouble xoffset; gdouble yoffset; image = gimp_value_get_image (gimp_value_array_index (args, 0), gimp); xoffset = g_value_get_double (gimp_value_array_index (args, 1)); yoffset = g_value_get_double (gimp_value_array_index (args, 2)); if (success) { GimpGrid *grid = gimp_image_get_grid (image); if (grid) g_object_set (grid, "xoffset", xoffset, "yoffset", yoffset, NULL); else success = FALSE; } return gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); }
static GValueArray * image_grid_set_style_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GValueArray *args, GError **error) { gboolean success = TRUE; GimpImage *image; gint32 style; image = gimp_value_get_image (&args->values[0], gimp); style = g_value_get_enum (&args->values[1]); if (success) { GimpGrid *grid = gimp_image_get_grid (image); if (grid) g_object_set (grid, "style", style, NULL); else success = FALSE; } return gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); }
static GimpValueArray * image_grid_get_foreground_color_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GimpValueArray *args, GError **error) { gboolean success = TRUE; GimpValueArray *return_vals; GimpImage *image; GimpRGB fgcolor = { 0.0, 0.0, 0.0, 1.0 }; image = gimp_value_get_image (gimp_value_array_index (args, 0), gimp); if (success) { GimpGrid *grid = gimp_image_get_grid (image); if (grid) fgcolor = grid->fgcolor; else success = FALSE; } return_vals = gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); if (success) gimp_value_set_rgb (gimp_value_array_index (return_vals, 1), &fgcolor); return return_vals; }
static GValueArray * image_grid_set_background_color_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GValueArray *args, GError **error) { gboolean success = TRUE; GimpImage *image; GimpRGB bgcolor; image = gimp_value_get_image (&args->values[0], gimp); gimp_value_get_rgb (&args->values[1], &bgcolor); if (success) { GimpGrid *grid = gimp_image_get_grid (image); if (grid) g_object_set (grid, "bgcolor", &bgcolor, NULL); else success = FALSE; } return gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); }
static GValueArray * image_grid_get_background_color_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GValueArray *args, GError **error) { gboolean success = TRUE; GValueArray *return_vals; GimpImage *image; GimpRGB bgcolor = { 0.0, 0.0, 0.0, 1.0 }; image = gimp_value_get_image (&args->values[0], gimp); if (success) { GimpGrid *grid = gimp_image_get_grid (image); if (grid) bgcolor = grid->bgcolor; else success = FALSE; } return_vals = gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); if (success) gimp_value_set_rgb (&return_vals->values[1], &bgcolor); return return_vals; }
static GValueArray * image_grid_get_offset_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GValueArray *args, GError **error) { gboolean success = TRUE; GValueArray *return_vals; GimpImage *image; gdouble xoffset = 0.0; gdouble yoffset = 0.0; image = gimp_value_get_image (&args->values[0], gimp); if (success) { GimpGrid *grid = gimp_image_get_grid (image); if (grid) g_object_get (grid, "xoffset", &xoffset, "yoffset", &yoffset, NULL); else success = FALSE; } return_vals = gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); if (success) { g_value_set_double (&return_vals->values[1], xoffset); g_value_set_double (&return_vals->values[2], yoffset); } return return_vals; }
static GimpValueArray * image_grid_get_spacing_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GimpValueArray *args, GError **error) { gboolean success = TRUE; GimpValueArray *return_vals; GimpImage *image; gdouble xspacing = 0.0; gdouble yspacing = 0.0; image = gimp_value_get_image (gimp_value_array_index (args, 0), gimp); if (success) { GimpGrid *grid = gimp_image_get_grid (image); if (grid) g_object_get (grid, "xspacing", &xspacing, "yspacing", &yspacing, NULL); else success = FALSE; } return_vals = gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); if (success) { g_value_set_double (gimp_value_array_index (return_vals, 1), xspacing); g_value_set_double (gimp_value_array_index (return_vals, 2), yspacing); } return return_vals; }
gboolean gimp_image_snap_x (GimpImage *image, gdouble x, gdouble *tx, gdouble epsilon_x, gboolean snap_to_guides, gboolean snap_to_grid, gboolean snap_to_canvas) { gdouble mindist = G_MAXDOUBLE; gboolean snapped = FALSE; g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE); g_return_val_if_fail (tx != NULL, FALSE); *tx = x; if (! gimp_image_get_guides (image)) snap_to_guides = FALSE; if (! gimp_image_get_grid (image)) snap_to_grid = FALSE; if (! (snap_to_guides || snap_to_grid || snap_to_canvas)) return FALSE; if (x < -epsilon_x || x >= (gimp_image_get_width (image) + epsilon_x)) return FALSE; if (snap_to_guides) { GList *list; for (list = gimp_image_get_guides (image); list; list = g_list_next (list)) { GimpGuide *guide = list->data; gint position = gimp_guide_get_position (guide); if (gimp_guide_get_orientation (guide) == GIMP_ORIENTATION_VERTICAL) { snapped |= gimp_image_snap_distance (x, position, epsilon_x, &mindist, tx); } } } if (snap_to_grid) { GimpGrid *grid = gimp_image_get_grid (image); gdouble xspacing; gdouble xoffset; gdouble i; gimp_grid_get_spacing (grid, &xspacing, NULL); gimp_grid_get_offset (grid, &xoffset, NULL); /* the snap-to-grid part could probably be rewritten */ while (xoffset > xspacing) xoffset -= xspacing; for (i = xoffset; i <= gimp_image_get_width (image); i += xspacing) { if (i < 0) continue; snapped |= gimp_image_snap_distance (x, i, epsilon_x, &mindist, tx); } } if (snap_to_canvas) { snapped |= gimp_image_snap_distance (x, 0, epsilon_x, &mindist, tx); snapped |= gimp_image_snap_distance (x, gimp_image_get_width (image), epsilon_x, &mindist, tx); } return snapped; }
gboolean gimp_image_snap_rectangle (GimpImage *image, gdouble x1, gdouble y1, gdouble x2, gdouble y2, gdouble *tx1, gdouble *ty1, gdouble epsilon_x, gdouble epsilon_y, gboolean snap_to_guides, gboolean snap_to_grid, gboolean snap_to_canvas, gboolean snap_to_vectors) { gdouble nx, ny; gdouble mindist_x = G_MAXDOUBLE; gdouble mindist_y = G_MAXDOUBLE; gdouble x_center = (x1 + x2) / 2.0; gdouble y_center = (y1 + y2) / 2.0; gboolean snapped = FALSE; g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE); g_return_val_if_fail (tx1 != NULL, FALSE); g_return_val_if_fail (ty1 != NULL, FALSE); *tx1 = x1; *ty1 = y1; if (! gimp_image_get_guides (image)) snap_to_guides = FALSE; if (! gimp_image_get_grid (image)) snap_to_grid = FALSE; if (! gimp_image_get_active_vectors (image)) snap_to_vectors = FALSE; if (! (snap_to_guides || snap_to_grid || snap_to_canvas || snap_to_vectors)) return FALSE; /* left edge */ if (gimp_image_snap_x (image, x1, &nx, MIN (epsilon_x, mindist_x), snap_to_guides, snap_to_grid, snap_to_canvas)) { mindist_x = ABS (nx - x1); *tx1 = nx; snapped = TRUE; } /* right edge */ if (gimp_image_snap_x (image, x2, &nx, MIN (epsilon_x, mindist_x), snap_to_guides, snap_to_grid, snap_to_canvas)) { mindist_x = ABS (nx - x2); *tx1 = RINT (x1 + (nx - x2)); snapped = TRUE; } /* center, vertical */ if (gimp_image_snap_x (image, x_center, &nx, MIN (epsilon_x, mindist_x), snap_to_guides, snap_to_grid, snap_to_canvas)) { mindist_x = ABS (nx - x_center); *tx1 = RINT (x1 + (nx - x_center)); snapped = TRUE; } /* top edge */ if (gimp_image_snap_y (image, y1, &ny, MIN (epsilon_y, mindist_y), snap_to_guides, snap_to_grid, snap_to_canvas)) { mindist_y = ABS (ny - y1); *ty1 = ny; snapped = TRUE; } /* bottom edge */ if (gimp_image_snap_y (image, y2, &ny, MIN (epsilon_y, mindist_y), snap_to_guides, snap_to_grid, snap_to_canvas)) { mindist_y = ABS (ny - y2); *ty1 = RINT (y1 + (ny - y2)); snapped = TRUE; } /* center, horizontal */ if (gimp_image_snap_y (image, y_center, &ny, MIN (epsilon_y, mindist_y), snap_to_guides, snap_to_grid, snap_to_canvas)) { mindist_y = ABS (ny - y_center); *ty1 = RINT (y1 + (ny - y_center)); snapped = TRUE; } if (snap_to_vectors) { GimpVectors *vectors = gimp_image_get_active_vectors (image); GimpStroke *stroke = NULL; GimpCoords coords1 = GIMP_COORDS_DEFAULT_VALUES; GimpCoords coords2 = GIMP_COORDS_DEFAULT_VALUES; while ((stroke = gimp_vectors_stroke_get_next (vectors, stroke))) { GimpCoords nearest; gdouble dist; /* top edge */ coords1.x = x1; coords1.y = y1; coords2.x = x2; coords2.y = y1; if (gimp_stroke_nearest_tangent_get (stroke, &coords1, &coords2, 1.0, &nearest, NULL, NULL, NULL) >= 0) { snapped |= gimp_image_snap_distance (y1, nearest.y, epsilon_y, &mindist_y, ty1); } if (gimp_stroke_nearest_intersection_get (stroke, &coords1, &coords2, 1.0, &nearest, NULL, NULL, NULL) >= 0) { snapped |= gimp_image_snap_distance (x1, nearest.x, epsilon_x, &mindist_x, tx1); } if (gimp_stroke_nearest_intersection_get (stroke, &coords2, &coords1, 1.0, &nearest, NULL, NULL, NULL) >= 0) { dist = ABS (nearest.x - x2); if (dist < MIN (epsilon_x, mindist_x)) { mindist_x = dist; *tx1 = RINT (x1 + (nearest.x - x2)); snapped = TRUE; } } /* bottom edge */ coords1.x = x1; coords1.y = y2; coords2.x = x2; coords2.y = y2; if (gimp_stroke_nearest_tangent_get (stroke, &coords1, &coords2, 1.0, &nearest, NULL, NULL, NULL) >= 0) { dist = ABS (nearest.y - y2); if (dist < MIN (epsilon_y, mindist_y)) { mindist_y = dist; *ty1 = RINT (y1 + (nearest.y - y2)); snapped = TRUE; } } if (gimp_stroke_nearest_intersection_get (stroke, &coords1, &coords2, 1.0, &nearest, NULL, NULL, NULL) >= 0) { snapped |= gimp_image_snap_distance (x1, nearest.x, epsilon_x, &mindist_x, tx1); } if (gimp_stroke_nearest_intersection_get (stroke, &coords2, &coords1, 1.0, &nearest, NULL, NULL, NULL) >= 0) { dist = ABS (nearest.x - x2); if (dist < MIN (epsilon_x, mindist_x)) { mindist_x = dist; *tx1 = RINT (x1 + (nearest.x - x2)); snapped = TRUE; } } /* left edge */ coords1.x = x1; coords1.y = y1; coords2.x = x1; coords2.y = y2; if (gimp_stroke_nearest_tangent_get (stroke, &coords1, &coords2, 1.0, &nearest, NULL, NULL, NULL) >= 0) { snapped |= gimp_image_snap_distance (x1, nearest.x, epsilon_x, &mindist_x, tx1); } if (gimp_stroke_nearest_intersection_get (stroke, &coords1, &coords2, 1.0, &nearest, NULL, NULL, NULL) >= 0) { snapped |= gimp_image_snap_distance (y1, nearest.y, epsilon_y, &mindist_y, ty1); } if (gimp_stroke_nearest_intersection_get (stroke, &coords2, &coords1, 1.0, &nearest, NULL, NULL, NULL) >= 0) { dist = ABS (nearest.y - y2); if (dist < MIN (epsilon_y, mindist_y)) { mindist_y = dist; *ty1 = RINT (y1 + (nearest.y - y2)); snapped = TRUE; } } /* right edge */ coords1.x = x2; coords1.y = y1; coords2.x = x2; coords2.y = y2; if (gimp_stroke_nearest_tangent_get (stroke, &coords1, &coords2, 1.0, &nearest, NULL, NULL, NULL) >= 0) { dist = ABS (nearest.x - x2); if (dist < MIN (epsilon_x, mindist_x)) { mindist_x = dist; *tx1 = RINT (x1 + (nearest.x - x2)); snapped = TRUE; } } if (gimp_stroke_nearest_intersection_get (stroke, &coords1, &coords2, 1.0, &nearest, NULL, NULL, NULL) >= 0) { snapped |= gimp_image_snap_distance (y1, nearest.y, epsilon_y, &mindist_y, ty1); } if (gimp_stroke_nearest_intersection_get (stroke, &coords2, &coords1, 1.0, &nearest, NULL, NULL, NULL) >= 0) { dist = ABS (nearest.y - y2); if (dist < MIN (epsilon_y, mindist_y)) { mindist_y = dist; *ty1 = RINT (y1 + (nearest.y - y2)); snapped = TRUE; } } /* center */ coords1.x = x_center; coords1.y = y_center; if (gimp_stroke_nearest_point_get (stroke, &coords1, 1.0, &nearest, NULL, NULL, NULL) >= 0) { if (gimp_image_snap_distance (x_center, nearest.x, epsilon_x, &mindist_x, &nx)) { mindist_x = ABS (nx - x_center); *tx1 = RINT (x1 + (nx - x_center)); snapped = TRUE; } if (gimp_image_snap_distance (y_center, nearest.y, epsilon_y, &mindist_y, &ny)) { mindist_y = ABS (ny - y_center); *ty1 = RINT (y1 + (ny - y_center)); snapped = TRUE; } } } } return snapped; }
gboolean gimp_image_snap_point (GimpImage *image, gdouble x, gdouble y, gdouble *tx, gdouble *ty, gdouble epsilon_x, gdouble epsilon_y, gboolean snap_to_guides, gboolean snap_to_grid, gboolean snap_to_canvas, gboolean snap_to_vectors) { gdouble mindist_x = G_MAXDOUBLE; gdouble mindist_y = G_MAXDOUBLE; gboolean snapped = FALSE; g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE); g_return_val_if_fail (tx != NULL, FALSE); g_return_val_if_fail (ty != NULL, FALSE); *tx = x; *ty = y; if (! gimp_image_get_guides (image)) snap_to_guides = FALSE; if (! gimp_image_get_grid (image)) snap_to_grid = FALSE; if (! gimp_image_get_active_vectors (image)) snap_to_vectors = FALSE; if (! (snap_to_guides || snap_to_grid || snap_to_canvas || snap_to_vectors)) return FALSE; if (x < -epsilon_x || x >= (gimp_image_get_width (image) + epsilon_x) || y < -epsilon_y || y >= (gimp_image_get_height (image) + epsilon_y)) { return FALSE; } if (snap_to_guides) { GList *list; for (list = gimp_image_get_guides (image); list; list = g_list_next (list)) { GimpGuide *guide = list->data; gint position = gimp_guide_get_position (guide); switch (gimp_guide_get_orientation (guide)) { case GIMP_ORIENTATION_HORIZONTAL: snapped |= gimp_image_snap_distance (y, position, epsilon_y, &mindist_y, ty); break; case GIMP_ORIENTATION_VERTICAL: snapped |= gimp_image_snap_distance (x, position, epsilon_x, &mindist_x, tx); break; default: break; } } } if (snap_to_grid) { GimpGrid *grid = gimp_image_get_grid (image); gdouble xspacing, yspacing; gdouble xoffset, yoffset; gdouble i; gimp_grid_get_spacing (grid, &xspacing, &yspacing); gimp_grid_get_offset (grid, &xoffset, &yoffset); while (xoffset > xspacing) xoffset -= xspacing; while (yoffset > yspacing) yoffset -= yspacing; for (i = xoffset; i <= gimp_image_get_width (image); i += xspacing) { if (i < 0) continue; snapped |= gimp_image_snap_distance (x, i, epsilon_x, &mindist_x, tx); } for (i = yoffset; i <= gimp_image_get_height (image); i += yspacing) { if (i < 0) continue; snapped |= gimp_image_snap_distance (y, i, epsilon_y, &mindist_y, ty); } } if (snap_to_canvas) { snapped |= gimp_image_snap_distance (x, 0, epsilon_x, &mindist_x, tx); snapped |= gimp_image_snap_distance (x, gimp_image_get_width (image), epsilon_x, &mindist_x, tx); snapped |= gimp_image_snap_distance (y, 0, epsilon_y, &mindist_y, ty); snapped |= gimp_image_snap_distance (y, gimp_image_get_height (image), epsilon_y, &mindist_y, ty); } if (snap_to_vectors) { GimpVectors *vectors = gimp_image_get_active_vectors (image); GimpStroke *stroke = NULL; GimpCoords coords = { 0, 0, 0, 0, 0 }; coords.x = x; coords.y = y; while ((stroke = gimp_vectors_stroke_get_next (vectors, stroke))) { GimpCoords nearest; if (gimp_stroke_nearest_point_get (stroke, &coords, 1.0, &nearest, NULL, NULL, NULL) >= 0) { snapped |= gimp_image_snap_distance (x, nearest.x, epsilon_x, &mindist_x, tx); snapped |= gimp_image_snap_distance (y, nearest.y, epsilon_y, &mindist_y, ty); } } } return snapped; }
gboolean gimp_image_snap_y (GimpImage *image, gdouble y, gdouble *ty, gdouble epsilon_y, gboolean snap_to_guides, gboolean snap_to_grid, gboolean snap_to_canvas) { gdouble mindist = G_MAXDOUBLE; gboolean snapped = FALSE; g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE); g_return_val_if_fail (ty != NULL, FALSE); *ty = y; if (! gimp_image_get_guides (image)) snap_to_guides = FALSE; if (! gimp_image_get_grid (image)) snap_to_grid = FALSE; if (! (snap_to_guides || snap_to_grid || snap_to_canvas)) return FALSE; if (y < -epsilon_y || y >= (gimp_image_get_height (image) + epsilon_y)) return FALSE; if (snap_to_guides) { GList *list; for (list = gimp_image_get_guides (image); list; list = g_list_next (list)) { GimpGuide *guide = list->data; gint position = gimp_guide_get_position (guide); if (gimp_guide_get_orientation (guide) == GIMP_ORIENTATION_HORIZONTAL) { snapped |= gimp_image_snap_distance (y, position, epsilon_y, &mindist, ty); } } } if (snap_to_grid) { GimpGrid *grid = gimp_image_get_grid (image); gdouble yspacing; gdouble yoffset; gdouble i; gimp_grid_get_spacing (grid, NULL, &yspacing); gimp_grid_get_offset (grid, NULL, &yoffset); while (yoffset > yspacing) yoffset -= yspacing; for (i = yoffset; i <= gimp_image_get_height (image); i += yspacing) { if (i < 0) continue; snapped |= gimp_image_snap_distance (y, i, epsilon_y, &mindist, ty); } } if (snap_to_canvas) { snapped |= gimp_image_snap_distance (y, 0, epsilon_y, &mindist, ty); snapped |= gimp_image_snap_distance (y, gimp_image_get_height (image), epsilon_y, &mindist, ty); } return snapped; }
gboolean gimp_image_snap_x (GimpImage *image, gdouble x, gdouble *tx, gdouble epsilon_x, gboolean snap_to_guides, gboolean snap_to_grid, gboolean snap_to_canvas) { gdouble mindist = G_MAXDOUBLE; gdouble dist; gboolean snapped = FALSE; g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE); g_return_val_if_fail (tx != NULL, FALSE); *tx = x; if (! gimp_image_get_guides (image)) snap_to_guides = FALSE; if (! gimp_image_get_grid (image)) snap_to_grid = FALSE; if (! (snap_to_guides || snap_to_grid || snap_to_canvas)) return FALSE; if (x < -epsilon_x || x >= (gimp_image_get_width (image) + epsilon_x)) return FALSE; if (snap_to_guides) { GList *list; for (list = gimp_image_get_guides (image); list; list = g_list_next (list)) { GimpGuide *guide = list->data; gint position = gimp_guide_get_position (guide); if (position < 0) continue; if (gimp_guide_get_orientation (guide) == GIMP_ORIENTATION_VERTICAL) { dist = ABS (position - x); if (dist < MIN (epsilon_x, mindist)) { mindist = dist; *tx = position; snapped = TRUE; } } } } if (snap_to_grid) { GimpGrid *grid = gimp_image_get_grid (image); gdouble xspacing; gdouble xoffset; gdouble i; g_object_get (grid, "xspacing", &xspacing, "xoffset", &xoffset, NULL); while (xoffset > xspacing) xoffset -= xspacing; for (i = xoffset; i <= gimp_image_get_width (image); i += xspacing) { if (i < 0) continue; dist = ABS (i - x); if (dist < MIN (epsilon_x, mindist)) { mindist = dist; *tx = i; snapped = TRUE; } } } if (snap_to_canvas) { dist = ABS (x); if (dist < MIN (epsilon_x, mindist)) { mindist = dist; *tx = 0; snapped = TRUE; } dist = ABS (gimp_image_get_width (image) - x); if (dist < MIN (epsilon_x, mindist)) { mindist = dist; *tx = gimp_image_get_width (image); snapped = TRUE; } } return snapped; }
gboolean gimp_image_snap_point (GimpImage *image, gdouble x, gdouble y, gdouble *tx, gdouble *ty, gdouble epsilon_x, gdouble epsilon_y, gboolean snap_to_guides, gboolean snap_to_grid, gboolean snap_to_canvas, gboolean snap_to_vectors) { gdouble mindist_x = G_MAXDOUBLE; gdouble mindist_y = G_MAXDOUBLE; gdouble dist; gboolean snapped = FALSE; g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE); g_return_val_if_fail (tx != NULL, FALSE); g_return_val_if_fail (ty != NULL, FALSE); *tx = x; *ty = y; if (! gimp_image_get_guides (image)) snap_to_guides = FALSE; if (! gimp_image_get_grid (image)) snap_to_grid = FALSE; if (! gimp_image_get_active_vectors (image)) snap_to_vectors = FALSE; if (! (snap_to_guides || snap_to_grid || snap_to_canvas || snap_to_vectors)) return FALSE; if (x < -epsilon_x || x >= (gimp_image_get_width (image) + epsilon_x) || y < -epsilon_y || y >= (gimp_image_get_height (image) + epsilon_y)) { return FALSE; } if (snap_to_guides) { GList *list; for (list = gimp_image_get_guides (image); list; list = g_list_next (list)) { GimpGuide *guide = list->data; gint position = gimp_guide_get_position (guide); if (position < 0) continue; switch (gimp_guide_get_orientation (guide)) { case GIMP_ORIENTATION_HORIZONTAL: dist = ABS (position - y); if (dist < MIN (epsilon_y, mindist_y)) { mindist_y = dist; *ty = position; snapped = TRUE; } break; case GIMP_ORIENTATION_VERTICAL: dist = ABS (position - x); if (dist < MIN (epsilon_x, mindist_x)) { mindist_x = dist; *tx = position; snapped = TRUE; } break; default: break; } } } if (snap_to_grid) { GimpGrid *grid = gimp_image_get_grid (image); gdouble xspacing, yspacing; gdouble xoffset, yoffset; gdouble i; g_object_get (grid, "xspacing", &xspacing, "yspacing", &yspacing, "xoffset", &xoffset, "yoffset", &yoffset, NULL); while (xoffset > xspacing) xoffset -= xspacing; while (yoffset > yspacing) yoffset -= yspacing; for (i = xoffset; i <= gimp_image_get_width (image); i += xspacing) { if (i < 0) continue; dist = ABS (i - x); if (dist < MIN (epsilon_x, mindist_x)) { mindist_x = dist; *tx = i; snapped = TRUE; } } for (i = yoffset; i <= gimp_image_get_height (image); i += yspacing) { if (i < 0) continue; dist = ABS (i - y); if (dist < MIN (epsilon_y, mindist_y)) { mindist_y = dist; *ty = i; snapped = TRUE; } } } if (snap_to_canvas) { dist = ABS (x); if (dist < MIN (epsilon_x, mindist_x)) { mindist_x = dist; *tx = 0; snapped = TRUE; } dist = ABS (gimp_image_get_width (image) - x); if (dist < MIN (epsilon_x, mindist_x)) { mindist_x = dist; *tx = gimp_image_get_width (image); snapped = TRUE; } dist = ABS (y); if (dist < MIN (epsilon_y, mindist_y)) { mindist_y = dist; *ty = 0; snapped = TRUE; } dist = ABS (gimp_image_get_height (image) - y); if (dist < MIN (epsilon_y, mindist_y)) { mindist_y = dist; *ty = gimp_image_get_height (image); snapped = TRUE; } } if (snap_to_vectors) { GimpVectors *vectors = gimp_image_get_active_vectors (image); GimpStroke *stroke = NULL; GimpCoords coords = { 0, 0, 0, 0, 0 }; coords.x = x; coords.y = y; while ((stroke = gimp_vectors_stroke_get_next (vectors, stroke))) { GimpCoords nearest; if (gimp_stroke_nearest_point_get (stroke, &coords, 1.0, &nearest, NULL, NULL, NULL) >= 0) { dist = ABS (nearest.x - x); if (dist < MIN (epsilon_x, mindist_x)) { mindist_x = dist; *tx = nearest.x; snapped = TRUE; } dist = ABS (nearest.y - y); if (dist < MIN (epsilon_y, mindist_y)) { mindist_y = dist; *ty = nearest.y; snapped = TRUE; } } } } return snapped; }
gboolean gimp_image_snap_y (GimpImage *image, gdouble y, gdouble *ty, gdouble epsilon_y, gboolean snap_to_guides, gboolean snap_to_grid, gboolean snap_to_canvas) { gdouble mindist = G_MAXDOUBLE; gdouble dist; gboolean snapped = FALSE; g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE); g_return_val_if_fail (ty != NULL, FALSE); *ty = y; if (! gimp_image_get_guides (image)) snap_to_guides = FALSE; if (! gimp_image_get_grid (image)) snap_to_grid = FALSE; if (! (snap_to_guides || snap_to_grid || snap_to_canvas)) return FALSE; if (y < -epsilon_y || y >= (gimp_image_get_height (image) + epsilon_y)) return FALSE; if (snap_to_guides) { GList *list; for (list = gimp_image_get_guides (image); list; list = g_list_next (list)) { GimpGuide *guide = list->data; gint position = gimp_guide_get_position (guide); if (position < 0) continue; if (gimp_guide_get_orientation (guide) == GIMP_ORIENTATION_HORIZONTAL) { dist = ABS (position - y); if (dist < MIN (epsilon_y, mindist)) { mindist = dist; *ty = position; snapped = TRUE; } } } } if (snap_to_grid) { GimpGrid *grid = gimp_image_get_grid (image); gdouble yspacing; gdouble yoffset; gdouble i; g_object_get (grid, "yspacing", &yspacing, "yoffset", &yoffset, NULL); while (yoffset > yspacing) yoffset -= yspacing; for (i = yoffset; i <= gimp_image_get_height (image); i += yspacing) { if (i < 0) continue; dist = ABS (i - y); if (dist < MIN (epsilon_y, mindist)) { mindist = dist; *ty = i; snapped = TRUE; } } } if (snap_to_canvas) { dist = ABS (y); if (dist < MIN (epsilon_y, mindist)) { mindist = dist; *ty = 0; snapped = TRUE; } dist = ABS (gimp_image_get_height (image) - y); if (dist < MIN (epsilon_y, mindist)) { mindist = dist; *ty = gimp_image_get_height (image); snapped = TRUE; } } return snapped; }
void gimp_display_shell_connect (GimpDisplayShell *shell) { GimpImage *image; GimpContainer *vectors; GList *list; g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); g_return_if_fail (GIMP_IS_DISPLAY (shell->display)); image = gimp_display_get_image (shell->display); vectors = gimp_image_get_vectors (image); g_return_if_fail (GIMP_IS_IMAGE (image)); g_signal_connect (image, "clean", G_CALLBACK (gimp_display_shell_clean_dirty_handler), shell); g_signal_connect (image, "dirty", G_CALLBACK (gimp_display_shell_clean_dirty_handler), shell); g_signal_connect (image, "undo-event", G_CALLBACK (gimp_display_shell_undo_event_handler), shell); g_signal_connect (gimp_image_get_grid (image), "notify", G_CALLBACK (gimp_display_shell_grid_notify_handler), shell); g_object_set (shell->grid, "grid", gimp_image_get_grid (image), NULL); g_signal_connect (image, "name-changed", G_CALLBACK (gimp_display_shell_name_changed_handler), shell); g_signal_connect (image, "selection-invalidate", G_CALLBACK (gimp_display_shell_selection_invalidate_handler), shell); g_signal_connect (image, "size-changed-detailed", G_CALLBACK (gimp_display_shell_size_changed_detailed_handler), shell); g_signal_connect (image, "resolution-changed", G_CALLBACK (gimp_display_shell_resolution_changed_handler), shell); g_signal_connect (image, "quick-mask-changed", G_CALLBACK (gimp_display_shell_quick_mask_changed_handler), shell); g_signal_connect (image, "guide-added", G_CALLBACK (gimp_display_shell_guide_add_handler), shell); g_signal_connect (image, "guide-removed", G_CALLBACK (gimp_display_shell_guide_remove_handler), shell); g_signal_connect (image, "guide-moved", G_CALLBACK (gimp_display_shell_guide_move_handler), shell); for (list = gimp_image_get_guides (image); list; list = g_list_next (list)) { gimp_display_shell_guide_add_handler (image, list->data, shell); } g_signal_connect (image, "sample-point-added", G_CALLBACK (gimp_display_shell_sample_point_add_handler), shell); g_signal_connect (image, "sample-point-removed", G_CALLBACK (gimp_display_shell_sample_point_remove_handler), shell); g_signal_connect (image, "sample-point-moved", G_CALLBACK (gimp_display_shell_sample_point_move_handler), shell); for (list = gimp_image_get_sample_points (image); list; list = g_list_next (list)) { gimp_display_shell_sample_point_add_handler (image, list->data, shell); } g_signal_connect (image, "invalidate-preview", G_CALLBACK (gimp_display_shell_invalidate_preview_handler), shell); g_signal_connect (image, "precision-changed", G_CALLBACK (gimp_display_shell_precision_changed_handler), shell); g_signal_connect (image, "profile-changed", G_CALLBACK (gimp_display_shell_profile_changed_handler), shell); g_signal_connect (image, "precision-changed", G_CALLBACK (gimp_display_shell_precision_changed_handler), shell); g_signal_connect (image, "saved", G_CALLBACK (gimp_display_shell_saved_handler), shell); g_signal_connect (image, "exported", G_CALLBACK (gimp_display_shell_exported_handler), shell); g_signal_connect (image, "active-vectors-changed", G_CALLBACK (gimp_display_shell_active_vectors_handler), shell); shell->vectors_freeze_handler = gimp_tree_handler_connect (vectors, "freeze", G_CALLBACK (gimp_display_shell_vectors_freeze_handler), shell); shell->vectors_thaw_handler = gimp_tree_handler_connect (vectors, "thaw", G_CALLBACK (gimp_display_shell_vectors_thaw_handler), shell); shell->vectors_visible_handler = gimp_tree_handler_connect (vectors, "visibility-changed", G_CALLBACK (gimp_display_shell_vectors_visible_handler), shell); g_signal_connect (vectors, "add", G_CALLBACK (gimp_display_shell_vectors_add_handler), shell); g_signal_connect (vectors, "remove", G_CALLBACK (gimp_display_shell_vectors_remove_handler), shell); for (list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (vectors)); list; list = g_list_next (list)) { gimp_display_shell_vectors_add_handler (vectors, list->data, shell); } g_signal_connect (shell->display->config, "notify::transparency-size", G_CALLBACK (gimp_display_shell_check_notify_handler), shell); g_signal_connect (shell->display->config, "notify::transparency-type", G_CALLBACK (gimp_display_shell_check_notify_handler), shell); g_signal_connect (shell->display->config, "notify::image-title-format", G_CALLBACK (gimp_display_shell_title_notify_handler), shell); g_signal_connect (shell->display->config, "notify::image-status-format", G_CALLBACK (gimp_display_shell_title_notify_handler), shell); g_signal_connect (shell->display->config, "notify::navigation-preview-size", G_CALLBACK (gimp_display_shell_nav_size_notify_handler), shell); g_signal_connect (shell->display->config, "notify::monitor-resolution-from-windowing-system", G_CALLBACK (gimp_display_shell_monitor_res_notify_handler), shell); g_signal_connect (shell->display->config, "notify::monitor-xresolution", G_CALLBACK (gimp_display_shell_monitor_res_notify_handler), shell); g_signal_connect (shell->display->config, "notify::monitor-yresolution", G_CALLBACK (gimp_display_shell_monitor_res_notify_handler), shell); g_signal_connect (shell->display->config->default_view, "notify::padding-mode", G_CALLBACK (gimp_display_shell_padding_notify_handler), shell); g_signal_connect (shell->display->config->default_view, "notify::padding-color", G_CALLBACK (gimp_display_shell_padding_notify_handler), shell); g_signal_connect (shell->display->config->default_fullscreen_view, "notify::padding-mode", G_CALLBACK (gimp_display_shell_padding_notify_handler), shell); g_signal_connect (shell->display->config->default_fullscreen_view, "notify::padding-color", G_CALLBACK (gimp_display_shell_padding_notify_handler), shell); g_signal_connect (shell->display->config, "notify::marching-ants-speed", G_CALLBACK (gimp_display_shell_ants_speed_notify_handler), shell); g_signal_connect (shell->display->config, "notify::zoom-quality", G_CALLBACK (gimp_display_shell_quality_notify_handler), shell); gimp_display_shell_invalidate_preview_handler (image, shell); gimp_display_shell_quick_mask_changed_handler (image, shell); gimp_display_shell_profile_changed_handler (GIMP_COLOR_MANAGED (image), shell); gimp_canvas_layer_boundary_set_layer (GIMP_CANVAS_LAYER_BOUNDARY (shell->layer_boundary), gimp_image_get_active_layer (image)); }
void gimp_display_shell_disconnect (GimpDisplayShell *shell) { GimpImage *image; GimpContainer *vectors; GList *list; g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); g_return_if_fail (GIMP_IS_DISPLAY (shell->display)); image = gimp_display_get_image (shell->display); g_return_if_fail (GIMP_IS_IMAGE (image)); vectors = gimp_image_get_vectors (image); gimp_display_shell_icon_update_stop (shell); gimp_canvas_layer_boundary_set_layer (GIMP_CANVAS_LAYER_BOUNDARY (shell->layer_boundary), NULL); g_signal_handlers_disconnect_by_func (shell->display->config, gimp_display_shell_quality_notify_handler, shell); g_signal_handlers_disconnect_by_func (shell->display->config, gimp_display_shell_ants_speed_notify_handler, shell); g_signal_handlers_disconnect_by_func (shell->display->config->default_fullscreen_view, gimp_display_shell_padding_notify_handler, shell); g_signal_handlers_disconnect_by_func (shell->display->config->default_view, gimp_display_shell_padding_notify_handler, shell); g_signal_handlers_disconnect_by_func (shell->display->config, gimp_display_shell_monitor_res_notify_handler, shell); g_signal_handlers_disconnect_by_func (shell->display->config, gimp_display_shell_nav_size_notify_handler, shell); g_signal_handlers_disconnect_by_func (shell->display->config, gimp_display_shell_title_notify_handler, shell); g_signal_handlers_disconnect_by_func (shell->display->config, gimp_display_shell_check_notify_handler, shell); g_signal_handlers_disconnect_by_func (vectors, gimp_display_shell_vectors_remove_handler, shell); g_signal_handlers_disconnect_by_func (vectors, gimp_display_shell_vectors_add_handler, shell); gimp_tree_handler_disconnect (shell->vectors_visible_handler); shell->vectors_visible_handler = NULL; gimp_tree_handler_disconnect (shell->vectors_thaw_handler); shell->vectors_thaw_handler = NULL; gimp_tree_handler_disconnect (shell->vectors_freeze_handler); shell->vectors_freeze_handler = NULL; g_signal_handlers_disconnect_by_func (image, gimp_display_shell_active_vectors_handler, shell); for (list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (vectors)); list; list = g_list_next (list)) { gimp_canvas_proxy_group_remove_item (GIMP_CANVAS_PROXY_GROUP (shell->vectors), list->data); } g_signal_handlers_disconnect_by_func (image, gimp_display_shell_exported_handler, shell); g_signal_handlers_disconnect_by_func (image, gimp_display_shell_saved_handler, shell); g_signal_handlers_disconnect_by_func (image, gimp_display_shell_profile_changed_handler, shell); g_signal_handlers_disconnect_by_func (image, gimp_display_shell_precision_changed_handler, shell); g_signal_handlers_disconnect_by_func (image, gimp_display_shell_invalidate_preview_handler, shell); g_signal_handlers_disconnect_by_func (image, gimp_display_shell_guide_add_handler, shell); g_signal_handlers_disconnect_by_func (image, gimp_display_shell_guide_remove_handler, shell); g_signal_handlers_disconnect_by_func (image, gimp_display_shell_guide_move_handler, shell); for (list = gimp_image_get_guides (image); list; list = g_list_next (list)) { gimp_canvas_proxy_group_remove_item (GIMP_CANVAS_PROXY_GROUP (shell->guides), list->data); } g_signal_handlers_disconnect_by_func (image, gimp_display_shell_sample_point_add_handler, shell); g_signal_handlers_disconnect_by_func (image, gimp_display_shell_sample_point_remove_handler, shell); g_signal_handlers_disconnect_by_func (image, gimp_display_shell_sample_point_move_handler, shell); for (list = gimp_image_get_sample_points (image); list; list = g_list_next (list)) { gimp_canvas_proxy_group_remove_item (GIMP_CANVAS_PROXY_GROUP (shell->sample_points), list->data); } g_signal_handlers_disconnect_by_func (image, gimp_display_shell_quick_mask_changed_handler, shell); g_signal_handlers_disconnect_by_func (image, gimp_display_shell_resolution_changed_handler, shell); g_signal_handlers_disconnect_by_func (image, gimp_display_shell_size_changed_detailed_handler, shell); g_signal_handlers_disconnect_by_func (image, gimp_display_shell_selection_invalidate_handler, shell); g_signal_handlers_disconnect_by_func (image, gimp_display_shell_name_changed_handler, shell); g_signal_handlers_disconnect_by_func (gimp_image_get_grid (image), gimp_display_shell_grid_notify_handler, shell); g_signal_handlers_disconnect_by_func (image, gimp_display_shell_undo_event_handler, shell); g_signal_handlers_disconnect_by_func (image, gimp_display_shell_clean_dirty_handler, shell); }
GtkWidget * grid_dialog_new (GimpImage *image, GimpContext *context, GtkWidget *parent) { GimpGrid *grid; GimpGrid *grid_backup; GtkWidget *dialog; GtkWidget *editor; gdouble xres; gdouble yres; g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); g_return_val_if_fail (parent == NULL || GTK_IS_WIDGET (parent), NULL); gimp_image_get_resolution (image, &xres, &yres); grid = gimp_image_get_grid (GIMP_IMAGE (image)); grid_backup = gimp_config_duplicate (GIMP_CONFIG (grid)); dialog = gimp_viewable_dialog_new (GIMP_VIEWABLE (image), context, _("Configure Grid"), "gimp-grid-configure", GIMP_STOCK_GRID, _("Configure Image Grid"), parent, gimp_standard_help_func, GIMP_HELP_IMAGE_GRID, GIMP_STOCK_RESET, GRID_RESPONSE_RESET, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog), GRID_RESPONSE_RESET, GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); g_signal_connect (dialog, "response", G_CALLBACK (grid_dialog_response), dialog); editor = gimp_grid_editor_new (grid, context, xres, yres); gtk_container_set_border_width (GTK_CONTAINER (editor), 12); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), editor, TRUE, TRUE, 0); gtk_widget_show (editor); g_object_set_data (G_OBJECT (dialog), "image", image); g_object_set_data (G_OBJECT (dialog), "grid", grid); g_object_set_data_full (G_OBJECT (dialog), "grid-backup", grid_backup, (GDestroyNotify) g_object_unref); return dialog; }