* applied another large patch to cleanup and refactor code by Julun (aka HOST)

* Julun also fixed some font sensitivity issues
* Julun already replaced the bitmap clock with resizable clock rendering,
  I took this as a base and tried to make it visually pleasing



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22199 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2007-09-07 10:23:12 +00:00
parent 6b6f6b7240
commit 53d9356e96
10 changed files with 397 additions and 278 deletions
+143 -121
View File
@@ -4,169 +4,190 @@
* *
* Authors: * Authors:
* Mike Berg (inseculous) * Mike Berg (inseculous)
* Julun <[email protected]>
* Stephan Aßmus <[email protected]>
*/ */
/*! Notes: OffscreenClock borrows heavily from the clock source. */
#include "AnalogClock.h" #include "AnalogClock.h"
#include "Bitmaps.h"
#include "TimeMessages.h" #include "TimeMessages.h"
#include <Alert.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <Debug.h> #include <Message.h>
#include <Dragger.h>
#include <Window.h>
class OffscreenClock : public BView { class OffscreenClock : public BView {
public: public:
OffscreenClock(BRect frame, const char *name); OffscreenClock(BRect frame, const char *name);
virtual ~OffscreenClock(); ~OffscreenClock();
void DrawClock(); void SetTo(int32 hour, int32 minute, int32 second);
BPoint Position(); bool IsDirty() const
{ return fDirty; }
void SetTo(int32 hour, int32 minute, int32 second); void DrawClock();
private: private:
BBitmap *fBitmap; void _DrawHands(float x, float y, float radius,
BBitmap *fCenterBitmap; rgb_color hourMinuteColor, rgb_color secondsColor);
BBitmap *fCapBitmap;
BPoint fCenter;
BPoint fMinutePoints[60]; int32 fHours;
BPoint fHourPoints[60]; int32 fMinutes;
short fHours; int32 fSeconds;
short fMinutes; bool fDirty;
short fSeconds;
}; };
const BRect kClockRect(0, 0, kClockFaceWidth -1, kClockFaceHeight -1);
const BRect kCenterRect(0, 0, kCenterWidth -1, kCenterHeight -1);
const BRect kCapRect(0, 0, kCapWidth -1, kCapHeight -1);
/*!
Analog Clock face rendering view.
*/
OffscreenClock::OffscreenClock(BRect frame, const char *name) OffscreenClock::OffscreenClock(BRect frame, const char *name)
: BView(frame, name, B_NOT_RESIZABLE, B_WILL_DRAW) : BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW),
fHours(0),
fMinutes(0),
fSeconds(0),
fDirty(true)
{ {
fBitmap = new BBitmap(kClockRect, kClockFaceColorSpace); SetFlags(Flags() | B_SUBPIXEL_PRECISE);
fBitmap->SetBits(kClockFaceBits, (kClockFaceWidth) *(kClockFaceHeight +3), 0, kClockFaceColorSpace);
ReplaceTransparentColor(fBitmap, ui_color(B_PANEL_BACKGROUND_COLOR));
fCenterBitmap = new BBitmap(kCenterRect, kCenterColorSpace);
fCenterBitmap->SetBits(kCenterBits, (kCenterWidth) *(kCenterHeight +1), 0, kCenterColorSpace);
fCapBitmap = new BBitmap(kCapRect, kCapColorSpace);
fCapBitmap->SetBits(kCapBits, (kCapWidth +1) *(kCapHeight +1) +1, 0, kCapColorSpace);
fCenter = BPoint(42, 42);
float counter;
short index;
float x, y, mRadius, hRadius;
mRadius = fCenter.x - 12;
hRadius = mRadius - 10;
index = 0;
//
// Generate minutes/hours points array
//
for (counter = 90; counter >= 0; counter -= 6,index++) {
x = mRadius * cos(((360 - counter)/180.0) * 3.1415);
x += fCenter.x;
y = mRadius * sin(((360 - counter)/180.0) * 3.1415);
y += fCenter.x;
fMinutePoints[index].Set(x,y);
x = hRadius * cos(((360 - counter)/180.0) * 3.1415);
x += fCenter.x;
y = hRadius * sin(((360 - counter)/180.0) * 3.1415);
y += fCenter.x;
fHourPoints[index].Set(x,y);
}
for (counter = 354; counter > 90; counter -= 6,index++) {
x = mRadius * cos(((360 - counter)/180.0) * 3.1415);
x += fCenter.x;
y = mRadius * sin(((360 - counter)/180.0) * 3.1415);
y += fCenter.x;
fMinutePoints[index].Set(x,y);
x = hRadius * cos(((360 - counter)/180.0) * 3.1415);
x += fCenter.x;
y = hRadius * sin(((360 - counter)/180.0) * 3.1415);
y += fCenter.x;
fHourPoints[index].Set(x,y);
}
} }
OffscreenClock::~OffscreenClock() OffscreenClock::~OffscreenClock()
{ {
delete fBitmap;
delete fCenterBitmap;
delete fCapBitmap;
} }
void void
OffscreenClock::SetTo(int32 hour, int32 minute, int32 second) OffscreenClock::SetTo(int32 hour, int32 minute, int32 second)
{ {
if (fSeconds != second || fMinutes != minute || fHours != hour) { if (fHours == hour && fMinutes == minute && fSeconds == second)
fHours = hour; return;
fMinutes = minute;
fSeconds = second; fHours = hour;
} fMinutes = minute;
fSeconds = second;
fDirty = true;
} }
void void
OffscreenClock::DrawClock() OffscreenClock::DrawClock()
{ {
ASSERT(Window()->IsLocked()); if (!LockLooper())
return;
// draw clockface BRect bounds = Bounds();
SetDrawingMode(B_OP_COPY); // clear background
DrawBitmap(fBitmap, BPoint(0, 0)); rgb_color background = ui_color(B_PANEL_BACKGROUND_COLOR);
SetHighColor(background);
FillRect(bounds);
SetHighColor(0, 0, 0, 255); float radius = floorf((MIN(bounds.Width(), bounds.Height()) / 2.0)) - 2.5;
float x = floorf((bounds.left + bounds.right) / 2 + 0.5) + 0.5;
float y = floorf((bounds.top + bounds.bottom) / 2 + 0.5) + 0.5;
// + 0.5 is for the offset to pixel centers
// (important when drawing with B_SUBPIXEL_PRECISE)
short hours = fHours; bounds.Set(x - radius, y - radius, x + radius, y + radius);
if (hours >= 12)
hours -= 12;
hours *= 5; SetPenSize(2.0);
hours += (fMinutes / 12);
// draw center hub SetHighColor(tint_color(background, B_DARKEN_1_TINT));
SetDrawingMode(B_OP_OVER); StrokeEllipse(bounds.OffsetByCopy(-1, -1));
DrawBitmap(fCenterBitmap, fCenter - BPoint(kCenterWidth/2.0, kCenterHeight/2.0));
// draw hands SetHighColor(tint_color(background, B_LIGHTEN_2_TINT));
StrokeLine(fCenter, fHourPoints[hours]); StrokeEllipse(bounds.OffsetByCopy(1, 1));
StrokeLine(fCenter, fMinutePoints[fMinutes]);
SetHighColor(tint_color(HighColor(), B_LIGHTEN_1_TINT));
StrokeLine(fCenter, fMinutePoints[fSeconds]);
// draw center cap SetHighColor(tint_color(background, B_DARKEN_3_TINT));
DrawBitmap(fCapBitmap, fCenter -BPoint(kCapWidth/2.0, kCapHeight/2.0)); StrokeEllipse(bounds);
SetLowColor(255, 255, 255);
FillEllipse(bounds, B_SOLID_LOW);
radius -= 3;
SetHighColor(tint_color(HighColor(), B_DARKEN_2_TINT));
// minutes
SetPenSize(1.0);
SetLineMode(B_BUTT_CAP, B_MITER_JOIN);
for (int32 minute = 1; minute < 60; minute++) {
if (minute % 5 == 0)
continue;
float x1 = x + sinf(minute * PI / 30.0) * radius;
float y1 = y + cosf(minute * PI / 30.0) * radius;
float x2 = x + sinf(minute * PI / 30.0) * (radius * 0.95);
float y2 = y + cosf(minute * PI / 30.0) * (radius * 0.95);
StrokeLine(BPoint(x1, y1), BPoint(x2, y2));
}
SetHighColor(tint_color(HighColor(), B_DARKEN_1_TINT));
// hours
SetPenSize(2.0);
SetLineMode(B_ROUND_CAP, B_MITER_JOIN);
for (int32 hour = 0; hour < 12; hour++) {
float x1 = x + sinf(hour * PI / 6.0) * radius;
float y1 = y + cosf(hour * PI / 6.0) * radius;
float x2 = x + sinf(hour * PI / 6.0) * (radius * 0.9);
float y2 = y + cosf(hour * PI / 6.0) * (radius * 0.9);
StrokeLine(BPoint(x1, y1), BPoint(x2, y2));
}
rgb_color hourMinutColor = tint_color(HighColor(), B_DARKEN_2_TINT);
rgb_color secondsColor = (rgb_color){ 255, 0, 0, 255 };
rgb_color shadowColor = tint_color(LowColor(),
(B_DARKEN_1_TINT + B_DARKEN_2_TINT) / 2);
_DrawHands(x + 1.5, y + 1.5, radius, shadowColor, shadowColor);
_DrawHands(x, y, radius, hourMinutColor, secondsColor);
Sync(); Sync();
UnlockLooper();
}
void
OffscreenClock::_DrawHands(float x, float y, float radius,
rgb_color hourMinuteColor, rgb_color secondsColor)
{
SetHighColor(hourMinuteColor);
float offsetX;
float offsetY;
// calc, draw hour hand
SetPenSize(4.0);
float hours = fHours + float(fMinutes) / 60.0;
offsetX = (radius * 0.7) * sinf((hours * PI) / 6.0);
offsetY = (radius * 0.7) * cosf((hours * PI) / 6.0);
StrokeLine(BPoint(x, y), BPoint(x + offsetX, y - offsetY));
// calc, draw minute hand
SetPenSize(3.0);
float minutes = fMinutes + float(fSeconds) / 60.0;
offsetX = (radius * 0.9) * sinf((minutes * PI) / 30.0);
offsetY = (radius * 0.9) * cosf((minutes * PI) / 30.0);
StrokeLine(BPoint(x, y), BPoint(x + offsetX, y - offsetY));
SetHighColor(secondsColor);
// calc, draw second hand
SetPenSize(1.0);
offsetX = (radius * 0.95) * sinf((fSeconds * PI) / 30.0);
offsetY = (radius * 0.95) * cosf((fSeconds * PI) / 30.0);
StrokeLine(BPoint(x, y), BPoint(x + offsetX, y - offsetY));
// draw the center knob
SetHighColor(hourMinuteColor);
FillEllipse(BPoint(x, y), radius * 0.06, radius * 0.06);
} }
// #pragma mark - // #pragma mark -
/*! TAnalogClock::TAnalogClock(BRect frame, const char *name, uint32 resizeMask, uint32 flags)
BView to display clock face of current time. : BView(frame, name, resizeMask, flags | B_DRAW_ON_CHILDREN),
*/ fBitmap(NULL),
TAnalogClock::TAnalogClock(BRect frame, const char *name, uint32 resizingmode, uint32 flags) fClock(NULL)
: BView(frame, name, resizingmode, flags | B_DRAW_ON_CHILDREN)
{ {
_InitView(frame); _InitView(frame);
} }
@@ -181,8 +202,8 @@ TAnalogClock::~TAnalogClock()
void void
TAnalogClock::_InitView(BRect rect) TAnalogClock::_InitView(BRect rect)
{ {
fClock = new OffscreenClock(kClockRect, "offscreen"); fClock = new OffscreenClock(Bounds(), "offscreen");
fBitmap = new BBitmap(kClockRect, B_CMAP8, true); fBitmap = new BBitmap(Bounds(), B_RGB32, true);
fBitmap->Lock(); fBitmap->Lock();
fBitmap->AddChild(fClock); fBitmap->AddChild(fClock);
fBitmap->Unlock(); fBitmap->Unlock();
@@ -230,12 +251,10 @@ TAnalogClock::MessageReceived(BMessage *message)
void void
TAnalogClock::Draw(BRect /*updateRect*/) TAnalogClock::Draw(BRect /*updateRect*/)
{ {
SetHighColor(0, 100, 10); if (fBitmap) {
if (fClock->IsDirty())
if (fBitmap->Lock()) { fClock->DrawClock();
fClock->DrawClock();
DrawBitmap(fBitmap, BPoint(0, 0)); DrawBitmap(fBitmap, BPoint(0, 0));
fBitmap->Unlock();
} }
} }
@@ -243,6 +262,9 @@ TAnalogClock::Draw(BRect /*updateRect*/)
void void
TAnalogClock::SetTo(int32 hour, int32 minute, int32 second) TAnalogClock::SetTo(int32 hour, int32 minute, int32 second)
{ {
fClock->SetTo(hour, minute, second); if (fClock)
fClock->SetTo(hour, minute, second);
Invalidate(); Invalidate();
} }
+18 -12
View File
@@ -1,34 +1,40 @@
/* /*
* Copyright 2004-2006, Haiku, Inc. All Rights Reserved. * Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Mike Berg (inseculous) * Mike Berg (inseculous)
* Julun <[email protected]>
*/ */
#ifndef ANALOG_CLOCK_H #ifndef ANALOG_CLOCK_H
#define ANALOG_CLOCK_H #define ANALOG_CLOCK_H
#include <Message.h>
#include <View.h> #include <View.h>
class BBitmap;
class OffscreenClock; class OffscreenClock;
class TAnalogClock: public BView {
class TAnalogClock : public BView {
public: public:
TAnalogClock(BRect frame, const char *name, uint32 resizingmode, uint32 flags); TAnalogClock(BRect frame, const char *name,
virtual ~TAnalogClock(); uint32 resizeMask, uint32 flags);
virtual ~TAnalogClock();
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void Draw(BRect updaterect); virtual void Draw(BRect updateRect);
virtual void MessageReceived(BMessage *); virtual void MessageReceived(BMessage *message);
void SetTo(int32 hour, int32 minute, int32 second); void SetTo(int32 hour, int32 minute, int32 second);
private: private:
void _InitView(BRect frame); void _InitView(BRect frame);
BBitmap *fBitmap; BBitmap *fBitmap;
OffscreenClock *fClock; OffscreenClock *fClock;
}; };
#endif // ANALOG_CLOCK_H #endif // ANALOG_CLOCK_H
+5
View File
@@ -1,6 +1,7 @@
SubDir HAIKU_TOP src preferences time ; SubDir HAIKU_TOP src preferences time ;
SetSubDirSupportedPlatformsBeOSCompatible ; SetSubDirSupportedPlatformsBeOSCompatible ;
AddSubDirSupportedPlatforms libbe_test ;
Preference Time : Preference Time :
AnalogClock.cpp AnalogClock.cpp
@@ -20,3 +21,7 @@ Preference Time :
: Time.rdef : Time.rdef
; ;
if $(TARGET_PLATFORM) = libbe_test {
HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : Time
: tests!apps ;
}
+132 -96
View File
@@ -1,6 +1,18 @@
/* /*
SettingsView.cpp * Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
*/ * Distributed under the terms of the MIT License.
*
* Authors:
* <unkown>
* Julun <[email protected]>
*/
#include "SettingsView.h"
#include "AnalogClock.h"
#include "CalendarView.h"
#include "DateTimeEdit.h"
#include "TimeMessages.h"
#include <Entry.h> #include <Entry.h>
#include <File.h> #include <File.h>
#include <FindDirectory.h> #include <FindDirectory.h>
@@ -9,17 +21,12 @@
#include <String.h> #include <String.h>
#include <StringView.h> #include <StringView.h>
#include "Bitmaps.h"
#include "SettingsView.h"
#include "TimeMessages.h"
/*=====> TSettingsView <=====*/
TSettingsView::TSettingsView(BRect frame) TSettingsView::TSettingsView(BRect frame)
: BView(frame,"Settings", B_FOLLOW_ALL, : BView(frame,"Settings", B_FOLLOW_ALL,
B_WILL_DRAW|B_FRAME_EVENTS|B_NAVIGABLE_JUMP) B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP),
{ fGmtTime(NULL)
{
InitView(); InitView();
} }
@@ -63,75 +70,101 @@ TSettingsView::MessageReceived(BMessage *message)
} }
void
TSettingsView::GetPreferredSize(float *width, float *height)
{
// hardcode in TimeWindow ...
*width = 361.0f;
*height = 227.0f;
if (fGmtTime) {
// we are initialized
*width = Bounds().Width();
*height = fGmtTime->Frame().bottom;
}
}
void void
TSettingsView::InitView() TSettingsView::InitView()
{ {
ReadFiles(); ReadRTCSettings();
font_height finfo; font_height fontHeight;
be_plain_font->GetHeight(&finfo); be_plain_font->GetHeight(&fontHeight);
float text_height = finfo.descent +finfo.ascent +finfo.leading; float textHeight = fontHeight.descent + fontHeight.ascent + fontHeight.leading;
BRect bounds(Bounds());
bounds.right = (bounds.Width()/2.0) -5;
BRect frame(bounds);
// left side // left side
frame.InsetBy(6, 6); BRect frameLeft(Bounds());
frame.bottom = frame.top +text_height +6; frameLeft.right = frameLeft.Width() / 2;
f_dateedit = new TDateEdit(frame, "date_edit", 3); frameLeft.InsetBy(10.0f, 10.0f);
frameLeft.bottom = frameLeft.top + textHeight +6;
frame.top = f_dateedit->Frame().bottom;
frame.bottom = bounds.bottom; fDateEdit = new TDateEdit(frameLeft, "date_edit", 3);
frame.InsetBy(10, 8); AddChild(fDateEdit);
f_calendar = new TCalendarView(frame, "calendar", B_FOLLOW_NONE, B_WILL_DRAW); frameLeft.top = fDateEdit->Frame().bottom + 10;
frameLeft.bottom = Bounds().bottom - 10;
AddChild(f_dateedit);
AddChild(f_calendar); fCalendar = new TCalendarView(frameLeft, "calendar", B_FOLLOW_NONE, B_WILL_DRAW);
AddChild(fCalendar);
frameLeft.top = fCalendar->Frame().bottom + 10;
BStringView *text = new BStringView(frameLeft, "timezone", "Timezone:");
AddChild(text);
text->ResizeToPreferred();
frameLeft.left += 20.0f;
frameLeft.top = text->Frame().bottom + 5;
fTimeZone = new BStringView(frameLeft, "label", " ");
AddChild(fTimeZone);
// right side // right side
bounds.OffsetBy(bounds.Width() +9, 0); BRect frameRight(Bounds());
f_temp = bounds; frameRight.left = frameRight.Width() / 2;
frame = bounds; frameRight.InsetBy(10.0f, 10.0f);
frame.InsetBy(26, 6); frameRight.bottom = frameRight.top + textHeight +6;
frame.bottom = frame.top +text_height +6;
frame.right += 4; fTimeEdit = new TTimeEdit(frameRight, "time_edit", 4);
f_timeedit = new TTimeEdit(frame, "time_edit", 4); AddChild(fTimeEdit);
AddChild(f_timeedit);
frameRight.top = fTimeEdit->Frame().bottom + 10;
frameRight.bottom = Bounds().bottom - 10;
float left = fTimeEdit->Frame().left;
float tmp = MIN(frameRight.Width(), frameRight.Height());
frameRight.left = left + (fTimeEdit->Bounds().Width() - tmp) /2;
frameRight.bottom = frameRight.top + tmp;
frameRight.right = frameRight.left + tmp;
frame.top = f_timeedit->Frame().bottom; fClock = new TAnalogClock(frameRight, "analog clock", B_FOLLOW_NONE, B_WILL_DRAW);
frame.bottom = bounds.bottom -(text_height *3); AddChild(fClock);
frame.InsetBy((frame.Width() - kClockFaceWidth + 1)/2.0, (frame.Height() - kClockFaceHeight + 1)/2.0);
f_clock = new TAnalogClock(frame, "analog clock",
B_FOLLOW_NONE, B_WILL_DRAW);
AddChild(f_clock);
// clock radio buttons // clock radio buttons
frame = bounds.InsetByCopy(6, 10); frameRight.left = left;
frame.top = f_clock->Frame().bottom +12; frameRight.top = fClock->Frame().bottom + 10;
frame.bottom = frame.top +text_height +2; text = new BStringView(frameRight, "clockis", "Clock set to:");
BString label = "Clock set to:";
float width = be_plain_font->StringWidth(label.String());
frame.right = frame.left +width;
BStringView *text = new BStringView(frame, "clockis", "Clock set to:");
AddChild(text); AddChild(text);
text->ResizeToPreferred();
frame.OffsetBy(frame.Width() +9, -1);
frame.right = bounds.right-2; frameRight.left += 20.0f;
frameRight.top = text->Frame().bottom + 5;
f_local = new BRadioButton(frame, "local", "Local time", new BMessage(H_RTC_CHANGE));
AddChild(f_local); fLocalTime = new BRadioButton(frameRight, "local", "Local time", new BMessage(H_RTC_CHANGE));
AddChild(fLocalTime);
frame.OffsetBy(0, text_height +4); fLocalTime->ResizeToPreferred();
f_gmt = new BRadioButton(frame, "gmt", "GMT", new BMessage(H_RTC_CHANGE));
AddChild(f_gmt); frameRight.left = fLocalTime->Frame().right +10.0f;
if (f_islocal) fGmtTime = new BRadioButton(frameRight, "gmt", "GMT", new BMessage(H_RTC_CHANGE));
f_local->SetValue(1); AddChild(fGmtTime);
fGmtTime->ResizeToPreferred();
if (fIsLocalTime)
fLocalTime->SetValue(B_CONTROL_ON);
else else
f_gmt->SetValue(1); fGmtTime->SetValue(B_CONTROL_ON);
} }
@@ -145,8 +178,8 @@ TSettingsView::Draw(BRect /*updateRect*/)
rgb_color dark = tint_color(viewcolor, B_DARKEN_4_TINT); rgb_color dark = tint_color(viewcolor, B_DARKEN_4_TINT);
rgb_color light = tint_color(viewcolor, B_LIGHTEN_MAX_TINT); rgb_color light = tint_color(viewcolor, B_LIGHTEN_MAX_TINT);
BPoint start(bounds.Width()/2.0 +2.0, bounds.top +1); BPoint start(bounds.Width() / 2.0f +2.0f, bounds.top +1.0f);
BPoint end(bounds.Width()/2.0 +2.0, bounds.bottom -1); BPoint end(bounds.Width() / 2.0 +2.0f, bounds.bottom -1.0f);
BeginLineArray(2); BeginLineArray(2);
AddLine(start, end, dark); AddLine(start, end, dark);
@@ -155,77 +188,80 @@ TSettingsView::Draw(BRect /*updateRect*/)
AddLine(start, end, light); AddLine(start, end, light);
EndLineArray(); EndLineArray();
f_timeedit->Draw(bounds); fTimeEdit->Draw(bounds);
f_dateedit->Draw(bounds); fDateEdit->Draw(bounds);
} }
bool bool
TSettingsView::GMTime() TSettingsView::GMTime()
{ {
return f_gmt->Value() == 1; return fGmtTime->Value() == B_CONTROL_ON;
}
void
TSettingsView::SetTimeZone(const char *timezone)
{
fTimeZone->SetText(timezone);
fTimeZone->ResizeToPreferred();
} }
void void
TSettingsView::UpdateDateTime(BMessage *message) TSettingsView::UpdateDateTime(BMessage *message)
{ {
int32 month, day, year, hour, minute, second; int32 day;
int32 month;
int32 year;
if (message->FindInt32("month", &month) == B_OK if (message->FindInt32("month", &month) == B_OK
&& message->FindInt32("day", &day) == B_OK && message->FindInt32("day", &day) == B_OK
&& message->FindInt32("year", &year) == B_OK) && message->FindInt32("year", &year) == B_OK)
{ {
f_dateedit->SetTo(year, month, day); fDateEdit->SetTo(year, month, day);
f_calendar->SetTo(year, month, day); fCalendar->SetTo(year, month, day);
} }
int32 hour;
int32 minute;
int32 second;
if (message->FindInt32("hour", &hour) == B_OK if (message->FindInt32("hour", &hour) == B_OK
&& message->FindInt32("minute", &minute) == B_OK && message->FindInt32("minute", &minute) == B_OK
&& message->FindInt32("second", &second) == B_OK) && message->FindInt32("second", &second) == B_OK)
{ {
f_timeedit->SetTo(hour, minute, second); fTimeEdit->SetTo(hour, minute, second);
f_clock->SetTo(hour, minute, second); fClock->SetTo(hour, minute, second);
} }
} }
void void
TSettingsView::ReadFiles() TSettingsView::ReadRTCSettings()
{ {
// do all file reading here
// read RTC_time_settings
BPath path; BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) { if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) {
return; // NO USER SETTINGS DIRECTORY!!! return; // NO USER SETTINGS DIRECTORY!!!
} }
path.Append("RTC_time_settings"); path.Append("RTC_time_settings");
BEntry entry(path.Path());
BFile file; BFile file;
BEntry entry(path.Path());
if (entry.Exists()) { if (entry.Exists()) {
//read file
file.SetTo(&entry, B_READ_ONLY); file.SetTo(&entry, B_READ_ONLY);
status_t err = file.InitCheck(); if (file.InitCheck() == B_OK) {
if (err == B_OK) {
char buff[6]; char buff[6];
file.Read(buff, 6); file.Read(buff, 6);
BString text; BString text(buff);
text << buff;
if (text.Compare("local\n", 5) == 0) if (text.Compare("local\n", 5) == 0)
f_islocal = true; fIsLocalTime = true;
else else
f_islocal = false; fIsLocalTime = false;
} }
} else { } else {
// create set to local // create set to local
f_islocal = true; fIsLocalTime = true;
file.SetTo(&entry, B_CREATE_FILE|B_READ_WRITE); file.SetTo(&entry, B_CREATE_FILE | B_READ_WRITE);
file.Write("local\n", 6); file.Write("local\n", 6);
} }
// done reading RTC_time_settings
} }
+40 -30
View File
@@ -1,43 +1,53 @@
/* /*
* Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
SettingsView.h * Distributed under the terms of the MIT License.
*/ *
* Authors:
* <unkown>
* Julun <[email protected]>
*/
#ifndef SETTINGS_VIEW_H #ifndef SETTINGS_VIEW_H
#define SETTINGS_VIEW_H #define SETTINGS_VIEW_H
#include <RadioButton.h>
#include <View.h> #include <View.h>
#include "AnalogClock.h"
#include "CalendarView.h"
#include "DateTimeEdit.h"
class TSettingsView:public BView { class TDateEdit;
class TTimeEdit;
class TCalendarView;
class TAnalogClock;
class BRadioButton;
class BStringView;
class TSettingsView : public BView {
public: public:
TSettingsView(BRect frame); TSettingsView(BRect frame);
virtual ~TSettingsView(); virtual ~TSettingsView();
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void Draw(BRect updaterect); virtual void Draw(BRect updaterect);
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
virtual void GetPreferredSize(float *width, float *height);
void ChangeRTCSetting();
void ChangeRTCSetting();
bool GMTime(); bool GMTime();
void SetTimeZone(const char *timezone);
private: private:
void InitView(); void InitView();
void ReadFiles(); // reads RTC_time_settings void ReadRTCSettings();
void UpdateDateTime(BMessage *message); void UpdateDateTime(BMessage *message);
BRect f_temp; BRadioButton *fLocalTime;
BRadioButton *f_local; BRadioButton *fGmtTime;
BRadioButton *f_gmt; TDateEdit *fDateEdit;
TDateEdit *f_dateedit; TTimeEdit *fTimeEdit;
TTimeEdit *f_timeedit; TCalendarView *fCalendar;
TCalendarView *f_calendar; TAnalogClock *fClock;
TAnalogClock *f_clock; bool fIsLocalTime;
bool f_islocal; // local or gmt? BStringView *fTimeZone;
}; };
#endif #endif
+1
View File
@@ -39,3 +39,4 @@ const uint32 H_USER_CHANGE = 'obUC';
const uint32 H_RTC_CHANGE = 'obRC'; const uint32 H_RTC_CHANGE = 'obRC';
#endif //TIME_MESSAGES_H #endif //TIME_MESSAGES_H
+21 -8
View File
@@ -1,7 +1,10 @@
/* /*
* TTimeWindow.cpp * Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
* Time mccall@@digitalparadise.co.uk * Distributed under the terms of the MIT License.
* *
* Authors:
* mccall@@digitalparadise.co.uk
* Julun <[email protected]>
*/ */
#include <Application.h> #include <Application.h>
@@ -19,7 +22,7 @@
#include "TimeSettings.h" #include "TimeSettings.h"
#include "ZoneView.h" #include "ZoneView.h"
#define TIME_WINDOW_RIGHT 361 //332 #define TIME_WINDOW_RIGHT 400 //332
#define TIME_WINDOW_BOTTOM 227 //208 #define TIME_WINDOW_BOTTOM 227 //208
@@ -29,10 +32,13 @@ TTimeWindow::TTimeWindow()
{ {
MoveTo(dynamic_cast<TimeApplication *>(be_app)->WindowCorner()); MoveTo(dynamic_cast<TimeApplication *>(be_app)->WindowCorner());
BScreen screen; BRect frame = Frame();
BRect bounds = Bounds();
BRect screenFrame = BScreen().Frame();
// Code to make sure that the window doesn't get drawn off screen... // Code to make sure that the window doesn't get drawn off screen...
if (!(screen.Frame().right >= Frame().right && screen.Frame().bottom >= Frame().bottom)) if (!(screenFrame.right >= frame.right && screenFrame.bottom >= frame.bottom))
MoveTo((screen.Frame().right-Bounds().right)*.5,(screen.Frame().bottom-Bounds().bottom)*.5); MoveTo((screenFrame.right - bounds.right) * 0.5f,
(screenFrame.bottom - bounds.bottom) * 0.5f);
InitWindow(); InitWindow();
SetPulseRate(500000); SetPulseRate(500000);
@@ -99,7 +105,7 @@ TTimeWindow::InitWindow()
fTimeZones = new TZoneView(bounds); fTimeZones = new TZoneView(bounds);
if (fBaseView->StartWatchingAll(fTimeZones) != B_OK) if (fBaseView->StartWatchingAll(fTimeZones) != B_OK)
printf("TimeZones->StartWatchingAll(TimeZone) failed!!!\n"); printf("TimeZones->StartWatchingAll(TimeZone) failed!!!\n");
// add tabs // add tabs
BTab *tab = new BTab(); BTab *tab = new BTab();
tabview->AddTab(fTimeSettings, tab); tabview->AddTab(fTimeSettings, tab);
@@ -110,4 +116,11 @@ TTimeWindow::InitWindow()
tab->SetLabel("Time Zone"); tab->SetLabel("Time Zone");
fBaseView->AddChild(tabview); fBaseView->AddChild(tabview);
float width;
float height;
fTimeSettings->GetPreferredSize(&width, &height);
// width/ height from settingsview + all InsetBy etc..
ResizeTo(width +10, height + tabview->TabHeight() +25);
} }
+4
View File
@@ -1,3 +1,7 @@
/*
* Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef TIME_WINDOW_H #ifndef TIME_WINDOW_H
#define TIME_WINDOW_H #define TIME_WINDOW_H
+23 -8
View File
@@ -1,12 +1,20 @@
/* /*
ZoneView.cpp * Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
by Mike Berg (inseculous) * Distributed under the terms of the MIT License.
*
Status: mimics original Time Zone tab of Time Pref App * Authors:
Exceptions: doesn't calc "Time in" time. * Mike Berg (inseculous)
Issues: After experimenting with both Time Prefs, it seems the original doesn't * Julun <[email protected]>
use the link file in the users settings file to get the current Timezone. */
Need to find the call it uses to get its inital info so I can get exact duplication. /*
Exceptions:
doesn't calc "Time in" time.
Issues:
After experimenting with both Time Prefs, it seems the original
doesn't use the link file in the users settings file to get the
current Timezone. Need to find the call it uses to get its
inital info so I can get exact duplication.
*/ */
#include <Button.h> #include <Button.h>
@@ -144,6 +152,13 @@ TZoneView::MessageReceived(BMessage *message)
} }
const char*
TZoneView::TimeZone()
{
return f_current->Text();
}
void void
TZoneView::UpdateDateTime(BMessage *message) TZoneView::UpdateDateTime(BMessage *message)
{ {
+10 -3
View File
@@ -1,7 +1,11 @@
/* /*
ZoneView.h * Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
Header file for the base class of the Time Zone tab in Time Pref App. * Distributed under the terms of the MIT License.
*/ *
* Authors:
* Mike Berg (inseculous)
* Julun <[email protected]>
*/
#ifndef ZONE_VIEW_H #ifndef ZONE_VIEW_H
#define ZONE_VIEW_H #define ZONE_VIEW_H
@@ -37,6 +41,9 @@ class TZoneView: public BView {
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void AllAttached(); virtual void AllAttached();
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
const char* TimeZone();
protected: protected:
void UpdateDateTime(BMessage *message); void UpdateDateTime(BMessage *message);
void ChangeRegion(BMessage *); void ChangeRegion(BMessage *);