00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <TROOT.h>
00024 #include <TSystem.h>
00025 #include "Aclock.h"
00026
00027
00028 ClassImp(Aclock)
00029
00030
00031 Float_t MinuteHand::fgMinuteHandX[] = { -0.05, 0, 0.05 };
00032 Float_t MinuteHand::fgMinuteHandY[] = { -0.04, 0.625, -0.04 };
00033
00034 Float_t HourHand::fgHourHandX[] = { -0.05, 0, 0.05 };
00035 Float_t HourHand::fgHourHandY[] = { -0.04, 0.4, -0.04 };
00036
00037 Float_t SecondHand::fgSecondHandX[] = { 0., 0.035, 0., -0.035 };
00038 Float_t SecondHand::fgSecondHandY[] = { 0.78, 0.73, 0.68, 0.73 };
00039
00040 TDatime *ClockHand::fgTime = new TDatime;
00041
00042
00043 TPolygon::TPolygon(Int_t n, Float_t *x, Float_t *y) : TPolyLine(n+1,x,y)
00044 {
00045
00046
00047 if (!TVirtualPad::Pad()) { Error("Constructor","Create TPad first!"); return; }
00048
00049 fPad = (TPad*)TVirtualPad::Pad();
00050 fX[n] = x[0];
00051 fY[n] = y[0];
00052 Draw();
00053 }
00054
00055 void TPolygon::Paint(Option_t *)
00056 {
00057
00058
00059 TAttLine::Modify();
00060 TAttFill::Modify();
00061 fPad->PaintFillArea(fN-1, fX, fY);
00062 fPad->PaintPolyLine(fN, fX, fY, "");
00063 }
00064
00065
00066
00067 ClockHand::ClockHand(Int_t n, Float_t *x, Float_t *y) : TPolygon(n,x,y)
00068 {
00069
00070
00071 fPrevTimeValue = 0;
00072 fX0 = new Float_t[GetN()];
00073 fY0 = new Float_t[GetN()];
00074
00075 for (int i = 0; i < GetN(); i++) {
00076 fX0[i] = fX[i];
00077 fY0[i] = fY[i];
00078 }
00079 SetFillColor(9);
00080 }
00081
00082 void ClockHand::Update()
00083 {
00084
00085
00086 if (!IsModified()) return;
00087
00088 fPrevTimeValue = GetTimeValue();
00089 Move(GetHandAngle());
00090 }
00091
00092 void ClockHand::Move(Float_t clock_angle)
00093 {
00094
00095
00096 Int_t n = GetN();
00097
00098
00099 static ClockPoints *points = new ClockPoints();
00100
00101 Float_t wh = (Float_t)fPad->XtoPixel(fPad->GetX2());
00102 Float_t hh = (Float_t)fPad->YtoPixel(fPad->GetY1());
00103
00104 for (int i = 0; i < n; i++) {
00105 points->SetXY(fX0[i],fY0[i]);
00106 points->Rotate(clock_angle);
00107
00108 if (wh < hh) points->Scale(0.5,0.5*wh/hh);
00109 else points->Scale(0.5*hh/wh,0.5);
00110
00111 points->Shift(0.5,0.5);
00112 fX[i] = points->GetX();
00113 fY[i] = points->GetY();
00114 }
00115 }
00116
00117
00118 Aclock::Aclock(Int_t csize) : TTimer(500, kTRUE)
00119 {
00120
00121
00122 fPad = new TCanvas("Aclock:canvas","xclock",-csize,csize);
00123
00124 fPad->SetFillColor(14);
00125
00126 fMinuteHand = new MinuteHand();
00127 fSecondHand = new SecondHand();
00128 fHourHand = new HourHand();
00129
00130 SetBit(kCanDelete);
00131 Draw();
00132 Animate();
00133 gSystem->AddTimer(this);
00134 }
00135
00136 Aclock::~Aclock()
00137 {
00138
00139
00140 delete fMinuteHand;
00141 delete fSecondHand;
00142 delete fHourHand;
00143 }
00144
00145 void Aclock::Paint(Option_t *)
00146 {
00147
00148
00149 static ClockPoints *point1 = new ClockPoints();
00150 static ClockPoints *point2 = new ClockPoints();
00151
00152 Float_t wh = (Float_t)fPad->XtoPixel(fPad->GetX2());
00153 Float_t hh = (Float_t)fPad->YtoPixel(fPad->GetY1());
00154
00155 for (int i = 0; i < 60; i++ ) {
00156 point1->SetXY(0.,0.9);
00157
00158 if (!(i%5)) point2->SetXY(0.,0.8);
00159 else point2->SetXY(0.,0.87);
00160
00161 Float_t angle = 6.*i;
00162 point1->Rotate(angle);
00163 point2->Rotate(angle);
00164
00165 if (wh < hh) {
00166 point1->Scale(0.5,0.5*wh/hh);
00167 point2->Scale(0.5,0.5*wh/hh);
00168 } else {
00169 point1->Scale(0.5*hh/wh,0.5);
00170 point2->Scale(0.5*hh/wh,0.5);
00171 }
00172
00173 point1->Shift(0.5,0.5);
00174 point2->Shift(0.5,0.5);
00175
00176 fPad->PaintLine(point1->GetX(),point1->GetY(),point2->GetX(),point2->GetY());
00177 }
00178 }
00179
00180 void Aclock::Animate()
00181 {
00182
00183
00184 if (!fSecondHand->IsModified()) return;
00185
00186 fHourHand->Update();
00187 fMinuteHand->Update();
00188 fSecondHand->Update();
00189 fPad->Modified();
00190 fPad->Update();
00191 }
00192
00193 Bool_t Aclock::Notify()
00194 {
00195
00196
00197 Animate();
00198 TTimer::Reset();
00199 return kFALSE;
00200 }