mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 07:49:12 +02:00
+ initial implemenation
This commit is contained in:
parent
31ff347814
commit
53c07e6516
54
docs/mouseex/Makefile
Normal file
54
docs/mouseex/Makefile
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#######################################################################
|
||||||
|
#
|
||||||
|
# Makefile to compile all examples and convert them to LaTeX
|
||||||
|
#
|
||||||
|
#######################################################################
|
||||||
|
|
||||||
|
# Compiler
|
||||||
|
PP=ppc386
|
||||||
|
|
||||||
|
# Unit directory
|
||||||
|
# UNITDIR=/usr/lib/ppc/0.99.0/linuxunits
|
||||||
|
|
||||||
|
|
||||||
|
# Any options you wish to pass.
|
||||||
|
PPOPTS=
|
||||||
|
|
||||||
|
# Script to convert the programs to LaTeX examples which can be included.
|
||||||
|
PP2TEX=pp2tex
|
||||||
|
|
||||||
|
# Script to collect all examples in 1 file.
|
||||||
|
MAKETEX=make1tex
|
||||||
|
|
||||||
|
#######################################################################
|
||||||
|
# No need to edit after this line.
|
||||||
|
#######################################################################
|
||||||
|
|
||||||
|
ifdef UNITDIR
|
||||||
|
PPOPTS:=$(PPOPTS) -Up$(UNITDIR);
|
||||||
|
endif
|
||||||
|
|
||||||
|
.SUFFIXES: .pp .tex
|
||||||
|
|
||||||
|
.PHONY: all tex clean
|
||||||
|
|
||||||
|
OBJECTS=mouse1 mouse2 mouse3 mouse4 mouse5 mouse6 mouse7 mouse8 mouse9 \
|
||||||
|
mouse10
|
||||||
|
|
||||||
|
TEXOBJECTS=$(addsuffix .tex, $(OBJECTS))
|
||||||
|
|
||||||
|
all : $(OBJECTS)
|
||||||
|
|
||||||
|
tex : $(TEXOBJECTS)
|
||||||
|
|
||||||
|
onetex : tex
|
||||||
|
$(MAKETEX) $(TEXOBJECTS)
|
||||||
|
|
||||||
|
clean :
|
||||||
|
rm -f *.o *.s $(OBJECTS) $(TEXOBJECTS)
|
||||||
|
|
||||||
|
$(OBJECTS): %: %.pp
|
||||||
|
$(PP) $(PPOPTS) $*
|
||||||
|
|
||||||
|
$(TEXOBJECTS): %.tex: %.pp head.tex foot.tex
|
||||||
|
$(PP2TEX) $*
|
2
docs/mouseex/foot.tex
Normal file
2
docs/mouseex/foot.tex
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
\end{verbatim}
|
||||||
|
\end{FPCList}
|
3
docs/mouseex/head.tex
Normal file
3
docs/mouseex/head.tex
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
\begin{FPCList}
|
||||||
|
\item[Example]
|
||||||
|
\begin{verbatim}
|
30
docs/mouseex/mouse1.pp
Normal file
30
docs/mouseex/mouse1.pp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
Program Mouse1;
|
||||||
|
|
||||||
|
{example for InitMouse and MouseFound}
|
||||||
|
|
||||||
|
Uses Mouse;
|
||||||
|
|
||||||
|
Begin
|
||||||
|
If MouseFound Then
|
||||||
|
Begin
|
||||||
|
{go into graphics mode 13h}
|
||||||
|
Asm
|
||||||
|
movl $0x013, %eax
|
||||||
|
pushl %ebp
|
||||||
|
int $0x010
|
||||||
|
popl %ebp
|
||||||
|
End;
|
||||||
|
InitMouse;
|
||||||
|
ShowMouse; {otherwise it stays invisible}
|
||||||
|
Writeln('Mouse Found! (press enter to quit)');
|
||||||
|
Readln;
|
||||||
|
{back to text mode}
|
||||||
|
Asm
|
||||||
|
movl $3, %eax
|
||||||
|
pushl %ebp
|
||||||
|
int $0x010
|
||||||
|
popl %ebp
|
||||||
|
End
|
||||||
|
End
|
||||||
|
End.
|
||||||
|
|
28
docs/mouseex/mouse10.pp
Normal file
28
docs/mouseex/mouse10.pp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
Uses Mouse, Crt;
|
||||||
|
|
||||||
|
Var hor, vert: Longint;
|
||||||
|
x, y: Longint;
|
||||||
|
|
||||||
|
Begin
|
||||||
|
If MouseFound Then
|
||||||
|
Begin
|
||||||
|
ClrScr;
|
||||||
|
Writeln('Click any button to quit after you''ve entered a sequence of numbers.');
|
||||||
|
Writeln;
|
||||||
|
Writeln('Horizontal mickey''s per pixel:');
|
||||||
|
Writeln('Vertical mickey''s per pixel:');
|
||||||
|
ShowMouse;
|
||||||
|
Repeat
|
||||||
|
GotoXY(32,3);
|
||||||
|
ClrEol;
|
||||||
|
Readln(hor);
|
||||||
|
GotoXY(30,4);
|
||||||
|
ClrEol;
|
||||||
|
Readln(vert);
|
||||||
|
SetMouseSpeed(hor, vert);
|
||||||
|
Until (GetLastButtonPress(LButton,x,y) <> 0) Or
|
||||||
|
(GetLastButtonPress(RButton,x,y) <> 0) Or
|
||||||
|
(GetLastButtonPress(MButton,x,y) <> 0);
|
||||||
|
End
|
||||||
|
End.
|
||||||
|
|
17
docs/mouseex/mouse2.pp
Normal file
17
docs/mouseex/mouse2.pp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{example for ShowMouse and HideMouse}
|
||||||
|
|
||||||
|
Uses Mouse;
|
||||||
|
|
||||||
|
Begin
|
||||||
|
ClrScr;
|
||||||
|
If MouseFound Then
|
||||||
|
Begin
|
||||||
|
Writeln('Now you can see the mouse... (press enter to continue)');
|
||||||
|
ShowMouse;
|
||||||
|
Readln;
|
||||||
|
HideMouse;
|
||||||
|
Writeln('And now you can''t... (press enter to quit)');
|
||||||
|
Readln
|
||||||
|
End
|
||||||
|
End.
|
||||||
|
|
47
docs/mouseex/mouse3.pp
Normal file
47
docs/mouseex/mouse3.pp
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
{example for GetMouseState, IsLPressed, IsRPressed and IsMPressed}
|
||||||
|
|
||||||
|
Uses Mouse, Crt;
|
||||||
|
|
||||||
|
Var X, Y, State: Longint;
|
||||||
|
|
||||||
|
Begin
|
||||||
|
If MouseFound Then
|
||||||
|
Begin
|
||||||
|
ClrScr;
|
||||||
|
ShowMouse;
|
||||||
|
GotoXY(5,24);
|
||||||
|
Write('Left button:');
|
||||||
|
GotoXY(30,24);
|
||||||
|
Write('Right button:');
|
||||||
|
GotoXY(55,24);
|
||||||
|
Write('Middle button:');
|
||||||
|
While KeyPressed do Readkey; {clear keyboard buffer}
|
||||||
|
Repeat
|
||||||
|
GetMouseState(x, y, State);
|
||||||
|
GotoXY(20, 22);
|
||||||
|
Write('X: ',x:5,' (column: ',(x div 8):2,') Y: ',y:5, ' (row: ',(y div 8):2,')');
|
||||||
|
GotoXY(18, 24); {left button}
|
||||||
|
If (State and LButton) = LButton Then
|
||||||
|
{or: "If LPressed Then". If you use this function, no call to GetMouseState
|
||||||
|
is necessary}
|
||||||
|
Write('Down')
|
||||||
|
Else
|
||||||
|
Write('Up ');
|
||||||
|
GotoXY(44, 24); {right button}
|
||||||
|
If (State and RButton) = RButton Then
|
||||||
|
{or: "If RPressed Then"}
|
||||||
|
Write('Down')
|
||||||
|
Else
|
||||||
|
Write('Up ');
|
||||||
|
GotoXY(70, 24); {middle button}
|
||||||
|
If (State and MButton) = MButton Then
|
||||||
|
{or: "If MPressed Then"}
|
||||||
|
Write('Down')
|
||||||
|
Else
|
||||||
|
Write('Up ')
|
||||||
|
Until KeyPressed;
|
||||||
|
HideMouse;
|
||||||
|
While KeyPressed Do Readkey
|
||||||
|
End
|
||||||
|
End.
|
||||||
|
|
18
docs/mouseex/mouse4.pp
Normal file
18
docs/mouseex/mouse4.pp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{example for SetMousePos}
|
||||||
|
|
||||||
|
Uses Mouse, Crt;
|
||||||
|
|
||||||
|
Begin
|
||||||
|
If MouseFound Then
|
||||||
|
Begin
|
||||||
|
ShowMouse;
|
||||||
|
While KeyPressed do ReadKey;
|
||||||
|
Repeat
|
||||||
|
SetMousePos(Random(80*8), Random(25*8));
|
||||||
|
delay(100);
|
||||||
|
Until Keypressed;
|
||||||
|
HideMouse;
|
||||||
|
While KeyPressed do ReadKey;
|
||||||
|
End;
|
||||||
|
End.
|
||||||
|
|
73
docs/mouseex/mouse5.pp
Normal file
73
docs/mouseex/mouse5.pp
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
{example for GetLastButtonPress and GetLastButtonRelease}
|
||||||
|
|
||||||
|
Uses Mouse, Crt;
|
||||||
|
|
||||||
|
Var x, y, times: Longint;
|
||||||
|
c: Char;
|
||||||
|
|
||||||
|
Begin
|
||||||
|
If MouseFound Then
|
||||||
|
Begin
|
||||||
|
ClrScr;
|
||||||
|
ShowMouse;
|
||||||
|
Writeln('Move the mouse and click the buttons (press escape to quit).');
|
||||||
|
Writeln('Press the L-key to see the stats for the left button.');
|
||||||
|
Writeln('Press the R-key to see the stats for the right button.');
|
||||||
|
Writeln('Press the M-key to see the stats for the middle button.');
|
||||||
|
GotoXY(1,19);
|
||||||
|
Write('Since the last call to GetLastButtonPress with this button as parameter, the');
|
||||||
|
GotoXY(1,22);
|
||||||
|
Write('Since the last call to GetLastButtonRelease with this button as parameter, the');
|
||||||
|
Repeat
|
||||||
|
If Keypressed Then
|
||||||
|
Begin
|
||||||
|
c := UpCase(Readkey);
|
||||||
|
Case c Of
|
||||||
|
'L':
|
||||||
|
Begin
|
||||||
|
GotoXY(1, 20);
|
||||||
|
ClrEol;
|
||||||
|
times := GetLastButtonPress(LButton, x, y);
|
||||||
|
Write('left button has been pressed ',times,
|
||||||
|
' times, the last time at (',x,',',y,')');
|
||||||
|
times := GetLastButtonRelease(LButton, x, y);
|
||||||
|
GotoXY(1,23);
|
||||||
|
ClrEol;
|
||||||
|
Write('left button has been released ',times,
|
||||||
|
' times, the last time at (',x,',',y,')')
|
||||||
|
End;
|
||||||
|
'R':
|
||||||
|
Begin
|
||||||
|
GotoXY(1, 20);
|
||||||
|
ClrEol;
|
||||||
|
times := GetLastButtonPress(RButton, x, y);
|
||||||
|
Writeln('right button has been pressed ',times,
|
||||||
|
' times, the last time at (',x,',',y,')');
|
||||||
|
times := GetLastButtonRelease(RButton, x, y);
|
||||||
|
GotoXY(1,23);
|
||||||
|
ClrEol;
|
||||||
|
Write('right button has been released ',times,
|
||||||
|
' times, the last time at (',x,',',y,')')
|
||||||
|
End;
|
||||||
|
'M':
|
||||||
|
Begin
|
||||||
|
GotoXY(1, 20);
|
||||||
|
ClrEol;
|
||||||
|
times := GetLastButtonPress(MButton, x, y);
|
||||||
|
Writeln('middle button has been pressed ',times,
|
||||||
|
' times, the last time at (',x,',',y,')');
|
||||||
|
times := GetLastButtonRelease(MButton, x, y);
|
||||||
|
GotoXY(1,23);
|
||||||
|
ClrEol;
|
||||||
|
Write('middle button has been released ',times,
|
||||||
|
' times, the last time at (',x,',',y,')')
|
||||||
|
End
|
||||||
|
End
|
||||||
|
End;
|
||||||
|
Until (c = #27); {escape}
|
||||||
|
While KeyPressed do ReadKey;
|
||||||
|
GotoXY(1,24);
|
||||||
|
HideMouse
|
||||||
|
End
|
||||||
|
End.
|
||||||
|
|
22
docs/mouseex/mouse6.pp
Normal file
22
docs/mouseex/mouse6.pp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{example for SetMouseXRange, SetMouseYRange and SetMouseWindow}
|
||||||
|
|
||||||
|
Uses Mouse, Crt;
|
||||||
|
|
||||||
|
Begin
|
||||||
|
If MouseFound Then
|
||||||
|
Begin
|
||||||
|
SetMouseXRange(20*8,50*8); {charracter width and height = 8 pixels}
|
||||||
|
SetMouseYRange(10*8,15*8);
|
||||||
|
|
||||||
|
{the two lines of code have exactly the same effect as
|
||||||
|
SetMouseWindow(20*8,10*8,50*8,15*8)}
|
||||||
|
|
||||||
|
Writeln('Press any key to quit.');
|
||||||
|
ShowMouse;
|
||||||
|
While KeyPressed Do ReadKey;
|
||||||
|
Readkey;
|
||||||
|
While KeyPressed Do ReadKey;
|
||||||
|
HideMouse
|
||||||
|
End
|
||||||
|
End.
|
||||||
|
|
41
docs/mouseex/mouse7.pp
Normal file
41
docs/mouseex/mouse7.pp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
{example for SetMouseShape}
|
||||||
|
|
||||||
|
{warning: no error checking is performed on the input}
|
||||||
|
|
||||||
|
{the Ascii value you enter is XOR'ed with the Ascii value of the character
|
||||||
|
on the screen over which you move the cursor. To get a "transparent" cursor,
|
||||||
|
use the Ascii value 0}
|
||||||
|
|
||||||
|
Uses Mouse, Crt;
|
||||||
|
|
||||||
|
Var ascii, fc, bc: Byte;
|
||||||
|
x,y: Longint;
|
||||||
|
|
||||||
|
Begin
|
||||||
|
If MouseFound Then
|
||||||
|
Begin
|
||||||
|
ClrScr;
|
||||||
|
Writeln('Press any mouse button to quit after you''ve entered a sequence of numbers.');
|
||||||
|
Writeln;
|
||||||
|
Writeln('ASCII value of mouse cursor:');
|
||||||
|
Writeln('Forground color:');
|
||||||
|
Writeln('Background color:');
|
||||||
|
ShowMouse;
|
||||||
|
Repeat
|
||||||
|
GotoXY(30,3);
|
||||||
|
ClrEol;
|
||||||
|
Readln(ascii);
|
||||||
|
GotoXY(18,4);
|
||||||
|
ClrEol;
|
||||||
|
Readln(fc);
|
||||||
|
GotoXY(19,5);
|
||||||
|
ClrEol;
|
||||||
|
Readln(bc);
|
||||||
|
SetMouseShape(fc, bc, ascii)
|
||||||
|
Until (GetLastButtonPress(LButton,x,y) <> 0) Or
|
||||||
|
(GetLastButtonPress(RButton,x,y) <> 0) Or
|
||||||
|
(GetLastButtonPress(MButton,x,y) <> 0);
|
||||||
|
HideMouse
|
||||||
|
End;
|
||||||
|
End.
|
||||||
|
|
29
docs/mouseex/mouse8.pp
Normal file
29
docs/mouseex/mouse8.pp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{example for SetMouseAscii}
|
||||||
|
|
||||||
|
{warning: no error checking is performed on the input}
|
||||||
|
|
||||||
|
Uses Mouse, Crt;
|
||||||
|
|
||||||
|
Var ascii: Byte;
|
||||||
|
x,y: Longint;
|
||||||
|
|
||||||
|
Begin
|
||||||
|
If MouseFound Then
|
||||||
|
Begin
|
||||||
|
ClrScr;
|
||||||
|
Writeln('Press any mouse button to quit after you''ve entered an Ascii value.');
|
||||||
|
Writeln;
|
||||||
|
Writeln('ASCII value of mouse cursor:');
|
||||||
|
ShowMouse;
|
||||||
|
Repeat
|
||||||
|
GotoXY(30,3);
|
||||||
|
ClrEol;
|
||||||
|
Readln(ascii);
|
||||||
|
SetMouseAscii(ascii)
|
||||||
|
Until (GetLastButtonPress(LButton,x,y) <> 0) Or
|
||||||
|
(GetLastButtonPress(RButton,x,y) <> 0) Or
|
||||||
|
(GetLastButtonPress(MButton,x,y) <> 0);
|
||||||
|
HideMouse
|
||||||
|
End;
|
||||||
|
End.
|
||||||
|
|
54
docs/mouseex/mouse9.pp
Normal file
54
docs/mouseex/mouse9.pp
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
{example for SetMouseHideWindow}
|
||||||
|
|
||||||
|
{warning: when the mouse is moved into the specified region, it is turned off
|
||||||
|
until you call ShowMouse again. However, when you've called ShowMouse,
|
||||||
|
you'll have to call SetMouseHideWindow again to redefine the hide window...
|
||||||
|
It's not our fault, that's the way it's implemented in the mouse driver.
|
||||||
|
|
||||||
|
Below you can find an example of how to define a "permanent" hide region
|
||||||
|
with the cursor showing up again when you move it out of the region
|
||||||
|
|
||||||
|
Note: the mouse functions are zero-based, GotoXY is 1-based}
|
||||||
|
|
||||||
|
Uses Mouse, Crt;
|
||||||
|
|
||||||
|
Var x, y, buttons: Longint;
|
||||||
|
MouseOn: Boolean;
|
||||||
|
|
||||||
|
Begin
|
||||||
|
If MouseFound Then
|
||||||
|
Begin
|
||||||
|
ClrScr;
|
||||||
|
For y := 1 to 25 Do
|
||||||
|
Begin
|
||||||
|
GotoXY(20,y);
|
||||||
|
Write('|');
|
||||||
|
GotoXY(60,y);
|
||||||
|
Write('|');
|
||||||
|
End;
|
||||||
|
MouseOn := true;
|
||||||
|
GotoXY(30, 24);
|
||||||
|
Writeln('Press any key to quit');
|
||||||
|
ShowMouse;
|
||||||
|
SetMousePos(1,1);
|
||||||
|
While KeyPressed Do Readkey;
|
||||||
|
Repeat
|
||||||
|
GetMouseState(x,y,buttons);
|
||||||
|
If Not(MouseOn) And
|
||||||
|
((x <= 19*8) or (x >= 59*8)) Then
|
||||||
|
Begin
|
||||||
|
ShowMouse;
|
||||||
|
MouseOn := true
|
||||||
|
End;
|
||||||
|
If MouseOn And (x > 19*8) And (x<59*8) Then
|
||||||
|
Begin
|
||||||
|
SetMouseHideWindow(20*8,0,60*8,25*8);
|
||||||
|
MouseOn := false
|
||||||
|
End;
|
||||||
|
Until KeyPressed;
|
||||||
|
While KeyPressed Do Readkey;
|
||||||
|
HideMouse
|
||||||
|
End
|
||||||
|
End.
|
||||||
|
|
||||||
|
|
5
docs/mouseex/pp2tex
Normal file
5
docs/mouseex/pp2tex
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Simply paste a header and footer to the program.
|
||||||
|
cat head.tex > $1.tex
|
||||||
|
cat $1.pp >> $1.tex
|
||||||
|
cat foot.tex >> $1.tex
|
Loading…
Reference in New Issue
Block a user