* whitespace cleanup

* implemented the disabled look and color ramping


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28503 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2008-11-04 19:08:26 +00:00
parent 167460c123
commit d2184e65c1
2 changed files with 103 additions and 82 deletions
+2 -2
View File
@@ -91,8 +91,8 @@ class BColorControl : public BControl {
void _DrawColorArea(BView* target, BRect update);
void _DrawSelectors(BView* target);
void _ColorRamp(BRect rect, BView* target,
rgb_color baseColor, int16 flag,
bool focused, BRect update);
rgb_color baseColor, rgb_color compColor,
int16 flag, bool focused, BRect update);
BPoint _SelectorPosition(const BRect& rampRect, uint8 shade) const;
BRect _PaletteSelectorFrame(uint8 colorIndex) const;
BRect _RampFrame(uint8 rampIndex) const;
+67 -46
View File
@@ -6,6 +6,7 @@
* Marc Flerackers ([email protected])
* Axel Dörfler, [email protected]
* Alexandre Deckner, [email protected]
* Jérôme Duval
*/
/** BColorControl displays a palette of selectable colors. */
@@ -413,25 +414,38 @@ BColorControl::_DrawColorArea(BView* target, BRect update)
BRegion region(update);
target->ConstrainClippingRegion(&region);
rgb_color noTint = ui_color(B_PANEL_BACKGROUND_COLOR),
lightenmax = tint_color(noTint, B_LIGHTEN_MAX_TINT),
darken1 = tint_color(noTint, B_DARKEN_1_TINT),
darken4 = tint_color(noTint, B_DARKEN_4_TINT);
rgb_color noTint = ui_color(B_PANEL_BACKGROUND_COLOR);
rgb_color lighten1 = tint_color(noTint, B_LIGHTEN_1_TINT);
rgb_color lightenmax = tint_color(noTint, B_LIGHTEN_MAX_TINT);
rgb_color darken1 = tint_color(noTint, B_DARKEN_1_TINT);
rgb_color darken2 = tint_color(noTint, B_DARKEN_2_TINT);
rgb_color darken4 = tint_color(noTint, B_DARKEN_4_TINT);
BRect bevelRect = fPaletteFrame.InsetByCopy(-2.0,-2.0); //bevel
bool enabled = IsEnabled();
// First bevel
target->SetHighColor(darken1);
if (enabled)
target->SetHighColor(darken1);
else
target->SetHighColor(noTint);
target->StrokeLine(bevelRect.LeftBottom(), bevelRect.LeftTop());
target->StrokeLine(bevelRect.LeftTop(), bevelRect.RightTop());
target->SetHighColor(lightenmax);
if (enabled)
target->SetHighColor(lightenmax);
else
target->SetHighColor(lighten1);
target->StrokeLine(BPoint(bevelRect.left + 1.0f, bevelRect.bottom), bevelRect.RightBottom());
target->StrokeLine(bevelRect.RightBottom(), BPoint(bevelRect.right, bevelRect.top + 1.0f));
bevelRect.InsetBy(1.0f, 1.0f);
// Second bevel
target->SetHighColor(darken4);
if (enabled)
target->SetHighColor(darken4);
else
target->SetHighColor(darken2);
target->StrokeLine(bevelRect.LeftBottom(), bevelRect.LeftTop());
target->StrokeLine(bevelRect.LeftTop(), bevelRect.RightTop());
target->SetHighColor(noTint);
@@ -439,43 +453,52 @@ BColorControl::_DrawColorArea(BView* target, BRect update)
target->StrokeLine(bevelRect.RightBottom(), BPoint(bevelRect.right, bevelRect.top + 1.0f));
if (fPaletteMode) {
int colBegin = max_c(0, -1 + int(update.left) / int(fCellSize));
int colEnd = min_c(fColumns, 2 + int(update.right) / int(fCellSize));
int rowBegin = max_c(0, -1 + int(update.top) / int(fCellSize));
int rowEnd = min_c(fRows, 2 + int(update.bottom) / int(fCellSize));
int colBegin = max_c(0, -1 + int(update.left) / int(fCellSize));
int colEnd = min_c(fColumns, 2 + int(update.right) / int(fCellSize));
int rowBegin = max_c(0, -1 + int(update.top) / int(fCellSize));
int rowEnd = min_c(fRows, 2 + int(update.bottom) / int(fCellSize));
//grid
target->SetHighColor(darken1);
for (int xi = 0; xi < fColumns+1; xi++){
//grid
if (enabled)
target->SetHighColor(darken1);
else
target->SetHighColor(noTint);
for (int xi = 0; xi < fColumns+1; xi++) {
float x = fPaletteFrame.left + float(xi) * fCellSize;
target->StrokeLine(BPoint(x, fPaletteFrame.top), BPoint(x, fPaletteFrame.bottom));
}
for (int yi = 0; yi < fRows+1; yi++){
for (int yi = 0; yi < fRows+1; yi++) {
float y = fPaletteFrame.top + float(yi) * fCellSize;
target->StrokeLine(BPoint(fPaletteFrame.left, y), BPoint(fPaletteFrame.right, y));
}
//colors
for (int col = colBegin; col < colEnd; col++){
for (int row = rowBegin; row < rowEnd; row++){
uint8 colorIndex = row * fColumns + col;
float x = fPaletteFrame.left + col * fCellSize;
//colors
for (int col = colBegin; col < colEnd; col++) {
for (int row = rowBegin; row < rowEnd; row++) {
uint8 colorIndex = row * fColumns + col;
float x = fPaletteFrame.left + col * fCellSize;
float y = fPaletteFrame.top + row * fCellSize;
target->SetHighColor(system_colors()->color_list[colorIndex]);
target->SetHighColor(system_colors()->color_list[colorIndex]);
target->FillRect(BRect(x+1, y+1, x + fCellSize - 1, y + fCellSize - 1));
}
}
}
}
} else {
rgb_color white = {255, 255, 255, 255};
rgb_color red = {255, 0, 0, 255};
rgb_color green = {0, 255, 0, 255};
rgb_color blue = {0, 0, 255, 255};
_ColorRamp(_RampFrame(0), target, white, 0, false, update);
_ColorRamp(_RampFrame(1), target, red, 0, false, update);
_ColorRamp(_RampFrame(2), target, green, 0, false, update);
_ColorRamp(_RampFrame(3), target, blue, 0, false, update);
rgb_color compColor = {0, 0, 0, 255};
if (!enabled) {
compColor.red = compColor.green = compColor.blue = 156;
red.red = green.green = blue.blue = 70;
white.red = white.green = white.blue = 70;
}
_ColorRamp(_RampFrame(0), target, white, compColor, 0, false, update);
_ColorRamp(_RampFrame(1), target, red, compColor, 0, false, update);
_ColorRamp(_RampFrame(2), target, green, compColor, 0, false, update);
_ColorRamp(_RampFrame(3), target, blue, compColor, 0, false, update);
}
ConstrainClippingRegion(NULL);
@@ -512,7 +535,7 @@ BColorControl::_DrawSelectors(BView* target)
void
BColorControl::_ColorRamp(BRect rect, BView* target,
rgb_color baseColor, int16 flag, bool focused, BRect update)
rgb_color baseColor, rgb_color compColor, int16 flag, bool focused, BRect update)
{
float width = rect.Width() + 1;
rgb_color color;
@@ -524,10 +547,9 @@ BColorControl::_ColorRamp(BRect rect, BView* target,
target->BeginLineArray((int32)update.Width() + 1);
for (float i = (update.left - rect.left); i <= (update.right - rect.left) + 1; i++) {
color.red = (uint8)(i * baseColor.red / width);
color.green = (uint8)(i * baseColor.green / width);
color.blue = (uint8)(i * baseColor.blue / width);
color.red = (uint8)(i * baseColor.red / width) + compColor.red;
color.green = (uint8)(i * baseColor.green / width) + compColor.green;
color.blue = (uint8)(i * baseColor.blue / width) + compColor.blue;
target->AddLine(BPoint(rect.left + i, rect.top),
BPoint(rect.left + i, rect.bottom - 1), color);
}
@@ -681,18 +703,18 @@ BColorControl::MouseDown(BPoint point)
return;
if (fPaletteMode) {
int column = (int) ( (point.x - fPaletteFrame.left) / fCellSize );
int column = (int) ( (point.x - fPaletteFrame.left) / fCellSize );
int row = (int) ( (point.y - fPaletteFrame.top) / fCellSize );
int colorIndex = row * fColumns + column;
if (colorIndex >= 0 && colorIndex < 256) {
fSelectedPaletteColorIndex = colorIndex;
SetValue(system_colors()->color_list[colorIndex]);
}
int colorIndex = row * fColumns + column;
if (colorIndex >= 0 && colorIndex < 256) {
fSelectedPaletteColorIndex = colorIndex;
SetValue(system_colors()->color_list[colorIndex]);
}
} else {
rgb_color color = ValueAsColor();
uint8 shade = (unsigned char)max_c(0,
min_c((point.x - _RampFrame(0).left) * 255 / _RampFrame(0).Width(), 255));
min_c((point.x - _RampFrame(0).left) * 255 / _RampFrame(0).Width(), 255));
if (_RampFrame(0).Contains(point)) {
color.red = color.green = color.blue = shade;
@@ -728,14 +750,13 @@ BColorControl::MouseMoved(BPoint point, uint32 transit,
return;
if (fPaletteMode && fPaletteFrame.Contains(point)) {
int column = (int) ( (point.x - fPaletteFrame.left) / fCellSize );
int column = (int) ( (point.x - fPaletteFrame.left) / fCellSize );
int row = (int) ( (point.y - fPaletteFrame.top) / fCellSize );
int colorIndex = row * fColumns + column;
if (colorIndex >= 0 && colorIndex < 256) {
fSelectedPaletteColorIndex = colorIndex;
SetValue(system_colors()->color_list[colorIndex]);
}
int colorIndex = row * fColumns + column;
if (colorIndex >= 0 && colorIndex < 256) {
fSelectedPaletteColorIndex = colorIndex;
SetValue(system_colors()->color_list[colorIndex]);
}
} else {
if (fFocusedComponent == 0)
return;