Logo ROOT   6.18/05
Reference Guide
List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
ROOT::Experimental::RCanvas Class Reference

A window's topmost RPad.

Definition at line 33 of file RCanvas.hxx.

Public Member Functions

 RCanvas ()=default
 Create a temporary RCanvas; for long-lived ones please use Create(). More...
 
 ~RCanvas ()=default
 
template<class PANEL >
bool AddPanel (std::shared_ptr< PANEL > &panel)
 Insert panel into the canvas, canvas should be shown at this moment. More...
 
const RCanvasGetCanvas () const override
 Access to the top-most canvas, if any (const version). More...
 
RCanvasGetCanvas () override
 Access to the top-most canvas, if any (non-const version). More...
 
const std::array< RPadLength::Pixel, 2 > & GetSize () const
 Return canvas pixel size as array with two elements - width and height. More...
 
const std::string & GetTitle () const
 Get the canvas's title. More...
 
void Hide ()
 Hide all canvas displays. More...
 
bool IsModified () const
 Returns true is canvas was modified since last painting. More...
 
void Modified ()
 
std::array< RPadLength::Normal, 2 > PixelsToNormal (const std::array< RPadLength::Pixel, 2 > &pos) const final
 Convert a Pixel position to Canvas-normalized positions. More...
 
void Remove ()
 Remove canvas from global canvas lists, will be destroyed when shared_ptr will be removed. More...
 
void Run (double tm=0.)
 Run canvas functionality for given time (in seconds) More...
 
void SaveAs (const std::string &filename, bool async=false, CanvasCallback_t callback=nullptr)
 Save canvas in image file. More...
 
RCanvasSetSize (const RPadLength::Pixel &width, const RPadLength::Pixel &height)
 Set canvas pixel size - width and height. More...
 
RCanvasSetSize (const std::array< RPadLength::Pixel, 2 > &sz)
 Set canvas pixel size as array with two elements - width and height. More...
 
RCanvasSetTitle (const std::string &title)
 Set the canvas's title. More...
 
void Show (const std::string &where="")
 Display the canvas. More...
 
void Update (bool async=false, CanvasCallback_t callback=nullptr)
 update drawing More...
 
- Public Member Functions inherited from ROOT::Experimental::RPadBase
virtual ~RPadBase ()
 
void CreateFrameIfNeeded ()
 
std::vector< std::vector< RPad * > > Divide (int nHoriz, int nVert, const RPadExtent &padding={})
 Divide this pad into a grid of subpads with padding in between. More...
 
template<class T , class... ARGS>
auto Draw (const std::shared_ptr< T > &what, ARGS... args)
 Add something to be painted. More...
 
template<class T , class... ARGS, class = typename std::enable_if<!ROOT::TypeTraits::IsSmartOrDumbPtr<T>::value>::type>
auto Draw (const T &what, ARGS... args)
 Add a copy of something to be painted. More...
 
template<class T , class... ARGS>
auto Draw (std::unique_ptr< T > &&what, ARGS... args)
 Add something to be painted. More...
 
std::shared_ptr< RDrawableFindDrawable (const std::string &id) const
 
RPadUserAxisBaseGetAxis (size_t dimension) const
 Get a pad axis from the RFrame. More...
 
virtual const RCanvasGetCanvas () const =0
 Access to the top-most canvas, if any (const version). More...
 
virtual RCanvasGetCanvas ()=0
 Access to the top-most canvas, if any (non-const version). More...
 
const RFrameGetFrame () const
 
RPadUserAxisBaseGetOrCreateAxis (size_t dimension)
 Get a pad axis from the RFrame. More...
 
RFrameGetOrCreateFrame ()
 
const Primitives_tGetPrimitives () const
 Get the elements contained in the canvas. More...
 
virtual std::array< RPadLength::Normal, 2 > PixelsToNormal (const std::array< RPadLength::Pixel, 2 > &pos) const =0
 Convert a Pixel position to Canvas-normalized positions. More...
 
