ROOT logo
// @(#)root/gui:$Id: TGGC.h 23115 2008-04-10 13:35:37Z rdm $
// Author: Fons Rademakers   20/9/2000

/*************************************************************************
 * Copyright (C) 1995-2000, 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_TGGC
#define ROOT_TGGC


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TGGC and TGGCPool                                                    //
//                                                                      //
// Encapsulate a graphics context used in the low level graphics.       //
// TGGCPool provides a pool of graphics contexts.                       //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TGObject
#include "TGObject.h"
#endif
#ifndef ROOT_TRefCnt
#include "TRefCnt.h"
#endif

class THashTable;


class TGGC : public TObject, public TRefCnt {

friend class TGGCPool;

protected:
   GCValues_t     fValues;     // graphics context values + mask
   GContext_t     fContext;    // graphics context handle

   TGGC(GCValues_t *values, Bool_t calledByGCPool);
   void UpdateValues(GCValues_t *v);

   TString GetMaskString() const;    //used in SavePrimitive()

public:
   TGGC(GCValues_t *values = 0);
   TGGC(const TGGC &g);
   virtual ~TGGC();
   TGGC &operator=(const TGGC &rhs);

   GContext_t GetGC() const { return fContext; }
   GContext_t operator()() const;

   void SetAttributes(GCValues_t *values);
   void SetFunction(EGraphicsFunction v);
   void SetPlaneMask(ULong_t v);
   void SetForeground(Pixel_t v);
   void SetBackground(Pixel_t v);
   void SetLineWidth(Int_t v);
   void SetLineStyle(Int_t v);
   void SetCapStyle(Int_t v);
   void SetJoinStyle(Int_t v);
   void SetFillStyle(Int_t v);
   void SetFillRule(Int_t v);
   void SetTile(Pixmap_t v);
   void SetStipple(Pixmap_t v);
   void SetTileStipXOrigin(Int_t v);
   void SetTileStipYOrigin(Int_t v);
   void SetFont(FontH_t v);
   void SetSubwindowMode(Int_t v);
   void SetGraphicsExposures(Bool_t v);
   void SetClipXOrigin(Int_t v);
   void SetClipYOrigin(Int_t v);
   void SetClipMask(Pixmap_t v);
   void SetDashOffset(Int_t v);
   void SetDashList(const char v[], Int_t len);
   void SetArcMode(Int_t v);

   const GCValues_t *GetAttributes() const { return &fValues; }
   Mask_t            GetMask() const { return fValues.fMask; }
   EGraphicsFunction GetFunction() const { return fValues.fFunction; }
   ULong_t           GetPlaneMask() const { return fValues.fPlaneMask; }
   Pixel_t           GetForeground() const { return fValues.fForeground; }
   Pixel_t           GetBackground() const { return fValues.fBackground; }
   Int_t             GetLineWidth() const { return fValues.fLineWidth; }
   Int_t             GetLineStyle() const { return fValues.fLineStyle; }
   Pixmap_t          GetTile() const { return fValues.fTile; }
   Pixmap_t          GetStipple() const { return fValues.fStipple; }
   Int_t             GetTileStipXOrigin() const { return fValues.fTsXOrigin; }
   Int_t             GetTileStipYOrigin() const { return fValues.fTsYOrigin; }
   Int_t             GetSubwindowMode() const { return fValues.fSubwindowMode; }
   FontH_t           GetFont() const { return fValues.fFont; }
   Bool_t            GetGraphicsExposures() const { return fValues.fGraphicsExposures; }
   Int_t             GetClipXOrigin() const { return fValues.fClipXOrigin; }
   Int_t             GetClipYOrigin() const { return fValues.fClipYOrigin; }
   Pixmap_t          GetClipMask() const { return fValues.fClipMask; }
   Int_t             GetCapStyle() const { return fValues.fCapStyle; }
   Int_t             GetJoinStyle() const { return fValues.fJoinStyle; }
   Int_t             GetFillStyle() const { return fValues.fFillStyle; }
   Int_t             GetFillRule() const { return fValues.fFillRule; }
   Int_t             GetDashOffset() const { return fValues.fDashOffset; }
   Int_t             GetDashLen() const { return fValues.fDashLen; }
   const char       *GetDashes() const { return fValues.fDashes; }
   Int_t             GetArcMode() const { return fValues.fArcMode; }

   void Print(Option_t *option="") const;
   void SavePrimitive(ostream &out, Option_t *option = "");

   ClassDef(TGGC,0)  // Graphics context
};


class TGGCPool : public TGObject {

friend class TGGC;

private:
   THashTable  *fList;   // hash table of graphics contexts in pool

   void   ForceFreeGC(const TGGC *gc);
   Int_t  MatchGC(const TGGC *gc, GCValues_t *values);
   void   UpdateGC(TGGC *gc, GCValues_t *values);

protected:
   TGGCPool(const TGGCPool& gp) : TGObject(gp), fList(gp.fList) { }
   TGGCPool& operator=(const TGGCPool& gp)
     {if(this!=&gp) {TGObject::operator=(gp); fList=gp.fList;}
     return *this;}

public:
   TGGCPool(TGClient *client);
   virtual ~TGGCPool();

   TGGC *GetGC(GCValues_t *values, Bool_t rw = kFALSE);
   TGGC *GetGC(GContext_t gct);
   void  FreeGC(const TGGC *gc);
   void  FreeGC(GContext_t gc);

   TGGC *FindGC(const TGGC *gc);
   TGGC *FindGC(GContext_t gc);

   void  Print(Option_t *option="") const;

   ClassDef(TGGCPool,0)  // Graphics context pool
};

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