(*
* Svgalib-Gpc - Pascal porting of Svgalib header files.
* Copyright 1999, 2000 (C) Nicola Girardi <girardi@vicenza.linux.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*)
(*
* This is not the plain translation of vgamouse.h, but it's
* a modified mouse support using TFDDs (see gpc sources)
*
* If you want to use your own handlers just go to vgamouse.h
* and look at the prototypes you need. Then you know, it's up to you.
*)
unit VgaMouse;
interface
uses GPC; (* for TFDD *)
(* Mouse interface for svgalib. *)
(* Can be used independently. *)
const MOUSE_MICROSOFT = 0;
MOUSE_MOUSESYSTEMS = 1;
MOUSE_MMSERIES = 2;
MOUSE_LOGITECH = 3;
MOUSE_BUSMOUSE = 4;
MOUSE_PS2 = 5;
MOUSE_LOGIMAN = 6;
MOUSE_GPM = 7;
MOUSE_SPACEBALL = 8;
MOUSE_NONE = 9; (* Some special number for a non supported/existing mouse *)
MOUSE_INTELLIMOUSE = 10;
MOUSE_IMPS2 = 11;
MOUSE_UNCONFIGURED = 12;
MOUSE_ORIENTATION_VERTICAL = 0;
MOUSE_ORIENTATION_HORIZONTAL = 1;
MOUSE_ACCEL_TYPE_NORMAL = 1;
MOUSE_ACCEL_TYPE_POWER = 2;
DEFAULT_ACCEL_THRESH = 5;
DEFAULT_ACCEL_POWER = 1.2;
DEFAULT_ACCEL_OFFSET = 1;
DEFAULT_ACCEL_MULT = 10;
DEFAULT_MAXDELTA = 0;
DEFAULT_ACCEL_MAXDELTA = 0;
DEFAULT_ACCEL_TYPE = 0; (* MOUSE_ACCEL_TYPE_POWER *)
(* MS IntelliMouse has 18 steps, Logitech FirstMouse+ has 24 *)
DEFAULT_WHEEL_STEPS = 18;
DEFAULT_WHEEL_DELTA = (360 div DEFAULT_WHEEL_STEPS);
(* Logical or the following values to one of the above at will and give that for
* type in mouse_init (still they make only sense for serial mice)
*)
MOUSE_CHG_DTR = $80000000; (* CLEAR (!) the DTR line *)
MOUSE_DTR_HIGH = $40000000; (* when used with MOUSE_CHG_DTR set DTR not clear it *)
MOUSE_CHG_RTS = $20000000; (* CLEAR (!) the RTS line *)
MOUSE_RTS_HIGH = $10000000; (* when used with MOUSE_CHG_RTS set RTS not clear it *)
(* If MOUSE_CHG_DTR is not given the DTR state is not touched.. same with RTS resp.
* So I use MOUSE_MOUSESYSTEMS|MOUSE_CHG_RTS to force my
* multiprotocol mouse to MOUSESYSTEMS and use init the driver to MOUSESYSTEMS
*)
MOUSE_TYPE_MASK = $ffff; (* the upper 16bit are reserved for future flags *)
MOUSE_LEFTBUTTON = 4;
MOUSE_MIDDLEBUTTON = 2;
MOUSE_RIGHTBUTTON = 1;
MOUSE_FOURTHBUTTON = 8;
MOUSE_FIFTHBUTTON = 16;
MOUSE_SIXTHBUTTON = 32;
MOUSE_RESETBUTTON = 64;
MOUSE_XDIM = 1;
MOUSE_YDIM = 2;
MOUSE_ZDIM = 4;
MOUSE_RXDIM = 8;
MOUSE_RYDIM = 16;
MOUSE_RZDIM = 32;
MOUSE_2DIM = 3;
MOUSE_3DIM = 7;
MOUSE_6DIM = 63;
MOUSE_DEFAULTSAMPLERATE = 150;
var MouseFile: Text; (* this can be accessed by user programs
* to select on several files and on the mouse
* file
*)
procedure MouseInit; (* inititializing procedure *)
procedure MouseClose; (* close mouse file *)
function MouseMoved : boolean;
(* If there's an event ready to be read, handles hit *)
function MouseUpdate : Integer; asmname 'mouse_update';
(* Similar to mouse_update, but wait for an event to happen. *)
procedure MouseWaitForUpdate; asmname 'mouse_waitforupdate';
(* mouse_init sets default event handler that keeps track of absolute *)
(* coordinates: *)
const MOUSE_NOWRAP = 0;
MOUSE_WRAPX = 1;
MOUSE_WRAPY = 2;
MOUSE_WRAPZ = 4;
MOUSE_WRAPRX = 8;
MOUSE_WRAPRY = 16;
MOUSE_WRAPRZ = 32;
MOUSE_WRAP = 63;
MOUSE_ROT_COORDS = 196;
MOUSE_ROT_INFINITESIMAL = 0; (* report changes in angle about axes *)
MOUSE_ROT_RX_RY_RZ = 64; (* report angle about axes *)
(* Warning! Next two not yet supported! *)
MOUSE_ROT_ZXZ = 128; (* use x convention Euler angles *)
MOUSE_ROT_YPR = 196; (* use yaw, pitch, and roll *)
(* Set position of mouse. *)
procedure MouseSetPosition(x, y: Integer); asmname 'mouse_setposition';
(* Set position of mouse in all 6 dimensions. *)
procedure MouseSetPosition6d(x, y, z, rx, ry, rz, dim_mask: Integer); asmname 'mouse_setposition_6d';
(* Set horizontal range of mouse to [x1, x2] incl. *)
procedure MouseSetXRange(x1, x2: Integer); asmname 'mouse_setxrange';
(* Set vertical range of mouse to [y1, y2] incl. *)
procedure MouseSetYRange(y1, y2: Integer); asmname 'mouse_setyrange';
(* Set all ranges of mouse in 6 dimensions. *)
procedure MouseSetRange6d(x1, x2, y1, y2, z1, z2, rx1, rx2, ry1, ry2,
rz1, rz2, dim_mask: Integer); asmname 'mouse_setrange_6d';
(* Set scale factor by which raw mouse coordinates are divided. *)
procedure MouseSetScale(s: Integer); asmname 'mouse_setscale';
(* Enable/disable wrapping of mouse in horizontal and/or vertical range. *)
procedure MouseSetWrap(w: Integer); asmname 'mouse_setwrap';
(* Get current mouse x-coordinate. *)
function MouseGetX : Integer; asmname 'mouse_getx';
(* Get current mouse y-coordinate. *)
function MouseGetY : Integer; asmname 'mouse_gety';
(* Get position of mouse in all 6 dimensions. *)
procedure MouseGetPosition6d(var x, y, z, rx, ry, rz: Integer);
(* Get current mouse button status. *)
function MouseGetButton : Integer;
implementation
var
MouseFD : Integer = -1; (* mouse uninitialized *)
function MouseSelectFunc (var PrivateData; Writing: Boolean) : Integer;
begin
if Writing then MouseSelectFunc:= -1
else MouseSelectFunc:= MouseFD;
end;
procedure MouseOpenProc(var PrivateData; Mode : TOpenMode);
(* Initialize mouse device. Returns the mouse fd if succesful, -1 otherwise. *)
function MouseInitFD(dev : CString; v_type: Integer;
samplerate : Integer) : Integer; asmname 'mouse_init_return_fd';
(* needed by the init function *)
function VgaGetMouseType : Integer; asmname 'vga_getmousetype';
begin
if MouseFD = -1 then
begin
MouseFD:= MouseInitFD(String2CString('/dev/mouse'),
(* i don't want to read the exact mouse
* device by libvga.config
*)
VgaGetMouseType,
MOUSE_DEFAULTSAMPLERATE);
(*MouseSetDefaultEventHandler;*) (* this is already set by MouseInitFD *)
end;
end;
procedure MouseCloseProc(var PrivateData);
procedure MouseClose; asmname 'mouse_close';
begin
MouseClose;
MouseFD:= -1;
end;
procedure MouseInit;
begin
AssignTFDD(MouseFile, MouseOpenProc, MouseSelectFunc, TSelectProc(nil),
TReadFunc(nil), TWriteFunc(nil), TFlushProc(nil),
MouseCloseProc, TDoneProc(nil), Pointer(nil));
Reset(MouseFile);
end;
procedure MouseClose;
begin
Close(MouseFile);
end;
(* returns true if the mouse is moved *)
function MouseMoved : Boolean;
begin MouseMoved:= ( MouseUpdate <> 0 ) end;
end.
syntax highlighted by Code2HTML, v. 0.8.8b