Wt  4.11.0
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Wt::WColor Class Reference

A value class that defines a color. More...

#include <Wt/WColor.h>

Public Member Functions

 WColor ()
 Creates a default color.
 
 WColor (int red, int green, int blue, int alpha=255)
 Creates a color with given red/green/blue/alpha components.
 
 WColor (const WString &name)
 Creates a color from a CSS name.
 
 WColor (StandardColor name)
 Creates a predefined color.
 
void setRgb (int red, int green, int blue, int alpha=255)
 Sets the red/green/blue/alpha components.
 
void setName (const WString &name)
 Sets the CSS name.
 
bool isDefault () const
 Returns if the color is the default color.
 
int red () const
 Returns the red component.
 
int green () const
 Returns the green component.
 
int blue () const
 Returns the blue component.
 
int alpha () const
 Returns the alpha component.
 
const WStringname () const
 Returns the CSS name.
 
bool operator== (const WColor &other) const
 Comparison operator.
 
bool operator!= (const WColor &other) const
 Comparison operator.
 
const std::string cssText (bool withAlpha=true) const
 Returns the color as a CSS property value.
 

Detailed Description

A value class that defines a color.

A color corresponds to a CSS color. You can specify a color either using its red/green/blue components, or from a valid CSS name.

The color supports an alpha channel, which determines the degree of transparency. An alpha value of 0 is completely transparent (and thus invisible), while a value of 255 is completely opaque.

Constructor & Destructor Documentation

◆ WColor() [1/4]

Wt::WColor::WColor ( )

Creates a default color.

The default color is depending on the context, another color (for example from a hierarchical parent in a widget tree), or a completely transparent color.

◆ WColor() [2/4]

Wt::WColor::WColor ( int  red,
int  green,
int  blue,
int  alpha = 255 
)

Creates a color with given red/green/blue/alpha components.

All four components must be specified with a value in the range (0 - 255). The alpha channel determines the degree of transparency. An alpha value of 0 is completely transparent (and thus invisible), while a value of 255 is completely opaque.

See also
setRgb(int, int, int, int)

◆ WColor() [3/4]

Wt::WColor::WColor ( const WString name)

Creates a color from a CSS name.

The name may be any valid CSS color name, including names colors such as "aqua", or colors defined as RGB components.

Only if the color is defined in terms of RGB components (using the #rgb, #rrggbb, rgb() or rgba() formats), will the CSS color be parsed into red, blue and green values. Otherwise, these values are not available, and the color can only be used in media that support CSS colors.

See also http://www.w3.org/TR/css3-color

◆ WColor() [4/4]

Wt::WColor::WColor ( StandardColor  name)

Creates a predefined color.

Constructs one of the 16 predefined Wt colors constants.

Member Function Documentation

◆ alpha()

int Wt::WColor::alpha ( ) const

Returns the alpha component.

Only available when the color was specified in terms of the RGB components using setRgb(int, int, int, int) or WColor(int, int, int, int).

◆ blue()

int Wt::WColor::blue ( ) const

Returns the blue component.

Only available when the color was specified in terms of the RGB components using setRgb(int, int, int, int), WColor(int, int, int, int) or WColor(const WString& name) when the name was parsable.

If not available this method return 0.

◆ cssText()

const std::string Wt::WColor::cssText ( bool  withAlpha = true) const

Returns the color as a CSS property value.

This returns the color in rgb or rgba notation.

◆ green()

int Wt::WColor::green ( ) const

Returns the green component.

Only available when the color was specified in terms of the RGB components using setRgb(int, int, int, int), WColor(int, int, int, int) or WColor(const WString& name) when the name was parsable.

If not available this method return 0.

◆ isDefault()

bool Wt::WColor::isDefault ( ) const

Returns if the color is the default color.

See also
WColor()

◆ name()

const WString & Wt::WColor::name ( ) const

Returns the CSS name.

Only available when it was set with setName(const WString&) or WColor(const WString& name).

◆ operator!=()

bool Wt::WColor::operator!= ( const WColor other) const

Comparison operator.

Returns false if the two colors were not defined in exactly the same way. It may return return although they actually represent the same color.

◆ operator==()

bool Wt::WColor::operator== ( const WColor other) const

Comparison operator.

Returns true if the two colors were defined in exactly the same way. It may return false although they actually represent the same color.

◆ red()

int Wt::WColor::red ( ) const

Returns the red component.

Only available when the color was specified in terms of the RGB components using setRgb(int, int, int, int), WColor(int, int, int, int) or WColor(const WString& name) when the name was parsable .

If not available this method return 0.

◆ setName()

void Wt::WColor::setName ( const WString name)

Sets the CSS name.

See also
WColor(const WString&)

◆ setRgb()

void Wt::WColor::setRgb ( int  red,
int  green,
int  blue,
int  alpha = 255 
)

Sets the red/green/blue/alpha components.

All four components must be specified with a value in the range (0 - 255). The alpha channel determines the degree of transparency. An alpha value of 0 is completely transparent (and thus invisible), while a value of 255 is completely opaque.