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.
Classes | Functions
Image

Classes

class  doodle::Image
 Image class to store a 2D array of RGBA colors. Also manages an image on the Graphics Card. More...
 

Functions

Image doodle::capture_screenshot_to_image ()
 Captures a screenshot of the whole screen. More...
 
Image doodle::capture_screenshot_to_image (int left_x, int bottom_y, int pixels_width, int pixels_height) noexcept
 Captures a screenshot of a subsection of the screen. More...
 
void doodle::draw_image (const Image &image, double x, double y) noexcept
 Draw an entire image to the screen. More...
 
void doodle::draw_image (const Image &image, double x, double y, double width, double height) noexcept
 Draw an entire image to the screen and resize it to a custom size. More...
 
void doodle::draw_image (const Image &image, double x, double y, double width, double height, int texel_x, int texel_y) noexcept
 Draw a subsection of the image to the screen. More...
 
void doodle::draw_image (const Image &image, double x, double y, double width, double height, int texel_x, int texel_y, int texel_width, int texel_height) noexcept
 Draw a subsection of the image to the screen. More...
 
void doodle::set_tint_color (HexColor color) noexcept
 Sets the fill value for displaying images to the specified HexColor. More...
 
void doodle::set_tint_color (Color color) noexcept
 Sets the fill value for displaying textures to the specified Color. More...
 
void doodle::set_tint_color (double grey, double alpha=255) noexcept
 Sets the fill value for displaying textures to the specified grey color. More...
 
void doodle::set_tint_color (double red, double green, double blue, double alpha=255) noexcept
 Sets the fill value for displaying textures to the specified RGBA color. More...
 
void doodle::no_tint () noexcept
 Removes the current fill value for displaying images and reverts to displaying textures with their original colors. More...
 
void doodle::set_image_mode (RectMode mode) noexcept
 Modifies the location from which textures are drawn by changing the way in which parameters given to draw_image() are interpreted. More...
 
void doodle::begin_drawing_to_image (int image_width, int image_height, bool apply_antialiasing=true)
 Redirect all draw command to draw to an image. More...
 
Image doodle::end_drawing_to_image (bool smooth_texture=false)
 End a session of drawing to an image. More...
 

Detailed Description

Function Documentation

◆ begin_drawing_to_image()

void doodle::begin_drawing_to_image ( int  image_width,
int  image_height,
bool  apply_antialiasing = true 
)

Redirect all draw command to draw to an image.

Parameters
image_widthThe desired width of the image
image_heightThe desired height of the image
apply_antialiasingShould multi-sample anti-aliasing be applied?
using namespace doodle;
Image GenerateBearImage(bool apply_antialising);
int main(void)
{
create_window(480, 320);
const Image bear_aliased = GenerateBearImage(false);
const Image bear_not_aliased = GenerateBearImage(true);
while (!is_window_closed())
{
clear_background(100, 149, 237);
for (int i = 0; i < 26; i++)
draw_ellipse(-Width / 2.0 + i * 20.0, 0, 10);
draw_image(bear_aliased, -Width / 4.0, 0, 250, 250);
draw_image(bear_not_aliased, Width / 4.0, 0, 250, 250);
}
return 0;
}
Image GenerateBearImage(bool apply_antialising)
{
begin_drawing_to_image(250, 250, apply_antialising);
set_fill_color(87, 27, 0);
draw_ellipse(100, 150, 105, 105); // left big ear
draw_ellipse(400, 150, 100, 100); // right big ear
set_fill_color(174, 66, 1);
draw_ellipse(100, 150, 70, 70); // left ear
draw_ellipse(400, 150, 70, 70); // right ear
set_outline_width(3); // head
draw_ellipse(500 / 2.0, 500 / 2.0, 335, 335); // head
no_outline(); // eyes
set_fill_color(255, 255, 255); // white
draw_ellipse(170, 200, 70, 70); // left eye
draw_ellipse(330, 200, 70, 70);
set_fill_color(0, 0, 0); // black
draw_ellipse(170, 200, 50, 50); // left pupil
draw_ellipse(330, 200, 50, 50); // right pupil
no_outline(); // nose
set_fill_color(0, 0, 0);
draw_ellipse(250, 270, 75, 50);
no_fill(); // mouth
draw_ellipse(250, 325, 100, 50);
}
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.
bool create_window() noexcept
Create a default window.
int Width
System variable that stores the width of the drawing canvas. This value is set by the desired_width p...
bool is_window_closed() noexcept
Is the window closed?
void update_window() noexcept
Update the doodle application.
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 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 ...
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...
void pop_settings() noexcept
The pop_settings() function restores to the previous style settings and transformations,...
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,...
@ LeftHanded_OriginTopLeft
The Origin (0,0) is always in the top left of the screen. Positive x goes to the right and Positive y...
@ Center
RectMode::CENTER interprets the first two parameters of draw_rectangle() as the shape's center point.
void apply_scale(double scale) noexcept
Uniformly increases or decreases the size of a shape by expanding and contracting vertices.
Definition: angle.hpp:11

