* Made TSectionEdit use be_control_look to draw its frame. Also, it no longer

uses those ugly bitmaps for the up/down buttons - while the updated drawing is
  far from nice either, it at least fits our UI style a lot better.
* Fixed typo "seperator" -> "separator".
* Coding style cleanup (still some stuff left).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31374 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-07-02 15:32:19 +00:00
parent d3bde5de44
commit 02b73236ae
4 changed files with 183 additions and 234 deletions
+48 -47
View File
@@ -25,7 +25,8 @@ using BPrivate::B_LOCAL_TIME;
TTimeEdit::TTimeEdit(BRect frame, const char* name, uint32 sections) TTimeEdit::TTimeEdit(BRect frame, const char* name, uint32 sections)
: TSectionEdit(frame, name, sections), :
TSectionEdit(frame, name, sections),
fLastKeyDownTime(0) fLastKeyDownTime(0)
{ {
InitView(); InitView();
@@ -106,7 +107,7 @@ TTimeEdit::DrawSection(uint32 index, bool hasFocus)
BString text; BString text;
switch (index) { switch (index) {
case 0: case 0:
{ // hour // hour
if (value > 12) { if (value > 12) {
if (value < 22) if (value < 22)
text << "0"; text << "0";
@@ -118,36 +119,35 @@ TTimeEdit::DrawSection(uint32 index, bool hasFocus)
text << "0"; text << "0";
text << value; text << value;
} }
} break; break;
case 1: case 1:
case 2: case 2:
{ // minute // minute
// second // second
if (value < 10) if (value < 10)
text << "0"; text << "0";
text << value; text << value;
} break; break;
case 3: case 3:
{ // am/pm // am/pm
value = fTime.Hour(); value = fTime.Hour();
if (value >= 12) if (value >= 12)
text << "PM"; text << "PM";
else else
text << "AM"; text << "AM";
} break; break;
default: default:
return; return;
break;
} }
// calc and center text in section rect // calc and center text in section rect
float width = be_plain_font->StringWidth(text.String()); float width = be_plain_font->StringWidth(text.String());
BPoint offset(-((bounds.Width()- width) / 2.0) -1.0 BPoint offset(-((bounds.Width()- width) / 2.0) -1.0,
, bounds.Height() / 2.0 -6.0); bounds.Height() / 2.0 -6.0);
SetHighColor(0, 0, 0, 255); SetHighColor(0, 0, 0, 255);
FillRect(bounds, B_SOLID_LOW); FillRect(bounds, B_SOLID_LOW);
@@ -156,7 +156,7 @@ TTimeEdit::DrawSection(uint32 index, bool hasFocus)
void void
TTimeEdit::DrawSeperator(uint32 index) TTimeEdit::DrawSeparator(uint32 index)
{ {
if (index == 3) if (index == 3)
return; return;
@@ -168,15 +168,14 @@ TTimeEdit::DrawSeperator(uint32 index)
return; return;
BRect bounds = section->Frame(); BRect bounds = section->Frame();
float sepWidth = SeperatorWidth(); float sepWidth = SeparatorWidth();
char* sep = ":"; char* sep = ":";
if (index == 2) if (index == 2)
sep = "-"; sep = "-";
float width = be_plain_font->StringWidth(sep); float width = be_plain_font->StringWidth(sep);
BPoint offset(-((sepWidth - width) / 2.0) -1.0 BPoint offset(-((sepWidth - width) / 2.0) -1.0, bounds.Height() / 2.0 -6.0);
, bounds.Height() / 2.0 -6.0);
DrawString(sep, bounds.RightBottom() - offset); DrawString(sep, bounds.RightBottom() - offset);
} }
@@ -187,7 +186,7 @@ TTimeEdit::SetSections(BRect area)
// by default divide up the sections evenly // by default divide up the sections evenly
BRect bounds(area); BRect bounds(area);
float sepWidth = SeperatorWidth(); float sepWidth = SeparatorWidth();
float sep_2 = ceil(sepWidth / fSectionCount +1); float sep_2 = ceil(sepWidth / fSectionCount +1);
float width = bounds.Width() / fSectionCount -sep_2; float width = bounds.Width() / fSectionCount -sep_2;
@@ -206,7 +205,7 @@ TTimeEdit::SetSections(BRect area)
float float
TTimeEdit::SeperatorWidth() const TTimeEdit::SeparatorWidth() const
{ {
return 10.0f; return 10.0f;
} }
@@ -290,37 +289,37 @@ TTimeEdit::_CheckRange()
int32 value = fHoldValue; int32 value = fHoldValue;
switch (fFocus) { switch (fFocus) {
case 0: case 0:
{ // hour // hour
if (value > 23) if (value > 23)
value = 0; value = 0;
else if (value < 0) else if (value < 0)
value = 23; value = 23;
fTime.SetTime(value, fTime.Minute(), fTime.Second()); fTime.SetTime(value, fTime.Minute(), fTime.Second());
} break; break;
case 1: case 1:
{ // minute // minute
if (value> 59) if (value> 59)
value = 0; value = 0;
else if (value < 0) else if (value < 0)
value = 59; value = 59;
fTime.SetTime(fTime.Hour(), value, fTime.Second()); fTime.SetTime(fTime.Hour(), value, fTime.Second());
} break; break;
case 2: case 2:
{ // second // second
if (value > 59) if (value > 59)
value = 0; value = 0;
else if (value < 0) else if (value < 0)
value = 59; value = 59;
fTime.SetTime(fTime.Hour(), fTime.Minute(), value); fTime.SetTime(fTime.Hour(), fTime.Minute(), value);
} break; break;
case 3: case 3:
{ // AM/PM
value = fTime.Hour(); value = fTime.Hour();
if (value < 13) if (value < 13)
value += 12; value += 12;
@@ -331,7 +330,7 @@ TTimeEdit::_CheckRange()
// modify hour value to reflect change in am/ pm // modify hour value to reflect change in am/ pm
fTime.SetTime(value, fTime.Minute(), fTime.Second()); fTime.SetTime(value, fTime.Minute(), fTime.Second());
} break; break;
default: default:
return; return;
@@ -348,22 +347,22 @@ TTimeEdit::_IsValidDoubleDigi(int32 value)
bool isInRange = false; bool isInRange = false;
switch (fFocus) { switch (fFocus) {
case 0: case 0:
{ // hour // hour
if (value <= 23) if (value <= 23)
isInRange = true; isInRange = true;
} break; break;
case 1: case 1:
{ // minute // minute
if (value <= 59) if (value <= 59)
isInRange = true; isInRange = true;
} break; break;
case 2: case 2:
{ // second // second
if (value <= 59) if (value <= 59)
isInRange = true; isInRange = true;
} break; break;
default: default:
return isInRange; return isInRange;
@@ -496,8 +495,8 @@ TDateEdit::DrawSection(uint32 index, bool hasFocus)
// calc and center text in section rect // calc and center text in section rect
float width = StringWidth(text.String()); float width = StringWidth(text.String());
BPoint offset(-(bounds.Width() - width) / 2.0 - 1.0 BPoint offset(-(bounds.Width() - width) / 2.0 - 1.0,
, (bounds.Height() / 2.0 - 6.0)); (bounds.Height() / 2.0 - 6.0));
SetHighColor(0, 0, 0, 255); SetHighColor(0, 0, 0, 255);
FillRect(bounds, B_SOLID_LOW); FillRect(bounds, B_SOLID_LOW);
@@ -506,7 +505,7 @@ TDateEdit::DrawSection(uint32 index, bool hasFocus)
void void
TDateEdit::DrawSeperator(uint32 index) TDateEdit::DrawSeparator(uint32 index)
{ {
if (index == 3) if (index == 3)
return; return;
@@ -515,11 +514,11 @@ TDateEdit::DrawSeperator(uint32 index)
section = static_cast<TSection*> (fSectionList->ItemAt(index)); section = static_cast<TSection*> (fSectionList->ItemAt(index));
BRect bounds = section->Frame(); BRect bounds = section->Frame();
float sepWidth = SeperatorWidth(); float sepWidth = SeparatorWidth();
float width = be_plain_font->StringWidth("/"); float width = be_plain_font->StringWidth("/");
BPoint offset(-(sepWidth / 2.0 - width / 2.0) -1.0 BPoint offset(-(sepWidth / 2.0 - width / 2.0) -1.0,
, bounds.Height() / 2.0 -6.0); bounds.Height() / 2.0 -6.0);
SetHighColor(0, 0, 0, 255); SetHighColor(0, 0, 0, 255);
DrawString("/", bounds.RightBottom() - offset); DrawString("/", bounds.RightBottom() - offset);
@@ -534,7 +533,7 @@ TDateEdit::SetSections(BRect area)
fSectionList->AddItem(new TSection(area)); fSectionList->AddItem(new TSection(area));
BRect bounds(area); BRect bounds(area);
float sepWidth = SeperatorWidth(); float sepWidth = SeparatorWidth();
// year // year
TSection *section = NULL; TSection *section = NULL;
@@ -560,7 +559,7 @@ TDateEdit::SetSections(BRect area)
float float
TDateEdit::SeperatorWidth() const TDateEdit::SeparatorWidth() const
{ {
return 10.0f; return 10.0f;
} }
@@ -645,7 +644,6 @@ TDateEdit::_CheckRange()
switch (fFocus) { switch (fFocus) {
case 0: case 0:
{
// month // month
if (value > 12) if (value > 12)
value = 1; value = 1;
@@ -653,7 +651,7 @@ TDateEdit::_CheckRange()
value = 12; value = 12;
fDate.SetDate(fDate.Year(), value, fDate.Day()); fDate.SetDate(fDate.Year(), value, fDate.Day());
} break; break;
case 1: case 1:
{ {
@@ -665,10 +663,10 @@ TDateEdit::_CheckRange()
value = days; value = days;
fDate.SetDate(fDate.Year(), fDate.Month(), value); fDate.SetDate(fDate.Year(), fDate.Month(), value);
} break; break;
}
case 2: case 2:
{
// year // year
if (value > 2037) if (value > 2037)
value = 2037; value = 2037;
@@ -676,7 +674,7 @@ TDateEdit::_CheckRange()
value = 1970; value = 1970;
fDate.SetDate(value, fDate.Month(), fDate.Day()); fDate.SetDate(value, fDate.Month(), fDate.Day());
} break; break;
default: default:
return; return;
@@ -694,19 +692,22 @@ TDateEdit::_IsValidDoubleDigi(int32 value)
int32 year = 0; int32 year = 0;
switch (fFocus) { switch (fFocus) {
case 1: case 1:
{ // day {
// day // day
int32 days = fDate.DaysInMonth(); int32 days = fDate.DaysInMonth();
if (value <= days) if (value <= days)
isInRange = true; isInRange = true;
} break; break;
}
case 2: case 2:
{ //year {
// year
year = int32(fHoldValue / 100) * 100 + value; year = int32(fHoldValue / 100) * 100 + value;
if (year <= 2037 && year >= 1970) if (year <= 2037 && year >= 1970)
isInRange = true; isInRange = true;
} break; break;
}
default: default:
return isInRange; return isInRange;
+4 -4
View File
@@ -30,11 +30,11 @@ class TTimeEdit : public TSectionEdit {
virtual void InitView(); virtual void InitView();
virtual void DrawSection(uint32 index, bool isfocus); virtual void DrawSection(uint32 index, bool isfocus);
virtual void DrawSeperator(uint32 index); virtual void DrawSeparator(uint32 index);
virtual void SetSections(BRect area); virtual void SetSections(BRect area);
virtual void SectionFocus(uint32 index); virtual void SectionFocus(uint32 index);
virtual float SeperatorWidth() const; virtual float SeparatorWidth() const;
virtual void DoUpPress(); virtual void DoUpPress();
virtual void DoDownPress(); virtual void DoDownPress();
@@ -63,11 +63,11 @@ class TDateEdit : public TSectionEdit {
virtual void InitView(); virtual void InitView();
virtual void DrawSection(uint32 index, bool isfocus); virtual void DrawSection(uint32 index, bool isfocus);
virtual void DrawSeperator(uint32 index); virtual void DrawSeparator(uint32 index);
virtual void SetSections(BRect area); virtual void SetSections(BRect area);
virtual void SectionFocus(uint32 index); virtual void SectionFocus(uint32 index);
virtual float SeperatorWidth() const; virtual float SeparatorWidth() const;
virtual void DoUpPress(); virtual void DoUpPress();
virtual void DoDownPress(); virtual void DoDownPress();
+44 -93
View File
@@ -9,22 +9,21 @@
*/ */
#include "SectionEdit.h" #include "SectionEdit.h"
#include "Bitmaps.h"
#include "TimeMessages.h"
#include <Bitmap.h> #include <Bitmap.h>
#include <ControlLook.h>
#include <List.h> #include <List.h>
#include <Window.h> #include <Window.h>
#include "TimeMessages.h"
const uint32 kArrowAreaWidth = 16; const uint32 kArrowAreaWidth = 16;
TSectionEdit::TSectionEdit(BRect frame, const char *name, uint32 sections) TSectionEdit::TSectionEdit(BRect frame, const char *name, uint32 sections)
: BControl(frame, name, NULL, NULL, B_FOLLOW_NONE, B_NAVIGABLE | B_WILL_DRAW), :
fUpArrow(NULL), BControl(frame, name, NULL, NULL, B_FOLLOW_NONE, B_NAVIGABLE | B_WILL_DRAW),
fDownArrow(NULL),
fSectionList(NULL), fSectionList(NULL),
fFocus(-1), fFocus(-1),
fSectionCount(sections) fSectionCount(sections)
@@ -35,9 +34,6 @@ TSectionEdit::TSectionEdit(BRect frame, const char *name, uint32 sections)
TSectionEdit::~TSectionEdit() TSectionEdit::~TSectionEdit()
{ {
delete fUpArrow;
delete fDownArrow;
int32 count = fSectionList->CountItems(); int32 count = fSectionList->CountItems();
if (count > 0) { if (count > 0) {
for (int32 index = 0; index < count; index++) for (int32 index = 0; index < count; index++)
@@ -50,22 +46,20 @@ TSectionEdit::~TSectionEdit()
void void
TSectionEdit::AttachedToWindow() TSectionEdit::AttachedToWindow()
{ {
if (Parent()) { if (Parent())
SetViewColor(Parent()->ViewColor()); SetViewColor(Parent()->ViewColor());
ReplaceTransparentColor(fUpArrow, ViewColor());
ReplaceTransparentColor(fDownArrow, ViewColor());
}
} }
void void
TSectionEdit::Draw(BRect updateRect) TSectionEdit::Draw(BRect updateRect)
{ {
DrawBorder(); DrawBorder(updateRect);
for (uint32 idx = 0; idx < fSectionCount; idx++) { for (uint32 idx = 0; idx < fSectionCount; idx++) {
DrawSection(idx, ((uint32)fFocus == idx) && IsFocus()); DrawSection(idx, ((uint32)fFocus == idx) && IsFocus());
if (idx < fSectionCount -1) if (idx < fSectionCount -1)
DrawSeperator(idx); DrawSeparator(idx);
} }
} }
@@ -170,17 +164,6 @@ TSectionEdit::FocusIndex() const
void void
TSectionEdit::InitView() TSectionEdit::InitView()
{ {
// create arrow bitmaps
BRect rect(0, 0, kUpArrowWidth -1, kUpArrowHeight -1);
fUpArrow = new BBitmap(rect, kUpArrowColorSpace);
fUpArrow->SetBits(kUpArrowBits, (kUpArrowWidth) *(kUpArrowHeight+1), 0
, kUpArrowColorSpace);
rect = BRect(0, 0, kDownArrowWidth -1, kDownArrowHeight -2);
fDownArrow = new BBitmap(rect, kDownArrowColorSpace);
fDownArrow->SetBits(kDownArrowBits, (kDownArrowWidth) *(kDownArrowHeight)
, 0, kDownArrowColorSpace);
// setup sections // setup sections
fSectionList = new BList(fSectionCount); fSectionList = new BList(fSectionCount);
fSectionArea = Bounds().InsetByCopy(2, 2); fSectionArea = Bounds().InsetByCopy(2, 2);
@@ -189,84 +172,52 @@ TSectionEdit::InitView()
void void
TSectionEdit::Draw3DFrame(BRect frame, bool inset) TSectionEdit::DrawBorder(const BRect& updateRect)
{ {
rgb_color color1 = LowColor(); BRect bounds(Bounds());
rgb_color color2 = HighColor(); fShowFocus = (IsFocus() && Window() && Window()->IsActive());
if (inset) { be_control_look->DrawBorder(this, bounds, updateRect, ViewColor(),
color1 = HighColor(); B_FANCY_BORDER, fShowFocus ? BControlLook::B_FOCUSED : 0);
color2 = LowColor();
// draw up/down control
bounds.left = bounds.right - kArrowAreaWidth;
bounds.right = Bounds().right - 2;
fUpRect.Set(bounds.left + 3, bounds.top + 2, bounds.right,
bounds.bottom / 2.0);
fDownRect = fUpRect.OffsetByCopy(0, fUpRect.Height() + 2);
BPoint middle(floorf(fUpRect.left + fUpRect.Width() / 2), fUpRect.top + 1);
BPoint left(fUpRect.left + 3, fUpRect.bottom - 1);
BPoint right(left.x + 2 * (middle.x - left.x), fUpRect.bottom - 1);
SetPenSize(2);
if (updateRect.Intersects(fUpRect)) {
FillRect(fUpRect, B_SOLID_LOW);
BeginLineArray(2);
AddLine(left, middle, HighColor());
AddLine(middle, right, HighColor());
EndLineArray();
} }
if (updateRect.Intersects(fDownRect)) {
middle.y = fDownRect.bottom - 1;
left.y = right.y = fDownRect.top + 1;
BeginLineArray(4); FillRect(fDownRect, B_SOLID_LOW);
// left side BeginLineArray(2);
AddLine(frame.LeftBottom(), frame.LeftTop(), color2); AddLine(left, middle, HighColor());
// right side AddLine(middle, right, HighColor());
AddLine(frame.RightTop(), frame.RightBottom(), color1);
// bottom side
AddLine(frame.RightBottom(), frame.LeftBottom(), color1);
// top side
AddLine(frame.LeftTop(), frame.RightTop(), color2);
EndLineArray(); EndLineArray();
} }
SetPenSize(1);
void
TSectionEdit::DrawBorder()
{
rgb_color bgcolor = ViewColor();
rgb_color light = tint_color(bgcolor, B_LIGHTEN_MAX_TINT);
rgb_color dark = tint_color(bgcolor, B_DARKEN_1_TINT);
rgb_color darker = tint_color(bgcolor, B_DARKEN_3_TINT);
SetHighColor(light);
SetLowColor(dark);
BRect bounds(Bounds());
Draw3DFrame(bounds, true);
StrokeLine(bounds.LeftBottom(), bounds.LeftBottom(), B_SOLID_LOW);
bounds.InsetBy(1, 1);
bounds.right -= kArrowAreaWidth;
fShowFocus = (IsFocus() && Window() && Window()->IsActive());
if (fShowFocus) {
rgb_color navcolor = keyboard_navigation_color();
SetHighColor(navcolor);
StrokeRect(bounds);
} else {
// draw border thickening (erase focus)
SetHighColor(darker);
SetLowColor(bgcolor);
Draw3DFrame(bounds, false);
}
// draw up/down control
SetHighColor(light);
bounds.left = bounds.right +1;
bounds.right = Bounds().right -1;
fUpRect.Set(bounds.left +3, bounds.top +2, bounds.right, bounds.bottom /2.0);
fDownRect = fUpRect.OffsetByCopy(0, fUpRect.Height()+2);
if (fUpArrow)
DrawBitmap(fUpArrow, fUpRect.LeftTop());
if (fDownArrow)
DrawBitmap(fDownArrow, fDownRect.LeftTop());
Draw3DFrame(bounds, false);
SetHighColor(dark);
StrokeLine(bounds.LeftBottom(), bounds.RightBottom());
StrokeLine(bounds.RightBottom(), bounds.RightTop());
SetHighColor(light);
StrokeLine(bounds.RightTop(), bounds.RightTop());
} }
float float
TSectionEdit::SeperatorWidth() const TSectionEdit::SeparatorWidth() const
{ {
return 0.0f; return 0.0f;
} }
+3 -6
View File
@@ -59,15 +59,14 @@ class TSectionEdit: public BControl {
virtual void InitView(); virtual void InitView();
// hooks // hooks
virtual void DrawBorder(); virtual void DrawBorder(const BRect& updateRect);
virtual void DrawSection(uint32 index, bool isFocus) {} virtual void DrawSection(uint32 index, bool isFocus) {}
virtual void DrawSeperator(uint32 index) {} virtual void DrawSeparator(uint32 index) {}
virtual void Draw3DFrame(BRect frame, bool inset);
virtual void SectionFocus(uint32 index) {} virtual void SectionFocus(uint32 index) {}
virtual void SectionChange(uint32 index, uint32 value) {} virtual void SectionChange(uint32 index, uint32 value) {}
virtual void SetSections(BRect area) {} virtual void SetSections(BRect area) {}
virtual float SeperatorWidth() const; virtual float SeparatorWidth() const;
virtual void DoUpPress() {} virtual void DoUpPress() {}
virtual void DoDownPress() {} virtual void DoDownPress() {}
@@ -76,8 +75,6 @@ class TSectionEdit: public BControl {
virtual void BuildDispatch(BMessage *message) = 0; virtual void BuildDispatch(BMessage *message) = 0;
protected: protected:
BBitmap *fUpArrow;
BBitmap *fDownArrow;
BList *fSectionList; BList *fSectionList;
BRect fUpRect; BRect fUpRect;