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.
Functions | Variables
Environment

Functions

bool doodle::create_window () noexcept
 Create a default window. More...
 
bool doodle::create_window (const std::string &title) noexcept
 Create a default window with a custom window title. More...
 
bool doodle::create_window (int desired_width, int desired_height) noexcept
 Create a window with a desired screen size. More...
 
bool doodle::create_window (const std::string &title, int desired_width, int desired_height) noexcept
 Create a window with a custom window title and a desired screen size. More...
 
bool doodle::create_window (const std::string &title, int desired_width, int desired_height, int screen_x, int screen_y) noexcept
 Create a window with a custom window title and a desired screen size. More...
 
bool doodle::is_window_closed () noexcept
 Is the window closed? More...
 
void doodle::update_window () noexcept
 Update the doodle application. More...
 
void doodle::close_window () noexcept
 Programmatically close the window. More...
 
void doodle::set_window_title (const std::string &new_title) noexcept
 Set a new title for the window. More...
 
bool doodle::is_full_screen () noexcept
 Is the window a fullscreen window? More...
 
void doodle::toggle_full_screen () noexcept
 Switch back and forth between fullscreen and windowed mode. More...
 
void doodle::set_callback_window_resized (std::function< void(int, int)> &&callback) noexcept
 The provided callback function is called whenever the window is resized by the user. More...
 
void doodle::set_callback_window_closed (std::function< void(void)> &&callback) noexcept
 The provided callback function will be called when the user uses the OS to close the window. More...
 
void doodle::set_callback_window_focus_changed (std::function< void(bool)> &&callback) noexcept
 THe provided callback function will be called when the window gains or loses focus. More...
 
void doodle::show_cursor (bool show_it=true) noexcept
 This function will allow you to hide or show the mouse cursor. More...
 
EVENT_HOOK void on_window_resized (int new_width, int new_height)
 The declaration of the optional on_window_resized function to implement in your doodle program. More...
 
EVENT_HOOK void on_window_closed ()
 The declaration of the optional on_window_closed function to implement in your doodle program. More...
 
EVENT_HOOK void on_window_focus_changed (bool is_focused)
 The declaration of the optional on_window_focus_changed function to implement in your doodle program. More...
 

Variables

int doodle::FrameCount
 The system variable FrameCount contains the number of frames that have been displayed since the program started. The first call to update_window() will set the value to 1 and subsequent calls increment the value. More...
 
double doodle::DeltaTime
 The system variable DeltaTime contains the time difference between the beginning of the previous frame and the beginning of the current frame in seconds. More...
 
double doodle::ElapsedTime
 Returns the number of seconds since starting the program. This information is often used for timing events and animation sequences. More...
 
int doodle::Width
 System variable that stores the width of the drawing canvas. This value is set by the desired_width parameter of the create_window() function. For example, the function call create_window(320, 240) sets the width variable to the value 320. More...
 
int doodle::Height
 System variable that stores the height of the drawing canvas. This value is set by the desired_height parameter of the create_window() function. For example, the function call create_window(320, 240) sets the height variable to the value 240. More...
 
bool doodle::WindowIsFocused
 Confirms if the window a doodle program is in is "focused," meaning that the doodle will accept mouse or keyboard input. This variable is "true" if the window is focused and "false" if not. More...
 

Detailed Description

global variables related to the state of the doodle

Function Documentation

◆ close_window()

void doodle::close_window ( )
noexcept

Programmatically close the window.

using namespace doodle;
int main(void)
{
create_window(480, 360);
bool closing = false;
double countDown = 2.0;
while (!is_window_closed())
{
clear_background(HexColor{0xE27E75FF});
if (!closing)
{
draw_text("Hi", 0, 0);
{
closing = true;
}
}
else
{
draw_text("Bye!", 0, 0);
countDown -= DeltaTime;
if (countDown < 0)
}
}
return 0;
}
void clear_background() noexcept
Clear the background to black.
double DeltaTime
The system variable DeltaTime contains the time difference between the beginning of the previous fram...
bool create_window() noexcept
Create a default window.
bool is_window_closed() noexcept
Is the window closed?
void close_window() noexcept
Programmatically close the window.
void update_window() noexcept
Update the doodle application.
bool KeyIsPressed
The boolean system variable KeyIsPressed is true if any key is pressed and false if no keys are press...
KeyboardButtons Key
The system variable key always contains the value of the most recent key on the keyboard that was typ...
void draw_text(const std::wstring &str, double x, double y) noexcept
Draws wide character based text to the screen.
Definition: angle.hpp:11
@ Escape
The Escape key.

