ROOT logo
// @(#)root/gl:$Id$
// Author: Alja Mrak-Tadel 2009

/*************************************************************************
* Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
* All rights reserved.                                                  *
*                                                                       *
* For the licensing terms see $ROOTSYS/LICENSE.                         *
* For the list of contributors see $ROOTSYS/README/CREDITS.             *
*************************************************************************/

#ifndef ROOT_TGLAxisPainter
#define ROOT_TGLAxisPainter

#include "TGLUtil.h"
#include "TGLFontManager.h"

class TAttAxis;
class TAxis;
class TH1;
class TPMERegexp;
class TGLRnrCtx;


//==============================================================================
// TGLAxisPainter
//==============================================================================

class TGLAxisPainter
{
public:
   typedef std::pair  <Float_t, Float_t>    Lab_t; // label <pos, value> pair
   typedef std::vector<Lab_t>               LabVec_t;
   typedef std::pair  <Float_t, Int_t>      TM_t;  // tick-mark <pos, order> pair
   typedef std::vector<TM_t>                TMVec_t; // vector od tick lines

private:
   TGLAxisPainter(const TGLAxisPainter&);            // Not implemented
   TGLAxisPainter& operator=(const TGLAxisPainter&); // Not implemented

   // Print format derived from attributers.
   Int_t fExp;
   Int_t fMaxDigits;
   Int_t fDecimals;
   TString fFormat;

   // Font derived from axis attributes.
   TGLFont fLabelFont;
   TGLFont fTitleFont;

   // Print format.
   void LabelsLimits(const char *label, Int_t &first, Int_t &last) const;
   void FormAxisValue(Double_t x, TString &s) const;

protected:
   TAttAxis        *fAttAxis;    // Model.
   Bool_t           fUseAxisColors; // Use colors from axes or from GL-rnr-ctx.
   TGLFont::EMode   fFontMode;   // To be put into TAttAxis
   LabVec_t         fLabVec;     // List of Labels position-value pairs
   TMVec_t          fTMVec;      // List of tick-mark position-value pairs

   //
   // Additional axis attributes required for GL rendering:

   // Orientation
   TGLVector3 fDir;
   TGLVector3 fTMOff[3];
   Int_t      fTMNDim;

   // Font.
   Int_t    fLabelPixelFontSize;
   Double_t fLabel3DFontSize;
   Int_t    fTitlePixelFontSize;
   Double_t fTitle3DFontSize;

   // Labels options. Allready exist in TAttAxis, but can't be set.
   TGLFont::ETextAlignH_e fLabelAlignH;
   TGLFont::ETextAlignV_e fLabelAlignV;
   TGLVector3  fTitlePos;
   TPMERegexp *fAllZeroesRE;

public:
   TGLAxisPainter();
   virtual ~TGLAxisPainter();

   // GetSets.
   Int_t        GetTMNDim() const { return fTMNDim; }
   void         SetTMNDim(Int_t x) { fTMNDim = x; }

   TGLVector3&  RefDir() { return fDir; }
   TGLVector3&  RefTMOff(Int_t i) { return fTMOff[i]; }

   TGLFont::EMode GetFontMode() const { return fFontMode; }
   void  SetFontMode(TGLFont::EMode m) { fFontMode=m; }

   // this setter not necessary
   void         SetLabelPixelFontSize(Int_t fs) { fLabelPixelFontSize=fs; }
   Int_t        GetLabelPixelFontSize() const { return fLabelPixelFontSize; }
   void         SetTitlePixelFontSize(Int_t fs) { fTitlePixelFontSize=fs; }
   Int_t        GetTitlePixelFontSize() const { return fTitlePixelFontSize; }

   TGLVector3&  RefTitlePos() { return fTitlePos; }


   void         SetLabelAlign(TGLFont::ETextAlignH_e, TGLFont::ETextAlignV_e);

   LabVec_t& RefLabVec() { return fLabVec; }
   TMVec_t&  RefTMVec()  { return fTMVec; }

