is a color

Moderators: heatherlaine, Klaus, FourthWorld, kevinmiller, LCMark

Post Reply
mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2673
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

is a color

Post by mwieder » Tue Jun 11, 2013 8:23 pm

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?

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1559
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: is a color

Post by monte » Tue Jun 11, 2013 9:20 pm

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...
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 970
Joined: Thu Apr 11, 2013 11:27 am

Re: is a color

Post by LCMark » Wed Jun 12, 2013 8:46 am

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

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2673
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: is a color

Post by mwieder » Wed Jun 12, 2013 3:34 pm

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?

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 970
Joined: Thu Apr 11, 2013 11:27 am

Re: is a color

Post by LCMark » Wed Jun 12, 2013 3:42 pm

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...

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2673
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: is a color

Post by mwieder » Wed Jun 12, 2013 9:30 pm

OK - pull request submitted. Seems to do all the right things in my testing.

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 970
Joined: Thu Apr 11, 2013 11:27 am

Re: is a color

Post by LCMark » Tue Jun 18, 2013 10:37 am

@mwieder: Thanks for this - I pulled it into 'develop' yesterday.

Post Reply

Return to “Engine Contributors”