TridSketchText Class Reference

#include <TridSketches.h>

Inheritance diagram for TridSketchText:
TridSketch

List of all members.

Public Types

enum  ETridSketchTextJustify {
  kCenter = 0, kJustifyLeft = 1, kJustifyRight = 2, kJustifyTop = 4,
  kJustifyBottom = 8
}
typedef enum
TridSketchText::ETridSketchTextJustify 
Justify_t

Public Member Functions

 TridSketchText (const TVector3 &pos=kv_o, const TVector3 &up=kv_y, const TVector3 &norm=kv_z, const char *text="")
 ~TridSketchText ()
void SetText (const char *text)
const char * GetText (void)
void SetFont (int font)
void SetCentered ()
void SetJustify (Int_t justify)
void SetScale (Float_t scale)
void SetScale (Float_t scalex, Float_t scaley)
void SetThickness (Float_t thick)
void DrawSelf (void)

Private Attributes

TVector3 fPosition
TVector3 fUp
TVector3 fNormal
Float_t fScaleHoriz
Float_t fScaleVert
Float_t fThickness
TString fText
Int_t fFont
Int_t fJustify

Detailed Description

Definition at line 247 of file TridSketches.h.


Member Typedef Documentation


Member Enumeration Documentation

Enumerator:
kCenter 
kJustifyLeft 
kJustifyRight 
kJustifyTop 
kJustifyBottom 

Definition at line 254 of file TridSketches.h.

00254                                       {
00255     kCenter = 0,
00256     kJustifyLeft = 1,
00257     kJustifyRight = 2,
00258     kJustifyTop   = 4,
00259     kJustifyBottom = 8
00260   } Justify_t;


Constructor & Destructor Documentation

TridSketchText::TridSketchText ( const TVector3 &  pos = kv_o,
const TVector3 &  up = kv_y,
const TVector3 &  norm = kv_z,
const char *  text = "" 
)

Definition at line 606 of file TridSketches.cxx.

00609   : TridSketch( kText, pos ),
00610     fPosition(pos),
00611     fUp(up.Unit()),       // Normalizes
00612     fNormal(norm.Unit()), // Normalizes
00613     fScaleHoriz(1),
00614     fScaleVert(1),
00615     fThickness(0.1),  
00616     fText(text),
00617     fFont(-1),
00618     fJustify(kCenter)
00619 {
00620 }

TridSketchText::~TridSketchText (  )  [inline]

Definition at line 252 of file TridSketches.h.

00252 {};


Member Function Documentation

void TridSketchText::DrawSelf ( void   )  [virtual]

Reimplemented from TridSketch.

Definition at line 622 of file TridSketches.cxx.

References fFont, fJustify, fNormal, fPosition, fScaleHoriz, fScaleVert, fText, fThickness, fUp, glfDraw3DSolidString(), glfGetCurrentFont(), glfGetStringBounds(), glfSetCurrentFont(), glfSetSymbolDepth(), glfStringCentering(), Msg::kError, kJustifyBottom, kJustifyLeft, kJustifyRight, kJustifyTop, kv_z(), and MSG.

