96 lines
3.8 KiB
Plaintext
96 lines
3.8 KiB
Plaintext
\12345678901234567890123456789012345
|
|
\User input/Graphical.......... X .
|
|
\ Please enter a string and 75000: .
|
|
\ String: Hello, World!___ .
|
|
\ Number: 75000___________ .
|
|
|
|
def X0=20, Y0=10; \upper-left corner of window's position (chars)
|
|
def StrMax = 16; \maximum number of characters in strings
|
|
char String(2, StrMax); \string arrays (includes Number string)
|
|
int StrInx(2); \index to character to be added to String
|
|
int Mouse, Button, C, I, SN;
|
|
|
|
func GetButton; \Return soft button number at mouse pointer
|
|
int X, Y;
|
|
[Mouse:= GetMouse;
|
|
X:= Mouse(0)/8 - X0; \convert pixels to char cells
|
|
Y:= Mouse(1)/16 - Y0;
|
|
if X>=32 & X<=34 & Y=0 then return 0; \exit [X]
|
|
if X>=10 & X<=10+StrMax & Y=4 then return 1; \line 1
|
|
if X>=10 & X<=10+StrMax & Y=6 then return 2; \line 2
|
|
return -1; \mouse not on any soft button
|
|
];
|
|
|
|
proc ShowCursor(Flag); \Turn cursor at insertion point on or off
|
|
int Flag;
|
|
[Cursor(10+StrInx(SN)+X0, 4+SN*2+Y0);
|
|
ChOut(6, if Flag then ^_ else ^ );
|
|
];
|
|
|
|
[SetVid($12); \640x480 graphics
|
|
TrapC(true); \disable Ctrl+C
|
|
Attrib($70); \black on gray
|
|
SetWind(0+X0, 0+Y0, 35+X0, 8+Y0, 0, \fill\true);
|
|
Cursor(33+X0, 0+Y0); Text(6, "X");
|
|
Cursor(2+X0, 2+Y0); Text(6, "Please enter a string and 75000:");
|
|
Cursor(2+X0, 4+Y0); Text(6, "String:");
|
|
Cursor(2+X0, 6+Y0); Text(6, "Number:");
|
|
|
|
Attrib($1F); \bright white on blue, for title
|
|
Cursor(0+X0, 0+Y0); Text(6, " User input/Graphical ");
|
|
|
|
Attrib($F0); \black on bright white
|
|
for SN:= 0 to 1 do \initialize Strings
|
|
[StrInx(SN):= 0;
|
|
Cursor(10+X0, 4+SN*2+Y0);
|
|
for I:= 0 to StrMax-1 do
|
|
[String(SN, I):= $20; ChOut(6, ^ )];
|
|
];
|
|
SN:= 0; \select first, topmost String
|
|
ShowCursor(true);
|
|
|
|
ShowMouse(true);
|
|
loop [MoveMouse; \make pointer track mouse movements
|
|
Mouse:= GetMouse;
|
|
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 release
|
|
[MoveMouse;
|
|
Mouse:= GetMouse;
|
|
];
|
|
if Button = GetButton then \if down Button = release button
|
|
[if Button = 0 then quit;
|
|
if Button # -1 then \move cursor to active String
|
|
[ShowCursor(false);
|
|
SN:= Button-1;
|
|
ShowCursor(true);
|
|
];
|
|
];
|
|
];
|
|
if KeyHit then
|
|
[ShowMouse(false); \don't overwrite mouse pointer
|
|
C:= ChIn(1); \get character from non-echoed keyboard
|
|
if SN = 0 and C >= $20 and C <= $7E or \all printable ASCIIs
|
|
SN = 1 and C >= $30 and C <= $39 then \only numeric digits
|
|
[String(SN, StrInx(SN)):= C;
|
|
if StrInx(SN) < StrMax-1 then StrInx(SN):= StrInx(SN)+1;
|
|
]
|
|
else if C = \BS\$08 then \delete back a character
|
|
[ShowCursor(false);
|
|
if StrInx(SN) > 0 then StrInx(SN):= StrInx(SN)-1;
|
|
]
|
|
else if C = \tab\$09 then \select next string
|
|
[ShowCursor(false);
|
|
SN:= rem((SN+1)/2);
|
|
]
|
|
else if C = \Esc\$1B then quit;
|
|
|
|
Cursor(10+X0, 4+SN*2+Y0); \show active String
|
|
for I:= 0 to StrInx(SN)-1 do ChOut(6, String(SN, I));
|
|
ChOut(6, ^_);
|
|
ShowMouse(true);
|
|
];
|
|
];
|
|
SetVid(3); \restore normal text mode immediately
|
|
]
|