Class: Wx::Colour

Inherits:
Object show all
Defined in:
lib/wx/doc/gen/colour.rb,
lib/wx/doc/colour.rb

Overview

Note:

This class is untracked and should not be derived from nor instances extended!

A colour is an object representing a combination of Red, Green, and Blue (RGB) intensity values and an Alpha value, and is used to determine drawing colours.

See the entry for ColourDatabase for how a pointer to a predefined, named colour may be returned instead of creating a new colour. Valid RGB values are in the range 0 to 255. You can retrieve the current system colour settings with SystemSettings.

Channel Accessor Functions

Note that this class provides pairs of functions for each of the colour channels, i.e. red, green, blue and alpha values. The one word functions #red, #green, #blue and #alpha return the values of type unsigned char, while #get_red, #get_green, #get_blue and #get_alpha returns the same value as unsigned int. According to the C++ integer promotion rules, the result of any arithmetic expression involving the former will be (signed) int, while that of the latter will be unsigned, which is what would be commonly expected, so the latter family of functions should be typically preferred (but they are only available since wxWidgets 3.1.6).

Category: Graphics Device Interface (GDI) Predefined objects/pointers:

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Object

#is_same_as, #un_share

Constructor Details

#initializeWx::Colour #initialize(red, green, blue, alpha = Wx::ALPHA_OPAQUE) ⇒ Wx::Colour #initialize(colourName) ⇒ Wx::Colour #initialize(colRGB) ⇒ Wx::Colour #initialize(colour) ⇒ Wx::Colour

Returns a new instance of Colour.

Overloads:

  • #initializeWx::Colour

    Default constructor.

  • #initialize(red, green, blue, alpha = Wx::ALPHA_OPAQUE) ⇒ Wx::Colour

    Parameters:

    • red (Integer)

      The red value.

    • green (Integer)

      The green value.

    • blue (Integer)

      The blue value.

    • alpha (Integer) (defaults to: Wx::ALPHA_OPAQUE)

      The alpha value. Alpha values range from 0 (ALPHA_TRANSPARENT) to 255 (ALPHA_OPAQUE).

  • #initialize(colourName) ⇒ Wx::Colour

    Parameters:

    • colourName (String)

      The colour name.

  • #initialize(colRGB) ⇒ Wx::Colour

    Parameters:

    • colRGB (Integer)

      A packed RGB value.

  • #initialize(colour) ⇒ Wx::Colour

    Copy constructor.

    Parameters:



168
# File 'lib/wx/doc/gen/colour.rb', line 168

def initialize(*args) end

Class Method Details

.alpha_blend(fg, bg, alpha) ⇒ Integer

Blend colour, taking alpha into account.

Parameters:

  • fg (Integer)
  • bg (Integer)
  • alpha (Float)

Returns:

  • (Integer)


319
# File 'lib/wx/doc/gen/colour.rb', line 319

def self.alpha_blend(fg, bg, alpha) end

.change_lightness(r, g, b, ialpha) ⇒ Array(Integer,Integer,Integer)

Utility function that simply darkens or lightens a color, based on the specified percentage ialpha.

ialpha of 0 would be make the color completely black, 200 completely white and 100 would not change the color.

Parameters:

  • r (Integer)
  • g (Integer)
  • b (Integer)
  • ialpha (Integer)

Returns:

  • (Array(Integer,Integer,Integer))


285
# File 'lib/wx/doc/gen/colour.rb', line 285

def self.change_lightness(r, g, b, ialpha) end

.self.create_grey(r, g, b) ⇒ Array(Integer,Integer,Integer) .self.create_grey(r, g, b, weight_r, weight_g, weight_b) ⇒ Array(Integer,Integer,Integer)

Overloads:

  • .self.create_grey(r, g, b) ⇒ Array(Integer,Integer,Integer)

    Create a grey colour from (in/out) rgb parameters using integer arithmetic.

    Parameters:

    • r (Integer)
    • g (Integer)
    • b (Integer)

    Returns:

    • (Array(Integer,Integer,Integer))
  • .self.create_grey(r, g, b, weight_r, weight_g, weight_b) ⇒ Array(Integer,Integer,Integer)

    Create a grey colour from (in/out) rgb parameters using floating point arithmetic.

    Defaults to using the standard ITU-T BT.601 when converting to YUV, where every pixel equals (R * weight_r) + (G * weight_g) + (B * weight_b).

    Parameters:

    • r (Integer)
    • g (Integer)
    • b (Integer)
    • weight_r (Float)
    • weight_g (Float)
    • weight_b (Float)

    Returns:

    • (Array(Integer,Integer,Integer))


312
# File 'lib/wx/doc/gen/colour.rb', line 312

def self.create_grey(*args) end

.create_mono(r, g, b, on) ⇒ Array(Integer,Integer,Integer)

Assigns the same value to r, g, b: 0 if on is false, 255 otherwise.

Parameters:

  • r (Integer)
  • g (Integer)
  • b (Integer)
  • on (Boolean)

Returns:

  • (Array(Integer,Integer,Integer))