bool Remove (RDrawingOptsBase &opts)
 Remove an object from the list of primitives. More...
 
void SetAllAxisAutoBounds ()
 Set the range of an axis as bound kind and bound (up or down). More...
 
void SetAllAxisBound (const std::vector< BoundKindAndValue > &vecBoundAndKind)
 Set the range of an axis as bound kind and bound (up or down). More...
 
void SetAllAxisBounds (const std::vector< std::array< double, 2 > > &vecBeginAndEnd)
 Set the range of an axis as bound kind and bound (up or down). More...
 
void SetAxisAutoBounds (int dimension)
 Set the range of an axis as bound kind and bound (up or down). More...
 
void SetAxisBound (int dimension, RPadUserAxisBase::EAxisBoundsKind boundsKind, double bound)
 Set the range of an axis as bound kind and bound (up or down). More...
 
void SetAxisBounds (int dimension, double begin, double end)
 Set the range of an axis as begin, end. More...
 
std::array< RPadLength::Normal, 2 > UserToNormal (const std::array< RPadLength::User, 2 > &pos) const
 Convert user coordinates to normal coordinates. More...
 
void Wipe ()
 Wipe the pad by clearing the list of primitives. More...
 

Static Public Member Functions

static std::shared_ptr< RCanvasCreate (const std::string &title)
 
static const std::vector< std::shared_ptr< RCanvas > > GetCanvases ()
 

Private Member Functions

 RCanvas (const RCanvas &)=delete
 Disable copy construction for now. More...
 
std::string GenerateUniqueId ()
 Generates unique ID inside the canvas. More...
 
RCanvasoperator= (const RCanvas &)=delete
 Disable assignment for now. More...
 

Private Attributes

uint64_t fIdCounter {2}
 counter for objects, id==1 is canvas itself More...
 
uint64_t fModified {0}
 Modify counter, incremented every time canvas is changed. More...
 
std::unique_ptr< Internal::RVirtualCanvasPainterfPainter
 The painter of this canvas, bootstrapping the graphics connection. More...
 
std::array< RPadLength::Pixel, 2 > fSize
 Size of the canvas in pixels,. More...
 
std::string fTitle
 use for ID generation More...
 

Friends

class RPadBase
 

Additional Inherited Members

- Public Types inherited from ROOT::Experimental::RPadBase
using Primitives_t = std::vector< std::shared_ptr< RDrawable > >
 
- Protected Member Functions inherited from ROOT::Experimental::RPadBase
 RPadBase ()=default
 Allow derived classes to default construct a RPadBase. More...
 

#include <ROOT/RCanvas.hxx>

Inheritance diagram for ROOT::Experimental::RCanvas:
[legend]

Constructor & Destructor Documentation

◆ RCanvas() [1/2]

ROOT::Experimental::RCanvas::RCanvas ( const RCanvas )
privatedelete

Disable copy construction for now.

◆ RCanvas() [2/2]

ROOT::Experimental::RCanvas::RCanvas ( )
default

Create a temporary RCanvas; for long-lived ones please use Create().

◆ ~RCanvas()

ROOT::Experimental::RCanvas::~RCanvas ( )
default

Member Function Documentation

◆ AddPanel()

template<class PANEL >
bool ROOT::Experimental::RCanvas::AddPanel ( std::shared_ptr< PANEL > &  panel)
inline

Insert panel into the canvas, canvas should be shown at this moment.

Definition at line 101 of file RCanvas.hxx.

◆ Create()

std::shared_ptr< ROOT::Experimental::RCanvas > ROOT::Experimental::RCanvas::Create ( const std::string &  title)
static

Definition at line 88 of file RCanvas.cxx.

◆ GenerateUniqueId()

std::string ROOT::Experimental::RCanvas::GenerateUniqueId ( )
private