00623 {
00624   //
00625   // Draws a box in the current context.
00626   //
00627   glPushMatrix();
00628   
00629   // Translate.
00630   glTranslated(fPosition.x(),fPosition.y(),fPosition.z());
00631     
00632   // Rotation. By default, text is drawn 
00633   // in the x-y plane, with the normal in z and the up arrow towards y.
00634   TVector3 stdnorm(0,0,1);
00635   TVector3 stdup  (0,1,0);
00636 
00637   // Rotate so that the normal is in the correct position.
00638   // Special case: flip by 180:
00639   TVector3 rot;
00640   Double_t ang1;
00641   if(fNormal == -kv_z) {
00642     rot = TVector3(0,1,0);
00643     ang1 = 180.; 
00644   } else {
00645     //rot = stdnorm.Cross(fNormal).Unit();
00646     //ang1 = acos(stdnorm.Dot(fNormal))*57.295779513;
00647     rot = stdnorm.Cross(fNormal);
00648     ang1= asin(rot.Mag())*57.295779513;
00649     if(ang1!=0) rot.SetMag(1.0);
00650   }
00651 
00652   if(ang1!=0)
00653     stdup.Rotate(ang1*0.01745329252,rot);  // stdup is y rotated into the new position.
00654 
00655   double ang2 = stdup.Angle(fUp)*57.295779513;
00656 
00657   // Rotate so that the Up vector is correct.
00658   if(ang2!=0)
00659     glRotated(ang2, fNormal.x(), fNormal.y(), fNormal.z() );
00660 
00661   // Rotate for normal to be correct.
00662   if(ang1!=0)
00663     glRotated(ang1, rot.x(), rot.y(), rot.z() );
00664   
00665   // Stretch.
00666   glScaled(fScaleHoriz, fScaleVert, 1.0);
00667 
00668   // Move to correct local Z
00669   glTranslated(0.,0.,-1.);
00670   
00671   // Set options
00672   int oldFont = glfGetCurrentFont();
00673   if(fFont>0) glfSetCurrentFont(fFont);
00674 
00675   glfSetSymbolDepth(fThickness);
00676   glfStringCentering(true);
00677 
00678   float minx, miny, maxx, maxy;
00679   glfGetStringBounds(const_cast<char*>(fText.Data()), &minx, &miny, &maxx, &maxy);
00680   
00681   // Adjust for stupidities in glf
00682   minx -= 1.0;
00683   maxx -= 1.0;
00684 
00685   float halfwidth =  (minx+maxx)*0.5;
00686   float halfheight = (-miny+maxy)*0.5;
00687 
00688   // Default: center.
00689   float movex = 0; //halfwidth;
00690   float movey = 0;
00691 
00692   if(fJustify & kJustifyLeft)   movex  = -halfwidth + minx;
00693   if(fJustify & kJustifyRight)  movex  = halfwidth - minx;
00694   if(fJustify & kJustifyTop)    movey += halfheight;
00695   if(fJustify & kJustifyBottom) movey -= halfheight;
00696 
00697   glTranslatef(-movex,-movey,0.0f);
00698   /*
00699     // Draw bounding box.
00700   glPushMatrix();
00701   glBegin(GL_LINE_LOOP);
00702   glColor4f(fColor.x(),fColor.y(),fColor.z(),fTransparency);
00703   glVertex3f(minx, miny, 1.0 );
00704   glVertex3f(minx, maxy, 1.0 );
00705   glVertex3f(maxx, maxy, 1.0 );
00706   glVertex3f(maxx, miny, 1.0 );
00707   //glVertex3f(minx, miny, 1.0 );
00708   glEnd();
00709   glPopMatrix();
00710   */
00711 
00712   // Draw.
00713   glfDraw3DSolidString(const_cast<char*>(fText.Data()));
00714 
00715   glfSetCurrentFont(oldFont);
00716 
00717   // Revert.
00718   glPopMatrix();
00719 
00720   int error;
00721   while ((error = glGetError()) != GL_NO_ERROR)  
00722     MSG("TriD",Msg::kError) << "TridSketchText::DrawSelf.  GL error: "
00723                             << "(" << error << ")"
00724                             <<  gluErrorString(error)
00725                             << endl;
00726 
00727    
00728 }

const char* TridSketchText::GetText ( void   )  [inline]

Definition at line 263 of file TridSketches.h.

00263 { return fText.Data();} ;

void TridSketchText::SetCentered (  )  [inline]

Definition at line 265 of file TridSketches.h.

References TridSketch::SetDirty().

00265 { fJustify = kCenter;  SetDirty();};

void TridSketchText::SetFont ( int  font  )  [inline]

Definition at line 264 of file TridSketches.h.

References TridSketch::SetDirty().

00264 { fFont = font;  SetDirty();};

void TridSketchText::SetJustify ( Int_t  justify  )  [inline]

Definition at line 266 of file TridSketches.h.

Referenced by TridHistoGLFrame::DrawObjects().

00266 { fJustify = justify; };

void TridSketchText::SetScale ( Float_t  scalex,
Float_t  scaley 
) [inline]

Definition at line 268 of file TridSketches.h.

References TridSketch::SetDirty().

00268 { fScaleHoriz = scalex; fScaleVert = scaley;  SetDirty();};

void TridSketchText::SetScale ( Float_t  scale  )  [inline]
void TridSketchText::SetText ( const char *  text  )  [inline]

Definition at line 262 of file TridSketches.h.

References TridSketch::SetDirty().

00262 { fText = text; SetDirty(); };

void TridSketchText::SetThickness ( Float_t  thick  )  [inline]

Member Data Documentation

Int_t TridSketchText::fFont [private]

Definition at line 280 of file TridSketches.h.

Referenced by DrawSelf().

Int_t TridSketchText::fJustify [private]

Definition at line 281 of file TridSketches.h.

Referenced by DrawSelf().

TVector3 TridSketchText::fNormal [private]

Definition at line 275 of file TridSketches.h.

Referenced by DrawSelf().

TVector3 TridSketchText::fPosition [private]

Definition at line 273 of file TridSketches.h.

Referenced by DrawSelf().

Float_t TridSketchText::fScaleHoriz [private]

Definition at line 276 of file TridSketches.h.

Referenced by DrawSelf().

Float_t TridSketchText::fScaleVert [private]

Definition at line 277 of file TridSketches.h.

Referenced by DrawSelf().

TString TridSketchText::fText [private]

Definition at line 279 of file TridSketches.h.

Referenced by DrawSelf().

Float_t TridSketchText::fThickness [private]

Definition at line 278 of file TridSketches.h.

Referenced by DrawSelf().

TVector3 TridSketchText::fUp [private]

Definition at line 274 of file TridSketches.h.

Referenced by DrawSelf().


The documentation for this class was generated from the following files:

Generated on 21 Jun 2018 for loon by  doxygen 1.6.1