2010-03-07 01:55:31 +01:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2010-03-07 01:55:31 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-10-15 01:58:39 +02:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2010-03-07 01:55:31 +01:00
|
|
|
#include <gegl.h>
|
|
|
|
|
2017-06-22 09:43:50 +02:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2010-03-07 01:55:31 +01:00
|
|
|
#include "core-types.h"
|
|
|
|
|
|
|
|
#include "gimpgrouplayer.h"
|
2017-06-22 09:43:50 +02:00
|
|
|
#include "gimpguide.h"
|
2010-03-07 01:55:31 +01:00
|
|
|
#include "gimpimage.h"
|
2017-06-22 08:16:43 +02:00
|
|
|
#include "gimpimage-pick-item.h"
|
2017-06-22 09:43:50 +02:00
|
|
|
#include "gimpimage-private.h"
|
2010-03-07 01:55:31 +01:00
|
|
|
#include "gimppickable.h"
|
2017-06-22 09:43:50 +02:00
|
|
|
#include "gimpsamplepoint.h"
|
2010-03-07 01:55:31 +01:00
|
|
|
|
|
|
|
#include "text/gimptextlayer.h"
|
|
|
|
|
2017-06-22 11:35:57 +02:00
|
|
|
#include "vectors/gimpstroke.h"
|
|
|
|
#include "vectors/gimpvectors.h"
|
|
|
|
|
2010-03-07 01:55:31 +01:00
|
|
|
|
|
|
|
GimpLayer *
|
2016-05-19 23:51:44 +02:00
|
|
|
gimp_image_pick_layer (GimpImage *image,
|
|
|
|
gint x,
|
2018-12-15 23:34:07 +01:00
|
|
|
gint y,
|
|
|
|
GimpLayer *previously_picked)
|
2010-03-07 01:55:31 +01:00
|
|
|
{
|
|
|
|
GList *all_layers;
|
|
|
|
GList *list;
|
2018-12-15 23:34:07 +01:00
|
|
|
gint off_x, off_y;
|
|
|
|
gint tries = 1;
|
2010-03-07 01:55:31 +01:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
|
|
|
|
|
|
|
all_layers = gimp_image_get_layer_list (image);
|
|
|
|
|
2018-12-15 23:34:07 +01:00
|
|
|
if (previously_picked)
|
2010-03-07 01:55:31 +01:00
|
|
|
{
|
2018-12-15 23:34:07 +01:00
|
|
|
gimp_item_get_offset (GIMP_ITEM (previously_picked), &off_x, &off_y);
|
|
|
|
if (gimp_pickable_get_opacity_at (GIMP_PICKABLE (previously_picked),
|
|
|
|
x - off_x, y - off_y) <= 0.25)
|
|
|
|
previously_picked = NULL;
|
|
|
|
else
|
|
|
|
tries++;
|
|
|
|
}
|
2010-03-07 01:55:31 +01:00
|
|
|
|
2018-12-15 23:34:07 +01:00
|
|
|
while (tries)
|
|
|
|
{
|
|
|
|
for (list = all_layers; list; list = g_list_next (list))
|
2010-03-07 01:55:31 +01:00
|
|
|
{
|
2018-12-15 23:34:07 +01:00
|
|
|
GimpLayer *layer = list->data;
|
|
|
|
|
|
|
|
if (previously_picked)
|
|
|
|
{
|
|
|
|
/* Take the first layer with a pixel at given coordinates
|
|
|
|
* after the previously picked one.
|
|
|
|
*/
|
|
|
|
if (layer == previously_picked)
|
|
|
|
previously_picked = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_item_get_offset (GIMP_ITEM (layer), &off_x, &off_y);
|
|
|
|
|
|
|
|
if (gimp_pickable_get_opacity_at (GIMP_PICKABLE (layer),
|
|
|
|
x - off_x, y - off_y) > 0.25)
|
|
|
|
{
|
|
|
|
g_list_free (all_layers);
|
|
|
|
|
|
|
|
return layer;
|
|
|
|
}
|
2010-03-07 01:55:31 +01:00
|
|
|
}
|
2018-12-15 23:34:07 +01:00
|
|
|
tries--;
|
2010-03-07 01:55:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (all_layers);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-03-29 13:58:23 +02:00
|
|
|
GimpLayer *
|
2016-05-19 23:51:44 +02:00
|
|
|
gimp_image_pick_layer_by_bounds (GimpImage *image,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
2011-03-29 13:58:23 +02:00
|
|
|
{
|
|
|
|
GList *all_layers;
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
|
|
|
|
|
|
|
all_layers = gimp_image_get_layer_list (image);
|
|
|
|
|
|
|
|
for (list = all_layers; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpLayer *layer = list->data;
|
|
|
|
|
2012-05-17 00:07:46 +02:00
|
|
|
if (gimp_item_is_visible (GIMP_ITEM (layer)))
|
2011-03-29 13:58:23 +02:00
|
|
|
{
|
|
|
|
gint off_x, off_y;
|
|
|
|
gint width, height;
|
|
|
|
|
|
|
|
gimp_item_get_offset (GIMP_ITEM (layer), &off_x, &off_y);
|
|
|
|
width = gimp_item_get_width (GIMP_ITEM (layer));
|
|
|
|
height = gimp_item_get_height (GIMP_ITEM (layer));
|
|
|
|
|
|
|
|
if (x >= off_x &&
|
|
|
|
y >= off_y &&
|
|
|
|
x < off_x + width &&
|
|
|
|
y < off_y + height)
|
|
|
|
{
|
|
|
|
g_list_free (all_layers);
|
|
|
|
|
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (all_layers);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-03-07 01:55:31 +01:00
|
|
|
GimpTextLayer *
|
2016-05-19 23:51:44 +02:00
|
|
|
gimp_image_pick_text_layer (GimpImage *image,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
2010-03-07 01:55:31 +01:00
|
|
|
{
|
|
|
|
GList *all_layers;
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
|
|
|
|
|
|
|
all_layers = gimp_image_get_layer_list (image);
|
|
|
|
|
|
|
|
for (list = all_layers; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpLayer *layer = list->data;
|
|
|
|
gint off_x, off_y;
|
|
|
|
|
|
|
|
gimp_item_get_offset (GIMP_ITEM (layer), &off_x, &off_y);
|
|
|
|
|
|
|
|
if (GIMP_IS_TEXT_LAYER (layer) &&
|
|
|
|
x >= off_x &&
|
|
|
|
y >= off_y &&
|
|
|
|
x < off_x + gimp_item_get_width (GIMP_ITEM (layer)) &&
|
2012-05-17 00:07:46 +02:00
|
|
|
y < off_y + gimp_item_get_height (GIMP_ITEM (layer)) &&
|
|
|
|
gimp_item_is_visible (GIMP_ITEM (layer)))
|
2010-03-07 01:55:31 +01:00
|
|
|
{
|
|
|
|
g_list_free (all_layers);
|
|
|
|
|
|
|
|
return GIMP_TEXT_LAYER (layer);
|
|
|
|
}
|
2011-08-20 15:01:46 +02:00
|
|
|
else if (gimp_pickable_get_opacity_at (GIMP_PICKABLE (layer),
|
2012-04-21 16:05:49 +02:00
|
|
|
x - off_x, y - off_y) > 0.25)
|
2010-03-07 01:55:31 +01:00
|
|
|
{
|
|
|
|
/* a normal layer covers any possible text layers below,
|
|
|
|
* bail out
|
|
|
|
*/
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (all_layers);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-06-22 09:43:50 +02:00
|
|
|
|
2017-06-22 11:35:57 +02:00
|
|
|
GimpVectors *
|
|
|
|
gimp_image_pick_vectors (GimpImage *image,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble epsilon_x,
|
|
|
|
gdouble epsilon_y)
|
|
|
|
{
|
|
|
|
GimpVectors *ret = NULL;
|
|
|
|
GList *all_vectors;
|
|
|
|
GList *list;
|
|
|
|
gdouble mindist = G_MAXDOUBLE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
|
|
|
|
|
|
|
all_vectors = gimp_image_get_vectors_list (image);
|
|
|
|
|
|
|
|
for (list = all_vectors; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpVectors *vectors = list->data;
|
|
|
|
|
|
|
|
if (gimp_item_is_visible (GIMP_ITEM (vectors)))
|
|
|
|
{
|
|
|
|
GimpStroke *stroke = NULL;
|
|
|
|
GimpCoords coords = GIMP_COORDS_DEFAULT_VALUES;
|
|
|
|
|
|
|
|
while ((stroke = gimp_vectors_stroke_get_next (vectors, stroke)))
|
|
|
|
{
|
|
|
|
gdouble dist;
|
|
|
|
|
|
|
|
coords.x = x;
|
|
|
|
coords.y = y;
|
|
|
|
|
|
|
|
dist = gimp_stroke_nearest_point_get (stroke, &coords, 1.0,
|
|
|
|
NULL, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
if (dist >= 0.0 &&
|
|
|
|
dist < MIN (epsilon_y, mindist))
|
|
|
|
{
|
|
|
|
mindist = dist;
|
|
|
|
ret = vectors;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (all_vectors);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
app: allow moving an intersecting pair of guides with the Move tool
This commit adds support for moving together an intersecting pair
of guides using the Move tool, by dragging the guides at their
point of intersection. This is useful when the guides are used to
mark a point, rather than a pair of lines (e.g., as is the case for
the mandala symmetry guides, which mark the symmetry's point of
origin).
Add gimp_image_pick_guides(), which can return a set of guides,
rather than a single guide. The API allows an arbitrary set of
guides to be returned, but, in practice, at most two intersecting
guides are returned, as per the above.
In GimpMoveTool and GimpGuideTool, add support for moving multiple
guides together, and, in GimpMoveTool, use gimp_image_pick_guides()
to potentially pick multiple guides.
2019-05-30 01:39:26 -04:00
|
|
|
static GimpGuide *
|
|
|
|
gimp_image_pick_guide_internal (GimpImage *image,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble epsilon_x,
|
|
|
|
gdouble epsilon_y,
|
|
|
|
GimpOrientationType orientation)
|
2017-06-22 09:43:50 +02:00
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
GimpGuide *ret = NULL;
|
|
|
|
gdouble mindist = G_MAXDOUBLE;
|
|
|
|
|
|
|
|
for (list = GIMP_IMAGE_GET_PRIVATE (image)->guides;
|
|
|
|
list;
|
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpGuide *guide = list->data;
|
|
|
|
gint position = gimp_guide_get_position (guide);
|
|
|
|
gdouble dist;
|
|
|
|
|
|
|
|
switch (gimp_guide_get_orientation (guide))
|
|
|
|
{
|
|
|
|
case GIMP_ORIENTATION_HORIZONTAL:
|
app: allow moving an intersecting pair of guides with the Move tool
This commit adds support for moving together an intersecting pair
of guides using the Move tool, by dragging the guides at their
point of intersection. This is useful when the guides are used to
mark a point, rather than a pair of lines (e.g., as is the case for
the mandala symmetry guides, which mark the symmetry's point of
origin).
Add gimp_image_pick_guides(), which can return a set of guides,
rather than a single guide. The API allows an arbitrary set of
guides to be returned, but, in practice, at most two intersecting
guides are returned, as per the above.
In GimpMoveTool and GimpGuideTool, add support for moving multiple
guides together, and, in GimpMoveTool, use gimp_image_pick_guides()
to potentially pick multiple guides.
2019-05-30 01:39:26 -04:00
|
|
|
if (orientation == GIMP_ORIENTATION_HORIZONTAL ||
|
|
|
|
orientation == GIMP_ORIENTATION_UNKNOWN)
|
2017-06-22 09:43:50 +02:00
|
|
|
{
|
app: allow moving an intersecting pair of guides with the Move tool
This commit adds support for moving together an intersecting pair
of guides using the Move tool, by dragging the guides at their
point of intersection. This is useful when the guides are used to
mark a point, rather than a pair of lines (e.g., as is the case for
the mandala symmetry guides, which mark the symmetry's point of
origin).
Add gimp_image_pick_guides(), which can return a set of guides,
rather than a single guide. The API allows an arbitrary set of
guides to be returned, but, in practice, at most two intersecting
guides are returned, as per the above.
In GimpMoveTool and GimpGuideTool, add support for moving multiple
guides together, and, in GimpMoveTool, use gimp_image_pick_guides()
to potentially pick multiple guides.
2019-05-30 01:39:26 -04:00
|
|
|
dist = ABS (position - y);
|
|
|
|
if (dist < MIN (epsilon_y, mindist))
|
|
|
|
{
|
|
|
|
mindist = dist;
|
|
|
|
ret = guide;
|
|
|
|
}
|
2017-06-22 09:43:50 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* mindist always is in vertical resolution to make it comparable */
|
|
|
|
case GIMP_ORIENTATION_VERTICAL:
|
app: allow moving an intersecting pair of guides with the Move tool
This commit adds support for moving together an intersecting pair
of guides using the Move tool, by dragging the guides at their
point of intersection. This is useful when the guides are used to
mark a point, rather than a pair of lines (e.g., as is the case for
the mandala symmetry guides, which mark the symmetry's point of
origin).
Add gimp_image_pick_guides(), which can return a set of guides,
rather than a single guide. The API allows an arbitrary set of
guides to be returned, but, in practice, at most two intersecting
guides are returned, as per the above.
In GimpMoveTool and GimpGuideTool, add support for moving multiple
guides together, and, in GimpMoveTool, use gimp_image_pick_guides()
to potentially pick multiple guides.
2019-05-30 01:39:26 -04:00
|
|
|
if (orientation == GIMP_ORIENTATION_VERTICAL ||
|
|
|
|
orientation == GIMP_ORIENTATION_UNKNOWN)
|
2017-06-22 09:43:50 +02:00
|
|
|
{
|
app: allow moving an intersecting pair of guides with the Move tool
This commit adds support for moving together an intersecting pair
of guides using the Move tool, by dragging the guides at their
point of intersection. This is useful when the guides are used to
mark a point, rather than a pair of lines (e.g., as is the case for
the mandala symmetry guides, which mark the symmetry's point of
origin).
Add gimp_image_pick_guides(), which can return a set of guides,
rather than a single guide. The API allows an arbitrary set of
guides to be returned, but, in practice, at most two intersecting
guides are returned, as per the above.
In GimpMoveTool and GimpGuideTool, add support for moving multiple
guides together, and, in GimpMoveTool, use gimp_image_pick_guides()
to potentially pick multiple guides.
2019-05-30 01:39:26 -04:00
|
|
|
dist = ABS (position - x);
|
|
|
|
if (dist < MIN (epsilon_x, mindist / epsilon_y * epsilon_x))
|
|
|
|
{
|
|
|
|
mindist = dist * epsilon_y / epsilon_x;
|
|
|
|
ret = guide;
|
|
|
|
}
|
2017-06-22 09:43:50 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
app: allow moving an intersecting pair of guides with the Move tool
This commit adds support for moving together an intersecting pair
of guides using the Move tool, by dragging the guides at their
point of intersection. This is useful when the guides are used to
mark a point, rather than a pair of lines (e.g., as is the case for
the mandala symmetry guides, which mark the symmetry's point of
origin).
Add gimp_image_pick_guides(), which can return a set of guides,
rather than a single guide. The API allows an arbitrary set of
guides to be returned, but, in practice, at most two intersecting
guides are returned, as per the above.
In GimpMoveTool and GimpGuideTool, add support for moving multiple
guides together, and, in GimpMoveTool, use gimp_image_pick_guides()
to potentially pick multiple guides.
2019-05-30 01:39:26 -04:00
|
|
|
GimpGuide *
|
|
|
|
gimp_image_pick_guide (GimpImage *image,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble epsilon_x,
|
|
|
|
gdouble epsilon_y)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
|
|
|
g_return_val_if_fail (epsilon_x > 0 && epsilon_y > 0, NULL);
|
|
|
|
|
|
|
|
return gimp_image_pick_guide_internal (image, x, y, epsilon_x, epsilon_y,
|
|
|
|
GIMP_ORIENTATION_UNKNOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
GList *
|
|
|
|
gimp_image_pick_guides (GimpImage *image,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble epsilon_x,
|
|
|
|
gdouble epsilon_y)
|
|
|
|
{
|
|
|
|
GimpGuide *guide;
|
|
|
|
GList *result = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
|
|
|
g_return_val_if_fail (epsilon_x > 0 && epsilon_y > 0, NULL);
|
|
|
|
|
|
|
|
guide = gimp_image_pick_guide_internal (image, x, y, epsilon_x, epsilon_y,
|
|
|
|
GIMP_ORIENTATION_HORIZONTAL);
|
|
|
|
|
|
|
|
if (guide)
|
|
|
|
result = g_list_append (result, guide);
|
|
|
|
|
|
|
|
guide = gimp_image_pick_guide_internal (image, x, y, epsilon_x, epsilon_y,
|
|
|
|
GIMP_ORIENTATION_VERTICAL);
|
|
|
|
|
|
|
|
if (guide)
|
|
|
|
result = g_list_append (result, guide);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-06-22 09:43:50 +02:00
|
|
|
GimpSamplePoint *
|
|
|
|
gimp_image_pick_sample_point (GimpImage *image,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble epsilon_x,
|
|
|
|
gdouble epsilon_y)
|
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
GimpSamplePoint *ret = NULL;
|
|
|
|
gdouble mindist = G_MAXDOUBLE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
|
|
|
g_return_val_if_fail (epsilon_x > 0 && epsilon_y > 0, NULL);
|
|
|
|
|
|
|
|
if (x < 0 || x >= gimp_image_get_width (image) ||
|
|
|
|
y < 0 || y >= gimp_image_get_height (image))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (list = GIMP_IMAGE_GET_PRIVATE (image)->sample_points;
|
|
|
|
list;
|
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpSamplePoint *sample_point = list->data;
|
|
|
|
gint sp_x;
|
|
|
|
gint sp_y;
|
|
|
|
gdouble dist;
|
|
|
|
|
|
|
|
gimp_sample_point_get_position (sample_point, &sp_x, &sp_y);
|
|
|
|
|
|
|
|
if (sp_x < 0 || sp_y < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
dist = hypot ((sp_x + 0.5) - x,
|
|
|
|
(sp_y + 0.5) - y);
|
|
|
|
if (dist < MIN (epsilon_y, mindist))
|
|
|
|
{
|
|
|
|
mindist = dist;
|
|
|
|
ret = sample_point;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|