Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Help With A Graphic Mouse UNIT!!!!!!!!!!!!!

___Matrix______Matrix___ Posts: 1Member

Hello to whomever is reading this message!!!!!
I recently found a mouse Unit on the NET, I used it, but I found a "bug" in it; If you have colors on the screen, such as a BMP picture, or anything else that has colors, when you move the mouse, suddenly colored pixels appear on the screen.......
Meanwhile I canged a few Procedures and Fumctions, Add a few of my own, but I was not successfull in fixing this bug.......
Here is the mouse unit....


{**********************************************************************}


Unit Mouse256;


Interface

uses graph;
type buttons=(left,right,middle);
const seta:array[0..15,0..10] of word=(
( 9 , 9 ,999,999,999,999,999,999,999,999,999),
( 9 , 50, 9 ,999,999,999,999,999,999,999,999),
( 9 , 50, 50, 9 ,999,999,999,999,999,999,999),
( 9 , 50, 50, 50, 9 ,999,999,999,999,999,999),
( 9 , 50, 50, 50, 50, 9 ,999,999,999,999,999),
( 9 , 50, 50, 50, 50, 50, 9 ,999,999,999,999),
( 9 , 50, 50, 50, 50, 50, 50, 9 ,999,999,999),
( 9 , 50, 50, 50, 50, 50, 50, 50, 9 ,999,999),
( 9 , 50, 50, 50, 50, 50, 50, 50, 50, 9 ,999),
( 9 , 50, 50, 50, 50, 50, 9 , 9 , 9 , 9 , 9 ),
( 9 , 50, 50, 9 , 50, 50, 9 ,999,999,999,999),
( 9 , 50, 9 ,999, 9 , 50, 50, 9 ,999,999,999),
( 9 , 9 ,999,999, 9 , 50, 50, 9 ,999,999,999),
( 9 ,999,999,999,999, 9 , 50, 50, 9 ,999,999),
(999,999,999,999,999, 9 , 50, 50, 9 ,999,999),
(999,999,999,999,999,999, 9 , 9 ,999,999,999)); {The form for the mouse}

var mx,my: integer;
Allowed_int: Boolean;
mask: array[0..15,0..10] of byte;
newseg,newofs,newmask :word;

Procedure Show_Mouse_Cursor(show:boolean);
{This procedure is responsible for showing the mouse.}
{if the parameter "show" would be "true" the mouse would be shown}
{on the screen othervise , not.}

procedure Set_Mouse_Speed(x_speed,y_speed:integer);
{This procedure sets the mouse movement speed.}
{"x_speed" and "y_speed" recieve the number of mickeys/pixels the mouse}
{Will move every 8 pixels.}
{"X_speed" default is 8}
{"y_speed" default is 16}

Procedure Read_Mouse_Position(Var x,y:word);
{This procedure returns the X,Y location of the mouse}

function Read_Button_Stat(button:buttons):boolean;
{This procedure returns boolean parameters which mean if the "bt" button}
{is pressed. "bt" can recieve: "left","right" and "middle".}

Function Read_Button_Stat_point(button:buttons; mtx,mty:integer):boolean;

Procedure Set_Mouse_Position(mx,my:word);
{The procedure moves the position of the mouse to (mx,my) .}

Procedure Set_Mouse_Range(x1,y1,x2,y2:word);
{The procedure determines a window in which the mouse would be able to move.}

Procedure Wait_For_Mouse;
{The procedure waits for any of these :}
{1. mouse movements }
{2. clicking on one of the mouse buttons }
{3. clicking on one of the keyboard buttons }

Function Is_Mouse_On(mx1,my1,mx2,my2:word):boolean;
{The function returns a boolean parameter which tells us if the mouse}
{position is on the window from the point (mx1,my1) to the point (mx2,my2)}

Function Is_Mouse_Pressed_On(mx1,my1,mx2,my2:word; button:buttons):boolean;
{The function returns a boolean parameter which tells us if the mouse}
{position is on the window from the point (mx1,my1) to the point (mx2,my2)}
{and the "bt" parameter button is pressed. "bt" can recieve: "left","right"}
{and "middle".}


Implementation
Uses dos;

{ ------------------------------------------------------------------------- }

Procedure Show_Mouse_Cursor(show:boolean);
Var
r,hm,hn:word;
Begin
If (show=TRUE) Then
Begin
for hn:=0 to 15 do
for hm:=0 to 10 do
mask[hn,hm]:=getpixel(mx+hm,my+hn);
for hn:=0 to 15 do
for hm:=0 to 10 do
if seta[hn,hm]<>999 then
putpixel(mx+hm,my+hn,seta[hn,hm]);

allowed_int:=true;

End
Else
Begin
allowed_int:=false;

for hn:=0 to 15 do
for hm:=0 to 10 do
putpixel(mx+hm,my+hn,mask[hn,hm]);
End;
End;

{ ------------------------------------------------------------------------- }

procedure Set_Mouse_Speed(x_speed,y_speed:integer);
Var regs:registers;
begin
regs.ax:=15;
regs.cx:=x_speed;
regs.dx:=y_speed;
intr($33,regs);
end;

{ ------------------------------------------------------------------------- }

Procedure Set_Mouse_Position(mx,my:word);assembler;
Asm
mov ax,4
mov cx,mx
mov dx,my
int 33h
End;

{ ------------------------------------------------------------------------- }

Procedure Set_Mouse_Range(x1,y1,x2,y2:word);assembler;
Asm
mov ax,7
mov cx,x1
mov dx,x2
int 33h

mov ax,8
mov cx,y1
mov dx,y2
int 33h
End;

{ ------------------------------------------------------------------------- }

