gtkmm: Gdk::RGBA Class Reference

gtkmm 4.6.0

Public Member Functions | Static Public Member Functions | Protected Attributes | Related Functions | List of all members
Gdk::RGBA Class Reference

An RGBA color. More...

`#include <gdkmm/rgba.h>`

## Public Member Functions
| RGBA (GdkRGBA* gobject, bool make_a_copy=true)
| RGBA (const RGBA& other)
RGBA& | operator= (const RGBA& other)
| RGBA (RGBA&& other) noexcept
RGBA& | operator= (RGBA&& other) noexcept
| ~RGBA () noexcept
void | swap (RGBA& other) noexcept
GdkRGBA* | gobj ()
| Provides access to the underlying C instance. More...
const GdkRGBA* | gobj () const
| Provides access to the underlying C instance. More...
GdkRGBA* | gobj_copy () const
| Provides access to the underlying C instance. The caller is responsible for freeing it. Use when directly setting fields in structs. More...
| RGBA ()
| Instantiate a new Gdk::RGBA. More...
| RGBA (const Glib::ustring& value)
| Parses a textual representation of a color and creates a new Gdk::RGBA with the corresponding values in its `red`, `green`, `blue` and `alpha` fields. More...
| RGBA (float red_, float green_, float blue_, float alpha_=1.0)
| Construct a Gdk::RGBA, by specifying red, green, and blue color component values, as fractions. More...
void | set_grey_u (gushort value, gushort alpha=65535)
| Set a grey color, by using the same value for all color components. More...
void | set_grey (float g, float alpha=1.0)
| Set a grey color, by using the same value for all color components. More...
void | set_rgba_u (gushort red_, gushort green_, gushort blue_, gushort alpha_=65535)
| Set the color, by specifying red, green, and blue color component values. More...
void | set_rgba (float red_, float green_, float blue_, float alpha_=1.0)
| Set the color, by specifying red, green, and blue color component values, as fractions. More...
void | set_hsv (float h, float s, float v, float alpha=1.0)
| Set the color, by specifying hue, saturation, and value (brightness). More...
void | set_hsl (float h, float s, float l, float alpha=1.0)
| Set the color, by specifying hue, saturation, and lightness. More...
bool | set (const Glib::ustring& spec)
| Parses a textual representation of a color. More...
gushort | get_red_u () const
| Get the red component of the color. More...
gushort | get_green_u () const
| Get the green component of the color. More...
gushort | get_blue_u () const
| Get the blue component of the color. More...
gushort | get_alpha_u () const
| Get the alpha component of the color. More...
void | set_red_u (gushort value)
| Set the red component of the color. More...
void | set_green_u (gushort value)
| Set the green component of the color. More...
void | set_blue_u (gushort value)
| Set the blue component of the color. More...
void | set_alpha_u (gushort value)
| Set the alpha component of the color. More...
float | get_red () const
| Get the red component of the color, as a fraction. More...
float | get_green () const
| Get the green component of the color, as a fraction. More...
float | get_blue () const
| Get the blue component of the color, as a fraction. More...
float | get_alpha () const
| Get the alpha component of the color, as a fraction. More...
void | set_red (float value)
| Set the red component of the color, as a fraction. More...
void | set_green (float value)
| Set the green component of the color, as a fraction. More...
void | set_blue (float value)
| Set the blue component of the color, as a fraction. More...
void | set_alpha (float value)
| Set the alpha component of the color, as a fraction. More...
Glib::ustring | to_string () const
| Returns a textual specification of rgba in the form `rgb(r,g,b)` or `rgba(r,g,b,a)`, where “r”, “g”, “b” and “a” represent the red, green, blue and alpha values respectively. More...
bool | is_clear () const
| Checks if an rgba value is transparent. More...
bool | is_opaque () const
| Checks if an rgba value is opaque. More...

## Static Public Member Functions
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system. More...

## Protected Attributes
GdkRGBA* | gobject_

## Related Functions
(Note that these are not member functions.)
bool | operator== (const RGBA& lhs, const RGBA& rhs)
bool | operator!= (const RGBA& lhs, const RGBA& rhs)
void | swap (RGBA& lhs, RGBA& rhs) noexcept
Gdk::RGBA | wrap (GdkRGBA* object, bool take_copy=false)
| A Glib::wrap() method for this object. More...