◆ create_window() [1/5]

bool doodle::create_window ( )
noexcept

Create a default window.

Creates a window in the middle of the screen, roughly 75% the width & height of the monitor.

Returns
True if window was create, false otherwise
#include <string>
using namespace doodle;
int main(void)
{
using namespace std::string_literals;
const std::string text = "("s + std::to_string(Width) + ","s + std::to_string(Height) + ")"s;
while (!is_window_closed())
{
clear_background(HexColor{0x9E1F33FF});
draw_text(text, 0, 0);
}
return 0;
}
int Width
System variable that stores the width of the drawing canvas. This value is set by the desired_width p...
int Height
System variable that stores the height of the drawing canvas. This value is set by the desired_height...
std::string to_string(MouseButtons button) noexcept
Convert MouseButtons enum to std::string.

On a 1920x1080 monitor:

◆ create_window() [2/5]

bool doodle::create_window ( const std::string &  title)
noexcept

Create a default window with a custom window title.

Parameters
titlecustom title for the window
Returns
True if window was create, false otherwise
#include <string>
using namespace doodle;
int main(void)
{
create_window("Orange Window");
using namespace std::string_literals;
const std::string text = "("s + std::to_string(Width) + ","s + std::to_string(Height) + ")"s;
while (!is_window_closed())
{
clear_background(HexColor{0xC75023FF});
draw_text(text, 0, 0);
}
return 0;
}

On a 1920x1080 monitor:

◆ create_window() [3/5]

bool doodle::create_window ( const std::string &  title,
int  desired_width,
int  desired_height 
)
noexcept

Create a window with a custom window title and a desired screen size.

Parameters
titlecustom title for the window
desired_widthhow wide you'd like the screen space to be
desired_heighthow tall you'd like the screen space to be
Returns
True if window was create, false otherwise
#include <string>
using namespace doodle;
int main(void)
{
create_window("Jungle Green Window", 480, 360);
using namespace std::string_literals;
const std::string text = "("s + std::to_string(Width) + ","s + std::to_string(Height) + ")"s;
while (!is_window_closed())
{
clear_background(HexColor{0x2A9D9BFF});
draw_text(text, -Width / 2.0 + 70, 0);
}
return 0;
}

◆ create_window() [4/5]

bool doodle::create_window ( const std::string &  title,
int  desired_width,
int  desired_height,
int  screen_x,
int  screen_y 
)
noexcept

Create a window with a custom window title and a desired screen size.

Parameters
titlecustom title for the window
desired_widthhow wide you'd like the screen space to be
desired_heighthow tall you'd like the screen space to be
screen_xwith respect to the top left of the window, defines where to position the window on the monitor screen
screen_ywith respect to the top left of the window, defines where to position the window on the monitor screen
Returns
True if window was create, false otherwise
#include <string>
using namespace doodle;
int main(void)
{
constexpr int desiredWidth = 960;
constexpr int desiredHeight = 720;
constexpr int screenX = 100;
constexpr int screenY = 50;
create_window("Tickle Me Pink Window", desiredWidth, desiredHeight, screenX, screenY);
using namespace std::string_literals;
const std::string text = "("s + std::to_string(Width) + ","s + std::to_string(Height) + ")"s;
while (!is_window_closed())
{
clear_background(HexColor{0xFF80A9FF});
draw_text(text, -Width / 2.0 + 280, 0);
}
return 0;
}

◆ create_window() [5/5]

bool doodle::create_window ( int  desired_width,
int  desired_height 
)
noexcept

Create a window with a desired screen size.

Parameters
desired_widthhow wide you'd like the screen space to be
desired_heighthow tall you'd like the screen space to be
Returns
True if window was create, false otherwise
#include <string>
using namespace doodle;
int main(void)
{
create_window(480, 360);
using namespace std::string_literals;
const std::string text = "("s + std::to_string(Width) + ","s + std::to_string(Height) + ")"s;
while (!is_window_closed())
{
clear_background(HexColor{0xF69C40FF});
draw_text(text, -Width / 2.0 + 70, 0);
}
return 0;
}

◆ is_full_screen()

bool doodle::is_full_screen ( )
noexcept

Is the window a fullscreen window?