Generates unique ID inside the canvas.

Definition at line 63 of file RCanvas.cxx.

◆ GetCanvas() [1/2]

const RCanvas * ROOT::Experimental::RCanvas::GetCanvas ( ) const
inlineoverridevirtual

Access to the top-most canvas, if any (const version).

Implements ROOT::Experimental::RPadBase.

Definition at line 68 of file RCanvas.hxx.

◆ GetCanvas() [2/2]

RCanvas * ROOT::Experimental::RCanvas::GetCanvas ( )
inlineoverridevirtual

Access to the top-most canvas, if any (non-const version).

Implements ROOT::Experimental::RPadBase.

Definition at line 71 of file RCanvas.hxx.

◆ GetCanvases()

const std::vector< std::shared_ptr< ROOT::Experimental::RCanvas > > ROOT::Experimental::RCanvas::GetCanvases ( )
static

Definition at line 47 of file RCanvas.cxx.

◆ GetSize()

const std::array< RPadLength::Pixel, 2 > & ROOT::Experimental::RCanvas::GetSize ( ) const
inline

Return canvas pixel size as array with two elements - width and height.

Definition at line 74 of file RCanvas.hxx.

◆ GetTitle()

const std::string & ROOT::Experimental::RCanvas::GetTitle ( ) const
inline

Get the canvas's title.

Definition at line 122 of file RCanvas.hxx.

◆ Hide()

void ROOT::Experimental::RCanvas::Hide ( )

Hide all canvas displays.

Definition at line 139 of file RCanvas.cxx.

◆ IsModified()

bool ROOT::Experimental::RCanvas::IsModified ( ) const

Returns true is canvas was modified since last painting.

Definition at line 71 of file RCanvas.cxx.

◆ Modified()

void ROOT::Experimental::RCanvas::Modified ( )
inline

Definition at line 107 of file RCanvas.hxx.

◆ operator=()

RCanvas & ROOT::Experimental::RCanvas::operator= ( const RCanvas )
privatedelete

Disable assignment for now.

◆ PixelsToNormal()

std::array< RPadLength::Normal, 2 > ROOT::Experimental::RCanvas::PixelsToNormal ( const std::array< RPadLength::Pixel, 2 > &  pos) const
inlinefinalvirtual

Convert a Pixel position to Canvas-normalized positions.

Implements ROOT::Experimental::RPadBase.

Definition at line 131 of file RCanvas.hxx.

◆ Remove()

void ROOT::Experimental::RCanvas::Remove ( )

Remove canvas from global canvas lists, will be destroyed when shared_ptr will be removed.

Remove canvas from global canvas lists, will be destroyed once last shared_ptr is disappear.

Definition at line 175 of file RCanvas.cxx.

◆ Run()

void ROOT::Experimental::RCanvas::Run ( double  tm = 0.)

Run canvas functionality for given time (in seconds)

Run canvas functionality for the given time (in seconds) Used to process canvas-related actions in the appropriate thread context.

Must be regularly called when canvas created and used in extra thread. Time parameter specifies minimal execution time in seconds - if default value 0 is used, just all pending actions will be performed. When canvas is not yet displayed - just performs sleep for given time interval.

Example of usage:

void draw_canvas(bool &run_loop, std::make_shared<RH1D> hist)
{
auto canvas = RCanvas::Create("Canvas title");
canvas->Draw(hist)->SetLineColor(RColor::kBlue);
canvas->Show();
while (run_loop) {
pHist->Fill(1);
canvas->Modified();
canvas->Update();
canvas->Run(0.1); // process canvas events
}
canvas->Remove();
}
int main()
{
RAxisConfig xaxis(100, -10., 10.);
auto pHist = std::make_shared<RH1D>(xaxis);
bool run_loop = true;
std::thread thrd(draw_canvas, run_loop, pHist);
std::this_thread::sleep_for(std::chrono::seconds(100));
run_loop = false;
thrd.join();
return 0;
}
static std::shared_ptr< RCanvas > Create(const std::string &title)
Definition: RCanvas.cxx:88
static constexpr RGBA kBlue
Definition: RColor.hxx:256
int main(int argc, char **argv)

