Logo ROOT  
Reference Guide
TGPicture.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 01/01/98
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_TGPicture
13 #define ROOT_TGPicture
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TGPicture, TGSelectdPicture & TGPicturePool //
19 // //
20 // The TGPicture class implements pictures and icons used in the //
21 // different GUI elements and widgets. The TGPicturePool class //
22 // implements a TGPicture cache. TGPictures are created, managed and //
23 // destroyed by the TGPicturePool. //
24 // //
25 //////////////////////////////////////////////////////////////////////////
26 
27 #include "TObject.h"
28 #include "TRefCnt.h"
29 #include "TString.h"
30 #include "TGClient.h"
31 #include "TGGC.h"
32 
33 class THashTable;
34 
35 
36 class TGPicture : public TObject, public TRefCnt {
37 
38 friend class TGPicturePool;
39 
40 protected:
41  TString fName; // name of picture
42  Bool_t fScaled; // kTRUE if picture is scaled
43  Pixmap_t fPic; // picture pixmap
44  Pixmap_t fMask; // picture mask pixmap
45  PictureAttributes_t fAttributes; // picture attributes
46 
47  TGPicture(const char *name, Bool_t scaled = kFALSE):
49  {
50  fAttributes.fPixels = 0;
51  SetRefCount(1);
52  }
53 
54  TGPicture(const char *name, Pixmap_t pxmap, Pixmap_t mask = 0);
55 
56  // override default of TObject
57  void Draw(Option_t * = "") { MayNotUse("Draw(Option_t*)"); }
58 
59 public:
60  virtual ~TGPicture();
61 
62  const char *GetName() const { return fName; }
63  UInt_t GetWidth() const { return fAttributes.fWidth; }
64  UInt_t GetHeight() const { return fAttributes.fHeight; }
65  Pixmap_t GetPicture() const { return fPic; }
66  Pixmap_t GetMask() const { return fMask; }
67  Bool_t IsScaled() const { return fScaled; }
68  ULong_t Hash() const { return fName.Hash(); }
69  static const char *HashName(const char *name, Int_t width, Int_t height);
70 
71  virtual void Draw(Handle_t id, GContext_t gc, Int_t x, Int_t y) const;
72  void Print(Option_t *option="") const;
73 
74  ClassDef(TGPicture,0) // Pictures and icons used by the GUI classes
75 };
76 
77 
78 class TGSelectedPicture : public TGPicture {
79 
80 protected:
81  const TGClient *fClient; // client to which selected picture belongs
82 
83  static TGGC *fgSelectedGC;
84  static TGGC &GetSelectedGC();
85 
87  TGPicture(gp), fClient(gp.fClient) { }
89  {if(this!=&gp) { TGPicture::operator=(gp); fClient=gp.fClient;}
90  return *this;}
91 
92 public:
93  TGSelectedPicture(const TGClient *client, const TGPicture *p);
94  virtual ~TGSelectedPicture();
95 
96  ClassDef(TGSelectedPicture,0) // Selected looking picture
97 };
98 
99 
100 class TGPicturePool : public TObject {
101 
102 protected:
103  const TGClient *fClient; // client for which we keep icon pool
104  TString fPath; // icon search path
105  THashTable *fPicList; // hash table containing the icons
106 
109 
110 public:
111  TGPicturePool(const TGClient *client, const char *path):
112  fClient(client), fPath(path), fPicList(0) { }
113  virtual ~TGPicturePool();
114 
115  const char *GetPath() const { return fPath; }
116  const TGPicture *GetPicture(const char *name);
117  const TGPicture *GetPicture(const char *name, char **xpm);
118  const TGPicture *GetPicture(const char *name, UInt_t new_width, UInt_t new_height);
119  const TGPicture *GetPicture(const char *name, Pixmap_t pxmap, Pixmap_t mask = 0);
120  void FreePicture(const TGPicture *pic);
121 
122  void Print(Option_t *option="") const;
123 
124  ClassDef(TGPicturePool,0) // Picture and icon cache
125 };
126 
127 #endif
TGPicture::fName
TString fName
Definition: TGPicture.h:41
TGPicture::TGPicture
TGPicture(const char *name, Bool_t scaled=kFALSE)
Definition: TGPicture.h:47
Pixmap_t
Handle_t Pixmap_t
Definition: GuiTypes.h:29
TGPicture
Definition: TGPicture.h:36
PictureAttributes_t::fPixels
ULong_t * fPixels
Definition: GuiTypes.h:329
TRefCnt::SetRefCount
void SetRefCount(UInt_t r)
Definition: TRefCnt.h:45
TGPicture::HashName
static const char * HashName(const char *name, Int_t width, Int_t height)
Static function returning a unique name used to look up a picture.
Definition: TGPicture.cxx:373
TGPicture::GetWidth
UInt_t GetWidth() const
Definition: TGPicture.h:63
PictureAttributes_t::fWidth
UInt_t fWidth
Definition: GuiTypes.h:325
TGSelectedPicture::~TGSelectedPicture
virtual ~TGSelectedPicture()
Delete selected picture.
Definition: TGPicture.cxx:428
TGPicture::Hash
ULong_t Hash() const
Return hash value for this object.
Definition: TGPicture.h:68
TGPicture::GetMask
Pixmap_t GetMask() const
Definition: TGPicture.h:66
TRefCnt.h
width
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
Int_t
int Int_t
Definition: RtypesCore.h:45
TString::Hash
UInt_t Hash(ECaseCompare cmp=kExact) const
Return hash value.
Definition: TString.cxx:638
TGPicture::Draw
void Draw(Option_t *="")
Default Draw method for all objects.
Definition: TGPicture.h:57
x
Double_t x[n]
Definition: legend1.C:17
TGSelectedPicture
Definition: TGPicture.h:78
TObject::MayNotUse
void MayNotUse(const char *method) const
Use this method to signal that a method (defined in a base class) may not be called in a derived clas...
Definition: TObject.cxx:943
TGPicturePool::TGPicturePool
TGPicturePool(const TGClient *client, const char *path)
Definition: TGPicture.h:111
TGPicture::IsScaled
Bool_t IsScaled() const
Definition: TGPicture.h:67
TGPicture::fScaled
Bool_t fScaled
Definition: TGPicture.h:42
TString
Definition: TString.h:136
TGSelectedPicture::TGSelectedPicture
TGSelectedPicture(const TGSelectedPicture &gp)
Definition: TGPicture.h:86
TString.h
TGPicturePool::fPicList
THashTable * fPicList
Definition: TGPicture.h:105
bool
GContext_t
Handle_t GContext_t
Definition: GuiTypes.h:37
kNone
const Handle_t kNone
Definition: GuiTypes.h:87
TGPicturePool::TGPicturePool
TGPicturePool(const TGPicturePool &)
copy constructor
Definition: TGPicture.cxx:54
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TGPicturePool::GetPicture
const TGPicture * GetPicture(const char *name)
Get a picture from the picture pool.
Definition: TGPicture.cxx:80
TGPicture::Print
void Print(Option_t *option="") const
Print picture info.
Definition: TGPicture.cxx:384
THashTable
Definition: THashTable.h:35
TGSelectedPicture::GetSelectedGC
static TGGC & GetSelectedGC()
Return selection graphics context in use.
Definition: TGPicture.cxx:437
TGSelectedPicture::fgSelectedGC
static TGGC * fgSelectedGC
Definition: TGPicture.h:83
TGPicturePool::GetPath
const char * GetPath() const
Definition: TGPicture.h:115
TGGC
Definition: TGGC.h:31
TGGC.h
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TGPicturePool::fClient
const TGClient * fClient
Definition: TGPicture.h:103
TGPicturePool
Definition: TGPicture.h:100
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
y
Double_t y[n]
Definition: legend1.C:17
ULong_t
unsigned long ULong_t
Definition: RtypesCore.h:55
TGPicture::fPic
Pixmap_t fPic
Definition: TGPicture.h:43
TGClient.h
TGPicture::fMask
Pixmap_t fMask
Definition: TGPicture.h:44
TGPicturePool::operator=
TGPicturePool & operator=(const TGPicturePool &)
assignment operator
Definition: TGPicture.cxx:65
unsigned int
TGPicturePool::~TGPicturePool
virtual ~TGPicturePool()
Delete picture cache.
Definition: TGPicture.cxx:291
TGPicture::fAttributes
PictureAttributes_t fAttributes
Definition: TGPicture.h:45
TObject::operator=
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition: TObject.h:268
PictureAttributes_t
Definition: GuiTypes.h:322
TObject.h
TGPicture::GetPicture
Pixmap_t GetPicture() const
Definition: TGPicture.h:65
TObject
Definition: TObject.h:37
Handle_t
ULong_t Handle_t
Definition: GuiTypes.h:25
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
name
char name[80]
Definition: TGX11.cxx:110
TGPicture::GetName
const char * GetName() const
Returns name of object.
Definition: TGPicture.h:62
TGSelectedPicture::fClient
const TGClient * fClient
Definition: TGPicture.h:81
TGPicture::~TGPicture
virtual ~TGPicture()
Delete picture object.
Definition: TGPicture.cxx:359
TRefCnt
Definition: TRefCnt.h:27
TGSelectedPicture::operator=
TGSelectedPicture & operator=(const TGSelectedPicture &gp)
Definition: TGPicture.h:88
TGPicturePool::FreePicture
void FreePicture(const TGPicture *pic)
Remove picture from cache if nobody is using it anymore.
Definition: TGPicture.cxx:275
TGPicture::GetHeight
UInt_t GetHeight() const
Definition: TGPicture.h:64
TGClient
Definition: TGClient.h:46
TGPicturePool::fPath
TString fPath
Definition: TGPicture.h:104
PictureAttributes_t::fHeight
UInt_t fHeight
Definition: GuiTypes.h:326
TGPicturePool::Print
void Print(Option_t *option="") const
List all pictures in the pool.
Definition: TGPicture.cxx:305