app: tag the symmetry properties as pixel-coordinate/pixel-distance

so they get the proper soft limits in the generated GUI. Also rename
some properties for consisency, and add some blank lines for better
readability.
This commit is contained in:
Michael Natterer 2016-07-06 12:37:10 +02:00
parent a96c273621
commit eae2261f16
3 changed files with 100 additions and 49 deletions

View File

@ -103,6 +103,7 @@ gimp_mandala_class_init (GimpMandalaClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpSymmetryClass *symmetry_class = GIMP_SYMMETRY_CLASS (klass);
GParamSpec *pspec;
object_class->constructed = gimp_mandala_constructed;
object_class->finalize = gimp_mandala_finalize;
@ -122,6 +123,10 @@ gimp_mandala_class_init (GimpMandalaClass *klass)
GIMP_PARAM_STATIC_STRINGS |
GIMP_SYMMETRY_PARAM_GUI);
pspec = g_object_class_find_property (object_class, "center-x");
gegl_param_spec_set_property_key (pspec, "unit", "pixel-coordinate");
gegl_param_spec_set_property_key (pspec, "axis", "x");
GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_CENTER_Y,
"center-y",
_("Center ordinate"),
@ -130,6 +135,10 @@ gimp_mandala_class_init (GimpMandalaClass *klass)
GIMP_PARAM_STATIC_STRINGS |
GIMP_SYMMETRY_PARAM_GUI);
pspec = g_object_class_find_property (object_class, "center-y");
gegl_param_spec_set_property_key (pspec, "unit", "pixel-coordinate");
gegl_param_spec_set_property_key (pspec, "axis", "y");
GIMP_CONFIG_PROP_INT (object_class, PROP_SIZE,
"size",
_("Number of points"),
@ -157,10 +166,6 @@ gimp_mandala_constructed (GObject *object)
{
GimpSymmetry *sym = GIMP_SYMMETRY (object);
/* TODO:
* - "center-x" property should be soft-limited by the width;
* - "center-y" property should be soft-limited by the height.
*/
g_signal_connect_object (sym->image, "size-changed-detailed",
G_CALLBACK (gimp_mandala_image_size_changed_cb),
sym, 0);
@ -188,6 +193,7 @@ gimp_mandala_finalize (GObject *object)
if (iter->data)
g_object_unref (G_OBJECT (iter->data));
}
g_list_free (mandala->ops);
mandala->ops = NULL;
}
@ -211,6 +217,7 @@ gimp_mandala_set_property (GObject *object,
g_value_get_double (value) < (gdouble) gimp_image_get_width (image))
{
mandala->center_x = g_value_get_double (value);
if (mandala->vertical_guide)
{
g_signal_handlers_block_by_func (mandala->vertical_guide,
@ -225,11 +232,13 @@ gimp_mandala_set_property (GObject *object,
}
}
break;
case PROP_CENTER_Y:
if (g_value_get_double (value) > 0.0 &&
g_value_get_double (value) < (gdouble) gimp_image_get_height (image))
{
mandala->center_y = g_value_get_double (value);
if (mandala->horizontal_guide)
{
g_signal_handlers_block_by_func (mandala->horizontal_guide,
@ -244,12 +253,15 @@ gimp_mandala_set_property (GObject *object,
}
}
break;
case PROP_SIZE:
mandala->size = g_value_get_int (value);
break;
case PROP_DISABLE_TRANSFORMATION:
mandala->disable_transformation = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@ -258,9 +270,9 @@ gimp_mandala_set_property (GObject *object,
static void
gimp_mandala_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpMandala *mandala = GIMP_MANDALA (object);
@ -293,6 +305,7 @@ gimp_mandala_active_changed (GimpSymmetry *sym)
{
if (! mandala->horizontal_guide)
gimp_mandala_add_guide (mandala, GIMP_ORIENTATION_HORIZONTAL);
if (! mandala->vertical_guide)
gimp_mandala_add_guide (mandala, GIMP_ORIENTATION_VERTICAL);
}
@ -300,6 +313,7 @@ gimp_mandala_active_changed (GimpSymmetry *sym)
{
if (mandala->horizontal_guide)
gimp_mandala_remove_guide (mandala, GIMP_ORIENTATION_HORIZONTAL);
if (mandala->vertical_guide)
gimp_mandala_remove_guide (mandala, GIMP_ORIENTATION_VERTICAL);
}
@ -329,6 +343,7 @@ gimp_mandala_add_guide (GimpMandala *mandala,
/* Mandala guide position at first activation is at canvas middle. */
if (mandala->center_y < 1.0)
mandala->center_y = (gdouble) gimp_image_get_height (image) / 2.0;
position = (gint) mandala->center_y;
}
else
@ -338,8 +353,10 @@ gimp_mandala_add_guide (GimpMandala *mandala,
/* Mandala guide position at first activation is at canvas middle. */
if (mandala->center_x < 1.0)
mandala->center_x = (gdouble) gimp_image_get_width (image) / 2.0;
position = (gint) mandala->center_x;
}
g_signal_connect (guide, "removed",
G_CALLBACK (gimp_mandala_guide_removed_cb),
mandala);
@ -550,8 +567,6 @@ gimp_mandala_image_size_changed_cb (GimpImage *image,
if (previous_width != gimp_image_get_width (image) ||
previous_height != gimp_image_get_height (image))
{
/* TODO: change soft limits of "center-x" and "center-y"
* properties. */
g_signal_emit_by_name (sym, "gui-param-changed", sym->image);
}
}

View File

@ -113,6 +113,7 @@ gimp_mirror_class_init (GimpMirrorClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpSymmetryClass *symmetry_class = GIMP_SYMMETRY_CLASS (klass);
GParamSpec *pspec;
object_class->constructed = gimp_mirror_constructed;
object_class->finalize = gimp_mirror_finalize;
@ -164,6 +165,10 @@ gimp_mirror_class_init (GimpMirrorClass *klass)
GIMP_PARAM_STATIC_STRINGS |
GIMP_SYMMETRY_PARAM_GUI);
pspec = g_object_class_find_property (object_class, "horizontal-position");
gegl_param_spec_set_property_key (pspec, "unit", "pixel-coordinate");
gegl_param_spec_set_property_key (pspec, "axis", "y");
GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_VERTICAL_POSITION,
"vertical-position",
_("Vertical axis position"),
@ -171,6 +176,10 @@ gimp_mirror_class_init (GimpMirrorClass *klass)
0.0, G_MAXDOUBLE, 0.0,
GIMP_PARAM_STATIC_STRINGS |
GIMP_SYMMETRY_PARAM_GUI);
pspec = g_object_class_find_property (object_class, "vertical-position");
gegl_param_spec_set_property_key (pspec, "unit", "pixel-coordinate");
gegl_param_spec_set_property_key (pspec, "axis", "x");
}
static void
@ -183,11 +192,6 @@ gimp_mirror_constructed (GObject *object)
{
GimpSymmetry *sym = GIMP_SYMMETRY (object);
/* TODO:
* - "horizontal-position" property should be soft-limited by the height;
* - "vertical-position" property should be soft-limited by the width.
*/
g_signal_connect_object (sym->image, "size-changed-detailed",
G_CALLBACK (gimp_mirror_image_size_changed_cb),
sym, 0);
@ -236,22 +240,27 @@ gimp_mirror_set_property (GObject *object,
gimp_mirror_set_horizontal_symmetry (mirror,
g_value_get_boolean (value));
break;
case PROP_VERTICAL_SYMMETRY:
gimp_mirror_set_vertical_symmetry (mirror,
g_value_get_boolean (value));
break;
case PROP_POINT_SYMMETRY:
gimp_mirror_set_point_symmetry (mirror,
g_value_get_boolean (value));
break;
case PROP_DISABLE_TRANSFORMATION:
mirror->disable_transformation = g_value_get_boolean (value);
break;
case PROP_HORIZONTAL_POSITION:
if (g_value_get_double (value) > 0.0 &&
g_value_get_double (value) < (gdouble) gimp_image_get_height (image))
{
mirror->horizontal_position = g_value_get_double (value);
if (mirror->horizontal_guide)
{
g_signal_handlers_block_by_func (mirror->horizontal_guide,
@ -266,11 +275,13 @@ gimp_mirror_set_property (GObject *object,
}
}
break;
case PROP_VERTICAL_POSITION:
if (g_value_get_double (value) > 0.0 &&
g_value_get_double (value) < (gdouble) gimp_image_get_width (image))
{
mirror->vertical_position = g_value_get_double (value);
if (mirror->vertical_guide)
{
g_signal_handlers_block_by_func (mirror->vertical_guide,
@ -285,6 +296,7 @@ gimp_mirror_set_property (GObject *object,
}
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@ -365,9 +377,10 @@ gimp_mirror_update_strokes (GimpSymmetry *sym,
g_signal_emit_by_name (sym, "strokes-updated", sym->image);
}
static void gimp_mirror_prepare_operations (GimpMirror *mirror,
gint paint_width,
gint paint_height)
static void
gimp_mirror_prepare_operations (GimpMirror *mirror,
gint paint_width,
gint paint_height)
{
if (paint_width == mirror->last_paint_width &&
paint_height == mirror->last_paint_height)
@ -526,6 +539,7 @@ gimp_mirror_remove_guide (GimpMirror *mirror,
g_signal_handlers_disconnect_by_func (G_OBJECT (guide),
gimp_mirror_guide_position_cb,
mirror);
gimp_image_remove_guide (image, guide, FALSE);
g_object_unref (guide);
@ -568,6 +582,7 @@ gimp_mirror_guide_removed_cb (GObject *object,
g_signal_handlers_disconnect_by_func (G_OBJECT (mirror->vertical_guide),
gimp_mirror_guide_position_cb,
mirror);
gimp_image_remove_guide (symmetry->image,
mirror->vertical_guide,
FALSE);
@ -594,6 +609,7 @@ gimp_mirror_guide_removed_cb (GObject *object,
g_signal_handlers_disconnect_by_func (G_OBJECT (mirror->horizontal_guide),
gimp_mirror_guide_position_cb,
mirror);
gimp_image_remove_guide (symmetry->image,
mirror->horizontal_guide,
FALSE);
@ -646,6 +662,7 @@ gimp_mirror_active_changed (GimpSymmetry *sym)
if ((mirror->horizontal_mirror || mirror->point_symmetry) &&
! mirror->horizontal_guide)
gimp_mirror_add_guide (mirror, GIMP_ORIENTATION_HORIZONTAL);
if ((mirror->vertical_mirror || mirror->point_symmetry) &&
! mirror->vertical_guide)
gimp_mirror_add_guide (mirror, GIMP_ORIENTATION_VERTICAL);
@ -654,6 +671,7 @@ gimp_mirror_active_changed (GimpSymmetry *sym)
{
if (mirror->horizontal_guide)
gimp_mirror_remove_guide (mirror, GIMP_ORIENTATION_HORIZONTAL);
if (mirror->vertical_guide)
gimp_mirror_remove_guide (mirror, GIMP_ORIENTATION_VERTICAL);
}
@ -674,7 +692,9 @@ gimp_mirror_set_horizontal_symmetry (GimpMirror *mirror,
gimp_mirror_add_guide (mirror, GIMP_ORIENTATION_HORIZONTAL);
}
else if (! mirror->point_symmetry)
gimp_mirror_remove_guide (mirror, GIMP_ORIENTATION_HORIZONTAL);
{
gimp_mirror_remove_guide (mirror, GIMP_ORIENTATION_HORIZONTAL);
}
gimp_mirror_reset (mirror);
}
@ -694,7 +714,9 @@ gimp_mirror_set_vertical_symmetry (GimpMirror *mirror,
gimp_mirror_add_guide (mirror, GIMP_ORIENTATION_VERTICAL);
}
else if (! mirror->point_symmetry)
gimp_mirror_remove_guide (mirror, GIMP_ORIENTATION_VERTICAL);
{
gimp_mirror_remove_guide (mirror, GIMP_ORIENTATION_VERTICAL);
}
gimp_mirror_reset (mirror);
}
@ -723,6 +745,7 @@ gimp_mirror_set_point_symmetry (GimpMirror *mirror,
/* Remove the horizontal guide unless needed by horizontal mirror */
if (! mirror->horizontal_mirror)
gimp_mirror_remove_guide (mirror, GIMP_ORIENTATION_HORIZONTAL);
/* Remove the vertical guide unless needed by vertical mirror */
if (! mirror->vertical_mirror)
gimp_mirror_remove_guide (mirror, GIMP_ORIENTATION_VERTICAL);
@ -742,8 +765,6 @@ gimp_mirror_image_size_changed_cb (GimpImage *image,
if (previous_width != gimp_image_get_width (image) ||
previous_height != gimp_image_get_height (image))
{
/* TODO: change soft limits of "vertical-position" and
* "horizontal-position" properties. */
g_signal_emit_by_name (sym, "gui-param-changed", sym->image);
}
}

View File

@ -45,11 +45,11 @@ enum
{
PROP_0,
PROP_X_INTERVAL,
PROP_Y_INTERVAL,
PROP_INTERVAL_X,
PROP_INTERVAL_Y,
PROP_SHIFT,
PROP_X_MAX,
PROP_Y_MAX
PROP_MAX_X,
PROP_MAX_Y
};
@ -91,6 +91,7 @@ gimp_tiling_class_init (GimpTilingClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpSymmetryClass *symmetry_class = GIMP_SYMMETRY_CLASS (klass);
GParamSpec *pspec;
object_class->constructed = gimp_tiling_constructed;
object_class->finalize = gimp_tiling_finalize;
@ -101,22 +102,30 @@ gimp_tiling_class_init (GimpTilingClass *klass)
symmetry_class->update_strokes = gimp_tiling_update_strokes;
symmetry_class->get_operation = gimp_tiling_get_operation;
GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_X_INTERVAL,
"x-interval",
GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_INTERVAL_X,
"interval-x",
_("Interval X"),
_("Interval on the X axis (pixels)"),
0.0, G_MAXDOUBLE, 0.0,
GIMP_PARAM_STATIC_STRINGS |
GIMP_SYMMETRY_PARAM_GUI);
GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_Y_INTERVAL,
"y-interval",
pspec = g_object_class_find_property (object_class, "interval-x");
gegl_param_spec_set_property_key (pspec, "unit", "pixel-distance");
gegl_param_spec_set_property_key (pspec, "axis", "x");
GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_INTERVAL_Y,
"interval-y",
_("Interval Y"),
_("Interval on the Y axis (pixels)"),
0.0, G_MAXDOUBLE, 0.0,
GIMP_PARAM_STATIC_STRINGS |
GIMP_SYMMETRY_PARAM_GUI);
pspec = g_object_class_find_property (object_class, "interval-y");
gegl_param_spec_set_property_key (pspec, "unit", "pixel-distance");
gegl_param_spec_set_property_key (pspec, "axis", "y");
GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_SHIFT,
"shift",
_("Shift"),
@ -125,16 +134,16 @@ gimp_tiling_class_init (GimpTilingClass *klass)
GIMP_PARAM_STATIC_STRINGS |
GIMP_SYMMETRY_PARAM_GUI);
GIMP_CONFIG_PROP_INT (object_class, PROP_X_MAX,
"x-max",
GIMP_CONFIG_PROP_INT (object_class, PROP_MAX_X,
"max-x",
_("Max strokes X"),
_("Maximum number of strokes on the X axis"),
0, 100, 0,
GIMP_PARAM_STATIC_STRINGS |
GIMP_SYMMETRY_PARAM_GUI);
GIMP_CONFIG_PROP_INT (object_class, PROP_Y_MAX,
"y-max",
GIMP_CONFIG_PROP_INT (object_class, PROP_MAX_Y,
"max-y",
_("Max strokes Y"),
_("Maximum number of strokes on the Y axis"),
0, 100, 0,
@ -153,11 +162,6 @@ gimp_tiling_constructed (GObject *object)
GimpSymmetry *sym = GIMP_SYMMETRY (object);
GimpTiling *tiling = GIMP_TILING (object);
/* TODO:
* - "x-interval" property should be soft-limited by the image width;
* - "shift" property should be soft-limited by the width;
* - "y-interval" property should be soft-limited by the height.
*/
g_signal_connect_object (sym->image, "size-changed-detailed",
G_CALLBACK (gimp_tiling_image_size_changed_cb),
sym, 0);
@ -184,7 +188,7 @@ gimp_tiling_set_property (GObject *object,
switch (property_id)
{
case PROP_X_INTERVAL:
case PROP_INTERVAL_X:
if (sym->image)
{
gdouble new_x = g_value_get_double (value);
@ -206,7 +210,8 @@ gimp_tiling_set_property (GObject *object,
}
}
break;
case PROP_Y_INTERVAL:
case PROP_INTERVAL_Y:
{
gdouble new_y = g_value_get_double (value);
@ -227,6 +232,7 @@ gimp_tiling_set_property (GObject *object,
}
}
break;
case PROP_SHIFT:
{
gdouble new_shift = g_value_get_double (value);
@ -240,16 +246,19 @@ gimp_tiling_set_property (GObject *object,
}
}
break;
case PROP_X_MAX:
case PROP_MAX_X:
tiling->max_x = g_value_get_int (value);
if (sym->drawable)
gimp_tiling_update_strokes (sym, sym->drawable, sym->origin);
break;
case PROP_Y_MAX:
case PROP_MAX_Y:
tiling->max_y = g_value_get_int (value);
if (sym->drawable)
gimp_tiling_update_strokes (sym, sym->drawable, sym->origin);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@ -266,19 +275,19 @@ gimp_tiling_get_property (GObject *object,
switch (property_id)
{
case PROP_X_INTERVAL:
case PROP_INTERVAL_X:
g_value_set_double (value, tiling->interval_x);
break;
case PROP_Y_INTERVAL:
case PROP_INTERVAL_Y:
g_value_set_double (value, tiling->interval_y);
break;
case PROP_SHIFT:
g_value_set_double (value, tiling->shift);
break;
case PROP_X_MAX:
case PROP_MAX_X:
g_value_set_int (value, tiling->max_x);
break;
case PROP_Y_MAX:
case PROP_MAX_Y:
g_value_set_int (value, tiling->max_y);
break;
default:
@ -312,33 +321,41 @@ gimp_tiling_update_strokes (GimpSymmetry *sym,
if (origin->x > 0 && tiling->max_x == 0)
startx = origin->x - tiling->interval_x * (gint) (origin->x / tiling->interval_x + 1);
if (origin->y > 0 && tiling->max_y == 0)
{
starty = origin->y - tiling->interval_y * (gint) (origin->y / tiling->interval_y + 1);
if (tiling->shift > 0.0)
startx -= tiling->shift * (gint) (origin->y / tiling->interval_y + 1);
}
for (y_count = 0, y = starty; y < height + tiling->interval_y;
y_count++, y += tiling->interval_y)
{
if (tiling->max_y && y_count >= (gint) tiling->max_y)
break;
for (x_count = 0, x = startx; x < width + tiling->interval_x;
x_count++, x += tiling->interval_x)
{
if (tiling->max_x && x_count >= (gint) tiling->max_x)
break;
coords = g_memdup (origin, sizeof (GimpCoords));
coords->x = x;
coords->y = y;
strokes = g_list_prepend (strokes, coords);
if (tiling->interval_x < 1.0)
break;
}
if (tiling->max_x || startx + tiling->shift <= 0.0)
startx = startx + tiling->shift;
else
startx = startx - tiling->interval_x + tiling->shift;
if (tiling->interval_y < 1.0)
break;
}
@ -366,11 +383,9 @@ gimp_tiling_image_size_changed_cb (GimpImage *image,
gint previous_height,
GimpSymmetry *sym)
{
if (previous_width != gimp_image_get_width (image) ||
if (previous_width != gimp_image_get_width (image) ||
previous_height != gimp_image_get_height (image))
{
/* TODO: change soft limits of "x-interval", "y-interval" and
* "shift" properties. */
g_signal_emit_by_name (sym, "gui-param-changed", sym->image);
}
}