home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / ZINC_6.ZIP / DOSSRC.ZIP / CURSOR.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-01  |  4.6 KB  |  193 lines

  1. //    Program name..    Zinc Interface Library
  2. //    Filename......    CURSOR.CPP
  3. //    Version.......    1.0
  4. //    
  5. //    COPYRIGHT (C) 1990.  All Rights Reserved.
  6. //    Zinc Software Incorporated.  Pleasant Grove, Utah  USA
  7.  
  8. #include "ui_evt.hpp"
  9.  
  10. static void VideoInt(void)
  11. {
  12.     asm        push    bp                // Save BP
  13.     asm        int        10H                // because INT 10H may clobber it
  14.     asm        pop        bp                // due to bug in older BIOS versions
  15. }
  16.  
  17. // ----- Constructor & Destructor -------------------------------------------
  18.  
  19. UI_CURSOR::UI_CURSOR(USHORT initialState) :
  20.     UI_DEVICE(E_CURSOR, initialState)
  21. {
  22.     /* Initialize the cursor device */
  23.     lastTime = *((USHORT far *)0x46CL);
  24.     cursorMask = DC_INSERT;
  25.     blink = (initialState == D_OFF) ? FALSE : TRUE;
  26.     line = column = 0;
  27.     installed = TRUE;
  28. }
  29.  
  30. // ----- Member functions ---------------------------------------------------
  31.  
  32. void UI_CURSOR::Display(USHORT displayCursorMask, USHORT displayState)
  33. {
  34.     if (!display)
  35.         return;
  36.     else if (display->isText)
  37.     {
  38.         _CX = (displayState == D_OFF || displayState == D_HIDE) ?
  39.             display->offCursorValue : display->onCursorValue;
  40.         if (displayState != D_OFF && displayCursorMask == DC_INSERT)
  41.             _CH = 0;
  42.         _AH = 1;
  43.         VideoInt();
  44.     }
  45.     else if (displayState != D_OFF && displayState != D_HIDE)
  46.     {
  47.         UI_REGION region;
  48.         region.left = column;
  49.         region.top = (displayCursorMask == DC_INSERT) ? line : line + 7;
  50.         region.right = column + 7;
  51.         region.bottom = (displayCursorMask == DC_INSERT) ? line + 6 : line + 8;
  52.         display->Rectangle(ID_SCREEN, region, _xorPalette, 1, TRUE, TRUE);
  53.     }
  54. }
  55.  
  56. int UI_CURSOR::Event(const UI_EVENT &event)
  57. {
  58.     if (state == DC_INVALID)
  59.         return (state);
  60.  
  61.     /* Switch on the rawCode */
  62.     USHORT ccode = event.rawCode;
  63.     USHORT t_cursorMask = cursorMask;
  64.     USHORT t_state = state;
  65.     switch (ccode)
  66.     {
  67.     case D_HIDE:
  68.     case D_SHOW:
  69.         if (state == D_OFF)
  70.             return (state);
  71.         UI_REGION region;
  72.         if (display->isText)
  73.         {
  74.             region.left = region.right = column;
  75.             region.top = region.bottom = line;
  76.         }
  77.         else
  78.         {
  79.             region.left = column;
  80.             region.top = (cursorMask == DC_INSERT) ? line : line + 7;
  81.             region.right = column + 7;
  82.             region.bottom = (cursorMask == DC_INSERT) ? line + 6 : line + 8;
  83.         }
  84.          if (Max(event.region.left, region.left) > Min(event.region.right, region.right) ||
  85.             Max(event.region.top, region.top) > Min(event.region.bottom, region.bottom))
  86.             return(0);
  87.         state = (ccode == D_HIDE) ? D_HIDE : D_ON;
  88.         blink = (ccode == D_HIDE) ? FALSE : TRUE;
  89.         break;
  90.  
  91.     case DC_BLINK:
  92.         state = (state == D_ON) ? D_OFF : D_ON;
  93.         break;
  94.  
  95.     case DC_INSERT:
  96.     case DC_OVERTYPE:
  97.     case DC_INSERT_OFF:
  98.     case DC_OVERTYPE_OFF:
  99.     case D_OFF:
  100.     case D_ON:
  101.         if (ccode == DC_INSERT_OFF || ccode == DC_INSERT)
  102.             cursorMask = DC_INSERT;
  103.         else if (ccode == DC_OVERTYPE_OFF || ccode == DC_OVERTYPE)
  104.             cursorMask = DC_OVERTYPE;
  105.         if ( ccode == D_OFF ||
  106.             (!display->isText && (ccode == DC_INSERT_OFF || ccode == DC_OVERTYPE_OFF) ) )
  107.             state = D_OFF;
  108.         else
  109.             state = D_ON;
  110.         blink = (ccode == D_OFF) ? FALSE : TRUE;
  111.         lastTime = *((USHORT far *)0x46CL);        // Reset blink count
  112.         break;
  113.  
  114.     case D_INITIALIZE:
  115.         t_state = (display->isText) ? D_ON : D_OFF;
  116.         if (display->isText)        // Change the cursor position.
  117.         {
  118.             _BH = 0;
  119.             _DH = line;
  120.             _DL = column;
  121.             _AH = 2;
  122.             VideoInt();
  123.         }
  124.         break;
  125.  
  126.     case D_POSITION:
  127.         if (event.position.line == line && event.position.column == column)
  128.             return (state);
  129.         if (!display->isText && state != D_OFF)
  130.         {
  131.             Display(cursorMask, state);
  132.             t_state = D_OFF;
  133.         }
  134.         line = event.position.line;
  135.         column = event.position.column;
  136.         if (display->isText)
  137.         {
  138.             _BH = 0;
  139.             _DH = line;
  140.             _DL = column;
  141.             _AH = 2;
  142.             VideoInt();
  143.         }
  144.         break;
  145.  
  146.     default:
  147.         return (state);
  148.     }
  149.  
  150.     /* Change the cursor state */
  151.     if (t_cursorMask != cursorMask || t_state != state)
  152.     {
  153.         USHORT t2_state = state;
  154.         state = DC_INVALID;
  155.         UI_REGION region;
  156.         if (display->isText)
  157.         {
  158.             region.left = region.right = column;
  159.             region.top = region.bottom = line;
  160.         }
  161.         else
  162.         {
  163.             region.left = column - 1;
  164.             region.top = line;
  165.             region.right = column + 7;
  166.             region.bottom = line + 7;
  167.         }
  168.         eventManager->DevicesHide(region);
  169.         if (!display->isText)
  170.             Display(t_cursorMask, t_state);
  171.         Display(cursorMask, t2_state);
  172.         eventManager->DevicesShow(region);
  173.         state = t2_state;
  174.     }
  175.  
  176.     /* Return the device state */
  177.     return (state);
  178. }
  179.  
  180. void UI_CURSOR::Poll(void)
  181. {
  182.     /* Check the state and time of the cursor */
  183.     USHORT currentTime = *((USHORT far *)0x46CL);
  184.     if (!display->isText && blink && currentTime - lastTime > 6)
  185.     {
  186.         UI_EVENT t_event;
  187.         t_event.rawCode = DC_BLINK;
  188.         Event(t_event);
  189.         lastTime = currentTime;
  190.     }
  191. }
  192.  
  193.