home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / C / MPP400 / MOUSE.H < prev    next >
C/C++ Source or Header  |  1992-10-07  |  10KB  |  279 lines

  1. /* -------------------------------------------------------------------- */
  2. /* Mouse++ Version 4.0             mouse.h             Revised 10/05/92 */
  3. /*                                                                      */
  4. /* General mouse class for Turbo C++/Borland C++.                       */
  5. /* Copyright 1991, 1992 by Carl W. Moreland                             */
  6. /* -------------------------------------------------------------------- */
  7.  
  8. #ifndef MOUSEdotH
  9. #define MOUSEdotH
  10.  
  11. const unsigned char MOUSE_BUFFER_SIZE = 8;
  12.  
  13. const unsigned char LEFTBUTTON   = 1;    // mouse button assignments
  14. const unsigned char RIGHTBUTTON  = 2;
  15. const unsigned char CENTERBUTTON = 4;
  16.  
  17. const unsigned char CURSORSOFT = 0;    // used in struct TextCursor
  18. const unsigned char CURSORHARD = 1;
  19.  
  20. const unsigned char MOUSE_MOVED = 0x01;    // event masks for event handler
  21. const unsigned char LB_PRESSED  = 0x02;
  22. const unsigned char LB_RELEASED = 0x04;
  23. const unsigned char RB_PRESSED  = 0x08;
  24. const unsigned char RB_RELEASED = 0x10;
  25. const unsigned char CB_PRESSED  = 0x20;
  26. const unsigned char CB_RELEASED = 0x40;
  27.  
  28. const unsigned char LB_EVENT    = 0x06;
  29. const unsigned char RB_EVENT    = 0x18;
  30. const unsigned char CB_EVENT    = 0x60;
  31. const unsigned char MB_PRESSED  = 0x2A;
  32. const unsigned char MB_RELEASED = 0x54;
  33. const unsigned char MB_EVENT    = 0x7E;
  34.  
  35. const unsigned char SHIFT_PRESSED  = 0x08; // key shift masks
  36. const unsigned char RSHIFT_PRESSED = 0x10;
  37. const unsigned char LSHIFT_PRESSED = 0x20;
  38. const unsigned char CTRL_PRESSED   = 0x40;
  39. const unsigned char ALT_PRESSED    = 0x80;
  40.  
  41. #define EventExit() __emit__(0x5D,    /* pop bp */ \
  42.                  0x5F,    /* pop di */ \
  43.                              0x5E,    /* pop si */ \
  44.                              0x1F,    /* pop ds */ \
  45.                              0x07,    /* pop es */ \
  46.                              0x5A,    /* pop dx */ \
  47.                              0x59,    /* pop cx */ \
  48.                              0x5B,    /* pop bx */ \
  49.                              0x58,    /* pop ax */ \
  50.                              0xCB);    /* retf   */
  51.  
  52. class Mouse;
  53. void far interrupt MouseHandler(void);
  54.  
  55. /* -------------------------------------------------------------------- */
  56.  
  57. class TextCursor
  58. {
  59.   unsigned char type;            // hard or soft cursor
  60.   unsigned sMask, cMask;        // screen and cursor masks
  61.  
  62. public:
  63.   TextCursor(unsigned sMask, unsigned cMask, int type=0);
  64.   friend Mouse;
  65. };                    // see cursor.h for predefined cursors
  66.  
  67. /* -------------------------------------------------------------------- */
  68.  
  69. class GraphicsCursor
  70. {
  71.   unsigned char hotx, hoty;         // hot spot; (0,0) = top left corner
  72.   unsigned *cImage;                  // 16 x 16 pixel screen & cursor masks
  73.   unsigned char cWidth, cHeight;    // image dimensions in pixels
  74.   unsigned char cWords;            // cursor width (words)
  75.   unsigned char type;            // 0 = normal size, 1 = arbitrary size
  76.  
  77. public:
  78.   GraphicsCursor(unsigned char hotx, unsigned char hoty,
  79.                  unsigned image[],
  80.                  unsigned char width, unsigned char height,
  81.                  unsigned char type=0);
  82.   friend Mouse;
  83. };                    // see cursor.h for predefined cursors
  84.  
  85. /* -------------------------------------------------------------------- */
  86.  
  87. class ColorGraphicsCursor
  88. {
  89.   static void *tmpImage;        // temp storage for video
  90.   static int tmpImageSize;        // size of temp storage
  91.   static int x, y;            // current cursor location
  92.   static unsigned char *videoAddress;   // video location of image
  93.   static int  videoLeftMask,  videoRightMask;
  94.   static int screenLeftMask, screenRightMask;
  95.   static unsigned char xStart, yStart, xEnd, yEnd;
  96.   static unsigned char iWidth, iHeight;    // image dimensions (bytes*pixels)
  97.  
  98.   unsigned char hotx, hoty;         // hot spot; (0,0) = topleft corner
  99.   void *cImage;               // n x m pixel cursor mask
  100.   void *cMask;                // n x m pixel screen mask
  101.   unsigned char cWidth, cHeight;    // cursor dimensions (pixels)
  102.   unsigned char cBytes;            // cursor width (bytes)
  103.  
  104.   void Hide(void)
  105.   {
  106.     if(x == -1) return;
  107.     VideoWrite();
  108.   }
  109.   void Show(void)
  110.   {
  111.     if(x == -1) return;
  112.     VideoRead();
  113.     CursorWrite();
  114.   }
  115.   void Move(void)
  116.   {
  117.     if(x != -1) VideoWrite();
  118.     VideoRead();
  119.     CursorWrite();
  120.   }
  121.   void VideoRead(void);
  122.   void VideoWrite(void);
  123.   void CursorWrite(void);
  124.  
  125. public:
  126.   ColorGraphicsCursor(unsigned char hotx, unsigned char hoty,
  127.                       unsigned char image[],
  128.                       unsigned char width=16, unsigned char height=16);
  129.   friend Mouse;
  130. };                    // see cursor.h for predefined cursors
  131.  
  132. /* -------------------------------------------------------------------- */
  133.  
  134. class MouseEventHandler            // structure to store handlers
  135. {
  136.   unsigned char mask;            // event mask
  137.   unsigned segment, offset;        // address of event handler
  138.  
  139. public:
  140.   MouseEventHandler(void);
  141.   MouseEventHandler(unsigned char mask,
  142.                     void interrupt (*handler)(void) = MouseHandler);
  143.   void Install(void);
  144.  
  145.   friend Mouse;
  146. };
  147.  
  148. /* -------------------------------------------------------------------- */
  149.  
  150. struct MouseEvent
  151. {
  152.   unsigned char event;            // trigger event
  153.   unsigned char button;            // button status
  154.   unsigned x, y;            // cursor coordinates
  155.   unsigned xcount, ycount;        // mickeys moved since last event
  156.   unsigned long time;            // time event occurred
  157. };
  158.  
  159. class EventBuffer            // event buffer structure
  160. {
  161.   unsigned char headPtr;        // buffer pointer
  162.   unsigned char tailPtr;        // buffer pointer
  163.   MouseEvent buffer[MOUSE_BUFFER_SIZE];
  164.  
  165. public:
  166.   int  IsFull(void);
  167.   int  HasEvent(void);
  168.   void Clear(void);
  169.   void PutEvent(unsigned char event, unsigned char button,
  170.                 unsigned x, unsigned y,
  171.                 unsigned xcount, unsigned ycount,
  172.         unsigned long time);
  173.   MouseEvent GetEvent(void);
  174. };
  175.  
  176. class Mouse
  177. {
  178.   unsigned char exists;            // 1 if mouse found, 0 if not
  179.   unsigned char enabled;        // 1 if mouse enabled, 0 if not
  180.   unsigned char visible;        // keeps track of Hide() & Show()
  181.   unsigned char buttons;         // number of buttons
  182.   GraphicsCursor *gc;            // current graphics cursor
  183.   ColorGraphicsCursor *cgc;        // current color graphics cursor
  184.   unsigned char cgcActive;        // color graphics cursor flag
  185.  
  186.   MouseEvent current;            // current event info
  187.   EventBuffer buffer;            // event buffer
  188.   MouseEventHandler oldHandler;        // handler found at start-up
  189.   MouseEventHandler currentHandler;    // current event handler
  190.   unsigned char handlerInstalled;    // event handler flag
  191.   unsigned char handlerActive;        // event handler active flag
  192.  
  193.   struct MouseClick            // MultiClick/Repeater structure
  194.   {
  195.     unsigned char count;        // number of clicks
  196.     unsigned long time;            // time of last click
  197.   } Click[3], Repeat[3];
  198.  
  199.   unsigned clickThreshold;        // MultiClick threshold
  200.   unsigned char repeatMask;        // button mask for Repeater
  201.   unsigned repeatDelay;            // delay time for Repeater
  202.   unsigned repeatRate;            // repeat rate for Repeater
  203.  
  204.   friend EventBuffer;
  205.  
  206. public:
  207.   Mouse(void);
  208.  ~Mouse(void);
  209.  
  210.   unsigned char Exists()  { return exists;  }
  211.   unsigned char Visible() { return visible; }
  212.   unsigned char Buttons() { return buttons; }
  213.  
  214.   int  x()              { return current.x; }
  215.   int  y()           { return current.y; }
  216.   int  xPos()          { return current.x; }
  217.   int  yPos()           { return current.y; }
  218.   int  xCount()        { return current.xcount; }
  219.   int  yCount()        { return current.ycount; }
  220.   unsigned char Button()  { return current.button; }
  221.   unsigned char LB_Dn()   { return (0x01 & current.button); }
  222.   unsigned char RB_Dn()   { return (0x02 & current.button); }
  223.   unsigned char CB_Dn()   { return (0x04 & current.button); }
  224.   unsigned char Event()   { return current.event; }
  225.  
  226.   void Enable(void);
  227.   void Disable(void);
  228.   void Show(void);
  229.   void Hide(void);
  230.   void Move(int x, int y);
  231.   void Position(void);
  232.   void Motion(void);
  233.   int  Pressed(int button);
  234.   int  Released(int button);
  235.   int  InBox(int left, int top, int right, int bottom);
  236.   void Exclude(int left, int top, int right, int bottom);
  237.   int  MultiClick(int button);
  238.   int  DoubleClick(int button);
  239.   void ClearClick(int button = 7);
  240.  
  241.   void xLimit(int min, int max);
  242.   void yLimit(int min, int max);
  243.   void xyLimit(int xmin, int xmax, int ymin, int ymax);
  244.   void MickToPix(int horiz, int vert);
  245.   int  GetVideoPage(void);
  246.   void SetVideoPage(int page);
  247.  
  248.   void SetCursor(TextCursor& cursor);
  249.   void SetCursor(GraphicsCursor& cursor);
  250.   void SetCursor(ColorGraphicsCursor& cursor);
  251.  
  252.   void SetSpeedThreshold(unsigned speed);
  253.   void SetClickThreshold(unsigned time);
  254.   void SetRepeatRate(unsigned char button=LEFTBUTTON,
  255.                      unsigned delay=250, unsigned rate=150);
  256.   void Repeater(void);
  257.  
  258.   void InstallHandler(void);
  259.   void InstallHandler(unsigned char mask,
  260.                       void interrupt (*handler)(void) = MouseHandler);
  261.   void InstallHandler(MouseEventHandler& handler);
  262.   void ClearHandler(void);
  263.   void Save(int event, int button, int x, int y, int xcount, int ycount);
  264.   void GetEvent(void);
  265.   void ClearEvent(void);
  266.   void ClearBuffer(void);
  267.  
  268.   struct MouseInfo        // structure to store mouse data
  269.   {
  270.     unsigned char type;        // bus=1, serial=2, InPort=3, PS/2=4, HP=5
  271.     unsigned char majorvers;    // software major version
  272.     unsigned char minorvers;    // software minor version
  273.     unsigned char irq;        // IRQ used (2-7), 0 for PS/2
  274.   } Info;
  275. };
  276.  
  277. extern Mouse mouse;
  278.  
  279. #endif