Logo ROOT   6.18/05
Reference Guide
RCanvas.hxx
Go to the documentation of this file.
1/// \file ROOT/RCanvas.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_RCanvas
17#define ROOT7_RCanvas
18
19#include "ROOT/RPad.hxx"
21
22#include <memory>
23#include <string>
24#include <vector>
25
26namespace ROOT {
27namespace Experimental {
28
29/** \class ROOT::Experimental::RCanvas
30 A window's topmost `RPad`.
31 */
32
33class RCanvas: public RPadBase {
34friend class RPadBase; /// use for ID generation
35private:
36 /// Title of the canvas.
37 std::string fTitle;
38
39 /// Size of the canvas in pixels,
40 std::array<RPadLength::Pixel, 2> fSize;
41
42 /// Modify counter, incremented every time canvas is changed
43 uint64_t fModified{0}; ///<!
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::RVirtualCanvasPainter> fPainter; ///<!
51
52 /// Disable copy construction for now.
53 RCanvas(const RCanvas &) = delete;
54
55 /// Disable assignment for now.
56 RCanvas &operator=(const RCanvas &) = delete;
57
58 std::string GenerateUniqueId();
59
60public:
61 static std::shared_ptr<RCanvas> Create(const std::string &title);
62
63 /// Create a temporary RCanvas; for long-lived ones please use Create().
64 RCanvas() = default;
65
66 ~RCanvas() = default;
67
68 const RCanvas *GetCanvas() const override { return this; }
69
70 /// Access to the top-most canvas, if any (non-const version).
71 RCanvas *GetCanvas() override { return this; }
72
73 /// Return canvas pixel size as array with two elements - width and height
74 const std::array<RPadLength::Pixel, 2> &GetSize() const { return fSize; }
75
76 /// Set canvas pixel size as array with two elements - width and height
77 RCanvas &SetSize(const std::array<RPadLength::Pixel, 2> &sz) {
78 fSize = sz;
79 return *this;
80 }
81
82 /// Set canvas pixel size - width and height
84 {
85 fSize[0] = width;
86 fSize[1] = height;
87 return *this;
88 }
89
90 /// Display the canvas.
91 void Show(const std::string &where = "");
92
93 /// Hide all canvas displays
94 void Hide();
95
96 /// Remove canvas from global canvas lists, will be destroyed when shared_ptr will be removed
97 void Remove();
98
99 /// Insert panel into the canvas, canvas should be shown at this moment
100 template <class PANEL>
101 bool AddPanel(std::shared_ptr<PANEL> &panel) {
102 if (!fPainter) return false;
103 return fPainter->AddPanel(panel->GetWindow());
104 }
105
106 // Indicates that primitives list was changed or any primitive was modified
107 void Modified() { fModified++; }
108
109 // Return if canvas was modified and not yet updated
110 bool IsModified() const;
111
112 /// update drawing
113 void Update(bool async = false, CanvasCallback_t callback = nullptr);
114
115 /// Run canvas functionality for given time (in seconds)
116 void Run(double tm = 0.);
117
118 /// Save canvas in image file
119 void SaveAs(const std::string &filename, bool async = false, CanvasCallback_t callback = nullptr);
120
121 /// Get the canvas's title.
122 const std::string &GetTitle() const { return fTitle; }
123
124 /// Set the canvas's title.
125 RCanvas &SetTitle(const std::string &title) {
126 fTitle = title;
127 return *this;
128 }
129
130 /// Convert a `Pixel` position to Canvas-normalized positions.
131 std::array<RPadLength::Normal, 2> PixelsToNormal(const std::array<RPadLength::Pixel, 2> &pos) const final
132 {
133 return {{pos[0] / fSize[0], pos[1] / fSize[1]}};
134 }
135
136 static const std::vector<std::shared_ptr<RCanvas>> GetCanvases();
137};
138
139} // namespace Experimental
140} // namespace ROOT
141
142#endif
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
A window's topmost RPad.
Definition: RCanvas.hxx:33
static const std::vector< std::shared_ptr< RCanvas > > GetCanvases()
Definition: RCanvas.cxx:47
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:71
const std::string & GetTitle() const
Get the canvas's title.
Definition: RCanvas.hxx:122
RCanvas & SetSize(const RPadLength::Pixel &width, const RPadLength::Pixel &height)
Set canvas pixel size - width and height.
Definition: RCanvas.hxx:83
RCanvas & SetTitle(const std::string &title)
Set the canvas's title.
Definition: RCanvas.hxx:125
RCanvas & SetSize(const std::array< RPadLength::Pixel, 2 > &sz)
Set canvas pixel size as array with two elements - width and height.
Definition: RCanvas.hxx:77
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:131
std::array< RPadLength::Pixel, 2 > fSize
Size of the canvas in pixels,.
Definition: RCanvas.hxx:40
bool IsModified() const
Returns true is canvas was modified since last painting.
Definition: RCanvas.cxx:71
const std::array< RPadLength::Pixel, 2 > & GetSize() const
Return canvas pixel size as array with two elements - width and height.
Definition: RCanvas.hxx:74
RCanvas & operator=(const RCanvas &)=delete
Disable assignment for now.
void Show(const std::string &where="")
Display the canvas.
Definition: RCanvas.cxx:113
void Remove()
Remove canvas from global canvas lists, will be destroyed when shared_ptr will be removed.
Definition: RCanvas.cxx:175
void Run(double tm=0.)
Run canvas functionality for given time (in seconds)
Definition: RCanvas.cxx:226
std::string fTitle
use for ID generation
Definition: RCanvas.hxx:37
uint64_t fModified
Modify counter, incremented every time canvas is changed.
Definition: RCanvas.hxx:43
std::unique_ptr< Internal::RVirtualCanvasPainter > fPainter
The painter of this canvas, bootstrapping the graphics connection.
Definition: RCanvas.hxx:50
static std::shared_ptr< RCanvas > Create(const std::string &title)
Definition: RCanvas.cxx:88
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:68
uint64_t fIdCounter
counter for objects, id==1 is canvas itself
Definition: RCanvas.hxx:45
void Update(bool async=false, CanvasCallback_t callback=nullptr)
update drawing
Definition: RCanvas.cxx:76
void SaveAs(const std::string &filename, bool async=false, CanvasCallback_t callback=nullptr)
Save canvas in image file.
Definition: RCanvas.cxx:151
bool AddPanel(std::shared_ptr< PANEL > &panel)
Insert panel into the canvas, canvas should be shown at this moment.
Definition: RCanvas.hxx:101
std::string GenerateUniqueId()
Generates unique ID inside the canvas.
Definition: RCanvas.cxx:63
void Hide()
Hide all canvas displays.
Definition: RCanvas.cxx:139
Base class for graphic containers for RDrawable-s.
Definition: RPad.hxx:41
std::function< void(bool)> CanvasCallback_t
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
A pixel coordinate: 0 in the left, bottom corner, 1 in the top, right corner of the RPad.
Definition: RPadLength.hxx:85