Logo ROOT   6.12/07
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/TColor.hxx"
20 #include "ROOT/TPad.hxx"
22 
23 #include <memory>
24 #include <string>
25 #include <vector>
26 
27 namespace ROOT {
28 namespace Experimental {
29 
30 class TDrawingOptsBaseNoDefault;
31 template <class PRIMITIVE>
33 
34 /** \class ROOT::Experimental::TCanvas
35  A window's topmost `TPad`.
36  Access is through TCanvasPtr.
37  */
38 
39 class TCanvas: public TPadBase {
40 private:
41  /// Title of the canvas.
42  std::string fTitle;
43 
44  /// Size of the canvas in pixels,
45  std::array<TPadCoord::Pixel, 2> fSize;
46 
47  /// Colors used by drawing options in the pad and any sub-pad.
49 
50  /// Integers used by drawing options in the pad and any sub-pad.
52 
53  /// Floating points used by drawing options in the pad and any sub-pad.
55 
56  /// Modify counter, incremented every time canvas is changed
57  uint64_t fModified; ///<!
58 
59  /// The painter of this canvas, bootstrapping the graphics connection.
60  /// Unmapped canvases (those that never had `Draw()` invoked) might not have
61  /// a painter.
62  std::unique_ptr<Internal::TVirtualCanvasPainter> fPainter; ///<!
63 
64  /// Disable copy construction for now.
65  TCanvas(const TCanvas &) = delete;
66 
67  /// Disable assignment for now.
68  TCanvas &operator=(const TCanvas &) = delete;
69 
70  ///\{
71  ///\name Drawing options attribute handling
72 
73  /// Attribute table (non-const access).
77 
78  /// Attribute table (const access).
82 
84  template <class PRIMITIVE>
86  ///\}
87 
88 public:
89  static std::shared_ptr<TCanvas> Create(const std::string &title);
90 
91  /// Create a temporary TCanvas; for long-lived ones please use Create().
92  TCanvas() = default;
93 
94  ~TCanvas() { Wipe(); /* FIXME: this should become Attrs owned and referenced by the TPads */}
95 
96  const TCanvas &GetCanvas() const override { return *this; }
97 
98  /// Access to the top-most canvas, if any (non-const version).
99  TCanvas &GetCanvas() override { return *this; }
100 
101  /// Return canvas pixel size as array with two elements - width and height
102  const std::array<TPadCoord::Pixel, 2> &GetSize() const { return fSize; }
103 
104  /// Set canvas pixel size as array with two elements - width and height
105  void SetSize(const std::array<TPadCoord::Pixel, 2> &sz) { fSize = sz; }
106 
107  /// Set canvas pixel size - width and height
108  void SetSize(const TPadCoord::Pixel &width, const TPadCoord::Pixel &height)
109  {
110  fSize[0] = width;
111  fSize[1] = height;
112  }
113 
114  /// Display the canvas.
115  void Show(const std::string &where = "");
116 
117  /// Close all canvas displays
118  void Hide();
119 
120  /// Insert panel into the canvas, canvas should be shown at this moment
121  template <class PANEL>
122  bool AddPanel(std::shared_ptr<PANEL> &panel) {
123  if (!fPainter) return false;
124  return fPainter->AddPanel(panel->GetWindow());
125  }
126 
127  // Indicates that primitives list was changed or any primitive was modified
128  void Modified() { fModified++; }
129 
130  // Return if canvas was modified and not yet updated
131  bool IsModified() const;
132 
133  /// update drawing
134  void Update(bool async = false, CanvasCallback_t callback = nullptr);
135 
136  /// Save canvas in image file
137  void SaveAs(const std::string &filename, bool async = false, CanvasCallback_t callback = nullptr);
138 
139  /// Get the canvas's title.
140  const std::string &GetTitle() const { return fTitle; }
141 
142  /// Set the canvas's title.
143  void SetTitle(const std::string &title) { fTitle = title; }
144 
145  /// Convert a `Pixel` position to Canvas-normalized positions.
146  std::array<TPadCoord::Normal, 2> PixelsToNormal(const std::array<TPadCoord::Pixel, 2> &pos) const final
147  {
148  return {{pos[0] / fSize[0], pos[1] / fSize[1]}};
149  }
150 
151  static const std::vector<std::shared_ptr<TCanvas>> &GetCanvases();
152 };
153 
154 } // namespace Experimental
155 } // namespace ROOT
156 
157 #endif
const Internal::TDrawingAttrTable< long long > & GetAttrTable(long long *) const
Definition: TCanvas.hxx:80
Internal::TDrawingAttrTable< TColor > fColorTable
Colors used by drawing options in the pad and any sub-pad.
Definition: TCanvas.hxx:48
Internal::TDrawingAttrTable< TColor > & GetAttrTable(TColor *)
Attribute table (non-const access).
Definition: TCanvas.hxx:74
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
TCanvas & GetCanvas() override
Access to the top-most canvas, if any (non-const version).
Definition: TCanvas.hxx:99
void SetSize(const std::array< TPadCoord::Pixel, 2 > &sz)
Set canvas pixel size as array with two elements - width and height.
Definition: TCanvas.hxx:105
std::string fTitle
Title of the canvas.
Definition: TCanvas.hxx:42
Internal::TDrawingAttrTable< long long > & GetAttrTable(long long *)
Definition: TCanvas.hxx:75
A window&#39;s topmost TPad.
Definition: TCanvas.hxx:39
uint64_t fModified
Modify counter, incremented every time canvas is changed.
Definition: TCanvas.hxx:57
const TCanvas & GetCanvas() const override
Access to the top-most canvas, if any (const version).
Definition: TCanvas.hxx:96
const std::string & GetTitle() const
Get the canvas&#39;s title.
Definition: TCanvas.hxx:140
TCanvas & operator=(const TCanvas &)=delete
Disable assignment for now.
A pixel coordinate: 0 in the left, bottom corner, 1 in the top, right corner of the TPad...
Definition: TPadCoord.hxx:80
void Wipe()
Remove an object from the list of primitives.
Definition: TPad.hxx:110
std::unique_ptr< Internal::TVirtualCanvasPainter > fPainter
The painter of this canvas, bootstrapping the graphics connection.
Definition: TCanvas.hxx:62
void Update(bool async=false, CanvasCallback_t callback=nullptr)
update drawing
Definition: TCanvas.cxx:51
Base class for graphic containers for TDrawable-s.
Definition: TPad.hxx:41
std::array< TPadCoord::Normal, 2 > PixelsToNormal(const std::array< TPadCoord::Pixel, 2 > &pos) const final
Convert a Pixel position to Canvas-normalized positions.
Definition: TCanvas.hxx:146
void Hide()
Close all canvas displays.
Definition: TCanvas.cxx:107
TCanvas()=default
Create a temporary TCanvas; for long-lived ones please use Create().
Internal::TDrawingAttrTable< double > & GetAttrTable(double *)
Definition: TCanvas.hxx:76
void SetSize(const TPadCoord::Pixel &width, const TPadCoord::Pixel &height)
Set canvas pixel size - width and height.
Definition: TCanvas.hxx:108
const Internal::TDrawingAttrTable< TColor > & GetAttrTable(TColor *) const
Attribute table (const access).
Definition: TCanvas.hxx:79
bool AddPanel(std::shared_ptr< PANEL > &panel)
Insert panel into the canvas, canvas should be shown at this moment.
Definition: TCanvas.hxx:122
std::array< TPadCoord::Pixel, 2 > fSize
Size of the canvas in pixels,.
Definition: TCanvas.hxx:45
const Internal::TDrawingAttrTable< double > & GetAttrTable(double *) const
Definition: TCanvas.hxx:81
void SaveAs(const std::string &filename, bool async=false, CanvasCallback_t callback=nullptr)
Save canvas in image file.
Definition: TCanvas.cxx:113
std::function< void(bool)> CanvasCallback_t
The TCanvas keep track of TColors, integer and floating point attributes used by the drawing options...
Definition: TCanvas.hxx:32
void Show(const std::string &where="")
Display the canvas.
Definition: TCanvas.cxx:85
Internal::TDrawingAttrTable< long long > fIntAttrTable
Integers used by drawing options in the pad and any sub-pad.
Definition: TCanvas.hxx:51
Internal::TDrawingAttrTable< double > fFPAttrTable
Floating points used by drawing options in the pad and any sub-pad.
Definition: TCanvas.hxx:54
A color: Red|Green|Blue|Alpha, or a position in a TPalette.
Definition: TColor.hxx:27
static std::shared_ptr< TCanvas > Create(const std::string &title)
Definition: TCanvas.cxx:63
const std::array< TPadCoord::Pixel, 2 > & GetSize() const
Return canvas pixel size as array with two elements - width and height.
Definition: TCanvas.hxx:102
void SetTitle(const std::string &title)
Set the canvas&#39;s title.
Definition: TCanvas.hxx:143
static const std::vector< std::shared_ptr< TCanvas > > & GetCanvases()
Definition: TCanvas.cxx:35