## Detailed Description

An RGBA color.

The RGBA class is a convenient way to pass colors around. It's based on cairo's way to deal with (possibly translucent) colors and mirrors its behavior. All values are in the range from 0.0 to 1.0 inclusive. So the color (0.0, 0.0, 0.0, 0.0) represents transparent black and (1.0, 1.0, 1.0, 1.0) is opaque white. Other values will be clamped to this range when drawing.

## Constructor & Destructor Documentation

## ◆ RGBA() [1/6]

Gdk::RGBA::RGBA | ( | GdkRGBA * | gobject,
|  | bool | make_a_copy = `true`
| ) |  |
| explicit

## ◆ RGBA() [2/6]

Gdk::RGBA::RGBA | ( | const RGBA& | other | ) |

## ◆ RGBA() [3/6]

Gdk::RGBA::RGBA | ( | RGBA&& | other | ) |
| noexcept

## ◆ ~RGBA()

Gdk::RGBA::~RGBA | ( |  | ) |
| noexcept

## ◆ RGBA() [4/6]

Gdk::RGBA::RGBA | ( |  | ) |

Instantiate a new Gdk::RGBA.

## ◆ RGBA() [5/6]

Gdk::RGBA::RGBA | ( | const Glib::ustring & | value | ) |
| explicit

Parses a textual representation of a color and creates a new Gdk::RGBA with the corresponding values in its `red`, `green`, `blue` and `alpha` fields.

The string can be one of:

- A standard name (taken from the X11 rgb.txt file)
- A hexadecimal value in the form `#rgb`, `#rrggbb`, `#rrrgggbbb` or #rrrrggggbbbb
- An RGB color in the form `rgb(r,g,b)` (In this case the color will have full opacity)
- An RGBA color in the form `rgba(r,g,b,a)`

Where `r`, `g`, `b` and `a` are respectively the red, green, blue and alpha color values. In the last two cases, `r` `g` and `b` are either integers in the range 0 to 255 or percentage values in the range 0% to 100%, and `a` is a floating point value in the range 0 to 1.

Parameters

  value | the string specifying the color.

## ◆ RGBA() [6/6]

Gdk::RGBA::RGBA | ( | float | red_,
|  | float | green_,
|  | float | blue_,
|  | float | alpha_ = `1.0`
| ) |  |

Construct a Gdk::RGBA, by specifying red, green, and blue color component values, as fractions.

Parameters

  red_ | The red component of the color, as a fraction.
  green_ | The green component of the color, as a fraction.
  blue_ | The blue component of the color, as a fraction.
  alpha_ | The alpha component of the color, as a fraction.

## Member Function Documentation

## ◆ get_alpha()

float Gdk::RGBA::get_alpha | ( |  | ) | const

Get the alpha component of the color, as a fraction.

Returns
  The alpha component of the color, as a fraction.

## ◆ get_alpha_u()

gushort Gdk::RGBA::get_alpha_u | ( |  | ) | const

Get the alpha component of the color.

Returns
  The alpha component of the color, in the range 0..65535.

## ◆ get_blue()

float Gdk::RGBA::get_blue | ( |  | ) | const

Get the blue component of the color, as a fraction.

Returns
  The blue component of the color, as a fraction.

## ◆ get_blue_u()

gushort Gdk::RGBA::get_blue_u | ( |  | ) | const

Get the blue component of the color.

Returns
  The blue component of the color, in the range 0..65535.

## ◆ get_green()

float Gdk::RGBA::get_green | ( |  | ) | const

Get the green component of the color, as a fraction.

Returns
  The green component of the color, as a fraction.

## ◆ get_green_u()

gushort Gdk::RGBA::get_green_u | ( |  | ) | const

Get the green component of the color.

Returns
  The green component of the color, in the range 0..65535.

## ◆ get_red()

float Gdk::RGBA::get_red | ( |  | ) | const

Get the red component of the color, as a fraction.

Returns
  The red component of the color, as a fraction.

## ◆ get_red_u()

gushort Gdk::RGBA::get_red_u | ( |  | ) | const

Get the red component of the color.

Returns
  The red component of the color, in the range 0..65535.

## ◆ get_type()