293
# File 'lib/wx/doc/gen/colour.rb', line 293

def self.create_mono(r, g, b, on) end

.make_disabled(r, g, b, brightness = 255) ⇒ Array(Integer,Integer,Integer)

Create a disabled (dimmed) colour from (in/out) rgb parameters.

Parameters:

  • r (Integer)
  • g (Integer)
  • b (Integer)
  • brightness (Integer) (defaults to: 255)

Returns:

  • (Array(Integer,Integer,Integer))


270
# File 'lib/wx/doc/gen/colour.rb', line 270

def self.make_disabled(r, g, b, brightness=255) end

Instance Method Details

#==(colour) ⇒ Boolean

Tests the equality of two colours by comparing individual red, green, blue intensities and alpha values.

Parameters:

Returns:

  • (Boolean)


255
# File 'lib/wx/doc/gen/colour.rb', line 255

def ==(colour) end

#alphaInteger

Returns the alpha value, on platforms where alpha is not yet supported, this always returns ALPHA_OPAQUE.

Returns:

  • (Integer)

See Also:



175
# File 'lib/wx/doc/gen/colour.rb', line 175

def alpha; end

#blueInteger

Returns the blue intensity.

Returns:

  • (Integer)

See Also:



182
# File 'lib/wx/doc/gen/colour.rb', line 182

def blue; end

#change_lightness(ialpha) ⇒ Wx::Colour

Wx::Colour wrapper for ChangeLightness(r,g,b,ialpha).

Parameters:

  • ialpha (Integer)

Returns:



275
# File 'lib/wx/doc/gen/colour.rb', line 275

def change_lightness(ialpha) end

#cloneWx::Colour

Calls #dup.

Returns:



20
# File 'lib/wx/doc/colour.rb', line 20

def clone; end

#dupWx::Colour

Returns a copy-constructed Colour object.

Returns:



16
# File 'lib/wx/doc/colour.rb', line 16

def dup; end

#get_alphaInteger

Returns the alpha value, on platforms where alpha is not yet supported, this always returns ALPHA_OPAQUE.

Returns:

  • (Integer)


186
# File 'lib/wx/doc/gen/colour.rb', line 186

def get_alpha; end

#get_as_string(flags = (wxC2S_NAME|wxC2S_CSS_SYNTAX)) ⇒ String Also known as: as_string

Converts this colour to a String using the given flags.

The supported flags are Wx::C2S_NAME, to obtain the colour name (e.g. colour(255,0,0) == “red”), Wx::C2S_CSS_SYNTAX, to obtain the colour in the “rgb(r,g,b)” or “rgba(r,g,b,a)” syntax (e.g. colour(255,0,0,85) == “rgba(255,0,0,0.333)”), and Wx::C2S_HTML_SYNTAX, to obtain the colour as “#” followed by 6 hexadecimal digits (e.g. colour(255,0,0) == “#FF0000”). This function returns empty string if the colour is not initialized (see #is_ok). Otherwise, the returned string is always non-empty, but the function asserts if the colour has alpha channel (i.e. is non opaque) but Wx::C2S_CSS_SYNTAX (which is the only one supporting alpha) is not specified in flags.

Note:

For non-solid (i.e. non-RGB) colour this function returns "rgb(??, ?? ??)" or "#??????".

Parameters:

  • flags (Integer) (defaults to: (wxC2S_NAME|wxC2S_CSS_SYNTAX))

Returns:

  • (String)


212
# File 'lib/wx/doc/gen/colour.rb', line 212

def get_as_string(flags=(wxC2S_NAME|wxC2S_CSS_SYNTAX)) end

#get_blueInteger

Returns the blue intensity as unsigned int.

Returns:

  • (Integer)


190
# File 'lib/wx/doc/gen/colour.rb', line 190

def get_blue; end

#get_greenInteger

Returns the green intensity as unsigned int.

Returns:

  • (Integer)


194
# File 'lib/wx/doc/gen/colour.rb', line 194

def get_green; end

#get_luminanceFloat Also known as: luminance

Return the perceived brightness of the colour.

This value is computed using the simple

0.299*R + 0.587*G + 0.114*B

formula with the coefficients taken from the RGB to YIQ conversion formula and R, G and B being the values of the corresponding colour channels normalized to 0..1 range, so that the return value is 0 for black and 1 for white.

Returns:

  • (Float)


223
# File 'lib/wx/doc/gen/colour.rb', line 223

def get_luminance; end

#get_redInteger

Returns the red intensity as unsigned int.

Returns:

  • (Integer)


198
# File 'lib/wx/doc/gen/colour.rb', line 198

def get_red; end

#get_rgbInteger Also known as: rgb

Gets the RGB or RGBA colour values as a single 32 bit value.

The returned value is of the same form as expected by #set_rgb and #set_rgba. Notice that #get_rgb returns the value with 0 as its highest byte independently of the value actually returned by #alpha. So for a fully opaque colour, the return value of #get_rgba is 0xFFBBGGRR while that of #get_rgb is 0x00BBGGRR.

Returns:

  • (Integer)


112
# File 'lib/wx/doc/gen/colour.rb', line 112

