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.
color.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 
9 
10 namespace doodle
11 {
52  struct [[nodiscard]] Color
53  {
54  public:
55  double red = 0;
56  double green = 0;
57  double blue = 0;
58  double alpha = 255;
59 
60  public:
82  constexpr Color() noexcept = default;
111  explicit constexpr Color(double grey, double alpha = 255) noexcept
112  : red(grey), green(grey), blue(grey), alpha(alpha)
113  {
114  }
147  constexpr Color(double red, double green, double blue, double alpha = 255) noexcept
148  : red(red), green(green), blue(blue), alpha(alpha)
149  {
150  }
151  };
152 
157  class [[nodiscard]] HexColor
158  {
159  public:
160  unsigned rgba = 0x000000ff;
161 
183  constexpr HexColor() noexcept = default;
210  constexpr HexColor(unsigned hex) noexcept : rgba(hex) {}
237  constexpr HexColor(int hex) noexcept : rgba(static_cast<unsigned>(hex)) {}
268  constexpr operator Color() const noexcept
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  }
275  };
277 }
This is a helper class to easily represent an RGBA color as an int with hexadecimal notation.
Definition: color.hpp:158
constexpr HexColor(int hex) noexcept
Implicitly convert from an int into a Hex Color.
Definition: color.hpp:237
constexpr HexColor() noexcept=default
The default color is black with full opacity.
Definition: angle.hpp:11
Color is a color represented with four unsigned bytes.
Definition: color.hpp:53
constexpr Color(double red, double green, double blue, double alpha=255) noexcept
When three values are specified, they are interpreted as RGB. Adding a fourth value applies alpha tra...
Definition: color.hpp:147
constexpr Color() noexcept=default
The default color is black with full opacity.