19 #ifndef EZGL_GRAPHICS_HPP
20 #define EZGL_GRAPHICS_HPP
22 #include "ezgl/color.hpp"
23 #include "ezgl/point.hpp"
24 #include "ezgl/rectangle.hpp"
25 #include "ezgl/camera.hpp"
30 #ifdef CAIRO_HAS_XLIB_SURFACE
31 #ifdef GDK_WINDOWING_X11
32 #include <cairo-xlib.h>
105 normal = CAIRO_FONT_SLANT_NORMAL,
110 italic = CAIRO_FONT_SLANT_ITALIC,
115 oblique = CAIRO_FONT_SLANT_OBLIQUE
125 normal = CAIRO_FONT_WEIGHT_NORMAL,
130 bold = CAIRO_FONT_WEIGHT_BOLD
140 butt = CAIRO_LINE_CAP_BUTT,
146 round = CAIRO_LINE_CAP_ROUND
242 void set_color(uint_fast8_t red, uint_fast8_t green, uint_fast8_t blue, uint_fast8_t alpha = 255);
398 double extent_angle);
408 void draw_arc(
point2d center,
double radius,
double start_angle,
double extent_angle);
423 double extent_angle);
433 void fill_arc(
point2d center,
double radius,
double start_angle,
double extent_angle);
514 void draw_rectangle_path(
point2d start,
point2d end,
bool fill_flag);
516 void draw_arc_path(
point2d center,
520 double stretch_factor,
524 bool rectangle_off_screen(
rectangle rect);
534 Drawable x11_drawable;
537 Display *x11_display =
nullptr;
543 bool transparency_flag =
false;
554 double rotation_angle = 0;
563 int current_line_width = 0;
572 color current_color = {0, 0, 0, 255};
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
Represents a two-dimensional point.
Definition: point.hpp:27
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
void set_color(uint_fast8_t red, uint_fast8_t green, uint_fast8_t blue, uint_fast8_t alpha=255)
Change the color for subsequent draw calls.
rectangle world_to_screen(const rectangle &box)
Get the screen coordinates (pixel locations) of the world coordinate rectangle box.
void fill_rectangle(rectangle r)
Draw a filled in rectangle.
void fill_poly(std::vector< point2d > const &points)
Draw a filled polygon The polygon can have an arbitrary shape and be convex or non-convex,...
void set_line_cap(line_cap cap)
Change how line endpoints will be rendered in subsequent draw calls.
void draw_text(point2d point, std::string const &text)
Draw text justified at the chosen point, according to the current justification.
static void free_surface(surface *surface)
Free a surface.
void set_text_rotation(double degrees)
set the rotation_angle at which subsequent text drawing should render.
void set_color(color new_color)
Change the color for subsequent draw calls.
rectangle get_visible_world()
Get the current visible bounds of the world.
void update_renderer(cairo_t *cairo, cairo_surface_t *m_surface)
Update the renderer when the cairo surface/context changes.
void fill_elliptic_arc(point2d center, double radius_x, double radius_y, double start_angle, double extent_angle)
Draw a filled in elliptic arc.
void draw_arc(point2d center, double radius, double start_angle, double extent_angle)
Draw the outline of an arc.
void fill_arc(point2d center, double radius, double start_angle, double extent_angle)
Draw a filled in arc.
void set_horiz_justification(justification horiz_just)
set horizontal justification; used for text and surfaces.
void draw_rectangle(point2d start, point2d end)
Draw the outline a rectangle.
rectangle get_visible_screen()
Get the current visible bounds of the screen in pixel coordinates.
void set_coordinate_system(t_coordinate_system new_coordinate_system)
Change the current coordinate system.
void draw_rectangle(point2d start, double width, double height)
Draw the outline of a rectangle.
std::function< point2d(point2d)> transform_fn
A callback for transforming points from one coordinate system to another.
Definition: graphics.hpp:495
void draw_text(point2d point, std::string const &text, double bound_x, double bound_y)
Draw text if it fits in the specified bounds; otherwise not drawn.
void format_font(std::string const &family, font_slant slant, font_weight weight)
Change the font.
void format_font(std::string const &family, font_slant slant, font_weight weight, double new_size)
Change the font.
void set_visible_world(rectangle new_world)
Set the visible bounds of the world.
void set_vert_justification(justification vert_just)
set vertical justification; used for text and surfaces.
void set_line_width(int width)
Set the line width.
void draw_surface(surface *p_surface, point2d anchor_point, double scale_factor=1)
Draw a surface.
void fill_rectangle(point2d start, double width, double height)
Draw a filled in rectangle.
void set_color(color new_color, uint_fast8_t alpha)
Change the color for subsequent draw calls.
static surface * load_png(const char *file_path)
load a png image into a bitmap surface
renderer(cairo_t *cairo, transform_fn transform, camera *m_camera, cairo_surface_t *m_surface)
Constructor.
void draw_rectangle(rectangle r)
Draw the outline of a rectangle.
void draw_line(point2d start, point2d end)
Draw a line.
void set_font_size(double new_size)
Change the font size.
void fill_rectangle(point2d start, point2d end)
Draw a filled in rectangle.
void draw_elliptic_arc(point2d center, double radius_x, double radius_y, double start_angle, double extent_angle)
Draw the outline of an elliptic arc.
void set_line_dash(line_dash dash)
Change the dash style of the line for subsequent draw calls.
A library for creating a graphical user interface.
Definition: application.hpp:40
line_dash
The dash style of a line.
Definition: graphics.hpp:152
@ none
No dashes in the line (i.e., solid).
@ asymmetric_5_3
Dash to whitespace ratio is 5:3.
font_weight
The weight of the font.
Definition: graphics.hpp:121
@ normal
No additional weight.
line_cap
The shape of a line's start and end point.
Definition: graphics.hpp:136
@ butt
Start and stop the line exactly where it begins/ends.
@ round
Each end of the line has circles.
font_slant
The slant of the font.
Definition: graphics.hpp:101
@ italic
Slant is more calligraphic.
@ oblique
Slanted to the right.
t_coordinate_system
Available coordinate systems.
Definition: graphics.hpp:57
@ WORLD
Default coordinate system; specified by the user as any desired range.
Definition: graphics.hpp:63
@ SCREEN
Screen (pixel) coordinate system.
Definition: graphics.hpp:67
justification
Justification options used for text and surfaces.
Definition: graphics.hpp:73
@ bottom
Bottom justification: used for vertical justification.
@ right
Right justification: used for horizontal justification.
@ left
Left justification: used for horizontal justification.
@ center
Center Justification: used for both vertical and horizontal justification.
@ top
Top justification: used for vertical justification.
cairo_surface_t surface
define ezgl::surface type used for drawing png bitmaps
Definition: graphics.hpp:52
Represents a color as a mixture or red, green, and blue as well as the transparency level.
Definition: color.hpp:31