static GType Gdk::RGBA::get_type | ( |  | ) |
| static

Get the GType for this class, for use with the underlying GObject type system.

## ◆ gobj() [1/2]

GdkRGBA * Gdk::RGBA::gobj | ( |  | ) |
| inline

Provides access to the underlying C instance.

## ◆ gobj() [2/2]

const GdkRGBA * Gdk::RGBA::gobj | ( |  | ) | const
| inline

Provides access to the underlying C instance.

## ◆ gobj_copy()

GdkRGBA * Gdk::RGBA::gobj_copy | ( |  | ) | const

Provides access to the underlying C instance. The caller is responsible for freeing it. Use when directly setting fields in structs.

## ◆ is_clear()

bool Gdk::RGBA::is_clear | ( |  | ) | const

Checks if an rgba value is transparent.

That is, drawing with the value would not produce any change.

Returns
  `true` if the rgba is clear.

## ◆ is_opaque()

bool Gdk::RGBA::is_opaque | ( |  | ) | const

Checks if an rgba value is opaque.

That is, drawing with the value will not retain any results from previous contents.

Returns
  `true` if the rgba is opaque.

## ◆ operator=() [1/2]

RGBA& Gdk::RGBA::operator= | ( | const RGBA& | other | ) |

## ◆ operator=() [2/2]

RGBA& Gdk::RGBA::operator= | ( | RGBA&& | other | ) |
| noexcept

## ◆ set()

bool Gdk::RGBA::set | ( | const Glib::ustring & | spec | ) |

Parses a textual representation of a color.

The string can be either one of:

- A standard name (Taken from the Css specification).
- A hexadecimal value in the form “\#rgb”, “\#rrggbb”, “\#rrrgggbbb” or ”\#rrrrggggbbbb”
- A hexadecimal value in the form “\#rgba”, “\#rrggbbaa”, or ”\#rrrrggggbbbbaaaa”
- A RGB color in the form “rgb(r,g,b)” (In this case the color will have full opacity)
- A RGBA color in the form “rgba(r,g,b,a)”

Where “r”, “g”, “b” and “a” are respectively the red, green, blue and alpha color values. In the last two cases, “r”, “g”, and “b” are either integers in the range 0 to 255 or percentage values in the range 0% to 100%, and a is a floating point value in the range 0 to 1.

Parameters

  spec | The string specifying the color.

Returns
  `true` if the parsing succeeded.

## ◆ set_alpha()

void Gdk::RGBA::set_alpha | ( | float | value | ) |

Set the alpha component of the color, as a fraction.

Parameters

  value | The alpha component of the color, as a fraction.

## ◆ set_alpha_u()

void Gdk::RGBA::set_alpha_u | ( | gushort | value | ) |

Set the alpha component of the color.

Parameters

  value | The alpha component of the color, in the range 0..65535.

## ◆ set_blue()

void Gdk::RGBA::set_blue | ( | float | value | ) |

Set the blue component of the color, as a fraction.

Parameters

  value | The blue component of the color, as a fraction.

## ◆ set_blue_u()

void Gdk::RGBA::set_blue_u | ( | gushort | value | ) |

Set the blue component of the color.

Parameters

  value | The blue component of the color, in the range 0..65535.

## ◆ set_green()

void Gdk::RGBA::set_green | ( | float | value | ) |

Set the green component of the color, as a fraction.

Parameters

  value | The green component of the color, as a fraction.

## ◆ set_green_u()

void Gdk::RGBA::set_green_u | ( | gushort | value | ) |

Set the green component of the color.

Parameters

  value | The green component of the color, in the range 0..65535.

## ◆ set_grey()

void Gdk::RGBA::set_grey | ( | float | g,
|  | float | alpha = `1.0`
| ) |  |

Set a grey color, by using the same value for all color components.

Parameters

  g | The value to be used for the red, green, and blue components, as a fraction.
  alpha | The alpha component of the color, as a fraction.

## ◆ set_grey_u()

void Gdk::RGBA::set_grey_u | ( | gushort | value,
|  | gushort | alpha = `65535`
| ) |  |

Set a grey color, by using the same value for all color components.

Parameters

  value | The value to be used for the red, green, and blue components, in the range 0..65535.
  alpha | The alpha component of the color, in the range 0..65535.

