Skip to content

Commit 73a4c5d

Browse files
committed
Provide new methods in TVirtualPadPainter
`NewPage()` used only PS to start page `IsCocoa()` let check if cocoa backend is used, invoved in several places `ResizeDrawable()` to change gVirtualX created pixmap Provide `TGLPadPainter::ClearDrawable()` while now pad painter API used in painting Now gVirtualPS usage in TPad minimized only to Print() method.
1 parent cb7ffad commit 73a4c5d

File tree

8 files changed

+96
-29
lines changed

8 files changed

+96
-29
lines changed

core/base/inc/TVirtualPadPainter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class TVirtualPadPainter {
7979
//Currently, must be implemented only for X11/GDI
8080
virtual Int_t CreateDrawable(UInt_t w, UInt_t h) = 0;//gVirtualX->OpenPixmap
8181
virtual void ClearDrawable() = 0;//gVirtualX->Clear()
82+
virtual Int_t ResizeDrawable(Int_t /* device */, UInt_t /* w */, UInt_t /* h */) { return 0; } //gVirtualX->ResizePixmap
8283
virtual void CopyDrawable(Int_t device, Int_t px, Int_t py) = 0;
8384
virtual void DestroyDrawable(Int_t device) = 0;//gVirtualX->CloseWindow
8485
virtual void SelectDrawable(Int_t device) = 0;//gVirtualX->SelectWindow
@@ -91,6 +92,7 @@ class TVirtualPadPainter {
9192
virtual void InitPainter();
9293
virtual void InvalidateCS();
9394
virtual void LockPainter();
95+
virtual void NewPage() {}
9496

9597
//Now, drawing primitives.
9698
virtual void DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2) = 0;
@@ -124,6 +126,7 @@ class TVirtualPadPainter {
124126
virtual void OnPad(TVirtualPad *) {}
125127

126128
virtual Bool_t IsNative() const { return kFALSE; }
129+
virtual Bool_t IsCocoa() const { return kFALSE; }
127130

128131
static TVirtualPadPainter *PadPainter(Option_t *opt = "");
129132

graf2d/gpad/inc/TPadPainter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class TPadPainter : public TVirtualPadPainter {
7474
//2. "Off-screen management" part.
7575
Int_t CreateDrawable(UInt_t w, UInt_t h) override;
7676
void ClearDrawable() override;
77+
Int_t ResizeDrawable(Int_t device, UInt_t w, UInt_t h) override;
7778
void CopyDrawable(Int_t device, Int_t px, Int_t py) override;
7879
void DestroyDrawable(Int_t device) override;
7980
void SelectDrawable(Int_t device) override;
@@ -113,6 +114,9 @@ class TPadPainter : public TVirtualPadPainter {
113114

114115
Bool_t IsNative() const override { return kTRUE; }
115116

117+
Bool_t IsCocoa() const;
118+
119+
116120
private:
117121
//Let's make this clear:
118122
TPadPainter(const TPadPainter &) = delete;

graf2d/gpad/inc/TPadPainterPS.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class TPadPainterPS : public TVirtualPadPainter {
8181
void DestroyDrawable(Int_t device) override;
8282
void SelectDrawable(Int_t device) override;
8383

84+
void NewPage() override;
85+
8486
//TASImage support (noop for a non-gl pad).
8587
void DrawPixels(const unsigned char *pixelData, UInt_t width, UInt_t height,
8688
Int_t dstX, Int_t dstY, Bool_t enableAlphaBlending) override;

graf2d/gpad/src/TPad.cxx

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -741,8 +741,14 @@ void TPad::Clear(Option_t *option)
741741
getchar();
742742
}
743743

744-
if (!gPad->IsBatch() && GetPainter()) GetPainter()->ClearDrawable();
745-
if (gVirtualPS && gPad == gPad->GetCanvas()) gVirtualPS->NewPage();
744+
auto pp = GetPainter();
745+
// If pad painter uses PS, ClearDrawable() start new page
746+
if (pp) {
747+
if (pp->IsNative())
748+
pp->ClearDrawable();
749+
else if (this == GetCanvas())
750+
pp->NewPage();
751+
}
746752

747753
PaintBorder(GetFillColor(), kTRUE);
748754
fCrosshairPos = 0;
@@ -3199,9 +3205,12 @@ void TPad::GetRangeAxis(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t
31993205

32003206
void TPad::HighLight(Color_t color, Bool_t set)
32013207
{
3202-
if (gVirtualPS && gVirtualPS->TestBit(kPrintingPS)) return;
3208+
if (auto pp = GetPainter())
3209+
if(!pp->IsNative())
3210+
return;
32033211

3204-
if (color <= 0) return;
3212+
if (color <= 0)
3213+
return;
32053214

32063215
AbsCoordinates(kTRUE);
32073216

@@ -3220,10 +3229,8 @@ void TPad::HighLight(Color_t color, Bool_t set)
32203229
// momentarily such that when DrawClone is called, it is
32213230
// not the right value (for DrawClone). Should be FIXED.
32223231
gROOT->SetSelectedPad(this);
3223-
if (GetBorderMode()>0) {
3224-
if (set) PaintBorder(-color, kFALSE);
3225-
else PaintBorder(-GetFillColor(), kFALSE);
3226-
}
3232+
if (GetBorderMode() > 0)
3233+
PaintBorder(set ? -color : -GetFillColor(), kFALSE);
32273234
}
32283235

32293236
AbsCoordinates(kFALSE);
@@ -3811,7 +3818,7 @@ void TPad::PaintBorder(Color_t color, Bool_t /* tops */)
38113818
//With Cocoa we have a transparency. But we also have
38123819
//pixmaps, and if you just paint a new content over the old one
38133820
//with alpha < 1., you'll be able to see the old content.
3814-
if (pp->IsNative() && gVirtualX->InheritsFrom("TGCocoa"))
3821+
if (pp->IsNative() && pp->IsCocoa())
38153822
pp->ClearDrawable();
38163823

38173824
PaintBox(fX1, fY1, fX2, fY2);
@@ -3917,7 +3924,7 @@ void TPad::PaintBorder(Color_t color, Bool_t /* tops */)
39173924
}
39183925

39193926
////////////////////////////////////////////////////////////////////////////////
3920-
/// Paint a frame border with Postscript.
3927+
/// Paint a frame border with Postscript - no longer used
39213928

39223929
void TPad::PaintBorderPS(Double_t xl,Double_t yl,Double_t xt,Double_t yt,Int_t bmode,Int_t bsize,Int_t dark,Int_t light)
39233930
{
@@ -4028,7 +4035,9 @@ void TPad::PaintModified()
40284035
TContext ctxt(this, kTRUE);
40294036
if (IsModified() || IsTransparent()) {
40304037
if ((fFillStyle < 3026) && (fFillStyle > 3000)) {
4031-
if (!gPad->IsBatch() && GetPainter()) GetPainter()->ClearDrawable();
4038+
auto pp = GetPainter();
4039+
if (pp && pp->IsNative())
4040+
pp->ClearDrawable();
40324041
}
40334042
PaintBorder(GetFillColor(), kTRUE);
40344043
}
@@ -4129,7 +4138,7 @@ void TPad::PaintBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Option_t
41294138
//ignore this style option when this is the canvas itself
41304139
if (this == fMother) {
41314140
//It's clear, that virtual X checks a style (4000) and will render a hollow rect!
4132-
if (gVirtualX->InheritsFrom("TGCocoa")) {
4141+
if (pp->IsCocoa()) {
41334142
style0 = style;
41344143
pp->SetFillStyle(1000);
41354144
}
@@ -5946,9 +5955,10 @@ void TPad::ResizePad(Option_t *option)
59465955
if (gPad->IsBatch())
59475956
fPixmapID = 0;
59485957
else {
5949-
if (GetPainter()){
5950-
GetPainter()->SetLineWidth(-1);
5951-
GetPainter()->SetTextSize(-1);
5958+
auto pp = GetPainter();
5959+
if (pp){
5960+
pp->SetLineWidth(-1);
5961+
pp->SetTextSize(-1);
59525962
}
59535963
// create or re-create off-screen pixmap
59545964
if (fPixmapID) {
@@ -5972,13 +5982,12 @@ void TPad::ResizePad(Option_t *option)
59725982
h = 10;
59735983
}
59745984
if (fPixmapID == -1) { // this case is handled via the ctor
5975-
if (GetPainter()) fPixmapID = GetPainter()->CreateDrawable(w, h);
5985+
if (pp)
5986+
fPixmapID = pp->CreateDrawable(w, h);
59765987
} else {
5977-
if (gVirtualX) {
5978-
if (gVirtualX->ResizePixmap(fPixmapID, w, h)) {
5979-
Resized();
5980-
Modified(kTRUE);
5981-
}
5988+
if (pp && pp->ResizeDrawable(fPixmapID, w, h)) {
5989+
Resized();
5990+
Modified(kTRUE);
59825991
}
59835992
}
59845993
}

graf2d/gpad/src/TPadPainter.cxx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,23 @@ Int_t TPadPainter::CreateDrawable(UInt_t w, UInt_t h)
361361
return gVirtualX->OpenPixmap(Int_t(w), Int_t(h));
362362
}
363363

364+
////////////////////////////////////////////////////////////////////////////////
365+
/// Resize a gVirtualX Pixmap.
366+
367+
Int_t TPadPainter::ResizeDrawable(Int_t device, UInt_t w, UInt_t h)
368+
{
369+
return gVirtualX->ResizePixmap(device, w, h);
370+
}
371+
372+
373+
////////////////////////////////////////////////////////////////////////////////
374+
/// Returns true when cocoa backend is used
375+
376+
Bool_t TPadPainter::IsCocoa() const
377+
{
378+
return gVirtualX->InheritsFrom("TGCocoa");
379+
}
380+
364381

365382
////////////////////////////////////////////////////////////////////////////////
366383
/// Clear the current gVirtualX window.

graf2d/gpad/src/TPadPainterPS.cxx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ Int_t TPadPainterPS::CreateDrawable(UInt_t, UInt_t)
332332

333333

334334
////////////////////////////////////////////////////////////////////////////////
335-
/// Clear the current gVirtualX window - not implemented
335+
/// Clear the current gVirtualX window - noop for PS
336336

337337
void TPadPainterPS::ClearDrawable()
338338
{
@@ -362,6 +362,17 @@ void TPadPainterPS::SelectDrawable(Int_t)
362362
{
363363
}
364364

365+
366+
////////////////////////////////////////////////////////////////////////////////
367+
/// Start new page on PS output
368+
369+
void TPadPainterPS::NewPage()
370+
{
371+
fPS->NewPage();
372+
}
373+
374+
375+
365376
////////////////////////////////////////////////////////////////////////////////
366377
///Noop, for non-gl pad TASImage calls gVirtualX->CopyArea.
367378

graf3d/gl/inc/TGLPadPainter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class TGLPadPainter : public TVirtualPadPainter {
9696
//2. "Off-screen management" part.
9797
Int_t CreateDrawable(UInt_t w, UInt_t h) override;
9898
void ClearDrawable() override;
99+
Int_t ResizeDrawable(Int_t device, UInt_t w, UInt_t h) override;
99100
void CopyDrawable(Int_t device, Int_t px, Int_t py) override;
100101
void DestroyDrawable(Int_t device) override;
101102
void SelectDrawable(Int_t device) override;
@@ -135,6 +136,8 @@ class TGLPadPainter : public TVirtualPadPainter {
135136

136137
Bool_t IsNative() const override { return kTRUE; }
137138

139+
Bool_t IsCocoa() const override;
140+
138141
private:
139142

140143
//Attention! GL_PROJECTION will become

graf3d/gl/src/TGLPadPainter.cxx

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,40 +311,58 @@ void TGLPadPainter::SetMarkerSize(Size_t msize)
311311
gVirtualX->SetMarkerSize(msize);
312312
}
313313

314-
315-
316-
317314
/*
318315
"Pixmap" part of TGLPadPainter.
319316
*/
320317

321318
////////////////////////////////////////////////////////////////////////////////
322319
///Not required at the moment.
323320

324-
Int_t TGLPadPainter::CreateDrawable(UInt_t/*w*/, UInt_t/*h*/)
321+
Int_t TGLPadPainter::CreateDrawable(UInt_t /* w */, UInt_t /* h */)
325322
{
323+
// return gVirtualX->OpenPixmap(Int_t(w), Int_t(h));
326324
return 0;
327325
}
328326

329327
////////////////////////////////////////////////////////////////////////////////
330-
///Not required at the moment.
328+
/// Resize a gVirtualX Pixmap.
329+
330+
Int_t TGLPadPainter::ResizeDrawable(Int_t device, UInt_t w, UInt_t h)
331+
{
332+
return gVirtualX->ResizePixmap(device, w, h);
333+
}
334+
335+
////////////////////////////////////////////////////////////////////////////////
336+
/// Call gVirtualX->ClearWindow()
331337

332338
void TGLPadPainter::ClearDrawable()
333339
{
340+
gVirtualX->ClearWindow();
341+
}
342+
343+
////////////////////////////////////////////////////////////////////////////////
344+
/// Returns true when cocoa backend is used
345+
346+
Bool_t TGLPadPainter::IsCocoa() const
347+
{
348+
return gVirtualX->InheritsFrom("TGCocoa");
334349
}
335350

336351
////////////////////////////////////////////////////////////////////////////////
337352
///Not required at the moment.
338353

339-
void TGLPadPainter::CopyDrawable(Int_t /*device*/, Int_t /*px*/, Int_t /*py*/)
354+
void TGLPadPainter::CopyDrawable(Int_t /* device */, Int_t /* px */, Int_t /* py */)
340355
{
356+
// gVirtualX->CopyPixmap(device, px, py);
341357
}
342358

343359
////////////////////////////////////////////////////////////////////////////////
344360
///Not required at the moment.
345361

346-
void TGLPadPainter::DestroyDrawable(Int_t /*device*/)
362+
void TGLPadPainter::DestroyDrawable(Int_t /* device */)
347363
{
364+
// gVirtualX->SelectWindow(device);
365+
// gVirtualX->ClosePixmap();
348366
}
349367

350368
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)