Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::common::Colour Class Reference

Stores the red, green, blue and alpha values of a colour. Can be parsed from a hex string, an ANSI string or a ConsoleColour. More...

#include <colour.h>

Public Member Functions

 Colour (ConsoleColour colour)
 Constructs a Colour from the the console equivalent.
 
 Colour (string string)
 Constructs a Colour from a string. If it starts with a '#' will be treated as a hex code otherwise, a ansi code.
 
 Colour (uint8_t red, uint8_t green, uint8_t blue)
 Constructs a Colour from a set of RGB values. Alpha defaults to 255.
 
 Colour (uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
 Constructs a Colour from a set of RGBA values.
 
ConsoleColour to_console_colour () const
 Converts the colour to a console colour.
 

Public Attributes

uint8_t red { 0 }
 The amount of red 0-255.
 
uint8_t green { 0 }
 The amount of green 0-255.
 
uint8_t blue { 0 }
 The amount of blue 0-255.
 
uint8_t alpha { 0 }
 The amount of alpha 0-255 (0 is visible, 255 is invisible) todo: confirm.
 

Detailed Description

Stores the red, green, blue and alpha values of a colour. Can be parsed from a hex string, an ANSI string or a ConsoleColour.

Definition at line 91 of file colour.h.

Constructor & Destructor Documentation

◆ Colour() [1/4]

Colour::Colour ( ConsoleColour  colour)
explicit

Constructs a Colour from the the console equivalent.

Parameters
colourThe console colour to convert

Definition at line 21 of file colour.cpp.

21 {
22 parse_console_colour(colour);
23}

◆ Colour() [2/4]

Colour::Colour ( string  string)
explicit

Constructs a Colour from a string. If it starts with a '#' will be treated as a hex code otherwise, a ansi code.

Parameters
stringThe string to parse, must be either a hex code or an ANSI escape code

Definition at line 30 of file colour.cpp.

30 {
31
32 if (string[0] == '#')
33 parse_hex_string(string);
34 else
35 parse_ansi_string(string);
36
37}

◆ Colour() [3/4]

Colour::Colour ( uint8_t  red,
uint8_t  green,
uint8_t  blue 
)

Constructs a Colour from a set of RGB values. Alpha defaults to 255.

Parameters
redThe amount of red 0-255
greenThe amount of green 0-255
blueThe amount of blue 0-255

Definition at line 46 of file colour.cpp.

47: red(red),
48 green(green),
49 blue(blue)
50{
51
52}
uint8_t green
The amount of green 0-255.
Definition colour.h:100
uint8_t blue
The amount of blue 0-255.
Definition colour.h:101
uint8_t red
The amount of red 0-255.
Definition colour.h:99

◆ Colour() [4/4]

Colour::Colour ( uint8_t  red,
uint8_t  green,
uint8_t  blue,
uint8_t  alpha 
)

Constructs a Colour from a set of RGBA values.

Parameters
redThe amount of red 0-255
greenThe amount of green 0-255
blueThe amount of blue 0-255
alphaThe amount of alpha 0-255

Definition at line 62 of file colour.cpp.

63: red(red),
64 green(green),
65 blue(blue),
67{
68
69}
uint8_t alpha
The amount of alpha 0-255 (0 is visible, 255 is invisible) todo: confirm.
Definition colour.h:102

Member Function Documentation

◆ to_console_colour()

ConsoleColour Colour::to_console_colour ( ) const

Converts the colour to a console colour.

Returns
The console colour

Definition at line 261 of file colour.cpp.

261 {
262
263
264 if (red == 0 && green == 0 && blue == 0)
265 return ConsoleColour::Black;
266
267 if (red == 0 && green == 128 && blue == 253)
268 return ConsoleColour::Blue;
269
270 if (red == 0 && green == 170 && blue == 0)
271 return ConsoleColour::Green;
272
273 if (red == 0 && green == 170 && blue == 170)
274 return ConsoleColour::Cyan;
275
276 if (red == 170 && green == 0 && blue == 0)
277 return ConsoleColour::Red;
278
279 if (red == 170 && green == 0 && blue == 170)
280 return ConsoleColour::Magenta;
281
282 if (red == 170 && green == 85 && blue == 0)
283 return ConsoleColour::Brown;
284
285 if (red == 170 && green == 170 && blue == 170)
286 return ConsoleColour::LightGrey;
287
288 if (red == 85 && green == 85 && blue == 85)
289 return ConsoleColour::DarkGrey;
290
291 if (red == 85 && green == 85 && blue == 255)
292 return ConsoleColour::LightBlue;
293
294 if (red == 85 && green == 255 && blue == 85)
295 return ConsoleColour::LightGreen;
296
297 if (red == 85 && green == 255 && blue == 255)
298 return ConsoleColour::LightCyan;
299
300 if (red == 255 && green == 85 && blue == 85)
301 return ConsoleColour::LightRed;
302
303 if (red == 255 && green == 85 && blue == 255)
304 return ConsoleColour::LightMagenta;
305
306 if (red == 0x96 && green == 0x82 && blue == 0x0E)
307 return ConsoleColour::Yellow;
308
309 if (red == 255 && green == 255 && blue == 255)
310 return ConsoleColour::White;
311
312 // Return a default value in case no match is found
313 return ConsoleColour::Black;
314}

References blue, green, and red.

Referenced by MaxOS::drivers::console::VESABootConsole::put_character().

Member Data Documentation

◆ alpha

uint8_t MaxOS::common::Colour::alpha { 0 }

The amount of alpha 0-255 (0 is visible, 255 is invisible) todo: confirm.

Definition at line 102 of file colour.h.

102{ 0 };

Referenced by MaxOS::common::GraphicsContext::colour_to_int().

◆ blue

uint8_t MaxOS::common::Colour::blue { 0 }

The amount of blue 0-255.

Definition at line 101 of file colour.h.

101{ 0 };

Referenced by MaxOS::common::GraphicsContext::colour_to_int(), MaxOS::common::GraphicsContext::invert_pixel(), and to_console_colour().

◆ green

uint8_t MaxOS::common::Colour::green { 0 }

The amount of green 0-255.

Definition at line 100 of file colour.h.

100{ 0 };

Referenced by MaxOS::common::GraphicsContext::colour_to_int(), MaxOS::common::GraphicsContext::invert_pixel(), and to_console_colour().

◆ red

uint8_t MaxOS::common::Colour::red { 0 }

The amount of red 0-255.

Definition at line 99 of file colour.h.

99{ 0 };

Referenced by MaxOS::common::GraphicsContext::colour_to_int(), MaxOS::common::GraphicsContext::invert_pixel(), and to_console_colour().


The documentation for this class was generated from the following files: