home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK4 / SAMPLES / CPPTUTOR / OOD / EVENT.CP$ / EVENT
Encoding:
Text File  |  1991-11-06  |  2.2 KB  |  104 lines

  1. /*********************************************************************
  2.  
  3.  FILE: EVENT.CPP
  4.  
  5. *********************************************************************/
  6.  
  7. #include "event.h"
  8.  
  9. #include <conio.h>
  10. #include <dos.h>
  11.  
  12. /*********************************************************************
  13.  
  14.  EventGenerator::EventGenerator
  15.  
  16. *********************************************************************/
  17.  
  18. EventGenerator::EventGenerator()
  19. {
  20.     lastStatus.position = Point(10,10);
  21.     lastStatus.button = 0;
  22. }
  23.  
  24. /*********************************************************************
  25.  
  26.  EventGenerator::~EventGenerator
  27.  
  28. *********************************************************************/
  29.  
  30. EventGenerator::~EventGenerator()
  31. {
  32. }
  33.  
  34.  
  35. /*********************************************************************
  36.  
  37.  EventGenerator::getMouseEvent
  38.  
  39. *********************************************************************/
  40.  
  41. MouseEvent *EventGenerator::getMouseEvent()
  42. {
  43.     MouseStatus status;
  44.  
  45.     if( !theMouse.read( &status ) )
  46.         return 0;
  47.  
  48.     if( status.button == lastStatus.button )
  49.     {
  50.         return 0;
  51.     }
  52.     else
  53.     {
  54.         lastStatus = status;
  55.  
  56.         if( status.button != 0 )
  57.         {
  58. //          lastStatus.position.x = (lastStatus.position.x >> 3) + 1;
  59. //          lastStatus.position.y = (lastStatus.position.y >> 3) + 1;
  60.             return new MouseEvent( lastStatus.position,
  61.                                    lastStatus.button );
  62.         }
  63.         else
  64.             return 0;
  65.     }
  66. }
  67.  
  68.  
  69. /*********************************************************************
  70.  
  71.  EventGenerator::getNextEvent
  72.  
  73. *********************************************************************/
  74.  
  75. Event *EventGenerator::getNextEvent()
  76. {
  77.     Event *temp;
  78.  
  79.     char ch1,
  80.          ch2;
  81.  
  82.     theMouse.show();
  83.  
  84.     if( kbhit() )
  85.     {
  86.         ch1 = getch();
  87.         if( ch1 == 0)   // extended key pressed
  88.         {
  89.             ch2 = getch();
  90.             return new KbdEvent(ch1, ch2);
  91.         }
  92.         else
  93.             return new KbdEvent(ch1, 0);
  94.     }
  95.     else if( (temp = getMouseEvent()) != 0 )
  96.     {
  97.         return temp;
  98.     }
  99.     else
  100.     {
  101.         return 0;
  102.     }
  103. }
  104.