OMOUSE.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * Seven Kingdoms: Ancient Adversaries
  3. *
  4. * Copyright 1997,1998 Enlight Software Ltd.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. //Filename : OMOUSE.H
  21. //Description : Header file for Mouse Handling Object (OMOUSE.CPP)
  22. #ifndef __OMOUSE_H
  23. #define __OMOUSE_H
  24. #ifndef __ALL_H
  25. #include <ALL.h>
  26. #endif
  27. #define DIRECTINPUT_VERSION 0x300
  28. #include <dinput.h>
  29. //-------- Define macro constant --------//
  30. //
  31. // Button id, for Mouse internal use only,
  32. // not appeal to mouse driver parameters
  33. //
  34. //---------------------------------------//
  35. // event_type
  36. enum MouseEventType
  37. {
  38. LEFT_BUTTON = 0,
  39. RIGHT_BUTTON = LEFT_BUTTON+1,
  40. KEY_PRESS = 2,
  41. LEFT_BUTTON_RELEASE = 4,
  42. RIGHT_BUTTON_RELEASE = LEFT_BUTTON_RELEASE+1,
  43. KEY_RELEASE = 6,
  44. };
  45. #define LEFT_BUTTON_MASK 1
  46. #define RIGHT_BUTTON_MASK 2
  47. // bit flag of any skey_state, event_skey_state
  48. #define LEFT_SHIFT_KEY_MASK 0x001
  49. #define RIGHT_SHIFT_KEY_MASK 0x002
  50. #define SHIFT_KEY_MASK 0x003
  51. #define LEFT_CONTROL_KEY_MASK 0x004
  52. #define RIGHT_CONTROL_KEY_MASK 0x008
  53. #define CONTROL_KEY_MASK 0x00c
  54. #define LEFT_ALT_KEY_MASK 0x010
  55. #define RIGHT_ALT_KEY_MASK 0x020
  56. #define ALT_KEY_MASK 0x030
  57. #define NUM_LOCK_STATE_MASK 0x040
  58. #define CAP_LOCK_STATE_MASK 0x080
  59. #define SCROLL_LOCK_STATE_MASK 0x100
  60. #define INSERT_STATE_MASK 0x200
  61. #define GRAPH_KEY_MASK 0x400
  62. //----- Define the upper limit for mouse coordination ------//
  63. #define MOUSE_X_UPPER_LIMIT (VGA_WIDTH-5)
  64. #define MOUSE_Y_UPPER_LIMIT (VGA_HEIGHT-5)
  65. //------ Default settting ---------//
  66. #define DEFAULT_DOUBLE_SPEED_THRESHOLD 8
  67. #define DEFAULT_TRIPLE_SPEED_THRESHOLD 16
  68. //-------- Define struct MouseClick -------//
  69. struct MouseClick // MultiClick buffer structure
  70. {
  71. int x, y;
  72. int release_x, release_y; // where mouse is release
  73. int count; // number of clicks
  74. DWORD time; // time of last click
  75. DWORD release_time; // time of last release
  76. };
  77. //------- Define struct MouseEvent --------//
  78. /*
  79. struct MouseEvent // event buffer structure
  80. {
  81. int state; // mouse state
  82. int x, y; // cursor coordinates
  83. DWORD time; // time event occurred
  84. unsigned scan_code; // if scan_code>0 then it's a key press event
  85. unsigned short skey_state; // speical key state, such as LEFT_SHIFT_KEY_MASK ...
  86. };
  87. */
  88. struct MouseEvent // event buffer structure
  89. {
  90. MouseEventType event_type; // mouse state
  91. DWORD time; // time event occurred
  92. unsigned short skey_state; // speical key state, such as LEFT_SHIFT_KEY_MASK ...
  93. // int state; // state mask of mouse button
  94. int x, y; // mousecursor coordinates
  95. unsigned scan_code; // if scan_code>0 then it's a key press event
  96. };
  97. //--------- Define class Mouse ------------//
  98. class Mouse
  99. {
  100. public:
  101. char init_flag;
  102. char handle_flicking;
  103. char* vga_update_buf;
  104. HHOOK key_hook_handle;
  105. // HANDLE direct_mouse_handle;
  106. LPDIRECTINPUT direct_input;
  107. LPDIRECTINPUTDEVICE di_mouse_device, di_keyb_device;
  108. //------- real-time mouse state -------//
  109. int cur_x, cur_y;
  110. int left_press, right_press;
  111. //------- real-time keyboard state ---------//
  112. unsigned short skey_state; // such as LEFT_SHIFT_KEY_MASK
  113. //------- boundary of mouse cursor hot spot --------//
  114. int bound_x1;
  115. int bound_y1;
  116. int bound_x2;
  117. int bound_y2;
  118. // ------ mouse setting ---------- //
  119. int double_speed_threshold; // default DEFAULT_DOUBLE_SPEED_THRESHOLD
  120. int triple_speed_threshold; // default DEFAULT_TRIPLE_SPEED_THRESHOLD
  121. //-------- click & key buffer ---------//
  122. unsigned short event_skey_state;
  123. char has_mouse_event; // if has_mouse_event, mouse_event_type is valid
  124. MouseEventType mouse_event_type;
  125. MouseClick click_buffer[2]; // left button & right button only
  126. // use : LEFT_BUTTON=0, RIGHT_BUTTON=1
  127. unsigned scan_code; // key pressed, keyboard event
  128. unsigned key_code; // converted from scan_code and event_skey_state
  129. //-------- event buffer ---------//
  130. enum { EVENT_BUFFER_SIZE = 20 }; // No. of events can be stored in buffer
  131. MouseEvent event_buffer[EVENT_BUFFER_SIZE];
  132. int head_ptr; // head pointer to the event buffer
  133. int tail_ptr; // tail pointer to the event buffer
  134. public:
  135. Mouse();
  136. ~Mouse();
  137. void init(HINSTANCE, HWND, LPDIRECTINPUT createdDirectInput=0);
  138. void deinit();
  139. void add_event(MouseEvent *);
  140. void add_key_event(unsigned, DWORD);
  141. int get_event();
  142. void poll_event();
  143. // #### begin Gilbert 31/10 #########//
  144. void update_skey_state();
  145. // #### end Gilbert 31/10 #########//
  146. void show();
  147. void hide();
  148. void hide_area(int,int,int,int);
  149. void show_area();
  150. //--- functions for real-time mouse state accessing ---//
  151. int in_area(int,int,int,int);
  152. int press_area(int,int,int,int,int=0);
  153. int wait_press(int timeOutSecond=0);
  154. //---- functions of mouse cursor boundary ------//
  155. void set_boundary(int, int, int, int);
  156. void reset_boundary();
  157. //----- functions for queue event accessing ----//
  158. int single_click(int,int,int,int,int=0);
  159. int double_click(int,int,int,int,int=0);
  160. int any_click (int,int,int,int,int=0);
  161. int any_click(int=0);
  162. int release_click(int,int,int,int,int=0);
  163. int click_x(int buttonId=0) { return click_buffer[buttonId].x; }
  164. int click_y(int buttonId=0) { return click_buffer[buttonId].y; }
  165. int release_x(int buttonId=0) { return click_buffer[buttonId].release_x; }
  166. int release_y(int buttonId=0) { return click_buffer[buttonId].release_y; }
  167. int click_count(int buttonId=0) { return click_buffer[buttonId].count; }
  168. int is_mouse_event() { return has_mouse_event; }
  169. int is_key_event() { return scan_code; }
  170. int is_any_event() { return has_mouse_event || scan_code; }
  171. int is_press_button_event() { return has_mouse_event && (mouse_event_type == LEFT_BUTTON || mouse_event_type == RIGHT_BUTTON); }
  172. int is_release_button_event() { return has_mouse_event && (mouse_event_type == LEFT_BUTTON_RELEASE || mouse_event_type == RIGHT_BUTTON_RELEASE); }
  173. void reset_click();
  174. static int is_key(unsigned keyCode, unsigned short skeyState, unsigned short charValue, unsigned flags = 0 );
  175. static int is_key(unsigned keyCode, unsigned short skeyState, char *keyStr, unsigned flags = 0 );
  176. // see omouse2.h for flags
  177. private:
  178. long micky_to_displacement(DWORD);
  179. };
  180. //---------- End of define class ---------------//
  181. extern Mouse mouse;
  182. #endif