Skip to content
Snippets Groups Projects
Commit ab953fbc authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers
Browse files

some colour utilities

parent 743b49b0
No related branches found
No related tags found
No related merge requests found
Pipeline #3323 failed
......@@ -54,11 +54,9 @@ namespace fggl::gui {
}*/
void Panel::render(gfx::Paint &paint) {
spdlog::info("Imma render mah panel! {}, {}", bottomRight().x, bottomRight().y );
// background painting time
gfx::Path2D background(topLeft());
background.colour(math::vec3(1.0F, 1.0F, 0.0F));
background.colour(math::vec3(32.0f/255.0f, 74.0F/255.0F, 135.0F/255.0F));
draw_box(background, topLeft(), bottomRight());
paint.fill(background);
......
......@@ -8,6 +8,43 @@
namespace fggl::gui {
constexpr float RGB_MAX_VAL = 255.0F;
constexpr math::vec3 rgbToNormal(char red, char green, char blue) {
return {red / RGB_MAX_VAL, green / RGB_MAX_VAL, blue / RGB_MAX_VAL};
}
/**
* Convert a Hue-saturation-value colour to RGB
*
* @param hue hue component, assumed 0 - 360
* @param saturation assumed 0 - 1
* @param value assumed 0 - 1
* @return RGB, in the range 0,1 for each component
*/
constexpr math::vec3 HSVtoNormal(float hue, float saturation, float value) {
assert( 0 < hue && hue <= 360);
assert( 0 < saturation && saturation <= 1);
assert( 0 < value && value <= 1);
const float chroma = value * saturation;
const float x = chroma * (1 - fabs( fmod(hue / 60.0F, 2) - 1) );
math::vec3 tmp{0,0,0};
if ( 0 <= hue && hue < 60 ) {
tmp = {chroma,x,0};
} else if ( 60 <= hue && hue < 120 ) {
tmp = {x, chroma, 0};
} else if (120 <= hue && hue < 180 ) {
tmp = {0, chroma, x};
} else if ( 180 <= hue && hue < 240 ) {
tmp = {0, x, chroma};
} else if ( 240 <= hue && hue < 300) {
tmp = {x, 0, chroma};
} else if ( 300 <= hue && hue < 360) {
tmp = {chroma, 0, x};
}
return tmp + (value - chroma);
}
void draw_box( gfx::Path2D& path, math::vec2 topLeft, math::vec2 bottomRight);
void draw_progress( gfx::Path2D& path, math::vec2 topLeft, math::vec2 size, float value);
void draw_slider( gfx::Path2D& path, math::vec2 topLeft, math::vec2 size, float value);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment