00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <TROOT.h>
00026 #include <TSystem.h>
00027 #include "Hello.h"
00028 #include "TList.h"
00029
00030 ClassImp(Hello)
00031
00032
00033 TChar::TChar(char ch, Coord_t x, Coord_t y) : TText(x, y, "")
00034 {
00035
00036
00037 SetTitle(Form("%c",ch));
00038 }
00039
00040 Float_t TChar::GetWidth()
00041 {
00042
00043
00044 UInt_t w,h;
00045
00046 if (!TVirtualPad::Pad()) return 0;
00047
00048 Float_t wh = (Float_t)gPad->XtoAbsPixel(gPad->GetX2());
00049 GetTextExtent(w, h, (char*)GetTitle());
00050 return w/wh;
00051 }
00052
00053
00054 Hello::Hello(const char *text) : TTimer(40, kTRUE)
00055 {
00056
00057
00058 TChar *ch;
00059 fI = 0;
00060 fList = new TList();
00061
00062 if (!TVirtualPad::Pad())
00063 fPad = new TCanvas("Hello:canvas","ROOT says Hello!",200,200,400,200);
00064 else
00065 fPad = (TPad*)gPad;
00066
00067 Connect(fPad, "Closed()", "TTimer", this, "TurnOff()");
00068
00069 while(text[fI]) {
00070 ch = new TChar(text[fI]);
00071 ch->SetTextFont(72);
00072 ch->SetTextSize(0.3);
00073 ch->Modify();
00074 fI++;
00075 fList->Add(ch);
00076 }
00077
00078 Draw();
00079 Paint();
00080 gSystem->AddTimer(this);
00081 }
00082
00083 Hello::~Hello()
00084 {
00085
00086
00087 fList->Delete();
00088 delete fList;
00089 }
00090
00091 void Hello::ExecuteEvent(Int_t event, Int_t, Int_t)
00092 {
00093
00094
00095 if (event == kButton1Up) {
00096 TTimer::Remove();
00097 }
00098 }
00099
00100 Float_t Hello::GetWidth()
00101 {
00102
00103
00104 TChar *ch;
00105 TIter nextin(fList);
00106 Float_t width = 0;
00107
00108 while ((ch = (TChar*)nextin()))
00109 width = width + ch->GetWidth();
00110
00111 return width;
00112 }
00113
00114 void Hello::Paint(Option_t *)
00115 {
00116
00117
00118 static int sin_tbl[16] = {
00119 0, 38, 71, 92, 100, 92, 71, 38, 0, -38, -71, -92, -100, -92, -71, -38
00120 };
00121
00122 TChar *ch;
00123 TIter nextin(fList);
00124 Float_t width = GetWidth();
00125
00126 Coord_t xnext = (1-width)/2.;
00127 Coord_t y;
00128 Coord_t y0 = 0.5;
00129
00130 fI = (fI+1) & 15;
00131 int i = 0;
00132
00133 while ((ch = (TChar*)nextin())) {
00134 int i16 = (fI+i) & 15;
00135 y = y0 - (Coord_t)sin_tbl[i16]/1500.;
00136 ch->SetY(y);
00137 ch->SetX(xnext);
00138 ch->SetTextColor(i16+200);
00139 i++;
00140 xnext = xnext + ch->GetWidth();
00141 ch->Paint("");
00142 }
00143 }
00144
00145 void Hello::Print(Option_t * opt) const
00146 {
00147 fList->Print(opt);
00148 }
00149
00150 void Hello::ls(Option_t *opt) const
00151 {
00152 fList->ls(opt);
00153 }
00154
00155 Bool_t Hello::Notify()
00156 {
00157
00158
00159 fPad->Modified();
00160 fPad->Update();
00161 TTimer::Reset();
00162 return kFALSE;
00163 }