Returns
true if the window is fullscreen, false if it is windowed
#include <sstream>
using namespace doodle;
int main(void)
{
create_window(640, 480);
{
if(button == KeyboardButtons::F)
else if(button == KeyboardButtons::Escape)
});
std::stringstream ss;
while (!is_window_closed())
{
clear_background(HexColor{0x614A86FF});
ss.clear();
ss.str("");
ss << "fullscreen: " << std::boolalpha << is_full_screen();
draw_text(ss.str(), -280,0);
}
return 0;
}
bool is_full_screen() noexcept
Is the window a fullscreen window?
void toggle_full_screen() noexcept
Switch back and forth between fullscreen and windowed mode.
void set_callback_key_released(std::function< void(KeyboardButtons)> &&callback) noexcept
The provided callback function is called once every time a key is released.
KeyboardButtons
Definition: input.hpp:26

◆ is_window_closed()

bool doodle::is_window_closed ( )
noexcept

Is the window closed?

Should be used to drive the applications main loop. If the user closes the window through the operating system then you need to end your loop.

Returns
true if the window closed, false if it is still open
#include <string>
using namespace doodle;
int main(void)
{
create_window(480, 360);
while (!is_window_closed())
{
clear_background(HexColor{0xD7CF9CFF});
draw_text("Winter Hazel", -Width / 2.0 + 20, 0);
}
return 0;
}

◆ on_window_closed()

EVENT_HOOK void on_window_closed ( )

The declaration of the optional on_window_closed function to implement in your doodle program.

If you define the function definition of this function then it will be called when the window closes.

#include <iostream>
using namespace doodle;
void on_window_closed() { std::cerr << "Shutdown!\n"; }
int main(void)
{
create_window(640, 480);
std::cout << "Start\n";
while (!is_window_closed())
{
clear_background(HexColor{0xedd884ff});
}
return 0;
}
EVENT_HOOK void on_window_closed()
The declaration of the optional on_window_closed function to implement in your doodle program.

Prints the following:

Start
Shutdown!

◆ on_window_focus_changed()

EVENT_HOOK void on_window_focus_changed ( bool  is_focused)

The declaration of the optional on_window_focus_changed function to implement in your doodle program.

If you define the function definition of this function then it will be called when the window changes it's focus.

Parameters
is_focusedtrue when window has focus and false otherwise
using namespace doodle;
Color clearColor = HexColor{0xD7A5860A};
int main(void)
{
create_window(480, 320);
while (!is_window_closed())
{
clear_background(clearColor);
}
return 0;
}
void on_window_focus_changed(bool is_focused)
{
if (is_focused)
{
clearColor = HexColor{0xD7A5860A};
set_window_title("doodle - focused");
}
else
{
clearColor = Color{0, 10};
set_window_title("doodle - not focused");
}
}
EVENT_HOOK void on_window_focus_changed(bool is_focused)
The declaration of the optional on_window_focus_changed function to implement in your doodle program.
void set_window_title(const std::string &new_title) noexcept
Set a new title for the window.

◆ on_window_resized()

EVENT_HOOK void on_window_resized ( int  new_width,
int  new_height 
)

The declaration of the optional on_window_resized function to implement in your doodle program.

If you define the function definition of this function then it will be called when the window resizes.

Parameters
new_widthWidth of the new window resolution
new_heightHeight of the new window resolution
#include <sstream>
using namespace doodle;
std::stringstream ss;
int main(void)
{
create_window(640, 480);
while (!is_window_closed())
{
clear_background(HexColor{0x969EC2FF});
draw_text(ss.str(), -280, 0);
}
return 0;
}
void on_window_resized(int new_width, int new_height)
{
ss.clear();
ss.str("");
ss << "(" << new_width << ", " << new_height << ")";
}
EVENT_HOOK void on_window_resized(int new_width, int new_height)
The declaration of the optional on_window_resized function to implement in your doodle program.

◆ set_callback_window_closed()

void doodle::set_callback_window_closed ( std::function< void(void)> &&  callback)
noexcept

The provided callback function will be called when the user uses the OS to close the window.

It takes in a std::function with a signature of something that returns nothing and takes in nothing. Something like

void windowClosed();
Parameters
callbackwhat to call when the window will close
#include <iostream>
using namespace doodle;
void windowClosed() { std::cerr << "Shutdown!\n"; }
int main(void)
{
create_window(640, 480);
std::cout << "Start\n";
while (!is_window_closed())
{
clear_background(HexColor{0xedd884ff});
}
return 0;
}
void set_callback_window_closed(std::function< void(void)> &&callback) noexcept
The provided callback function will be called when the user uses the OS to close the window.

