modules: Add option to lock color wheel rotation

This patch adds a gimp_color_wheel_set_triangle_locked ()
function which allows locking the rotation of the triangle
in the Color Wheel dialogue. Currently, the value is defaulted
to TRUE, to keep the triangle from rotating when the hue is
changed in the ring.
This commit is contained in:
Alx Sa 2024-12-18 15:10:32 -05:00
parent 277d49235f
commit 13fca65ca0
2 changed files with 44 additions and 24 deletions

View file

@ -81,6 +81,7 @@ typedef struct
/* Dragging mode */ /* Dragging mode */
DragMode mode; DragMode mode;
gboolean triangle_locked;
guint focus_on_ring : 1; guint focus_on_ring : 1;
@ -234,10 +235,11 @@ gimp_color_wheel_init (GimpColorWheel *wheel)
gtk_widget_set_has_window (GTK_WIDGET (wheel), FALSE); gtk_widget_set_has_window (GTK_WIDGET (wheel), FALSE);
gtk_widget_set_can_focus (GTK_WIDGET (wheel), TRUE); gtk_widget_set_can_focus (GTK_WIDGET (wheel), TRUE);
priv->format = NULL; priv->format = NULL;
priv->ring_fraction = DEFAULT_FRACTION; priv->ring_fraction = DEFAULT_FRACTION;
priv->size = DEFAULT_SIZE; priv->size = DEFAULT_SIZE;
priv->ring_width = DEFAULT_RING_WIDTH; priv->ring_width = DEFAULT_RING_WIDTH;
priv->triangle_locked = TRUE;
/* Allow the user to drag the rectangle on the preview */ /* Allow the user to drag the rectangle on the preview */
gesture = gtk_gesture_drag_new (GTK_WIDGET (wheel)); gesture = gtk_gesture_drag_new (GTK_WIDGET (wheel));
@ -500,7 +502,11 @@ compute_triangle (GimpColorWheel *wheel,
outer = priv->size / 2.0; outer = priv->size / 2.0;
inner = outer - priv->ring_width; inner = outer - priv->ring_width;
angle = priv->h * 2.0 * G_PI;
if (! priv->triangle_locked)
angle = priv->h * 2.0 * G_PI;
else
angle = 90 * G_PI;
*hx = floor (center_x + cos (angle) * inner + 0.5); *hx = floor (center_x + cos (angle) * inner + 0.5);
*hy = floor (center_y - sin (angle) * inner + 0.5); *hy = floor (center_y - sin (angle) * inner + 0.5);
@ -1538,3 +1544,15 @@ gimp_color_wheel_move (GimpColorWheel *wheel,
gimp_color_wheel_set_color (wheel, hue, sat, val); gimp_color_wheel_set_color (wheel, hue, sat, val);
} }
void
gimp_color_wheel_set_triangle_locked (GimpColorWheel *wheel,
gboolean triangle_locked)
{
GimpColorWheelPrivate *priv = gimp_color_wheel_get_instance_private (wheel);
g_return_if_fail (GIMP_IS_COLOR_WHEEL (wheel));
priv->triangle_locked = triangle_locked;
}

View file

@ -67,30 +67,32 @@ struct _GimpColorWheelClass
}; };
void color_wheel_register_type (GTypeModule *module); void color_wheel_register_type (GTypeModule *module);
GType gimp_color_wheel_get_type (void) G_GNUC_CONST; GType gimp_color_wheel_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_color_wheel_new (void); GtkWidget * gimp_color_wheel_new (void);
void gimp_color_wheel_set_color (GimpColorWheel *wheel, void gimp_color_wheel_set_color (GimpColorWheel *wheel,
double h, double h,
double s, double s,
double v); double v);
void gimp_color_wheel_get_color (GimpColorWheel *wheel, void gimp_color_wheel_get_color (GimpColorWheel *wheel,
gfloat *h, gfloat *h,
gfloat *s, gfloat *s,
gfloat *v); gfloat *v);
void gimp_color_wheel_set_ring_fraction (GimpColorWheel *wheel, void gimp_color_wheel_set_ring_fraction (GimpColorWheel *wheel,
gdouble fraction); gdouble fraction);
gdouble gimp_color_wheel_get_ring_fraction (GimpColorWheel *wheel); gdouble gimp_color_wheel_get_ring_fraction (GimpColorWheel *wheel);
void gimp_color_wheel_set_format (GimpColorWheel *wheel, void gimp_color_wheel_set_format (GimpColorWheel *wheel,
const Babl *format); const Babl *format);
void gimp_color_wheel_set_color_config (GimpColorWheel *wheel, void gimp_color_wheel_set_color_config (GimpColorWheel *wheel,
GimpColorConfig *config); GimpColorConfig *config);
void gimp_color_wheel_set_triangle_locked (GimpColorWheel *wheel,
gboolean triangle_locked);
gboolean gimp_color_wheel_is_adjusting (GimpColorWheel *wheel); gboolean gimp_color_wheel_is_adjusting (GimpColorWheel *wheel);
G_END_DECLS G_END_DECLS