Function Is_Mouse_On(mx1,my1,mx2,my2:word):boolean;
Var but99,mx99,my99:word;
Begin
Is_Mouse_On:=false;
read_mouse_position(mx99,my99);
if (mx99>=mx1) and (mx99<=mx2) and (my99>=my1) and (my99<=my2) then
Is_Mouse_On:=true;
End;

{ ------------------------------------------------------------------------- }

Function Is_Mouse_Pressed_On(mx1,my1,mx2,my2:word; button:buttons):boolean;
Var mx99,my99:word;
bt:boolean;
Begin
Is_Mouse_Pressed_On:=false;
read_mouse_position(mx99,my99);
bt:=read_button_stat_point(button,mx99,my99);
if (mx99>=mx1) and (mx99<=mx2) and (my99>=my1) and (my99<=my2) and (bt) then
Is_Mouse_Pressed_On:=true;
End;

{ ------------------------------------------------------------------------- }

Procedure Read_Mouse_Position(Var x,y:word);
Var
regs:registers;
Begin
regs.ax:=3;
intr($33,regs);
x:=(regs.cx);
y:=(regs.dx);
End;

{ ------------------------------------------------------------------------- }

Function Read_Button_Stat(button:buttons):boolean;
Var
regs:registers;
Begin
regs.ax:=5;
if (button=left) then
regs.bx:=0
else
if (button=right) then
regs.bx:=1
else
regs.bx:=2;
intr($33,regs);
case button of left: Read_Button_Stat:=(regs.bx mod 2=1);
right: Read_Button_Stat:=(((regs.bx div 2) mod 2)=1);
middle: Read_Button_Stat:=((regs.bx div 2) div 2)=1;
end;
End;

{ ------------------------------------------------------------------------- }

Function Read_Button_Stat_point(button:buttons; mtx,mty:integer):boolean;
Var
regs:registers;
Begin
regs.ax:=5;
if (button=left) then
regs.bx:=0
else
if (button=right) then
regs.bx:=1
else
regs.bx:=2;
intr($33,regs);
case button of left: Read_Button_Stat_point:=(regs.bx mod 2=1) and (mtx=regs.cx) and (mty=regs.dx);
right: Read_Button_Stat_point:=(((regs.bx div 2) mod 2)=1) and (mtx=regs.cx) and (mty=regs.dx);
middle: Read_Button_Stat_point:=(((regs.bx div 2) div 2)=1) and (mtx=regs.cx) and (mty=regs.dx);
end;
End;

Procedure Wait_For_Mouse;
Var
x1,x2,y1,y2:word;
l1,l2,r1,r2,m1,m2:boolean;
Begin
Read_Mouse_Position(x1,y1);
l1:=Read_button_Stat(left);
r1:=Read_button_Stat(right);
m1:=Read_button_Stat(middle);
repeat
Read_Mouse_Position(x2,y2);
l2:=Read_button_Stat(left);
r2:=Read_button_Stat(right);
m2:=Read_button_Stat(middle);
until (x1<>x2) or (y1<>y2) or (l1<>l2) or (r1<>r2) or (m1<>m2);
End;

{ ------------------------------------------------------------------------- }

procedure new_mouse(Flags,CS,IP,AX,BX,CX,DX,SI,DI,DS,ES,BP : word);interrupt;
var hx,hy,hb,ev:word;
hn,hm:integer;

begin
if (allowed_int) then
begin
ev:=ax;
hb:=bx;
hx:=cx;
hy:=dx;

if ((hx<>mx) or (hy<>my)) then
begin
for hn:=0 to 15 do
for hm:=0 to 10 do
putpixel(mx+hm,my+hn,mask[hn,hm]);

for hn:=0 to 15 do
for hm:=0 to 10 do
mask[hn,hm]:=getpixel(hx+hm,hy+hn);

for hn:=0 to 15 do
for hm:=0 to 10 do
if seta[hn,hm]<>999 then
putpixel(hx+hm,hy+hn,seta[hn,hm]);

mx:=hx;
my:=hy;
end;

{inline ($8B/ $E5/ $5D/ $07/ $1F/ $5F/ $5E/ $5A/ $59/ $5B/ $58/ $CB);}
ASM
MOV SP,BP
POP BP
POP ES
POP DS
POP DI
POP SI
POP DX
POP CX
POP BX
POP AX
RETF
End;
end;
end;

Begin

newseg:=seg(new_mouse);
newofs:=ofs(new_mouse);
newmask:=1;

asm
mov ax,0
int $33
mov ax,20
mov cx,newmask
mov es,newseg
mov dx,newofs
int $33
end;

End.

{**********************************************************************}

Hope someone can help me fix this problem!!!!
Thanks to whomever answers me!!!!
Yair

Comments

  • Phat NatPhat Nat Posts: 757Member
    :
    : Hello to whomever is reading this message!!!!!
    : I recently found a mouse Unit on the NET, I used it, but I found a "bug" in it; If you have colors on the screen, such as a BMP picture, or anything else that has colors, when you move the mouse, suddenly colored pixels appear on the screen.......
    : Meanwhile I canged a few Procedures and Fumctions, Add a few of my own, but I was not successfull in fixing this bug.......
    :
    : Hope someone can help me fix this problem!!!!
    : Thanks to whomever answers me!!!!
    : Yair

    What do you mean, on the screen? I tried it and it seemed to work fine (although I had to modify it because I don't have the GRAPH BGI files installed). The cursor flashes the background colors, but that is normal for standard screens. If you want to get rid of the cursor flash, slow the refresh rate (add a delay() in) or else use Virtual Screens. If you are still stuck, write back or email me.

    Phat Nat

Sign In or Register to comment.