RosettaCodeData/Task/Window-creation/XPL0/window-creation.xpl0

39 lines
1.9 KiB
Plaintext

\012345678901234567890123456789012345
\ Window creation............... X .
def X0=20, Y0=10; \position of upper-left corner of window (chars)
int Mouse, Button, X, Y;
func GetButton; \Return soft button number at mouse pointer
[Mouse:= GetMouse; \get pointer to mouse array information
X:= Mouse(0)/8 - X0; \convert pixels to 8x16-pixel character cells
Y:= Mouse(1)/16 - Y0;
if X>=32 & X<=34 & Y=0 then return 0; \exit [X]
return -1; \mouse not on any soft button
];
[SetVid($12); \set 640x480 graphics
TrapC(true); \prevent Ctrl+C from aborting the program
Attrib($70); \set black-on-gray color attribute
SetWind(0+X0, 0+Y0, 35+X0, 8+Y0, 0, \fill\true); \draw gray rectangle
Cursor(33+X0, 0+Y0); Text(6, "X"); \draw exit button
Attrib($9F); \set bright white on light blue, for title bar
Cursor(0+X0, 0+Y0); Text(6, " Window creation ");
ShowMouse(true); \turn on mouse pointer
loop [MoveMouse; \make pointer track mouse movements
Mouse:= GetMouse; \get pointer to mouse array information
if Mouse(2) then \a left or right mouse button is down
[Button:= GetButton; \get soft button at mouse pointer
while Mouse(2) do \wait for mouse button(s) to be released
[MoveMouse;
Mouse:= GetMouse;
];
if Button = GetButton then \if down Button = release button and it
if Button = 0 then quit; \is the exit [X] button then quit loop
];
if KeyHit then \get character from non-echoed keyboard
if ChIn(1) = \Esc\$1B then quit; \Esc key also exits program
];
SetVid(3); \restore normal text mode immediately
]