home *** CD-ROM | disk | FTP | other *** search
- #include "..\event\mouse.hpp"
- #include "..\game\game.hpp"
- #include "..\event\eventq.hpp"
- #include <dos.h>
-
- // ------------------------------------------------------------------
- // File: MOUSE.CPP
- // Path: ...\REHACK\EVENT\MOUSE.CPP
- // Version: 0.01
- // Author: Pat Reilly
- // CIS Id: 71333,2764
- // Created On: 6/26/93
- // Modified On:
- // Description: Mouse class for REHACK. See MOUSE.TXT for
- // more details.
- // Tabs: 4
- // ------------------------------------------------------------------
-
- bool Mouse::checked = false;
- bool Mouse::present = false;
- bool Mouse::installed = false;
- Event Mouse::curEvent;
- word Mouse::dblClickInterval = 8;
- dword Mouse::lastLBDown;
- dword Mouse::lastRBDown;
- dword Mouse::lastCBDown;
-
- Mouse::~Mouse()
- {
- remove();
- }
-
- bool Mouse::isPresent()
- {
- return checkFor();
- }
-
- bool Mouse::install()
- {
- if(checkFor() && !installed)
- {
- installed = true;
- getStatus(curEvent.posDevice);
- curEvent.setSystemTicks();
- curEvent.type = 0;
- lastLBDown = lastRBDown = lastCBDown = curEvent.ticks-dblClickInterval-40UL;
-
- word pseg = FP_SEG(Mouse::callbackFunction);
- word pofs = FP_OFF(Mouse::callbackFunction);
- asm {
- push es
- mov ax,12
- mov cx,0xFFFF
- mov es,pseg
- mov dx,pofs
- int 0x33
- pop es
- }
- return true;
- }
- else
- return false;
- }
-
- void Mouse::remove()
- {
- if(checkFor() && installed)
- {
- installed = false;
- _AX = 0;
- asm int 0x33;
- }
- }
-
- void Mouse::setBounds(const Rect& bounds)
- {
- if(checkFor())
- {
- // For 320x200
- _CX = bounds.topLeft.x*2;
- _DX = bounds.bottomRight.x*2;
- _AX = 7;
- asm int 0x33;
-
- _CX = bounds.topLeft.y;
- _DX = bounds.bottomRight.y;
- _AX = 8;
- asm int 0x33;
- }
- }
-
- void Mouse::show()
- {
- if(checkFor())
- {
- _AX = 1;
- asm int 0x33;
- }
- }
-
- void Mouse::hide()
- {
- if(checkFor())
- {
- _AX = 2;
- asm int 0x33;
- }
- }
-
- void Mouse::moveTo(const Point& pt)
- {
- if(checkFor())
- {
- _CX = pt.x*2;
- _DX = pt.y*2;
- _AX = 4;
- asm int 0x33;
- }
- }
-
- void Mouse::setCursor(const Point& pt, void* buf)
- {
- if(checkFor())
- {
- word pseg = FP_SEG(buf);
- word pofs = FP_OFF(buf);
- word x = pt.x;
- word y = pt.y;
- asm {
- push es
- mov ax,9
- mov cx,y
- mov bx,x
- mov es,pseg
- mov dx,pofs
- int 0x33
- pop es
- }
- }
- }
-
- void Mouse::setDblClickInterval(word w)
- {
- dblClickInterval = w;
- }
-
- void Mouse::getStatus(PosDeviceEvent& pd)
- {
- pd.buttons = 0;
- pd.dblClicked = false;
- pd.location.x = pd.location.y = -1;
-
- if(checkFor())
- {
- _AX = 3;
- asm int 0x33;
- pd.buttons = _BL;
- pd.location.x = _CX;
- pd.location.y = _DX;
- // For 320x200
- pd.location.x >>= 1;
- }
- }
-
- bool Mouse::checkFor()
- {
- if(!checked)
- {
- checked = true;
- if(getvect(0x33) != 0)
- {
- _AX = 0;
- asm int 0x33;
- present = bool(_AX != 0);
- }
- }
- return present;
- }
-
- const word
- cbfMove = 0x0001,
- cbfLBDown = 0x0002,
- cbfLBUp = 0x0004,
- cbfRBDown = 0x0008,
- cbfRBUp = 0x0010,
- cbfCBDown = 0x0020,
- cbfCBUp = 0x0040;
-
- #pragma saveregs
-
- void huge Mouse::callbackFunction()
- {
- word ax;
-
- ax = _AX;
-
- curEvent.posDevice.buttons = _BL;
- curEvent.posDevice.location.x = _CX;
- curEvent.posDevice.location.y = _DX;
- curEvent.posDevice.dblClicked = false;
- curEvent.type = 0;
- curEvent.setSystemTicks();
- // For 320x200
- curEvent.posDevice.location.x >>= 1;
-
- if(ax & cbfMove)
- curEvent.type |= PosDeviceMove;
- if(ax & (cbfLBDown | cbfRBDown | cbfCBDown))
- {
- curEvent.type |= PosDeviceBtnDown;
- if(ax & cbfLBDown)
- {
- if(curEvent.ticks-lastLBDown <= dblClickInterval)
- curEvent.posDevice.dblClicked = true;
- lastLBDown = curEvent.ticks;
- }
- else if(ax & cbfRBDown)
- {
- if(curEvent.ticks-lastRBDown <= dblClickInterval)
- curEvent.posDevice.dblClicked = true;
- lastRBDown = curEvent.ticks;
- }
- else
- {
- if(curEvent.ticks-lastCBDown <= dblClickInterval)
- curEvent.posDevice.dblClicked = true;
- lastCBDown = curEvent.ticks;
- }
- }
-
- if(ax & (cbfLBUp | cbfRBUp | cbfCBUp))
- curEvent.type |= PosDeviceBtnUp;
-
- Game::eventQueue.put(curEvent);
- }
-