BColorControl: Style fixes
* Update copyright in header, add my name, alphabetize. * Rename _ColorRamp() to _DrawColorRamp(). * Rename update parameter to updateRect
This commit is contained in:
parent
2a95812e46
commit
0289f92063
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2005, Haiku, Inc. All Rights Reserved.
|
* Copyright 2005-2013 Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef _COLOR_CONTROL_H
|
#ifndef _COLOR_CONTROL_H
|
||||||
@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
#include <Control.h>
|
#include <Control.h>
|
||||||
|
|
||||||
class BBitmap;
|
|
||||||
|
|
||||||
|
|
||||||
enum color_control_layout {
|
enum color_control_layout {
|
||||||
B_CELLS_4x64 = 4,
|
B_CELLS_4x64 = 4,
|
||||||
@ -19,6 +17,8 @@ enum color_control_layout {
|
|||||||
B_CELLS_64x4 = 64,
|
B_CELLS_64x4 = 64,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class BBitmap;
|
||||||
class BTextControl;
|
class BTextControl;
|
||||||
|
|
||||||
|
|
||||||
@ -93,13 +93,14 @@ private:
|
|||||||
void _LayoutView();
|
void _LayoutView();
|
||||||
void _InitOffscreen();
|
void _InitOffscreen();
|
||||||
void _DrawColorArea(BView* target, BRect update);
|
void _DrawColorArea(BView* target, BRect update);
|
||||||
void _DrawSelectors(BView* target);
|
void _DrawSelectors(BView* target);
|
||||||
void _ColorRamp(BRect rect, BView* target,
|
void _DrawColorRamp(BRect rect, BView* target,
|
||||||
rgb_color baseColor, rgb_color compColor,
|
rgb_color baseColor, rgb_color compColor,
|
||||||
int16 flag, bool focused, BRect update);
|
int16 flag, bool focused,
|
||||||
|
BRect updateRect);
|
||||||
BPoint _SelectorPosition(const BRect& rampRect,
|
BPoint _SelectorPosition(const BRect& rampRect,
|
||||||
uint8 shade) const;
|
uint8 shade) const;
|
||||||
BRect _PaletteSelectorFrame(uint8 colorIndex) const;
|
BRect _PaletteSelectorFrame(uint8 colorIndex) const;
|
||||||
BRect _RampFrame(uint8 rampIndex) const;
|
BRect _RampFrame(uint8 rampIndex) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2008, Haiku Inc.
|
* Copyright 2001-2013 Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Marc Flerackers (mflerackers@androme.be)
|
|
||||||
* Axel Dörfler, axeld@pinc-software.de
|
|
||||||
* Alexandre Deckner, alex@zappotek.com
|
* Alexandre Deckner, alex@zappotek.com
|
||||||
|
* Axel Dörfler, axeld@pinc-software.de
|
||||||
* Jérôme Duval
|
* Jérôme Duval
|
||||||
|
* Marc Flerackers, mflerackers@androme.be
|
||||||
|
* John Scipione, jscipione@gmail.com
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** BColorControl displays a palette of selectable colors. */
|
/** BColorControl displays a palette of selectable colors. */
|
||||||
@ -41,18 +42,20 @@ static const float kSelectorSize = 4.0f;
|
|||||||
static const float kSelectorHSpacing = 2.0f;
|
static const float kSelectorHSpacing = 2.0f;
|
||||||
static const float kTextFieldsHSpacing = 6.0f;
|
static const float kTextFieldsHSpacing = 6.0f;
|
||||||
|
|
||||||
|
|
||||||
BColorControl::BColorControl(BPoint leftTop, color_control_layout layout,
|
BColorControl::BColorControl(BPoint leftTop, color_control_layout layout,
|
||||||
float cellSize, const char *name, BMessage *message,
|
float cellSize, const char* name, BMessage* message, bool bufferedDrawing)
|
||||||
bool bufferedDrawing)
|
:
|
||||||
: BControl(BRect(leftTop, leftTop), name, NULL, message,
|
BControl(BRect(leftTop, leftTop), name, NULL, message,
|
||||||
B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE)
|
B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE)
|
||||||
{
|
{
|
||||||
_InitData(layout, cellSize, bufferedDrawing, NULL);
|
_InitData(layout, cellSize, bufferedDrawing, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BColorControl::BColorControl(BMessage* archive)
|
BColorControl::BColorControl(BMessage* archive)
|
||||||
: BControl(archive)
|
:
|
||||||
|
BControl(archive)
|
||||||
{
|
{
|
||||||
int32 layout;
|
int32 layout;
|
||||||
float cellSize;
|
float cellSize;
|
||||||
@ -94,7 +97,7 @@ BColorControl::_InitData(color_control_layout layout, float size,
|
|||||||
green = gSystemCatalog.GetString(green, "ColorControl");
|
green = gSystemCatalog.GetString(green, "ColorControl");
|
||||||
blue = gSystemCatalog.GetString(blue, "ColorControl");
|
blue = gSystemCatalog.GetString(blue, "ColorControl");
|
||||||
|
|
||||||
if (archive) {
|
if (archive != NULL) {
|
||||||
fRedText = (BTextControl*)FindView("_red");
|
fRedText = (BTextControl*)FindView("_red");
|
||||||
fGreenText = (BTextControl*)FindView("_green");
|
fGreenText = (BTextControl*)FindView("_green");
|
||||||
fBlueText = (BTextControl*)FindView("_blue");
|
fBlueText = (BTextControl*)FindView("_blue");
|
||||||
@ -116,17 +119,17 @@ BColorControl::_InitData(color_control_layout layout, float size,
|
|||||||
B_WILL_DRAW | B_NAVIGABLE);
|
B_WILL_DRAW | B_NAVIGABLE);
|
||||||
fRedText->SetDivider(labelWidth);
|
fRedText->SetDivider(labelWidth);
|
||||||
|
|
||||||
float offset = fRedText->Bounds().Height() + 2;
|
|
||||||
|
|
||||||
for (int32 i = 0; i < 256; i++)
|
for (int32 i = 0; i < 256; i++)
|
||||||
fRedText->TextView()->DisallowChar(i);
|
fRedText->TextView()->DisallowChar(i);
|
||||||
for (int32 i = '0'; i <= '9'; i++)
|
for (int32 i = '0'; i <= '9'; i++)
|
||||||
fRedText->TextView()->AllowChar(i);
|
fRedText->TextView()->AllowChar(i);
|
||||||
fRedText->TextView()->SetMaxBytes(3);
|
fRedText->TextView()->SetMaxBytes(3);
|
||||||
|
|
||||||
|
float offset = fRedText->Bounds().Height() + 2.0f;
|
||||||
|
|
||||||
// green
|
// green
|
||||||
|
|
||||||
rect.OffsetBy(0.0f, offset);
|
rect.OffsetBy(0, offset);
|
||||||
fGreenText = new BTextControl(rect, "_green", green, "0",
|
fGreenText = new BTextControl(rect, "_green", green, "0",
|
||||||
new BMessage(kMsgColorEntered), B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
new BMessage(kMsgColorEntered), B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||||
B_WILL_DRAW | B_NAVIGABLE);
|
B_WILL_DRAW | B_NAVIGABLE);
|
||||||
@ -140,7 +143,7 @@ BColorControl::_InitData(color_control_layout layout, float size,
|
|||||||
|
|
||||||
// blue
|
// blue
|
||||||
|
|
||||||
rect.OffsetBy(0.0f, offset);
|
rect.OffsetBy(0, offset);
|
||||||
fBlueText = new BTextControl(rect, "_blue", blue, "0",
|
fBlueText = new BTextControl(rect, "_blue", blue, "0",
|
||||||
new BMessage(kMsgColorEntered), B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
new BMessage(kMsgColorEntered), B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||||
B_WILL_DRAW | B_NAVIGABLE);
|
B_WILL_DRAW | B_NAVIGABLE);
|
||||||
@ -179,7 +182,7 @@ BColorControl::_InitData(color_control_layout layout, float size,
|
|||||||
void
|
void
|
||||||
BColorControl::_LayoutView()
|
BColorControl::_LayoutView()
|
||||||
{
|
{
|
||||||
if (fPaletteMode){
|
if (fPaletteMode) {
|
||||||
fPaletteFrame.Set(2.0f, 2.0f,
|
fPaletteFrame.Set(2.0f, 2.0f,
|
||||||
float(fColumns) * fCellSize + 2.0,
|
float(fColumns) * fCellSize + 2.0,
|
||||||
float(fRows) * fCellSize + 2.0);
|
float(fRows) * fCellSize + 2.0);
|
||||||
@ -187,11 +190,12 @@ BColorControl::_LayoutView()
|
|||||||
fPaletteFrame.Set(2.0f, 2.0f,
|
fPaletteFrame.Set(2.0f, 2.0f,
|
||||||
float(fColumns) * fCellSize + 2.0,
|
float(fColumns) * fCellSize + 2.0,
|
||||||
float(fRows) * fCellSize + 2.0 - 1.0);
|
float(fRows) * fCellSize + 2.0 - 1.0);
|
||||||
//1 pixel adjust so that the inner space
|
// 1 pixel adjust so that the inner space
|
||||||
//has exactly rows*cellsize pixels in height
|
// has exactly rows * cellsize pixels in height
|
||||||
}
|
}
|
||||||
|
|
||||||
BRect rect = fPaletteFrame.InsetByCopy(-2.0,-2.0); //bevel
|
BRect rect = fPaletteFrame.InsetByCopy(-2.0, -2.0);
|
||||||
|
// bevel
|
||||||
|
|
||||||
if (rect.Height() < fBlueText->Frame().bottom) {
|
if (rect.Height() < fBlueText->Frame().bottom) {
|
||||||
// adjust the height to fit
|
// adjust the height to fit
|
||||||
@ -213,13 +217,13 @@ BColorControl::_LayoutView()
|
|||||||
y += offset;
|
y += offset;
|
||||||
fBlueText->MoveTo(rect.right + kTextFieldsHSpacing, y);
|
fBlueText->MoveTo(rect.right + kTextFieldsHSpacing, y);
|
||||||
|
|
||||||
ResizeTo(rect.Width() + kTextFieldsHSpacing + fRedText->Bounds().Width(), rect.Height());
|
ResizeTo(rect.Width() + kTextFieldsHSpacing + fRedText->Bounds().Width(),
|
||||||
|
rect.Height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BArchivable *
|
BArchivable*
|
||||||
BColorControl::Instantiate(BMessage *archive)
|
BColorControl::Instantiate(BMessage* archive)
|
||||||
{
|
{
|
||||||
if (validate_instantiation(archive, "BColorControl"))
|
if (validate_instantiation(archive, "BColorControl"))
|
||||||
return new BColorControl(archive);
|
return new BColorControl(archive);
|
||||||
@ -229,7 +233,7 @@ BColorControl::Instantiate(BMessage *archive)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BColorControl::Archive(BMessage *archive, bool deep) const
|
BColorControl::Archive(BMessage* archive, bool deep) const
|
||||||
{
|
{
|
||||||
status_t status = BControl::Archive(archive, deep);
|
status_t status = BControl::Archive(archive, deep);
|
||||||
|
|
||||||
@ -376,7 +380,7 @@ BColorControl::AttachedToWindow()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BColorControl::MessageReceived(BMessage *message)
|
BColorControl::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case kMsgColorEntered:
|
case kMsgColorEntered:
|
||||||
@ -400,18 +404,19 @@ BColorControl::MessageReceived(BMessage *message)
|
|||||||
void
|
void
|
||||||
BColorControl::Draw(BRect updateRect)
|
BColorControl::Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
if (fBitmap)
|
if (fBitmap != NULL)
|
||||||
DrawBitmap(fBitmap, B_ORIGIN);
|
DrawBitmap(fBitmap, B_ORIGIN);
|
||||||
else
|
else
|
||||||
_DrawColorArea(this, updateRect);
|
_DrawColorArea(this, updateRect);
|
||||||
|
|
||||||
_DrawSelectors(this);
|
_DrawSelectors(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BColorControl::_DrawColorArea(BView* target, BRect update)
|
BColorControl::_DrawColorArea(BView* target, BRect updateRect)
|
||||||
{
|
{
|
||||||
BRect bevelRect = fPaletteFrame.InsetByCopy(-2.0,-2.0); //bevel
|
BRect bevelRect = fPaletteFrame.InsetByCopy(-2.0, -2.0);
|
||||||
bool enabled = IsEnabled();
|
bool enabled = IsEnabled();
|
||||||
|
|
||||||
rgb_color noTint = ui_color(B_PANEL_BACKGROUND_COLOR);
|
rgb_color noTint = ui_color(B_PANEL_BACKGROUND_COLOR);
|
||||||
@ -421,7 +426,8 @@ BColorControl::_DrawColorArea(BView* target, BRect update)
|
|||||||
uint32 flags = 0;
|
uint32 flags = 0;
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
flags |= BControlLook::B_DISABLED;
|
flags |= BControlLook::B_DISABLED;
|
||||||
be_control_look->DrawTextControlBorder(target, bevelRect, update,
|
|
||||||
|
be_control_look->DrawTextControlBorder(target, bevelRect, updateRect,
|
||||||
noTint, flags);
|
noTint, flags);
|
||||||
} else {
|
} else {
|
||||||
rgb_color lighten1 = tint_color(noTint, B_LIGHTEN_1_TINT);
|
rgb_color lighten1 = tint_color(noTint, B_LIGHTEN_1_TINT);
|
||||||
@ -429,17 +435,19 @@ BColorControl::_DrawColorArea(BView* target, BRect update)
|
|||||||
rgb_color darken2 = tint_color(noTint, B_DARKEN_2_TINT);
|
rgb_color darken2 = tint_color(noTint, B_DARKEN_2_TINT);
|
||||||
rgb_color darken4 = tint_color(noTint, B_DARKEN_4_TINT);
|
rgb_color darken4 = tint_color(noTint, B_DARKEN_4_TINT);
|
||||||
|
|
||||||
// First bevel
|
// first bevel
|
||||||
if (enabled)
|
if (enabled)
|
||||||
target->SetHighColor(darken1);
|
target->SetHighColor(darken1);
|
||||||
else
|
else
|
||||||
target->SetHighColor(noTint);
|
target->SetHighColor(noTint);
|
||||||
|
|
||||||
target->StrokeLine(bevelRect.LeftBottom(), bevelRect.LeftTop());
|
target->StrokeLine(bevelRect.LeftBottom(), bevelRect.LeftTop());
|
||||||
target->StrokeLine(bevelRect.LeftTop(), bevelRect.RightTop());
|
target->StrokeLine(bevelRect.LeftTop(), bevelRect.RightTop());
|
||||||
if (enabled)
|
if (enabled)
|
||||||
target->SetHighColor(lightenmax);
|
target->SetHighColor(lightenmax);
|
||||||
else
|
else
|
||||||
target->SetHighColor(lighten1);
|
target->SetHighColor(lighten1);
|
||||||
|
|
||||||
target->StrokeLine(BPoint(bevelRect.left + 1.0f, bevelRect.bottom),
|
target->StrokeLine(BPoint(bevelRect.left + 1.0f, bevelRect.bottom),
|
||||||
bevelRect.RightBottom());
|
bevelRect.RightBottom());
|
||||||
target->StrokeLine(bevelRect.RightBottom(),
|
target->StrokeLine(bevelRect.RightBottom(),
|
||||||
@ -447,11 +455,12 @@ BColorControl::_DrawColorArea(BView* target, BRect update)
|
|||||||
|
|
||||||
bevelRect.InsetBy(1.0f, 1.0f);
|
bevelRect.InsetBy(1.0f, 1.0f);
|
||||||
|
|
||||||
// Second bevel
|
// second bevel
|
||||||
if (enabled)
|
if (enabled)
|
||||||
target->SetHighColor(darken4);
|
target->SetHighColor(darken4);
|
||||||
else
|
else
|
||||||
target->SetHighColor(darken2);
|
target->SetHighColor(darken2);
|
||||||
|
|
||||||
target->StrokeLine(bevelRect.LeftBottom(), bevelRect.LeftTop());
|
target->StrokeLine(bevelRect.LeftBottom(), bevelRect.LeftTop());
|
||||||
target->StrokeLine(bevelRect.LeftTop(), bevelRect.RightTop());
|
target->StrokeLine(bevelRect.LeftTop(), bevelRect.RightTop());
|
||||||
target->SetHighColor(noTint);
|
target->SetHighColor(noTint);
|
||||||
@ -462,26 +471,31 @@ BColorControl::_DrawColorArea(BView* target, BRect update)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fPaletteMode) {
|
if (fPaletteMode) {
|
||||||
int colBegin = max_c(0, -1 + int(update.left) / int(fCellSize));
|
int colBegin = max_c(0, -1 + int(updateRect.left) / int(fCellSize));
|
||||||
int colEnd = min_c(fColumns, 2 + int(update.right) / int(fCellSize));
|
int colEnd = min_c(fColumns,
|
||||||
int rowBegin = max_c(0, -1 + int(update.top) / int(fCellSize));
|
2 + int(updateRect.right) / int(fCellSize));
|
||||||
int rowEnd = min_c(fRows, 2 + int(update.bottom) / int(fCellSize));
|
int rowBegin = max_c(0, -1 + int(updateRect.top) / int(fCellSize));
|
||||||
|
int rowEnd = min_c(fRows, 2 + int(updateRect.bottom)
|
||||||
|
/ int(fCellSize));
|
||||||
|
|
||||||
//grid
|
// grid
|
||||||
if (enabled)
|
if (enabled)
|
||||||
target->SetHighColor(darken1);
|
target->SetHighColor(darken1);
|
||||||
else
|
else
|
||||||
target->SetHighColor(noTint);
|
target->SetHighColor(noTint);
|
||||||
|
|
||||||
for (int xi = 0; xi < fColumns+1; xi++) {
|
for (int xi = 0; xi < fColumns+1; xi++) {
|
||||||
float x = fPaletteFrame.left + float(xi) * fCellSize;
|
float x = fPaletteFrame.left + float(xi) * fCellSize;
|
||||||
target->StrokeLine(BPoint(x, fPaletteFrame.top), BPoint(x, fPaletteFrame.bottom));
|
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;
|
float y = fPaletteFrame.top + float(yi) * fCellSize;
|
||||||
target->StrokeLine(BPoint(fPaletteFrame.left, y), BPoint(fPaletteFrame.right, y));
|
target->StrokeLine(BPoint(fPaletteFrame.left, y),
|
||||||
|
BPoint(fPaletteFrame.right, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
//colors
|
// colors
|
||||||
for (int col = colBegin; col < colEnd; col++) {
|
for (int col = colBegin; col < colEnd; col++) {
|
||||||
for (int row = rowBegin; row < rowEnd; row++) {
|
for (int row = rowBegin; row < rowEnd; row++) {
|
||||||
uint8 colorIndex = row * fColumns + col;
|
uint8 colorIndex = row * fColumns + col;
|
||||||
@ -489,25 +503,30 @@ BColorControl::_DrawColorArea(BView* target, BRect update)
|
|||||||
float y = fPaletteFrame.top + row * 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));
|
target->FillRect(BRect(x + 1, y + 1,
|
||||||
|
x + fCellSize - 1, y + fCellSize - 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rgb_color white = {255, 255, 255, 255};
|
rgb_color white = { 255, 255, 255, 255 };
|
||||||
rgb_color red = {255, 0, 0, 255};
|
rgb_color red = { 255, 0, 0, 255 };
|
||||||
rgb_color green = {0, 255, 0, 255};
|
rgb_color green = { 0, 255, 0, 255 };
|
||||||
rgb_color blue = {0, 0, 255, 255};
|
rgb_color blue = { 0, 0, 255, 255 };
|
||||||
|
|
||||||
rgb_color compColor = {0, 0, 0, 255};
|
rgb_color compColor = { 0, 0, 0, 255 };
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
compColor.red = compColor.green = compColor.blue = 156;
|
compColor.red = compColor.green = compColor.blue = 156;
|
||||||
red.red = green.green = blue.blue = 70;
|
red.red = green.green = blue.blue = 70;
|
||||||
white.red = white.green = white.blue = 70;
|
white.red = white.green = white.blue = 70;
|
||||||
}
|
}
|
||||||
_ColorRamp(_RampFrame(0), target, white, compColor, 0, false, update);
|
_DrawColorRamp(_RampFrame(0), target, white, compColor, 0, false,
|
||||||
_ColorRamp(_RampFrame(1), target, red, compColor, 0, false, update);
|
updateRect);
|
||||||
_ColorRamp(_RampFrame(2), target, green, compColor, 0, false, update);
|
_DrawColorRamp(_RampFrame(1), target, red, compColor, 0, false,
|
||||||
_ColorRamp(_RampFrame(3), target, blue, compColor, 0, false, update);
|
updateRect);
|
||||||
|
_DrawColorRamp(_RampFrame(2), target, green, compColor, 0, false,
|
||||||
|
updateRect);
|
||||||
|
_DrawColorRamp(_RampFrame(3), target, blue, compColor, 0, false,
|
||||||
|
updateRect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -520,7 +539,7 @@ BColorControl::_DrawSelectors(BView* target)
|
|||||||
|
|
||||||
if (fPaletteMode) {
|
if (fPaletteMode) {
|
||||||
if (fSelectedPaletteColorIndex != -1) {
|
if (fSelectedPaletteColorIndex != -1) {
|
||||||
target->SetHighColor(lightenmax);
|
target->SetHighColor(lightenmax);
|
||||||
target->StrokeRect(_PaletteSelectorFrame(fSelectedPaletteColorIndex));
|
target->StrokeRect(_PaletteSelectorFrame(fSelectedPaletteColorIndex));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -541,21 +560,24 @@ BColorControl::_DrawSelectors(BView* target)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BColorControl::_ColorRamp(BRect rect, BView* target,
|
BColorControl::_DrawColorRamp(BRect rect, BView* target,
|
||||||
rgb_color baseColor, rgb_color compColor, int16 flag, bool focused, BRect update)
|
rgb_color baseColor, rgb_color compColor, int16 flag, bool focused,
|
||||||
|
BRect updateRect)
|
||||||
{
|
{
|
||||||
float width = rect.Width() + 1;
|
float width = rect.Width() + 1;
|
||||||
rgb_color color;
|
rgb_color color;
|
||||||
color.alpha = 255;
|
color.alpha = 255;
|
||||||
|
|
||||||
update = update & rect;
|
updateRect = updateRect & rect;
|
||||||
|
|
||||||
if (update.IsValid() && update.Width() >= 0){
|
if (updateRect.IsValid() && updateRect.Width() >= 0) {
|
||||||
target->BeginLineArray((int32)update.Width() + 1);
|
target->BeginLineArray((int32)updateRect.Width() + 1);
|
||||||
|
|
||||||
for (float i = (update.left - rect.left); i <= (update.right - rect.left) + 1; i++) {
|
for (float i = (updateRect.left - rect.left);
|
||||||
|
i <= (updateRect.right - rect.left) + 1; i++) {
|
||||||
color.red = (uint8)(i * baseColor.red / width) + compColor.red;
|
color.red = (uint8)(i * baseColor.red / width) + compColor.red;
|
||||||
color.green = (uint8)(i * baseColor.green / width) + compColor.green;
|
color.green = (uint8)(i * baseColor.green / width)
|
||||||
|
+ compColor.green;
|
||||||
color.blue = (uint8)(i * baseColor.blue / width) + compColor.blue;
|
color.blue = (uint8)(i * baseColor.blue / width) + compColor.blue;
|
||||||
target->AddLine(BPoint(rect.left + i, rect.top),
|
target->AddLine(BPoint(rect.left + i, rect.top),
|
||||||
BPoint(rect.left + i, rect.bottom - 1), color);
|
BPoint(rect.left + i, rect.bottom - 1), color);
|
||||||
@ -582,7 +604,7 @@ BColorControl::_RampFrame(uint8 rampIndex) const
|
|||||||
{
|
{
|
||||||
float rampHeight = float(fRows) * fCellSize / 4.0f;
|
float rampHeight = float(fRows) * fCellSize / 4.0f;
|
||||||
|
|
||||||
return BRect( fPaletteFrame.left,
|
return BRect(fPaletteFrame.left,
|
||||||
fPaletteFrame.top + float(rampIndex) * rampHeight,
|
fPaletteFrame.top + float(rampIndex) * rampHeight,
|
||||||
fPaletteFrame.right,
|
fPaletteFrame.right,
|
||||||
fPaletteFrame.top + float(rampIndex + 1) * rampHeight);
|
fPaletteFrame.top + float(rampIndex + 1) * rampHeight);
|
||||||
@ -604,7 +626,8 @@ void
|
|||||||
BColorControl::_InitOffscreen()
|
BColorControl::_InitOffscreen()
|
||||||
{
|
{
|
||||||
if (fBitmap->Lock()) {
|
if (fBitmap->Lock()) {
|
||||||
_DrawColorArea(fOffscreenView, fPaletteFrame.InsetByCopy(-2.0f,-2.0f));
|
_DrawColorArea(fOffscreenView,
|
||||||
|
fPaletteFrame.InsetByCopy(-2.0f, -2.0f));
|
||||||
fOffscreenView->Sync();
|
fOffscreenView->Sync();
|
||||||
fBitmap->Unlock();
|
fBitmap->Unlock();
|
||||||
}
|
}
|
||||||
@ -712,9 +735,9 @@ BColorControl::MouseDown(BPoint point)
|
|||||||
MakeFocus();
|
MakeFocus();
|
||||||
|
|
||||||
if (fPaletteMode) {
|
if (fPaletteMode) {
|
||||||
int column = (int) ( (point.x - fPaletteFrame.left) / fCellSize );
|
int col = (int)((point.x - fPaletteFrame.left) / fCellSize);
|
||||||
int row = (int) ( (point.y - fPaletteFrame.top) / fCellSize );
|
int row = (int)((point.y - fPaletteFrame.top) / fCellSize);
|
||||||
int colorIndex = row * fColumns + column;
|
int colorIndex = row * fColumns + col;
|
||||||
if (colorIndex >= 0 && colorIndex < 256) {
|
if (colorIndex >= 0 && colorIndex < 256) {
|
||||||
fSelectedPaletteColorIndex = colorIndex;
|
fSelectedPaletteColorIndex = colorIndex;
|
||||||
SetValue(system_colors()->color_list[colorIndex]);
|
SetValue(system_colors()->color_list[colorIndex]);
|
||||||
@ -723,8 +746,8 @@ BColorControl::MouseDown(BPoint point)
|
|||||||
rgb_color color = ValueAsColor();
|
rgb_color color = ValueAsColor();
|
||||||
|
|
||||||
uint8 shade = (unsigned char)max_c(0,
|
uint8 shade = (unsigned char)max_c(0,
|
||||||
min_c((point.x - _RampFrame(0).left) * 255 / _RampFrame(0).Width(),
|
min_c((point.x - _RampFrame(0).left) * 255
|
||||||
255));
|
/ _RampFrame(0).Width(), 255));
|
||||||
|
|
||||||
if (_RampFrame(0).Contains(point)) {
|
if (_RampFrame(0).Contains(point)) {
|
||||||
color.red = color.green = color.blue = shade;
|
color.red = color.green = color.blue = shade;
|
||||||
@ -741,27 +764,27 @@ BColorControl::MouseDown(BPoint point)
|
|||||||
}
|
}
|
||||||
|
|
||||||
SetValue(color);
|
SetValue(color);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Invoke();
|
Invoke();
|
||||||
|
|
||||||
SetTracking(true);
|
SetTracking(true);
|
||||||
SetMouseEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY|B_LOCK_WINDOW_FOCUS);
|
SetMouseEventMask(B_POINTER_EVENTS,
|
||||||
|
B_NO_POINTER_HISTORY | B_LOCK_WINDOW_FOCUS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BColorControl::MouseMoved(BPoint point, uint32 transit,
|
BColorControl::MouseMoved(BPoint point, uint32 transit,
|
||||||
const BMessage *message)
|
const BMessage* message)
|
||||||
{
|
{
|
||||||
if (!IsTracking())
|
if (!IsTracking())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (fPaletteMode && fPaletteFrame.Contains(point)) {
|
if (fPaletteMode && fPaletteFrame.Contains(point)) {
|
||||||
int column = (int) ( (point.x - fPaletteFrame.left) / fCellSize );
|
int col = (int)((point.x - fPaletteFrame.left) / fCellSize);
|
||||||
int row = (int) ( (point.y - fPaletteFrame.top) / fCellSize );
|
int row = (int)((point.y - fPaletteFrame.top) / fCellSize);
|
||||||
int colorIndex = row * fColumns + column;
|
int colorIndex = row * fColumns + col;
|
||||||
if (colorIndex >= 0 && colorIndex < 256) {
|
if (colorIndex >= 0 && colorIndex < 256) {
|
||||||
fSelectedPaletteColorIndex = colorIndex;
|
fSelectedPaletteColorIndex = colorIndex;
|
||||||
SetValue(system_colors()->color_list[colorIndex]);
|
SetValue(system_colors()->color_list[colorIndex]);
|
||||||
@ -773,7 +796,8 @@ BColorControl::MouseMoved(BPoint point, uint32 transit,
|
|||||||
rgb_color color = ValueAsColor();
|
rgb_color color = ValueAsColor();
|
||||||
|
|
||||||
uint8 shade = (unsigned char)max_c(0,
|
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));
|
||||||
|
|
||||||
switch (fFocusedComponent) {
|
switch (fFocusedComponent) {
|
||||||
case 1:
|
case 1:
|
||||||
@ -807,17 +831,20 @@ BColorControl::DetachedFromWindow()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BColorControl::GetPreferredSize(float *_width, float *_height)
|
BColorControl::GetPreferredSize(float* _width, float* _height)
|
||||||
{
|
{
|
||||||
BRect rect = fPaletteFrame.InsetByCopy(-2.0,-2.0); //bevel
|
BRect rect = fPaletteFrame.InsetByCopy(-2.0, -2.0);
|
||||||
|
// bevel
|
||||||
|
|
||||||
if (rect.Height() < fBlueText->Frame().bottom) {
|
if (rect.Height() < fBlueText->Frame().bottom) {
|
||||||
// adjust the height to fit
|
// adjust the height to fit
|
||||||
rect.bottom = fBlueText->Frame().bottom;
|
rect.bottom = fBlueText->Frame().bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_width)
|
if (_width) {
|
||||||
*_width = rect.Width() + kTextFieldsHSpacing + fRedText->Bounds().Width();
|
*_width = rect.Width() + kTextFieldsHSpacing
|
||||||
|
+ fRedText->Bounds().Width();
|
||||||
|
}
|
||||||
|
|
||||||
if (_height)
|
if (_height)
|
||||||
*_height = rect.Height();
|
*_height = rect.Height();
|
||||||
@ -834,9 +861,9 @@ BColorControl::ResizeToPreferred()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BColorControl::Invoke(BMessage *msg)
|
BColorControl::Invoke(BMessage* message)
|
||||||
{
|
{
|
||||||
return BControl::Invoke(msg);
|
return BControl::Invoke(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -854,16 +881,17 @@ BColorControl::FrameResized(float new_width, float new_height)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BHandler *
|
BHandler*
|
||||||
BColorControl::ResolveSpecifier(BMessage *msg, int32 index,
|
BColorControl::ResolveSpecifier(BMessage* message, int32 index,
|
||||||
BMessage *specifier, int32 form, const char *property)
|
BMessage* specifier, int32 form, const char* property)
|
||||||
{
|
{
|
||||||
return BControl::ResolveSpecifier(msg, index, specifier, form, property);
|
return BControl::ResolveSpecifier(message, index, specifier, form,
|
||||||
|
property);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BColorControl::GetSupportedSuites(BMessage *data)
|
BColorControl::GetSupportedSuites(BMessage* data)
|
||||||
{
|
{
|
||||||
return BControl::GetSupportedSuites(data);
|
return BControl::GetSupportedSuites(data);
|
||||||
}
|
}
|
||||||
@ -918,10 +946,10 @@ BColorControl::Perform(perform_code code, void* _data)
|
|||||||
{
|
{
|
||||||
perform_data_get_height_for_width* data
|
perform_data_get_height_for_width* data
|
||||||
= (perform_data_get_height_for_width*)_data;
|
= (perform_data_get_height_for_width*)_data;
|
||||||
BColorControl::GetHeightForWidth(data->width, &data->min, &data->max,
|
BColorControl::GetHeightForWidth(data->width, &data->min,
|
||||||
&data->preferred);
|
&data->max, &data->preferred);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
case PERFORM_CODE_SET_LAYOUT:
|
case PERFORM_CODE_SET_LAYOUT:
|
||||||
{
|
{
|
||||||
perform_data_set_layout* data = (perform_data_set_layout*)_data;
|
perform_data_set_layout* data = (perform_data_set_layout*)_data;
|
||||||
|
Loading…
Reference in New Issue
Block a user