#include "TEveText.h"
#include "TEveTrans.h"
#include "TGLFontManager.h"
#include "TObjArray.h"
#include "TObjString.h"
#include "TString.h"
#include "TBuffer3D.h"
#include "TBuffer3DTypes.h"
#include "TVirtualPad.h"
#include "TVirtualViewer3D.h"
#include "TMath.h"
ClassImp(TEveText);
TEveText::TEveText(const char* txt) :
TEveElement(fTextColor),
TNamed("TEveText", ""),
TAtt3D(),
TAttBBox(),
fText(txt),
fTextColor(0),
fFontSize(12),
fFontFile(4),
fFontMode(-1),
fExtrude(1.0f),
fAutoLighting(kTRUE),
fLighting(kFALSE)
{
InitMainTrans();
SetFontMode(TGLFont::kPixmap);
}
void TEveText::SetFontSize(Int_t val, Bool_t validate)
{
if (validate) {
Int_t* fsp = &TGLFontManager::GetFontSizeArray()->front();
Int_t ns = TGLFontManager::GetFontSizeArray()->size();
Int_t idx = TMath::BinarySearch(ns, fsp, val);
fFontSize = fsp[idx];
} else {
fFontSize = val;
}
}
void TEveText::SetFontFile(const char* name)
{
TObjArray* fa =TGLFontManager::GetFontFileArray();
TIter next_base(fa);
TObjString* os;
Int_t idx = 0;
while ((os = (TObjString*) next_base()) != 0) {
if (os->GetString() == name) {
SetFontFile(idx);
return;
}
idx++;
}
}
void TEveText::SetFontMode( Int_t mode)
{
fFontMode = mode;
Bool_t edit = (fFontMode > TGLFont::kPixmap);
TEveTrans& t = RefMainTrans();
t.SetEditRotation(edit);
t.SetEditScale(edit);
}
void TEveText::Paint(Option_t* )
{
static const TEveException eH("TEveText::Paint ");
TBuffer3D buff(TBuffer3DTypes::kGeneric);
buff.fID = this;
buff.fColor = GetMainColor();
buff.fTransparency = GetMainTransparency();
if (HasMainTrans())
RefMainTrans().SetBuffer3D(buff);
buff.SetSectionsValid(TBuffer3D::kCore);
Int_t reqSections = gPad->GetViewer3D()->AddObject(buff);
if (reqSections != TBuffer3D::kNone)
Error(eH, "only direct GL rendering supported.");
}
void TEveText::ComputeBBox()
{
BBoxZero();
}
const TGPicture* TEveText::GetListTreeIcon(Bool_t)
{
return TEveElement::fgListTreeIcons[5];
}