home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / pascal / rehack / event / event.hpp next >
Encoding:
C/C++ Source or Header  |  1993-06-27  |  2.7 KB  |  149 lines

  1. #ifndef _EVENT_HPP
  2. #define _EVENT_HPP
  3.  
  4. // ------------------------------------------------------------------
  5. // File:        EVENT.HPP
  6. // Path:        ...\REHACK\EVENT\EVENT.HPP
  7. // Version:        0.01
  8. // Author:        Pat Reilly
  9. // CIS Id:        71333,2764
  10. // Created On:    6/18/93
  11. // Modified On:    6/25/93
  12. // Description:    Event class for REHACK. See EVENT.TXT for
  13. //                more details.
  14. // Tabs:        4
  15. // ------------------------------------------------------------------
  16.  
  17. #ifndef _MISC_HPP
  18. #include "..\GENERAL\MISC.HPP"
  19. #endif
  20.  
  21. // Constance used by PosDeviceEvent class for designating buttons.
  22.  
  23. const byte
  24.     LeftBtn        = 1,
  25.     RightBtn    = 2,
  26.     CenterBtn    = 4;
  27.  
  28. // Class PosDeviceEvent
  29.  
  30. struct PosDeviceEvent
  31. {
  32.     byte buttons;        // Bits: LeftBtn, RightBtn, CenterBtn.
  33.     bool dblClicked;    // True if a button event and a double click.
  34.     Point location;        // XY position at the time of the event.
  35. };
  36.  
  37. // Class KeyCode
  38.  
  39. struct KeyCode
  40. {
  41.     byte code;        // character code of the key.
  42.     byte scan;        // scan code of the key.
  43. };
  44.  
  45. // Class KeyEvent
  46.  
  47. struct KeyEvent
  48. {
  49.     union
  50.     {
  51.         word    value;            // 16-bit key value.
  52.         KeyCode charScanValue;    // KeyCode value.
  53.     };
  54. };
  55.  
  56. // Class MsgEvent
  57.  
  58. struct MsgEvent
  59. {
  60.     word id;                    // message identifier.
  61.     union
  62.     {
  63.         void* pointerValue;        // Extra info as a generic pointer.
  64.         long  longValue;        // Extra info as a long value.
  65.         short shortValue;        // Extra info as a short value.
  66.         Point pointValue;        // Extra info as a point value.
  67.     };
  68. };
  69.  
  70. // Some standard message id's.
  71. const word
  72.     IdNull        = 0,
  73.     IdCancel    = 1,
  74.     IdQuit        = 2;
  75.  
  76.  
  77. const word
  78.     PosDeviceBtnDown    = 0x0001,
  79.     PosDeviceBtnUp        = 0x0002,
  80.     PosDeviceMove        = 0x0004,
  81.     PosDevice            = 0x000F,
  82.  
  83.     KeyDown                = 0x0010,
  84.     KeyUp                = 0x0020,
  85.     Key                    = 0x0030,
  86.  
  87.     Broadcast            = 0x8000,
  88.     Message                = 0xFF00;
  89.  
  90. // Class Event
  91.  
  92. struct Event
  93. {
  94.     word  type;
  95.     dword ticks;
  96.     union
  97.     {
  98.         PosDeviceEvent posDevice;
  99.         KeyEvent       key;
  100.         MsgEvent       msg;
  101.     };
  102.  
  103.     bool isNull() const;
  104.     bool isPositional() const;
  105.     bool isFocused() const;
  106.     bool isBroadcast() const;
  107.     bool isMessage() const;
  108.     void clear();
  109.     void setSystemTicks();
  110. };
  111.  
  112. inline bool Event::isNull() const
  113. {
  114.     return bool(type == 0);
  115. }
  116.  
  117. inline bool Event::isPositional() const
  118. {
  119.     return bool((type & PosDevice) != 0);
  120. }
  121.  
  122. inline bool Event::isFocused() const
  123. {
  124.     return bool((type & (Key|Message) & ~Broadcast) != 0);
  125. }
  126.  
  127. inline bool Event::isBroadcast() const
  128. {
  129.     return bool((type & Broadcast) != 0);
  130. }
  131.  
  132. inline bool Event::isMessage() const
  133. {
  134.     return bool((type & Message) != 0);
  135. }
  136.  
  137. inline void Event::clear()
  138. {
  139.     type = 0;
  140. }
  141.  
  142. inline void Event::setSystemTicks()
  143. {
  144.     // Does this work with MSC++? It is certainly PC-only code...
  145.     ticks = *( (dword FAR *)(0x046CUL) );
  146. }
  147.  
  148. #endif    // _EVENT_HPP
  149.