⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mouse.cpp

📁 这是一个C++编程文档
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* -------------------------------------------------------------------- */
/* Mouse++ Version 4.0            mouse.cpp            Revised 10/05/92 */
/*                                                                      */
/* General mouse class for Turbo C++/Borland C++.                       */
/* Copyright 1991, 1992 by Carl W. Moreland                             */
/* -------------------------------------------------------------------- */

#include <dos.h>
#include "mouse.h"

Mouse mouse;
void interrupt RepeatHandler(...);
void interrupt far (*oldInterrupt_1C)(...);

/* -------------------------------------------------------------------- */

Mouse::Mouse(void)			// reset mouse - constructor
{
  int found;
  unsigned seg, off;

  exists  = 0;				// initialize everything
  enabled = 0;
  visible = 0;
  current.button = 0;
  current.x      = 0;
  current.y      = 0;
  current.xcount = 0;
  current.ycount = 0;
  clickThreshold = 250;
  repeatDelay    = 1000;
  repeatRate     = 200;
  handlerInstalled = 0;
  handlerActive = 0;
  current.event = 0x00;
  buffer.Clear();

  _AX = 0x00;				// check for the existance of
  geninterrupt(0x33);			//   a mouse
  found   = _AX;
  buttons = _BX;			// also returns # of buttons

  if(found)
    exists = 1;
  if(!exists) return;

  _ES = 0;
  _DX = 0;
  _CX = 0;				// clear the event handler
  _AX = 0x14;
  geninterrupt(0x33);
  oldHandler.mask    = _CX;		// save the old event handler
  off = _DX;
  seg = _ES;
  oldHandler.offset  = off;
  oldHandler.segment = seg;

  _AX = 0x24;				// get some mouse info
  geninterrupt(0x33);
  Info.majorvers = _BH;
  Info.minorvers = _BL;
  Info.type      = _CH;
  Info.irq       = _CL;

  oldInterrupt_1C = getvect(0x1C);
  setvect(0x1C, RepeatHandler);
}

Mouse::~Mouse(void)			// restore mouse - destructor
{
  if(!exists) return;

  _AX = 0x00;				// reset mouse
  geninterrupt(0x33);

  if(oldHandler.mask)			// restore old event handler
    InstallHandler(oldHandler);

  setvect(0x1C, oldInterrupt_1C);
}

void Mouse::Enable(void)		// enable the mouse
{
  if(!exists || enabled) return;

  if(currentHandler.mask && !handlerInstalled)
    InstallHandler();			// re-install event handler

  enabled = 1;
}

void Mouse::Disable(void)		// disable the mouse
{
  if(!exists || !enabled) return;

  if(handlerInstalled)
  {
    ClearHandler();			// disable the event handler
    ClearClick();			// clear the multi-click buffers
  }
  Hide();				// turn the cursor off
  enabled = 0;
}

void Mouse::Show(void)		    	// show mouse cursor
{
  if(!exists || !enabled) return;
  if(visible) return;

  if(cgcActive)
    cgc->Show();
  else
  {
    _AX = 0x01;
    geninterrupt(0x33);
  }
  visible = 1;
}

void Mouse::Hide(void)			// hide mouse cursor
{
  if(!exists || !enabled) return;
  if(visible < 1) return;

  if(cgcActive)
    cgc->Hide();
  else
  {
    _AX = 0x02;
    geninterrupt(0x33);
  }
  visible = 0;
}

void Mouse::Move(int x, int y)		// move cursor to col, row
{					// col & row are pixel coordinates
  if(!exists || !enabled) return;

  _DX = y;
  _CX = x;
  _AX = 0x04;
  geninterrupt(0x33);
}

void Mouse::xLimit(int min, int max)	// set min/max column range
{					// min & max are pixel coordinates
  if(!exists) return;

  _DX = max;
  _CX = min;
  _AX = 0x07;
  geninterrupt(0x33);
}

void Mouse::yLimit(int min, int max)	// set min/max row range
{					// min & max are pixel coordinates
  if(!exists) return;

  _DX = max;
  _CX = min;
  _AX = 0x08;
  geninterrupt(0x33);
}

void Mouse::xyLimit(int xmin, int xmax, int ymin, int ymax)
{
  xLimit(xmin, xmax);
  yLimit(ymin, ymax);
}

int Mouse::GetVideoPage(void)		// get the cursor's display page
{
  if(!exists) return 0;

  _AX = 0x1E;
  geninterrupt(0x33);
  return _BX;
}

void Mouse::SetVideoPage(int page)	// set the cursor's display page
{
  if(!exists) return;

  _BX = page;
  _AX = 0x1D;
  geninterrupt(0x33);
}

