doodle  0.2
Intended to support teaching C++, doodle is a simple library that helps make a window and makes it easy to do some drawing.
drawing.hpp
Go to the documentation of this file.
1 /*--------------------------------------------------------------*
2  Copyright (C) 2021 Rudy Castan
3 
4  This file is distributed WITHOUT ANY WARRANTY. See the file
5  `License.md' for details.
6 *--------------------------------------------------------------*/
7 #pragma once
8 #include <doodle/color.hpp>
9 
10 #include <doodle/image.hpp>
11 #include <string>
12 
13 namespace doodle
14 {
43  void clear_background() noexcept;
69  void clear_background(HexColor color) noexcept;
105  void clear_background(Color color) noexcept;
138  void clear_background(double grey, double alpha = 255) noexcept;
173  void clear_background(double red, double green, double blue, double alpha = 255) noexcept;
174 
201  void set_fill_color(HexColor color) noexcept;
229  void set_fill_color(Color color) noexcept;
257  void set_fill_color(double grey, double alpha = 255) noexcept;
288  void set_fill_color(double red, double green, double blue, double alpha = 255) noexcept;
313  void no_fill() noexcept;
341  void set_outline_color(HexColor color) noexcept;
370  void set_outline_color(Color color) noexcept;
399  void set_outline_color(double grey, double alpha = 255) noexcept;
430  void set_outline_color(double red, double green, double blue, double alpha = 255) noexcept;
454  void no_outline();
498  void draw_ellipse(double x, double y, double width, double height = 0) noexcept;
538  void draw_line(double x1, double y1, double x2, double y2) noexcept;
576  void draw_quad(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) noexcept;
614  void draw_rectangle(double x, double y, double width, double height = 0) noexcept;
655  void draw_triangle(double x1, double y1, double x2, double y2, double x3, double y3) noexcept;
656 
661  enum class EllipseMode
662  {
666  Center,
671  Corner
672  };
713  void set_ellipse_mode(EllipseMode mode) noexcept;
718  enum class RectMode
719  {
725  Corner,
729  Center
730  };
771  void set_rectangle_mode(RectMode mode) noexcept;
777  enum class FrameOfReference
778  {
827  };
868  void set_frame_of_reference(FrameOfReference frame_of_reference) noexcept;
900  void smooth_drawing() noexcept;
932  void no_smoothing() noexcept;
966  void set_outline_width(double line_width) noexcept;
967 
1030  void push_settings() noexcept;
1082  void pop_settings() noexcept;
1151  void draw_text(const std::wstring& str, double x, double y) noexcept;
1195  void draw_text(const std::string& str, double x, double y) noexcept;
1253  int create_distance_field_bitmap_font(const std::filesystem::path& fnt_filepath) noexcept;
1257  constexpr int DEFAULT_FONT_ID = 0;
1310  void set_font(int font_id) noexcept;
1335  void set_font_size(double font_size) noexcept;
1392  void set_font_fade_out_interval(double inside_distance, double outside_distance) noexcept;
1442  void set_font_backdrop_fade_out_interval(double inside_distance, double outside_distance) noexcept;
1475  void set_font_backdrop_offset(double texel_x, double texel_y) noexcept;
1519 
1567  Image capture_screenshot_to_image(int left_x, int bottom_y, int pixels_width, int pixels_height) noexcept;
1568 
1607  void draw_image(const Image& image, double x, double y) noexcept;
1645  void draw_image(const Image& image, double x, double y, double width, double height) noexcept;
1711  void draw_image(const Image& image, double x, double y, double width, double height, int texel_x,
1712  int texel_y) noexcept;
1780  void draw_image(const Image& image, double x, double y, double width, double height, int texel_x, int texel_y,
1781  int texel_width, int texel_height) noexcept;
1819  void set_tint_color(HexColor color) noexcept;
1857  void set_tint_color(Color color) noexcept;
1896  void set_tint_color(double grey, double alpha = 255) noexcept;
1937  void set_tint_color(double red, double green, double blue, double alpha = 255) noexcept;
1974  void no_tint() noexcept;
2019  void set_image_mode(RectMode mode) noexcept;
2063  void apply_scale(double scale) noexcept;
2104  void apply_scale(double scale_x, double scale_y) noexcept;
2143  void apply_rotate(double angle_in_radians) noexcept;
2182  void apply_translate(double translate_x, double translate_y) noexcept;
2231  void apply_matrix(double a, double b, double c, double d, double e, double f) noexcept;
2232 
2251  void begin_drawing_to_image(int image_width, int image_height, bool apply_antialiasing = true);
2252 
2262  Image end_drawing_to_image(bool smooth_texture = false);
2263 
2266 }
This is a helper class to easily represent an RGBA color as an int with hexadecimal notation.
Definition: color.hpp:158
Image class to store a 2D array of RGBA colors. Also manages an image on the Graphics Card.
Definition: image.hpp:30
void set_fill_color(HexColor color) noexcept
Sets the color used to fill shapes to the specified HexColor.
void no_outline()
Disables drawing the outline.
void set_outline_color(HexColor color) noexcept
Set the outline and lines of shapes to the specified HexColor.
void no_fill() noexcept
Disables filling geometry.
void clear_background() noexcept
Clear the background to black.
Image end_drawing_to_image(bool smooth_texture=false)
End a session of drawing to an image.
void draw_image(const Image &image, double x, double y) noexcept
Draw an entire image to the screen.
void set_tint_color(HexColor color) noexcept
Sets the fill value for displaying images to the specified HexColor.
void begin_drawing_to_image(int image_width, int image_height, bool apply_antialiasing=true)
Redirect all draw command to draw to an image.
void set_image_mode(RectMode mode) noexcept
Modifies the location from which textures are drawn by changing the way in which parameters given to ...
Image capture_screenshot_to_image()
Captures a screenshot of the whole screen.
void no_tint() noexcept
Removes the current fill value for displaying images and reverts to displaying textures with their or...
void smooth_drawing() noexcept
Draws all geometry with smooth (anti-aliased) edges.
EllipseMode
With set_ellipse_mode(), modifies the location from which ellipses are drawn by changing the way in w...
Definition: drawing.hpp:662
void set_ellipse_mode(EllipseMode mode) noexcept
Modifies the location from which ellipses are drawn by changing the way in which parameters given to ...
void draw_quad(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) noexcept
Draw a quad.
void draw_line(double x1, double y1, double x2, double y2) noexcept
Draws a line (a direct path between two points) to the screen.
void draw_triangle(double x1, double y1, double x2, double y2, double x3, double y3) noexcept
Draw a triangle to the screen.
void set_outline_width(double line_width) noexcept
Sets the width of the outline used for lines and the border around shapes. All widths are set in unit...
FrameOfReference
Used to define the coordinate system you would like to reference.
Definition: drawing.hpp:778
RectMode
With set_rectangle_mode(), modifies the location from which rectangles are drawn by changing the way ...
Definition: drawing.hpp:719
void set_rectangle_mode(RectMode mode) noexcept
Modifies the location from which rectangles are drawn by changing the way in which parameters given t...
void pop_settings() noexcept
The pop_settings() function restores to the previous style settings and transformations,...
void no_smoothing() noexcept
Draws all geometry with jagged (aliased) edges.
void draw_rectangle(double x, double y, double width, double height=0) noexcept
Draws a rectangle to the screen.
void draw_ellipse(double x, double y, double width, double height=0) noexcept
Draws an ellipse (oval) to the screen.
void set_frame_of_reference(FrameOfReference frame_of_reference) noexcept
Change the coordinate system you would like to use when describing your primitives.
void push_settings() noexcept
The push_settings() function saves the current drawing style settings and transformations,...
@ Corner
Interprets the first two parameters of draw_ellipse() as the upper-left or bottom-left corner of the ...
@ Center
Interprets the first two parameters of draw_ellipse() as the shape's center point.
@ LeftHanded_OriginTopLeft
The Origin (0,0) is always in the top left of the screen. Positive x goes to the right and Positive y...
@ RightHanded_OriginCenter
The Origin (0,0) is always in the center of the screen. Positive x goes to the right and Positive y g...
@ RightHanded_OriginBottomLeft
The Origin (0,0) is always in the bottom left of the screen. Positive x goes to the right and Positiv...
@ Corner
The default mode is RectMode::CORNER, which interprets the first two parameters of draw_rectangle() a...
@ Center
RectMode::CENTER interprets the first two parameters of draw_rectangle() as the shape's center point.
void apply_rotate(double angle_in_radians) noexcept
Rotates a shape the amount specified by the angle in radians.
void apply_translate(double translate_x, double translate_y) noexcept
Specifies an amount to displace objects within the display window.
void apply_scale(double scale) noexcept
Uniformly increases or decreases the size of a shape by expanding and contracting vertices.
void apply_matrix(double a, double b, double c, double d, double e, double f) noexcept
Multiplies the current matrix by the one specified through the parameters.
void set_font_backdrop_offset(double texel_x, double texel_y) noexcept
Repositions the backdrop of the font characters. Useful for creating a custom drop shadow effect.
int create_distance_field_bitmap_font(const std::filesystem::path &fnt_filepath) noexcept
Given a file path to a *.fnt file it will create a distance field bitmap font.
void set_font_fade_out_interval(double inside_distance, double outside_distance) noexcept
Defines the distance interval to draw font characters and how to fade them out from opaque to translu...
void draw_text(const std::wstring &str, double x, double y) noexcept
Draws wide character based text to the screen.
void set_font_backdrop_fade_out_interval(double inside_distance, double outside_distance) noexcept
Defines the distance interval to draw the backdrop of font characters and how to fade them out from o...
constexpr int DEFAULT_FONT_ID
Holds the ID value for the provided font that comes with doodle.
Definition: drawing.hpp:1257
void set_font_size(double font_size) noexcept
Sets the current font size. This size will be used in all subsequent calls to the draw_text() functio...
void set_font(int font_id) noexcept
Changes the font type to be used when drawing text.
Definition: angle.hpp:11
Color is a color represented with four unsigned bytes.
Definition: color.hpp:53