This static class Color (gb.qt4) has properties that return the system colours. Please note that in Gambas there is also a class Color (gb.image) in addition to the class Color (gb.qt4). This static class Color (gb.image) defines constants of predefined colours and contains some useful methods to deal with colours. The fact is that the colour constants and the useful methods are in Color (gb.image) and the system colours are in Color (gb.qt4). The Colour (gb.image) class contains constants and methods that do not depend on specific libraries. The constants are in RGB format. The methods use algorithms written or adapted by Minisini. The system colours, on the other hand, are linked to the current system and are provided by the current toolkit.
The (static) properties are described in the following table:
Colour name | Decimal | hexaDecimal |
---|---|---|
Background | 15724527 | &HEFEFEF |
ButtonBackground | 14540772 | &HDDDFE4 |
ButtonForeground | 0 | &H0 |
Foreground | 0 | &H0 |
LightBackground | 13885419 | &HD3DFEB |
LightForeground | 10921381 | &HA6A5A5 |
SelectedBackground | 6786482 | &H678DB2 |
SelectedForeground | 16777215 | &HFFFFFF |
TextBackground | 16777215 | &HFFFFFF |
TextForeground | 0 | &H0 |
TooltipBackground | 16777180 | &HFFFFDC |
TooltipForeground | 0 | &H0 |
Table 23.4.2.1.1: Colour constants class Color (gb.qt4)
This class Color (gb.image) is static and defines these colour constants:
Colour name | Decimal | hexaDecimal | RGB | HSV |
---|---|---|---|---|
Default - Transparent | -1 | &HFFFFFFFF | - | - |
Black | 0 | &H000000 | 0,0,0 | 0,0,0 |
White | 16777217 | &HFFFFFF | 255,255,255 | 0,0,255 |
Gray | 8421504 | &H808080 | 128,128,128 | 0,0,128 |
DarkGray | 4210752 | &H404040 | 64,64,64 | 0,0,64 |
LightGray | 12632256 | &HC0C0C0 | 192,192,192 | 0,0,192 |
Red | 16711680 | &HFF0000 | 255,0,0 | 0,255,255 |
DarkRed | 8388608 | &H800000 | 128,0,0 | 0,255,128 |
Green | 65280 | &H00FF00 | 0,255,0 | 120,255,255 |
DarkGreen | 32768 | &H008000 | 0,128,0 | 120,255,128 |
Blue | 255 | &H0000FF | 0,0,255 | 240,255,255 |
DarkBlue | 128 | &H000080 | 0,0,128 | 240,255,128 |
Yellow | 16776960 | &HFFFF00 | 255,255,0 | 60,255,255 |
DarkYellow | 8421376 | &H808000 | 128,128,0 | 60,255,128 |
Orange | 16744448 | &HFF8000 | 255,128,0 | 30,255,255 |
Magenta | 16711935 | &HFF00FF | 255,0,255 | 300,255,255 |
DarkMagenta | 8388736 | &H800080 | 128,0,128 | 300,255,128 |
Cyan | 65535 | &H00FFFF | 0,255,255 | 180,255,255 |
DarkCyan | 32896 | &H008080 | 0,128,128 | 180,255,128 |
Pink | 16744703 | &HFF80FF | 255,128,255 | 300,127,255 |
Violet | 8388863 | &H8000FF | 128,0,255 | 270,255,255 |
Table 23.4.2.1 : Colour constants of the static class Color (gb.image)
The numerous methods of the class Color (gb.image) enable the user to work with colours in Gambas in a qualified manner.
Colour | Description |
---|---|
RGB ( Red AS Integer, Green AS Integer, Blue AS Integer [ , Alpha AS Integer ] ) AS Integer | Returns a colour value from the RGB colour space with its red, green and blue colour component. |
HSV ( Hue AS Integer, Saturation AS Integer, Value AS Integer [ , Alpha AS Integer ] ) AS Integer | Returns a colour value from the HSV colour space with its hue, saturation and brightness colour components. |
SetRGB ( Color As Integer [ , Red As Integer, Green As Integer, Blue As Integer, Alpha As Integer ] ) As Integer | The set colour is optionally changed by the four new RGBA colour components. If at least one of these four colour components is specified, the corresponding colour component of the set colour is replaced by the specified parameter. If no colour component is specified, the set colour remains unchanged. |
SetHSV ( Colour As Integer [ , Hue As Integer, Saturation As Integer, Value As Integer, Alpha As Integer ] ) As Integer | The set colour is optionally changed by the four new HSVA colour components. If at least one of these four colour components is specified, the corresponding colour component of the set colour is replaced by the specified parameter. If no colour component is specified, the set colour remains unchanged. |
SetAlpha ( Color As Integer, Alpha As Integer ) As Integer | Changes the alpha value of a colour and returns the new colour. |
GetAlpha ( Color As Integer ) As Integer | Returns the alpha value of the specified colour. |
Darker ( Color As Integer ) As Integer | Returns a darker shade of the existing colour. |
Lighter ( Color As Integer ) As Integer | Returns a lighter shade of the existing colour. |
Blend ( Source As Integer, Destination As Integer ) As Integer | Blends the source colour and the destination colour depending on the alpha channel of the two colours and returns the resulting colour. The alpha channel of the resulting colour is the most transparent alpha channel of the source and destination. |
Merge ( Color1 As Integer, Color2 As Integer [ , Weight As Float ] ) As Integer | Returns a mixture of Color1 and Color2. Weight is the relative weight of the first colour, which is between 0 and 1. If the weight is not specified, it is set to 0.5. |
Desaturate ( Color As Integer ) As Integer | Returns the specified colour (desaturated) as a shade of grey. |
Gradient ( Color1 As Integer, Color2 As Integer [ , Weight As Float ] ) As Integer | Depending on the weight, a colour between Color1 and Color2 is returned. If the weight is 0, the colour Color1 is returned. If the weight is 1, the colour Color2 is returned. If no weight is specified, the weight is set to 0.5. |
Distance (Color1 As Integer, Color2 As Integer) As Float | Returns the RGB distance between two colours as a floating point number between 0.0 and 1.0. |
Table 23.4.2.1.2: Methods of the Colour (gb.image) class
In the selected examples, the original colours and the changed colours are displayed in two ColorButtons or three ColorChoosers and the source code used is specified.
Example 1 - Colour.Darker(..)
Public Sub btnDarker_Click() Dim iSourceColor, iResultColor As Integer iSourceColor = ColorButton1.Color iResultColor = Color.Darker(iSourceColor) ColorButton2.Color = iResultColor '-- ColorButton2.Color = Color.Darker(ColorButton1.Color) '-- Short version End
Example 2 - Colour.Lighter(..)
Public Sub btnLighter_Click() ColorButton2.Color = Color.Lighter(ColorButton1.Color) End
Example 3 - Colour.Desaturate(..)
Public Sub btnDesaturate_Click() ColorButton2.Color = Color.Desaturate(ColorButton1.Color) End
Example 4 - Colour.Distance(..)
Public Sub btnDistance_Click() Dim iColor1, iColor2 As Integer Dim fDistance As Float iColor1 = ColorButton1.Color iColor2 = ColorButton2.Color fDistance = Color.Distance(iColor1, iColor2) Print fDistance End
With the two colours red (Color.RGB(255,0,0)) and green (Color.HSV(120,255,255)), this results in a distance value of 0.70710678118655. Isn't that nice! In any case, the author is thrilled - but can't do anything with this value.
Example 5 - Colour.Merge(..)
Public Sub btnMerge_Click() Dim iColor1, iColor2, iResultColor As Integer Dim fWeight As Float '-- Weight is the relative weight of the first color, between 0 and 1. iColor1 = ColorButton1.Color fWeight = 0.3 iColor2 = ColorButton2.Color iResultColor = Color.Merge(iColor1, iColor2, fWeight) '-- iResultColor = Color.Merge(iColor1, iColor2) ' ---> fWeight = 0.5 (Default) ColorButton3.Color = iResultColor End
Example 6 - Colour.Gradient(..)
Public Sub btnGradient_Click() Dim iColor1, iColor2, iResultColor As Integer Dim fWeight As Float iColor1 = ColorButton1.Color iColor2 = ColorButton2.Color '-- fWeight = 0.0 ' Sonderfall 1 '-- fWeight = 1.0 ' Sonderfall 2 fWeight = 0.4 iResultColor = Color.Gradient(iColor1, iColor2, fWeight) '-- iResultColor = Color.Gradient(iColor1, iColor2) ' ---> fWeight = 0.5 (Default) ColorButton3.Color = iResultColor End
Example 7 - Colour.Blend(..)
Public Sub btnBlend_Click() Dim iSourceColor, iDestinationColor, iResultColor As Integer iSourceColor = ColorButton1.Color iSourceColor = Color.SetAlpha(iSourceColor, 190) ColorChooser1.SelectedColor = iSourceColor iDestinationColor = ColorButton2.Color iDestinationColor = Color.SetAlpha(iDestinationColor, 90) ColorChooser2.SelectedColor = iDestinationColor iResultColor = Color.Blend(iSourceColor, iDestinationColor) Print Color.GetAlpha(iResultColor) '-- Alternative: Print Color[iResultColor].Alpha ColorChooser3.SelectedColor = iResultColor End