def get_rgb; end

#get_rgbaInteger Also known as: rgba

Gets the RGB or RGBA colour values as a single 32 bit value.

The returned value is of the same form as expected by #set_rgb and #set_rgba. Notice that #get_rgb returns the value with 0 as its highest byte independently of the value actually returned by #alpha. So for a fully opaque colour, the return value of #get_rgba is 0xFFBBGGRR while that of #get_rgb is 0x00BBGGRR.

Returns:

  • (Integer)


120
# File 'lib/wx/doc/gen/colour.rb', line 120

def get_rgba; end

#greenInteger

Returns the green intensity.

Returns:

  • (Integer)

See Also:



231
# File 'lib/wx/doc/gen/colour.rb', line 231

def green; end

#is_okBoolean Also known as: ok?

Returns true if the colour object is valid (the colour has been initialised with RGB values).

Returns:

  • (Boolean)


235
# File 'lib/wx/doc/gen/colour.rb', line 235

def is_ok; end

#is_solidBoolean Also known as: solid?

Returns true if the color can be described using RGB values, i.e.

is solid, false if it is a pattern (currently only possible on macOS)

Returns:

  • (Boolean)


249
# File 'lib/wx/doc/gen/colour.rb', line 249

def is_solid; end

#make_disabled(brightness = 255) ⇒ Wx::Colour

Make a disabled version of this colour.

This method modifies the object in place and returns the object itself.

Parameters:

  • brightness (Integer) (defaults to: 255)

Returns:



262
# File 'lib/wx/doc/gen/colour.rb', line 262

def make_disabled(brightness=255) end

#redInteger

Returns the red intensity.

Returns:

  • (Integer)

See Also:



243
# File 'lib/wx/doc/gen/colour.rb', line 243

def red; end

#set(red, green, blue, alpha = Wx::ALPHA_OPAQUE) ⇒ void #set(rGB) ⇒ void #set(str) ⇒ Boolean

Overloads:

  • #set(red, green, blue, alpha = Wx::ALPHA_OPAQUE) ⇒ void

    This method returns an undefined value.

    Sets the RGB intensity values using the given values (first overload), extracting them from the packed long (second overload), using the given string (third overload).

    When using third form, #set accepts: colour names (those listed in Wx::ColourDatabase), the CSS-like "rgb(r,g,b)" or "rgba(r,g,b,a)" syntax (case insensitive) and the HTML-like syntax: "#" followed by 6 hexadecimal digits for red, green, blue components. Returns true if the conversion was successful, false otherwise.

    Parameters:

    • red (Integer)
    • green (Integer)
    • blue (Integer)
    • alpha (Integer) (defaults to: Wx::ALPHA_OPAQUE)
  • #set(rGB) ⇒ void

    This method returns an undefined value.

    Sets the RGB intensity values using the given values (first overload), extracting them from the packed long (second overload), using the given string (third overload).

    When using third form, #set accepts: colour names (those listed in Wx::ColourDatabase), the CSS-like "rgb(r,g,b)" or "rgba(r,g,b,a)" syntax (case insensitive) and the HTML-like syntax: "#" followed by 6 hexadecimal digits for red, green, blue components. Returns true if the conversion was successful, false otherwise.

    Parameters:

    • rGB (Integer)
  • #set(str) ⇒ Boolean

    Sets the RGB intensity values using the given values (first overload), extracting them from the packed long (second overload), using the given string (third overload).

    When using third form, #set accepts: colour names (those listed in Wx::ColourDatabase), the CSS-like "rgb(r,g,b)" or "rgba(r,g,b,a)" syntax (case insensitive) and the HTML-like syntax: "#" followed by 6 hexadecimal digits for red, green, blue components. Returns true if the conversion was successful, false otherwise.

    Parameters:

    • str (String)

    Returns:

    • (Boolean)


147
# File 'lib/wx/doc/gen/colour.rb', line 147

def set(*args) end

#set_rgb(colRGB) ⇒ void Also known as: rgb=

This method returns an undefined value.

Sets the RGB or RGBA colour values from a single 32 bit value.

The arguments colRGB and colRGBA should be of the form 0x00BBGGRR and 0xAABBGGRR respectively where 0xRR, 0xGG, 0xBB and 0xAA are the values of the red, green, blue and alpha components. Notice the right-to-left order of components!

Parameters:

  • colRGB (Integer)

See Also:



93
# File 'lib/wx/doc/gen/colour.rb', line 93

def set_rgb(colRGB) end

#set_rgba(colRGBA) ⇒ void Also known as: rgba=

This method returns an undefined value.

Sets the RGB or RGBA colour values from a single 32 bit value.

The arguments colRGB and colRGBA should be of the form 0x00BBGGRR and 0xAABBGGRR respectively where 0xRR, 0xGG, 0xBB and 0xAA are the values of the red, green, blue and alpha components. Notice the right-to-left order of components!

Parameters:

  • colRGBA (Integer)

See Also:



104
# File 'lib/wx/doc/gen/colour.rb', line 104

def set_rgba(colRGBA) end