Logo ROOT  
Reference Guide
RCanvas.hxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2015, 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_RCanvas
10#define ROOT7_RCanvas
11
12#include "ROOT/RPadBase.hxx"
14
15#include <memory>
16#include <string>
17#include <vector>
18
19namespace ROOT {
20namespace Experimental {
21
22/** \class RCanvas
23\ingroup GpadROOT7
24\brief A window's topmost `RPad`.
25\author Axel Naumann <axel@cern.ch>
26\date 2015-07-08
27\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
28*/
29
30class RCanvas: public RPadBase {
31friend class RPadBase; /// use for ID generation
32friend class RCanvasPainter; /// used for primitives drawing
33private:
34 /// Title of the canvas.
35 std::string fTitle;
36
37 /// Size of the canvas in pixels,
38 std::array<RPadLength::Pixel, 2> fSize;
39
40 /// Modify counter, incremented every time canvas is changed
41 uint64_t fModified{0}; ///<!
42
43 /// The painter of this canvas, bootstrapping the graphics connection.
44 /// Unmapped canvases (those that never had `Draw()` invoked) might not have
45 /// a painter.
46 std::unique_ptr<Internal::RVirtualCanvasPainter> fPainter; ///<!
47
48 /// Disable copy construction for now.
49 RCanvas(const RCanvas &) = delete;
50
51 /// Disable assignment for now.
52 RCanvas &operator=(const RCanvas &) = delete;
53
54public:
55 static std::shared_ptr<RCanvas> Create(const std::string &title);
56
57 /// Create a temporary RCanvas; for long-lived ones please use Create().
58 RCanvas() = default;
59
60 ~RCanvas() = default;
61
62 const RCanvas *GetCanvas() const override { return this; }
63
64 /// Access to the top-most canvas, if any (non-const version).
65 RCanvas *GetCanvas() override { return this; }
66
67 /// Return canvas pixel size as array with two elements - width and height
68 const std::array<RPadLength::Pixel, 2> &GetSize() const { return fSize; }
69
70 /// Set canvas pixel size as array with two elements - width and height
71 RCanvas &SetSize(const std::array<RPadLength::Pixel, 2> &sz)
72 {
73 fSize = sz;
74 return *this;
75 }
76
77 /// Set canvas pixel size - width and height
79 {
80 fSize[0] = width;
81 fSize[1] = height;
82 return *this;
83 }
84
85 /// Display the canvas.
86 void Show(const std::string &where = "");
87
88 /// Returns window name used to display canvas
89 std::string GetWindowAddr() const;
90
91 /// Hide all canvas displays
92 void Hide();
93
94 /// Remove canvas from global canvas lists, will be destroyed when shared_ptr will be removed
95 void Remove();
96
97 /// Insert panel into the canvas, canvas should be shown at this moment
98 template <class PANEL>
99 bool AddPanel(std::shared_ptr<PANEL> &panel)
100 {
101 if (!fPainter) return false;
102 return fPainter->AddPanel(panel->GetWindow());
103 }
104
105 // Indicates that primitives list was changed or any primitive was modified
106 void Modified() { fModified++; }
107
108 // Return if canvas was modified and not yet updated
109 bool IsModified() const;
110
111 /// update drawing
112 void Update(bool async = false, CanvasCallback_t callback = nullptr);
113
114 /// Run canvas functionality for given time (in seconds)
115 void Run(double tm = 0.);
116
117 /// Save canvas in image file
118 void SaveAs(const std::string &filename, bool async = false, CanvasCallback_t callback = nullptr);
119
120 /// Get the canvas's title.
121 const std::string &GetTitle() const { return fTitle; }
122
123 /// Set the canvas's title.
124 RCanvas &SetTitle(const std::string &title)
125 {
126 fTitle = title;
127 return *this;
128 }
129
130 void ResolveSharedPtrs();
131
132 /// Convert a `Pixel` position to Canvas-normalized positions.
133 std::array<RPadLength::Normal, 2> PixelsToNormal(const std::array<RPadLength::Pixel, 2> &pos) const final
134 {
135 return {{pos[0] / fSize[0], pos[1] / fSize[1]}};
136 }
137
138 static const std::vector<std::shared_ptr<RCanvas>> GetCanvases();
139};
140
141} // namespace Experimental
142} // namespace ROOT
143
144#endif
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
A window's topmost RPad.
Definition: RCanvas.hxx:30
static const std::vector< std::shared_ptr< RCanvas > > GetCanvases()
Definition: RCanvas.cxx:40
RCanvas(const RCanvas &)=delete
Disable copy construction for now.
RCanvas * GetCanvas() override
Access to the top-most canvas, if any (non-const version).
Definition: RCanvas.hxx:65
const std::string & GetTitle() const
Get the canvas's title.
Definition: RCanvas.hxx:121
RCanvas & SetSize(const RPadLength::Pixel &width, const RPadLength::Pixel &height)
Set canvas pixel size - width and height.
Definition: RCanvas.hxx:78
RCanvas & SetTitle(const std::string &title)
Set the canvas's title.
Definition: RCanvas.hxx:124
RCanvas & SetSize(const std::array< RPadLength::Pixel, 2 > &sz)
Set canvas pixel size as array with two elements - width and height.
Definition: RCanvas.hxx:71
std::array< RPadLength::Normal, 2 > PixelsToNormal(const std::array< RPadLength::Pixel, 2 > &pos) const final
Convert a Pixel position to Canvas-normalized positions.
Definition: RCanvas.hxx:133
std::array< RPadLength::Pixel, 2 > fSize
Size of the canvas in pixels,.
Definition: RCanvas.hxx:38
bool IsModified() const
Returns true is canvas was modified since last painting.
Definition: RCanvas.cxx:50
const std::array< RPadLength::Pixel, 2 > & GetSize() const
Return canvas pixel size as array with two elements - width and height.
Definition: RCanvas.hxx:68
RCanvas & operator=(const RCanvas &)=delete
Disable assignment for now.
void Show(const std::string &where="")
Display the canvas.
Definition: RCanvas.cxx:86
std::string GetWindowAddr() const
Returns window name used to display canvas.
Definition: RCanvas.cxx:112
void Remove()
Remove canvas from global canvas lists, will be destroyed when shared_ptr will be removed.
Definition: RCanvas.cxx:160
void ResolveSharedPtrs()
To resolve problem with storing of shared pointers Call this method when reading canvas from the file...
Definition: RCanvas.cxx:225
void Run(double tm=0.)
Run canvas functionality for given time (in seconds)
Definition: RCanvas.cxx:211
std::string fTitle
used for primitives drawing
Definition: RCanvas.hxx:35
uint64_t fModified
Modify counter, incremented every time canvas is changed.
Definition: RCanvas.hxx:41
std::unique_ptr< Internal::RVirtualCanvasPainter > fPainter
The painter of this canvas, bootstrapping the graphics connection.
Definition: RCanvas.hxx:46
static std::shared_ptr< RCanvas > Create(const std::string &title)
Definition: RCanvas.cxx:61
RCanvas()=default
Create a temporary RCanvas; for long-lived ones please use Create().
const RCanvas * GetCanvas() const override
Access to the top-most canvas, if any (const version).
Definition: RCanvas.hxx:62
void Update(bool async=false, CanvasCallback_t callback=nullptr)
update drawing
Definition: RCanvas.cxx:55
void SaveAs(const std::string &filename, bool async=false, CanvasCallback_t callback=nullptr)
Save canvas in image file.
Definition: RCanvas.cxx:136
friend class RCanvasPainter
use for ID generation
Definition: RCanvas.hxx:32
bool AddPanel(std::shared_ptr< PANEL > &panel)
Insert panel into the canvas, canvas should be shown at this moment.
Definition: RCanvas.hxx:99
void Hide()
Hide all canvas displays.
Definition: RCanvas.cxx:124
Base class for graphic containers for RDrawable-s.
Definition: RPadBase.hxx:37
std::function< void(bool)> CanvasCallback_t
VSD Structures.
Definition: StringConv.hxx:21