Prints the following:

Start
Shutdown!

◆ set_callback_window_focus_changed()

void doodle::set_callback_window_focus_changed ( std::function< void(bool)> &&  callback)
noexcept

THe provided callback function will be called when the window gains or loses focus.

It takes in a std::function with a signature of something that returns nothing and takes in a boolean. Something like

void windowFocusChanged(bool is_focused);
Parameters
callbackwhat to call when the window has lost or gained focus
using namespace doodle;
int main(void)
{
create_window(480, 320);
Color clearColor = HexColor{0xD7A5860A};
set_callback_window_focus_changed([&](bool is_focused) {
if (is_focused)
{
clearColor = HexColor{0xD7A5860A};
set_window_title("doodle - focused");
}
else
{
clearColor = Color{0, 10};
set_window_title("doodle - not focused");
}
});
while (!is_window_closed())
{
clear_background(clearColor);
}
return 0;
}
void set_callback_window_focus_changed(std::function< void(bool)> &&callback) noexcept
THe provided callback function will be called when the window gains or loses focus.

◆ set_callback_window_resized()

void doodle::set_callback_window_resized ( std::function< void(int, int)> &&  callback)
noexcept

The provided callback function is called whenever the window is resized by the user.

It takes in a std::function with a signature of something that returns nothing and takes in two integers. Something like

void windowResized(int new_width, int new_height);
Parameters
callbackwhat to call when the window is resized
#include <sstream>
using namespace doodle;
int main(void)
{
create_window(640, 480);
std::stringstream ss;
set_callback_window_resized([&ss](int new_width, int new_height)
{
ss.clear();
ss.str("");
ss << "(" << new_width << ", " << new_height << ")";
});
while (!is_window_closed())
{
clear_background(HexColor{0x969EC2FF});
draw_text(ss.str(), -280,0);
}
return 0;
}
void set_callback_window_resized(std::function< void(int, int)> &&callback) noexcept
The provided callback function is called whenever the window is resized by the user.

◆ set_window_title()

void doodle::set_window_title ( const std::string &  new_title)
noexcept

Set a new title for the window.

Parameters
new_titlea new title for the window
#include <sstream>
using namespace doodle;
int main(void)
{
create_window(480, 360);
double frameTime = 0;
double frameCount = 0;
while (!is_window_closed())
{
frameTime += DeltaTime;
frameCount += 1.0;
if (frameTime > 0.5)
{
const auto fps = frameCount / frameTime;
frameCount = 0;
frameTime = 0;
std::stringstream ss;
ss << "doodle [fps=" << fps << "]";
set_window_title(ss.str());
}
}
return 0;
}

◆ show_cursor()

void doodle::show_cursor ( bool  show_it = true)
noexcept

This function will allow you to hide or show the mouse cursor.

Parameters
show_itshould the cursor be visible or not
using namespace doodle;
{
if (button == KeyboardButtons::Escape)
show_cursor(false);
if (button == KeyboardButtons::Space)
}
int main(void)
{
create_window(480, 360);
while (!is_window_closed())
{
clear_background(HexColor{0xf7fcfdaa});
}
return 0;
}
void show_cursor(bool show_it=true) noexcept
This function will allow you to hide or show the mouse cursor.
EVENT_HOOK void on_key_released(doodle::KeyboardButtons button)
The declaration of the optional on_key_released function to implement in your doodle program.
@ Space
The Space key.

◆ toggle_full_screen()

void doodle::toggle_full_screen ( )
noexcept

Switch back and forth between fullscreen and windowed mode.

#include <sstream>
using namespace doodle;
int main(void)
{
create_window(640, 480);
{
if(button == KeyboardButtons::F)
else if(button == KeyboardButtons::Escape)
});
std::stringstream ss;
while (!is_window_closed())
{
clear_background(HexColor{0x614A86FF});
ss.clear();
ss.str("");
ss << "fullscreen: " << std::boolalpha << is_full_screen();
draw_text(ss.str(), -280,0);
}
return 0;
}

◆ update_window()

void doodle::update_window ( )
noexcept

Update the doodle application.

This needs to be called once every frame of the main loop. This is where events and drawing logic is updated.

