app: add gimp_grid_get_spacing() and gimp_grid_get_offset()
and do the rounding to integer there instead of in several places.
This commit is contained in:
@ -26,6 +26,7 @@
|
|||||||
#include <gegl.h>
|
#include <gegl.h>
|
||||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||||
|
|
||||||
|
#include "libgimpmath/gimpmath.h"
|
||||||
#include "libgimpbase/gimpbase.h"
|
#include "libgimpbase/gimpbase.h"
|
||||||
#include "libgimpconfig/gimpconfig.h"
|
#include "libgimpconfig/gimpconfig.h"
|
||||||
|
|
||||||
@ -225,6 +226,30 @@ gimp_grid_set_property (GObject *object,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gimp_grid_get_spacing (GimpGrid *grid,
|
||||||
|
gdouble *xspacing,
|
||||||
|
gdouble *yspacing)
|
||||||
|
{
|
||||||
|
g_return_if_fail (GIMP_IS_GRID (grid));
|
||||||
|
|
||||||
|
/* FIXME subpixel grid */
|
||||||
|
if (xspacing) *xspacing = RINT (grid->xspacing);
|
||||||
|
if (yspacing) *yspacing = RINT (grid->yspacing);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gimp_grid_get_offset (GimpGrid *grid,
|
||||||
|
gdouble *xoffset,
|
||||||
|
gdouble *yoffset)
|
||||||
|
{
|
||||||
|
g_return_if_fail (GIMP_IS_GRID (grid));
|
||||||
|
|
||||||
|
/* FIXME subpixel grid */
|
||||||
|
if (xoffset) *xoffset = RINT (grid->xoffset);
|
||||||
|
if (yoffset) *yoffset = RINT (grid->yoffset);
|
||||||
|
}
|
||||||
|
|
||||||
const gchar *
|
const gchar *
|
||||||
gimp_grid_parasite_name (void)
|
gimp_grid_parasite_name (void)
|
||||||
{
|
{
|
||||||
|
@ -58,6 +58,14 @@ struct _GimpGridClass
|
|||||||
|
|
||||||
|
|
||||||
GType gimp_grid_get_type (void) G_GNUC_CONST;
|
GType gimp_grid_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
|
void gimp_grid_get_spacing (GimpGrid *grid,
|
||||||
|
gdouble *xspacing,
|
||||||
|
gdouble *yspacing);
|
||||||
|
void gimp_grid_get_offset (GimpGrid *grid,
|
||||||
|
gdouble *xoffset,
|
||||||
|
gdouble *yoffset);
|
||||||
|
|
||||||
const gchar * gimp_grid_parasite_name (void) G_GNUC_CONST;
|
const gchar * gimp_grid_parasite_name (void) G_GNUC_CONST;
|
||||||
GimpParasite * gimp_grid_to_parasite (const GimpGrid *grid);
|
GimpParasite * gimp_grid_to_parasite (const GimpGrid *grid);
|
||||||
GimpGrid * gimp_grid_from_parasite (const GimpParasite *parasite);
|
GimpGrid * gimp_grid_from_parasite (const GimpParasite *parasite);
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "core-types.h"
|
#include "core-types.h"
|
||||||
|
|
||||||
#include "gimp.h"
|
#include "gimp.h"
|
||||||
|
#include "gimpgrid.h"
|
||||||
#include "gimpguide.h"
|
#include "gimpguide.h"
|
||||||
#include "gimpimage.h"
|
#include "gimpimage.h"
|
||||||
#include "gimpimage-grid.h"
|
#include "gimpimage-grid.h"
|
||||||
@ -101,16 +102,8 @@ gimp_image_snap_x (GimpImage *image,
|
|||||||
gdouble xoffset;
|
gdouble xoffset;
|
||||||
gdouble i;
|
gdouble i;
|
||||||
|
|
||||||
g_object_get (grid,
|
gimp_grid_get_spacing (grid, &xspacing, NULL);
|
||||||
"xspacing", &xspacing,
|
gimp_grid_get_offset (grid, &xoffset, NULL);
|
||||||
"xoffset", &xoffset,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
/* FIXME subpixel grid */
|
|
||||||
xspacing = RINT (xspacing);
|
|
||||||
xoffset = RINT (xoffset);
|
|
||||||
|
|
||||||
g_printerr ("snap: spacing = %f offset = %f\n", xspacing, xoffset);
|
|
||||||
|
|
||||||
/* the snap-to-grid part could probably be rewritten */
|
/* the snap-to-grid part could probably be rewritten */
|
||||||
while (xoffset > xspacing)
|
while (xoffset > xspacing)
|
||||||
@ -194,14 +187,8 @@ gimp_image_snap_y (GimpImage *image,
|
|||||||
gdouble yoffset;
|
gdouble yoffset;
|
||||||
gdouble i;
|
gdouble i;
|
||||||
|
|
||||||
g_object_get (grid,
|
gimp_grid_get_spacing (grid, NULL, &yspacing);
|
||||||
"yspacing", &yspacing,
|
gimp_grid_get_offset (grid, NULL, &yoffset);
|
||||||
"yoffset", &yoffset,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
/* FIXME subpixel grid */
|
|
||||||
yspacing = RINT (yspacing);
|
|
||||||
yoffset = RINT (yoffset);
|
|
||||||
|
|
||||||
while (yoffset > yspacing)
|
while (yoffset > yspacing)
|
||||||
yoffset -= yspacing;
|
yoffset -= yspacing;
|
||||||
@ -306,18 +293,8 @@ gimp_image_snap_point (GimpImage *image,
|
|||||||
gdouble xoffset, yoffset;
|
gdouble xoffset, yoffset;
|
||||||
gdouble i;
|
gdouble i;
|
||||||
|
|
||||||
g_object_get (grid,
|
gimp_grid_get_spacing (grid, &xspacing, &yspacing);
|
||||||
"xspacing", &xspacing,
|
gimp_grid_get_offset (grid, &xoffset, &yoffset);
|
||||||
"yspacing", &yspacing,
|
|
||||||
"xoffset", &xoffset,
|
|
||||||
"yoffset", &yoffset,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
/* FIXME subpixel grid */
|
|
||||||
xspacing = RINT (xspacing);
|
|
||||||
yspacing = RINT (yspacing);
|
|
||||||
xoffset = RINT (xoffset);
|
|
||||||
yoffset = RINT (yoffset);
|
|
||||||
|
|
||||||
while (xoffset > xspacing)
|
while (xoffset > xspacing)
|
||||||
xoffset -= xspacing;
|
xoffset -= xspacing;
|
||||||
|
@ -200,18 +200,8 @@ gimp_canvas_grid_draw (GimpCanvasItem *item,
|
|||||||
|
|
||||||
#define CROSSHAIR 2
|
#define CROSSHAIR 2
|
||||||
|
|
||||||
g_object_get (private->grid,
|
gimp_grid_get_spacing (private->grid, &xspacing, &yspacing);
|
||||||
"xspacing", &xspacing,
|
gimp_grid_get_offset (private->grid, &xoffset, &yoffset);
|
||||||
"yspacing", &yspacing,
|
|
||||||
"xoffset", &xoffset,
|
|
||||||
"yoffset", &yoffset,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
/* FIXME subpixel grid */
|
|
||||||
xspacing = RINT (xspacing);
|
|
||||||
yspacing = RINT (yspacing);
|
|
||||||
xoffset = RINT (xoffset);
|
|
||||||
yoffset = RINT (yoffset);
|
|
||||||
|
|
||||||
g_return_if_fail (xspacing > 0.0 &&
|
g_return_if_fail (xspacing > 0.0 &&
|
||||||
yspacing > 0.0);
|
yspacing > 0.0);
|
||||||
|
Reference in New Issue
Block a user