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

39 lines
1.9 KiB
Text
Raw Permalink Normal View History

2025-02-27 18:35:13 -05:00
\012345678901234567890123456789012345
\ Window creation............... X .
2024-10-16 18:07:41 -07:00
2025-02-27 18:35:13 -05:00
def X0=20, Y0=10; \position of upper-left corner of window (chars)
int Mouse, Button, X, Y;
2024-10-16 18:07:41 -07:00
func GetButton; \Return soft button number at mouse pointer
2025-02-27 18:35:13 -05:00
[Mouse:= GetMouse; \get pointer to mouse array information
X:= Mouse(0)/8 - X0; \convert pixels to 8x16-pixel character cells
2024-10-16 18:07:41 -07:00
Y:= Mouse(1)/16 - Y0;
2025-02-27 18:35:13 -05:00
if X>=32 & X<=34 & Y=0 then return 0; \exit [X]
2024-10-16 18:07:41 -07:00
return -1; \mouse not on any soft button
];
2025-02-27 18:35:13 -05:00
[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
2024-10-16 18:07:41 -07:00
Cursor(0+X0, 0+Y0); Text(6, " Window creation ");
2025-02-27 18:35:13 -05:00
ShowMouse(true); \turn on mouse pointer
2024-10-16 18:07:41 -07:00
loop [MoveMouse; \make pointer track mouse movements
2025-02-27 18:35:13 -05:00
Mouse:= GetMouse; \get pointer to mouse array information
2024-10-16 18:07:41 -07:00
if Mouse(2) then \a left or right mouse button is down
[Button:= GetButton; \get soft button at mouse pointer
2025-02-27 18:35:13 -05:00
while Mouse(2) do \wait for mouse button(s) to be released
2024-10-16 18:07:41 -07:00
[MoveMouse;
Mouse:= GetMouse;
];
2025-02-27 18:35:13 -05:00
if Button = GetButton then \if down Button = release button and it
if Button = 0 then quit; \is the exit [X] button then quit loop
2024-10-16 18:07:41 -07:00
];
2025-02-27 18:35:13 -05:00
if KeyHit then \get character from non-echoed keyboard
if ChIn(1) = \Esc\$1B then quit; \Esc key also exits program
2024-10-16 18:07:41 -07:00
];
SetVid(3); \restore normal text mode immediately
]