Ferruslogic / TinyColor

LiveCode Script library for small and fast color manipulation and conversion.
MIT License
6 stars 2 forks source link

lighten and darken fail with RGB colors #1

Open stam66 opened 2 years ago

stam66 commented 2 years ago

I'm having an issue with lighten/darken (not tested other functions yet). If i pass a colorName or hex value, these all work as expected.

However if i pass the color of a control (which is set as an RGB value) or if i simply pass an RGB value, darken returns black and lighten returns a dark grey, no matter what color is passed as RBG.

The attached stack is a simple test - the buttons on the left assign aa color to 'source' by color name, RGB or hex, the buttons on the right lighten/darken the 'destination' graphic based on the 'source' background color. tinyColor test.livecode.zip

stam66 commented 2 years ago

Further to this, i realised the issue - the input is expected to be in the format RGB(r, g, b) instead of "r, g, b" - the latter is common usage in livecode and this therefore causes issues.

For example, passing darken("RGB(255,104,110)", 30) works as expected, but passing darken("255,104,110", 30) fails - the RBG values in sColor are all 0.

Could i therefore make a request to parse "r, g, b" as an RGB triplet without the qualifier 'RGB()', as is commonly the case in LiveCode?

Thank you

stam66 commented 2 years ago

A small addition to inputToRGB handler fixes this issue - in other words, statements like darken(the backgroundColor of graphic 1, 25) will now work as expected instead of returning 0,0,0.

I'm made a pull request with this working fix - it's my first pull request so apologies if it's not done correctly!