23 #include "ROOT/TDrawingAttr.hxx" 24 #include "ROOT/TDrawingOptsBase.hxx" 32 namespace Experimental {
61 template <
class DRAWABLE>
64 fPrimitives.emplace_back(std::move(uPtr));
68 using Options_t =
typename std::remove_reference<decltype(uPtr->GetOptions())>::
type;
69 auto spDrawable = std::static_pointer_cast<DRAWABLE>(fPrimitives.back());
72 return std::shared_ptr<Options_t>(spDrawable, &spDrawable->GetOptions());
87 std::vector<std::vector<TPad *>>
Divide(
int nHoriz,
int nVert,
const TPadExtent &padding = {});
92 template <
class T,
class...
ARGS>
93 auto Draw(
const std::shared_ptr<T> &what,
ARGS... args)
101 template <
class T,
class...
ARGS>
110 template <
class T,
class...
ARGS,
class =
typename std::enable_if<!ROOT::TypeTraits::IsSmartOrDumbPtr<T>::value>
::type>
114 return Draw(std::make_unique<T>(what), args...);
119 auto iter = std::find_if(fPrimitives.begin(), fPrimitives.end(),
120 [&opts](
const std::shared_ptr<TDrawable>& drawable) {
return &drawable->GetOptionsBase() == &opts; });
121 if (iter == fPrimitives.end())
127 std::shared_ptr<TDrawable>
FindDrawable(
const std::string &
id)
const;
147 void SetAllAxisBounds(
const std::vector<std::array<double, 2>> &vecBeginAndEnd);
154 void SetAllAxisBound(
const std::vector<BoundKindAndValue> &vecBoundAndKind);
161 virtual std::array<TPadLength::Normal, 2>
PixelsToNormal(
const std::array<TPadLength::Pixel, 2> &pos)
const = 0;
170 std::array<TPadLength::Normal, 2>
UserToNormal(
const std::array<TPadLength::User, 2> &pos)
const 172 return fFrame->UserToNormal(pos);
191 friend std::unique_ptr<TPadDrawable>
GetDrawable(std::unique_ptr<TPad> &&pad);
218 std::array<TPadLength::Normal, 2>
PixelsToNormal(
const std::array<TPadLength::Pixel, 2> &pos)
const override 220 std::array<TPadLength::Normal, 2> posInParentNormal = fParent->
PixelsToNormal(pos);
221 std::array<TPadLength::Normal, 2> myPixelInNormal =
223 std::array<TPadLength::Normal, 2> myUserInNormal =
227 return {{posInParentNormal[0] / (fSize.
fHoriz.
fNormal + myPixelInNormal[0] + myUserInNormal[0]),
228 posInParentNormal[1] / (fSize.
fVert.
fNormal + myPixelInNormal[1] + myUserInNormal[1])}};
236 return {{pos.
fHoriz.
fNormal + pixelsInNormal[0] + userInNormal[0],
237 pos.
fVert.
fNormal + pixelsInNormal[1] + userInNormal[1]}};
246 TDrawingAttr<TPadPos> fPos{*
this,
"PadOffset"};
262 const TDrawingAttr<TPadPos> &
GetOffset()
const {
return fPos; }
270 const std::shared_ptr<TPad>
fPad;
286 template <
class...
ARGS>
287 inline std::shared_ptr<TPadDrawable>
GetDrawable(std::unique_ptr<TPad> &&pad,
ARGS... args)
289 return std::make_shared<TPadDrawable>(std::move(pad),
TPadDrawingOpts(args...));
292 template <
class...
ARGS>
293 inline std::shared_ptr<TPadDrawable>
GetDrawable(
const std::shared_ptr<TPad> &pad,
ARGS... args)
Draw a TPad, by drawing its contained graphical elements at the pad offset in the parent pad...
TPadUserAxisBase * GetOrCreateAxis(size_t dimension)
Get a pad axis from the TFrame.
std::vector< std::vector< TPad * > > Divide(int nHoriz, int nVert, const TPadExtent &padding={})
Divide this pad into a grid of subpads with padding in between.
TPadLength fVert
Vertical position.
Namespace for new ROOT classes and functions.
TPadUserAxisBase * GetAxis(size_t dimension) const
Get a pad axis from the TFrame.
A window's topmost TPad.
virtual const TCanvas * GetCanvas() const =0
Access to the top-most canvas, if any (const version).
Drawing options for a TPad.
TPad(TPadBase &parent, const TPadExtent &size)
Create a child pad.
no defined axis range; the painter will decide
std::shared_ptr< TDrawable > FindDrawable(const std::string &id) const
TPadBase & operator=(const TPadBase &)=delete
Disable assignment.
TPadDrawingOpts & At(const TPadPos &pos)
Set the position of this pad with respect to the parent pad.
auto Draw(std::unique_ptr< T > &&what, ARGS... args)
Add something to be painted.
TCanvas * GetCanvas() override
Access to the top-most canvas (non-const version).
void SetAllAxisBound(const std::vector< BoundKindAndValue > &vecBoundAndKind)
Set the range of an axis as bound kind and bound (up or down).
TPadLength fHoriz
Horizontal position.
std::unique_ptr< TFrame > fFrame
TFrame with user coordinate system, if used by this pad.
TPadBase * GetParent()
Access to the parent pad (non-const version).
Pixel fPixel
The pixel coordinate summand.
const TDrawingAttr< TPadPos > & GetOffset() const
void Wipe()
Wipe the pad by clearing the list of primitives.
const TPadExtent & GetSize() const
Get the size of the pad in parent (!) coordinates.
auto Draw(const T &what, ARGS... args)
Add a copy of something to be painted.
Primitives_t fPrimitives
Content of the pad.
A position (horizontal and vertical) in a TPad.
Base class for graphic containers for TDrawable-s.
void AssignUniqueID(std::shared_ptr< TDrawable > &ptr)
Simple struct representing an axis bound.
const TPadBase * GetParent() const
Access to the parent pad (const version).
const Primitives_t & GetPrimitives() const
Get the elements contained in the canvas.
Normal fNormal
The normalized coordinate summand.
const std::shared_ptr< TPad > fPad
The pad to be painted.
TPadUserAxisBase::EAxisBoundsKind fKind
const TCanvas * GetCanvas() const override
Access to the top-most canvas (const version).
The most important graphics class in the ROOT system.
TPadDrawingOpts(const TPadPos &pos)
Construct the drawing options.
void SetAllAxisBounds(const std::vector< std::array< double, 2 >> &vecBeginAndEnd)
Set the range of an axis as bound kind and bound (up or down).
TFrame * GetOrCreateFrame()
EAxisBoundsKind
Types of axis bounds to respect by the painter.
void SetAxisAutoBounds(int dimension)
Set the range of an axis as bound kind and bound (up or down).
std::array< TPadLength::Normal, 2 > ToNormal(const Internal::TPadHorizVert &pos) const
Convert a TPadPos to [x, y] of normalized coordinates.
void SetAxisBound(int dimension, TPadUserAxisBase::EAxisBoundsKind boundsKind, double bound)
Set the range of an axis as bound kind and bound (up or down).
TPadDrawingOpts & GetOptions()
Drawing options.
Abstract interface for object painting on the pad/canvas.
std::vector< std::shared_ptr< TDrawable > > Primitives_t
Holds a user coordinate system with a palette.
void CreateFrameIfNeeded()
std::shared_ptr< TPadDrawable > GetDrawable(std::unique_ptr< TPad > &&pad, ARGS... args)
TDrawingAttr< TPadPos > & GetOffset()
void SetAllAxisAutoBounds()
Set the range of an axis as bound kind and bound (up or down).
An extent / size (horizontal and vertical) in a TPad.
std::array< TPadLength::Normal, 2 > PixelsToNormal(const std::array< TPadLength::Pixel, 2 > &pos) const override
Convert a Pixel position to Canvas-normalized positions.
TPadBase()=default
Allow derived classes to default construct a TPadBase.
auto AddDrawable(std::shared_ptr< DRAWABLE > &&uPtr)
Adds a DRAWABLE to fPrimitives, returning a shared_ptr to DRAWABLE::GetOptions(). ...
User fUser
The user coordinate summand.
const TFrame * GetFrame() const
std::array< TPadLength::Normal, 2 > UserToNormal(const std::array< TPadLength::User, 2 > &pos) const
Convert user coordinates to normal coordinates.
void SetAxisBounds(int dimension, double begin, double end)
Set the range of an axis as begin, end.
Graphic container for TDrawable-s.
TPadDrawingOpts fOpts
The drawing options.
virtual std::array< TPadLength::Normal, 2 > PixelsToNormal(const std::array< TPadLength::Pixel, 2 > &pos) const =0
Convert a Pixel position to Canvas-normalized positions.
A 2D (horizontal and vertical) combination of TPadLengths.
auto Draw(const std::shared_ptr< T > &what, ARGS... args)
Add something to be painted.
bool Remove(TDrawingOptsBase &opts)
Remove an object from the list of primitives.