using namespace doodle;
int main(void)
{
create_window(480, 360);
set_fill_color(HexColor{0xe1aa2dff});
while (!is_window_closed())
{
update_window(); // update mouse, keyboard, window, graphics, etc...
clear_background(HexColor{0x3f965bff});
}
return 0;
}
void set_fill_color(HexColor color) noexcept
Sets the color used to fill shapes to the specified HexColor.
int get_mouse_x() noexcept
Get the mouse's X position relative to the currently set doodle::FrameOfReference.
int get_mouse_y() noexcept
Get the mouse's Y position relative to the currently set doodle::FrameOfReference.
void draw_ellipse(double x, double y, double width, double height=0) noexcept
Draws an ellipse (oval) to the screen.

Variable Documentation

◆ DeltaTime

double doodle::DeltaTime
extern

The system variable DeltaTime contains the time difference between the beginning of the previous frame and the beginning of the current frame in seconds.

This variable is useful for creating time sensitive animation or physics calculation that should stay constant regardless of frame rate.

#include <thread>
using namespace doodle;
int main(void)
{
create_window(480, 360);
double x = -Width / 2.0;
Color rectangleColor{255, 0, 0};
bool increaseDeltaTime = false;
constexpr double pixerlsPerSecond = 200.0;
while (!is_window_closed())
{
draw_text("dt: " + std::to_string(static_cast<int>(DeltaTime * 1000)) + "ms", -Width / 2.0 + 30.0,
-Height / 2.0 + 80.0);
// Regardless of the length of DeltaTime we will move the rectangle across the screen in the same
// amount of time
x += DeltaTime * pixerlsPerSecond;
if (x >= Width / 2.0)
{
if (increaseDeltaTime)
{
increaseDeltaTime = false;
rectangleColor.red = 255;
rectangleColor.blue = 0;
}
else
{
increaseDeltaTime = true;
rectangleColor.red = 0;
rectangleColor.blue = 255;
}
x = -Width / 2.0;
}
set_fill_color(rectangleColor);
draw_rectangle(x, Height / 8.0, 80.0);
if (increaseDeltaTime)
{
using namespace std::chrono_literals;
std::this_thread::sleep_for(100ms); // 100 milliseconds
}
}
return 0;
}
void draw_rectangle(double x, double y, double width, double height=0) noexcept
Draws a rectangle to the screen.

◆ ElapsedTime

double doodle::ElapsedTime
extern

Returns the number of seconds since starting the program. This information is often used for timing events and animation sequences.

#include <doodle/doodle.hpp>
using namespace doodle;
int main(void)
{
create_window(480, 360);
while (!is_window_closed())
{
draw_text("Seconds:\n\t" + std::to_string(ElapsedTime) + "s", -Width / 2.0 + 30.0, Height / 16.0);
}
return 0;
}
double ElapsedTime
Returns the number of seconds since starting the program. This information is often used for timing e...

◆ FrameCount

int doodle::FrameCount
extern

The system variable FrameCount contains the number of frames that have been displayed since the program started. The first call to update_window() will set the value to 1 and subsequent calls increment the value.

#include <string>
using namespace doodle;
int main(void)
{
create_window(480, 360);
while (!is_window_closed())
{
}
return 0;
}
int FrameCount
The system variable FrameCount contains the number of frames that have been displayed since the progr...

◆ Height

int doodle::Height
extern

System variable that stores the height of the drawing canvas. This value is set by the desired_height parameter of the create_window() function. For example, the function call create_window(320, 240) sets the height variable to the value 240.

#include <iostream>
using namespace doodle;
int main(void)
{
create_window(480, 360);
std::cout << Width << ", " << Height << "\n";
// prints: 480, 360
return 0;
}

◆ Width

int doodle::Width
extern

System variable that stores the width of the drawing canvas. This value is set by the desired_width parameter of the create_window() function. For example, the function call create_window(320, 240) sets the width variable to the value 320.

#include <iostream>
using namespace doodle;
int main(void)
{
create_window(480, 360);
std::cout << Width << ", " << Height << "\n";
// prints: 480, 360
return 0;
}

◆ WindowIsFocused

bool doodle::WindowIsFocused
extern

Confirms if the window a doodle program is in is "focused," meaning that the doodle will accept mouse or keyboard input. This variable is "true" if the window is focused and "false" if not.

using namespace doodle;
int main(void)
{
create_window(480, 320);
while (!is_window_closed())
{
{
clear_background(HexColor{0xD7A5860A});
set_window_title("doodle - focused");
}
else
{
set_window_title("doodle - not focused");
}
}
return 0;
}
bool WindowIsFocused
Confirms if the window a doodle program is in is "focused," meaning that the doodle will accept mouse...