Lots of fixes, geometry calculations updated, added buffered BSlider support

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2540 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Marc Flerackers
2003-01-23 15:11:19 +00:00
parent ac6f7aa850
commit 8ce46bc32b
+41 -34
View File
@@ -41,12 +41,15 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
BCheckBox::BCheckBox(BRect frame, const char *name, const char *label, BCheckBox::BCheckBox(BRect frame, const char *name, const char *label,
BMessage *message, uint32 resizingMode, uint32 flags) BMessage *message, uint32 resizingMode, uint32 flags)
: BControl(frame, name, label, message, resizingMode, flags) : BControl(frame, name, label, message, resizingMode, flags),
fOutlined(false)
{ {
fOutlined = false; // Resize to minimum height if needed
font_height fh;
if (Bounds().Height() < 18.0f) GetFontHeight(&fh);
ResizeTo(Bounds().Width(), 18.0f); float minHeight = 6.0f + (float)ceil(fh.ascent + fh.descent);
if (Bounds().Height() < minHeight)
ResizeTo(Bounds().Width(), minHeight);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
BCheckBox::~BCheckBox() BCheckBox::~BCheckBox()
@@ -55,9 +58,9 @@ BCheckBox::~BCheckBox()
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
BCheckBox::BCheckBox(BMessage *archive) BCheckBox::BCheckBox(BMessage *archive)
: BControl(archive) : BControl(archive),
fOutlined(false)
{ {
fOutlined = false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
BArchivable *BCheckBox::Instantiate(BMessage *archive) BArchivable *BCheckBox::Instantiate(BMessage *archive)
@@ -75,6 +78,25 @@ status_t BCheckBox::Archive(BMessage *archive, bool deep) const
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BCheckBox::Draw(BRect updateRect) void BCheckBox::Draw(BRect updateRect)
{ {
font_height fh;
GetFontHeight(&fh);
// If the focus is changing, just redraw the focus indicator
if (IsFocusChanging())
{
float x = ceil(10.0f + fh.ascent);
float y = 5.0f + ceil(fh.ascent);
if (IsFocus())
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
else
SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
StrokeLine(BPoint(x, y), BPoint(x + StringWidth(Label()), y));
return;
}
rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR), rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR),
lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT), lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT),
lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT), lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT),
@@ -84,7 +106,7 @@ void BCheckBox::Draw(BRect updateRect)
darken4 = tint_color(no_tint, B_DARKEN_4_TINT), darken4 = tint_color(no_tint, B_DARKEN_4_TINT),
darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT); darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT);
BRect rect(1.0, 3.0, 13.0, 15.0); BRect rect(1.0f, 3.0f, ceil(3.0f + fh.ascent), ceil(5.0f + fh.ascent));
if (IsEnabled()) if (IsEnabled())
{ {
@@ -149,21 +171,18 @@ void BCheckBox::Draw(BRect updateRect)
} }
// Label // Label
BFont font;
GetFont(&font);
font_height fh;
font.GetHeight(&fh);
SetHighColor(darkenmax); SetHighColor(darkenmax);
DrawString(Label(), BPoint(20.0f, 8.0f + (float)ceil(fh.ascent / 2.0f))); DrawString(Label(), BPoint(ceil(10.0f + fh.ascent),
3.0f + ceil(fh.ascent)));
// Focus // Focus
if (IsFocus()) if (IsFocus())
{ {
float h = 8.0f + (float)ceil(fh.ascent / 2.0f) + 2.0f; float x = ceil(10.0f + fh.ascent);
float y = 5.0f + ceil(fh.ascent);
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR)); SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
StrokeLine(BPoint(20.0f, h), BPoint(20.0f + StringWidth(Label()), h)); StrokeLine(BPoint(x, y), BPoint(x + StringWidth(Label()), y));
} }
} }
else else
@@ -207,13 +226,9 @@ void BCheckBox::Draw(BRect updateRect)
} }
// Label // Label
BFont font;
GetFont(&font);
font_height fh;
font.GetHeight(&fh);
SetHighColor(tint_color(no_tint, B_DISABLED_LABEL_TINT)); SetHighColor(tint_color(no_tint, B_DISABLED_LABEL_TINT));
DrawString(Label(), BPoint(20.0f, 8.0f + (float)ceil(fh.ascent / 2.0f))); DrawString(Label(), BPoint(ceil(10.0f + fh.ascent),
3.0f + ceil(fh.ascent)));
} }
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -250,13 +265,7 @@ void BCheckBox::WindowActivated(bool active)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BCheckBox::KeyDown(const char *bytes, int32 numBytes) void BCheckBox::KeyDown(const char *bytes, int32 numBytes)
{ {
// if (*((int*)bytes) == VK_RETURN || *((int*)bytes) == VK_SPACE) BControl::KeyDown(bytes, numBytes);
// SetValue(Value() ? 0 : 1);
// else
// {
// SetValue(0);
BControl::KeyDown(bytes, numBytes);
// }
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BCheckBox::MouseUp(BPoint point) void BCheckBox::MouseUp(BPoint point)
@@ -313,15 +322,13 @@ void BCheckBox::GetPreferredSize(float *width, float *height)
font_height fh; font_height fh;
GetFontHeight(&fh); GetFontHeight(&fh);
*height = (float)ceil(fh.ascent + fh.descent + fh.leading) + 6.0f; *height = 6.0f + (float)ceil(fh.ascent + fh.descent);
*width = 22.0f + (float)ceil(StringWidth(Label())); *width = 12.0f + (float)ceil(fh.ascent) + (float)ceil(StringWidth(Label()));
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BCheckBox::ResizeToPreferred() void BCheckBox::ResizeToPreferred()
{ {
float widht, height; BControl::ResizeToPreferred();
GetPreferredSize(&widht, &height);
BView::ResizeTo(widht,height);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
status_t BCheckBox::Invoke(BMessage *message) status_t BCheckBox::Invoke(BMessage *message)