/usr/share/doc/root/test/Hello.cxx is in root-system-doc 5.34.30-0ubuntu8.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | // @(#)root/test:$Id$
// Author: Valeriy Onuchin & Fons Rademakers 04/10/98
///////////////////////////////////////////////////////////////////
// Animated Text with cool wave effect.
//
// ROOT implementation of the hello world example borrowed
// from the Qt hello world example.
//
// To run this example do the following:
// $ root
// root [0] gSystem.Load("Hello")
// root [1] Hello h
// <enjoy>
// root [2] .q
//
// Other ROOT fun examples: Tetris, Aclock ...
//
// Begin_Html
// <img src="http://emcal06.rhic.bnl.gov/~onuchin/root/gif/hello_clock.gif">
// End_Html
//
///////////////////////////////////////////////////////////////////
#include <TROOT.h>
#include <TSystem.h>
#include "Hello.h"
#include "TList.h"
ClassImp(Hello)
TChar::TChar(char ch, Coord_t x, Coord_t y) : TText(x, y, "")
{
// Create single character text.
SetTitle(Form("%c",ch));
}
Float_t TChar::GetWidth()
{
// Return character width
UInt_t w,h;
if (!TVirtualPad::Pad()) return 0;
Float_t wh = (Float_t)gPad->XtoAbsPixel(gPad->GetX2());
GetTextExtent(w, h, (char*)GetTitle());
return w/wh;
}
Hello::Hello(const char *text) : TTimer(40, kTRUE)
{
// Hello constructor
TChar *ch;
fI = 0;
fList = new TList();
if (!TVirtualPad::Pad())
fPad = new TCanvas("Hello:canvas","ROOT says Hello!",200,200,400,200);
else
fPad = (TPad*)gPad;
Connect(fPad, "Closed()", "TTimer", this, "TurnOff()");
while(text[fI]) { // create list of characters
ch = new TChar(text[fI]);
ch->SetTextFont(72); // times-bold-r-normal
ch->SetTextSize(0.3);
ch->Modify();
fI++;
fList->Add(ch);
}
Draw(); // append this to current pad
Paint(); // calculate new coordinates of chars and paint it
gSystem->AddTimer(this); // start timer= start animation
}
Hello::~Hello()
{
// Clean up hello.
fList->Delete();
delete fList;
}
void Hello::ExecuteEvent(Int_t event, Int_t, Int_t)
{
// Actions when mouse clicked.
if (event == kButton1Up) {
TTimer::Remove();
}
}
Float_t Hello::GetWidth()
{
// Return text width
TChar *ch;
TIter nextin(fList);
Float_t width = 0;
while ((ch = (TChar*)nextin()))
width = width + ch->GetWidth();
return width;
}
void Hello::Paint(Option_t *)
{
// Paint text
static int sin_tbl[16] = {
0, 38, 71, 92, 100, 92, 71, 38, 0, -38, -71, -92, -100, -92, -71, -38
};
TChar *ch;
TIter nextin(fList);
Float_t width = GetWidth();
Coord_t xnext = (1-width)/2.; // draw text in the center of the pad
Coord_t y;
Coord_t y0 = 0.5;
fI = (fI+1) & 15;
int i = 0;
while ((ch = (TChar*)nextin())) {
int i16 = (fI+i) & 15;
y = y0 - (Coord_t)sin_tbl[i16]/1500.; // sin-wave coordinates
ch->SetY(y);
ch->SetX(xnext);
ch->SetTextColor(i16+200); // let's use x3d colors
i++;
xnext = xnext + ch->GetWidth(); // x position of next character
ch->Paint(""); // paint character
}
}
void Hello::Print(Option_t * opt) const
{
fList->Print(opt);
}
void Hello::ls(Option_t *opt) const
{
fList->ls(opt);
}
Bool_t Hello::Notify()
{
// Actions after timer time-out
fPad->Modified();
fPad->Update();
TTimer::Reset();
return kFALSE;
}
|