Clock: TOffscreenView: small cleanup
This commit is contained in:
parent
301f4b463a
commit
2a24174d9b
@ -33,57 +33,43 @@ TOffscreenView::TOffscreenView(BRect frame, const char *name, short mRadius,
|
|||||||
fShowSeconds(show)
|
fShowSeconds(show)
|
||||||
{
|
{
|
||||||
status_t error;
|
status_t error;
|
||||||
#ifdef __HAIKU__
|
|
||||||
BResources rsrcs;
|
BResources rsrcs;
|
||||||
error = rsrcs.SetToImage(&&dummy_label);
|
error = rsrcs.SetToImage(&&dummy_label);
|
||||||
dummy_label:
|
dummy_label:
|
||||||
if (error == B_OK) {
|
if (error == B_OK) {
|
||||||
{
|
for (short i = 0; i <= 8; i++)
|
||||||
#else
|
fClockFace[i] = NULL;
|
||||||
// Note: Since we can be run as replicant, we get our
|
|
||||||
// resources this way, not via be_app->AppResources().
|
|
||||||
entry_ref ref;
|
|
||||||
error = be_roster->FindApp(kAppSignature, &ref);
|
|
||||||
if (error == B_NO_ERROR) {
|
|
||||||
BFile file(&ref, O_RDONLY);
|
|
||||||
error = file.InitCheck();
|
|
||||||
if (error == B_NO_ERROR) {
|
|
||||||
BResources rsrcs(&file);
|
|
||||||
#endif
|
|
||||||
for (short i = 0; i <= 8; i++)
|
|
||||||
fClockFace[i] = NULL;
|
|
||||||
|
|
||||||
size_t len;
|
size_t len;
|
||||||
void *picH;
|
void *picH;
|
||||||
BRect theRect(0, 0, 82, 82);
|
BRect theRect(0, 0, 82, 82);
|
||||||
for (short loop = 0; loop <= 8; loop++) {
|
for (short loop = 0; loop <= 8; loop++) {
|
||||||
if ((picH = rsrcs.FindResource('PICT', loop + 4, &len))) {
|
if ((picH = rsrcs.FindResource('PICT', loop + 4, &len))) {
|
||||||
fClockFace[loop] = new BBitmap(theRect, B_CMAP8);
|
fClockFace[loop] = new BBitmap(theRect, B_CMAP8);
|
||||||
fClockFace[loop]->SetBits(picH, len, 0, B_CMAP8);
|
fClockFace[loop]->SetBits(picH, len, 0, B_CMAP8);
|
||||||
free(picH);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
theRect.Set(0,0,15,15);
|
|
||||||
if ((picH = rsrcs.FindResource(B_MINI_ICON_TYPE, "center", &len))) {
|
|
||||||
fCenter = new BBitmap(theRect, B_CMAP8);
|
|
||||||
fCenter->SetBits(picH, len, 0, B_CMAP8);
|
|
||||||
free(picH);
|
|
||||||
}
|
|
||||||
|
|
||||||
theRect.Set(0,0,2,2);
|
|
||||||
if ((picH = rsrcs.FindResource('PICT', 13, &len))) {
|
|
||||||
fInner = new BBitmap(theRect, B_CMAP8);
|
|
||||||
fInner->SetBits(picH, len, 0, B_CMAP8);
|
|
||||||
free(picH);
|
free(picH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
theRect.Set(0,0,15,15);
|
||||||
|
if ((picH = rsrcs.FindResource(B_MINI_ICON_TYPE, "center", &len))) {
|
||||||
|
fCenter = new BBitmap(theRect, B_CMAP8);
|
||||||
|
fCenter->SetBits(picH, len, 0, B_CMAP8);
|
||||||
|
free(picH);
|
||||||
|
}
|
||||||
|
|
||||||
|
theRect.Set(0,0,2,2);
|
||||||
|
if ((picH = rsrcs.FindResource('PICT', 13, &len))) {
|
||||||
|
fInner = new BBitmap(theRect, B_CMAP8);
|
||||||
|
fInner->SetBits(picH, len, 0, B_CMAP8);
|
||||||
|
free(picH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
float x, y;
|
float x, y;
|
||||||
float counter;
|
float counter;
|
||||||
short index = 0;
|
short index = 0;
|
||||||
|
|
||||||
// Generate minutes points array
|
// Generate minutes points array
|
||||||
for (counter = 90; counter >= 0; counter -= 6, index++) {
|
for (counter = 90; counter >= 0; counter -= 6, index++) {
|
||||||
x = mRadius * cos(((360 - counter)/180.0) * 3.1415);
|
x = mRadius * cos(((360 - counter)/180.0) * 3.1415);
|
||||||
@ -115,7 +101,7 @@ dummy_label:
|
|||||||
|
|
||||||
void
|
void
|
||||||
TOffscreenView::NextFace()
|
TOffscreenView::NextFace()
|
||||||
{
|
{
|
||||||
fFace++;
|
fFace++;
|
||||||
if (fFace > 8)
|
if (fFace > 8)
|
||||||
fFace = 1;
|
fFace = 1;
|
||||||
@ -124,13 +110,13 @@ TOffscreenView::NextFace()
|
|||||||
|
|
||||||
void
|
void
|
||||||
TOffscreenView::DrawX()
|
TOffscreenView::DrawX()
|
||||||
{
|
{
|
||||||
ASSERT(Window());
|
ASSERT(Window());
|
||||||
|
|
||||||
if (Window()->Lock()) {
|
if (Window()->Lock()) {
|
||||||
if (fClockFace != NULL)
|
if (fClockFace != NULL)
|
||||||
DrawBitmap(fClockFace[fFace], BPoint(0, 0));
|
DrawBitmap(fClockFace[fFace], BPoint(0, 0));
|
||||||
|
|
||||||
//
|
//
|
||||||
// Draw hands
|
// Draw hands
|
||||||
//
|
//
|
||||||
@ -163,7 +149,7 @@ TOffscreenView::~TOffscreenView()
|
|||||||
for (int32 counter = 0; counter <= 8; counter++)
|
for (int32 counter = 0; counter <= 8; counter++)
|
||||||
delete fClockFace[counter];
|
delete fClockFace[counter];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
@ -194,7 +180,7 @@ TOnscreenView::InitObject(BRect rect, short mRadius, short hRadius,
|
|||||||
if (fOffscreen != NULL && fOffscreen->Lock()) {
|
if (fOffscreen != NULL && fOffscreen->Lock()) {
|
||||||
fOffscreen->AddChild(fOffscreenView);
|
fOffscreen->AddChild(fOffscreenView);
|
||||||
fOffscreen->Unlock();
|
fOffscreen->Unlock();
|
||||||
|
|
||||||
fOffscreenView->DrawX();
|
fOffscreenView->DrawX();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -226,19 +212,19 @@ TOnscreenView::Archive(BMessage *data, bool deep) const
|
|||||||
|
|
||||||
if (status == B_OK)
|
if (status == B_OK)
|
||||||
status = data->AddRect("bounds", Bounds());
|
status = data->AddRect("bounds", Bounds());
|
||||||
|
|
||||||
if (status == B_OK)
|
if (status == B_OK)
|
||||||
status = data->AddInt32("mRadius", fOffscreenView->fMinutesRadius);
|
status = data->AddInt32("mRadius", fOffscreenView->fMinutesRadius);
|
||||||
|
|
||||||
if (status == B_OK)
|
if (status == B_OK)
|
||||||
status = data->AddInt32("hRadius", fOffscreenView->fHoursRadius);
|
status = data->AddInt32("hRadius", fOffscreenView->fHoursRadius);
|
||||||
|
|
||||||
if (status == B_OK)
|
if (status == B_OK)
|
||||||
status = data->AddInt32("offset", fOffscreenView->fOffset);
|
status = data->AddInt32("offset", fOffscreenView->fOffset);
|
||||||
|
|
||||||
if (status == B_OK)
|
if (status == B_OK)
|
||||||
status = data->AddBool("seconds", fOffscreenView->fShowSeconds);
|
status = data->AddBool("seconds", fOffscreenView->fShowSeconds);
|
||||||
|
|
||||||
if (status == B_OK)
|
if (status == B_OK)
|
||||||
status = data->AddInt32("face", fOffscreenView->fFace);
|
status = data->AddInt32("face", fOffscreenView->fFace);
|
||||||
|
|
||||||
@ -263,11 +249,11 @@ TOnscreenView::Pulse()
|
|||||||
|
|
||||||
time_t current = time(0);
|
time_t current = time(0);
|
||||||
struct tm *loctime = localtime(¤t);
|
struct tm *loctime = localtime(¤t);
|
||||||
|
|
||||||
short hours = loctime->tm_hour;
|
short hours = loctime->tm_hour;
|
||||||
short minutes = loctime->tm_min;
|
short minutes = loctime->tm_min;
|
||||||
short seconds = loctime->tm_sec;
|
short seconds = loctime->tm_sec;
|
||||||
|
|
||||||
if ((fOffscreenView->fShowSeconds && (seconds != fOffscreenView->fSeconds))
|
if ((fOffscreenView->fShowSeconds && (seconds != fOffscreenView->fSeconds))
|
||||||
|| (minutes != fOffscreenView->fMinutes)) {
|
|| (minutes != fOffscreenView->fMinutes)) {
|
||||||
fOffscreenView->fHours = hours;
|
fOffscreenView->fHours = hours;
|
||||||
@ -335,7 +321,7 @@ TOnscreenView::MouseDown( BPoint point )
|
|||||||
BPoint cursor;
|
BPoint cursor;
|
||||||
uint32 buttons;
|
uint32 buttons;
|
||||||
BRect bounds = Bounds();
|
BRect bounds = Bounds();
|
||||||
|
|
||||||
GetMouse(&cursor,&buttons);
|
GetMouse(&cursor,&buttons);
|
||||||
if (buttons & B_SECONDARY_MOUSE_BUTTON) {
|
if (buttons & B_SECONDARY_MOUSE_BUTTON) {
|
||||||
fOffscreenView->fShowSeconds = !fOffscreenView->fShowSeconds;
|
fOffscreenView->fShowSeconds = !fOffscreenView->fShowSeconds;
|
||||||
|
Loading…
Reference in New Issue
Block a user