Ticket #1701: colorControl8.diff
File colorControl8.diff, 22.3 KB (added by , 14 years ago) |
---|
-
src/kits/interface/ColorControl.cpp
5 5 * Authors: 6 6 * Marc Flerackers (mflerackers@androme.be) 7 7 * Axel Dörfler, axeld@pinc-software.de 8 * Alexandre Deckner, alex@zappotek.com 8 9 */ 9 10 10 11 /** BColorControl displays a palette of selectable colors. */ … … 23 24 24 25 static const uint32 kMsgColorEntered = 'ccol'; 25 26 static const uint32 kMinCellSize = 6; 27 static const float kSelectorPenSize = 2.0f; 28 static const float kSelectorSize = 4.0f; 29 static const float kSelectorHSpacing = 2.0f; 30 static const float kTextFieldsHSpacing = 6.0f; 26 31 27 28 32 BColorControl::BColorControl(BPoint leftTop, color_control_layout layout, 29 33 float cellSize, const char *name, BMessage *message, 30 34 bool bufferedDrawing) … … 61 65 { 62 66 fColumns = layout; 63 67 fRows = 256 / fColumns; 64 fCellSize = max_c(kMinCellSize, size); 68 fCellSize = ceil(max_c(kMinCellSize, size)); 69 //TODO: check the colorspace dynamically? 70 fPaletteMode = BScreen(Window()).ColorSpace() == B_CMAP8; 71 fSelectedPaletteColorIndex = -1; 72 fPreviousSelectedPaletteColorIndex = -1; 65 73 fFocusedComponent = 0; 74 75 if (fPaletteMode){ 76 fPaletteFrame.Set(2.0f, 2.0f, 77 float(fColumns) * fCellSize + 2.0, 78 float(fRows) * fCellSize + 2.0); 79 } else { 80 fPaletteFrame.Set(2.0f, 2.0f, 81 float(fColumns) * fCellSize + 2.0, 82 float(fRows) * fCellSize + 2.0 - 1.0); 83 //1 pixel adjust so that the inner space 84 //has exactly rows*cellsize pixels in height 85 } 66 86 67 87 if (archive) { 68 88 int32 value = 0; … … 129 149 } 130 150 131 151 if (useOffscreen) { 132 BRect bounds (Bounds());133 bounds. right = floorf(fBlueText->Frame().left) - 1;134 135 fBitmap = new BBitmap(bounds, /*BScreen(Window()).ColorSpace()*/B_RGB32, true, false);152 BRect bounds = fPaletteFrame; 153 bounds.InsetBy(-2.0f, -2.0f); 154 155 fBitmap = new BBitmap(bounds, BScreen(Window()).ColorSpace(), true, false); 136 156 fOffscreenView = new BView(bounds, "off_view", 0, 0); 137 157 138 158 fBitmap->Lock(); … … 148 168 void 149 169 BColorControl::_LayoutView() 150 170 { 151 BRect rect (0.0f, 0.0f, ceil(fColumns * fCellSize), ceil(fRows * fCellSize + 2));152 171 BRect rect = fPaletteFrame.InsetByCopy(-2.0,-2.0); //bevel 172 153 173 if (rect.Height() < fBlueText->Frame().bottom) { 154 174 // adjust the height to fit 155 175 rect.bottom = fBlueText->Frame().bottom; 156 176 } 157 158 ResizeTo(rect.Width() + fRedText->Bounds().Width(), rect.Height()); 159 177 160 178 float offset = floor(rect.bottom / 4); 161 179 float y = offset; 162 180 if (offset < fRedText->Bounds().Height() + 2) { 163 181 offset = fRedText->Bounds().Height() + 2; 164 182 y = 0; 165 } 183 } 166 184 167 fRedText->MoveTo(rect.right + 1, y);185 fRedText->MoveTo(rect.right + kTextFieldsHSpacing, y); 168 186 169 187 y += offset; 170 fGreenText->MoveTo(rect.right + 1, y);188 fGreenText->MoveTo(rect.right + kTextFieldsHSpacing, y); 171 189 172 190 y += offset; 173 fBlueText->MoveTo(rect.right + 1, y); 191 fBlueText->MoveTo(rect.right + kTextFieldsHSpacing, y); 192 193 ResizeTo(rect.Width() + kTextFieldsHSpacing + fRedText->Bounds().Width(), rect.Height()); 194 174 195 } 175 196 176 197 … … 220 241 c2.red = (value & 0xFF000000) >> 24; 221 242 c2.green = (value & 0x00FF0000) >> 16; 222 243 c2.blue = (value & 0x0000FF00) >> 8; 244 c2.alpha = 255; 223 245 char string[4]; 224 246 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 231 if (c1.red != c2.red) { 247 if (fPaletteMode) { 248 249 //workaround when two indexes have the same color 250 rgb_color c = BScreen(Window()).ColorForIndex(fSelectedPaletteColorIndex); 251 c.alpha = 255; 252 if (fSelectedPaletteColorIndex == -1 || c != c2) { 253 //here SetValue hasn't been called by mouse tracking 254 fSelectedPaletteColorIndex = BScreen(Window()).IndexForColor(c2); 255 } 256 257 c2 = BScreen(Window()).ColorForIndex(fSelectedPaletteColorIndex); 258 232 259 sprintf(string, "%d", c2.red); 233 260 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));240 }241 242 if (c1.green != c2.green) {243 261 sprintf(string, "%d", c2.green); 244 262 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));251 }252 if (c1.blue != c2.blue) {253 263 sprintf(string, "%d", c2.blue); 254 264 fBlueText->SetText(string); 255 265 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)); 266 Invalidate(_PaletteSelectorFrame(fPreviousSelectedPaletteColorIndex)); 267 Invalidate(_PaletteSelectorFrame(fSelectedPaletteColorIndex)); 268 269 fPreviousSelectedPaletteColorIndex = fSelectedPaletteColorIndex; 270 271 } else { 272 273 float invalidateRadius = kSelectorSize/2 + kSelectorPenSize; 274 BPoint p; 275 276 if (c1.red != c2.red) { 277 sprintf(string, "%d", c2.red); 278 fRedText->SetText(string); 279 280 p = _SelectorPosition(_RampFrame(1), c1.red); 281 Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius, 282 p.x + invalidateRadius, p.y + invalidateRadius)); 283 284 p = _SelectorPosition(_RampFrame(1), c2.red); 285 Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius, 286 p.x + invalidateRadius, p.y + invalidateRadius)); 287 } 288 289 if (c1.green != c2.green) { 290 sprintf(string, "%d", c2.green); 291 fGreenText->SetText(string); 292 293 p = _SelectorPosition(_RampFrame(2), c1.green); 294 Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius, 295 p.x + invalidateRadius, p.y + invalidateRadius)); 296 297 p = _SelectorPosition(_RampFrame(2), c2.green); 298 Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius, 299 p.x + invalidateRadius, p.y + invalidateRadius)); 300 } 301 if (c1.blue != c2.blue) { 302 sprintf(string, "%d", c2.blue); 303 fBlueText->SetText(string); 304 305 p = _SelectorPosition(_RampFrame(3), c1.blue); 306 Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius, 307 p.x + invalidateRadius, p.y + invalidateRadius)); 308 309 p = _SelectorPosition(_RampFrame(3), c2.blue); 310 Invalidate(BRect(p.x - invalidateRadius, p.y - invalidateRadius, 311 p.x + invalidateRadius, p.y + invalidateRadius)); 312 } 261 313 } 262 314 263 315 BControl::SetValueNoUpdate(value); … … 308 360 fRedText->SetTarget(this); 309 361 fGreenText->SetTarget(this); 310 362 fBlueText->SetTarget(this); 363 364 if (fBitmap) 365 _InitOffscreen(); 311 366 } 312 367 313 368 … … 318 373 case kMsgColorEntered: 319 374 { 320 375 rgb_color color; 321 color.red = strtol(fRedText->Text(), NULL, 10);322 color.green = strtol(fGreenText->Text(), NULL, 10);323 color.blue = strtol(fBlueText->Text(), NULL, 10);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/*)*/; 324 379 color.alpha = 255; 325 380 381 //TODO: text is not updated if the clamping 382 // gives the same value next time 383 326 384 SetValue(color); 327 385 Invoke(); 328 386 break; … … 341 399 return; 342 400 343 401 if (fOffscreenView->Bounds().Intersects(updateRect)) { 344 _UpdateOffscreen(updateRect);345 402 BRegion region(updateRect); 346 403 ConstrainClippingRegion(®ion); 347 404 DrawBitmap(fBitmap, B_ORIGIN); … … 349 406 } 350 407 351 408 fBitmap->Unlock(); 409 _DrawSelectors(this); 410 352 411 } else 353 412 _DrawColorArea(this, updateRect); 413 _DrawSelectors(this); 354 414 } 355 415 356 416 … … 359 419 { 360 420 BRegion region(update); 361 421 target->ConstrainClippingRegion(®ion); 362 363 BRect rect(0.0f, 0.0f, ceil(fColumns * fCellSize), Bounds().bottom); 364 422 365 423 rgb_color noTint = ui_color(B_PANEL_BACKGROUND_COLOR), 366 424 lightenmax = tint_color(noTint, B_LIGHTEN_MAX_TINT), 367 425 darken1 = tint_color(noTint, B_DARKEN_1_TINT), 368 426 darken4 = tint_color(noTint, B_DARKEN_4_TINT); 369 427 428 BRect bevelRect = fPaletteFrame.InsetByCopy(-2.0,-2.0); //bevel 429 370 430 // First bevel 371 431 target->SetHighColor(darken1); 372 target->StrokeLine( rect.LeftBottom(), rect.LeftTop());373 target->StrokeLine( rect.LeftTop(), rect.RightTop());432 target->StrokeLine(bevelRect.LeftBottom(), bevelRect.LeftTop()); 433 target->StrokeLine(bevelRect.LeftTop(), bevelRect.RightTop()); 374 434 target->SetHighColor(lightenmax); 375 target->StrokeLine(BPoint( rect.left + 1.0f, rect.bottom), rect.RightBottom());376 target->StrokeLine( rect.RightBottom(), BPoint(rect.right, rect.top + 1.0f));435 target->StrokeLine(BPoint(bevelRect.left + 1.0f, bevelRect.bottom), bevelRect.RightBottom()); 436 target->StrokeLine(bevelRect.RightBottom(), BPoint(bevelRect.right, bevelRect.top + 1.0f)); 377 437 378 rect.InsetBy(1.0f, 1.0f);438 bevelRect.InsetBy(1.0f, 1.0f); 379 439 380 440 // Second bevel 381 441 target->SetHighColor(darken4); 382 target->StrokeLine( rect.LeftBottom(), rect.LeftTop());383 target->StrokeLine( rect.LeftTop(), rect.RightTop());442 target->StrokeLine(bevelRect.LeftBottom(), bevelRect.LeftTop()); 443 target->StrokeLine(bevelRect.LeftTop(), bevelRect.RightTop()); 384 444 target->SetHighColor(noTint); 385 target->StrokeLine(BPoint(rect.left + 1.0f, rect.bottom), rect.RightBottom()); 386 target->StrokeLine(rect.RightBottom(), BPoint(rect.right, rect.top + 1.0f)); 445 target->StrokeLine(BPoint(bevelRect.left + 1.0f, bevelRect.bottom), bevelRect.RightBottom()); 446 target->StrokeLine(bevelRect.RightBottom(), BPoint(bevelRect.right, bevelRect.top + 1.0f)); 447 448 if (fPaletteMode) { 449 450 int colBegin = max_c(0, -1 + int(update.left) / int(fCellSize)); 451 int colEnd = min_c(fColumns, 2 + int(update.right) / int(fCellSize)); 452 int rowBegin = max_c(0, -1 + int(update.top) / int(fCellSize)); 453 int rowEnd = min_c(fRows, 2 + int(update.bottom) / int(fCellSize)); 454 455 //grid 456 target->SetHighColor(darken1); 457 for (int xi = 0; xi < fColumns+1; xi++){ 458 float x = fPaletteFrame.left + float(xi) * fCellSize; 459 target->StrokeLine(BPoint(x, fPaletteFrame.top), BPoint(x, fPaletteFrame.bottom)); 460 } 461 for (int yi = 0; yi < fRows+1; yi++){ 462 float y = fPaletteFrame.top + float(yi) * fCellSize; 463 target->StrokeLine(BPoint(fPaletteFrame.left, y), BPoint(fPaletteFrame.right, y)); 464 } 465 466 //colors 467 for (int col = colBegin; col < colEnd; col++){ 468 469 for (int row = rowBegin; row < rowEnd; row++){ 470 471 uint8 colorIndex = row * fColumns + col; 472 float x = fPaletteFrame.left + col * fCellSize; 473 float y = fPaletteFrame.top + row * fCellSize; 474 475 target->SetHighColor(system_colors()->color_list[colorIndex]); 476 target->FillRect(BRect(x+1, y+1, x + fCellSize - 1, y + fCellSize - 1)); 477 } 478 } 479 480 } else { 481 482 rgb_color white = {255, 255, 255, 255}; 483 rgb_color red = {255, 0, 0, 255}; 484 rgb_color green = {0, 255, 0, 255}; 485 rgb_color blue = {0, 0, 255, 255}; 486 487 _ColorRamp(_RampFrame(0), target, white, 0, false, update); 488 _ColorRamp(_RampFrame(1), target, red, 0, false, update); 489 _ColorRamp(_RampFrame(2), target, green, 0, false, update); 490 _ColorRamp(_RampFrame(3), target, blue, 0, false, update); 491 } 492 493 ConstrainClippingRegion(NULL); 494 } 387 495 388 // Ramps389 rgb_color white = {255, 255, 255, 255};390 rgb_color red = {255, 0, 0, 255};391 rgb_color green = {0, 255, 0, 255};392 rgb_color blue = {0, 0, 255, 255};393 496 394 rect.InsetBy(1.0f, 1.0f); 395 396 BRect rampRect(rect); 397 float rampSize = rampRect.Height() / 4.0; 398 399 rampRect.bottom = rampRect.top + rampSize; 400 401 _ColorRamp(rampRect, target, white, 0, false); 402 403 rampRect.OffsetBy(0, rampSize); 404 _ColorRamp(rampRect, target, red, 0, false); 405 406 rampRect.OffsetBy(0,rampSize); 407 _ColorRamp(rampRect, target, green, 0, false); 408 409 rampRect.OffsetBy(0, rampSize); 410 _ColorRamp(rampRect, target, blue, 0, false); 411 412 // Selectors 413 rgb_color color = ValueAsColor(); 414 float x, y = rampSize * 1.5; 415 416 target->SetDrawingMode(B_OP_OVER); 417 target->SetPenSize(2.0f); 418 419 x = rect.left + color.red * (rect.Width() - 7) / 255; 420 target->SetHighColor(255, 255, 255); 421 target->StrokeEllipse(BRect(x, y, x + 4.0f, y + 4.0f)); 422 423 y += rampSize; 424 425 x = rect.left + color.green * (rect.Width() - 7) / 255; 426 target->SetHighColor(255, 255, 255); 427 target->StrokeEllipse(BRect(x, y, x + 4.0f, y + 4.0f)); 428 429 y += rampSize; 430 431 x = rect.left + color.blue * (rect.Width() - 7) / 255; 432 target->SetHighColor(255, 255, 255); 433 target->StrokeEllipse(BRect(x, y, x + 4.0f, y + 4.0f)); 434 435 target->SetPenSize(1.0f); 436 target->SetDrawingMode(B_OP_COPY); 437 438 target->ConstrainClippingRegion(NULL); 497 void 498 BColorControl::_DrawSelectors(BView* target) 499 { 500 rgb_color noTint = ui_color(B_PANEL_BACKGROUND_COLOR); 501 rgb_color lightenmax = tint_color(noTint, B_LIGHTEN_MAX_TINT); 502 503 504 if (fPaletteMode) { 505 if (fSelectedPaletteColorIndex != -1) { 506 target->SetHighColor(lightenmax); 507 target->StrokeRect(_PaletteSelectorFrame(fSelectedPaletteColorIndex)); 508 } 509 510 } else { 511 512 rgb_color color = ValueAsColor(); 513 target->SetPenSize(kSelectorPenSize); 514 target->SetHighColor(255, 255, 255); 515 516 target->StrokeEllipse(_SelectorPosition(_RampFrame(1), color.red), 517 kSelectorSize / 2, kSelectorSize / 2); 518 target->StrokeEllipse(_SelectorPosition(_RampFrame(2), color.green), 519 kSelectorSize / 2, kSelectorSize / 2); 520 target->StrokeEllipse(_SelectorPosition(_RampFrame(3), color.blue), 521 kSelectorSize / 2, kSelectorSize / 2); 522 523 target->SetPenSize(1.0f); 524 } 439 525 } 440 526 441 527 442 528 void 443 529 BColorControl::_ColorRamp(BRect rect, BView* target, 444 rgb_color baseColor, int16 flag, bool focused )530 rgb_color baseColor, int16 flag, bool focused, BRect update) 445 531 { 446 float width = rect.Width() +1;532 float width = rect.Width() + 1; 447 533 rgb_color color; 448 534 color.alpha = 255; 535 536 update = update & rect; 449 537 450 target->BeginLineArray((int32)width); 538 if (update.IsValid() && update.Width() >= 0){ 539 target->BeginLineArray((int32)update.Width() + 1); 540 541 for (float i = (update.left - rect.left); i <= (update.right - rect.left) + 1; i++) { 542 color.red = (uint8)(i * baseColor.red / width); 543 color.green = (uint8)(i * baseColor.green / width); 544 color.blue = (uint8)(i * baseColor.blue / width); 545 546 target->AddLine(BPoint(rect.left + i, rect.top), 547 BPoint(rect.left + i, rect.bottom - 1), color); 548 } 549 550 target->EndLineArray(); 551 } 552 } 451 553 452 for (float i = 0; i <= width; i++) {453 color.red = (uint8)(i * baseColor.red / width);454 color.green = (uint8)(i * baseColor.green / width);455 color.blue = (uint8)(i * baseColor.blue / width);456 554 457 target->AddLine(BPoint(rect.left + i, rect.top), 458 BPoint(rect.left + i, rect.bottom), color); 459 } 555 BPoint 556 BColorControl::_SelectorPosition(const BRect& rampRect, uint8 shade) const 557 { 558 float radius = kSelectorSize / 2 + kSelectorPenSize / 2; 559 560 return BPoint(rampRect.left + kSelectorHSpacing + radius + 561 shade * (rampRect.Width() - 2 * (kSelectorHSpacing + radius)) / 255, 562 rampRect.top + rampRect.Height() / 2); 563 } 460 564 461 target->EndLineArray(); 565 566 BRect 567 BColorControl::_RampFrame(uint8 rampIndex) const 568 { 569 float rampHeight = 2 * fCellSize; 570 571 return BRect( fPaletteFrame.left, 572 fPaletteFrame.top + float(rampIndex) * rampHeight, 573 fPaletteFrame.right, 574 fPaletteFrame.top + float(rampIndex + 1) * rampHeight); 462 575 } 463 576 464 577 578 BRect 579 BColorControl::_PaletteSelectorFrame(uint8 colorIndex) const 580 { 581 uint32 row = colorIndex / fColumns; 582 uint32 column = colorIndex % fColumns; 583 float x = fPaletteFrame.left + column * fCellSize; 584 float y = fPaletteFrame.top + row * fCellSize; 585 return BRect(x, y, x + fCellSize, y + fCellSize); 586 } 587 588 465 589 void 466 BColorControl::_ UpdateOffscreen(BRect update)590 BColorControl::_InitOffscreen() 467 591 { 468 if (fBitmap->Lock()) { 469 update = update & fOffscreenView->Bounds(); 470 fOffscreenView->FillRect(update); 471 _DrawColorArea(fOffscreenView, update); 592 if (fBitmap->Lock()) { 593 _DrawColorArea(fOffscreenView, fPaletteFrame.InsetByCopy(-2.0f,-2.0f)); 472 594 fOffscreenView->Sync(); 473 595 fBitmap->Unlock(); 474 596 } … … 478 600 void 479 601 BColorControl::SetCellSize(float cellSide) 480 602 { 481 fCellSize = max_c(kMinCellSize, cellSide);482 603 fCellSize = ceil(max_c(kMinCellSize, cellSide)); 604 //TODO: update fPaletteFrame here? 483 605 ResizeToPreferred(); 484 606 } 485 607 … … 516 638 fRows = 4; 517 639 break; 518 640 } 641 642 //TODO: update fPaletteFrame here? 519 643 520 644 ResizeToPreferred(); 521 645 Invalidate(); … … 566 690 void 567 691 BColorControl::MouseDown(BPoint point) 568 692 { 569 BRect rect(0.0f, 0.0f, fColumns * fCellSize, Bounds().bottom); 570 if (!rect.Contains(point)) 693 if (!fPaletteFrame.Contains(point)) 571 694 return; 572 573 rgb_color color = ValueAsColor(); 574 575 float rampsize = rect.bottom / 4; 576 577 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) { 581 color.red = color.green = color.blue = shade; 582 fFocusedComponent = 1; 583 } else if (point.y - 2 < (rampsize * 2)) { 584 color.red = shade; 585 fFocusedComponent = 2; 586 } else if (point.y - 2 < (rampsize * 3)) { 587 color.green = shade; 588 fFocusedComponent = 3; 589 } else { 590 color.blue = shade; 591 fFocusedComponent = 4; 695 696 if (fPaletteMode) { 697 698 int column = (int) ( (point.x - fPaletteFrame.left) / fCellSize ); 699 int row = (int) ( (point.y - fPaletteFrame.top) / fCellSize ); 700 int colorIndex = row * fColumns + column; 701 if (colorIndex >= 0 && colorIndex < 256) { 702 fSelectedPaletteColorIndex = colorIndex; 703 SetValue(system_colors()->color_list[colorIndex]); 704 } 705 706 } else { 707 708 rgb_color color = ValueAsColor(); 709 710 uint8 shade = (unsigned char)max_c(0, 711 min_c((point.x - _RampFrame(0).left) * 255 / _RampFrame(0).Width(), 255)); 712 713 if (_RampFrame(0).Contains(point)) { 714 color.red = color.green = color.blue = shade; 715 fFocusedComponent = 1; 716 } else if (_RampFrame(1).Contains(point)) { 717 color.red = shade; 718 fFocusedComponent = 2; 719 } else if (_RampFrame(2).Contains(point)) { 720 color.green = shade; 721 fFocusedComponent = 3; 722 } else if (_RampFrame(3).Contains(point)){ 723 color.blue = shade; 724 fFocusedComponent = 4; 725 } 726 727 SetValue(color); 728 592 729 } 593 594 SetValue(color); 730 595 731 Invoke(); 596 732 597 733 SetTracking(true); … … 604 740 BColorControl::MouseMoved(BPoint point, uint32 transit, 605 741 const BMessage *message) 606 742 { 607 if (fFocusedComponent == 0 || !IsTracking()) 608 return; 743 if (!IsTracking()) 744 return; 745 746 if (fPaletteMode && fPaletteFrame.Contains(point)) { 747 748 int column = (int) ( (point.x - fPaletteFrame.left) / fCellSize ); 749 int row = (int) ( (point.y - fPaletteFrame.top) / fCellSize ); 750 int colorIndex = row * fColumns + column; 751 if (colorIndex >= 0 && colorIndex < 256) { 752 fSelectedPaletteColorIndex = colorIndex; 753 SetValue(system_colors()->color_list[colorIndex]); 754 } 755 756 } else { 609 757 610 rgb_color color = ValueAsColor(); 611 612 BRect rect(0.0f, 0.0f, fColumns * fCellSize, Bounds().bottom); 613 614 uint8 shade = (unsigned char)max_c(0, 615 min_c((point.x - 2) * 255 / (rect.Width() - 4.0f), 255)); 616 617 switch (fFocusedComponent) { 618 case 1: 619 color.red = color.green = color.blue = shade; 620 break; 621 case 2: 622 color.red = shade; 623 break; 624 case 3: 625 color.green = shade; 626 break; 627 case 4: 628 color.blue = shade; 629 break; 630 default: 631 break; 758 if (fFocusedComponent == 0) 759 return; 760 761 rgb_color color = ValueAsColor(); 762 763 uint8 shade = (unsigned char)max_c(0, 764 min_c((point.x - _RampFrame(0).left) * 255 / _RampFrame(0).Width(), 255)); 765 766 switch (fFocusedComponent) { 767 case 1: 768 color.red = color.green = color.blue = shade; 769 break; 770 case 2: 771 color.red = shade; 772 break; 773 case 3: 774 color.green = shade; 775 break; 776 case 4: 777 color.blue = shade; 778 break; 779 default: 780 break; 781 } 782 783 SetValue(color); 632 784 } 633 634 SetValue(color); 785 635 786 Invoke(); 636 787 } 637 788 … … 646 797 void 647 798 BColorControl::GetPreferredSize(float *_width, float *_height) 648 799 { 800 BRect rect = fPaletteFrame.InsetByCopy(-2.0,-2.0); //bevel 801 802 if (rect.Height() < fBlueText->Frame().bottom) { 803 // adjust the height to fit 804 rect.bottom = fBlueText->Frame().bottom; 805 } 806 649 807 if (_width) 650 *_width = fColumns * fCellSize + 4.0f+ fRedText->Bounds().Width();808 *_width = rect.Width() + kTextFieldsHSpacing + fRedText->Bounds().Width(); 651 809 652 810 if (_height) 653 *_height = fBlueText->Frame().bottom;811 *_height = rect.Height(); 654 812 } 655 813 656 814 -
headers/os/interface/ColorControl.h
87 87 float size, bool useOffscreen, 88 88 BMessage* archive = NULL); 89 89 void _LayoutView(); 90 void _ UpdateOffscreen(BRect update);90 void _InitOffscreen(); 91 91 void _DrawColorArea(BView* target, BRect update); 92 void _DrawSelectors(BView* target); 92 93 void _ColorRamp(BRect rect, BView* target, 93 94 rgb_color baseColor, int16 flag, 94 bool focused); 95 95 bool focused, BRect update); 96 BPoint _SelectorPosition(const BRect& rampRect, uint8 shade) const; 97 BRect _PaletteSelectorFrame(uint8 colorIndex) const; 98 BRect _RampFrame(uint8 rampIndex) const; 99 96 100 private: 101 BRect fPaletteFrame; 102 int16 fSelectedPaletteColorIndex; 103 int16 fPreviousSelectedPaletteColorIndex; 104 97 105 float fCellSize; 98 106 int32 fRows; 99 107 int32 fColumns; 108 bool fPaletteMode; 109 bool _unused[3]; 100 110 101 111 BTextControl* fRedText; 102 112 BTextControl* fGreenText; … … 105 115 BBitmap* fBitmap; 106 116 BView* fOffscreenView; 107 117 108 int32 fFocusedComponent; 109 uint32 _reserved[ 8];118 int32 fFocusedComponent; 119 uint32 _reserved[2]; 110 120 }; 111 121 112 122 inline void -
src/preferences/backgrounds/BackgroundsView.cpp
216 216 rightbox->AddChild(fIconLabelOutline); 217 217 218 218 rect.top += fIconLabelOutline->Bounds().Height() + 15; 219 fPicker = new BColorControl(BPoint(10, rect.top), B_CELLS_32x8, 5.0, "Picker",219 fPicker = new BColorControl(BPoint(10, rect.top), B_CELLS_32x8, 7.0, "Picker", 220 220 new BMessage(kMsgUpdateColor)); 221 221 rightbox->AddChild(fPicker); 222 222