From 580a531ef511c1b80c30fa61b27e0209ff693f96 Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Thu, 13 Jul 2023 14:34:25 +0200 Subject: Clamp input values of Fl_Color_Chooser (#749) Note: this may be somewhat confusing if the user enters out-of-range values manually because they are overwritten immediately with valid input but the effects seen in issue #749 are IMHO worse. --- src/Fl_Color_Chooser.cxx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Fl_Color_Chooser.cxx b/src/Fl_Color_Chooser.cxx index a8b7ac5c5..209f4b45b 100644 --- a/src/Fl_Color_Chooser.cxx +++ b/src/Fl_Color_Chooser.cxx @@ -1,7 +1,7 @@ // // Color chooser for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2019 by Bill Spitzak and others. +// Copyright 1998-2023 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -428,9 +428,14 @@ int Flcc_ValueBox::handle_key(int key) { void Fl_Color_Chooser::rgb_cb(Fl_Widget* o, void*) { Fl_Color_Chooser* c = (Fl_Color_Chooser*)(o->parent()); - double R = c->rvalue.value(); - double G = c->gvalue.value(); - double B = c->bvalue.value(); + // clamp input values to valid ranges (issue #749, part 1) + double R = c->rvalue.clamp(c->rvalue.value()); + double G = c->gvalue.clamp(c->gvalue.value()); + double B = c->bvalue.clamp(c->bvalue.value()); + // update input values if they were clamped (#749, part 2) + c->rvalue.value(R); + c->gvalue.value(G); + c->bvalue.value(B); if (c->mode() == M_HSV) { if (c->hsv(R,G,B)) c->do_callback(FL_REASON_CHANGED); return; -- cgit v1.2.3