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).
- BLACK
- BLUE
- CYAN
- GREEN
- YELLOW
- LIGHT_GREY
- RED
- WHITE
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
-
#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_opaque ⇒ Boolean
(also: #opaque?)
Returns true if the color is completely opaque (i.e., full opacity).
-
#is_solid ⇒ Boolean
(also: #solid?)
Returns true if the color can be described using RGB values, i.e.
-
#is_translucent ⇒ Boolean
(also: #translucent?)
Returns true if the color has some translucency (not fully opaque, but not transparent either).
-
#is_transparent ⇒ Boolean
(also: #transparent?)
Returns true if the color is completely transparent (i.e., no opacity).
-
#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.
167 |
# File 'lib/wx/doc/gen/colour.rb', line 167 def initialize(*args) end |
Class Method Details
.alpha_blend(fg, bg, alpha) ⇒ Integer
Blend colour, taking alpha into account.
328 |
# File 'lib/wx/doc/gen/colour.rb', line 328 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.
294 |
# File 'lib/wx/doc/gen/colour.rb', line 294 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)
321 |
# File 'lib/wx/doc/gen/colour.rb', line 321 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.
302 |
# File 'lib/wx/doc/gen/colour.rb', line 302 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.
279 |
# File 'lib/wx/doc/gen/colour.rb', line 279 def self.make_disabled(r, g, b, brightness=255) end |
Instance Method Details
#alpha ⇒ Integer
Returns the alpha value, on platforms where alpha is not yet supported, this always returns ALPHA_OPAQUE.
174 |
# File 'lib/wx/doc/gen/colour.rb', line 174 def alpha; end |
#blue ⇒ Integer
Returns the blue intensity.
181 |
# File 'lib/wx/doc/gen/colour.rb', line 181 def blue; end |
#change_lightness(ialpha) ⇒ Wx::Colour
Wx::Colour wrapper for ChangeLightness(r,g,b,ialpha).
284 |
# File 'lib/wx/doc/gen/colour.rb', line 284 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.
185 |
# File 'lib/wx/doc/gen/colour.rb', line 185 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 "#??????".
211 |
# File 'lib/wx/doc/gen/colour.rb', line 211 def get_as_string(flags=(wxC2S_NAME|wxC2S_CSS_SYNTAX)) end |
#get_blue ⇒ Integer
Returns the blue intensity as unsigned int.
189 |
# File 'lib/wx/doc/gen/colour.rb', line 189 def get_blue; end |
#get_green ⇒ Integer
Returns the green intensity as unsigned int.
193 |
# File 'lib/wx/doc/gen/colour.rb', line 193 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.
222 |
# File 'lib/wx/doc/gen/colour.rb', line 222 def get_luminance; end |
#get_red ⇒ Integer
Returns the red intensity as unsigned int.
197 |
# File 'lib/wx/doc/gen/colour.rb', line 197 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.
111 |
# File 'lib/wx/doc/gen/colour.rb', line 111 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.
119 |
# File 'lib/wx/doc/gen/colour.rb', line 119 def get_rgba; end |
#green ⇒ Integer
Returns the green intensity.
230 |
# File 'lib/wx/doc/gen/colour.rb', line 230 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).
234 |
# File 'lib/wx/doc/gen/colour.rb', line 234 def is_ok; end |
#is_opaque ⇒ Boolean Also known as: opaque?
Returns true if the color is completely opaque (i.e., full opacity).
258 |
# File 'lib/wx/doc/gen/colour.rb', line 258 def is_opaque; 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)
248 |
# File 'lib/wx/doc/gen/colour.rb', line 248 def is_solid; end |
#is_translucent ⇒ Boolean Also known as: translucent?
Returns true if the color has some translucency (not fully opaque, but not transparent either).
263 |
# File 'lib/wx/doc/gen/colour.rb', line 263 def is_translucent; end |
#is_transparent ⇒ Boolean Also known as: transparent?
Returns true if the color is completely transparent (i.e., no opacity).
253 |
# File 'lib/wx/doc/gen/colour.rb', line 253 def is_transparent; 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.
271 |
# File 'lib/wx/doc/gen/colour.rb', line 271 def make_disabled(brightness=255) end |
#red ⇒ Integer
Returns the red intensity.
242 |
# File 'lib/wx/doc/gen/colour.rb', line 242 def red; end |
#set(red, green, blue, alpha = Wx::ALPHA_OPAQUE) ⇒ void #set(rGB) ⇒ void #set(str) ⇒ Boolean
146 |
# File 'lib/wx/doc/gen/colour.rb', line 146 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!
92 |
# File 'lib/wx/doc/gen/colour.rb', line 92 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!
103 |
# File 'lib/wx/doc/gen/colour.rb', line 103 def set_rgba(colRGBA) end |