Logo ROOT   6.14/05
Reference Guide
TCanvas.hxx
Go to the documentation of this file.
1 /// \file ROOT/TCanvas.hxx
2 /// \ingroup Gpad ROOT7
3 /// \author Axel Naumann <axel@cern.ch>
4 /// \date 2015-07-08
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-2015, 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 #ifndef ROOT7_TCanvas
17 #define ROOT7_TCanvas
18 
19 #include "ROOT/TPad.hxx"
21 
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 namespace ROOT {
27 namespace Experimental {
28 
29 /** \class ROOT::Experimental::TCanvas
30  A window's topmost `TPad`.
31  */
32 
33 class TCanvas: public TPadBase {
34 friend class TPadBase; /// use for ID generation
35 private:
36  /// Title of the canvas.
37  std::string fTitle;
38 
39  /// Size of the canvas in pixels,
40  std::array<TPadLength::Pixel, 2> fSize;
41 
42  /// Modify counter, incremented every time canvas is changed
43  uint64_t fModified; ///<!
44 
45  uint64_t fIdCounter{2}; ///< counter for objects, id==1 is canvas itself
46 
47  /// The painter of this canvas, bootstrapping the graphics connection.
48  /// Unmapped canvases (those that never had `Draw()` invoked) might not have
49  /// a painter.
50  std::unique_ptr<Internal::TVirtualCanvasPainter> fPainter; ///<!
51 
52  /// Disable copy construction for now.
53  TCanvas(const TCanvas &) = delete;
54 
55  /// Disable assignment for now.
56  TCanvas &operator=(const TCanvas &) = delete;
57 
58  std::string GenerateUniqueId();
59 
60 public:
61  static std::shared_ptr<TCanvas> Create(const std::string &title);
62 
63  /// Create a temporary TCanvas; for long-lived ones please use Create().
64  TCanvas() = default;
65 
66  ~TCanvas() = default;
67 
68  const TCanvas *GetCanvas() const override { return this; }
69 
70  /// Access to the top-most canvas, if any (non-const version).
71  TCanvas *GetCanvas() override { return this; }
72 
73  /// Return canvas pixel size as array with two elements - width and height
74  const std::array<TPadLength::Pixel, 2> &GetSize() const { return fSize; }
75 
76  /// Set canvas pixel size as array with two elements - width and height
77  void SetSize(const std::array<TPadLength::Pixel, 2> &sz) { fSize = sz; }
78 
79  /// Set canvas pixel size - width and height
80  void SetSize(const TPadLength::Pixel &width, const TPadLength::Pixel &height)
81  {
82  fSize[0] = width;
83  fSize[1] = height;
84  }
85 
86  /// Display the canvas.
87  void Show(const std::string &where = "");
88 
89  /// Close all canvas displays
90  void Hide();
91 
92  /// Insert panel into the canvas, canvas should be shown at this moment
93  template <class PANEL>
94  bool AddPanel(std::shared_ptr<PANEL> &panel) {
95  if (!fPainter) return false;
96  return fPainter->AddPanel(panel->GetWindow());
97  }
98 
99  // Indicates that primitives list was changed or any primitive was modified
100  void Modified() { fModified++; }
101 
102  // Return if canvas was modified and not yet updated
103  bool IsModified() const;
104 
105  /// update drawing
106  void Update(bool async = false, CanvasCallback_t callback = nullptr);
107 
108  /// Save canvas in image file
109  void SaveAs(const std::string &filename, bool async = false, CanvasCallback_t callback = nullptr);
110 
111  /// Get the canvas's title.
112  const std::string &GetTitle() const { return fTitle; }
113 
114  /// Set the canvas's title.
115  void SetTitle(const std::string &title) { fTitle = title; }
116 
117  /// Convert a `Pixel` position to Canvas-normalized positions.
118  std::array<TPadLength::Normal, 2> PixelsToNormal(const std::array<TPadLength::Pixel, 2> &pos) const final
119  {
120  return {{pos[0] / fSize[0], pos[1] / fSize[1]}};
121  }
122 
123  static const std::vector<std::shared_ptr<TCanvas>> &GetCanvases();
124 };
125 
126 } // namespace Experimental
127 } // namespace ROOT
128 
129 #endif
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
std::string fTitle
use for ID generation
Definition: TCanvas.hxx:37
std::string GenerateUniqueId()
Generates unique ID inside the canvas.
Definition: TCanvas.cxx:49
image html pict1_TGaxis_012 png width
Define new text attributes for the label number "labNum".
Definition: TGaxis.cxx:2551
A window&#39;s topmost TPad.
Definition: TCanvas.hxx:33
uint64_t fModified
Modify counter, incremented every time canvas is changed.
Definition: TCanvas.hxx:43
const std::string & GetTitle() const
Get the canvas&#39;s title.
Definition: TCanvas.hxx:112
TCanvas & operator=(const TCanvas &)=delete
Disable assignment for now.
std::array< TPadLength::Normal, 2 > PixelsToNormal(const std::array< TPadLength::Pixel, 2 > &pos) const final
Convert a Pixel position to Canvas-normalized positions.
Definition: TCanvas.hxx:118
uint64_t fIdCounter
counter for objects, id==1 is canvas itself
Definition: TCanvas.hxx:45
std::unique_ptr< Internal::TVirtualCanvasPainter > fPainter
The painter of this canvas, bootstrapping the graphics connection.
Definition: TCanvas.hxx:50
TCanvas * GetCanvas() override
Access to the top-most canvas, if any (non-const version).
Definition: TCanvas.hxx:71
void Update(bool async=false, CanvasCallback_t callback=nullptr)
update drawing
Definition: TCanvas.cxx:62
Base class for graphic containers for TDrawable-s.
Definition: TPad.hxx:41
const std::array< TPadLength::Pixel, 2 > & GetSize() const
Return canvas pixel size as array with two elements - width and height.
Definition: TCanvas.hxx:74
void Hide()
Close all canvas displays.
Definition: TCanvas.cxx:122
TCanvas()=default
Create a temporary TCanvas; for long-lived ones please use Create().
bool IsModified() const
Returns true is canvas was modified since last painting.
Definition: TCanvas.cxx:57
bool AddPanel(std::shared_ptr< PANEL > &panel)
Insert panel into the canvas, canvas should be shown at this moment.
Definition: TCanvas.hxx:94
std::array< TPadLength::Pixel, 2 > fSize
Size of the canvas in pixels,.
Definition: TCanvas.hxx:40
void SetSize(const std::array< TPadLength::Pixel, 2 > &sz)
Set canvas pixel size as array with two elements - width and height.
Definition: TCanvas.hxx:77
void SetSize(const TPadLength::Pixel &width, const TPadLength::Pixel &height)
Set canvas pixel size - width and height.
Definition: TCanvas.hxx:80
void SaveAs(const std::string &filename, bool async=false, CanvasCallback_t callback=nullptr)
Save canvas in image file.
Definition: TCanvas.cxx:134
std::function< void(bool)> CanvasCallback_t
void Show(const std::string &where="")
Display the canvas.
Definition: TCanvas.cxx:96
const TCanvas * GetCanvas() const override
Access to the top-most canvas, if any (const version).
Definition: TCanvas.hxx:68
static std::shared_ptr< TCanvas > Create(const std::string &title)
Definition: TCanvas.cxx:74
A pixel coordinate: 0 in the left, bottom corner, 1 in the top, right corner of the TPad...
Definition: TPadLength.hxx:83
void SetTitle(const std::string &title)
Set the canvas&#39;s title.
Definition: TCanvas.hxx:115
static const std::vector< std::shared_ptr< TCanvas > > & GetCanvases()
Definition: TCanvas.cxx:35