From 6a8938305e13a9bf43023e3268f5d3db0b86c52f Mon Sep 17 00:00:00 2001 From: josh Date: Wed, 4 Jun 2025 13:46:43 -0500 Subject: [PATCH] Gas Readme First Draft. --- README.md | 78 ++++++++++++++++++++++++++++++++++++++++++++++ include/Color4.hpp | 6 +++- include/mcolor.h | 8 +++-- main.cpp | 7 ++--- src/Color4.cpp | 2 +- src/mcolor.cpp | 6 ++-- 6 files changed, 97 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e69de29..cf12ec6 100644 --- a/README.md +++ b/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`, +- Colors::Reds +- Colors::Oranges +- Colors::Yellows +- Colors::Greens +- Colors::Cyans +- Colors::Blues +- Colors::Purples +- Colors::Pinks +- Colors::Whites +- Colors::Grays +- Colors::Browns + +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. + + diff --git a/include/Color4.hpp b/include/Color4.hpp index 66e3a3c..9f18cba 100644 --- a/include/Color4.hpp +++ b/include/Color4.hpp @@ -18,7 +18,11 @@ class Color4; std::string toEscapeCode(Color4 c, bool bg=false); -void print_builtin_color_list(); +namespace mcolor +{ + void printBuiltinColorList(); +} + /// A type representing a color with alpha. /// Our default format is RGBA with 8 bits-per-channel. diff --git a/include/mcolor.h b/include/mcolor.h index 1d100fb..4094445 100644 --- a/include/mcolor.h +++ b/include/mcolor.h @@ -7,7 +7,9 @@ #include #include #include +#include "Color3.hpp" #include "Color4.hpp" +#include "Colors.hpp" #include "AnsiEscapeCodes.hpp" namespace mcolor { @@ -15,9 +17,11 @@ namespace mcolor { 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(); -#endif + void printAnsiColorTable(); diff --git a/main.cpp b/main.cpp index 7b5fa2e..11d3692 100644 --- a/main.cpp +++ b/main.cpp @@ -12,9 +12,8 @@ std::string fmt_color(const Color4& c) int main() { -#ifdef WIN32 - mcolor::windowsSaneify(); -#endif + mcolor::windowsSaneify(); + // TODO: Demo Color Space Math Operations @@ -22,7 +21,7 @@ int main() // TODO: Demo Color output in console. - print_builtin_color_list(); + mcolor::printBuiltinColorList(); mcolor::printAnsiColorTable(); mcolor::printRGBConsoleTest(); diff --git a/src/Color4.cpp b/src/Color4.cpp index e9d8a06..a2831ee 100644 --- a/src/Color4.cpp +++ b/src/Color4.cpp @@ -14,7 +14,7 @@ std::string toEscapeCode(Color4 c, bool bg){ return std::format("\033[38;2;{};{};{}m", c.r, c.g, c.b); } -void print_builtin_color_list() { +void mcolor::printBuiltinColorList() { #if !defined(WIN32) int i = 0; for (const Color4& color : list) { diff --git a/src/mcolor.cpp b/src/mcolor.cpp index f56e3a3..51124fe 100644 --- a/src/mcolor.cpp +++ b/src/mcolor.cpp @@ -26,7 +26,7 @@ namespace mcolor return std::format("\033[{}m", static_cast::type>(c)); } -#ifdef WIN32 + /* * Beat Windows into submission and make it interpret ansi codes. * 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. */ void windowsSaneify() { +#ifdef WIN32 HANDLE handleOut = GetStdHandle(STD_OUTPUT_HANDLE); DWORD consoleMode; GetConsoleMode( handleOut, &consoleMode); @@ -44,8 +45,9 @@ namespace mcolor consoleMode |= DISABLE_NEWLINE_AUTO_RETURN; SetConsoleMode( handleOut , consoleMode ); SetConsoleOutputCP(CP_UTF8); - } #endif + } + void printAnsiColorTable() { std::vector ansifg = {