From 784a99b9b023e655b02c7cf04160fbd787386c6c Mon Sep 17 00:00:00 2001 From: Alexander Ewering Date: Tue, 4 Oct 2005 21:23:19 +0000 Subject: Beware, coded between 10 phone calls and 20 sudden surprises, but I still hope it's somehow usable :-) Colourpicker update: ------------------- 1) Converted numbuts to sliders and made the colourpicker wider. Sliders are more useful for something like RGB and HSV because they're fixed range values 2) Added a hex button for entering HTML-like color (#RRGGBB, can be entered both with and without the hash sign). This should completely replace the former strange NKEY functionality in buttonswindows, and even add hex support for buttons which didn't have it before. Please test thoroughly, I never coded something in a hurry like this. There are small rounding errors still... Maybe someone finds the reason? :) --- source/blender/blenlib/BLI_arithb.h | 2 ++ source/blender/blenlib/intern/arithb.c | 13 +++++++++++++ 2 files changed, 15 insertions(+) (limited to 'source/blender/blenlib') diff --git a/source/blender/blenlib/BLI_arithb.h b/source/blender/blenlib/BLI_arithb.h index f31729ac54a..fedcefcd8b8 100644 --- a/source/blender/blenlib/BLI_arithb.h +++ b/source/blender/blenlib/BLI_arithb.h @@ -650,6 +650,8 @@ hsv_to_rgb( float *g, float *b ); +void hex_to_rgb(char *hexcol, float *r, float *g, float *b); + void rgb_to_hsv( float r, float g, float b, diff --git a/source/blender/blenlib/intern/arithb.c b/source/blender/blenlib/intern/arithb.c index 723a046b699..ad2d5c1e458 100644 --- a/source/blender/blenlib/intern/arithb.c +++ b/source/blender/blenlib/intern/arithb.c @@ -2520,6 +2520,19 @@ void hsv_to_rgb(float h, float s, float v, float *r, float *g, float *b) } } +void hex_to_rgb(char *hexcol, float *r, float *g, float *b) +{ + unsigned int ri, gi, bi; + + if (hexcol[0] == '#') hexcol++; + + if (sscanf(hexcol, "%02x%02x%02x", &ri, &gi, &bi)) { + *r = ri / 255.0; + *g = gi / 255.0; + *b = bi / 255.0; + } +} + void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv) { float h, s, v; -- cgit v1.2.3