Page 1 of 1

is a color

Posted: Tue Jun 11, 2013 8:23 pm
by mwieder
There's a thread in the use-list about "is a color" only evaluating a maximum of three numbers and ignoring more.
http://article.gmane.org/gmane.comp.ide ... ser/188165

I can't say whether it's right or not, but here's what the color parser in the engine code (in uidc.cpp) does:

Code: Select all

check for a number
if that fails,
  check against the colornames
  return boolean for the colornames check
else
  check for a second number (g value)
  if only one number
    dissect the first number into rgb components
  else (we have r&b values) <g>
    get a third number (g value)
    if only two numbers, return False
parse the rgb values into a color variable
return True
so 4th through nth numbers will just be ignored.

Should this be "fixed" by returning false if there's a fourth number in the line? Is there a reason to stop at three - do we need a fourth number entry in color specifications in the future for something? Do we need it now?

Re: is a color

Posted: Tue Jun 11, 2013 9:20 pm
by monte
At least on mobile there are some commands that accept RGBA values as well as RGB. Perhaps RGBA could be used as a shortcut for setting the blendLevel + color in one hit?... Basically is a color should throw an error where setting a color does...

Re: is a color

Posted: Wed Jun 12, 2013 8:46 am
by LCMark
This is definitely a bug - I had noticed it come into bugzilla (and noticed the thread on the list). The 'parsecolor' method should definitely return an error if a color isn't of one of the following forms:
  • A single int (compatibility with SuperCard - erk)
  • A hex color value
  • A name
  • A triple of ints

Re: is a color

Posted: Wed Jun 12, 2013 3:34 pm
by mwieder
So I take it one more call to MCU_strtol() to check for a fourth number would take care of that?
Would just checking for a False return value also cover the "42,42,42,hello" case?

Re: is a color

Posted: Wed Jun 12, 2013 3:42 pm
by LCMark
I think it's just a case of checking that it has reached the end of the string (i.e. l == 0) in two places...

If the second MCU_strotol returns done == False, then if l != 0 it should return 'false' (this would mean the string was something like "100,foo").

If the third MCU_strotol returns done == True and l != 0, then it should return 'false' (this would mean the string was something like "100,200,300foo" or "100,200,300,foo".

At least that's my reading of the code...

Re: is a color

Posted: Wed Jun 12, 2013 9:30 pm
by mwieder
OK - pull request submitted. Seems to do all the right things in my testing.

Re: is a color

Posted: Tue Jun 18, 2013 10:37 am
by LCMark
@mwieder: Thanks for this - I pulled it into 'develop' yesterday.