Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:00

0001 // @(#)root/gl:$Id$
0002 // Author:  Timur Pocheptsov  06/05/2009
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2009, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TGLPadPainter
0013 #define ROOT_TGLPadPainter
0014 
0015 #include "TVirtualPadPainter.h"
0016 #include "TGLFontManager.h"
0017 #include "TGLPadUtils.h"
0018 #include "TPoint.h"
0019 
0020 #include <vector>
0021 
0022 class TLinearGradient;
0023 class TRadialGradient;
0024 /*
0025 The _main_ purpose of TGLPadPainter is to enable 2d gl raphics
0026 inside standard TPad/TCanvas.
0027 */
0028 class TGLPadPainter : public TVirtualPadPainter {
0029 private:
0030    Rgl::Pad::PolygonStippleSet fSSet;
0031    Rgl::Pad::Tesselator        fTess;
0032    Rgl::Pad::MarkerPainter     fMarker;
0033    Rgl::Pad::GLLimits          fLimits;
0034 
0035    std::vector<Double_t>       fVs;//Vertex buffer for tesselator.
0036 
0037    TGLFontManager              fFM;
0038    TGLFont                     fF;
0039 
0040    Int_t                       fVp[4];
0041 
0042    std::vector<TPoint>         fPoly;
0043    Bool_t                      fIsHollowArea;
0044 
0045    Bool_t                      fLocked;
0046 
0047    template<class Char_t>
0048    void DrawTextHelper(Double_t x, Double_t y, const Char_t *text, ETextMode mode);
0049 public:
0050    TGLPadPainter();
0051 
0052    //Final overriders for TVirtualPadPainter pure virtual functions.
0053    //1. Part, which simply delegates to TVirtualX.
0054    //Line attributes.
0055    Color_t  GetLineColor() const override;
0056    Style_t  GetLineStyle() const override;
0057    Width_t  GetLineWidth() const override;
0058 
0059    void     SetLineColor(Color_t lcolor) override;
0060    void     SetLineStyle(Style_t lstyle) override;
0061    void     SetLineWidth(Width_t lwidth) override;
0062    //Fill attributes.
0063    Color_t  GetFillColor() const override;
0064    Style_t  GetFillStyle() const override;
0065    Bool_t   IsTransparent() const override;
0066 
0067    void     SetFillColor(Color_t fcolor) override;
0068    void     SetFillStyle(Style_t fstyle) override;
0069    void     SetOpacity(Int_t percent) override;
0070    //Text attributes.
0071    Short_t  GetTextAlign() const override;
0072    Float_t  GetTextAngle() const override;
0073    Color_t  GetTextColor() const override;
0074    Font_t   GetTextFont()  const override;
0075    Float_t  GetTextSize()  const override;
0076    Float_t  GetTextMagnitude() const override;
0077 
0078    void     SetTextAlign(Short_t align) override;
0079    void     SetTextAngle(Float_t tangle) override;
0080    void     SetTextColor(Color_t tcolor) override;
0081    void     SetTextFont(Font_t tfont) override;
0082    void     SetTextSize(Float_t tsize) override;
0083    void     SetTextSizePixels(Int_t npixels) override;
0084 
0085    //2. "Off-screen management" part.
0086    Int_t    CreateDrawable(UInt_t w, UInt_t h) override;
0087    void     ClearDrawable() override;
0088    void     CopyDrawable(Int_t device, Int_t px, Int_t py) override;
0089    void     DestroyDrawable(Int_t device) override;
0090    void     SelectDrawable(Int_t device) override;
0091 
0092    void     InitPainter() override;
0093    void     InvalidateCS() override;
0094    void     LockPainter() override;
0095 
0096    void     DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2) override;
0097    void     DrawLineNDC(Double_t u1, Double_t v1, Double_t u2, Double_t v2) override;
0098 
0099    void     DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, EBoxMode mode) override;
0100    //TPad needs double and float versions.
0101    void     DrawFillArea(Int_t n, const Double_t *x, const Double_t *y) override;
0102    void     DrawFillArea(Int_t n, const Float_t *x, const Float_t *y) override;
0103 
0104    //TPad needs both double and float versions of DrawPolyLine.
0105    void     DrawPolyLine(Int_t n, const Double_t *x, const Double_t *y) override;
0106    void     DrawPolyLine(Int_t n, const Float_t *x, const Float_t *y) override;
0107    void     DrawPolyLineNDC(Int_t n, const Double_t *u, const Double_t *v) override;
0108 
0109    //TPad needs both versions.
0110    void     DrawPolyMarker(Int_t n, const Double_t *x, const Double_t *y) override;
0111    void     DrawPolyMarker(Int_t n, const Float_t *x, const Float_t *y) override;
0112 
0113    void     DrawText(Double_t x, Double_t y, const char *text, ETextMode mode) override;
0114    void     DrawText(Double_t, Double_t, const wchar_t *, ETextMode) override;
0115    void     DrawTextNDC(Double_t x, Double_t y, const char *text, ETextMode mode) override;
0116    void     DrawTextNDC(Double_t, Double_t, const wchar_t *, ETextMode) override;
0117 
0118    //jpg, png, gif and bmp output.
0119    void     SaveImage(TVirtualPad *pad, const char *fileName, Int_t type) const override;
0120 
0121    //TASImage support.
0122    void     DrawPixels(const unsigned char *pixelData, UInt_t width, UInt_t height,
0123                        Int_t dstX, Int_t dstY, Bool_t enableBlending) override;
0124 
0125 
0126 private:
0127 
0128    //Attention! GL_PROJECTION will become
0129    //the current matrix after these calls.
0130    void     SaveProjectionMatrix()const;
0131    void     RestoreProjectionMatrix()const;
0132 
0133    //Attention! GL_MODELVIEW will become the
0134    //current matrix after these calls.
0135    void     SaveModelviewMatrix()const;
0136    void     RestoreModelviewMatrix()const;
0137 
0138    void     SaveViewport();
0139    void     RestoreViewport();
0140 
0141    void     DrawPolyMarker();
0142 
0143    //Aux. functions for a gradient and solid fill:
0144    void DrawPolygonWithGradient(Int_t n, const Double_t *x, const Double_t *y);
0145    //
0146    void DrawGradient(const TLinearGradient *gradient, Int_t n, const Double_t *x, const Double_t *y);
0147    void DrawGradient(const TRadialGradient *gradient, Int_t n, const Double_t *x, const Double_t *y);
0148    //
0149    void DrawTesselation(Int_t n, const Double_t *x, const Double_t *y);
0150 
0151    TGLPadPainter(const TGLPadPainter &rhs);
0152    TGLPadPainter & operator = (const TGLPadPainter &rhs);
0153 
0154    ClassDefOverride(TGLPadPainter, 0)
0155 };
0156 
0157 #endif
0158