   void      SetAttAxis(TAttAxis* a) { fAttAxis = a; }
   TAttAxis* GetAttAxis() { return fAttAxis; }

   void   SetUseAxisColors(Bool_t x) { fUseAxisColors = x;    }
   Bool_t GetUseAxisColors() const   { return fUseAxisColors; }

   // Utility.
   void SetLabelFont(TGLRnrCtx &rnrCtx, const char* fontName, Int_t pixelSize = 64, Double_t font3DSize = -1);
   void SetTitleFont(TGLRnrCtx &rnrCtx, const char* fontName, Int_t pixelSize = 64, Double_t font3DSize = -1);

   void SetTextFormat(Double_t min, Double_t max, Double_t binWidth);

   // Renderers.
   void RnrText (const TString &txt, const TGLVector3 &pos, TGLFont::ETextAlignH_e aH, TGLFont::ETextAlignV_e aV, const TGLFont &font) const;
   void RnrTitle(const TString &title, TGLVector3 &pos, TGLFont::ETextAlignH_e aH, TGLFont::ETextAlignV_e aV) const;
   void RnrLabels() const;
   void RnrLines() const;

   void PaintAxis(TGLRnrCtx& ctx, TAxis* ax);

   ClassDef(TGLAxisPainter, 0); // GL axis painter.
};


//==============================================================================
// TGLAxisPainterBox
//==============================================================================

class TGLAxisPainterBox : public TGLAxisPainter
{
protected:
   TGLVector3          fAxisTitlePos[3];
   TAxis*              fAxis[3];

public:
   TGLAxisPainterBox();
   virtual ~TGLAxisPainterBox();

   void SetAxis3DTitlePos(TGLRnrCtx &rnrCtx);
   void DrawAxis3D(TGLRnrCtx &rnrCtx);

   void PlotStandard(TGLRnrCtx &rnrCtx, const TH1* histo, const TGLBoundingBox& bbox);

   ClassDef(TGLAxisPainterBox, 0); // Painter of GL axes for a 3D box.
};

