44 TGGC *TGSelectedPicture::fgSelectedGC = 0;
47 ClassImp(TGSelectedPicture);
48 ClassImp(TGPicturePool);
54 TGPicturePool::TGPicturePool(
const TGPicturePool& pp) :
65 TGPicturePool& TGPicturePool::operator=(
const TGPicturePool& pp)
68 TObject::operator=(pp);
80 const TGPicture *TGPicturePool::GetPicture(
const char *name)
83 fPicList =
new THashTable(50);
87 TString ext = strrchr(pname,
'.');
91 char *pxname = gSystem->ExpandPathName(gSystem->UnixPathName(pname));
96 TGPicture *pic = (TGPicture *)fPicList->FindObject(pname);
97 if (pic && !pic->IsScaled()) {
98 if (pic->fPic == kNone)
104 char *picnam = gSystem->Which(fPath, pname, kReadPermission);
106 pic =
new TGPicture(pname);
107 pic->fAttributes.fColormap = fClient->GetDefaultColormap();
108 pic->fAttributes.fCloseness = 40000;
109 pic->fAttributes.fMask = kPASize | kPAColormap | kPACloseness;
114 TImage *img = TImage::Open(picnam);
116 pic =
new TGPicture(pname);
117 pic->fAttributes.fColormap = fClient->GetDefaultColormap();
118 pic->fAttributes.fCloseness = 40000;
119 pic->fAttributes.fMask = kPASize | kPAColormap | kPACloseness;
125 pic =
new TGPicture(pname, img->GetPixmap(), img->GetMask());
137 const TGPicture *TGPicturePool::GetPicture(
const char *name,
138 UInt_t new_width, UInt_t new_height)
141 fPicList =
new THashTable(50);
143 TString pname = name;
145 TString ext = strrchr(pname,
'.');
149 char *pxname = gSystem->ExpandPathName(gSystem->UnixPathName(pname));
154 const char *hname = TGPicture::HashName(pname, new_width, new_height);
155 TGPicture *pic = (TGPicture *)fPicList->FindObject(hname);
156 if (pic && pic->GetWidth() == new_width && pic->GetHeight() == new_height) {
157 if (pic->fPic == kNone)
163 char *picnam = gSystem->Which(fPath, pname, kReadPermission);
165 pic =
new TGPicture(hname, kTRUE);
166 pic->fAttributes.fColormap = fClient->GetDefaultColormap();
167 pic->fAttributes.fCloseness = 40000;
168 pic->fAttributes.fMask = kPASize | kPAColormap | kPACloseness;
169 pic->fAttributes.fWidth = new_width;
170 pic->fAttributes.fHeight = new_height;
175 TImage *img = TImage::Open(picnam);
177 pic =
new TGPicture(hname, kTRUE);
178 pic->fAttributes.fColormap = fClient->GetDefaultColormap();
179 pic->fAttributes.fCloseness = 40000;
180 pic->fAttributes.fMask = kPASize | kPAColormap | kPACloseness;
181 pic->fAttributes.fWidth = new_width;
182 pic->fAttributes.fHeight = new_height;
188 img->Scale(new_width, new_height);
190 pic =
new TGPicture(hname, img->GetPixmap(), img->GetMask());
202 const TGPicture *TGPicturePool::GetPicture(
const char *name, Pixmap_t pxmap,
206 fPicList =
new THashTable(50);
211 gVirtualX->GetWindowSize(pxmap, xy, xy, w, h);
213 const char *hname = TGPicture::HashName(name, w, h);
214 TGPicture *pic = (TGPicture *)fPicList->FindObject(hname);
221 pic =
new TGPicture(hname, pxmap, mask);
232 const TGPicture *TGPicturePool::GetPicture(
const char *name,
char **xpm)
241 fPicList =
new THashTable(50);
244 while (isspace((
int)*ptr)) ++ptr;
247 while (isspace((
int)*ptr)) ++ptr;
250 const char *hname = TGPicture::HashName(name, w, h);
251 TGPicture *pic = (TGPicture *)fPicList->FindObject(hname);
257 TImage *img = TImage::Open(xpm);
259 pic =
new TGPicture(hname, kTRUE);
260 pic->fAttributes.fColormap = fClient->GetDefaultColormap();
261 pic->fAttributes.fCloseness = 40000;
262 pic->fAttributes.fMask = kPASize | kPAColormap | kPACloseness;
263 pic->fAttributes.fWidth = w;
264 pic->fAttributes.fHeight = h;
269 pic =
new TGPicture(hname, img->GetPixmap(), img->GetMask());
277 void TGPicturePool::FreePicture(
const TGPicture *fpic)
279 if (!fPicList)
return;
281 TGPicture *pic = (TGPicture *)fPicList->FindObject(fpic);
283 if (pic->RemoveReference() == 0) {
284 fPicList->Remove(pic);
293 TGPicturePool::~TGPicturePool()
301 ROOT::CallRecursiveRemoveIfNeeded(*
this);
307 void TGPicturePool::Print(Option_t *)
const
312 Info(
"Print",
"no pictures in picture pool");
318 TGPicture::TGPicture(
const char *name, Pixmap_t pxmap, Pixmap_t mask)
326 fAttributes.fColormap = gClient->GetDefaultColormap();
327 fAttributes.fCloseness = 40000;
328 fAttributes.fMask = kPASize | kPAColormap | kPACloseness;
329 fAttributes.fPixels = 0;
330 fAttributes.fDepth = 0;
331 fAttributes.fNpixels = 0;
332 fAttributes.fXHotspot = 0;
333 fAttributes.fYHotspot = 0;
335 gVirtualX->GetWindowSize(fPic, xy, xy, fAttributes.fWidth, fAttributes.fHeight);
342 void TGPicture::Draw(Handle_t
id, GContext_t gc, Int_t x, Int_t y)
const
346 gcv.fMask = kGCClipMask | kGCClipXOrigin | kGCClipYOrigin;
347 gcv.fClipMask = fMask;
348 gcv.fClipXOrigin = x;
349 gcv.fClipYOrigin = y;
350 gVirtualX->ChangeGC(gc, &gcv);
351 gVirtualX->CopyArea(fPic,
id, gc, 0, 0, fAttributes.fWidth, fAttributes.fHeight,
353 gcv.fMask = kGCClipMask;
354 gcv.fClipMask = kNone;
355 gVirtualX->ChangeGC(gc, &gcv);
361 TGPicture::~TGPicture()
364 gVirtualX->DeletePixmap(fPic);
366 gVirtualX->DeletePixmap(fMask);
367 if (fAttributes.fPixels)
368 delete [] fAttributes.fPixels;
375 const char *TGPicture::HashName(
const char *name, Int_t width, Int_t height)
377 static TString hashName;
379 hashName.Form(
"%s__%dx%d", name, width, height);
380 return hashName.Data();
386 void TGPicture::Print(Option_t *)
const
388 Printf(
"TGPicture: %s,%sref cnt = %u %lx", GetName(),
389 fScaled ?
" scaled, " :
" ", References(), fPic);
396 TGSelectedPicture::TGSelectedPicture(
const TGClient *client,
const TGPicture *p) :
403 Window_t root = fClient->GetDefaultRoot()->GetId();
408 fPic = gVirtualX->CreatePixmap(root, w, h);
409 fMask = p->GetMask();
411 fAttributes.fWidth = w;
412 fAttributes.fHeight = h;
414 gVirtualX->CopyArea(p->GetPicture(), fPic, GetSelectedGC()(), 0, 0, w, h, 0, 0);
416 gcv.fMask = kGCClipMask | kGCClipXOrigin | kGCClipYOrigin;
417 gcv.fClipMask = p->GetMask();
418 gcv.fClipXOrigin = 0;
419 gcv.fClipYOrigin = 0;
420 GetSelectedGC().SetAttributes(&gcv);
422 gVirtualX->FillRectangle(fPic, GetSelectedGC()(), 0, 0, w, h);
424 GetSelectedGC().SetClipMask(kNone);
430 TGSelectedPicture::~TGSelectedPicture()
439 TGGC &TGSelectedPicture::GetSelectedGC()
442 fgSelectedGC =
new TGGC(*gClient->GetResourcePool()->GetFrameGC());
443 fgSelectedGC->SetForeground(gClient->GetResourcePool()->GetSelectedBgndColor());
444 fgSelectedGC->SetBackground(gClient->GetResourcePool()->GetBlackColor());
445 fgSelectedGC->SetFillStyle(kFillStippled);
446 fgSelectedGC->SetStipple(gClient->GetResourcePool()->GetCheckeredBitmap());
448 return *fgSelectedGC;