gui-kit

API Reference

Color

Setters and getters for color operations.

The guikit::Color class is a utility class that can be used as helper to set colors. the color is stored as a single uint32_t ( 32 bit unsigned integer )

This doc assumes using namespace guikit is set and #include <guikit/color.hpp> is included. Otherwise, use guikit::Color instead of Color.

Constructors

  1. By listing individual color components
     // red      // green   // blue    // opacity
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a);

Example:

// Bright red
Color(255,0,0,255);
  1. By using single hexadecimal literal to specify the color
Color(uint32_t color);
// Bright Red
Color(0xFF0000FF);

Available methods

set()

change the values of the color object.

Color& set(uint8_t r, uint8_t g, uint8_t b, uint8_t a);

Example:

// Changing red to green
Color(255,0,0,255).set(0,255,0,255);

setR(uint8_t r)

set the red component of the color object

Color& setR(uint8_t r);

Example:

Color(0,0,0,255).setR(255);

setG(uint8_t g)

set the green component of the color object

Color& setG(uint8_t g);

Example:

Color(0,0,0,255).setG(255);

setB(uint8_t b)

set the blue component of the color object

Color& setB(uint8_t b);

Example:

Color(0,0,0,255).setB(255);

setA(uint8_t a)

set the alpha (opacity) component of the color object

Color& setA(uint8_t a);

Example:

Color(0,0,0,255).setA(128); 

getABGR()

get the color as a 32-bit unsigned integer in ABGR format.

uint32_t getABGR();

Example:

uint32_t abgr = Color(255,0,0,255).getABGR();

getRGBA()

get the color as a 32-bit unsigned integer in RGBA format.

uint32_t getRGBA();

Example:

uint32_t rgba = Color(255,0,0,255).getRGBA();

Full Example

Here is a full example of how to use the Color class:

#include <guikit/color.hpp>
#include <cstdint>
#include <iostream>

using namespace guikit;

int main() {
    // initialize using hex (opaque red)
    Color myColor(0xFF0000FF);

    // change value to semi-transparent purple using chaining
    myColor.setB(255).setA(128);

    // access components
    std::cout << "Red:   " << (int)myColor.r << std::endl;
    std::cout << "Green: " << (int)myColor.g << std::endl;
    std::cout << "Blue:  " << (int)myColor.b << std::endl;
    std::cout << "Alpha: " << (int)myColor.a << std::endl;

    // access raw color
    std::cout << "Raw RGBA value: 0x" << std::hex << myColor.getRGBA() << std::endl;

    return 0;
}

On this page