This class provides static methods for dealing with colors. More...
#include "gcolor.h"
Public Types | |
enum | { BLACK = 0x000000, BLUE = 0x0000FF, BROWN = 0x926239, CYAN = 0x00FFFF, DARKGRAY = 0x595959, GRAY = 0x999999, GREEN = 0x00FF00, LIGHTGRAY = 0xBFBFBF, MAGENTA = 0xFF00FF, ORANGE = 0xFFC800, PINK = 0xFFAFAF, PURPLE = 0xFF00FF, RED = 0xFF0000, WHITE = 0xFFFFFF, YELLOW = 0xFFFF00 } |
Constants representing common system color names. More... | |
Static Public Member Functions | |
static int | convertARGBToARGB(int a, int r, int g, int b) |
Converts four integer RGB values from 0-255 into an ARGB integer of the form 0xaarrggbb . More... | |
static string | convertARGBToColor(int a, int r, int g, int b) |
Converts four integer RGB values from 0-255 into a color name in the form "#aarrggbb" . More... | |
static string | convertARGBToColor(int argb) |
Converts the given ARGB integer into a color name in the form "#aarrggbb" . More... | |
static int | convertColorToARGB(string colorName) |
Converts a color name into an ARGB integer that encodes the alpha (opacity), red, green, and blue components of the color. More... | |
static int | convertColorToRGB(string colorName) |
Converts a color name into an integer that encodes the red, green, and blue components of the color. More... | |
static string | convertQColorToColor(const QColor &color) |
Converts a Qt RGB color object into a color string. More... | |
static int | convertQColorToRGB(const QColor &color) |
Converts a Qt color object into an RGB integer. More... | |
static string | convertRGBToColor(int rgb) |
Converts an RGB integer value into a color name in the form "#rrggbb" . More... | |
static string | convertRGBToColor(int r, int g, int b) |
Converts three integer RGB values from 0-255 into a color name in the form "#rrggbb" . More... | |
static int | convertRGBToRGB(int r, int g, int b) |
Converts three integer RGB values from 0-255 into a single RGB integer. More... | |
static int | fixAlpha(int argb) |
Sets the 'alpha' (high order bits) of the given integer to ff. More... | |
static double | getLuminance(int rgb) |
Returns the photometric luminance of the given RGB integer, which is a measure of how bright the color is. More... | |
static double | getLuminance(string color) |
Returns the photometric luminance of the given color, which is a measure of how bright the color is. More... | |
static bool | hasAlpha(string color) |
Returns true if the given color string is of the 8-hex-character form that contains an alpha channel in the highest order two characters, preceded by a hash sign, such as "#aaff0033". More... | |
static void | splitARGB(int argb, int &a, int &r, int &g, int &b) |
Splits the given ARGB integer into four integer RGB values from 0-255. More... | |
static void | splitRGB(int rgb, int &r, int &g, int &b) |
Splits the given RGB integer into three integer RGB values from 0-255. More... | |
static QColor | toQColor(string color) |
Converts a color string into a Qt color object. More... | |
static QColor | toQColorARGB(int argb) |
Converts an ARGB integer into a Qt color object. More... | |
Public Attributes | |
enum sgl::GColor:: { ... } | Color |
Constants representing common system color names. More... | |
This class provides static methods for dealing with colors.
Many graphical interactors and objects accept colors specified as strings or as RGB integers. An RGB integer is an integer with red, green, and blue values from 0-255 packed into its bits as follows:
00000000 00000000 00000000 00000000 ^ ^ ^ ^ | | | | alpha red green blue
A color can also be specified as a string. A color string can be one of the predefined color names:
BLACK
, BLUE
, CYAN
, DARK_GRAY
, GRAY
, GREEN
, LIGHT_GRAY
, MAGENTA
, ORANGE
, PINK
, RED
, WHITE
, and YELLOW
.
The case of the individual letters in the color name is ignored, as are spaces and underscores, so that the color DARK_GRAY
can be written as "Dark Gray"
.
Lastly, the color can also be specified as a string in the form "#rrggbb"
where rr
, gg
, and bb
are pairs of hexadecimal digits indicating the red, green, and blue components of the color, respectively. You can also include an alpha (opacity) channel by writing the hex string in ARGB form as "#aarrggbb"
.
anonymous enum |
|
static |
Converts four integer RGB values from 0-255 into an ARGB integer of the form 0xaarrggbb
.
Each of the aa
, rr
, gg
, and bb
values are two-digit hexadecimal numbers indicating the intensity of that component. If any of a, r, g, or b is outside the range of 0-255, throws an error.
|
static |
Converts four integer RGB values from 0-255 into a color name in the form "#aarrggbb"
.
Each of the aa
, rr
, gg
, and bb
values are two-digit hexadecimal numbers indicating the intensity of that component. If any of a, r, g, or b is outside the range of 0-255, throws an error.
|
static |
Converts the given ARGB integer into a color name in the form "#aarrggbb"
.
|
static |
Converts a color name into an ARGB integer that encodes the alpha (opacity), red, green, and blue components of the color.
|
static |
Converts a color name into an integer that encodes the red, green, and blue components of the color.
This function is also compatible with ARGB colors.
|
static |
Converts a Qt RGB color object into a color string.
Does not preserve alpha transparency.
|
static |
Converts a Qt color object into an RGB integer.
Does not preserve alpha transparency.
|
static |
Converts an RGB integer value into a color name in the form "#rrggbb"
.
Does not preserve alpha transparency.
|
static |
Converts three integer RGB values from 0-255 into a color name in the form "#rrggbb"
.
Each of the rr
, gg
, and bb
values are two-digit hexadecimal numbers indicating the intensity of that component. If any of r, g, or b is outside the range of 0-255, throws an error.
|
static |
Converts three integer RGB values from 0-255 into a single RGB integer.
Each of the rr
, gg
, and bb
values are two-digit hexadecimal numbers indicating the intensity of that component. If any of r, g, or b is outside the range of 0-255, throws an error.
|
static |
Sets the 'alpha' (high order bits) of the given integer to ff.
If RGB is not completely black, but alpha is 0, assumes that the client meant to use an opaque color and add ff as alpha channel.
|
static |
Returns the photometric luminance of the given RGB integer, which is a measure of how bright the color is.
This is calculated using the following formula: https://en.wikipedia.org/wiki/Relative_luminance
|
static |
Returns the photometric luminance of the given color, which is a measure of how bright the color is.
This is calculated using the following formula: https://en.wikipedia.org/wiki/Relative_luminance
|
static |
Returns true if the given color string is of the 8-hex-character form that contains an alpha channel in the highest order two characters, preceded by a hash sign, such as "#aaff0033".
|
static |
Splits the given ARGB integer into four integer RGB values from 0-255.
Each of the aa
, rr
, gg
, and bb
values are two-digit hexadecimal numbers indicating the intensity of that component.
|
static |
Splits the given RGB integer into three integer RGB values from 0-255.
Each of the rr
, gg
, and bb
values are two-digit hexadecimal numbers indicating the intensity of that component. Ignores alpha transparency.
|
static |
Converts a color string into a Qt color object.
Preserves alpha transparency if the color string contains an alpha component.
|
static |
Converts an ARGB integer into a Qt color object.
Preserves alpha transparency in the QColor object.
enum { ... } Color |
Constants representing common system color names.