4 #include <cairomm/context.h> 5 namespace creativity {
namespace data {
namespace graph {
21 constexpr
RGBA(
const double &r,
const double &g,
const double &b,
const double &a = 1.0) :
22 red {r < 0 or r > 1 ?
throw std::out_of_range(
"") : r},
23 green{g < 0 or g > 1 ?
throw std::out_of_range(
"") : g},
24 blue {b < 0 or b > 1 ?
throw std::out_of_range(
"") : b},
25 alpha{a < 0 or a > 1 ?
throw std::out_of_range(
"") : a} {}
32 explicit constexpr
RGBA(
const double &i,
const double &a = 1.0) : RGBA(i,i,i,a) {}
41 constexpr
bool operator!=(
const RGBA& other)
const {
return not (*
this == other); }
57 constexpr
operator bool()
const {
return alpha > 0; }
74 double newalpha = other.
alpha + myweight;
75 r_((myweight*
red + other.
alpha*other.
red ) / newalpha);
90 template <
class T,
typename =
typename std::enable_if<
91 std::is_same<double, decltype(T::get_red())>::value and
92 std::is_same<double, decltype(T::get_green())>::value and
93 std::is_same<double, decltype(T::get_blue())>::value and
94 std::is_same<double, decltype(T::get_alpha())>::value>::type>
95 RGBA(
const T& rgba) :
RGBA(rgba.get_red(), rgba.get_blue(), rgba.get_green(), rgba.get_alpha()) {}
106 os <<
"RGBA(" << colour.
red <<
"," << colour.
green <<
"," << colour.
blue <<
"," << colour.
alpha <<
")";
112 void r_(
double r) {
const_cast<double&
>(
red) = r < 0 ? 0 : r > 1 ? 1 : r; }
113 void g_(
double g) {
const_cast<double&
>(
green) = g < 0 ? 0 : g > 1 ? 1 : g; }
114 void b_(
double b) {
const_cast<double&
>(
blue) = b < 0 ? 0 : b > 1 ? 1 : b; }
115 void a_(
double a) {
const_cast<double&
>(
alpha) = a < 0 ? 0 : a > 1 ? 1 : a; }
127 LineStyle(
RGBA rgba,
double thickness = 1.0,
double length = std::numeric_limits<double>::quiet_NaN())
128 : colour{std::move(rgba)}, thickness{std::move(thickness)}, length{std::move(length)}
132 void applyTo(Cairo::RefPtr<Cairo::Context> ctx)
const { colour.applyTo(ctx); ctx->set_line_width(thickness); }
192 bool border_top =
true, border_right =
true, border_bottom =
true, border_left =
true;
196 double borderT()
const {
return border_top ? border.thickness : 0; }
198 double borderR()
const {
return border_right ? border.thickness : 0; }
200 double borderB()
const {
return border_bottom ? border.thickness : 0; }
202 double borderL()
const {
return border_left ? border.thickness : 0; }
204 double borderLR()
const {
return borderL() + borderR(); }
206 double borderTB()
const {
return borderT() + borderB(); }
LineStyle border
The border colour for the region.
Definition: style.hpp:167
constexpr bool operator==(const RGBA &other) const
Compares two RGBA objects: they are considered equal if all components are equal. ...
Definition: style.hpp:38
constexpr RGBA(const double &i, const double &a=1.0)
Creates a RGBA object with a gray value and optional alpha value.
Definition: style.hpp:32
FillStyle(RGBA fill)
Constructs a FillStyle using just a fill colour: the borders will be omitted (i.e.
Definition: style.hpp:149
double borderB() const
Returns the border width if the bottom border is to be drawn, 0 otherwise.
Definition: style.hpp:200
RGBA(const T &rgba)
Creates the struct from an object with get_red(), get_green(), get_blue(), and get_alpha() methods...
Definition: style.hpp:95
Primary namespace for all Creativity library code.
Definition: config.hpp:4
Style class for a filled region.
Definition: style.hpp:145
RGBA & operator*=(const RGBA &other)
Multiplies this colour by another colour.
Definition: style.hpp:70
Definition: Variable.hpp:389
friend std::ostream & operator<<(std::ostream &os, const RGBA &colour)
Sents this RGBA to an output stream in the form "RGBA(r,g,b,a)" where r, g, b, and a are replaced wit...
Definition: style.hpp:105
const double green
The green channel value.
Definition: style.hpp:97
Style class for a filled, rectangular region.
Definition: style.hpp:173
double thickness
The thickness of the line.
Definition: style.hpp:136
constexpr bool equalsRGB(const RGBA &other) const
Returns true if the red, green, and blue channels are equal.
Definition: style.hpp:46
constexpr bool transparent() const
Returns true if the object is completely transparent, that is, has alpha = 0.
Definition: style.hpp:52
double borderL() const
Returns the border width if the left border is to be drawn, 0 otherwise.
Definition: style.hpp:202
const double blue
The blue channel value.
Definition: style.hpp:97
RectangleStyle(FillStyle f)
Initialize using a FillStyle.
Definition: style.hpp:188
double borderLR() const
Returns the total drawn horizontal border width, i.e. borderR() + borderL()
Definition: style.hpp:204
void applyTo(Cairo::RefPtr< Cairo::Context > ctx) const
Applies this colour to the given Cairo::Context as the source colour.
Definition: style.hpp:84
const double red
The red channel value.
Definition: style.hpp:97
Simple class holding red, green, blue, and alpha values. Each should be a value in [0...
Definition: style.hpp:8
FillStyle(RGBA fill, LineStyle border)
Constructs a FillStyle using a fill colour and line style for the borders.
Definition: style.hpp:151
RGBA operator*(const RGBA &other) const
"Multiplies" two RGBA objects together via alpha compositing "over" filter.
Definition: style.hpp:67
double borderT() const
Returns the border width if the top border is to be drawn, 0 otherwise.
Definition: style.hpp:196
FillStyle(LineStyle border)
Constructs a FillStyle using just a LineStyle; the fill will be omitted (i.e. transparent).
Definition: style.hpp:153
RGBA & operator=(const RGBA ©)
Copy assignment operator.
Definition: style.hpp:35
const double alpha
The alpha channel value (1 == opaque, 0 == transparent)
Definition: style.hpp:97
Style class for a drawn line.
Definition: style.hpp:124
constexpr RGBA(const double &r, const double &g, const double &b, const double &a=1.0)
Creates a RGBA colour object with a red, green, blue, and (optional) alpha value. ...
Definition: style.hpp:21
double borderR() const
Returns the border width if the right border is to be drawn, 0 otherwise.
Definition: style.hpp:198
constexpr bool opaque() const
Returns true if the object is opaque, that is, has alpha = 1.
Definition: style.hpp:49
RGBA colour
The colour of the line.
Definition: style.hpp:134
RGBA fill_colour
The fill colour for the region.
Definition: style.hpp:164
constexpr bool operator!=(const RGBA &other) const
Negation of ==.
Definition: style.hpp:41
double length
Length of the line, if applicable.
Definition: style.hpp:141
LineStyle(RGBA rgba, double thickness=1.0, double length=std::numeric_limits< double >::quiet_NaN())
Constructs a line style directly from an Gdk::RGBA object.
Definition: style.hpp:127
void applyTo(Cairo::RefPtr< Cairo::Context > ctx) const
Applies the line style to the given Cairo::Context.
Definition: style.hpp:132
double borderTB() const
Returns the total drawn vertical border width, i.e. borderT() + borderB()
Definition: style.hpp:206