Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-28 09:29:59

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 "TPadPainterBase.h"
0016 #include "TGLFontManager.h"
0017 #include "TGLPadUtils.h"
0018 #include "TPoint.h"
0019 #include "GuiTypes.h"
0020 
0021 #include <vector>
0022 
0023 class TLinearGradient;
0024 class TRadialGradient;
0025 /*
0026 The _main_ purpose of TGLPadPainter is to enable 2d gl raphics
0027 inside standard TPad/TCanvas.
0028 */
0029 class TGLPadPainter : public TPadPainterBase {
0030 private:
0031    Rgl::Pad::PolygonStippleSet fSSet;
0032    Rgl::Pad::Tesselator        fTess;
0033    Rgl::Pad::MarkerPainter     fMarker;
0034    Rgl::Pad::GLLimits          fLimits;
0035 
0036    WinContext_t   fWinContext; // context of selected drawable
0037    TAttFill       fGlFillAtt;  // fill attributes used for GL
0038 
0039    std::vector<Double_t>       fVs;//Vertex buffer for tesselator.
0040 
0041    TGLFontManager              fFM;
0042    TGLFont                     fF;
0043 
0044    Int_t                       fVp[4];
0045 
0046    std::vector<TPoint>         fPoly;
0047    Bool_t                      fIsHollowArea;
0048 
0049    Bool_t                      fLocked;
0050 
0051    template<class Char_t>
0052    void DrawTextHelper(Double_t x, Double_t y, const Char_t *text, ETextMode mode);
0053 public:
0054    TGLPadPainter();
0055 
0056    void     SetOpacity(Int_t percent) override;
0057    Float_t  GetTextMagnitude() const override;
0058 
0059 
0060    void      OnPad(TVirtualPad *) override;
0061 
0062    // Overwrite only attributes setters
0063    void      SetAttFill(const TAttFill &att) override;
0064    void      SetAttLine(const TAttLine &att) override;
0065    void      SetAttMarker(const TAttMarker &att) override;
0066    void      SetAttText(const TAttText &att) override;
0067 
0068    //2. "Off-screen management" part.
0069    Int_t    CreateDrawable(UInt_t w, UInt_t h) override;
0070    void     ClearDrawable() override;
0071    void     ClearWindow(Int_t device) override;
0072    Int_t    ResizeDrawable(Int_t device, UInt_t w, UInt_t h) override;
0073    void     CopyDrawable(Int_t device, Int_t px, Int_t py) override;
0074    void     DestroyDrawable(Int_t device) override;
0075    void     SelectDrawable(Int_t device) override;
0076    void     UpdateDrawable(Int_t mode) override;
0077    void     SetDrawMode(Int_t device, Int_t mode) override;
0078 
0079    void     InitPainter() override;
0080    void     InvalidateCS() override;
0081    void     LockPainter() override;
0082 
0083    void     DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2) override;
0084    void     DrawLineNDC(Double_t u1, Double_t v1, Double_t u2, Double_t v2) override;
0085 
0086    void     DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, EBoxMode mode) override;
0087    //TPad needs double and float versions.
0088    void     DrawFillArea(Int_t n, const Double_t *x, const Double_t *y) override;
0089    void     DrawFillArea(Int_t n, const Float_t *x, const Float_t *y) override;
0090 
0091    //TPad needs both double and float versions of DrawPolyLine.
0092    void     DrawPolyLine(Int_t n, const Double_t *x, const Double_t *y) override;
0093    void     DrawPolyLine(Int_t n, const Float_t *x, const Float_t *y) override;
0094    void     DrawPolyLineNDC(Int_t n, const Double_t *u, const Double_t *v) override;
0095 
0096    //TPad needs both versions.
0097    void     DrawPolyMarker(Int_t n, const Double_t *x, const Double_t *y) override;
0098    void     DrawPolyMarker(Int_t n, const Float_t *x, const Float_t *y) override;
0099 
0100    void     DrawText(Double_t x, Double_t y, const char *text, ETextMode mode) override;
0101    void     DrawText(Double_t, Double_t, const wchar_t *, ETextMode) override;
0102    void     DrawTextNDC(Double_t x, Double_t y, const char *text, ETextMode mode) override;
0103    void     DrawTextNDC(Double_t, Double_t, const wchar_t *, ETextMode) override;
0104 
0105    //jpg, png, gif and bmp output.
0106    void     SaveImage(TVirtualPad *pad, const char *fileName, Int_t type) const override;
0107 
0108    //TASImage support.
0109    void     DrawPixels(const unsigned char *pixelData, UInt_t width, UInt_t height,
0110                        Int_t dstX, Int_t dstY, Bool_t enableBlending) override;
0111 
0112    Bool_t IsNative() const override { return kTRUE; }
0113 
0114    Bool_t   IsCocoa() const override;
0115 
0116    Bool_t   IsSupportAlpha() const override { return kTRUE; }
0117 
0118 private:
0119 
0120    //Attention! GL_PROJECTION will become
0121    //the current matrix after these calls.
0122    void     SaveProjectionMatrix()const;
0123    void     RestoreProjectionMatrix()const;
0124 
0125    //Attention! GL_MODELVIEW will become the
0126    //current matrix after these calls.
0127    void     SaveModelviewMatrix()const;
0128    void     RestoreModelviewMatrix()const;
0129 
0130    void     SaveViewport();
0131    void     RestoreViewport();
0132 
0133    void     DrawPolyMarker();
0134 
0135    //Aux. functions for a gradient and solid fill:
0136    void DrawPolygonWithGradient(Int_t n, const Double_t *x, const Double_t *y);
0137    //
0138    void DrawGradient(const TLinearGradient *gradient, Int_t n, const Double_t *x, const Double_t *y);
0139    void DrawGradient(const TRadialGradient *gradient, Int_t n, const Double_t *x, const Double_t *y);
0140    //
0141    void DrawTesselation(Int_t n, const Double_t *x, const Double_t *y);
0142 
0143    TGLPadPainter(const TGLPadPainter &rhs);
0144    TGLPadPainter & operator = (const TGLPadPainter &rhs);
0145 
0146    ClassDefOverride(TGLPadPainter, 0)
0147 };
0148 
0149 #endif
0150