Logo ROOT   6.12/07
Reference Guide
TPad.cxx
Go to the documentation of this file.
1 /// \file TPad.cxx
2 /// \ingroup Gpad ROOT7
3 /// \author Axel Naumann <axel@cern.ch>
4 /// \date 2017-07-07
5 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6 /// is welcome!
7 
8 /*************************************************************************
9  * Copyright (C) 1995-2017, Rene Brun and Fons Rademakers. *
10  * All rights reserved. *
11  * *
12  * For the licensing terms see $ROOTSYS/LICENSE. *
13  * For the list of contributors see $ROOTSYS/README/CREDITS. *
14  *************************************************************************/
15 
16 #include "ROOT/TPad.hxx"
17 
18 #include "ROOT/TLogger.hxx"
19 #include "ROOT/TPadExtent.hxx"
20 #include "ROOT/TPadPos.hxx"
21 
22 #include <cassert>
23 #include <limits>
24 
26 
27 std::vector<std::vector<ROOT::Experimental::TPad *>>
28 ROOT::Experimental::TPadBase::Divide(int nHoriz, int nVert, const TPadExtent &padding /*= {}*/)
29 {
30  std::vector<std::vector<TPad *>> ret;
31  if (!nHoriz)
32  R__ERROR_HERE("Gpad") << "Cannot divide into 0 horizontal sub-pads!";
33  if (!nVert)
34  R__ERROR_HERE("Gpad") << "Cannot divide into 0 vertical sub-pads!";
35  if (!nHoriz || !nVert)
36  return ret;
37 
38  // Start with the whole (sub-)pad:
39  TPadExtent offset{1._normal, 1._normal};
40  /// We need n Pads plus n-1 padding. Thus each `(subPadSize + padding)` is `(parentPadSize + padding) / n`.
41  offset = (offset + padding);
42  offset *= {1. / nHoriz, 1. / nVert};
43  const TPadExtent size = offset - padding;
44 
45  ret.resize(nHoriz);
46  for (int iHoriz = 0; iHoriz < nHoriz; ++iHoriz) {
47  ret[iHoriz].resize(nVert);
48  for (int iVert = 0; iVert < nVert; ++iVert) {
49  TPadPos subPos = offset;
50  subPos *= {1. * nHoriz, 1. * nVert};
51  auto uniqPad = std::make_unique<TPad>(*this, size);
52  ret[iHoriz][iVert] = uniqPad.get();
53  Draw(std::move(uniqPad)).At(subPos);
54  }
55  }
56  return ret;
57 }
58 
60 
61 ROOT::Experimental::TPadDrawable::TPadDrawable(std::unique_ptr<TPad> &&pPad, TPadBase &parent)
62  : fPad(std::move(pPad)), fOpts(parent)
63 {
64  assert(&fPad->GetParent() == &parent && "Parent mismatch!");
65 }
std::vector< std::vector< TPad * > > Divide(int nHoriz, int nVert, const TPadExtent &padding={})
Divide this pad into a grid of subpad with padding in between.
Definition: TPad.cxx:28
STL namespace.
virtual ~TPad()
Destructor to have a vtable.
A position (horizontal and vertical) in a TPad.
Definition: TPadPos.hxx:27
Base class for graphic containers for TDrawable-s.
Definition: TPad.hxx:41
auto & Draw(const std::shared_ptr< T > &what)
Add something to be painted.
Definition: TPad.hxx:84
An extent / size (horizontal and vertical) in a TPad.
Definition: TPadExtent.hxx:44
TPadDrawable(std::unique_ptr< TPad > &&pPad, TPadBase &parent)
Move a sub-pad into this (i.e. parent&#39;s) list of drawables.
Definition: TPad.cxx:61
const std::unique_ptr< TPad > fPad
The pad to be painted.
Definition: TPad.hxx:218
#define R__ERROR_HERE(GROUP)
Definition: TLogger.hxx:126