hrev45753 adds 8 changesets to branch 'master' old head: 2a95812e466a5357cc05bf29f1bed5c75d5222ca new head: 1f0b41ba7fdcc573354eea3e1354520d9a036023 overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=1f0b41b+%5E2a95812 ---------------------------------------------------------------------------- 0289f92: BColorControl: Style fixes * Update copyright in header, add my name, alphabetize. * Rename _ColorRamp() to _DrawColorRamp(). * Rename update parameter to updateRect 1186916: BColorControl: Create _SetCellSize() method ...eliminating duplicated code. 62fec20: BColorControl: Size text rect based on font size * Also change kMinCellSize from a uint32 to a float so that it can be used with std::min() and std::max() instead of min_c() and max_c(). * Set the text controls sizes and margins based on the font size. Also rework _TextRectOffset() so that it will get the right spacing from by dividing the palette frame by 3. * Replace bare numbers and refactor with calculation or magic constant. * Create a private method _TextRectOffset() which calculates and returns the vertical text rect offset to use based on the font size. * Replace 2.0 with new kBevelSpacing constant where appropriate. * fPaletteFrame calculation in _LayoutView() was refactored but should not have changed. abbd44a: BColorControl: Rename bevelRect to just rect ... with an explanatory comment. Correct similar comment. Tiny style fix. 8b3b14f: BColorControl: Introduce a _PaletteFrame() method ... eliminating duplicate code. da6c116: BColorControl: Introduce kRampCount magic constant. d5432ed: BColorControl: Refactor _LayoutView() In a few cases we were doing the work of _LayoutView() twice because we called _LayoutView() and then called ResizeToPreferred() which called _LayoutView() again. Now only call ResizeToPreferred() which calls _LayoutView(). 1f0b41b: BColorControl: Position text controls better Position the text control vertically in the middle of the ramp in the case that the text controls are pushed down so that the red, green, and blue text controls are next to the red, green, and blue ramps. [ John Scipione <jscipione@xxxxxxxxx> ] ---------------------------------------------------------------------------- 2 files changed, 194 insertions(+), 148 deletions(-) headers/os/interface/ColorControl.h | 22 ++- src/kits/interface/ColorControl.cpp | 320 ++++++++++++++++++-------------- ############################################################################ Commit: 0289f920635a70531741f8200c0ef60761f84ebf URL: http://cgit.haiku-os.org/haiku/commit/?id=0289f92 Author: John Scipione <jscipione@xxxxxxxxx> Date: Fri May 31 04:19:10 2013 UTC BColorControl: Style fixes * Update copyright in header, add my name, alphabetize. * Rename _ColorRamp() to _DrawColorRamp(). * Rename update parameter to updateRect ---------------------------------------------------------------------------- diff --git a/headers/os/interface/ColorControl.h b/headers/os/interface/ColorControl.h index 7c1437f..647a30a 100644 --- a/headers/os/interface/ColorControl.h +++ b/headers/os/interface/ColorControl.h @@ -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. */ #ifndef _COLOR_CONTROL_H @@ -8,8 +8,6 @@ #include <Control.h> -class BBitmap; - enum color_control_layout { B_CELLS_4x64 = 4, @@ -19,6 +17,8 @@ enum color_control_layout { B_CELLS_64x4 = 64, }; + +class BBitmap; class BTextControl; @@ -93,13 +93,14 @@ private: void _LayoutView(); void _InitOffscreen(); void _DrawColorArea(BView* target, BRect update); - void _DrawSelectors(BView* target); - void _ColorRamp(BRect rect, BView* target, - rgb_color baseColor, rgb_color compColor, - int16 flag, bool focused, BRect update); + void _DrawSelectors(BView* target); + void _DrawColorRamp(BRect rect, BView* target, + rgb_color baseColor, rgb_color compColor, + int16 flag, bool focused, + BRect updateRect); BPoint _SelectorPosition(const BRect& rampRect, uint8 shade) const; - BRect _PaletteSelectorFrame(uint8 colorIndex) const; + BRect _PaletteSelectorFrame(uint8 colorIndex) const; BRect _RampFrame(uint8 rampIndex) const; private: diff --git a/src/kits/interface/ColorControl.cpp b/src/kits/interface/ColorControl.cpp index 4187652..c9edb40 100644 --- a/src/kits/interface/ColorControl.cpp +++ b/src/kits/interface/ColorControl.cpp @@ -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. * * Authors: - * Marc Flerackers (mflerackers@xxxxxxxxxx) - * Axel Dörfler, axeld@xxxxxxxxxxxxxxxx * Alexandre Deckner, alex@xxxxxxxxxxxx + * Axel Dörfler, axeld@xxxxxxxxxxxxxxxx * Jérôme Duval + * Marc Flerackers, mflerackers@xxxxxxxxxx + * John Scipione, jscipione@xxxxxxxxx */ /** 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 kTextFieldsHSpacing = 6.0f; + BColorControl::BColorControl(BPoint leftTop, color_control_layout layout, - float cellSize, const char *name, BMessage *message, - bool bufferedDrawing) - : BControl(BRect(leftTop, leftTop), name, NULL, message, - B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE) + float cellSize, const char* name, BMessage* message, bool bufferedDrawing) + : + BControl(BRect(leftTop, leftTop), name, NULL, message, + B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE) { _InitData(layout, cellSize, bufferedDrawing, NULL); } BColorControl::BColorControl(BMessage* archive) - : BControl(archive) + : + BControl(archive) { int32 layout; float cellSize; @@ -94,7 +97,7 @@ BColorControl::_InitData(color_control_layout layout, float size, green = gSystemCatalog.GetString(green, "ColorControl"); blue = gSystemCatalog.GetString(blue, "ColorControl"); - if (archive) { + if (archive != NULL) { fRedText = (BTextControl*)FindView("_red"); fGreenText = (BTextControl*)FindView("_green"); fBlueText = (BTextControl*)FindView("_blue"); @@ -116,17 +119,17 @@ BColorControl::_InitData(color_control_layout layout, float size, B_WILL_DRAW | B_NAVIGABLE); fRedText->SetDivider(labelWidth); - float offset = fRedText->Bounds().Height() + 2; - for (int32 i = 0; i < 256; i++) fRedText->TextView()->DisallowChar(i); for (int32 i = '0'; i <= '9'; i++) fRedText->TextView()->AllowChar(i); fRedText->TextView()->SetMaxBytes(3); + float offset = fRedText->Bounds().Height() + 2.0f; + // green - rect.OffsetBy(0.0f, offset); + rect.OffsetBy(0, offset); fGreenText = new BTextControl(rect, "_green", green, "0", new BMessage(kMsgColorEntered), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE); @@ -140,7 +143,7 @@ BColorControl::_InitData(color_control_layout layout, float size, // blue - rect.OffsetBy(0.0f, offset); + rect.OffsetBy(0, offset); fBlueText = new BTextControl(rect, "_blue", blue, "0", new BMessage(kMsgColorEntered), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE); @@ -179,7 +182,7 @@ BColorControl::_InitData(color_control_layout layout, float size, void BColorControl::_LayoutView() { - if (fPaletteMode){ + if (fPaletteMode) { fPaletteFrame.Set(2.0f, 2.0f, float(fColumns) * fCellSize + 2.0, float(fRows) * fCellSize + 2.0); @@ -187,11 +190,12 @@ BColorControl::_LayoutView() fPaletteFrame.Set(2.0f, 2.0f, float(fColumns) * fCellSize + 2.0, float(fRows) * fCellSize + 2.0 - 1.0); - //1 pixel adjust so that the inner space - //has exactly rows*cellsize pixels in height + // 1 pixel adjust so that the inner space + // 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) { // adjust the height to fit @@ -213,13 +217,13 @@ BColorControl::_LayoutView() y += offset; 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 * -BColorControl::Instantiate(BMessage *archive) +BArchivable* +BColorControl::Instantiate(BMessage* archive) { if (validate_instantiation(archive, "BColorControl")) return new BColorControl(archive); @@ -229,7 +233,7 @@ BColorControl::Instantiate(BMessage *archive) status_t -BColorControl::Archive(BMessage *archive, bool deep) const +BColorControl::Archive(BMessage* archive, bool deep) const { status_t status = BControl::Archive(archive, deep); @@ -376,7 +380,7 @@ BColorControl::AttachedToWindow() void -BColorControl::MessageReceived(BMessage *message) +BColorControl::MessageReceived(BMessage* message) { switch (message->what) { case kMsgColorEntered: @@ -400,18 +404,19 @@ BColorControl::MessageReceived(BMessage *message) void BColorControl::Draw(BRect updateRect) { - if (fBitmap) + if (fBitmap != NULL) DrawBitmap(fBitmap, B_ORIGIN); else _DrawColorArea(this, updateRect); + _DrawSelectors(this); } 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(); rgb_color noTint = ui_color(B_PANEL_BACKGROUND_COLOR); @@ -421,7 +426,8 @@ BColorControl::_DrawColorArea(BView* target, BRect update) uint32 flags = 0; if (!enabled) flags |= BControlLook::B_DISABLED; - be_control_look->DrawTextControlBorder(target, bevelRect, update, + + be_control_look->DrawTextControlBorder(target, bevelRect, updateRect, noTint, flags); } else { 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 darken4 = tint_color(noTint, B_DARKEN_4_TINT); - // First bevel + // first bevel if (enabled) target->SetHighColor(darken1); else target->SetHighColor(noTint); + target->StrokeLine(bevelRect.LeftBottom(), bevelRect.LeftTop()); target->StrokeLine(bevelRect.LeftTop(), bevelRect.RightTop()); if (enabled) target->SetHighColor(lightenmax); else target->SetHighColor(lighten1); + target->StrokeLine(BPoint(bevelRect.left + 1.0f, bevelRect.bottom), bevelRect.RightBottom()); target->StrokeLine(bevelRect.RightBottom(), @@ -447,11 +455,12 @@ BColorControl::_DrawColorArea(BView* target, BRect update) bevelRect.InsetBy(1.0f, 1.0f); - // Second bevel + // second bevel if (enabled) target->SetHighColor(darken4); else target->SetHighColor(darken2); + target->StrokeLine(bevelRect.LeftBottom(), bevelRect.LeftTop()); target->StrokeLine(bevelRect.LeftTop(), bevelRect.RightTop()); target->SetHighColor(noTint); @@ -462,26 +471,31 @@ BColorControl::_DrawColorArea(BView* target, BRect update) } 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)); - - //grid + int colBegin = max_c(0, -1 + int(updateRect.left) / int(fCellSize)); + int colEnd = min_c(fColumns, + 2 + int(updateRect.right) / 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 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)); + target->StrokeLine(BPoint(x, fPaletteFrame.top), + BPoint(x, fPaletteFrame.bottom)); } 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)); + target->StrokeLine(BPoint(fPaletteFrame.left, y), + BPoint(fPaletteFrame.right, y)); } - //colors + // colors for (int col = colBegin; col < colEnd; col++) { for (int row = rowBegin; row < rowEnd; row++) { uint8 colorIndex = row * fColumns + col; @@ -489,25 +503,30 @@ BColorControl::_DrawColorArea(BView* target, BRect update) float y = fPaletteFrame.top + row * fCellSize; 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 { - 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}; + 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 }; - rgb_color compColor = {0, 0, 0, 255}; + 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); + _DrawColorRamp(_RampFrame(0), target, white, compColor, 0, false, + updateRect); + _DrawColorRamp(_RampFrame(1), target, red, compColor, 0, false, + 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 (fSelectedPaletteColorIndex != -1) { - target->SetHighColor(lightenmax); + target->SetHighColor(lightenmax); target->StrokeRect(_PaletteSelectorFrame(fSelectedPaletteColorIndex)); } } else { @@ -541,21 +560,24 @@ BColorControl::_DrawSelectors(BView* target) void -BColorControl::_ColorRamp(BRect rect, BView* target, - rgb_color baseColor, rgb_color compColor, int16 flag, bool focused, BRect update) +BColorControl::_DrawColorRamp(BRect rect, BView* target, + rgb_color baseColor, rgb_color compColor, int16 flag, bool focused, + BRect updateRect) { float width = rect.Width() + 1; rgb_color color; color.alpha = 255; - update = update & rect; + updateRect = updateRect & rect; - if (update.IsValid() && update.Width() >= 0){ - target->BeginLineArray((int32)update.Width() + 1); + if (updateRect.IsValid() && updateRect.Width() >= 0) { + 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.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; target->AddLine(BPoint(rect.left + i, rect.top), BPoint(rect.left + i, rect.bottom - 1), color); @@ -582,7 +604,7 @@ BColorControl::_RampFrame(uint8 rampIndex) const { float rampHeight = float(fRows) * fCellSize / 4.0f; - return BRect( fPaletteFrame.left, + return BRect(fPaletteFrame.left, fPaletteFrame.top + float(rampIndex) * rampHeight, fPaletteFrame.right, fPaletteFrame.top + float(rampIndex + 1) * rampHeight); @@ -604,7 +626,8 @@ void BColorControl::_InitOffscreen() { if (fBitmap->Lock()) { - _DrawColorArea(fOffscreenView, fPaletteFrame.InsetByCopy(-2.0f,-2.0f)); + _DrawColorArea(fOffscreenView, + fPaletteFrame.InsetByCopy(-2.0f, -2.0f)); fOffscreenView->Sync(); fBitmap->Unlock(); } @@ -712,9 +735,9 @@ BColorControl::MouseDown(BPoint point) MakeFocus(); if (fPaletteMode) { - int column = (int) ( (point.x - fPaletteFrame.left) / fCellSize ); - int row = (int) ( (point.y - fPaletteFrame.top) / fCellSize ); - int colorIndex = row * fColumns + column; + int col = (int)((point.x - fPaletteFrame.left) / fCellSize); + int row = (int)((point.y - fPaletteFrame.top) / fCellSize); + int colorIndex = row * fColumns + col; if (colorIndex >= 0 && colorIndex < 256) { fSelectedPaletteColorIndex = colorIndex; SetValue(system_colors()->color_list[colorIndex]); @@ -723,8 +746,8 @@ BColorControl::MouseDown(BPoint point) 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; @@ -741,27 +764,27 @@ BColorControl::MouseDown(BPoint point) } SetValue(color); - } Invoke(); 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 BColorControl::MouseMoved(BPoint point, uint32 transit, - const BMessage *message) + const BMessage* message) { if (!IsTracking()) return; if (fPaletteMode && fPaletteFrame.Contains(point)) { - int column = (int) ( (point.x - fPaletteFrame.left) / fCellSize ); - int row = (int) ( (point.y - fPaletteFrame.top) / fCellSize ); - int colorIndex = row * fColumns + column; + int col = (int)((point.x - fPaletteFrame.left) / fCellSize); + int row = (int)((point.y - fPaletteFrame.top) / fCellSize); + int colorIndex = row * fColumns + col; if (colorIndex >= 0 && colorIndex < 256) { fSelectedPaletteColorIndex = colorIndex; SetValue(system_colors()->color_list[colorIndex]); @@ -773,7 +796,8 @@ BColorControl::MouseMoved(BPoint point, uint32 transit, 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)); switch (fFocusedComponent) { case 1: @@ -807,17 +831,20 @@ BColorControl::DetachedFromWindow() 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) { // adjust the height to fit rect.bottom = fBlueText->Frame().bottom; } - if (_width) - *_width = rect.Width() + kTextFieldsHSpacing + fRedText->Bounds().Width(); + if (_width) { + *_width = rect.Width() + kTextFieldsHSpacing + + fRedText->Bounds().Width(); + } if (_height) *_height = rect.Height(); @@ -834,9 +861,9 @@ BColorControl::ResizeToPreferred() 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 * -BColorControl::ResolveSpecifier(BMessage *msg, int32 index, - BMessage *specifier, int32 form, const char *property) +BHandler* +BColorControl::ResolveSpecifier(BMessage* message, int32 index, + 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 -BColorControl::GetSupportedSuites(BMessage *data) +BColorControl::GetSupportedSuites(BMessage* 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; - BColorControl::GetHeightForWidth(data->width, &data->min, &data->max, - &data->preferred); + BColorControl::GetHeightForWidth(data->width, &data->min, + &data->max, &data->preferred); return B_OK; -} + } case PERFORM_CODE_SET_LAYOUT: { perform_data_set_layout* data = (perform_data_set_layout*)_data; ############################################################################ Commit: 1186916f06ee1662d1708603ef40704b8d2abedb URL: http://cgit.haiku-os.org/haiku/commit/?id=1186916 Author: John Scipione <jscipione@xxxxxxxxx> Date: Fri May 31 04:43:15 2013 UTC BColorControl: Create _SetCellSize() method ...eliminating duplicated code. ---------------------------------------------------------------------------- diff --git a/headers/os/interface/ColorControl.h b/headers/os/interface/ColorControl.h index 647a30a..8390098 100644 --- a/headers/os/interface/ColorControl.h +++ b/headers/os/interface/ColorControl.h @@ -102,7 +102,8 @@ private: uint8 shade) const; BRect _PaletteSelectorFrame(uint8 colorIndex) const; BRect _RampFrame(uint8 rampIndex) const; - + void _SetCellSize(float size); + private: BRect fPaletteFrame; int16 fSelectedPaletteColorIndex; diff --git a/src/kits/interface/ColorControl.cpp b/src/kits/interface/ColorControl.cpp index c9edb40..ad450cc 100644 --- a/src/kits/interface/ColorControl.cpp +++ b/src/kits/interface/ColorControl.cpp @@ -84,7 +84,8 @@ BColorControl::_InitData(color_control_layout layout, float size, // so we take the main_screen colorspace at startup fColumns = layout; fRows = 256 / fColumns; - fCellSize = ceil(max_c(kMinCellSize, size)); + + _SetCellSize(size); fSelectedPaletteColorIndex = -1; fPreviousSelectedPaletteColorIndex = -1; @@ -611,6 +612,13 @@ BColorControl::_RampFrame(uint8 rampIndex) const } +void +BColorControl::_SetCellSize(float size) +{ + fCellSize = ceilf(max_c(kMinCellSize, size)); +} + + BRect BColorControl::_PaletteSelectorFrame(uint8 colorIndex) const { @@ -635,9 +643,9 @@ BColorControl::_InitOffscreen() void -BColorControl::SetCellSize(float cellSide) +BColorControl::SetCellSize(float size) { - fCellSize = ceil(max_c(kMinCellSize, cellSide)); + _SetCellSize(size); _LayoutView(); ResizeToPreferred(); } ############################################################################ Commit: 62fec205dd2373d78f22df0848c073cc5ef5f7d7 URL: http://cgit.haiku-os.org/haiku/commit/?id=62fec20 Author: John Scipione <jscipione@xxxxxxxxx> Date: Mon Jun 3 00:51:26 2013 UTC BColorControl: Size text rect based on font size * Also change kMinCellSize from a uint32 to a float so that it can be used with std::min() and std::max() instead of min_c() and max_c(). * Set the text controls sizes and margins based on the font size. Also rework _TextRectOffset() so that it will get the right spacing from by dividing the palette frame by 3. * Replace bare numbers and refactor with calculation or magic constant. * Create a private method _TextRectOffset() which calculates and returns the vertical text rect offset to use based on the font size. * Replace 2.0 with new kBevelSpacing constant where appropriate. * fPaletteFrame calculation in _LayoutView() was refactored but should not have changed. ---------------------------------------------------------------------------- diff --git a/headers/os/interface/ColorControl.h b/headers/os/interface/ColorControl.h index 8390098..a0d7cd0 100644 --- a/headers/os/interface/ColorControl.h +++ b/headers/os/interface/ColorControl.h @@ -103,6 +103,7 @@ private: BRect _PaletteSelectorFrame(uint8 colorIndex) const; BRect _RampFrame(uint8 rampIndex) const; void _SetCellSize(float size); + float _TextRectOffset(); private: BRect fPaletteFrame; diff --git a/src/kits/interface/ColorControl.cpp b/src/kits/interface/ColorControl.cpp index ad450cc..378c78d 100644 --- a/src/kits/interface/ColorControl.cpp +++ b/src/kits/interface/ColorControl.cpp @@ -36,11 +36,13 @@ using BPrivate::gSystemCatalog; #define B_TRANSLATION_CONTEXT "ColorControl" static const uint32 kMsgColorEntered = 'ccol'; -static const uint32 kMinCellSize = 6; +static const float kMinCellSize = 6.0f; static const float kSelectorPenSize = 2.0f; static const float kSelectorSize = 4.0f; static const float kSelectorHSpacing = 2.0f; static const float kTextFieldsHSpacing = 6.0f; +static const float kDefaultFontSize = 12.0f; +static const float kBevelSpacing = 2.0f; BColorControl::BColorControl(BPoint leftTop, color_control_layout layout, @@ -108,14 +110,20 @@ BColorControl::_InitData(color_control_layout layout, float size, SetValue(value); } else { - BRect rect(0.0f, 0.0f, 70.0f, 15.0f); + BRect textRect(0.0f, 0.0f, 0.0f, 0.0f); float labelWidth = std::max(StringWidth(red), - std::max(StringWidth(green), StringWidth(blue))) + 5; - rect.right = labelWidth + StringWidth("999") + 20; + std::max(StringWidth(green), StringWidth(blue))) + + kTextFieldsHSpacing; + textRect.right = labelWidth + StringWidth("999999"); + // enough room for 3 digits plus 3 digits of padding + font_height fontHeight; + GetFontHeight(&fontHeight); + float labelHeight = fontHeight.ascent + fontHeight.descent; + textRect.bottom = labelHeight; // red - fRedText = new BTextControl(rect, "_red", red, "0", + fRedText = new BTextControl(textRect, "_red", red, "0", new BMessage(kMsgColorEntered), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE); fRedText->SetDivider(labelWidth); @@ -126,12 +134,10 @@ BColorControl::_InitData(color_control_layout layout, float size, fRedText->TextView()->AllowChar(i); fRedText->TextView()->SetMaxBytes(3); - float offset = fRedText->Bounds().Height() + 2.0f; - // green - rect.OffsetBy(0, offset); - fGreenText = new BTextControl(rect, "_green", green, "0", + textRect.OffsetBy(0, _TextRectOffset()); + fGreenText = new BTextControl(textRect, "_green", green, "0", new BMessage(kMsgColorEntered), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE); fGreenText->SetDivider(labelWidth); @@ -144,8 +150,8 @@ BColorControl::_InitData(color_control_layout layout, float size, // blue - rect.OffsetBy(0, offset); - fBlueText = new BTextControl(rect, "_blue", blue, "0", + textRect.OffsetBy(0, _TextRectOffset()); + fBlueText = new BTextControl(textRect, "_blue", blue, "0", new BMessage(kMsgColorEntered), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE); fBlueText->SetDivider(labelWidth); @@ -165,7 +171,7 @@ BColorControl::_InitData(color_control_layout layout, float size, if (useOffscreen) { BRect bounds = fPaletteFrame; - bounds.InsetBy(-2.0f, -2.0f); + bounds.InsetBy(-kBevelSpacing, -kBevelSpacing); fBitmap = new BBitmap(bounds, B_RGB32, true, false); fOffscreenView = new BView(bounds, "off_view", 0, 0); @@ -183,30 +189,24 @@ BColorControl::_InitData(color_control_layout layout, float size, void BColorControl::_LayoutView() { - if (fPaletteMode) { - fPaletteFrame.Set(2.0f, 2.0f, - float(fColumns) * fCellSize + 2.0, - float(fRows) * fCellSize + 2.0); - } else { - fPaletteFrame.Set(2.0f, 2.0f, - float(fColumns) * fCellSize + 2.0, - float(fRows) * fCellSize + 2.0 - 1.0); - // 1 pixel adjust so that the inner space - // has exactly rows * cellsize pixels in height + fPaletteFrame.Set(0, 0, fColumns * fCellSize, fRows * fCellSize); + fPaletteFrame.OffsetBy(kBevelSpacing, kBevelSpacing); + if (!fPaletteMode) { + // Reduce the inner space by 1 pixel so that the frame + // is exactly rows * cellsize pixels in height + fPaletteFrame.bottom -= 1; } - BRect rect = fPaletteFrame.InsetByCopy(-2.0, -2.0); - // bevel + BRect rect = fPaletteFrame.InsetByCopy(-kBevelSpacing, -kBevelSpacing); + // frame not including bevel - if (rect.Height() < fBlueText->Frame().bottom) { - // adjust the height to fit + if (rect.Height() < fBlueText->Frame().bottom) rect.bottom = fBlueText->Frame().bottom; - } - float offset = floor(rect.bottom / 4); + float offset = floorf(rect.bottom / 4); float y = offset; - if (offset < fRedText->Bounds().Height() + 2) { - offset = fRedText->Bounds().Height() + 2; + if (offset < _TextRectOffset()) { + offset = _TextRectOffset(); y = 0; } @@ -417,7 +417,7 @@ BColorControl::Draw(BRect updateRect) void BColorControl::_DrawColorArea(BView* target, BRect updateRect) { - BRect bevelRect = fPaletteFrame.InsetByCopy(-2.0, -2.0); + BRect bevelRect = fPaletteFrame.InsetByCopy(-kBevelSpacing, -kBevelSpacing); bool enabled = IsEnabled(); rgb_color noTint = ui_color(B_PANEL_BACKGROUND_COLOR); @@ -615,7 +615,18 @@ BColorControl::_RampFrame(uint8 rampIndex) const void BColorControl::_SetCellSize(float size) { - fCellSize = ceilf(max_c(kMinCellSize, size)); + BFont font; + GetFont(&font); + fCellSize = std::max(kMinCellSize, + ceilf(size * font.Size() / kDefaultFontSize)); +} + + +float +BColorControl::_TextRectOffset() +{ + return std::max(fRedText->Bounds().Height(), + ceilf(_PaletteFrame().Height() / 3)); } @@ -635,7 +646,7 @@ BColorControl::_InitOffscreen() { if (fBitmap->Lock()) { _DrawColorArea(fOffscreenView, - fPaletteFrame.InsetByCopy(-2.0f, -2.0f)); + fPaletteFrame.InsetByCopy(-kBevelSpacing, -kBevelSpacing)); fOffscreenView->Sync(); fBitmap->Unlock(); } @@ -841,7 +852,7 @@ BColorControl::DetachedFromWindow() void BColorControl::GetPreferredSize(float* _width, float* _height) { - BRect rect = fPaletteFrame.InsetByCopy(-2.0, -2.0); + BRect rect = fPaletteFrame.InsetByCopy(-kBevelSpacing, -kBevelSpacing); // bevel if (rect.Height() < fBlueText->Frame().bottom) { ############################################################################ Commit: abbd44acfbc1b552f23f0742131eb3c93ba9b983 URL: http://cgit.haiku-os.org/haiku/commit/?id=abbd44a Author: John Scipione <jscipione@xxxxxxxxx> Date: Thu Jun 6 00:20:18 2013 UTC BColorControl: Rename bevelRect to just rect ... with an explanatory comment. Correct similar comment. Tiny style fix. ---------------------------------------------------------------------------- diff --git a/src/kits/interface/ColorControl.cpp b/src/kits/interface/ColorControl.cpp index 378c78d..f5bf69d 100644 --- a/src/kits/interface/ColorControl.cpp +++ b/src/kits/interface/ColorControl.cpp @@ -198,7 +198,7 @@ BColorControl::_LayoutView() } BRect rect = fPaletteFrame.InsetByCopy(-kBevelSpacing, -kBevelSpacing); - // frame not including bevel + // frame including bevel if (rect.Height() < fBlueText->Frame().bottom) rect.bottom = fBlueText->Frame().bottom; @@ -417,7 +417,8 @@ BColorControl::Draw(BRect updateRect) void BColorControl::_DrawColorArea(BView* target, BRect updateRect) { - BRect bevelRect = fPaletteFrame.InsetByCopy(-kBevelSpacing, -kBevelSpacing); + BRect rect = fPaletteFrame.InsetByCopy(-kBevelSpacing, -kBevelSpacing); + // frame including bevel bool enabled = IsEnabled(); rgb_color noTint = ui_color(B_PANEL_BACKGROUND_COLOR); @@ -428,8 +429,8 @@ BColorControl::_DrawColorArea(BView* target, BRect updateRect) if (!enabled) flags |= BControlLook::B_DISABLED; - be_control_look->DrawTextControlBorder(target, bevelRect, updateRect, - noTint, flags); + be_control_look->DrawTextControlBorder(target, rect, updateRect, noTint, + flags); } else { rgb_color lighten1 = tint_color(noTint, B_LIGHTEN_1_TINT); rgb_color lightenmax = tint_color(noTint, B_LIGHTEN_MAX_TINT); @@ -442,19 +443,19 @@ BColorControl::_DrawColorArea(BView* target, BRect updateRect) else target->SetHighColor(noTint); - target->StrokeLine(bevelRect.LeftBottom(), bevelRect.LeftTop()); - target->StrokeLine(bevelRect.LeftTop(), bevelRect.RightTop()); + target->StrokeLine(rect.LeftBottom(), rect.LeftTop()); + target->StrokeLine(rect.LeftTop(), rect.RightTop()); 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)); + target->StrokeLine(BPoint(rect.left + 1.0f, rect.bottom), + rect.RightBottom()); + target->StrokeLine(rect.RightBottom(), + BPoint(rect.right, rect.top + 1.0f)); - bevelRect.InsetBy(1.0f, 1.0f); + rect.InsetBy(1.0f, 1.0f); // second bevel if (enabled) @@ -462,13 +463,13 @@ BColorControl::_DrawColorArea(BView* target, BRect updateRect) else target->SetHighColor(darken2); - target->StrokeLine(bevelRect.LeftBottom(), bevelRect.LeftTop()); - target->StrokeLine(bevelRect.LeftTop(), bevelRect.RightTop()); + target->StrokeLine(rect.LeftBottom(), rect.LeftTop()); + target->StrokeLine(rect.LeftTop(), rect.RightTop()); target->SetHighColor(noTint); - target->StrokeLine(BPoint(bevelRect.left + 1.0f, bevelRect.bottom), - bevelRect.RightBottom()); - target->StrokeLine(bevelRect.RightBottom(), - BPoint(bevelRect.right, bevelRect.top + 1.0f)); + target->StrokeLine(BPoint(rect.left + 1.0f, rect.bottom), + rect.RightBottom()); + target->StrokeLine(rect.RightBottom(), + BPoint(rect.right, rect.top + 1.0f)); } if (fPaletteMode) { @@ -485,12 +486,12 @@ BColorControl::_DrawColorArea(BView* target, BRect updateRect) else 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; 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)); ############################################################################ Commit: 8b3b14fdfa14986ac57f083e427b8e0ae7d6fe4b URL: http://cgit.haiku-os.org/haiku/commit/?id=8b3b14f Author: John Scipione <jscipione@xxxxxxxxx> Date: Thu Jun 6 03:18:29 2013 UTC BColorControl: Introduce a _PaletteFrame() method ... eliminating duplicate code. ---------------------------------------------------------------------------- diff --git a/headers/os/interface/ColorControl.h b/headers/os/interface/ColorControl.h index a0d7cd0..6875ee2 100644 --- a/headers/os/interface/ColorControl.h +++ b/headers/os/interface/ColorControl.h @@ -100,6 +100,7 @@ private: BRect updateRect); BPoint _SelectorPosition(const BRect& rampRect, uint8 shade) const; + BRect _PaletteFrame() const; BRect _PaletteSelectorFrame(uint8 colorIndex) const; BRect _RampFrame(uint8 rampIndex) const; void _SetCellSize(float size); diff --git a/src/kits/interface/ColorControl.cpp b/src/kits/interface/ColorControl.cpp index f5bf69d..7c144f9 100644 --- a/src/kits/interface/ColorControl.cpp +++ b/src/kits/interface/ColorControl.cpp @@ -170,9 +170,7 @@ BColorControl::_InitData(color_control_layout layout, float size, _LayoutView(); if (useOffscreen) { - BRect bounds = fPaletteFrame; - bounds.InsetBy(-kBevelSpacing, -kBevelSpacing); - + BRect bounds = _PaletteFrame(); fBitmap = new BBitmap(bounds, B_RGB32, true, false); fOffscreenView = new BView(bounds, "off_view", 0, 0); @@ -417,8 +415,7 @@ BColorControl::Draw(BRect updateRect) void BColorControl::_DrawColorArea(BView* target, BRect updateRect) { - BRect rect = fPaletteFrame.InsetByCopy(-kBevelSpacing, -kBevelSpacing); - // frame including bevel + BRect rect = _PaletteFrame(); bool enabled = IsEnabled(); rgb_color noTint = ui_color(B_PANEL_BACKGROUND_COLOR); @@ -602,6 +599,13 @@ BColorControl::_SelectorPosition(const BRect& rampRect, uint8 shade) const BRect +BColorControl::_PaletteFrame() const +{ + return fPaletteFrame.InsetByCopy(-kBevelSpacing, -kBevelSpacing); +} + + +BRect BColorControl::_RampFrame(uint8 rampIndex) const { float rampHeight = float(fRows) * fCellSize / 4.0f; @@ -646,8 +650,7 @@ void BColorControl::_InitOffscreen() { if (fBitmap->Lock()) { - _DrawColorArea(fOffscreenView, - fPaletteFrame.InsetByCopy(-kBevelSpacing, -kBevelSpacing)); + _DrawColorArea(fOffscreenView, _PaletteFrame()); fOffscreenView->Sync(); fBitmap->Unlock(); } @@ -853,8 +856,7 @@ BColorControl::DetachedFromWindow() void BColorControl::GetPreferredSize(float* _width, float* _height) { - BRect rect = fPaletteFrame.InsetByCopy(-kBevelSpacing, -kBevelSpacing); - // bevel + BRect rect = _PaletteFrame(); if (rect.Height() < fBlueText->Frame().bottom) { // adjust the height to fit ############################################################################ Commit: da6c116d637493cdac2f615cdeabfa05d3964226 URL: http://cgit.haiku-os.org/haiku/commit/?id=da6c116 Author: John Scipione <jscipione@xxxxxxxxx> Date: Thu Jun 6 03:20:13 2013 UTC BColorControl: Introduce kRampCount magic constant. ---------------------------------------------------------------------------- diff --git a/src/kits/interface/ColorControl.cpp b/src/kits/interface/ColorControl.cpp index 7c144f9..6a76a35 100644 --- a/src/kits/interface/ColorControl.cpp +++ b/src/kits/interface/ColorControl.cpp @@ -43,6 +43,7 @@ static const float kSelectorHSpacing = 2.0f; static const float kTextFieldsHSpacing = 6.0f; static const float kDefaultFontSize = 12.0f; static const float kBevelSpacing = 2.0f; +static const uint32 kRampCount = 4; BColorControl::BColorControl(BPoint leftTop, color_control_layout layout, @@ -608,7 +609,7 @@ BColorControl::_PaletteFrame() const BRect BColorControl::_RampFrame(uint8 rampIndex) const { - float rampHeight = float(fRows) * fCellSize / 4.0f; + float rampHeight = (float)(fRows * fCellSize / kRampCount); return BRect(fPaletteFrame.left, fPaletteFrame.top + float(rampIndex) * rampHeight, ############################################################################ Commit: d5432ed60914ac43e426c11b4841041779f32bd8 URL: http://cgit.haiku-os.org/haiku/commit/?id=d5432ed Author: John Scipione <jscipione@xxxxxxxxx> Date: Fri Jun 7 21:09:34 2013 UTC BColorControl: Refactor _LayoutView() In a few cases we were doing the work of _LayoutView() twice because we called _LayoutView() and then called ResizeToPreferred() which called _LayoutView() again. Now only call ResizeToPreferred() which calls _LayoutView(). ---------------------------------------------------------------------------- diff --git a/src/kits/interface/ColorControl.cpp b/src/kits/interface/ColorControl.cpp index 6a76a35..c2c4888 100644 --- a/src/kits/interface/ColorControl.cpp +++ b/src/kits/interface/ColorControl.cpp @@ -168,7 +168,7 @@ BColorControl::_InitData(color_control_layout layout, float size, AddChild(fBlueText); } - _LayoutView(); + ResizeToPreferred(); if (useOffscreen) { BRect bounds = _PaletteFrame(); @@ -199,9 +199,6 @@ BColorControl::_LayoutView() BRect rect = fPaletteFrame.InsetByCopy(-kBevelSpacing, -kBevelSpacing); // frame including bevel - if (rect.Height() < fBlueText->Frame().bottom) - rect.bottom = fBlueText->Frame().bottom; - float offset = floorf(rect.bottom / 4); float y = offset; if (offset < _TextRectOffset()) { @@ -216,9 +213,6 @@ BColorControl::_LayoutView() y += offset; fBlueText->MoveTo(rect.right + kTextFieldsHSpacing, y); - - ResizeTo(rect.Width() + kTextFieldsHSpacing + fRedText->Bounds().Width(), - rect.Height()); } @@ -662,7 +656,6 @@ void BColorControl::SetCellSize(float size) { _SetCellSize(size); - _LayoutView(); ResizeToPreferred(); } @@ -700,8 +693,6 @@ BColorControl::SetLayout(color_control_layout layout) break; } - _LayoutView(); - ResizeToPreferred(); Invalidate(); } @@ -877,9 +868,8 @@ BColorControl::GetPreferredSize(float* _width, float* _height) void BColorControl::ResizeToPreferred() { - BControl::ResizeToPreferred(); - _LayoutView(); + BControl::ResizeToPreferred(); } ############################################################################ Revision: hrev45753 Commit: 1f0b41ba7fdcc573354eea3e1354520d9a036023 URL: http://cgit.haiku-os.org/haiku/commit/?id=1f0b41b Author: John Scipione <jscipione@xxxxxxxxx> Date: Fri Jun 7 21:14:56 2013 UTC BColorControl: Position text controls better Position the text control vertically in the middle of the ramp in the case that the text controls are pushed down so that the red, green, and blue text controls are next to the red, green, and blue ramps. ---------------------------------------------------------------------------- diff --git a/src/kits/interface/ColorControl.cpp b/src/kits/interface/ColorControl.cpp index c2c4888..3ac5d50 100644 --- a/src/kits/interface/ColorControl.cpp +++ b/src/kits/interface/ColorControl.cpp @@ -196,16 +196,17 @@ BColorControl::_LayoutView() fPaletteFrame.bottom -= 1; } - BRect rect = fPaletteFrame.InsetByCopy(-kBevelSpacing, -kBevelSpacing); - // frame including bevel - - float offset = floorf(rect.bottom / 4); - float y = offset; - if (offset < _TextRectOffset()) { - offset = _TextRectOffset(); - y = 0; + float rampHeight = (float)(fRows * fCellSize / kRampCount); + float offset = _TextRectOffset(); + float y = 0; + if (rampHeight > fRedText->Frame().Height()) { + // there is enough room to fit kRampCount labels, + // shift text controls down by one ramp + offset = rampHeight; + y = floorf(offset + (offset - fRedText->Frame().Height()) / 2); } + BRect rect = _PaletteFrame(); fRedText->MoveTo(rect.right + kTextFieldsHSpacing, y); y += offset;