Sorry forgot to upload this one.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8249 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
94f1d71f18
commit
ae2555ef40
@ -1,164 +1,213 @@
|
|||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
#include <Screen.h>
|
|
||||||
#include <String.h>
|
|
||||||
#include <SupportDefs.h>
|
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "AnalogClock.h"
|
#include "AnalogClock.h"
|
||||||
#include "Bitmaps.h"
|
#include "Bitmaps.h"
|
||||||
#include "TimeMessages.h"
|
#include "TimeMessages.h"
|
||||||
|
|
||||||
TOffscreen::TOffscreen(BRect frame, char *name)
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
TOffscreen::TOffscreen(BRect frame, const char *name)
|
||||||
: BView(frame, name, B_NOT_RESIZABLE, B_WILL_DRAW)
|
: BView(frame, name, B_NOT_RESIZABLE, B_WILL_DRAW)
|
||||||
{
|
{
|
||||||
f_bitmap = new BBitmap(BRect(0, 0, kClockFaceWidth, kClockFaceHeight), kClockFaceColorSpace);
|
f_bitmap = new BBitmap(kClockRect, kClockFaceColorSpace);
|
||||||
f_bitmap->SetBits(kClockFaceBits, (kClockFaceWidth +1) *(kClockFaceHeight +1), 0, kClockFaceColorSpace);
|
f_bitmap->SetBits(kClockFaceBits, (kClockFaceWidth) *(kClockFaceHeight +3), 0, kClockFaceColorSpace);
|
||||||
|
|
||||||
ReplaceTransparentColor(f_bitmap, ui_color(B_PANEL_BACKGROUND_COLOR));
|
ReplaceTransparentColor(f_bitmap, ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
|
f_centerbmp = new BBitmap(kCenterRect, kCenterColorSpace);
|
||||||
|
f_centerbmp->SetBits(kCenterBits, (kCenterWidth) *(kCenterHeight +1), 0, kCenterColorSpace);
|
||||||
|
|
||||||
|
f_capbmp = new BBitmap(kCapRect, kCapColorSpace);
|
||||||
|
f_capbmp->SetBits(kCapBits, (kCapWidth +1) *(kCapHeight +1) +1, 0, kCapColorSpace);
|
||||||
|
|
||||||
|
f_center = BPoint(42, 42);
|
||||||
|
|
||||||
float counter;
|
float counter;
|
||||||
short index = 0;
|
short index;
|
||||||
float x,y;
|
float x, y, mRadius, hRadius;
|
||||||
float mRadius = 30;
|
|
||||||
float hRadius = 20;
|
mRadius = f_center.x -12;
|
||||||
f_Offset = 41;
|
hRadius = mRadius -10;
|
||||||
|
index = 0;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Generate minutes points array
|
// Generate minutes/hours 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);
|
||||||
x += f_Offset;
|
x += f_center.x;
|
||||||
y = mRadius * sin(((360 - counter)/180.0) * 3.1415);
|
y = mRadius * sin(((360 - counter)/180.0) * 3.1415);
|
||||||
y += f_Offset;
|
y += f_center.x;
|
||||||
f_MinutePoints[index].Set(x,y);
|
f_MinutePoints[index].Set(x,y);
|
||||||
x = hRadius * cos(((360 - counter)/180.0) * 3.1415);
|
x = hRadius * cos(((360 - counter)/180.0) * 3.1415);
|
||||||
x += f_Offset;
|
x += f_center.x;
|
||||||
y = hRadius * sin(((360 - counter)/180.0) * 3.1415);
|
y = hRadius * sin(((360 - counter)/180.0) * 3.1415);
|
||||||
y += f_Offset;
|
y += f_center.x;
|
||||||
f_HourPoints[index].Set(x,y);
|
f_HourPoints[index].Set(x,y);
|
||||||
}
|
}
|
||||||
for (counter = 354; counter > 90; counter -= 6,index++) {
|
for (counter = 354; counter > 90; counter -= 6,index++) {
|
||||||
x = mRadius * cos(((360 - counter)/180.0) * 3.1415);
|
x = mRadius * cos(((360 - counter)/180.0) * 3.1415);
|
||||||
x += f_Offset;
|
x += f_center.x;
|
||||||
y = mRadius * sin(((360 - counter)/180.0) * 3.1415);
|
y = mRadius * sin(((360 - counter)/180.0) * 3.1415);
|
||||||
y += f_Offset;
|
y += f_center.x;
|
||||||
f_MinutePoints[index].Set(x,y);
|
f_MinutePoints[index].Set(x,y);
|
||||||
x = hRadius * cos(((360 - counter)/180.0) * 3.1415);
|
x = hRadius * cos(((360 - counter)/180.0) * 3.1415);
|
||||||
x += f_Offset;
|
x += f_center.x;
|
||||||
y = hRadius * sin(((360 - counter)/180.0) * 3.1415);
|
y = hRadius * sin(((360 - counter)/180.0) * 3.1415);
|
||||||
y += f_Offset;
|
y += f_center.x;
|
||||||
f_HourPoints[index].Set(x,y);
|
f_HourPoints[index].Set(x,y);
|
||||||
}
|
}
|
||||||
BRect bounds(Bounds());
|
|
||||||
f_center = BPoint(bounds.Width()/2.0, bounds.Height()/2.0);
|
|
||||||
f_offset = BPoint((kClockFaceWidth-1)/2, (kClockFaceHeight-1)/2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TOffscreen::~TOffscreen()
|
TOffscreen::~TOffscreen()
|
||||||
{
|
{
|
||||||
|
delete f_bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
TOffscreen::AttachedToWindow()
|
|
||||||
{
|
|
||||||
SetViewColor(200, 20, 20);
|
|
||||||
SetFontSize(18);
|
|
||||||
SetFont(be_plain_font);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TOffscreen::DrawX()
|
TOffscreen::DrawX()
|
||||||
{
|
{
|
||||||
short hours;
|
if (Window()->Lock()) {
|
||||||
ASSERT(Window());
|
|
||||||
if (Window()->Lock())
|
|
||||||
{
|
|
||||||
DrawBitmap(f_bitmap, BPoint(0, 0));
|
|
||||||
|
|
||||||
SetHighColor(0, 0, 0);
|
// draw clockface
|
||||||
hours = f_Hours;
|
SetDrawingMode(B_OP_COPY);
|
||||||
|
DrawBitmap(f_bitmap, BPoint(0, 0));
|
||||||
|
|
||||||
|
SetHighColor(0, 0, 0, 255);
|
||||||
|
|
||||||
|
short hours = f_Hours;
|
||||||
if (hours>= 12)
|
if (hours>= 12)
|
||||||
hours -= 12;
|
hours -= 12;
|
||||||
|
|
||||||
hours *= 5;
|
hours *= 5;
|
||||||
hours += (f_Minutes/12);
|
hours += (f_Minutes / 12);
|
||||||
|
|
||||||
|
// draw center hub
|
||||||
|
SetDrawingMode(B_OP_OVER);
|
||||||
|
DrawBitmap(f_centerbmp, f_center -BPoint(kCenterWidth/2.0, kCenterHeight/2.0));
|
||||||
|
|
||||||
|
// draw hands
|
||||||
StrokeLine(f_center, f_HourPoints[hours]);
|
StrokeLine(f_center, f_HourPoints[hours]);
|
||||||
SetDrawingMode(B_OP_COPY);
|
|
||||||
StrokeLine(f_center, f_MinutePoints[f_Minutes]);
|
StrokeLine(f_center, f_MinutePoints[f_Minutes]);
|
||||||
SetHighColor(tint_color(HighColor(), B_LIGHTEN_1_TINT));
|
SetHighColor(tint_color(HighColor(), B_LIGHTEN_1_TINT));
|
||||||
StrokeLine(f_center, f_MinutePoints[f_Seconds]);
|
StrokeLine(f_center, f_MinutePoints[f_Seconds]);
|
||||||
Sync();
|
|
||||||
|
// draw center cap
|
||||||
|
DrawBitmap(f_capbmp, f_center -BPoint(kCapWidth/2.0, kCapHeight/2.0));
|
||||||
|
|
||||||
|
Sync();
|
||||||
Window()->Unlock();
|
Window()->Unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BPoint
|
|
||||||
TOffscreen::Position()
|
|
||||||
|
/*=====> TAnalogClock <=====*/
|
||||||
|
|
||||||
|
TAnalogClock::TAnalogClock(BRect frame, const char *name, uint32 resizingmode, uint32 flags)
|
||||||
|
: BView(frame, name, resizingmode, flags|B_DRAW_ON_CHILDREN)
|
||||||
{
|
{
|
||||||
return (f_center -f_offset);
|
InitView(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TAnalogClock::TAnalogClock(BRect frame, const char *name, uint32 resizingmode, uint32 flags)
|
TAnalogClock::~TAnalogClock()
|
||||||
: BView(frame, name, resizingmode, flags)
|
{
|
||||||
, f_bitmap(NULL)
|
delete f_bitmap;
|
||||||
, f_offscreen(NULL)
|
}
|
||||||
{
|
|
||||||
BRect bounds(0, 0, kClockFaceWidth -1, kClockFaceHeight -2);
|
|
||||||
f_offscreen = new TOffscreen(bounds, "offscreen");
|
void
|
||||||
f_bitmap = new BBitmap(bounds, B_COLOR_8_BIT, TRUE);
|
TAnalogClock::InitView(BRect rect)
|
||||||
|
{
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
f_offscreen = new TOffscreen(kClockRect, "offscreen");
|
||||||
|
f_bitmap = new BBitmap(kClockRect, B_COLOR_8_BIT, true);
|
||||||
f_bitmap->Lock();
|
f_bitmap->Lock();
|
||||||
f_bitmap->AddChild(f_offscreen);
|
f_bitmap->AddChild(f_offscreen);
|
||||||
f_bitmap->Unlock();
|
f_bitmap->Unlock();
|
||||||
f_offscreen->DrawX();
|
f_offscreen->DrawX();
|
||||||
|
#endif
|
||||||
|
|
||||||
BRect rect(Bounds());
|
// offscreen clock is kClockFaceWidth by kClockFaceHeight
|
||||||
float x = (rect.Width()/2.0) -(bounds.Width()/2.0) -2;
|
// which might be smaller then TAnalogClock frame so "center" it.
|
||||||
float y = (rect.Height()/2.0) -(bounds.Height()/2.0) -1;
|
f_drawpt = BPoint(rect.Width()/2.0 -(kClockFaceWidth/2.0),
|
||||||
|
rect.Height()/2.0 -(kClockFaceHeight/2.0));
|
||||||
f_drawpt.Set(x, y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TAnalogClock::~TAnalogClock()
|
|
||||||
{
|
|
||||||
delete f_bitmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TAnalogClock::AttachedToWindow()
|
TAnalogClock::AttachedToWindow()
|
||||||
{
|
{
|
||||||
if (Parent())
|
if (Parent()) {
|
||||||
SetViewColor(Parent()->ViewColor());
|
SetViewColor(Parent()->ViewColor());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TAnalogClock::MessageReceived(BMessage *message)
|
||||||
|
{
|
||||||
|
int32 change;
|
||||||
|
switch(message->what) {
|
||||||
|
case B_OBSERVER_NOTICE_CHANGE:
|
||||||
|
message->FindInt32(B_OBSERVE_WHAT_CHANGE, &change);
|
||||||
|
switch (change) {
|
||||||
|
case OB_TM_CHANGED:
|
||||||
|
{
|
||||||
|
int32 hour = 0;
|
||||||
|
int32 minute = 0;
|
||||||
|
int32 second = 0;
|
||||||
|
if (message->FindInt32("hour", &hour) == B_OK
|
||||||
|
&& message->FindInt32("minute", &minute) == B_OK
|
||||||
|
&& message->FindInt32("second", &second) == B_OK)
|
||||||
|
SetTo(hour, minute, second);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
BView::MessageReceived(message);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
BView::MessageReceived(message);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TAnalogClock::Draw(BRect updaterect)
|
TAnalogClock::Draw(BRect updaterect)
|
||||||
{
|
{
|
||||||
time_t current;
|
|
||||||
ASSERT(f_bitmap);
|
|
||||||
ASSERT(f_offscreen);
|
ASSERT(f_offscreen);
|
||||||
|
ASSERT(f_bitmap);
|
||||||
bool locked = f_bitmap->Lock();
|
SetHighColor(0, 100, 10);
|
||||||
ASSERT(locked);
|
bool b = f_bitmap->Lock();
|
||||||
|
ASSERT(b);
|
||||||
f_offscreen->DrawX();
|
f_offscreen->DrawX();
|
||||||
DrawBitmap(f_bitmap, f_drawpt);
|
DrawBitmap(f_bitmap, f_drawpt);
|
||||||
f_bitmap->Unlock();
|
f_bitmap->Unlock();
|
||||||
|
|
||||||
current = time(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TAnalogClock::Update(tm *atm)
|
TAnalogClock::SetTo(int32 hour, int32 minute, int32 second)
|
||||||
{
|
{
|
||||||
if ((atm->tm_sec != f_offscreen->f_Seconds)
|
if (f_offscreen->f_Seconds != second
|
||||||
|| (atm->tm_min != f_offscreen->f_Minutes))
|
|| f_offscreen->f_Minutes != minute) {
|
||||||
{
|
f_offscreen->f_Hours = hour;
|
||||||
f_offscreen->f_Hours = atm->tm_hour;
|
f_offscreen->f_Minutes = minute;
|
||||||
f_offscreen->f_Minutes = atm->tm_min;
|
f_offscreen->f_Seconds = second;
|
||||||
f_offscreen->f_Seconds = atm->tm_sec;
|
|
||||||
Draw(Bounds());
|
Draw(Bounds());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user