Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
14 namespace ROOT {
15 namespace 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 
25 class 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 
35 protected:
36 
37  std::unique_ptr<RDisplayItem> Display() const final;
38 
39 
40 public:
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; }
76  RAttrLine &AttrLine() { return fAttrLine; }
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 =
83  fParent->PixelsToNormal({{fSize.Horiz().GetPixel(), fSize.Vert().GetPixel()}});
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