* clamps the textcontrol input to 255

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25013 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Alexandre Deckner
2008-04-17 22:57:04 +00:00
parent 74158bb474
commit e8fa461ae7
+18 -28
View File
@@ -236,9 +236,6 @@ BColorControl::SetLayout(BLayout* layout)
void void
BColorControl::SetValue(int32 value) BColorControl::SetValue(int32 value)
{ {
if (Value() == value)
return;
rgb_color c1 = ValueAsColor(); rgb_color c1 = ValueAsColor();
rgb_color c2; rgb_color c2;
c2.red = (value & 0xFF000000) >> 24; c2.red = (value & 0xFF000000) >> 24;
@@ -255,15 +252,8 @@ BColorControl::SetValue(int32 value)
//here SetValue hasn't been called by mouse tracking //here SetValue hasn't been called by mouse tracking
fSelectedPaletteColorIndex = BScreen(Window()).IndexForColor(c2); fSelectedPaletteColorIndex = BScreen(Window()).IndexForColor(c2);
} }
c2 = BScreen(Window()).ColorForIndex(fSelectedPaletteColorIndex);
sprintf(string, "%d", c2.red); c2 = BScreen(Window()).ColorForIndex(fSelectedPaletteColorIndex);
fRedText->SetText(string);
sprintf(string, "%d", c2.green);
fGreenText->SetText(string);
sprintf(string, "%d", c2.blue);
fBlueText->SetText(string);
Invalidate(_PaletteSelectorFrame(fPreviousSelectedPaletteColorIndex)); Invalidate(_PaletteSelectorFrame(fPreviousSelectedPaletteColorIndex));
Invalidate(_PaletteSelectorFrame(fSelectedPaletteColorIndex)); Invalidate(_PaletteSelectorFrame(fSelectedPaletteColorIndex));
@@ -274,9 +264,6 @@ BColorControl::SetValue(int32 value)
BPoint p; BPoint p;
if (c1.red != c2.red) { if (c1.red != c2.red) {
sprintf(string, "%d", c2.red);
fRedText->SetText(string);
p = _SelectorPosition(_RampFrame(1), c1.red); p = _SelectorPosition(_RampFrame(1), c1.red);
Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius, Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius,
p.x + invalidateRadius, p.y + invalidateRadius)); p.x + invalidateRadius, p.y + invalidateRadius));
@@ -285,11 +272,7 @@ BColorControl::SetValue(int32 value)
Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius, Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius,
p.x + invalidateRadius, p.y + invalidateRadius)); p.x + invalidateRadius, p.y + invalidateRadius));
} }
if (c1.green != c2.green) { if (c1.green != c2.green) {
sprintf(string, "%d", c2.green);
fGreenText->SetText(string);
p = _SelectorPosition(_RampFrame(2), c1.green); p = _SelectorPosition(_RampFrame(2), c1.green);
Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius, Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius,
p.x + invalidateRadius, p.y + invalidateRadius)); p.x + invalidateRadius, p.y + invalidateRadius));
@@ -299,9 +282,6 @@ BColorControl::SetValue(int32 value)
p.x + invalidateRadius, p.y + invalidateRadius)); p.x + invalidateRadius, p.y + invalidateRadius));
} }
if (c1.blue != c2.blue) { if (c1.blue != c2.blue) {
sprintf(string, "%d", c2.blue);
fBlueText->SetText(string);
p = _SelectorPosition(_RampFrame(3), c1.blue); p = _SelectorPosition(_RampFrame(3), c1.blue);
Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius, Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius,
p.x + invalidateRadius, p.y + invalidateRadius)); p.x + invalidateRadius, p.y + invalidateRadius));
@@ -311,6 +291,19 @@ BColorControl::SetValue(int32 value)
p.x + invalidateRadius, p.y + invalidateRadius)); p.x + invalidateRadius, p.y + invalidateRadius));
} }
} }
// the textcontrols have to be updated even when the color
// hasn't changed since the value is clamped upstream
// and the textcontrols would still show the unclamped value
sprintf(string, "%d", c2.red);
fRedText->SetText(string);
sprintf(string, "%d", c2.green);
fGreenText->SetText(string);
sprintf(string, "%d", c2.blue);
fBlueText->SetText(string);
if (Value() == value)
return;
BControl::SetValueNoUpdate(value); BControl::SetValueNoUpdate(value);
@@ -373,13 +366,10 @@ BColorControl::MessageReceived(BMessage *message)
case kMsgColorEntered: case kMsgColorEntered:
{ {
rgb_color color; rgb_color color;
color.red = /*min_c(*/strtol(fRedText->Text(), NULL, 10), 255/*)*/; color.red = min_c(strtol(fRedText->Text(), NULL, 10), 255);
color.green = /*min_c(*/strtol(fGreenText->Text(), NULL, 10), 255/*)*/; color.green = min_c(strtol(fGreenText->Text(), NULL, 10), 255);
color.blue = /*min_c(*/strtol(fBlueText->Text(), NULL, 10), 255/*)*/; color.blue = min_c(strtol(fBlueText->Text(), NULL, 10), 255);
color.alpha = 255; color.alpha = 255;
//TODO: text is not updated if the clamping
// gives the same value next time
SetValue(color); SetValue(color);
Invoke(); Invoke();