Changeset 25013

Show
Ignore:
Timestamp:
04/17/08 17:57:04 (1 month ago)
Author:
aldeck
Message:
* clamps the textcontrol input to 255 
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • haiku/trunk/src/kits/interface/ColorControl.cpp

    r23680 r25013  
    237237BColorControl::SetValue(int32 value) 
    238238{ 
    239         if (Value() == value) 
    240                 return; 
    241  
    242239        rgb_color c1 = ValueAsColor(); 
    243240        rgb_color c2; 
     
    256253                        fSelectedPaletteColorIndex = BScreen(Window()).IndexForColor(c2); 
    257254                }                                
    258                                 
     255                 
    259256                c2 = BScreen(Window()).ColorForIndex(fSelectedPaletteColorIndex);        
    260                  
    261                 sprintf(string, "%d", c2.red); 
    262                 fRedText->SetText(string); 
    263                 sprintf(string, "%d", c2.green); 
    264                 fGreenText->SetText(string); 
    265                 sprintf(string, "%d", c2.blue); 
    266                 fBlueText->SetText(string); 
    267257                 
    268258                Invalidate(_PaletteSelectorFrame(fPreviousSelectedPaletteColorIndex)); 
     
    275265                 
    276266                if (c1.red != c2.red) { 
    277                         sprintf(string, "%d", c2.red); 
    278                         fRedText->SetText(string); 
    279                          
    280267                        p = _SelectorPosition(_RampFrame(1), c1.red); 
    281268                        Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius, 
     
    286273                                 p.x + invalidateRadius, p.y + invalidateRadius));       
    287274                } 
    288          
    289275                if (c1.green != c2.green) { 
    290                         sprintf(string, "%d", c2.green); 
    291                         fGreenText->SetText(string); 
    292          
    293276                        p = _SelectorPosition(_RampFrame(2), c1.green); 
    294277                        Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius, 
     
    300283                } 
    301284                if (c1.blue != c2.blue) { 
    302                         sprintf(string, "%d", c2.blue); 
    303                         fBlueText->SetText(string); 
    304                          
    305285                        p = _SelectorPosition(_RampFrame(3), c1.blue); 
    306286                        Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius, 
     
    312292                }  
    313293        } 
     294         
     295        // the textcontrols have to be updated even when the color 
     296        // hasn't changed since the value is clamped upstream 
     297        // and the textcontrols would still show the unclamped value 
     298        sprintf(string, "%d", c2.red); 
     299        fRedText->SetText(string); 
     300        sprintf(string, "%d", c2.green); 
     301        fGreenText->SetText(string); 
     302        sprintf(string, "%d", c2.blue); 
     303        fBlueText->SetText(string); 
     304 
     305        if (Value() == value) 
     306                return; 
    314307 
    315308        BControl::SetValueNoUpdate(value); 
     
    374367                { 
    375368                        rgb_color color; 
    376                         color.red = /*min_c(*/strtol(fRedText->Text(), NULL, 10), 255/*)*/; 
    377                         color.green = /*min_c(*/strtol(fGreenText->Text(), NULL, 10), 255/*)*/; 
    378                         color.blue = /*min_c(*/strtol(fBlueText->Text(), NULL, 10), 255/*)*/; 
    379                         color.alpha = 255; 
    380                                  
    381                         //TODO: text is not updated if the clamping 
    382                         //              gives the same value next time 
     369                        color.red = min_c(strtol(fRedText->Text(), NULL, 10), 255); 
     370                        color.green = min_c(strtol(fGreenText->Text(), NULL, 10), 255); 
     371                        color.blue = min_c(strtol(fBlueText->Text(), NULL, 10), 255); 
     372                        color.alpha = 255;                       
    383373                                         
    384374                        SetValue(color);