◆ capture_screenshot_to_image() [1/2]

Image doodle::capture_screenshot_to_image ( )

Captures a screenshot of the whole screen.

Returns
The screenshot is saved into an Image object, which can be used to save it to a file if desired.
using namespace doodle;
int main(void)
{
create_window(480, 360);
clear_background(HexColor{0x1E4155FF});
set_fill_color(HexColor{0x149EBCFF});
draw_ellipse(-Width / 4.0, -Height / 4.0, 100, 60);
set_fill_color(HexColor{0xFDEED8Ff});
draw_rectangle(Width / 4.0, -Height / 4.0, 100, 60);
set_fill_color(HexColor{0xE74F32FF});
draw_triangle(50, 50, 200, 70, 150, 100);
set_fill_color(HexColor{0xC82733FF});
draw_quad(-50, 25, -230, 70, -150, 160, -60, 140);
const Image results = capture_screenshot_to_image();
results.SaveToFile(R"(capture_screenshot_to_image.png)");
return 0;
}
int Height
System variable that stores the height of the drawing canvas. This value is set by the desired_height...
Image capture_screenshot_to_image()
Captures a screenshot of the whole screen.
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_triangle(double x1, double y1, double x2, double y2, double x3, double y3) noexcept
Draw a triangle to the screen.
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 draw_rectangle(double x, double y, double width, double height=0) noexcept
Draws a rectangle to the screen.

◆ capture_screenshot_to_image() [2/2]

Image doodle::capture_screenshot_to_image ( int  left_x,
int  bottom_y,
int  pixels_width,
int  pixels_height 
)
noexcept

Captures a screenshot of a subsection of the screen.

Useful if you only want to save a portion of the screen.

The coordinates you give are assumed to be in the RightHanded_OriginBottomLeft frame of reference.

Parameters
left_xx-coordinate for the left part of the box containing the screenshot
bottom_yy-coordinate for the bottom part of the box containing the screenshot
pixels_widthwidth of the box containing the screenshot
pixels_heightheight of the box containing the screenshot
Returns
The screenshot is saved into an Image object, which can be used to save it to a file if desired.
using namespace doodle;
int main(void)
{
create_window(480, 360);
clear_background(HexColor{0x1E4155FF});
set_fill_color(HexColor{0x149EBCFF});
draw_ellipse(-Width / 4.0, -Height / 4.0, 100, 60);
set_fill_color(HexColor{0xFDEED8Ff});
draw_rectangle(Width / 4.0, -Height / 4.0, 100, 60);
set_fill_color(HexColor{0xE74F32FF});
draw_triangle(50, 50, 200, 70, 150, 100);
set_fill_color(HexColor{0xC82733FF});
draw_quad(-50, 25, -230, 70, -150, 160, -60, 140);
// take a screenshot of only the right half of the screen
const int left = Width / 2;
const int bottom = 0;
const int capture_width = Width / 2;
const int capture_height = Height;
const Image results = capture_screenshot_to_image(left, bottom, capture_width, capture_height);
results.SaveToFile(R"(capture_screenshot_to_image_2_subsection.png)");
return 0;
}

◆ draw_image() [1/4]

