Class: Wx::Colour
- Defined in:
- lib/wx/doc/gen/colour.rb,
lib/wx/doc/colour.rb
Overview
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:
-
NULL_COLOUR - An empty, invalid colour.
-
TRANSPARENT_COLOUR - Valid but fully transparent colour (new in 2.9.1).
Class Method Summary collapse
-
.alpha_blend(fg, bg, alpha) ⇒ Integer
Blend colour, taking alpha into account.
-
.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.
- .create_grey(*args) ⇒ Object
-
.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.
-
.make_disabled(r, g, b, brightness = 255) ⇒ Array(Integer,Integer,Integer)
Create a disabled (dimmed) colour from (in/out) rgb parameters.
Instance Method Summary collapse
-
#==(colour) ⇒ Boolean
Tests the equality of two colours by comparing individual red, green, blue intensities and alpha values.
-
#alpha ⇒ Integer
Returns the alpha value, on platforms where alpha is not yet supported, this always returns ALPHA_OPAQUE.
-
#blue ⇒ Integer
Returns the blue intensity.
-
#change_lightness(ialpha) ⇒ Wx::Colour
Colour wrapper for ChangeLightness(r,g,b,ialpha).
-
#clone ⇒ Wx::Colour
Calls #dup.
-
#dup ⇒ Wx::Colour
Returns a copy-constructed Colour object.
-
#get_alpha ⇒ Integer
Returns the alpha value, on platforms where alpha is not yet supported, this always returns ALPHA_OPAQUE.
-
#get_as_string(flags = (wxC2S_NAME|wxC2S_CSS_SYNTAX)) ⇒ String
(also: #as_string)
Converts this colour to a String using the given flags.
-
#get_blue ⇒ Integer
Returns the blue intensity as unsigned int.
-
#get_green ⇒ Integer
Returns the green intensity as unsigned int.
-
#get_luminance ⇒ Float
(also: #luminance)
Return the perceived brightness of the colour.
-
#get_red ⇒ Integer
Returns the red intensity as unsigned int.
-
#get_rgb ⇒ Integer
(also: #rgb)
Gets the RGB or RGBA colour values as a single 32 bit value.
-
#get_rgba ⇒ Integer
(also: #rgba)
Gets the RGB or RGBA colour values as a single 32 bit value.
-
#green ⇒ Integer
Returns the green intensity.
-
#initialize(*args) ⇒ Colour
constructor
A new instance of Colour.
-
#is_ok ⇒ Boolean
(also: #ok?)
Returns true if the colour object is valid (the colour has been initialised with RGB values).
-
#is_solid ⇒ Boolean
(also: #solid?)
Returns true if the color can be described using RGB values, i.e.
-
#make_disabled(brightness = 255) ⇒ Wx::Colour
Make a disabled version of this colour.
-
#red ⇒ Integer
Returns the red intensity.
- #set(*args) ⇒ Object
-
#set_rgb(colRGB) ⇒ void
(also: #rgb=)
Sets the RGB or RGBA colour values from a single 32 bit value.
-
#set_rgba(colRGBA) ⇒ void
(also: #rgba=)
Sets the RGB or RGBA colour values from a single 32 bit value.
Methods inherited from Object
Constructor Details
#initialize ⇒ Wx::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.
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.
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.
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)
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.
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.
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.
255 |
# File 'lib/wx/doc/gen/colour.rb', line 255 def ==(colour) end |
#alpha ⇒ Integer
Returns the alpha value, on platforms where alpha is not yet supported, this always returns ALPHA_OPAQUE.
175 |
# File 'lib/wx/doc/gen/colour.rb', line 175 def alpha; end |
#blue ⇒ Integer
Returns the blue intensity.
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).
275 |
# File 'lib/wx/doc/gen/colour.rb', line 275 def change_lightness(ialpha) end |
#dup ⇒ Wx::Colour
Returns a copy-constructed Colour object.
16 |
# File 'lib/wx/doc/colour.rb', line 16 def dup; end |
#get_alpha ⇒ Integer
Returns the alpha value, on platforms where alpha is not yet supported, this always returns ALPHA_OPAQUE.
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.
For non-solid (i.e. non-RGB) colour this function returns "rgb(??, ?? ??)" or "#??????".
212 |
# File 'lib/wx/doc/gen/colour.rb', line 212 def get_as_string(flags=(wxC2S_NAME|wxC2S_CSS_SYNTAX)) end |
#get_blue ⇒ Integer
Returns the blue intensity as unsigned int.
190 |
# File 'lib/wx/doc/gen/colour.rb', line 190 def get_blue; end |
#get_green ⇒ Integer
Returns the green intensity as unsigned int.
194 |
# File 'lib/wx/doc/gen/colour.rb', line 194 def get_green; end |
#get_luminance ⇒ Float 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.
223 |
# File 'lib/wx/doc/gen/colour.rb', line 223 def get_luminance; end |
#get_red ⇒ Integer
Returns the red intensity as unsigned int.
198 |
# File 'lib/wx/doc/gen/colour.rb', line 198 def get_red; end |
#get_rgb ⇒ Integer 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.
112 |
# File 'lib/wx/doc/gen/colour.rb', line 112 def get_rgb; end |
#get_rgba ⇒ Integer 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.
120 |
# File 'lib/wx/doc/gen/colour.rb', line 120 def get_rgba; end |
#green ⇒ Integer
Returns the green intensity.
231 |
# File 'lib/wx/doc/gen/colour.rb', line 231 def green; end |
#is_ok ⇒ Boolean Also known as: ok?
Returns true if the colour object is valid (the colour has been initialised with RGB values).
235 |
# File 'lib/wx/doc/gen/colour.rb', line 235 def is_ok; end |
#is_solid ⇒ Boolean 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)
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.
262 |
# File 'lib/wx/doc/gen/colour.rb', line 262 def make_disabled(brightness=255) end |
#red ⇒ Integer
Returns the red intensity.
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
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!
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!
104 |
# File 'lib/wx/doc/gen/colour.rb', line 104 def set_rgba(colRGBA) end |