diff --git a/graf2d/gpadv7/inc/ROOT/RDrawable.hxx b/graf2d/gpadv7/inc/ROOT/RDrawable.hxx index e53d7e00710c77ea702be3e50b36523c03d87288..ddb620d851799d55e36a4c1c560090483f95c01a 100644 --- a/graf2d/gpadv7/inc/ROOT/RDrawable.hxx +++ b/graf2d/gpadv7/inc/ROOT/RDrawable.hxx @@ -98,14 +98,14 @@ public: class RDrawable { -friend class RPadBase; // to access Display method +friend class RPadBase; // to access Display method and IsFrameRequired friend class RAttrBase; friend class RStyle; friend class RLegend; // to access CollectShared method private: RAttrMap fAttr; ///< attributes values - std::weak_ptr<RStyle> fStyle; ///<! style applied for RDrawable + std::weak_ptr<RStyle> fStyle; ///<! style applied for RDrawable, not stored when canvas is saved std::string fCssType; ///<! drawable type, not stored in the root file, must be initialized in constructor std::string fCssClass; ///< user defined drawable class, can later go inside map std::string fId; ///< optional object identifier, may be used in CSS as well @@ -114,6 +114,8 @@ protected: virtual void CollectShared(Internal::RIOSharedVector_t &) {} + virtual bool IsFrameRequired() const { return false; } + RAttrMap &GetAttrMap() { return fAttr; } const RAttrMap &GetAttrMap() const { return fAttr; } diff --git a/graf2d/gpadv7/inc/ROOT/RPadBase.hxx b/graf2d/gpadv7/inc/ROOT/RPadBase.hxx index 75d9815cf932a210f7dc63a1f7cc419635f38c8a..7b75ec844aee3858ffd85b8050b09feffbc75034 100644 --- a/graf2d/gpadv7/inc/ROOT/RPadBase.hxx +++ b/graf2d/gpadv7/inc/ROOT/RPadBase.hxx @@ -50,6 +50,12 @@ private: /// Disable assignment. RPadBase &operator=(const RPadBase &) = delete; + void TestIfFrameRequired(const RDrawable *drawable) + { + if (drawable->IsFrameRequired()) + GetOrCreateFrame(); + } + protected: /// Allow derived classes to default construct a RPadBase. RPadBase() : RDrawable("pad") {} @@ -79,6 +85,8 @@ public: { auto drawable = std::make_shared<T>(args...); + TestIfFrameRequired(drawable.get()); + fPrimitives.emplace_back(drawable); return drawable; @@ -87,20 +95,24 @@ public: /// Add existing drawable instance to canvas auto Draw(std::shared_ptr<RDrawable> &&drawable) { + TestIfFrameRequired(drawable.get()); + fPrimitives.emplace_back(std::move(drawable)); return fPrimitives.back().get_shared(); } - /// Add something to be painted. - /// The pad observes what's lifetime through a weak pointer. - /// Drawing options will be constructed through `args`, which can be empty for default-constructed options. + /// Add object to be painted. + /// Correspondent drawable will be created via GetDrawable() function which should be defined and be accessed at calling time. + /// If required, extra arguments for GetDrawable() function can be provided. template <class T, class... ARGS> auto Draw(const std::shared_ptr<T> &what, ARGS... args) { // Requires GetDrawable(what) to be known! auto drawable = GetDrawable(what, args...); + TestIfFrameRequired(drawable.get()); + fPrimitives.emplace_back(drawable); return drawable; diff --git a/graf2d/primitivesv7/inc/ROOT/RFrameTitle.hxx b/graf2d/primitivesv7/inc/ROOT/RFrameTitle.hxx index 2683cbd5059e59b9b1236ed86359a1e09ee67860..ef85964a38d49e1c39688da25e1140c355d09026 100644 --- a/graf2d/primitivesv7/inc/ROOT/RFrameTitle.hxx +++ b/graf2d/primitivesv7/inc/ROOT/RFrameTitle.hxx @@ -28,7 +28,7 @@ namespace Experimental { */ -class RFrameTitle : public RDrawable { +class RFrameTitle final : public RDrawable { class RTitleAttrs : public RAttrBase { friend class RFrameTitle; @@ -39,6 +39,10 @@ class RFrameTitle : public RDrawable { RAttrText fAttrText{this, "text_"}; ///<! text attributes RTitleAttrs fAttr{this,""}; ///<! title direct attributes +protected: + + bool IsFrameRequired() const final { return true; } + public: RFrameTitle() : RDrawable("title") {} diff --git a/hist/histdrawv7/inc/ROOT/RHistDrawable.hxx b/hist/histdrawv7/inc/ROOT/RHistDrawable.hxx index f2de09a7322be1f6522031ca283e26c9bfce1ec2..36e6914143108f39b53a5b3513a90805694855b7 100644 --- a/hist/histdrawv7/inc/ROOT/RHistDrawable.hxx +++ b/hist/histdrawv7/inc/ROOT/RHistDrawable.hxx @@ -49,6 +49,8 @@ protected: void CollectShared(Internal::RIOSharedVector_t &vect) final { vect.emplace_back(&fHistImpl); } + bool IsFrameRequired() const final { return true; } + public: RHistDrawable(); virtual ~RHistDrawable() = default; diff --git a/tutorials/v7/draw_frame.cxx b/tutorials/v7/draw_frame.cxx index a9866f29011345f78e2d78618b0c68f934407ecc..fc3378237a5b825b9b4e9df345571472d0df56b4 100644 --- a/tutorials/v7/draw_frame.cxx +++ b/tutorials/v7/draw_frame.cxx @@ -22,6 +22,7 @@ #include "ROOT/RFrame.hxx" #include "ROOT/RHistDrawable.hxx" #include "ROOT/RStyle.hxx" +#include "ROOT/RPad.hxx" // macro must be here while cling is not capable to load // library automatically for outlined function see ROOT-10336