void doodle::draw_image ( const Image image,
double  x,
double  y 
)
noexcept

Draw an entire image to the screen.

The width and height of the image will be based off of the image width and image height.

Parameters
imageimage object to draw
xx-coordinate of the rectangle to draw the image.
yy-coordinate of the rectangle to draw the image.

The following example uses this orange hero image file.

#include <exception>
#include <iostream>
using namespace doodle;
int main(void)
try
{
create_window(240, 180);
const Image orangeHero{"orange_hero.png"};
while (!is_window_closed())
{
clear_background(HexColor{0x3546530A});
draw_image(orangeHero, 0, 0);
}
return 0;
}
catch (const std::exception& e)
{
std::cerr << e.what() << '\n';
return -1;
}

◆ draw_image() [2/4]

void doodle::draw_image ( const Image image,
double  x,
double  y,
double  width,
double  height 
)
noexcept

Draw an entire image to the screen and resize it to a custom size.

Parameters
imageimage object to draw
xx-coordinate of the rectangle to draw the image.
yy-coordinate of the rectangle to draw the image.
widthhow wide to draw the image
heighthow tall to draw the image

The following example uses this orange hero image file.

#include <exception>
#include <iostream>
using namespace doodle;
int main(void)
try
{
create_window(240, 180);
const Image orangeHero{"orange_hero.png"};
while (!is_window_closed())
{
clear_background(HexColor{0x3546530A});
draw_image(orangeHero, 0, 0, 64, 128);
}
return 0;
}
catch (const std::exception& e)
{
std::cerr << e.what() << '\n';
return -1;
}

◆ draw_image() [3/4]

void doodle::draw_image ( const Image image,
double  x,
double  y,
double  width,
double  height,
int  texel_x,
int  texel_y 
)
noexcept

Draw a subsection of the image to the screen.

The subsection is defined is defined by the box

Image
  (0,0)
    +---------------------------------------------------------------------+
    |                                                                     |
    |(texel_x,texel_y)                                                    |
    |        o--------------------------------+                           |
    |        |                                |                           |
    |        |                                |                           |
    |        |                                |                           |
    |        |                                |                           |
    |        |                                |                           |
    |        +--------------------------------o                           |
    |                           (texel_x+width,texel_y+height)            |
    |                                                                     |
    |                                                                     |
    |                                                                     |
    +---------------------------------------------------------------------+
                                                              (image_width,image_height)
Parameters
imageimage object to draw
xx-coordinate of the rectangle to draw the image.
yy-coordinate of the rectangle to draw the image.
widthhow wide to draw the image
heighthow tall to draw the image
texel_xHorizontally, where in image to start reading colors from the image. 0 is the far left and image width is the far right.
texel_yVertically, where in image to start reading colors from the image. 0 is the far top and image height is the far bottom.

The following example uses this orange hero image file.

#include <exception>
#include <iostream>
using namespace doodle;
int main(void)
try
{
create_window(240, 180);
const Image orangeHero{"orange_hero.png"};
while (!is_window_closed())
{
clear_background(HexColor{0x3546530A});
draw_image(orangeHero, 0, 0, 16, 16, 8, 0);
}
return 0;
}
catch (const std::exception& e)
{
std::cerr << e.what() << '\n';
return -1;
}

◆ draw_image() [4/4]

void doodle::draw_image ( const Image image,
double  x,
double  y,
double  width,
double  height,
int  texel_x,
int  texel_y,
int  texel_width,
int  texel_height 
)
noexcept

Draw a subsection of the image to the screen.

The subsection is defined is defined by the box

  Image
(0,0)
  +---------------------------------------------------------------------+
  |                                                                     |
  |(texel_x,texel_y)                                                    |
  |        o--------------------------------+                           |
  |        |                                |                           |
  |        |                                |                           |
  |        |                                |                           |
  |        |                                |                           |
  |        |                                |                           |
  |        +--------------------------------o                           |
  |                     (texel_x+texel_width,texel_y+texel_height)      |
  |                                                                     |
  |                                                                     |
  |                                                                     |
  +---------------------------------------------------------------------+
                                                            (image_width,image_height)
