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.
Public Member Functions | Public Attributes | List of all members
doodle::HexColor Class Reference

This is a helper class to easily represent an RGBA color as an int with hexadecimal notation. More...

#include <doodle/color.hpp>

Public Member Functions

constexpr HexColor () noexcept=default
 The default color is black with full opacity. More...
 
constexpr HexColor (unsigned hex) noexcept
 Implicitly convert from an unsigned int into a Hex Color. More...
 
constexpr HexColor (int hex) noexcept
 Implicitly convert from an int into a Hex Color. More...
 
constexpr operator Color () const noexcept
 Implicitly convert from a HexColor to a Color. More...
 

Public Attributes

unsigned rgba = 0x000000ff
 

Detailed Description

This is a helper class to easily represent an RGBA color as an int with hexadecimal notation.

Definition at line 157 of file color.hpp.

Constructor & Destructor Documentation

◆ HexColor() [1/3]

constexpr doodle::HexColor::HexColor ( )
constexprdefaultnoexcept

The default color is black with full opacity.

using namespace doodle;
int main(void)
{
create_window(100, 100);
while (!is_window_closed())
{
set_fill_color(HexColor{}); // default is black color
draw_ellipse(0, 0, 35);
}
return 0;
}
constexpr HexColor() noexcept=default
The default color is black with full opacity.
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 clear_background() noexcept
Clear the background to black.
bool create_window() noexcept
Create a default window.
bool is_window_closed() noexcept
Is the window closed?
void update_window() noexcept
Update the doodle application.
void draw_ellipse(double x, double y, double width, double height=0) noexcept
Draws an ellipse (oval) to the screen.
Definition: angle.hpp:11

◆ HexColor() [2/3]

constexpr doodle::HexColor::HexColor ( unsigned  hex)
inlineconstexprnoexcept

Implicitly convert from an unsigned int into a Hex Color.

Parameters
hexunsigned number to read as RGBA
using namespace doodle;
int main(void)
{
create_window(100, 100);
constexpr unsigned r = 0xff0000ff;
constexpr HexColor red = r;
while (!is_window_closed())
{
draw_ellipse(0, 0, 35);
}
return 0;
}

Definition at line 210 of file color.hpp.

210 : rgba(hex) {}
unsigned rgba
Definition: color.hpp:160

◆ HexColor() [3/3]

constexpr doodle::HexColor::HexColor ( int  hex)
inlineconstexprnoexcept

Implicitly convert from an int into a Hex Color.

Parameters
hexint number to read as RGBA
using namespace doodle;
int main(void)
{
create_window(100, 100);
constexpr int g = 0x00ff00ff;
constexpr HexColor green = g;
while (!is_window_closed())
{
draw_ellipse(0, 0, 35);
}
return 0;
}

Definition at line 237 of file color.hpp.

237 : rgba(static_cast<unsigned>(hex)) {}

Member Function Documentation

◆ operator Color()

constexpr doodle::HexColor::operator Color ( ) const
inlineconstexprnoexcept

Implicitly convert from a HexColor to a Color.

This is really the reason why this class exists. This allows us to implicitly specify an RGBA color with a single int and store it as a Color.

using namespace doodle;
void SetMyColor(Color color) noexcept
{
}
int main(void)
{
create_window(100, 100);
while (!is_window_closed())
{
SetMyColor(HexColor{0x0000ffff}); // implicitly convert from HexColor to Color
draw_ellipse(-25, 25, 40);
SetMyColor(HexColor{0xaaed5fff});
draw_rectangle(0, -40, 40);
}
return 0;
}
void set_outline_color(HexColor color) noexcept
Set the outline and lines of shapes to the specified HexColor.
void draw_rectangle(double x, double y, double width, double height=0) noexcept
Draws a rectangle to the screen.

Definition at line 268 of file color.hpp.

269  {
270  return Color{static_cast<double>((rgba & 0xff000000) >> 24),
271  static_cast<double>((rgba & 0x00ff0000) >> 16),
272  static_cast<double>((rgba & 0x0000ff00) >> 8),
273  static_cast<double>((rgba & 0x000000ff) >> 0)};
274  }

Member Data Documentation

◆ rgba

unsigned doodle::HexColor::rgba = 0x000000ff

Definition at line 160 of file color.hpp.


The documentation for this class was generated from the following file: