(Revision 42 uploaded, fixes rATN and rTAN function for using rad for ATN and TAN functions, there was a mistake and not worked properly before current revision).
An example using Events (light events from an object).
Light events are construction without specific parameters signature (like the object which called Events in M2000). We use then from the method drawSquare. If we don't use functions for servicing these then we will not have problem. The parameters will be erased from the stack of values.
The light events aren't multicast enabled, call always one service function using the name space of the module where we define the group WithEvents, here the FourSidesOfSquare module. So if we want to get values from stack to variables we have to use New X, Y to get X and Y as new variables (because may be X and Y exist on module FourSidesOfSquare. Although Modules/Functions have own namespace, when we call them using Call Local the get the namespace of the caller. For events they get the namespace of the module which we define the WithEvents group a.
If we pass the group named a using by reference to another module, and execute the drawSquare module of a, then we get the events and call "back" the module FourSidesOfSquare.
For the drawing routines: We use a frame @ variant which place text at center of a parallelogram defines by two values (width and height). So see in the image bellow, the white 1 on the black square border.
class square {
Events "drawme", "drawme2"
private:
long x
public:
module drawSquare {
b=1
for a=1 to .x
call event "drawme", a, b
next
if .x>2 then
for b=2 to .x-1
call event "drawme", 1, b
call event "drawme", .x, b
for c=2 to .x-1
call event "drawme2", c, b
next
next
end if
if .x>1 then
for a=1 to .x
call event "drawme", a, .x
next
end if
}
// read only
Property Length {
value {
link parent x to x
value=x
} = 0&
}
class:
module square(n as long) {
if n<1 then Error "From 1 only"
.x<=n
}
}
module FourSidesOfSquare {
Window 12, 16000, 10000;
cls 5,0
double
report 2, "Four sides of square"
normal
group withevents a=square(20)
sq_width=min.data(scale.x, scale.y)/24
sq_width=(sq_width div twipsX)* twipsX
x_origin=(scale.x-20*sq_width) div 2-sq_width
y_origin=(scale.y-20*sq_width) div 2-sq_width
function a_drawme {
move x_origin+Number*sq_width, y_origin+Number*sq_width
fill sq_width, sq_width, 0
REM
{ ' split rem from block to print 1 at center of square tile
step -sq_width, -sq_width
pen 15 {fill @ sq_width, sq_width, 5,"1"}
}
}
function a_drawme2 {
move x_origin+Number*sq_width, y_origin+Number*sq_width
fill sq_width, sq_width, 15
}
a.drawSquare
rem
a=square(10) ' split line before a to change square width
x_origin=(WIDTH-a.length) DIV 2 -1
y_origin=(HEIGHT-a.length) DIV 2 -1
// alter definitions
function a_drawme {
Cursor x_origin+number, y_origin+number
PEN 5 {Print "1";}
}
function a_drawme2 {
Cursor x_origin+number, y_origin+number
PEN 1 {Print "0";}
}
a.drawSquare
Push Key$
Drop
}
FourSidesOfSquare
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου
You can feel free to write any suggestion, or idea on the subject.