19 #ifndef EZGL_CANVAS_HPP
20 #define EZGL_CANVAS_HPP
22 #include "ezgl/camera.hpp"
23 #include "ezgl/rectangle.hpp"
24 #include "ezgl/graphics.hpp"
25 #include "ezgl/color.hpp"
28 #include <cairo-pdf.h>
29 #include <cairo-svg.h>
64 char const *
id()
const
66 return m_canvas_id.c_str();
116 bool print_svg(
const char *file_name,
int width = 0,
int height = 0);
117 bool print_png(
const char *file_name,
int width = 0,
int height = 0);
139 std::string m_canvas_id;
148 color m_background_color;
151 GtkWidget *m_drawing_area =
nullptr;
154 cairo_surface_t *m_surface =
nullptr;
157 cairo_t *m_context =
nullptr;
160 renderer *m_animation_renderer =
nullptr;
164 static gboolean configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer data);
167 static gboolean draw_surface(GtkWidget *widget, cairo_t *context, gpointer data);
The core application.
Definition: application.hpp:95
Manages the transformations between coordinate systems.
Definition: camera.hpp:40
Responsible for creating, destroying, and maintaining the rendering context of a GtkWidget.
Definition: canvas.hpp:54
camera const & get_camera() const
Get an immutable reference to this canvas' camera.
Definition: canvas.hpp:89
void initialize(GtkWidget *drawing_area)
Lazy initialization of the canvas class.
int width() const
Get the width of the canvas in pixels.
int height() const
Get the height of the canvas in pixels.
canvas(std::string canvas_id, draw_canvas_fn draw_callback, rectangle coordinate_system, color background_color)
Create a canvas that can be drawn to.
char const * id() const
Get the name (identifier) of the canvas.
Definition: canvas.hpp:64
camera & get_camera()
Get a mutable reference to this canvas' camera.
Definition: canvas.hpp:97
renderer * create_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...
void redraw()
Force the canvas to redraw itself.
Represents a rectangle as two diagonally opposite points.
Definition: rectangle.hpp:31
Provides functions to draw primitives (e.g., lines, shapes) to a rendering context (the MainCanvas).
Definition: graphics.hpp:173
A library for creating a graphical user interface.
Definition: application.hpp:40
void(*)(renderer *) draw_canvas_fn
The signature of a function that draws to an ezgl::canvas.
Definition: canvas.hpp:43
Represents a color as a mixture or red, green, and blue as well as the transparency level.
Definition: color.hpp:31