Logo ROOT   6.16/01
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 void SetSize(const std::array<RPadLength::Pixel, 2> &sz) { fSize = sz; }
78
79 /// Set canvas pixel size - width and 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 /// Hide all canvas displays
90 void Hide();
91
92 /// Remove canvas from global canvas lists, will be destroyed when shared_ptr will be removed
93 void Remove();
94
95 /// Insert panel into the canvas, canvas should be shown at this moment
96 template <class PANEL>
97 bool AddPanel(std::shared_ptr<PANEL> &panel) {
98 if (!fPainter) return false;
99 return fPainter->AddPanel(panel->GetWindow());
100 }
101
102 // Indicates that primitives list was changed or any primitive was modified
103 void Modified() { fModified++; }
104
105 // Return if canvas was modified and not yet updated
106 bool IsModified() const;
107
108 /// update drawing
109 void Update(bool async = false, CanvasCallback_t callback = nullptr);
110
111 /// Run canvas functionality for given time (in seconds)
112 void Run(double tm = 0.);
113
114 /// Save canvas in image file
115 void SaveAs(const std::string &filename, bool async = false, CanvasCallback_t callback = nullptr);
116
117 /// Get the canvas's title.
118 const std::string &GetTitle() const { return fTitle; }
119
120 /// Set the canvas's title.
121 void SetTitle(const std::string &title) { fTitle = title; }
122
123 /// Convert a `Pixel` position to Canvas-normalized positions.
124 std::array<RPadLength::Normal, 2> PixelsToNormal(const std::array<RPadLength::Pixel, 2> &pos) const final
125 {
126 return {{pos[0] / fSize[0], pos[1] / fSize[1]}};
127 }
128
129 static const std::vector<std::shared_ptr<RCanvas>> GetCanvases();
130};
131
132} // namespace Experimental
133} // namespace ROOT
134
135#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:118
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:124
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
void 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::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
void SetTitle(const std::string &title)
Set the canvas's title.
Definition: RCanvas.hxx:121
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 SetSize(const RPadLength::Pixel &width, const RPadLength::Pixel &height)
Set canvas pixel size - width and height.
Definition: RCanvas.hxx:80
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:97
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