SGL
Public Types | Static Public Member Functions | Public Attributes | List of all members
GColor Class Reference

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...
 

Detailed Description

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".

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Constants representing common system color names.

Enumerator
BLACK 
BLUE 
BROWN 
CYAN 
DARKGRAY 
GRAY 
GREEN 
LIGHTGRAY 
MAGENTA 
ORANGE 
PINK 
PURPLE 
RED 
WHITE 
YELLOW 

Member Function Documentation

◆ convertARGBToARGB()

int convertARGBToARGB ( int  a,
int  r,
int  g,
int  b 
)
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.

◆ convertARGBToColor() [1/2]

string convertARGBToColor ( int  a,
int  r,
int  g,
int  b 
)
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.

◆ convertARGBToColor() [2/2]

string convertARGBToColor ( int  argb)
static

Converts the given ARGB integer into a color name in the form "#aarrggbb".

◆ convertColorToARGB()

int convertColorToARGB ( string   colorName)
static

Converts a color name into an ARGB integer that encodes the alpha (opacity), red, green, and blue components of the color.

◆ convertColorToRGB()

int convertColorToRGB ( string   colorName)
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.

◆ convertQColorToColor()

string convertQColorToColor ( const QColor &  color)
static

Converts a Qt RGB color object into a color string.

Does not preserve alpha transparency.

◆ convertQColorToRGB()

int convertQColorToRGB ( const QColor &  color)
static

Converts a Qt color object into an RGB integer.

Does not preserve alpha transparency.

◆ convertRGBToColor() [1/2]

string convertRGBToColor ( int  rgb)
static

Converts an RGB integer value into a color name in the form "#rrggbb".

Does not preserve alpha transparency.

◆ convertRGBToColor() [2/2]

string convertRGBToColor ( int  r,
int  g,
int  b 
)
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.

◆ convertRGBToRGB()

int convertRGBToRGB ( int  r,
int  g,
int  b 
)
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.

◆ fixAlpha()

int fixAlpha ( int  argb)
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.

◆ getLuminance() [1/2]

double getLuminance ( int  rgb)
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

◆ getLuminance() [2/2]

double getLuminance ( string   color)
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

◆ hasAlpha()

bool hasAlpha ( string   color)
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".

◆ splitARGB()

void splitARGB ( int  argb,
int &  a,
int &  r,
int &  g,
int &  b 
)
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.

◆ splitRGB()

void splitRGB ( int  rgb,
int &  r,
int &  g,
int &  b 
)
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.

◆ toQColor()

QColor toQColor ( string   color)
static

Converts a color string into a Qt color object.

Preserves alpha transparency if the color string contains an alpha component.

◆ toQColorARGB()

QColor toQColorARGB ( int  argb)
static

Converts an ARGB integer into a Qt color object.

Preserves alpha transparency in the QColor object.

Member Data Documentation

◆ Color

enum { ... } Color

Constants representing common system color names.