Commit a0129504 authored by Michael Natterer's avatar Michael Natterer 😴

Issue #1805 - Sample Points keep resetting themselves to "Pixel"

Remember the sample point's GimpColorPickMode in the sample point
itself, so it is remembered across switching between images.

Not persistent in the XCF yet tho...
parent 2aaa1334
......@@ -131,6 +131,27 @@ gimp_image_move_sample_point (GimpImage *image,
gimp_image_sample_point_moved (image, sample_point);
}
void
gimp_image_set_sample_point_pick_mode (GimpImage *image,
GimpSamplePoint *sample_point,
GimpColorPickMode pick_mode,
gboolean push_undo)
{
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (GIMP_IS_SAMPLE_POINT (sample_point));
if (push_undo)
gimp_image_undo_push_sample_point (image,
C_("undo-type",
"Set Sample Point Pick Mode"),
sample_point);
gimp_sample_point_set_pick_mode (sample_point, pick_mode);
/* well... */
gimp_image_sample_point_moved (image, sample_point);
}
GList *
gimp_image_get_sample_points (GimpImage *image)
{
......
......@@ -43,6 +43,11 @@ void gimp_image_move_sample_point (GimpImage *image,
gint x,
gint y,
gboolean push_undo);
void gimp_image_set_sample_point_pick_mode
(GimpImage *image,
GimpSamplePoint *sample_point,
GimpColorPickMode pick_mode,
gboolean push_undo);
GList * gimp_image_get_sample_points (GimpImage *image);
GimpSamplePoint * gimp_image_get_sample_point (GimpImage *image,
......
......@@ -31,14 +31,16 @@ enum
{
PROP_0,
PROP_POSITION_X,
PROP_POSITION_Y
PROP_POSITION_Y,
PROP_PICK_MODE
};
struct _GimpSamplePointPrivate
{
gint position_x;
gint position_y;
gint position_x;
gint position_y;
GimpColorPickMode pick_mode;
};
......@@ -79,6 +81,13 @@ gimp_sample_point_class_init (GimpSamplePointClass *klass)
GIMP_SAMPLE_POINT_POSITION_UNDEFINED,
0);
GIMP_CONFIG_PROP_ENUM (object_class, PROP_PICK_MODE,
"pick-mode",
NULL, NULL,
GIMP_TYPE_COLOR_PICK_MODE,
GIMP_COLOR_PICK_MODE_PIXEL,
0);
g_type_class_add_private (klass, sizeof (GimpSamplePointPrivate));
}
......@@ -106,6 +115,9 @@ gimp_sample_point_get_property (GObject *object,
case PROP_POSITION_Y:
g_value_set_int (value, sample_point->priv->position_y);
break;
case PROP_PICK_MODE:
g_value_set_enum (value, sample_point->priv->pick_mode);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
......@@ -129,6 +141,9 @@ gimp_sample_point_set_property (GObject *object,
case PROP_POSITION_Y:
sample_point->priv->position_y = g_value_get_int (value);
break;
case PROP_PICK_MODE:
sample_point->priv->pick_mode = g_value_get_enum (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
......@@ -164,13 +179,40 @@ gimp_sample_point_set_position (GimpSamplePoint *sample_point,
{
g_return_if_fail (GIMP_IS_SAMPLE_POINT (sample_point));
sample_point->priv->position_x = position_x;
sample_point->priv->position_y = position_y;
if (sample_point->priv->position_x != position_x ||
sample_point->priv->position_y != position_y)
{
sample_point->priv->position_x = position_x;
sample_point->priv->position_y = position_y;
g_object_freeze_notify (G_OBJECT (sample_point));
g_object_notify (G_OBJECT (sample_point), "position-x");
g_object_notify (G_OBJECT (sample_point), "position-y");
g_object_thaw_notify (G_OBJECT (sample_point));
}
}
GimpColorPickMode
gimp_sample_point_get_pick_mode (GimpSamplePoint *sample_point)
{
g_return_val_if_fail (GIMP_IS_SAMPLE_POINT (sample_point),
GIMP_COLOR_PICK_MODE_PIXEL);
g_object_freeze_notify (G_OBJECT (sample_point));
return sample_point->priv->pick_mode;
}
g_object_notify (G_OBJECT (sample_point), "position-x");
g_object_notify (G_OBJECT (sample_point), "position-y");
void
gimp_sample_point_set_pick_mode (GimpSamplePoint *sample_point,
GimpColorPickMode pick_mode)
{
g_return_if_fail (GIMP_IS_SAMPLE_POINT (sample_point));
if (sample_point->priv->pick_mode != pick_mode)
{
sample_point->priv->pick_mode = pick_mode;
g_object_thaw_notify (G_OBJECT (sample_point));
g_object_notify (G_OBJECT (sample_point), "pick-mode");
}
}
......@@ -49,16 +49,20 @@ struct _GimpSamplePointClass
};
GType gimp_sample_point_get_type (void) G_GNUC_CONST;
GType gimp_sample_point_get_type (void) G_GNUC_CONST;
GimpSamplePoint * gimp_sample_point_new (guint32 sample_point_ID);
GimpSamplePoint * gimp_sample_point_new (guint32 sample_point_ID);
void gimp_sample_point_get_position (GimpSamplePoint *sample_point,
gint *position_x,
gint *position_y);
void gimp_sample_point_set_position (GimpSamplePoint *sample_point,
gint position_x,
gint position_y);
void gimp_sample_point_get_position (GimpSamplePoint *sample_point,
gint *position_x,
gint *position_y);
void gimp_sample_point_set_position (GimpSamplePoint *sample_point,
gint position_x,
gint position_y);
GimpColorPickMode gimp_sample_point_get_pick_mode (GimpSamplePoint *sample_point);
void gimp_sample_point_set_pick_mode (GimpSamplePoint *sample_point,
GimpColorPickMode pick_mode);
#endif /* __GIMP_SAMPLE_POINT_H__ */
......@@ -72,6 +72,7 @@ gimp_sample_point_undo_constructed (GObject *object)
gimp_sample_point_get_position (sample_point,
&sample_point_undo->x,
&sample_point_undo->y);
sample_point_undo->pick_mode = gimp_sample_point_get_pick_mode (sample_point);
}
static void
......@@ -83,12 +84,14 @@ gimp_sample_point_undo_pop (GimpUndo *undo,
GimpSamplePoint *sample_point;
gint x;
gint y;
GimpColorPickMode pick_mode;
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
sample_point = GIMP_SAMPLE_POINT (GIMP_AUX_ITEM_UNDO (undo)->aux_item);
gimp_sample_point_get_position (sample_point, &x, &y);
pick_mode = gimp_sample_point_get_pick_mode (sample_point);
if (x == GIMP_SAMPLE_POINT_POSITION_UNDEFINED)
{
......@@ -106,10 +109,13 @@ gimp_sample_point_undo_pop (GimpUndo *undo,
gimp_sample_point_set_position (sample_point,
sample_point_undo->x,
sample_point_undo->y);
gimp_sample_point_set_pick_mode (sample_point,
sample_point_undo->pick_mode);
gimp_image_sample_point_moved (undo->image, sample_point);
}
sample_point_undo->x = x;
sample_point_undo->y = y;
sample_point_undo->x = x;
sample_point_undo->y = y;
sample_point_undo->pick_mode = pick_mode;
}
......@@ -35,10 +35,11 @@ typedef struct _GimpSamplePointUndoClass GimpSamplePointUndoClass;
struct _GimpSamplePointUndo
{
GimpAuxItemUndo parent_instance;
GimpAuxItemUndo parent_instance;
gint x;
gint y;
gint x;
gint y;
GimpColorPickMode pick_mode;
};
struct _GimpSamplePointUndoClass
......
......@@ -85,6 +85,9 @@ static void gimp_sample_point_editor_points_changed (GimpSamplePointEditor *ed
static void gimp_sample_point_editor_dirty (GimpSamplePointEditor *editor,
gint index);
static gboolean gimp_sample_point_editor_update (GimpSamplePointEditor *editor);
static void gimp_sample_point_editor_mode_notify (GimpColorFrame *frame,
const GParamSpec *pspec,
GimpSamplePointEditor *editor);
G_DEFINE_TYPE (GimpSamplePointEditor, gimp_sample_point_editor,
......@@ -472,6 +475,10 @@ gimp_sample_point_editor_points_changed (GimpSamplePointEditor *editor)
gtk_grid_attach (GTK_GRID (editor->grid), editor->color_frames[i],
column, row, 1, 1);
g_signal_connect_object (editor->color_frames[i], "notify::mode",
G_CALLBACK (gimp_sample_point_editor_mode_notify),
editor, 0);
g_object_set_data (G_OBJECT (editor->color_frames[i]),
"dirty", GINT_TO_POINTER (TRUE));
}
......@@ -519,7 +526,7 @@ gimp_sample_point_editor_update (GimpSamplePointEditor *editor)
{
GimpImageEditor *image_editor = GIMP_IMAGE_EDITOR (editor);
GList *sample_points;
gint n_points = 0;
gint n_points;
GList *list;
gint i;
......@@ -536,17 +543,18 @@ gimp_sample_point_editor_update (GimpSamplePointEditor *editor)
i < n_points;
i++, list = g_list_next (list))
{
GimpColorFrame *color_frame = GIMP_COLOR_FRAME (editor->color_frames[i]);
GimpColorFrame *color_frame = GIMP_COLOR_FRAME (editor->color_frames[i]);
if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (color_frame),
"dirty")))
{
GimpSamplePoint *sample_point = list->data;
const Babl *format;
guchar pixel[32];
GimpRGB color;
gint x;
gint y;
GimpSamplePoint *sample_point = list->data;
const Babl *format;
guchar pixel[32];
GimpRGB color;
GimpColorPickMode pick_mode;
gint x;
gint y;
g_object_set_data (G_OBJECT (color_frame),
"dirty", GINT_TO_POINTER (FALSE));
......@@ -569,8 +577,48 @@ gimp_sample_point_editor_update (GimpSamplePointEditor *editor)
{
gimp_color_frame_set_invalid (color_frame);
}
pick_mode = gimp_sample_point_get_pick_mode (sample_point);
gimp_color_frame_set_mode (color_frame, pick_mode);
}
}
return FALSE;
}
static void
gimp_sample_point_editor_mode_notify (GimpColorFrame *frame,
const GParamSpec *pspec,
GimpSamplePointEditor *editor)
{
GimpImageEditor *image_editor = GIMP_IMAGE_EDITOR (editor);
GList *sample_points;
gint n_points;
GList *list;
gint i;
sample_points = gimp_image_get_sample_points (image_editor->image);
n_points = MIN (editor->n_color_frames, g_list_length (sample_points));
for (i = 0, list = sample_points;
i < n_points;
i++, list = g_list_next (list))
{
if (GIMP_COLOR_FRAME (editor->color_frames[i]) == frame)
{
GimpSamplePoint *sample_point = list->data;
GimpColorPickMode pick_mode;
g_object_get (frame, "mode", &pick_mode, NULL);
if (pick_mode != gimp_sample_point_get_pick_mode (sample_point))
gimp_image_set_sample_point_pick_mode (image_editor->image,
sample_point,
pick_mode,
TRUE);
break;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment