0

I'm working on stackfile export to JSON for use in a VCS system and I've found some bizarre results from exporting/importing gradients. The dictionary says the following about the properties:

fillGradient["from"] - A coordinate specifying the starting point of the gradient

fillGradient["to"] - A coordinate specifying the end point of the gradient

fillGradient["via"] - A coordinate specifying the intermediate point of the gradient (affects scaling and shearing of the gradient)

As you can see the coordinate system isn't specified. From some tests it appears the coordinates are relative to the card however this does not make sense to me as the value would change with every move. Does anyone have any further documentation on these properties and/or reasons the properties don't follow the markerPoints convention being relative to the object points where it clearly could do so.

Monte Goulding
  • 2,380
  • 1
  • 21
  • 25

3 Answers3

3

Points locations are relative to the card as you found. You might want to see this stack for reference: http://www.tactilemedia.com/site_files/downloads/gradient_explorer.rev

Scott Rossi
  • 885
  • 5
  • 6
2

Actually, these gradient properties are relative to the topleft of the card. This is the way that I was able to import Gradients from Adobe Ilustrator version 7 into LiveCode.

You could check the code in this stack:

http://andregarzia.on-rev.com/alejandro/stacks/Eps_Import_V05C.zip

  • Thanks mate! I can't really comprehend why they aren't relative to the object so they are portable but it's good to get solid confirmation. – Monte Goulding Mar 09 '13 at 08:24
2

Some time ago when I also got irritated over the strange coordinate system I added the following behavior to my graphics:

setProp relFillGradient[pKind] pPoint
   put round(item 1 of pPoint*the width of me + item 1 of the topLeft of me) into tX
   put round(item 2 of pPoint*the height of me + item 2 of the topLeft of me) into tY
   set the fillGradient[pKind] of me to tX,tY
end relFillGradient

getProp relFillGradient[pKind]
   put the fillGradient[pKind] of me into tPoint
   put (item 1 of tPoint - item 1 of the topleft of me)/the width of me into tRelX
   put (item 2 of tPoint - item 2 of the topleft of me)/the height of me into tRelY
   return (tRelX,tRelY)
end relFillGradient

Then to set the fillGradient you can do:

set the relFillGradient["from"] of graphic "myGraphic" to 0.1,0.3

Where the relative points is 0,0 for top left and 1,1 for bottom right.

NOTE: As you need to set the values to a rounded value you might not get the exact same value back from getProp.

If you don't want a percentage value (as I did) it gets even simpler as you can remove the multiplication and you get the benefit of not having to round your values.

hliljegren
  • 426
  • 3
  • 9