Ticket #503: patch-bug#503.diff

File patch-bug#503.diff, 1.6 KB (added by cl21, 16 years ago)

Only the rectangles containing the selectors are invalidated on color change. Reduces the flickering.

  • src/kits/interface/ColorControl.cpp

     
    222222    c2.blue = (value & 0x0000FF00) >> 8;
    223223    char string[4];
    224224
     225    // values for calculating the selector rectangles for invalidation
     226    // analogous to selector drawing in _DrawColorArea
     227    float rampXGradient = (ceil(fColumns * fCellSize) - 4 - 7)  / 255;
     228    float rampSize = (Bounds().bottom - 2) / 4.0;
     229    float x, y;
     230
    225231    if (c1.red != c2.red) {
    226232        sprintf(string, "%d", c2.red);
    227233        fRedText->SetText(string);
     234       
     235        y = rampSize * 1.5;
     236        x = 2 + c1.red * rampXGradient;
     237        Invalidate(BRect(x - 2, y - 2, x + 6, y + 6));
     238        x = 2 + c2.red * rampXGradient;
     239        Invalidate(BRect(x - 2, y - 2, x + 6, y + 6));
    228240    }
    229241
    230242    if (c1.green != c2.green) {
    231243        sprintf(string, "%d", c2.green);
    232244        fGreenText->SetText(string);
     245
     246        y = rampSize * 2.5;     
     247        x = 2 + c1.green * rampXGradient;
     248        Invalidate(BRect(x - 2, y - 2, x + 6, y + 6));
     249        x = 2 + c2.green * rampXGradient;
     250        Invalidate(BRect(x - 2, y - 2, x + 6, y + 6));
    233251    }
    234 
    235252    if (c1.blue != c2.blue) {
    236253        sprintf(string, "%d", c2.blue);
    237254        fBlueText->SetText(string);
     255       
     256        y = rampSize * 3.5;
     257        x = 2 + c1.blue * rampXGradient;
     258        Invalidate(BRect(x - 2, y - 2, x + 6, y + 6));
     259        x = 2 + c2.blue * rampXGradient;
     260        Invalidate(BRect(x - 2, y - 2, x + 6, y + 6));
    238261    }
    239262
    240263    BControl::SetValueNoUpdate(value);
    241264
    242     // TODO: This causes lot of flickering
    243     Invalidate();
    244 
    245265    if (LockLooper()) {
    246266        Window()->UpdateIfNeeded();
    247267        UnlockLooper();