Definition at line 226 of file RCanvas.cxx.

◆ SaveAs()

void ROOT::Experimental::RCanvas::SaveAs ( const std::string &  filename,
bool  async = false,
CanvasCallback_t  callback = nullptr 
)

Save canvas in image file.

Create image file for the canvas Supported SVG (extension .svg), JPEG (extension .jpg or .jpeg) and PNG (extension .png)

Parameters
asyncspecifies if file can be created asynchronous to the caller thread When operation completed, callback function is called

Definition at line 151 of file RCanvas.cxx.

◆ SetSize() [1/2]

RCanvas & ROOT::Experimental::RCanvas::SetSize ( const RPadLength::Pixel width,
const RPadLength::Pixel height 
)
inline

Set canvas pixel size - width and height.

Definition at line 83 of file RCanvas.hxx.

◆ SetSize() [2/2]

RCanvas & ROOT::Experimental::RCanvas::SetSize ( const std::array< RPadLength::Pixel, 2 > &  sz)
inline

Set canvas pixel size as array with two elements - width and height.

Definition at line 77 of file RCanvas.hxx.

◆ SetTitle()

RCanvas & ROOT::Experimental::RCanvas::SetTitle ( const std::string &  title)
inline

Set the canvas's title.

Definition at line 125 of file RCanvas.hxx.

◆ Show()

void ROOT::Experimental::RCanvas::Show ( const std::string &  where = "")

Display the canvas.

Create new display for the canvas Parameter.

where specifies which program could be used for display creation
Possible values:
 cef - Chromium Embeded Framework, local display, local communication
 qt5 - Qt5 WebEngine (when running via rootqt5), local display, local communication
browser - default system web-browser, communication via random http port from range 8800 - 9800 <prog> - any program name which will be started instead of default browser, like firefox or /usr/bin/opera one could also specify $url in program name, which will be replaced with canvas URL native - either any available local display or default browser

Canvas can be displayed in several different places

Definition at line 113 of file RCanvas.cxx.

◆ Update()

void ROOT::Experimental::RCanvas::Update ( bool  async = false,
CanvasCallback_t  callback = nullptr 
)

update drawing

Definition at line 76 of file RCanvas.cxx.

Friends And Related Function Documentation

◆ RPadBase

friend class RPadBase
friend

Definition at line 34 of file RCanvas.hxx.

Member Data Documentation

◆ fIdCounter

uint64_t ROOT::Experimental::RCanvas::fIdCounter {2}
private

counter for objects, id==1 is canvas itself

Definition at line 45 of file RCanvas.hxx.

◆ fModified

uint64_t ROOT::Experimental::RCanvas::fModified {0}
private

Modify counter, incremented every time canvas is changed.

!

Definition at line 43 of file RCanvas.hxx.

◆ fPainter

std::unique_ptr<Internal::RVirtualCanvasPainter> ROOT::Experimental::RCanvas::fPainter
private

The painter of this canvas, bootstrapping the graphics connection.

Unmapped canvases (those that never had Draw() invoked) might not have a painter. !

Definition at line 50 of file RCanvas.hxx.

◆ fSize

std::array<RPadLength::Pixel, 2> ROOT::Experimental::RCanvas::fSize
private

Size of the canvas in pixels,.

Definition at line 40 of file RCanvas.hxx.

◆ fTitle

std::string ROOT::Experimental::RCanvas::fTitle
private

use for ID generation

Title of the canvas.

Definition at line 37 of file RCanvas.hxx.

Libraries for ROOT::Experimental::RCanvas:
[legend]

The documentation for this class was generated from the following files: