ezgl  1.0.1
An Easy Graphics & GUI Library
Public Member Functions | Protected Member Functions | Friends | List of all members
ezgl::canvas Class Reference

Responsible for creating, destroying, and maintaining the rendering context of a GtkWidget. More...

#include <canvas.hpp>

Public Member Functions

 ~canvas ()
 Destructor.
 
char const * id () const
 Get the name (identifier) of the canvas.
 
int width () const
 Get the width of the canvas in pixels.
 
int height () const
 Get the height of the canvas in pixels.
 
void redraw ()
 Force the canvas to redraw itself. More...
 
camera const & get_camera () const
 Get an immutable reference to this canvas' camera.
 
cameraget_camera ()
 Get a mutable reference to this canvas' camera.
 
renderercreate_animation_renderer ()
 Create an animation renderer that can be used to draw on top of the current canvas.
 
bool print_pdf (const char *file_name, int width=0, int height=0)
 print_pdf, print_svg, and print_png generate a PDF, SVG, or PNG output file showing all the graphical content of the current canvas. More...
 
bool print_svg (const char *file_name, int width=0, int height=0)
 
bool print_png (const char *file_name, int width=0, int height=0)
 

Protected Member Functions

 canvas (std::string canvas_id, draw_canvas_fn draw_callback, rectangle coordinate_system, color background_color)
 Create a canvas that can be drawn to.
 
void initialize (GtkWidget *drawing_area)
 Lazy initialization of the canvas class. More...
 

Friends

class application
 

Detailed Description

Responsible for creating, destroying, and maintaining the rendering context of a GtkWidget.

Underneath, the class relies on a GtkDrawingArea as its GUI widget along with cairo to provide the rendering context. The class connects to the relevant GTK signals, namely configure and draw events, to remain responsive.

Each canvas is double-buffered. A draw callback (see: ezgl::draw_canvas_fn) is invoked each time the canvas needs to be redrawn. This may be caused by the user (e.g., resizing the screen), but can also be forced by the programmer.

Member Function Documentation

◆ initialize()

void ezgl::canvas::initialize ( GtkWidget *  drawing_area)
protected

Lazy initialization of the canvas class.

This function is required because GTK will not send activate/startup signals to an ezgl::application until control of the program has been reliquished. The GUI is not built until ezgl::application receives an activate signal.

◆ print_pdf()

bool ezgl::canvas::print_pdf ( const char *  file_name,
int  width = 0,
int  height = 0 
)

print_pdf, print_svg, and print_png generate a PDF, SVG, or PNG output file showing all the graphical content of the current canvas.

Parameters
file_namename of the output file
Returns
returns true if the function has successfully generated the output file, otherwise failed due to errors such as out of memory occurs.

◆ redraw()

void ezgl::canvas::redraw ( )

Force the canvas to redraw itself.

This will invoke the ezgl::draw_canvas_fn callback and queue a redraw of the GtkWidget.


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