If I understand correctly what you wish to do, here is a LCB-snippet, that may work in that direction (not tested, right out of my head).Dave B. wrote:[Cited from the use-list)
I'm trying to build a chemical periodic table widget. I can do this up to
the point of having it look like a periodic table (nice arrangement,
symbols in correct places). My plan depends on being able to store and
retrieve a rectangle for each element. I CAN compute an appropriate
rectangle for each chemical element that places it properly in a periodic
table. My plan depends on being able to store and retrieve a rectangle for
each element.
I want to create an array that has the 'usual' chemical information. I want
to include in that array the computed rectangle for each element such that
it can redraw the widget when a user reshapes the widget and can detect a
clickloc in the rectangle of the element to retrieve data
I've tried to store the rectangle in the array --and retrieve it -- without
success. I think the issue is that when it goes into the array it does so
as a string. I've tried to store 4 Numbers in the array for each chemical
element -- corresponding to the x,y of the top-left and bottom right of the
rectangle and then recreate the rectangle from those numbers. No success.
I've tried to store those as Integers and recreate them with commas into a
variable typed as an array. No success.
Code: Select all
private variable mNumOfElements as Number
private variable mCurrentElement as Number
private variable mCurrentRect as Rectangle
private variable mElements as Array
public handler OnCreate()
put 118 into mNumOfElements
put getPeriodicTable() into mElements
-- ...
end handler
private handler getPeriodicTable() returns Array
variable tTable as Array
-- Element 1
put the empty array into tTable["1"]
put 1 into tTable["1"]["Group"]
put 1 into tTable["1"]["Period"]
put "H" into tTable["1"]["Element"]
put "Hydrogen" into tTable["1"]["ElementName"]
put rectangle [20,20,80,80] into tTable["1"]["Rect"]
-- Element 2
put the empty array into tTable["2"]
put 18 into tTable["2"]["Group"]
put 1 into tTable["2"]["Period"]
put "He" into tTable["2"]["Element"]
put "Helium" into tTable["2"]["ElementName"]
put rectangle [420,20,480,80] into tTable["2"]["Rect"]
-- ....
return tTable
end handler
public handler OnMouseDown()
variable tRect as Rect
variable tPoint as Point
variable tCount as Number
put the click position into tPoint
repeat with tCount from 1 up to mNumOfElements
put mElements[(tCount formatted as string)]["rect"] into tRect
if tPoint is within tRect then
exit repeat
end if
end repeat
put tCount into mCurrentElement
put tRect into mCurrentRect
-- ...
end handler