creativity  v1.3.0
Agent-based model of creativity and piracy
Public Member Functions | Public Attributes | Friends | List of all members
creativity::data::graph::RGBA Class Referencefinal

Simple class holding red, green, blue, and alpha values. Each should be a value in [0,1]. More...

#include <creativity/data/graph/style.hpp>

Public Member Functions

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. More...
 
constexpr RGBA (const double &i, const double &a=1.0)
 Creates a RGBA object with a gray value and optional alpha value. More...
 
RGBAoperator= (const RGBA &copy)
 Copy assignment operator.
 
constexpr bool operator== (const RGBA &other) const
 Compares two RGBA objects: they are considered equal if all components are equal.
 
constexpr bool operator!= (const RGBA &other) const
 Negation of ==.
 
constexpr bool equalsRGB (const RGBA &other) const
 Returns true if the red, green, and blue channels are equal. More...
 
constexpr bool opaque () const
 Returns true if the object is opaque, that is, has alpha = 1. More...
 
constexpr bool transparent () const
 Returns true if the object is completely transparent, that is, has alpha = 0. More...
 
constexpr operator bool () const
 Using an RGBA object as a bool returns true unless the object is fully transparent. More...
 
RGBA operator* (const RGBA &other) const
 "Multiplies" two RGBA objects together via alpha compositing "over" filter. More...
 
RGBAoperator*= (const RGBA &other)
 Multiplies this colour by another colour. More...
 
void applyTo (Cairo::RefPtr< Cairo::Context > ctx) const
 Applies this colour to the given Cairo::Context as the source colour.
 
template<class T , typename = typename std::enable_if< std::is_same<double, decltype(T::get_red())>::value and std::is_same<double, decltype(T::get_green())>::value and std::is_same<double, decltype(T::get_blue())>::value and std::is_same<double, decltype(T::get_alpha())>::value>::type>
 RGBA (const T &rgba)
 Creates the struct from an object with get_red(), get_green(), get_blue(), and get_alpha() methods. More...
 

Public Attributes

const double red
 The red channel value.
 
const double green
 The green channel value.
 
const double blue
 The blue channel value.
 
const double alpha
 The alpha channel value (1 == opaque, 0 == transparent)
 

Friends

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 with their [0,1] values.
 

Detailed Description

Simple class holding red, green, blue, and alpha values. Each should be a value in [0,1].

Constructor & Destructor Documentation

§ RGBA() [1/3]

constexpr creativity::data::graph::RGBA::RGBA ( const double &  r,
const double &  g,
const double &  b,
const double &  a = 1.0 
)
inline

Creates a RGBA colour object with a red, green, blue, and (optional) alpha value.

Parameters
rthe red channel value, from 0 to 1. 0 is off, 1 is full intensity.
gthe red channel value, from 0 to 1. 0 is off, 1 is full intensity.
bthe red channel value, from 0 to 1. 0 is off, 1 is full intensity.
athe alpha channel value, from 0 to 1. 0 is completely transparent, 1 is completely opaque. If omitted, defaults to 1 (fully opaque).
Exceptions
std::out_of_rangeif any of the given values are outside the [0,1] range.

§ RGBA() [2/3]

constexpr creativity::data::graph::RGBA::RGBA ( const double &  i,
const double &  a = 1.0 
)
inlineexplicit

Creates a RGBA object with a gray value and optional alpha value.

The gray intensity is used for the three red, green, and blue values.

Exceptions
std::out_of_rangeif any of the given values are outside the [0,1] range.

§ RGBA() [3/3]

template<class T , typename = typename std::enable_if< std::is_same<double, decltype(T::get_red())>::value and std::is_same<double, decltype(T::get_green())>::value and std::is_same<double, decltype(T::get_blue())>::value and std::is_same<double, decltype(T::get_alpha())>::value>::type>
creativity::data::graph::RGBA::RGBA ( const T &  rgba)
inline

Creates the struct from an object with get_red(), get_green(), get_blue(), and get_alpha() methods.

In particular, this is designed to be usable with Gdk::RGBA (without actually having to add a dependency on gdkmm).

Member Function Documentation

§ equalsRGB()

constexpr bool creativity::data::graph::RGBA::equalsRGB ( const RGBA other) const
inline

Returns true if the red, green, and blue channels are equal.

The alpha values do not have to match.

§ opaque()

constexpr bool creativity::data::graph::RGBA::opaque ( ) const
inline

Returns true if the object is opaque, that is, has alpha = 1.

§ operator bool()

constexpr creativity::data::graph::RGBA::operator bool ( ) const
inline

Using an RGBA object as a bool returns true unless the object is fully transparent.

In other words, if (color) is equivalent to if (not color.transparent()).

§ operator*()

RGBA creativity::data::graph::RGBA::operator* ( const RGBA other) const
inline

"Multiplies" two RGBA objects together via alpha compositing "over" filter.

The result is the colour that would result if the left hand side argument was painted, then the right-hand-side argument was painted over top. If the RHS argument is opaque or LHS is transparent, the result is simply a copy of the RHS object; if RHS transparent, the result is a copy of the LHS object; otherwise the result is a new, combined color. The final opacity of the object will be between the larger opacity value of the two objects and 1 (i.e. overlaying results in increasing opacity).

§ operator*=()

RGBA& creativity::data::graph::RGBA::operator*= ( const RGBA other)
inline

Multiplies this colour by another colour.

See RGBA::operator* for details.

§ transparent()

constexpr bool creativity::data::graph::RGBA::transparent ( ) const
inline

Returns true if the object is completely transparent, that is, has alpha = 0.


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