* 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:
parent
d3bde5de44
commit
02b73236ae
@ -25,7 +25,8 @@ using BPrivate::B_LOCAL_TIME;
|
||||
|
||||
|
||||
TTimeEdit::TTimeEdit(BRect frame, const char* name, uint32 sections)
|
||||
: TSectionEdit(frame, name, sections),
|
||||
:
|
||||
TSectionEdit(frame, name, sections),
|
||||
fLastKeyDownTime(0)
|
||||
{
|
||||
InitView();
|
||||
@ -106,7 +107,7 @@ TTimeEdit::DrawSection(uint32 index, bool hasFocus)
|
||||
BString text;
|
||||
switch (index) {
|
||||
case 0:
|
||||
{ // hour
|
||||
// hour
|
||||
if (value > 12) {
|
||||
if (value < 22)
|
||||
text << "0";
|
||||
@ -118,36 +119,35 @@ TTimeEdit::DrawSection(uint32 index, bool hasFocus)
|
||||
text << "0";
|
||||
text << value;
|
||||
}
|
||||
} break;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
case 2:
|
||||
{ // minute
|
||||
// minute
|
||||
// second
|
||||
if (value < 10)
|
||||
text << "0";
|
||||
text << value;
|
||||
} break;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
{ // am/pm
|
||||
// am/pm
|
||||
value = fTime.Hour();
|
||||
if (value >= 12)
|
||||
text << "PM";
|
||||
else
|
||||
text << "AM";
|
||||
} break;
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
// calc and center text in section rect
|
||||
float width = be_plain_font->StringWidth(text.String());
|
||||
|
||||
BPoint offset(-((bounds.Width()- width) / 2.0) -1.0
|
||||
, bounds.Height() / 2.0 -6.0);
|
||||
BPoint offset(-((bounds.Width()- width) / 2.0) -1.0,
|
||||
bounds.Height() / 2.0 -6.0);
|
||||
|
||||
SetHighColor(0, 0, 0, 255);
|
||||
FillRect(bounds, B_SOLID_LOW);
|
||||
@ -156,7 +156,7 @@ TTimeEdit::DrawSection(uint32 index, bool hasFocus)
|
||||
|
||||
|
||||
void
|
||||
TTimeEdit::DrawSeperator(uint32 index)
|
||||
TTimeEdit::DrawSeparator(uint32 index)
|
||||
{
|
||||
if (index == 3)
|
||||
return;
|
||||
@ -168,15 +168,14 @@ TTimeEdit::DrawSeperator(uint32 index)
|
||||
return;
|
||||
|
||||
BRect bounds = section->Frame();
|
||||
float sepWidth = SeperatorWidth();
|
||||
float sepWidth = SeparatorWidth();
|
||||
|
||||
char* sep = ":";
|
||||
if (index == 2)
|
||||
sep = "-";
|
||||
|
||||
float width = be_plain_font->StringWidth(sep);
|
||||
BPoint offset(-((sepWidth - width) / 2.0) -1.0
|
||||
, bounds.Height() / 2.0 -6.0);
|
||||
BPoint offset(-((sepWidth - width) / 2.0) -1.0, bounds.Height() / 2.0 -6.0);
|
||||
DrawString(sep, bounds.RightBottom() - offset);
|
||||
}
|
||||
|
||||
@ -187,7 +186,7 @@ TTimeEdit::SetSections(BRect area)
|
||||
// by default divide up the sections evenly
|
||||
BRect bounds(area);
|
||||
|
||||
float sepWidth = SeperatorWidth();
|
||||
float sepWidth = SeparatorWidth();
|
||||
|
||||
float sep_2 = ceil(sepWidth / fSectionCount +1);
|
||||
float width = bounds.Width() / fSectionCount -sep_2;
|
||||
@ -206,7 +205,7 @@ TTimeEdit::SetSections(BRect area)
|
||||
|
||||
|
||||
float
|
||||
TTimeEdit::SeperatorWidth() const
|
||||
TTimeEdit::SeparatorWidth() const
|
||||
{
|
||||
return 10.0f;
|
||||
}
|
||||
@ -290,37 +289,37 @@ TTimeEdit::_CheckRange()
|
||||
int32 value = fHoldValue;
|
||||
switch (fFocus) {
|
||||
case 0:
|
||||
{ // hour
|
||||
// hour
|
||||
if (value > 23)
|
||||
value = 0;
|
||||
else if (value < 0)
|
||||
value = 23;
|
||||
|
||||
fTime.SetTime(value, fTime.Minute(), fTime.Second());
|
||||
} break;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
{ // minute
|
||||
// minute
|
||||
if (value> 59)
|
||||
value = 0;
|
||||
else if (value < 0)
|
||||
value = 59;
|
||||
|
||||
fTime.SetTime(fTime.Hour(), value, fTime.Second());
|
||||
} break;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
{ // second
|
||||
// second
|
||||
if (value > 59)
|
||||
value = 0;
|
||||
else if (value < 0)
|
||||
value = 59;
|
||||
|
||||
fTime.SetTime(fTime.Hour(), fTime.Minute(), value);
|
||||
} break;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
{
|
||||
// AM/PM
|
||||
value = fTime.Hour();
|
||||
if (value < 13)
|
||||
value += 12;
|
||||
@ -331,7 +330,7 @@ TTimeEdit::_CheckRange()
|
||||
|
||||
// modify hour value to reflect change in am/ pm
|
||||
fTime.SetTime(value, fTime.Minute(), fTime.Second());
|
||||
} break;
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
@ -348,22 +347,22 @@ TTimeEdit::_IsValidDoubleDigi(int32 value)
|
||||
bool isInRange = false;
|
||||
switch (fFocus) {
|
||||
case 0:
|
||||
{ // hour
|
||||
// hour
|
||||
if (value <= 23)
|
||||
isInRange = true;
|
||||
} break;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
{ // minute
|
||||
// minute
|
||||
if (value <= 59)
|
||||
isInRange = true;
|
||||
} break;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
{ // second
|
||||
// second
|
||||
if (value <= 59)
|
||||
isInRange = true;
|
||||
} break;
|
||||
break;
|
||||
|
||||
default:
|
||||
return isInRange;
|
||||
@ -496,8 +495,8 @@ TDateEdit::DrawSection(uint32 index, bool hasFocus)
|
||||
|
||||
// calc and center text in section rect
|
||||
float width = StringWidth(text.String());
|
||||
BPoint offset(-(bounds.Width() - width) / 2.0 - 1.0
|
||||
, (bounds.Height() / 2.0 - 6.0));
|
||||
BPoint offset(-(bounds.Width() - width) / 2.0 - 1.0,
|
||||
(bounds.Height() / 2.0 - 6.0));
|
||||
|
||||
SetHighColor(0, 0, 0, 255);
|
||||
FillRect(bounds, B_SOLID_LOW);
|
||||
@ -506,7 +505,7 @@ TDateEdit::DrawSection(uint32 index, bool hasFocus)
|
||||
|
||||
|
||||
void
|
||||
TDateEdit::DrawSeperator(uint32 index)
|
||||
TDateEdit::DrawSeparator(uint32 index)
|
||||
{
|
||||
if (index == 3)
|
||||
return;
|
||||
@ -515,11 +514,11 @@ TDateEdit::DrawSeperator(uint32 index)
|
||||
section = static_cast<TSection*> (fSectionList->ItemAt(index));
|
||||
BRect bounds = section->Frame();
|
||||
|
||||
float sepWidth = SeperatorWidth();
|
||||
float sepWidth = SeparatorWidth();
|
||||
float width = be_plain_font->StringWidth("/");
|
||||
|
||||
BPoint offset(-(sepWidth / 2.0 - width / 2.0) -1.0
|
||||
, bounds.Height() / 2.0 -6.0);
|
||||
BPoint offset(-(sepWidth / 2.0 - width / 2.0) -1.0,
|
||||
bounds.Height() / 2.0 -6.0);
|
||||
|
||||
SetHighColor(0, 0, 0, 255);
|
||||
DrawString("/", bounds.RightBottom() - offset);
|
||||
@ -534,7 +533,7 @@ TDateEdit::SetSections(BRect area)
|
||||
fSectionList->AddItem(new TSection(area));
|
||||
|
||||
BRect bounds(area);
|
||||
float sepWidth = SeperatorWidth();
|
||||
float sepWidth = SeparatorWidth();
|
||||
|
||||
// year
|
||||
TSection *section = NULL;
|
||||
@ -560,7 +559,7 @@ TDateEdit::SetSections(BRect area)
|
||||
|
||||
|
||||
float
|
||||
TDateEdit::SeperatorWidth() const
|
||||
TDateEdit::SeparatorWidth() const
|
||||
{
|
||||
return 10.0f;
|
||||
}
|
||||
@ -645,7 +644,6 @@ TDateEdit::_CheckRange()
|
||||
|
||||
switch (fFocus) {
|
||||
case 0:
|
||||
{
|
||||
// month
|
||||
if (value > 12)
|
||||
value = 1;
|
||||
@ -653,7 +651,7 @@ TDateEdit::_CheckRange()
|
||||
value = 12;
|
||||
|
||||
fDate.SetDate(fDate.Year(), value, fDate.Day());
|
||||
} break;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
{
|
||||
@ -665,10 +663,10 @@ TDateEdit::_CheckRange()
|
||||
value = days;
|
||||
|
||||
fDate.SetDate(fDate.Year(), fDate.Month(), value);
|
||||
} break;
|
||||
break;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
// year
|
||||
if (value > 2037)
|
||||
value = 2037;
|
||||
@ -676,7 +674,7 @@ TDateEdit::_CheckRange()
|
||||
value = 1970;
|
||||
|
||||
fDate.SetDate(value, fDate.Month(), fDate.Day());
|
||||
} break;
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
@ -694,19 +692,22 @@ TDateEdit::_IsValidDoubleDigi(int32 value)
|
||||
int32 year = 0;
|
||||
switch (fFocus) {
|
||||
case 1:
|
||||
{ // day
|
||||
{
|
||||
// day
|
||||
int32 days = fDate.DaysInMonth();
|
||||
if (value <= days)
|
||||
isInRange = true;
|
||||
} break;
|
||||
break;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{ //year
|
||||
{
|
||||
// year
|
||||
year = int32(fHoldValue / 100) * 100 + value;
|
||||
if (year <= 2037 && year >= 1970)
|
||||
isInRange = true;
|
||||
} break;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return isInRange;
|
||||
|
@ -30,11 +30,11 @@ class TTimeEdit : public TSectionEdit {
|
||||
|
||||
virtual void InitView();
|
||||
virtual void DrawSection(uint32 index, bool isfocus);
|
||||
virtual void DrawSeperator(uint32 index);
|
||||
virtual void DrawSeparator(uint32 index);
|
||||
|
||||
virtual void SetSections(BRect area);
|
||||
virtual void SectionFocus(uint32 index);
|
||||
virtual float SeperatorWidth() const;
|
||||
virtual float SeparatorWidth() const;
|
||||
|
||||
virtual void DoUpPress();
|
||||
virtual void DoDownPress();
|
||||
@ -63,11 +63,11 @@ class TDateEdit : public TSectionEdit {
|
||||
|
||||
virtual void InitView();
|
||||
virtual void DrawSection(uint32 index, bool isfocus);
|
||||
virtual void DrawSeperator(uint32 index);
|
||||
virtual void DrawSeparator(uint32 index);
|
||||
|
||||
virtual void SetSections(BRect area);
|
||||
virtual void SectionFocus(uint32 index);
|
||||
virtual float SeperatorWidth() const;
|
||||
virtual float SeparatorWidth() const;
|
||||
|
||||
virtual void DoUpPress();
|
||||
virtual void DoDownPress();
|
||||
|
@ -9,22 +9,21 @@
|
||||
*/
|
||||
|
||||
#include "SectionEdit.h"
|
||||
#include "Bitmaps.h"
|
||||
#include "TimeMessages.h"
|
||||
|
||||
|
||||
#include <Bitmap.h>
|
||||
#include <ControlLook.h>
|
||||
#include <List.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include "TimeMessages.h"
|
||||
|
||||
|
||||
const uint32 kArrowAreaWidth = 16;
|
||||
|
||||
|
||||
TSectionEdit::TSectionEdit(BRect frame, const char *name, uint32 sections)
|
||||
: BControl(frame, name, NULL, NULL, B_FOLLOW_NONE, B_NAVIGABLE | B_WILL_DRAW),
|
||||
fUpArrow(NULL),
|
||||
fDownArrow(NULL),
|
||||
:
|
||||
BControl(frame, name, NULL, NULL, B_FOLLOW_NONE, B_NAVIGABLE | B_WILL_DRAW),
|
||||
fSectionList(NULL),
|
||||
fFocus(-1),
|
||||
fSectionCount(sections)
|
||||
@ -35,9 +34,6 @@ TSectionEdit::TSectionEdit(BRect frame, const char *name, uint32 sections)
|
||||
|
||||
TSectionEdit::~TSectionEdit()
|
||||
{
|
||||
delete fUpArrow;
|
||||
delete fDownArrow;
|
||||
|
||||
int32 count = fSectionList->CountItems();
|
||||
if (count > 0) {
|
||||
for (int32 index = 0; index < count; index++)
|
||||
@ -50,22 +46,20 @@ TSectionEdit::~TSectionEdit()
|
||||
void
|
||||
TSectionEdit::AttachedToWindow()
|
||||
{
|
||||
if (Parent()) {
|
||||
if (Parent())
|
||||
SetViewColor(Parent()->ViewColor());
|
||||
ReplaceTransparentColor(fUpArrow, ViewColor());
|
||||
ReplaceTransparentColor(fDownArrow, ViewColor());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TSectionEdit::Draw(BRect updateRect)
|
||||
{
|
||||
DrawBorder();
|
||||
DrawBorder(updateRect);
|
||||
|
||||
for (uint32 idx = 0; idx < fSectionCount; idx++) {
|
||||
DrawSection(idx, ((uint32)fFocus == idx) && IsFocus());
|
||||
if (idx < fSectionCount -1)
|
||||
DrawSeperator(idx);
|
||||
DrawSeparator(idx);
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,17 +164,6 @@ TSectionEdit::FocusIndex() const
|
||||
void
|
||||
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
|
||||
fSectionList = new BList(fSectionCount);
|
||||
fSectionArea = Bounds().InsetByCopy(2, 2);
|
||||
@ -189,84 +172,52 @@ TSectionEdit::InitView()
|
||||
|
||||
|
||||
void
|
||||
TSectionEdit::Draw3DFrame(BRect frame, bool inset)
|
||||
TSectionEdit::DrawBorder(const BRect& updateRect)
|
||||
{
|
||||
rgb_color color1 = LowColor();
|
||||
rgb_color color2 = HighColor();
|
||||
BRect bounds(Bounds());
|
||||
fShowFocus = (IsFocus() && Window() && Window()->IsActive());
|
||||
|
||||
if (inset) {
|
||||
color1 = HighColor();
|
||||
color2 = LowColor();
|
||||
be_control_look->DrawBorder(this, bounds, updateRect, ViewColor(),
|
||||
B_FANCY_BORDER, fShowFocus ? BControlLook::B_FOCUSED : 0);
|
||||
|
||||
// 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);
|
||||
// left side
|
||||
AddLine(frame.LeftBottom(), frame.LeftTop(), color2);
|
||||
// right side
|
||||
AddLine(frame.RightTop(), frame.RightBottom(), color1);
|
||||
// bottom side
|
||||
AddLine(frame.RightBottom(), frame.LeftBottom(), color1);
|
||||
// top side
|
||||
AddLine(frame.LeftTop(), frame.RightTop(), color2);
|
||||
FillRect(fDownRect, B_SOLID_LOW);
|
||||
BeginLineArray(2);
|
||||
AddLine(left, middle, HighColor());
|
||||
AddLine(middle, right, HighColor());
|
||||
EndLineArray();
|
||||
}
|
||||
|
||||
|
||||
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());
|
||||
SetPenSize(1);
|
||||
}
|
||||
|
||||
|
||||
float
|
||||
TSectionEdit::SeperatorWidth() const
|
||||
TSectionEdit::SeparatorWidth() const
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
|
@ -59,15 +59,14 @@ class TSectionEdit: public BControl {
|
||||
virtual void InitView();
|
||||
|
||||
// hooks
|
||||
virtual void DrawBorder();
|
||||
virtual void DrawBorder(const BRect& updateRect);
|
||||
virtual void DrawSection(uint32 index, bool isFocus) {}
|
||||
virtual void DrawSeperator(uint32 index) {}
|
||||
virtual void Draw3DFrame(BRect frame, bool inset);
|
||||
virtual void DrawSeparator(uint32 index) {}
|
||||
|
||||
virtual void SectionFocus(uint32 index) {}
|
||||
virtual void SectionChange(uint32 index, uint32 value) {}
|
||||
virtual void SetSections(BRect area) {}
|
||||
virtual float SeperatorWidth() const;
|
||||
virtual float SeparatorWidth() const;
|
||||
|
||||
virtual void DoUpPress() {}
|
||||
virtual void DoDownPress() {}
|
||||
@ -76,8 +75,6 @@ class TSectionEdit: public BControl {
|
||||
virtual void BuildDispatch(BMessage *message) = 0;
|
||||
|
||||
protected:
|
||||
BBitmap *fUpArrow;
|
||||
BBitmap *fDownArrow;
|
||||
BList *fSectionList;
|
||||
|
||||
BRect fUpRect;
|
||||
|
Loading…
Reference in New Issue
Block a user