Gas Readme First Draft.
This commit is contained in:
78
README.md
78
README.md
@@ -0,0 +1,78 @@
|
|||||||
|
# mcolor - Maxine's Mean Color Library
|
||||||
|
|
||||||
|
mcolor is a C++20 library designed to provide an efficient suite for color management. Ideal for use in games, console applications, UI, and so forth.
|
||||||
|
|
||||||
|
## Color as a Class
|
||||||
|
|
||||||
|
At its heart, mcolor defines fundamental color structures for clear and concise representation:
|
||||||
|
|
||||||
|
- `Color3`: Represents an RGB color with 8-bit unsigned integer components (uint8_t r, g, b).
|
||||||
|
- `Color4`: Extends Color3 to include an alpha channel (uint8_t r, g, b, a).
|
||||||
|
|
||||||
|
These core types are complemented by a full range of conversion structs, enabling seamless transitions between various color models:
|
||||||
|
|
||||||
|
- `HSV`, `HSVA`: Hue, Saturation, Value (with Alpha)
|
||||||
|
- `RGB`, `RGBA`: Red, Green, Blue (with Alpha) using u8 components.
|
||||||
|
- `RGBf`, `RGBAf`: Red, Green, Blue (with Alpha) using float components.
|
||||||
|
- `LCH`, `LCHA`: Lightness, Chroma, Hue (with Alpha)
|
||||||
|
- `CMYK`: Cyan, Magenta, Yellow, Key (Black)
|
||||||
|
|
||||||
|
The library also includes organized Color Palettes within dedicated namespaces:
|
||||||
|
- `Colors::Primary`, or just `Colors`,
|
||||||
|
- <span style='color: red;'>Colors::Reds</span>
|
||||||
|
- <span style='color: orange;'>Colors::Oranges</span>
|
||||||
|
- <span style='color: yellow;'>Colors::Yellows</span>
|
||||||
|
- <span style='color: green;'>Colors::Greens</span>
|
||||||
|
- <span style='color: cyan;'>Colors::Cyans</span>
|
||||||
|
- <span style='color: blue;'>Colors::Blues</span>
|
||||||
|
- <span style='color: purple;'>Colors::Purples</span>
|
||||||
|
- <span style='color: pink;'>Colors::Pinks</span>
|
||||||
|
- <span style='color: white;'>Colors::Whites</span>
|
||||||
|
- <span style='color: gray;'>Colors::Grays</span>
|
||||||
|
- <span style='color: brown;'>Colors::Browns</span>
|
||||||
|
|
||||||
|
offering a rich set of predefined swatches for immediate use.
|
||||||
|
|
||||||
|
Additionally, we have worked to implement Ansi Escape Codes, console-output utilities, and cross-platform abstraction so that it works the same on Windows and Linux.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Integrating mcolor into your project is straightforward. Here's a quick sample:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
int main() {
|
||||||
|
#ifdef WIN32
|
||||||
|
mcolor::windowsSaneify();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
mcolor::printBuiltinColorList();
|
||||||
|
mcolor::printAnsiColorTable();
|
||||||
|
mcolor::printRGBConsoleTest();
|
||||||
|
|
||||||
|
|
||||||
|
for (float i = 0; i < 360; i+=10.f)
|
||||||
|
{
|
||||||
|
HSVA hsva {i, 1.f, 1.f};
|
||||||
|
|
||||||
|
Color4 c = Color4(hsva);
|
||||||
|
|
||||||
|
std::cout << std::format("{}hue:{} rgb: {},{},{} hex: {}", c.ToEscapeCode(), i, c.r, c.g, c.b, c.ToHex()) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Acknowledgements
|
||||||
|
|
||||||
|
This library was created by `maxine`, and is currently maintained by Josh O'Leary.
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
Pull requests and issues are always welcome! You know what to do!
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
This work is expressly dedicated to the Public Domain under the Unlicense.
|
||||||
|
|
||||||
|
|
||||||
|
@@ -18,7 +18,11 @@ class Color4;
|
|||||||
|
|
||||||
std::string toEscapeCode(Color4 c, bool bg=false);
|
std::string toEscapeCode(Color4 c, bool bg=false);
|
||||||
|
|
||||||
void print_builtin_color_list();
|
namespace mcolor
|
||||||
|
{
|
||||||
|
void printBuiltinColorList();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// A type representing a color with alpha.
|
/// A type representing a color with alpha.
|
||||||
/// Our default format is RGBA with 8 bits-per-channel.
|
/// Our default format is RGBA with 8 bits-per-channel.
|
||||||
|
@@ -7,7 +7,9 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "Color3.hpp"
|
||||||
#include "Color4.hpp"
|
#include "Color4.hpp"
|
||||||
|
#include "Colors.hpp"
|
||||||
#include "AnsiEscapeCodes.hpp"
|
#include "AnsiEscapeCodes.hpp"
|
||||||
|
|
||||||
namespace mcolor {
|
namespace mcolor {
|
||||||
@@ -15,9 +17,11 @@ namespace mcolor {
|
|||||||
|
|
||||||
std::string toEscapeCode(AnsiColor c);
|
std::string toEscapeCode(AnsiColor c);
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
|
/// Performs a hack that allows the windows console to interpret ANSI codes.
|
||||||
|
/// @note This only works on Windows 10 version 1511 and newer.
|
||||||
void windowsSaneify();
|
void windowsSaneify();
|
||||||
#endif
|
|
||||||
|
|
||||||
void printAnsiColorTable();
|
void printAnsiColorTable();
|
||||||
|
|
||||||
|
7
main.cpp
7
main.cpp
@@ -12,9 +12,8 @@ std::string fmt_color(const Color4& c)
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
mcolor::windowsSaneify();
|
||||||
mcolor::windowsSaneify();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// TODO: Demo Color Space Math Operations
|
// TODO: Demo Color Space Math Operations
|
||||||
|
|
||||||
@@ -22,7 +21,7 @@ int main()
|
|||||||
|
|
||||||
// TODO: Demo Color output in console.
|
// TODO: Demo Color output in console.
|
||||||
|
|
||||||
print_builtin_color_list();
|
mcolor::printBuiltinColorList();
|
||||||
mcolor::printAnsiColorTable();
|
mcolor::printAnsiColorTable();
|
||||||
mcolor::printRGBConsoleTest();
|
mcolor::printRGBConsoleTest();
|
||||||
|
|
||||||
|
@@ -14,7 +14,7 @@ std::string toEscapeCode(Color4 c, bool bg){
|
|||||||
return std::format("\033[38;2;{};{};{}m", c.r, c.g, c.b);
|
return std::format("\033[38;2;{};{};{}m", c.r, c.g, c.b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_builtin_color_list() {
|
void mcolor::printBuiltinColorList() {
|
||||||
#if !defined(WIN32)
|
#if !defined(WIN32)
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (const Color4& color : list) {
|
for (const Color4& color : list) {
|
||||||
|
@@ -26,7 +26,7 @@ namespace mcolor
|
|||||||
return std::format("\033[{}m", static_cast<typename std::underlying_type<AnsiColor>::type>(c));
|
return std::format("\033[{}m", static_cast<typename std::underlying_type<AnsiColor>::type>(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
/*
|
/*
|
||||||
* Beat Windows into submission and make it interpret ansi codes.
|
* Beat Windows into submission and make it interpret ansi codes.
|
||||||
* Fuck you Microsoft we're doing this the right way.
|
* Fuck you Microsoft we're doing this the right way.
|
||||||
@@ -37,6 +37,7 @@ namespace mcolor
|
|||||||
* along with any code that is printing the escape codes to a terminal.
|
* along with any code that is printing the escape codes to a terminal.
|
||||||
*/
|
*/
|
||||||
void windowsSaneify() {
|
void windowsSaneify() {
|
||||||
|
#ifdef WIN32
|
||||||
HANDLE handleOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
HANDLE handleOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
DWORD consoleMode;
|
DWORD consoleMode;
|
||||||
GetConsoleMode( handleOut, &consoleMode);
|
GetConsoleMode( handleOut, &consoleMode);
|
||||||
@@ -44,8 +45,9 @@ namespace mcolor
|
|||||||
consoleMode |= DISABLE_NEWLINE_AUTO_RETURN;
|
consoleMode |= DISABLE_NEWLINE_AUTO_RETURN;
|
||||||
SetConsoleMode( handleOut , consoleMode );
|
SetConsoleMode( handleOut , consoleMode );
|
||||||
SetConsoleOutputCP(CP_UTF8);
|
SetConsoleOutputCP(CP_UTF8);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void printAnsiColorTable() {
|
void printAnsiColorTable() {
|
||||||
std::vector<AnsiColor> ansifg = {
|
std::vector<AnsiColor> ansifg = {
|
||||||
|
Reference in New Issue
Block a user