background image
C H A P T E R 1 3
Drawing and Graphics
13-16
Using the Drawing Interface
viewFormat: nil,
ViewSetupFormScript: func()
begin
// aView is the view to be scaled
self.stepchildren := [aView];
end,
...};
Translating Data Shapes
13
You can use the global functions
PointsToArray
and
ArrayToPoints
to
translate points data between a polygon shape (
'polygonShape
) and a
NewtonScript array.
Finding Points Within a Shape
13
Use the
HitShape
function to determine whether a pen event occurred within the
boundaries of the shape. This operation is useful for implementing button-like
behavior in any shape. Possible results returned by the
HitShape
function include:
nil
// nothing hit
true
// the primitive shape passed was hit
[2,5] // X marks the shape hit in the following array
// shape := [s,s,[s,s,s,s,s,X,s],s,s]
You can retrieve the shape by using the value returned by the
HitShape
method
as a path expression, as in the following code fragment:
result := HitShape(shape,x,y);
if result then // make sure non-nil
begin
if IsArray(result) then // its an array path
thingHit := shape.(result);
else
thingHit := shape;// its a simple shape
end
Although the expression
shape.(result)
may look unusual, it is perfectly
legitimate NewtonScript. For further explanation of this syntax, see the "Array
Accessor" discussion in The NewtonScript Programming Language.
© 2007-2024, o7 studio » при воспроизведении материала сайта ссылка обязательна