Logo ROOT  
Reference Guide
RPad.hxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
3 * All rights reserved. *
4 * *
5 * For the licensing terms see $ROOTSYS/LICENSE. *
6 * For the list of contributors see $ROOTSYS/README/CREDITS. *
7 *************************************************************************/
8
9#ifndef ROOT7_RPad
10#define ROOT7_RPad
11
12#include "ROOT/RPadBase.hxx"
13
14namespace ROOT {
15namespace Experimental {
16
17/** \class RPad
18\ingroup GpadROOT7
19\brief Graphic container for `RDrawable`-s.
20\authors Axel Naumann <axel@cern.ch> Sergey Linev <s.linev@gsi.de>
21\date 2017-07-06
22\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
23*/
24
25class RPad: public RPadBase {
26
27 /// Pad containing this pad as a sub-pad.
28 RPadBase *fParent{nullptr}; ///< The parent pad, if this pad has one.
29
30 RPadPos fPos; ///< pad position
31 RPadExtent fSize; ///< pad size
32
33 RAttrLine fAttrLine{this, "border_"}; ///<! border attributes
34
35protected:
36
37 std::unique_ptr<RDisplayItem> Display() const final;
38
39
40public:
41 /// Create a topmost, non-paintable pad.
42 RPad() = default;
43
44 /// Create a child pad.
45 RPad(RPadBase *parent, const RPadPos &pos, const RPadExtent &size): fParent(parent) { fPos = pos; fSize = size; }
46
47 /// Destructor to have a vtable.
48 virtual ~RPad();
49
50 /// Access to the parent pad (const version).
51 const RPadBase *GetParent() const { return fParent; }
52
53 /// Access to the parent pad (non-const version).
54 RPadBase *GetParent() { return fParent; }
55
56 /// Access to the top-most canvas (const version).
57 const RCanvas *GetCanvas() const override { return fParent ? fParent->GetCanvas() : nullptr; }
58
59 /// Access to the top-most canvas (non-const version).
60 RCanvas *GetCanvas() override { return fParent ? fParent->GetCanvas() : nullptr; }
61
62 /// Get the position of the pad in parent (!) coordinates.
63 const RPadPos &GetPos() const { return fPos; }
64
65 /// Get the size of the pad in parent (!) coordinates.
66 const RPadExtent &GetSize() const { return fSize; }
67
68 /// Set the size of the pad in parent (!) coordinates.
69 void SetSize(const RPadExtent &sz) { fSize = sz; }
70
71 /// Set position
72 void SetPos(const RPadPos &p) { fPos = p; }
73
74 const RAttrLine &GetAttrLine() const { return fAttrLine; }
75 RPad &SetAttrLine(const RAttrLine &attr) { fAttrLine = attr; return *this; }
77
78 /// Convert a `Pixel` position to Canvas-normalized positions.
79 std::array<RPadLength::Normal, 2> PixelsToNormal(const std::array<RPadLength::Pixel, 2> &pos) const override
80 {
81 std::array<RPadLength::Normal, 2> posInParentNormal = fParent->PixelsToNormal(pos);
82 std::array<RPadLength::Normal, 2> myPixelInNormal =
84 std::array<RPadLength::Normal, 2> myUserInNormal =
85 fParent->UserToNormal({{fSize.Horiz().GetUser(), fSize.Vert().GetUser()}});
86 // If the parent says pos is at 0.6 in normal coords, and our size converted to normal is 0.2, then pos in our
87 // coord system is 3.0!
88 return {{posInParentNormal[0] / (fSize.Horiz().GetNormal() + myPixelInNormal[0] + myUserInNormal[0]),
89 posInParentNormal[1] / (fSize.Vert().GetNormal() + myPixelInNormal[1] + myUserInNormal[1])}};
90 }
91
92 /// Convert a RPadPos to [x, y] of normalized coordinates.
93 std::array<RPadLength::Normal, 2> ToNormal(const RPadPos &pos) const
94 {
95 std::array<RPadLength::Normal, 2> pixelsInNormal = PixelsToNormal({{pos.Horiz().GetPixel(), pos.Vert().GetPixel()}});
96 std::array<RPadLength::Normal, 2> userInNormal = UserToNormal({{pos.Horiz().GetUser(), pos.Vert().GetUser()}});
97 return {{pos.Horiz().GetNormal() + pixelsInNormal[0] + userInNormal[0],
98 pos.Vert().GetNormal() + pixelsInNormal[1] + userInNormal[1]}};
99 }
100
101
102};
103
104} // namespace Experimental
105} // namespace ROOT
106
107#endif
static void GetPixel(int y, int width, Byte_t *scline)
Get pixels in line y and put in array scline.
Definition: TGWin32.cxx:4277
Drawing line attributes for different objects.
Definition: RAttrLine.hxx:26
A window's topmost RPad.
Definition: RCanvas.hxx:30
Base class for graphic containers for RDrawable-s.
Definition: RPadBase.hxx:37
virtual std::array< RPadLength::Normal, 2 > PixelsToNormal(const std::array< RPadLength::Pixel, 2 > &pos) const =0
Convert a Pixel position to Canvas-normalized positions.
std::array< RPadLength::Normal, 2 > UserToNormal(const std::array< RPadLength::User, 2 > &pos) const
Convert user coordinates to normal coordinates.
Definition: RPadBase.hxx:203
virtual const RCanvas * GetCanvas() const =0
Access to the top-most canvas, if any (const version).
An extent / size (horizontal and vertical) in a RPad.
Definition: RPadExtent.hxx:27
A position (horizontal and vertical) in a RPad.
Definition: RPadPos.hxx:28
RPadLength & Horiz()
Definition: RPadPos.hxx:50
Graphic container for RDrawable-s.
Definition: RPad.hxx:25
const RPadExtent & GetSize() const
Get the size of the pad in parent (!) coordinates.
Definition: RPad.hxx:66
void SetSize(const RPadExtent &sz)
Set the size of the pad in parent (!) coordinates.
Definition: RPad.hxx:69
const RCanvas * GetCanvas() const override
Access to the top-most canvas (const version).
Definition: RPad.hxx:57
const RPadBase * GetParent() const
Access to the parent pad (const version).
Definition: RPad.hxx:51
RCanvas * GetCanvas() override
Access to the top-most canvas (non-const version).
Definition: RPad.hxx:60
virtual ~RPad()
Destructor to have a vtable.
RPad & SetAttrLine(const RAttrLine &attr)
Definition: RPad.hxx:75
RPadBase * GetParent()
Access to the parent pad (non-const version).
Definition: RPad.hxx:54
RPadPos fPos
pad position
Definition: RPad.hxx:30
std::array< RPadLength::Normal, 2 > ToNormal(const RPadPos &pos) const
Convert a RPadPos to [x, y] of normalized coordinates.
Definition: RPad.hxx:93
RAttrLine fAttrLine
! border attributes
Definition: RPad.hxx:33
RAttrLine & AttrLine()
Definition: RPad.hxx:76
std::array< RPadLength::Normal, 2 > PixelsToNormal(const std::array< RPadLength::Pixel, 2 > &pos) const override
Convert a Pixel position to Canvas-normalized positions.
Definition: RPad.hxx:79
const RAttrLine & GetAttrLine() const
Definition: RPad.hxx:74
RPadBase * fParent
Pad containing this pad as a sub-pad.
Definition: RPad.hxx:28
void SetPos(const RPadPos &p)
Set position.
Definition: RPad.hxx:72
const RPadPos & GetPos() const
Get the position of the pad in parent (!) coordinates.
Definition: RPad.hxx:63
std::unique_ptr< RDisplayItem > Display() const final
Create pad display item.
Definition: RPad.cxx:25
RPadExtent fSize
pad size
Definition: RPad.hxx:31
VSD Structures.
Definition: StringConv.hxx:21