#endif
 TGLAxisPainter.h:1
 TGLAxisPainter.h:2
 TGLAxisPainter.h:3
 TGLAxisPainter.h:4
 TGLAxisPainter.h:5
 TGLAxisPainter.h:6
 TGLAxisPainter.h:7
 TGLAxisPainter.h:8
 TGLAxisPainter.h:9
 TGLAxisPainter.h:10
 TGLAxisPainter.h:11
 TGLAxisPainter.h:12
 TGLAxisPainter.h:13
 TGLAxisPainter.h:14
 TGLAxisPainter.h:15
 TGLAxisPainter.h:16
 TGLAxisPainter.h:17
 TGLAxisPainter.h:18
 TGLAxisPainter.h:19
 TGLAxisPainter.h:20
 TGLAxisPainter.h:21
 TGLAxisPainter.h:22
 TGLAxisPainter.h:23
 TGLAxisPainter.h:24
 TGLAxisPainter.h:25
 TGLAxisPainter.h:26
 TGLAxisPainter.h:27
 TGLAxisPainter.h:28
 TGLAxisPainter.h:29
 TGLAxisPainter.h:30
 TGLAxisPainter.h:31
 TGLAxisPainter.h:32
 TGLAxisPainter.h:33
 TGLAxisPainter.h:34
 TGLAxisPainter.h:35
 TGLAxisPainter.h:36
 TGLAxisPainter.h:37
 TGLAxisPainter.h:38
 TGLAxisPainter.h:39
 TGLAxisPainter.h:40
 TGLAxisPainter.h:41
 TGLAxisPainter.h:42
 TGLAxisPainter.h:43
 TGLAxisPainter.h:44
 TGLAxisPainter.h:45
 TGLAxisPainter.h:46
 TGLAxisPainter.h:47
 TGLAxisPainter.h:48
 TGLAxisPainter.h:49
 TGLAxisPainter.h:50
 TGLAxisPainter.h:51
 TGLAxisPainter.h:52
 TGLAxisPainter.h:53
 TGLAxisPainter.h:54
 TGLAxisPainter.h:55
 TGLAxisPainter.h:56
 TGLAxisPainter.h:57
 TGLAxisPainter.h:58
 TGLAxisPainter.h:59
 TGLAxisPainter.h:60
 TGLAxisPainter.h:61
 TGLAxisPainter.h:62
 TGLAxisPainter.h:63
 TGLAxisPainter.h:64
 TGLAxisPainter.h:65
 TGLAxisPainter.h:66
 TGLAxisPainter.h:67
 TGLAxisPainter.h:68
 TGLAxisPainter.h:69
 TGLAxisPainter.h:70
 TGLAxisPainter.h:71
 TGLAxisPainter.h:72
 TGLAxisPainter.h:73
 TGLAxisPainter.h:74
 TGLAxisPainter.h:75
 TGLAxisPainter.h:76
 TGLAxisPainter.h:77
 TGLAxisPainter.h:78
 TGLAxisPainter.h:79
 TGLAxisPainter.h:80
 TGLAxisPainter.h:81
 TGLAxisPainter.h:82
 TGLAxisPainter.h:83
 TGLAxisPainter.h:84
 TGLAxisPainter.h:85
 TGLAxisPainter.h:86
 TGLAxisPainter.h:87
 TGLAxisPainter.h:88
 TGLAxisPainter.h:89
 TGLAxisPainter.h:90
 TGLAxisPainter.h:91
 TGLAxisPainter.h:92
 TGLAxisPainter.h:93
 TGLAxisPainter.h:94
 TGLAxisPainter.h:95
 TGLAxisPainter.h:96
 TGLAxisPainter.h:97
 TGLAxisPainter.h:98
 TGLAxisPainter.h:99
 TGLAxisPainter.h:100
 TGLAxisPainter.h:101
 TGLAxisPainter.h:102
 TGLAxisPainter.h:103
 TGLAxisPainter.h:104
 TGLAxisPainter.h:105
 TGLAxisPainter.h:106
 TGLAxisPainter.h:107
 TGLAxisPainter.h:108
 TGLAxisPainter.h:109
 TGLAxisPainter.h:110
 TGLAxisPainter.h:111
 TGLAxisPainter.h:112
 TGLAxisPainter.h:113
 TGLAxisPainter.h:114
 TGLAxisPainter.h:115
 TGLAxisPainter.h:116
 TGLAxisPainter.h:117
 TGLAxisPainter.h:118
 TGLAxisPainter.h:119
 TGLAxisPainter.h:120
 TGLAxisPainter.h:121
 TGLAxisPainter.h:122
 TGLAxisPainter.h:123
 TGLAxisPainter.h:124
 TGLAxisPainter.h:125
 TGLAxisPainter.h:126
 TGLAxisPainter.h:127
 TGLAxisPainter.h:128
 TGLAxisPainter.h:129
 TGLAxisPainter.h:130
 TGLAxisPainter.h:131
 TGLAxisPainter.h:132
 TGLAxisPainter.h:133
 TGLAxisPainter.h:134
 TGLAxisPainter.h:135
 TGLAxisPainter.h:136
 TGLAxisPainter.h:137
 TGLAxisPainter.h:138
 TGLAxisPainter.h:139
 TGLAxisPainter.h:140
 TGLAxisPainter.h:141
 TGLAxisPainter.h:142
 TGLAxisPainter.h:143
 TGLAxisPainter.h:144
 TGLAxisPainter.h:145
 TGLAxisPainter.h:146
 TGLAxisPainter.h:147
 TGLAxisPainter.h:148
 TGLAxisPainter.h:149
 TGLAxisPainter.h:150
 TGLAxisPainter.h:151
 TGLAxisPainter.h:152
 TGLAxisPainter.h:153
 TGLAxisPainter.h:154
 TGLAxisPainter.h:155
 TGLAxisPainter.h:156