void Mouse::MickToPix(int horiz, int vert)
{                 			// set the mickey to pixel ratio
  if(!exists) return;

  _DX = vert;
  _CX = horiz;
  _AX = 0x0F;
  geninterrupt(0x33);
}

void Mouse::SetSpeedThreshold(unsigned speed)
{					// set speed change threshold
  if(!exists) return;

  _DX = speed;
  _AX = 0x13;
  geninterrupt(0x33);
}

void Mouse::SetCursor(TextCursor& cursor)
{					// change the text cursor
  int wasVisible = 0;

  if(!exists) return;
  if(visible)
  {
    wasVisible = 1;
    Hide();
  }

  _DX = cursor.cMask;
  _CX = cursor.sMask;
  _BX = cursor.type;
  _AX = 0x0A;
  geninterrupt(0x33);
  cgcActive = 0;

  if(wasVisible)
    Show();
}

void Mouse::SetCursor(GraphicsCursor& cursor)
{					// change the graphics cursor
  int wasVisible = 0;

  if(!exists) return;
  if(visible)
  {
    wasVisible = 1;
    Hide();
  }

  if(cursor.type == 0)			// std 16x16 cursor
  {
    _ES = FP_SEG(cursor.cImage);
    _DX = FP_OFF(cursor.cImage);
    _CX = cursor.hoty;
    _BX = cursor.hotx;
    _AX = 0x09;
    geninterrupt(0x33);
  }
  else					// arbitrary cursor size
  {
    _ES = FP_SEG(cursor.cImage);
    _DX = FP_OFF(cursor.cImage);
    _CH = cursor.cHeight;
    _CL = cursor.hoty;
    _BH = cursor.cWords;
    _BL = cursor.hotx;
    _AX = 0x12;
    geninterrupt(0x33);
  }

  gc   = &cursor;
  cgcActive = 0;

  if(handlerInstalled)			// reinstall the current handler
    InstallHandler();

  if(wasVisible)
    Show();
}

void Mouse::SetCursor(ColorGraphicsCursor& cursor)
{
  int wasVisible = 0;

  if(!exists) return;
  if(visible)
  {
    wasVisible = 1;
    Hide();
  }

  cgc  = &cursor;
  cgcActive = 1;

  if(handlerInstalled)			// reinstall the current handler
    InstallHandler();

  if(wasVisible)			// need to get the current coords
  {
    _AX = 0x03;
    geninterrupt(0x33);
    cursor.x = _CX;
    cursor.y = _DX;
    Show();
  }
}

void Mouse::Position(void)		// update cursor position &
{					// button status
  if(!exists || !enabled) return;

  _AX = 0x03;
  geninterrupt(0x33);
  current.button = _BX;
  current.x = _CX;
  current.y = _DX;
}

int Mouse::Pressed(int button)		// check press status of button
{
  if(!exists || !enabled) return(0);

  if(handlerInstalled)
  {
    if(button == LEFTBUTTON)
      return(current.event & LB_PRESSED);
    else if(button == RIGHTBUTTON)
      return(current.event & RB_PRESSED);
    else if(button == CENTERBUTTON)
      return(current.event & CB_PRESSED);
  }

  _BX = button;
  _AX = 0x05;
  geninterrupt(0x33);
  current.button = _AX;
  int BX = _BX;
  if(BX)
  {
    current.x = _CX;
    current.y = _DX;
  }
  return(BX);
}

int Mouse::Released(int button)		// check release status of button
{
  if(!exists || !enabled) return(0);

  if(handlerInstalled)
  {
    if(button == LEFTBUTTON)
      return(current.event & LB_RELEASED);
    else if(button == RIGHTBUTTON)
      return(current.event & RB_RELEASED);
    else if(button == CENTERBUTTON)
      return(current.event & CB_RELEASED);
  }

  _AX = 0x06;
  _BX = button;
  geninterrupt(0x33);
  current.button = _AX;
  int BX = _BX;
  if(BX)
  {
    current.x = _CX;
    current.y = _DX;
  }
  return(BX);
}

void Mouse::Motion(void)		// get # of mickeys moved
{
  if(!exists || !enabled) return;

  _AX = 0x0B;
  geninterrupt(0x33);
  current.xcount = _CX;
  current.ycount = _DX;
}

int Mouse::InBox(int left,  int top,	// see if mouse is in a box
                 int right, int bottom)
{
  if(!exists || !enabled) return(0);

  if((current.x >= left)  && (current.y >= top) &&
     (current.x <= right) && (current.y <= bottom))
    return(1);
  return(0);
}

void Mouse::Exclude(int left,  int top,	// set up exclusion area
                    int right, int bottom)
{
  static unsigned char hotx, hoty, height, width;

  if(!exists || !enabled) return;

  if(cgcActive)
  {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -