Color
Edit on GitHubS | Return | Name | Parameters |
---|---|---|---|
Color | (uint32 argb = 0) | ||
Color | (uint8 r, uint8 g, uint8 b, uint8 a = 255) | ||
uint32 | GetARGB | (void) const | |
void | SetARGB | (uint32 argb) | |
bool | operator == | (const Color& color) const | |
bool | operator != | (const Color& color) const | |
uint8 | B | ||
uint8 | G | ||
uint8 | R | ||
uint8 | A |
Description
Represents a color defined by R, G, B, and A. Each component can be manipulated directly through the exposed property values. A single color occupies four bytes of memory, one for each channel of the color and each color is arranged in such a way as to allow casting to and from a 4-byte integer of the form 0xAARRGGBB
. The functions GetARGB and SetARGB, provide explicit ways of encoding and decoding colors to and from packed ARGB representations.
Constructors
Color | (uint32 argb = 0) |
Constructs a color from argb, a packed ARGB integer.
Color | (uint8 r, uint8 g, uint8 b, uint8 a = 255) |
Constructs a color with components set to r, g, b and a.
Functions
uint32 | GetARGB | (void) const |
Returns this color as a packed ARGB integer.
void | SetARGB | (uint32 argb) |
Sets this color to argb, a packed ARGB integer.
Operators
bool | operator == | (const Color& color) const |
bool | operator != | (const Color& color) const |
Performs equality comparison on each component.
Properties
uint8 | B | |
uint8 | G | |
uint8 | R | |
uint8 | A |
Provides direct access to the Red, Green, Blue and Alpha components of this color.
Examples
// C++
#include <Robot.h>
ROBOT_NS_USE_ALL;
int main (void)
{
Color c1, c2 (150, 200, 100);
// argb becomes 0xFF96C864
uint32 argb = c2.GetARGB();
// c1 becomes c2
c1.SetARGB (argb);
c1 == c2; // True
c1 != c2; // False
// Standard data
uint32 pixels[] =
{
0xFFFF0000,
0xFF00FF00,
0xFF0000FF,
};
// Pixels can be casted directly
Color* colors = (Color*) pixels;
colors[0]; // (255, 0, 0, 255)
colors[1]; // (0, 255, 0, 255)
colors[2]; // (0, 0, 255, 255)
colors[0].GetARGB(); // 0xFFFF0000
colors[1].GetARGB(); // 0xFF00FF00
colors[2].GetARGB(); // 0xFF0000FF
return 0;
}
// Node
var robot = require ("robot-js");
var c1 = robot.Color();
var c2 = robot.Color
(150, 200, 100);
// argb becomes 0xFF96C864
var argb = c2.getARGB();
// c1 becomes c2
c1.setARGB (argb);
c1.eq (c2); // True
c1.ne (c2); // False
c1.r; // 150
c1.g; // 200
c1.b; // 100
c1.a; // 255
// Color construction
c1 = robot.Color (c2);
c1 = robot.Color
({
r: 20,
g: 40,
b: 60,
a: 80 // Optional
});