Ticket #1701: colorControl.diff
File colorControl.diff, 6.7 KB (added by , 17 years ago) |
---|
-
src/kits/interface/ColorControl.cpp
23 23 24 24 static const uint32 kMsgColorEntered = 'ccol'; 25 25 static const uint32 kMinCellSize = 6; 26 static const float kSelectorPenSize = 2.0f; 27 static const float kSelectorSize = 4.0f; 28 static const float kSelectorHSpacing = 2.0f; 26 29 27 28 30 BColorControl::BColorControl(BPoint leftTop, color_control_layout layout, 29 31 float cellSize, const char *name, BMessage *message, 30 32 bool bufferedDrawing) … … 222 224 c2.blue = (value & 0x0000FF00) >> 8; 223 225 char string[4]; 224 226 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; 227 float invalidateRadius = kSelectorSize/2 + kSelectorPenSize; 228 BPoint p; 230 229 231 230 if (c1.red != c2.red) { 232 231 sprintf(string, "%d", c2.red); 233 232 fRedText->SetText(string); 234 233 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)); 234 p = _SelectorPosition(fRampRects[1], c1.red); 235 Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius, 236 p.x + invalidateRadius, p.y + invalidateRadius)); 237 238 p = _SelectorPosition(fRampRects[1], c2.red); 239 Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius, 240 p.x + invalidateRadius, p.y + invalidateRadius)); 240 241 } 241 242 242 243 if (c1.green != c2.green) { 243 244 sprintf(string, "%d", c2.green); 244 245 fGreenText->SetText(string); 245 246 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)); 247 p = _SelectorPosition(fRampRects[2], c1.green); 248 Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius, 249 p.x + invalidateRadius, p.y + invalidateRadius)); 250 251 p = _SelectorPosition(fRampRects[2], c2.green); 252 Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius, 253 p.x + invalidateRadius, p.y + invalidateRadius)); 251 254 } 252 255 if (c1.blue != c2.blue) { 253 256 sprintf(string, "%d", c2.blue); 254 257 fBlueText->SetText(string); 255 258 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)); 259 p = _SelectorPosition(fRampRects[3], c1.blue); 260 Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius, 261 p.x + invalidateRadius, p.y + invalidateRadius)); 262 263 p = _SelectorPosition(fRampRects[3], c2.blue); 264 Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius, 265 p.x + invalidateRadius, p.y + invalidateRadius)); 261 266 } 262 267 263 268 BControl::SetValueNoUpdate(value); … … 397 402 float rampSize = rampRect.Height() / 4.0; 398 403 399 404 rampRect.bottom = rampRect.top + rampSize; 400 405 fRampRects[0] = rampRect; 401 406 _ColorRamp(rampRect, target, white, 0, false); 402 407 403 408 rampRect.OffsetBy(0, rampSize); 409 fRampRects[1] = rampRect; 404 410 _ColorRamp(rampRect, target, red, 0, false); 405 411 406 rampRect.OffsetBy(0,rampSize); 412 rampRect.OffsetBy(0, rampSize); 413 fRampRects[2] = rampRect; 407 414 _ColorRamp(rampRect, target, green, 0, false); 408 415 409 416 rampRect.OffsetBy(0, rampSize); 417 fRampRects[3] = rampRect; 410 418 _ColorRamp(rampRect, target, blue, 0, false); 411 419 412 420 // Selectors 413 421 rgb_color color = ValueAsColor(); 414 float x, y = rampSize * 1.5; 415 422 416 423 target->SetDrawingMode(B_OP_OVER); 417 target->SetPenSize(2.0f); 418 419 x = rect.left + color.red * (rect.Width() - 7) / 255; 424 target->SetPenSize(kSelectorPenSize); 425 420 426 target->SetHighColor(255, 255, 255); 421 target->StrokeEllipse(BRect(x, y, x + 4.0f, y + 4.0f)); 427 target->StrokeEllipse(_SelectorPosition(fRampRects[1], color.red), 428 kSelectorSize / 2, kSelectorSize / 2); 422 429 423 y += rampSize;424 425 x = rect.left + color.green * (rect.Width() - 7) / 255;426 430 target->SetHighColor(255, 255, 255); 427 target->StrokeEllipse(BRect(x, y, x + 4.0f, y + 4.0f)); 431 target->StrokeEllipse(_SelectorPosition(fRampRects[2], color.green), 432 kSelectorSize / 2, kSelectorSize / 2); 428 433 429 y += rampSize;430 431 x = rect.left + color.blue * (rect.Width() - 7) / 255;432 434 target->SetHighColor(255, 255, 255); 433 target->StrokeEllipse(BRect(x, y, x + 4.0f, y + 4.0f)); 435 target->StrokeEllipse(_SelectorPosition(fRampRects[3], color.blue), 436 kSelectorSize / 2, kSelectorSize / 2); 434 437 435 438 target->SetPenSize(1.0f); 436 439 target->SetDrawingMode(B_OP_COPY); … … 462 465 } 463 466 464 467 468 BPoint 469 BColorControl::_SelectorPosition(const BRect& rampRect, uint8 shade) const 470 { 471 float radius = kSelectorSize / 2 + kSelectorPenSize / 2; 472 473 return BPoint(rampRect.left + kSelectorHSpacing + radius + 474 shade * (rampRect.Width() - 2 * (kSelectorHSpacing + radius)) / 255, 475 rampRect.top + rampRect.Height() / 2); 476 } 477 478 465 479 void 466 480 BColorControl::_UpdateOffscreen(BRect update) 467 481 { … … 572 586 573 587 rgb_color color = ValueAsColor(); 574 588 575 float rampsize = rect.bottom / 4;576 577 589 uint8 shade = (unsigned char)max_c(0, 578 min_c((point.x - 2) * 255 / (rect.Width() - 4.0f), 255));579 580 if ( point.y - 2 < rampsize) {590 min_c((point.x - fRampRects[0].left) * 255 / fRampRects[0].Width(), 255)); 591 592 if (fRampRects[0].Contains(point)) { 581 593 color.red = color.green = color.blue = shade; 582 594 fFocusedComponent = 1; 583 } else if ( point.y - 2 < (rampsize * 2)) {595 } else if (fRampRects[1].Contains(point)) { 584 596 color.red = shade; 585 597 fFocusedComponent = 2; 586 } else if ( point.y - 2 < (rampsize * 3)) {598 } else if (fRampRects[2].Contains(point)) { 587 599 color.green = shade; 588 600 fFocusedComponent = 3; 589 } else {601 } else if (fRampRects[3].Contains(point)){ 590 602 color.blue = shade; 591 603 fFocusedComponent = 4; 592 604 } … … 609 621 610 622 rgb_color color = ValueAsColor(); 611 623 612 BRect rect(0.0f, 0.0f, fColumns * fCellSize, Bounds().bottom);613 614 624 uint8 shade = (unsigned char)max_c(0, 615 min_c((point.x - 2) * 255 / (rect.Width() - 4.0f), 255));616 625 min_c((point.x - fRampRects[0].left) * 255 / fRampRects[0].Width(), 255)); 626 617 627 switch (fFocusedComponent) { 618 628 case 1: 619 629 color.red = color.green = color.blue = shade; -
headers/os/interface/ColorControl.h
92 92 void _ColorRamp(BRect rect, BView* target, 93 93 rgb_color baseColor, int16 flag, 94 94 bool focused); 95 BPoint _SelectorPosition(const BRect& rampRect, uint8 shade) const; 95 96 96 97 private: 98 BRect fRampRects[4]; 99 97 100 float fCellSize; 98 101 int32 fRows; 99 102 int32 fColumns;