## ◆ set_hsl()

void Gdk::RGBA::set_hsl | ( | float | h,
|  | float | s,
|  | float | l,
|  | float | alpha = `1.0`
| ) |  |

Set the color, by specifying hue, saturation, and lightness.

Parameters

  h | Hue, in the range 0..360 degrees.
  s | Saturation, in the range 0..1.
  l | Lightness, in the range 0..1.
  alpha | The alpha component of the color, in the range 0..1.

## ◆ set_hsv()

void Gdk::RGBA::set_hsv | ( | float | h,
|  | float | s,
|  | float | v,
|  | float | alpha = `1.0`
| ) |  |

Set the color, by specifying hue, saturation, and value (brightness).

Parameters

  h | Hue, in the range 0..360 degrees.
  s | Saturation, in the range 0..1.
  v | Value (a.k.a. brightness), in the range 0..1.
  alpha | The alpha component of the color, in the range 0..1.

## ◆ set_red()

void Gdk::RGBA::set_red | ( | float | value | ) |

Set the red component of the color, as a fraction.

Parameters

  value | The red component of the color, as a fraction.

## ◆ set_red_u()

void Gdk::RGBA::set_red_u | ( | gushort | value | ) |

Set the red component of the color.

Parameters

  value | The red component of the color, in the range 0..65535.

## ◆ set_rgba()

void Gdk::RGBA::set_rgba | ( | float | red_,
|  | float | green_,
|  | float | blue_,
|  | float | alpha_ = `1.0`
| ) |  |

Set the color, by specifying red, green, and blue color component values, as fractions.

Parameters

  red_ | The red component of the color, as a fraction.
  green_ | The green component of the color, as a fraction.
  blue_ | The blue component of the color, as a fraction.
  alpha_ | The alpha component of the color, as a fraction.

## ◆ set_rgba_u()

void Gdk::RGBA::set_rgba_u | ( | gushort | red_,
|  | gushort | green_,
|  | gushort | blue_,
|  | gushort | alpha_ = `65535`
| ) |  |

Set the color, by specifying red, green, and blue color component values.

Parameters

  red_ | The red component of the color, in the range 0..65535.
  green_ | The green component of the color, in the range 0..65535.
  blue_ | The blue component of the color, in the range 0..65535.
  alpha_ | The alpha component of the color, in the range 0..65535.

## ◆ swap()

void Gdk::RGBA::swap | ( | RGBA& | other | ) |
| noexcept

## ◆ to_string()

Glib::ustring Gdk::RGBA::to_string | ( |  | ) | const

Returns a textual specification of rgba in the form `rgb(r,g,b)` or `rgba(r,g,b,a)`, where “r”, “g”, “b” and “a” represent the red, green, blue and alpha values respectively.

“r”, “g”, and “b” are represented as integers in the range 0 to 255, and “a” is represented as a floating point value in the range 0 to 1.

These string forms are string forms that are supported by the CSS3 colors module, and can be parsed by parse().

Note that this string representation may lose some precision, since “r”, “g” and “b” are represented as 8-bit integers. If this is a concern, you should use a different representation.

Returns
  A newly allocated text string.

## Friends And Related Function Documentation

## ◆ operator!=()

bool operator!= | ( | const RGBA& | lhs,
|  | const RGBA& | rhs
| ) |  |
| related

Parameters

  lhs | The left-hand side
  rhs | The right-hand side

Returns
  The result

## ◆ operator==()

bool operator== | ( | const RGBA& | lhs,
|  | const RGBA& | rhs
| ) |  |
| related

Parameters

  lhs | The left-hand side
  rhs | The right-hand side

Returns
  The result

## ◆ swap()

void swap | ( | RGBA& | lhs,
|  | RGBA& | rhs
| ) |  |
| related

Parameters

  lhs | The left-hand side
  rhs | The right-hand side

## ◆ wrap()

Gdk::RGBA wrap | ( | GdkRGBA * | object,
|  | bool | take_copy = `false`
| ) |  |
| related

A Glib::wrap() method for this object.

Parameters

  object | The C instance.
  take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref.

Returns
  A C++ instance that wraps this C instance.

## Member Data Documentation

## ◆ gobject_

GdkRGBA* Gdk::RGBA::gobject_
| protected