Skip to content

Commit f4ef7ae

Browse files
committed
[webcanv] use TPadPainterBase for custom classes support
While now objects painting always runs though pad painter, only this instance is enough. No need for TVirtualPS emulation. Also attributes handling now done in base class. Simplify many places of the web canvas
1 parent 652008f commit f4ef7ae

File tree

8 files changed

+48
-298
lines changed

8 files changed

+48
-298
lines changed

gui/webgui6/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ ROOT_STANDARD_LIBRARY_PACKAGE(WebGui6
1616
TWebPadOptions.h
1717
TWebPadPainter.h
1818
TWebPainting.h
19-
TWebPS.h
2019
TWebSnapshot.h
2120
SOURCES
2221
src/TWebCanvas.cxx
2322
src/TWebControlBar.cxx
2423
src/TWebMenuItem.cxx
2524
src/TWebPadPainter.cxx
2625
src/TWebPainting.cxx
27-
src/TWebPS.cxx
2826
src/TWebSnapshot.cxx
2927
DEPENDENCIES
3028
Core

gui/webgui6/inc/LinkDef.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#pragma link C++ class TWebPadClick+;
2626

2727
#pragma link C++ class TWebPadPainter+;
28-
#pragma link C++ class TWebPS+;
2928
#pragma link C++ class TWebPainting+;
3029
#pragma link C++ class TWebSnapshot+;
3130
#pragma link C++ class TPadWebSnapshot+;

gui/webgui6/inc/TWebCanvas.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
class TPad;
2929
class TPadWebSnapshot;
30-
class TWebPS;
30+
class TWebPainting;
3131
class TObjLink;
3232
class TExec;
3333
class TWebCanvasTimer;
@@ -139,7 +139,7 @@ friend class TWebCanvasTimer;
139139
void AddColorsPalette(TPadWebSnapshot &master);
140140
void AddCustomFonts(TPadWebSnapshot &master);
141141

142-
void CreateObjectSnapshot(TPadWebSnapshot &master, TPad *pad, TObject *obj, const char *opt, TWebPS *masterps = nullptr);
142+
void CreateObjectSnapshot(TPadWebSnapshot &master, TPad *pad, TObject *obj, const char *opt, TWebPainting *masterps = nullptr);
143143
void CreatePadSnapshot(TPadWebSnapshot &paddata, TPad *pad, Long64_t version, PadPaintingReady_t func);
144144

145145
void CheckPadModified(TPad *pad);

gui/webgui6/inc/TWebPS.h

Lines changed: 0 additions & 72 deletions
This file was deleted.

gui/webgui6/inc/TWebPadPainter.h

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,21 @@
1111
#ifndef ROOT_TWebPadPainter
1212
#define ROOT_TWebPadPainter
1313

14-
#include "TVirtualPadPainter.h"
14+
#include "TPadPainterBase.h"
1515

16-
#include "TAttLine.h"
17-
#include "TAttFill.h"
18-
#include "TAttText.h"
19-
#include "TAttMarker.h"
2016
#include <string>
2117

2218
#include "TWebPainting.h"
23-
#include "TWebPS.h"
2419

2520
class TWebCanvas;
2621

27-
class TWebPadPainter : public TVirtualPadPainter, public TAttLine, public TAttFill, public TAttText, public TAttMarker {
22+
class TWebPadPainter : public TPadPainterBase {
2823

2924
friend class TWebCanvas;
3025

3126
protected:
3227

3328
TWebPainting *fPainting{nullptr}; ///<! object to store all painting, owned by TWebPS object
34-
TWebPS *fPS{nullptr}; ///<! current TWebPS instance
3529

3630
enum { attrLine = 0x1, attrFill = 0x2, attrMarker = 0x4, attrText = 0x8, attrAll = 0xf };
3731

@@ -41,51 +35,10 @@ friend class TWebCanvas;
4135

4236
TWebPadPainter() {} // NOLINT: not allowed to use = default because of TObject::kIsOnHeap detection, see ROOT-10300
4337

44-
void SetPainting(TWebPainting *p, TWebPS *ps) { fPainting = p; fPS = ps; }
45-
46-
//Final overrides for TVirtualPadPainter pure virtual functions.
47-
//1. Part, which simply catch attributes.
48-
//Line attributes.
49-
Color_t GetLineColor() const override { return fPS ? fPS->GetLineColor() : TAttLine::GetLineColor(); }
50-
Style_t GetLineStyle() const override { return fPS ? fPS->GetLineStyle() : TAttLine::GetLineStyle(); }
51-
Width_t GetLineWidth() const override { return fPS ? fPS->GetLineWidth() : TAttLine::GetLineWidth(); }
52-
53-
void SetLineColor(Color_t lcolor) override { if (fPS) fPS->SetLineColor(lcolor); else TAttLine::SetLineColor(lcolor); }
54-
void SetLineStyle(Style_t lstyle) override { if (fPS) fPS->SetLineStyle(lstyle); else TAttLine::SetLineStyle(lstyle); }
55-
void SetLineWidth(Width_t lwidth) override { if (fPS) fPS->SetLineWidth(lwidth); else TAttLine::SetLineWidth(lwidth); }
56-
57-
//Fill attributes.
58-
Color_t GetFillColor() const override { return fPS ? fPS->GetFillColor() : TAttFill::GetFillColor(); }
59-
Style_t GetFillStyle() const override { return fPS ? fPS->GetFillStyle() : TAttFill::GetFillStyle(); }
60-
Bool_t IsTransparent() const override { return fPS ? fPS->IsTransparent() : TAttFill::IsTransparent(); }
61-
62-
void SetFillColor(Color_t fcolor) override { if (fPS) fPS->SetFillColor(fcolor); else TAttFill::SetFillColor(fcolor); }
63-
void SetFillStyle(Style_t fstyle) override { if (fPS) fPS->SetFillStyle(fstyle); else TAttFill::SetFillStyle(fstyle); }
64-
void SetOpacity(Int_t percent) override { if (fPS) fPS->SetFillStyle(4000 + percent); else TAttFill::SetFillStyle(4000 + percent); }
65-
66-
//Text attributes.
67-
Short_t GetTextAlign() const override { return fPS ? fPS->GetTextAlign() : TAttText::GetTextAlign(); }
68-
Float_t GetTextAngle() const override { return fPS ? fPS->GetTextAngle() : TAttText::GetTextAngle(); }
69-
Color_t GetTextColor() const override { return fPS ? fPS->GetTextColor() : TAttText::GetTextColor(); }
70-
Font_t GetTextFont() const override { return fPS ? fPS->GetTextFont() : TAttText::GetTextFont(); }
71-
Float_t GetTextSize() const override { return fPS ? fPS->GetTextSize() : TAttText::GetTextSize(); }
72-
Float_t GetTextMagnitude() const override { return 0; }
73-
74-
void SetTextAlign(Short_t align) override { if (fPS) fPS->SetTextAlign(align); else TAttText::SetTextAlign(align); }
75-
void SetTextAngle(Float_t tangle) override { if (fPS) fPS->SetTextAngle(tangle); else TAttText::SetTextAngle(tangle); }
76-
void SetTextColor(Color_t tcolor) override { if (fPS) fPS->SetTextColor(tcolor); else TAttText::SetTextColor(tcolor); }
77-
void SetTextFont(Font_t tfont) override { if (fPS) fPS->SetTextFont(tfont); else TAttText::SetTextFont(tfont); }
78-
void SetTextSize(Float_t tsize) override { if (fPS) fPS->SetTextSize(tsize); else TAttText::SetTextSize(tsize); }
79-
void SetTextSizePixels(Int_t npixels) override { if (fPS) fPS->SetTextSizePixels(npixels); else TAttText::SetTextSizePixels(npixels); }
80-
81-
//Marker attributes
82-
Color_t GetMarkerColor() const override { return fPS ? fPS->GetMarkerColor() : TAttMarker::GetMarkerColor(); }
83-
Style_t GetMarkerStyle() const override { return fPS ? fPS->GetMarkerStyle() : TAttMarker::GetMarkerStyle(); }
84-
Size_t GetMarkerSize() const override { return fPS ? fPS->GetMarkerSize() : TAttMarker::GetMarkerSize(); }
85-
86-
void SetMarkerColor(Color_t mcolor) override { if (fPS) fPS->SetMarkerColor(mcolor); else TAttMarker::SetMarkerColor(mcolor); }
87-
void SetMarkerStyle(Style_t mstyle) override { if (fPS) fPS->SetMarkerStyle(mstyle); else TAttMarker::SetMarkerStyle(mstyle); }
88-
void SetMarkerSize(Size_t msize) override { if (fPS) fPS->SetMarkerSize(msize); else TAttMarker::SetMarkerSize(msize); }
38+
void SetPainting(TWebPainting *p) { fPainting = p; }
39+
40+
41+
void SetOpacity(Int_t percent) override;
8942

9043
//2. "Off-screen management" part.
9144
Int_t CreateDrawable(UInt_t, UInt_t) override { return -1; }

gui/webgui6/src/TWebCanvas.cxx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#include "TWebSnapshot.h"
1414
#include "TWebPadPainter.h"
15-
#include "TWebPS.h"
1615
#include "TWebMenuItem.h"
1716
#include "ROOT/RWebWindowsManager.hxx"
1817
#include "THttpServer.h"
@@ -54,6 +53,7 @@
5453
#include "TView.h"
5554
#include "TExec.h"
5655
#include "TVirtualX.h"
56+
#include "TVirtualPS.h"
5757
#include "TMath.h"
5858
#include "TTimer.h"
5959
#include "TThread.h"
@@ -511,7 +511,7 @@ bool TWebCanvas::IsCustomClass(const TClass *cl)
511511
//////////////////////////////////////////////////////////////////////////////////////////////////
512512
/// Creates representation of the object for painting in web browser
513513

514-
void TWebCanvas::CreateObjectSnapshot(TPadWebSnapshot &master, TPad *pad, TObject *obj, const char *opt, TWebPS *masterps)
514+
void TWebCanvas::CreateObjectSnapshot(TPadWebSnapshot &master, TPad *pad, TObject *obj, const char *opt, TWebPainting *masterps)
515515
{
516516
if (IsJSSupportedClass(obj, masterps != nullptr)) {
517517
master.NewPrimitive(obj, opt).SetSnapshot(TWebSnapshot::kObject, obj);
@@ -538,15 +538,15 @@ void TWebCanvas::CreateObjectSnapshot(TPadWebSnapshot &master, TPad *pad, TObjec
538538

539539
TVirtualPS *saveps = gVirtualPS;
540540

541-
TWebPS *webps = masterps;
541+
auto painting = masterps;
542542
if (!masterps) {
543-
webps = new TWebPS;
544-
webps->GetPainting()->SetClassName(obj->ClassName());
545-
webps->GetPainting()->SetObjectName(obj->GetName());
543+
painting = new TWebPainting;
544+
painting->SetClassName(obj->ClassName());
545+
painting->SetObjectName(obj->GetName());
546546
}
547-
gVirtualPS = webps;
547+
gVirtualPS = nullptr;
548548
if (painter)
549-
painter->SetPainting(webps->GetPainting(), webps);
549+
painter->SetPainting(painting);
550550

551551
// calling Paint function for the object
552552
obj->Paint(opt);
@@ -559,17 +559,18 @@ void TWebCanvas::CreateObjectSnapshot(TPadWebSnapshot &master, TPad *pad, TObjec
559559
}
560560

561561
if (painter)
562-
painter->SetPainting(nullptr, nullptr);
562+
painter->SetPainting(nullptr);
563563

564564
gVirtualPS = saveps;
565565

566566
fPadsStatus[pad]._has_specials = true;
567567

568568
// if there are master PS, do not create separate entries
569569
if (!masterps) {
570-
if (!webps->IsEmptyPainting())
571-
master.NewPrimitive(obj, opt).SetSnapshot(TWebSnapshot::kSVG, webps->TakePainting(), kTRUE);
572-
delete webps;
570+
if (!painting->IsEmpty())
571+
master.NewPrimitive(obj, opt).SetSnapshot(TWebSnapshot::kSVG, painting, kTRUE);
572+
else
573+
delete painting;
573574
}
574575
}
575576

@@ -685,7 +686,7 @@ void TWebCanvas::CreatePadSnapshot(TPadWebSnapshot &paddata, TPad *pad, Long64_t
685686

686687
TList *primitives = pad->GetListOfPrimitives();
687688

688-
TWebPS masterps;
689+
auto masterps = std::make_unique<TWebPainting>();
689690
bool usemaster = primitives ? (primitives->GetSize() > fPrimitivesMerge) : false;
690691

691692
TIter iter(primitives);
@@ -833,10 +834,10 @@ void TWebCanvas::CreatePadSnapshot(TPadWebSnapshot &paddata, TPad *pad, Long64_t
833834
primitives->Add(polargram, polargram_drawopt);
834835

835836
auto flush_master = [&]() {
836-
if (!usemaster || masterps.IsEmptyPainting()) return;
837+
if (!usemaster || masterps->IsEmpty()) return;
837838

838-
paddata.NewPrimitive(pad).SetSnapshot(TWebSnapshot::kSVG, masterps.TakePainting(), kTRUE);
839-
masterps.CreatePainting(); // create for next operations
839+
paddata.NewPrimitive(pad).SetSnapshot(TWebSnapshot::kSVG, masterps.release(), kTRUE);
840+
masterps = std::make_unique<TWebPainting>(); // create for next operations
840841
};
841842

842843
auto check_cutg_in_options = [&](const TString &opt) {
@@ -1156,7 +1157,7 @@ void TWebCanvas::CreatePadSnapshot(TPadWebSnapshot &paddata, TPad *pad, Long64_t
11561157
flush_master();
11571158
paddata.NewPrimitive(obj, iter.GetOption()).SetSnapshot(TWebSnapshot::kObject, obj);
11581159
} else {
1159-
CreateObjectSnapshot(paddata, pad, obj, iter.GetOption(), usemaster ? &masterps : nullptr);
1160+
CreateObjectSnapshot(paddata, pad, obj, iter.GetOption(), usemaster ? masterps.get() : nullptr);
11601161
}
11611162
}
11621163

@@ -1794,8 +1795,7 @@ void TWebCanvas::ProcessExecs(TPad *pad, TExec *extra)
17941795
return;
17951796

17961797
auto saveps = gVirtualPS;
1797-
TWebPS ps;
1798-
gVirtualPS = &ps;
1798+
gVirtualPS = nullptr;
17991799

18001800
auto savex = gVirtualX;
18011801
TVirtualX x;

0 commit comments

Comments
 (0)