Parameters
imageimage object to draw
xx-coordinate of the rectangle to draw the image.
yy-coordinate of the rectangle to draw the image.
widthhow wide to draw the image
heighthow tall to draw the image
texel_xHorizontally, where in image to start reading colors from the image. 0 is the far left and image width is the far right.
texel_yVertically, where in image to start reading colors from the image. 0 is the far top and image height is the far bottom.
texel_widthwidth of image subsection to read the colors from
texel_heightheight of image subsection to read the colors from

The following example uses this orange hero image file.

#include <exception>
#include <iostream>
using namespace doodle;
int main(void)
try
{
create_window(240, 180);
const Image orangeHero{"orange_hero.png"};
while (!is_window_closed())
{
clear_background(HexColor{0x3546530A});
draw_image(orangeHero, 0, 0, 128, 128, 8, 0, 16, 16);
}
return 0;
}
catch (const std::exception& e)
{
std::cerr << e.what() << '\n';
return -1;
}

◆ end_drawing_to_image()

Image doodle::end_drawing_to_image ( bool  smooth_texture = false)

End a session of drawing to an image.

Parameters
smooth_textureShould the texture use a smooth filtering when being drawn
Returns
An Image representing what was drawn.
using namespace doodle;
Image GenerateOFaceImage(bool smooth_filter);
int main(void)
{
create_window(480, 320);
const Image smiley_nosmooth = GenerateOFaceImage(false);
const Image smiley_smooth = GenerateOFaceImage(true);
while (!is_window_closed())
{
clear_background(100, 149, 237);
for (int i = 0; i < 20; i++)
draw_ellipse(0, -Height / 2.0 + i * 20.0, 10);
draw_image(smiley_nosmooth, 0, 0);
draw_image(smiley_smooth, -Width / 3.0, 0.0, 200, 200);
draw_image(smiley_nosmooth, Width / 3.0, 0.0, 200, 200);
}
return 0;
}
Image GenerateOFaceImage(bool smooth_filter)
{
constexpr double diameter = 100.0;
constexpr double size_scale = 0.25;
constexpr int image_width = static_cast<int>(diameter);
constexpr int image_height = static_cast<int>(diameter);
begin_drawing_to_image(image_width, image_height);
set_fill_color(255, 255, 0);
draw_ellipse(0, 0, diameter);
set_fill_color(255); // eyes
draw_ellipse(-67 * size_scale, 67 * size_scale, diameter / 10);
draw_ellipse(67 * size_scale, 67 * size_scale, diameter / 10);
draw_ellipse(-67 * size_scale, 67 * size_scale, diameter / 20);
draw_ellipse(67 * size_scale, 67 * size_scale, diameter / 20);
set_outline_width(3.0); // mouth
draw_ellipse(0, -67 * size_scale, diameter / 2 * size_scale, 90 * size_scale);
return end_drawing_to_image(smooth_filter);
}

◆ no_tint()

void doodle::no_tint ( )
noexcept

Removes the current fill value for displaying images and reverts to displaying textures with their original colors.

The following example uses this orange hero image file.

#include <exception>
#include <iostream>
using namespace doodle;
int main(void)
try
{
create_window(240, 180);
const Image orangeHero{"orange_hero.png"};
while (!is_window_closed())
{
set_tint_color(0, 153, 204);
draw_image(orangeHero, -Width / 4.0, 0, 64, 128);
draw_image(orangeHero, Width / 4.0, 0, 64, 128);
}
return 0;
}
catch (const std::exception& e)
{
std::cerr << e.what() << '\n';
return -1;
}
void set_tint_color(HexColor color) noexcept
Sets the fill value for displaying images to the specified HexColor.
void no_tint() noexcept
Removes the current fill value for displaying images and reverts to displaying textures with their or...

◆ set_image_mode()

void doodle::set_image_mode ( RectMode  mode)
noexcept

Modifies the location from which textures are drawn by changing the way in which parameters given to draw_image() are interpreted.

