app: in GimpDial, add "clockwise-angles" property ...

... and rename "clockwise" to "clockwise-delta"

Add a boolean "clockwise-angles" property to GimpDial, which, when
set, causes the dial legs' angles to be measured clockwise, rather
than counter-clockwise.  The property is FALSE by default.

Rename the "clockwise" property, which controls the direction of
the measured delta between the two angles, to "clockwise-delta", to
avoid confusion, and adapt the rest of the code.
This commit is contained in:
Ell 2018-07-24 01:57:03 -04:00
parent fdc3c84fc5
commit 0c477564ad
3 changed files with 60 additions and 27 deletions

View File

@ -47,15 +47,15 @@ invert_segment_clicked (GtkWidget *button,
gboolean clockwise; gboolean clockwise;
g_object_get (dial, g_object_get (dial,
"alpha", &alpha, "alpha", &alpha,
"beta", &beta, "beta", &beta,
"clockwise", &clockwise, "clockwise-delta", &clockwise,
NULL); NULL);
g_object_set (dial, g_object_set (dial,
"alpha", beta, "alpha", beta,
"beta", alpha, "beta", alpha,
"clockwise", ! clockwise, "clockwise-delta", ! clockwise,
NULL); NULL);
} }
@ -67,8 +67,8 @@ select_all_clicked (GtkWidget *button,
gboolean clockwise; gboolean clockwise;
g_object_get (dial, g_object_get (dial,
"alpha", &alpha, "alpha", &alpha,
"clockwise", &clockwise, "clockwise-delta", &clockwise,
NULL); NULL);
beta = alpha - (clockwise ? -1 : 1) * 0.00001; beta = alpha - (clockwise ? -1 : 1) * 0.00001;

View File

@ -47,7 +47,8 @@ enum
PROP_DRAW_BETA, PROP_DRAW_BETA,
PROP_ALPHA, PROP_ALPHA,
PROP_BETA, PROP_BETA,
PROP_CLOCKWISE PROP_CLOCKWISE_ANGLES,
PROP_CLOCKWISE_DELTA
}; };
typedef enum typedef enum
@ -63,7 +64,8 @@ struct _GimpDialPrivate
{ {
gdouble alpha; gdouble alpha;
gdouble beta; gdouble beta;
gboolean clockwise; gboolean clockwise_angles;
gboolean clockwise_delta;
gboolean draw_beta; gboolean draw_beta;
DialTarget target; DialTarget target;
@ -96,7 +98,7 @@ static void gimp_dial_draw_arrows (cairo_t *cr,
gint size, gint size,
gdouble alpha, gdouble alpha,
gdouble beta, gdouble beta,
gboolean clockwise, gboolean clockwise_delta,
DialTarget highlight, DialTarget highlight,
gboolean draw_beta); gboolean draw_beta);
@ -140,8 +142,15 @@ gimp_dial_class_init (GimpDialClass *klass)
GIMP_PARAM_READWRITE | GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT)); G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_CLOCKWISE, g_object_class_install_property (object_class, PROP_CLOCKWISE_ANGLES,
g_param_spec_boolean ("clockwise", g_param_spec_boolean ("clockwise-angles",
NULL, NULL,
FALSE,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_CLOCKWISE_DELTA,
g_param_spec_boolean ("clockwise-delta",
NULL, NULL, NULL, NULL,
FALSE, FALSE,
GIMP_PARAM_READWRITE | GIMP_PARAM_READWRITE |
@ -185,8 +194,13 @@ gimp_dial_set_property (GObject *object,
gtk_widget_queue_draw (GTK_WIDGET (dial)); gtk_widget_queue_draw (GTK_WIDGET (dial));
break; break;
case PROP_CLOCKWISE: case PROP_CLOCKWISE_ANGLES:
dial->priv->clockwise = g_value_get_boolean (value); dial->priv->clockwise_angles = g_value_get_boolean (value);
gtk_widget_queue_draw (GTK_WIDGET (dial));
break;
case PROP_CLOCKWISE_DELTA:
dial->priv->clockwise_delta = g_value_get_boolean (value);
gtk_widget_queue_draw (GTK_WIDGET (dial)); gtk_widget_queue_draw (GTK_WIDGET (dial));
break; break;
@ -219,8 +233,12 @@ gimp_dial_get_property (GObject *object,
g_value_set_double (value, dial->priv->beta); g_value_set_double (value, dial->priv->beta);
break; break;
case PROP_CLOCKWISE: case PROP_CLOCKWISE_ANGLES:
g_value_set_boolean (value, dial->priv->clockwise); g_value_set_boolean (value, dial->priv->clockwise_angles);
break;
case PROP_CLOCKWISE_DELTA:
g_value_set_boolean (value, dial->priv->clockwise_delta);
break; break;
case PROP_DRAW_BETA: case PROP_DRAW_BETA:
@ -237,9 +255,11 @@ static gboolean
gimp_dial_draw (GtkWidget *widget, gimp_dial_draw (GtkWidget *widget,
cairo_t *cr) cairo_t *cr)
{ {
GimpDial *dial = GIMP_DIAL (widget); GimpDial *dial = GIMP_DIAL (widget);
GtkAllocation allocation; GtkAllocation allocation;
gint size; gint size;
gdouble alpha = dial->priv->alpha;
gdouble beta = dial->priv->beta;
GTK_WIDGET_CLASS (parent_class)->draw (widget, cr); GTK_WIDGET_CLASS (parent_class)->draw (widget, cr);
@ -249,6 +269,12 @@ gimp_dial_draw (GtkWidget *widget,
gtk_widget_get_allocation (widget, &allocation); gtk_widget_get_allocation (widget, &allocation);
if (dial->priv->clockwise_angles)
{
alpha = -alpha;
beta = -beta;
}
cairo_save (cr); cairo_save (cr);
cairo_translate (cr, cairo_translate (cr,
@ -256,8 +282,8 @@ gimp_dial_draw (GtkWidget *widget,
(allocation.height - size) / 2.0); (allocation.height - size) / 2.0);
gimp_dial_draw_arrows (cr, size, gimp_dial_draw_arrows (cr, size,
dial->priv->alpha, dial->priv->beta, alpha, beta,
dial->priv->clockwise, dial->priv->clockwise_delta,
dial->priv->target, dial->priv->target,
dial->priv->draw_beta); dial->priv->draw_beta);
@ -283,6 +309,10 @@ gimp_dial_button_press_event (GtkWidget *widget,
angle = _gimp_circle_get_angle_and_distance (GIMP_CIRCLE (dial), angle = _gimp_circle_get_angle_and_distance (GIMP_CIRCLE (dial),
bevent->x, bevent->y, bevent->x, bevent->y,
NULL); NULL);
if (dial->priv->clockwise_angles && angle)
angle = 2.0 * G_PI - angle;
dial->priv->last_angle = angle; dial->priv->last_angle = angle;
switch (dial->priv->target) switch (dial->priv->target)
@ -315,6 +345,9 @@ gimp_dial_motion_notify_event (GtkWidget *widget,
mevent->x, mevent->y, mevent->x, mevent->y,
&distance); &distance);
if (dial->priv->clockwise_angles && angle)
angle = 2.0 * G_PI - angle;
if (_gimp_circle_has_grab (GIMP_CIRCLE (dial))) if (_gimp_circle_has_grab (GIMP_CIRCLE (dial)))
{ {
gdouble delta; gdouble delta;
@ -443,9 +476,9 @@ gimp_dial_draw_segment (cairo_t *cr,
gdouble radius, gdouble radius,
gdouble alpha, gdouble alpha,
gdouble beta, gdouble beta,
gboolean clockwise) gboolean clockwise_delta)
{ {
gint direction = clockwise ? -1 : 1; gint direction = clockwise_delta ? -1 : 1;
gint segment_dist; gint segment_dist;
gint tick; gint tick;
gdouble slice; gdouble slice;
@ -464,7 +497,7 @@ gimp_dial_draw_segment (cairo_t *cr,
cairo_new_sub_path (cr); cairo_new_sub_path (cr);
if (clockwise) if (clockwise_delta)
slice = -gimp_dial_normalize_angle (alpha - beta); slice = -gimp_dial_normalize_angle (alpha - beta);
else else
slice = gimp_dial_normalize_angle (beta - alpha); slice = gimp_dial_normalize_angle (beta - alpha);
@ -478,7 +511,7 @@ gimp_dial_draw_arrows (cairo_t *cr,
gint size, gint size,
gdouble alpha, gdouble alpha,
gdouble beta, gdouble beta,
gboolean clockwise, gboolean clockwise_delta,
DialTarget highlight, DialTarget highlight,
gboolean draw_beta) gboolean draw_beta)
{ {
@ -502,7 +535,7 @@ gimp_dial_draw_arrows (cairo_t *cr,
gimp_dial_draw_arrow (cr, radius, beta); gimp_dial_draw_arrow (cr, radius, beta);
if ((highlight & DIAL_TARGET_BOTH) != DIAL_TARGET_BOTH) if ((highlight & DIAL_TARGET_BOTH) != DIAL_TARGET_BOTH)
gimp_dial_draw_segment (cr, radius, alpha, beta, clockwise); gimp_dial_draw_segment (cr, radius, alpha, beta, clockwise_delta);
} }
cairo_set_line_width (cr, 3.0); cairo_set_line_width (cr, 3.0);
@ -525,7 +558,7 @@ gimp_dial_draw_arrows (cairo_t *cr,
gimp_dial_draw_arrow (cr, radius, beta); gimp_dial_draw_arrow (cr, radius, beta);
if ((highlight & DIAL_TARGET_BOTH) == DIAL_TARGET_BOTH) if ((highlight & DIAL_TARGET_BOTH) == DIAL_TARGET_BOTH)
gimp_dial_draw_segment (cr, radius, alpha, beta, clockwise); gimp_dial_draw_segment (cr, radius, alpha, beta, clockwise_delta);
} }
cairo_set_line_width (cr, 3.0); cairo_set_line_width (cr, 3.0);

View File

@ -930,7 +930,7 @@ gimp_prop_angle_range_dial_new (GObject *config,
NULL, NULL); NULL, NULL);
g_object_bind_property (config, clockwise_property_name, g_object_bind_property (config, clockwise_property_name,
dial, "clockwise", dial, "clockwise-delta",
G_BINDING_BIDIRECTIONAL | G_BINDING_BIDIRECTIONAL |
G_BINDING_SYNC_CREATE); G_BINDING_SYNC_CREATE);