Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGGC.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 20/9/2000
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TGGC
13 #define ROOT_TGGC
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TGGC and TGGCPool //
19 // //
20 // Encapsulate a graphics context used in the low level graphics. //
21 // TGGCPool provides a pool of graphics contexts. //
22 // //
23 //////////////////////////////////////////////////////////////////////////
24 
25 #include "TGObject.h"
26 #include "TRefCnt.h"
27 
28 class THashTable;
29 
30 
31 class TGGC : public TObject, public TRefCnt {
32 
33 friend class TGGCPool;
34 
35 protected:
36  GCValues_t fValues = {}; // graphics context values + mask
37  GContext_t fContext; // graphics context handle
38 
39  TGGC(GCValues_t *values, Bool_t calledByGCPool);
40  void UpdateValues(GCValues_t *v);
41 
42  TString GetMaskString() const; //used in SavePrimitive()
43 
44 public:
45  TGGC(GCValues_t *values = 0);
46  TGGC(const TGGC &g);
47  virtual ~TGGC();
48  TGGC &operator=(const TGGC &rhs);
49 
50  GContext_t GetGC() const { return fContext; }
51  GContext_t operator()() const;
52 
53  void SetAttributes(GCValues_t *values);
54  void SetFunction(EGraphicsFunction v);
55  void SetPlaneMask(ULong_t v);
56  void SetForeground(Pixel_t v);
57  void SetBackground(Pixel_t v);
58  void SetLineWidth(Int_t v);
59  void SetLineStyle(Int_t v);
60  void SetCapStyle(Int_t v);
61  void SetJoinStyle(Int_t v);
62  void SetFillStyle(Int_t v);
63  void SetFillRule(Int_t v);
64  void SetTile(Pixmap_t v);
65  void SetStipple(Pixmap_t v);
66  void SetTileStipXOrigin(Int_t v);
67  void SetTileStipYOrigin(Int_t v);
68  void SetFont(FontH_t v);
69  void SetSubwindowMode(Int_t v);
70  void SetGraphicsExposures(Bool_t v);
71  void SetClipXOrigin(Int_t v);
72  void SetClipYOrigin(Int_t v);
73  void SetClipMask(Pixmap_t v);
74  void SetDashOffset(Int_t v);
75  void SetDashList(const char v[], Int_t len);
76  void SetArcMode(Int_t v);
77 
78  const GCValues_t *GetAttributes() const { return &fValues; }
79  Mask_t GetMask() const { return fValues.fMask; }
80  EGraphicsFunction GetFunction() const { return fValues.fFunction; }
81  ULong_t GetPlaneMask() const { return fValues.fPlaneMask; }
82  Pixel_t GetForeground() const { return fValues.fForeground; }
83  Pixel_t GetBackground() const { return fValues.fBackground; }
84  Int_t GetLineWidth() const { return fValues.fLineWidth; }
85  Int_t GetLineStyle() const { return fValues.fLineStyle; }
86  Pixmap_t GetTile() const { return fValues.fTile; }
87  Pixmap_t GetStipple() const { return fValues.fStipple; }
88  Int_t GetTileStipXOrigin() const { return fValues.fTsXOrigin; }
89  Int_t GetTileStipYOrigin() const { return fValues.fTsYOrigin; }
90  Int_t GetSubwindowMode() const { return fValues.fSubwindowMode; }
91  FontH_t GetFont() const { return fValues.fFont; }
92  Bool_t GetGraphicsExposures() const { return fValues.fGraphicsExposures; }
93  Int_t GetClipXOrigin() const { return fValues.fClipXOrigin; }
94  Int_t GetClipYOrigin() const { return fValues.fClipYOrigin; }
95  Pixmap_t GetClipMask() const { return fValues.fClipMask; }
96  Int_t GetCapStyle() const { return fValues.fCapStyle; }
97  Int_t GetJoinStyle() const { return fValues.fJoinStyle; }
98  Int_t GetFillStyle() const { return fValues.fFillStyle; }
99  Int_t GetFillRule() const { return fValues.fFillRule; }
100  Int_t GetDashOffset() const { return fValues.fDashOffset; }
101  Int_t GetDashLen() const { return fValues.fDashLen; }
102  const char *GetDashes() const { return fValues.fDashes; }
103  Int_t GetArcMode() const { return fValues.fArcMode; }
104 
105  void Print(Option_t *option="") const;
106  void SavePrimitive(std::ostream &out, Option_t *option = "");
107 
108  ClassDef(TGGC,0) // Graphics context
109 };
110 
111 
112 class TGGCPool : public TGObject {
113 
114 friend class TGGC;
115 
116 private:
117  THashTable *fList; // hash table of graphics contexts in pool
118 
119  void ForceFreeGC(const TGGC *gc);
120  Int_t MatchGC(const TGGC *gc, GCValues_t *values);
121  void UpdateGC(TGGC *gc, GCValues_t *values);
122 
123 protected:
124  TGGCPool(const TGGCPool& gp) : TGObject(gp), fList(gp.fList) { }
125  TGGCPool& operator=(const TGGCPool& gp)
126  {if(this!=&gp) {TGObject::operator=(gp); fList=gp.fList;}
127  return *this;}
128 
129 public:
130  TGGCPool(TGClient *client);
131  virtual ~TGGCPool();
132 
133  TGGC *GetGC(GCValues_t *values, Bool_t rw = kFALSE);
134  TGGC *GetGC(GContext_t gct);
135  void FreeGC(const TGGC *gc);
136  void FreeGC(GContext_t gc);
137 
138  TGGC *FindGC(const TGGC *gc);
139  TGGC *FindGC(GContext_t gc);
140 
141  void Print(Option_t *option="") const;
142 
143  ClassDef(TGGCPool,0) // Graphics context pool
144 };
145 
146 #endif