The default mode is RectMode::CORNER, which interprets the first two parameters of draw_image() as upper-left or bottom-left corner of the shape in a left handed doodle::FrameOfReference and right handed doodle::FrameOfReference respectively, while the third and fourth parameters are its width and height.

RectMode::CENTER interprets the first two parameters of draw_image() as the shape's center point, while the third and fourth parameters are its width and height.

Parameters
modeeither CORNER or CENTER
#include <exception>
#include <iostream>
using namespace doodle;
int main(void)
try
{
create_window(240, 180);
const Image orangeHero{"orange_hero.png"};
while (!is_window_closed())
{
set_tint_color(0, 153, 204);
draw_image(orangeHero, 0, 0);
draw_image(orangeHero, 0, 0);
}
return 0;
}
catch (const std::exception& e)
{
std::cerr << e.what() << '\n';
return -1;
}
@ Corner
The default mode is RectMode::CORNER, which interprets the first two parameters of draw_rectangle() a...

◆ set_tint_color() [1/4]

void doodle::set_tint_color ( Color  color)
noexcept

Sets the fill value for displaying textures to the specified Color.

Textures can be tinted to specified colors or made transparent by including an alpha value.

Parameters
colorColor to apply to textures

The following example uses this orange hero image file.

#include <exception>
#include <iostream>
using namespace doodle;
int main(void)
try
{
create_window(240, 180);
const Image orangeHero{"orange_hero.png"};
while (!is_window_closed())
{
set_tint_color(Color{255, 78, 0}); // red
draw_image(orangeHero, 0, 0, 64, 128);
}
return 0;
}
catch (const std::exception& e)
{
std::cerr << e.what() << '\n';
return -1;
}

◆ set_tint_color() [2/4]

void doodle::set_tint_color ( double  grey,
double  alpha = 255 
)
noexcept

Sets the fill value for displaying textures to the specified grey color.

Textures can be tinted to specified colors or made transparent by including an alpha value.

Parameters
greyspecifies a value between white and black
alphaoptional opacity value of the background between 0-255. The default value is 255.

The following example uses this orange hero image file.

#include <exception>
#include <iostream>
using namespace doodle;
int main(void)
try
{
create_window(240, 180);
const Image orangeHero{"orange_hero.png"};
while (!is_window_closed())
{
set_tint_color(255, 128); // ~50% transparent
draw_image(orangeHero, 0, 0, 64, 128);
}
return 0;
}
catch (const std::exception& e)
{
std::cerr << e.what() << '\n';
return -1;
}

◆ set_tint_color() [3/4]

void doodle::set_tint_color ( double  red,
double  green,
double  blue,
double  alpha = 255 
)
noexcept

Sets the fill value for displaying textures to the specified RGBA color.

Textures can be tinted to specified colors or made transparent by including an alpha value.

Parameters
redvalue between 0-255
greenvalue between 0-255
bluevalue between 0-255
alphaoptional opacity value of the background between 0-255. The default value is 255.

The following example uses this orange hero image file.

#include <exception>
#include <iostream>
using namespace doodle;
int main(void)
try
{
create_window(240, 180);
const Image orangeHero{"orange_hero.png"};
while (!is_window_closed())
{
set_tint_color(255, 240, 0); // yellow
draw_image(orangeHero, 0, 0, 64, 128);
}
return 0;
}
catch (const std::exception& e)
{
std::cerr << e.what() << '\n';
return -1;
}

◆ set_tint_color() [4/4]

void doodle::set_tint_color ( HexColor  color)
noexcept

Sets the fill value for displaying images to the specified HexColor.

Images can be tinted to specified colors or made transparent by including an alpha value.

Parameters
colorHexColor to apply to images

The following example uses this orange hero image file.

#include <exception>
#include <iostream>
using namespace doodle;
int main(void)
try
{
create_window(240, 180);
const Image orangeHero{"orange_hero.png"};
while (!is_window_closed())
{
set_tint_color(HexColor{0xFF4E0080}); //~50% transparent and red
draw_image(orangeHero, 0, 0, 64, 128);
}
return 0;
}
catch (const std::exception& e)
{
std::cerr << e.what() << '\n';
return -1;
}