MOUSE.C 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  12. */
  13. /*
  14. * $Source: f:/miner/source/ui/rcs/mouse.c $
  15. * $Revision: 1.8 $
  16. * $Author: john $
  17. * $Date: 1995/03/06 17:54:17 $
  18. *
  19. * Mouse interface routines.
  20. *
  21. * $Log: mouse.c $
  22. * Revision 1.8 1995/03/06 17:54:17 john
  23. * fixed bug with mouse color being wrong.
  24. *
  25. * Revision 1.7 1994/09/23 14:57:52 john
  26. * Took out calls to init_mouse and init_keyboard.
  27. *
  28. * Revision 1.6 1994/04/22 11:10:06 john
  29. * *** empty log message ***
  30. *
  31. * Revision 1.5 1993/12/07 12:30:44 john
  32. * new version.
  33. *
  34. * Revision 1.4 1993/10/26 13:46:04 john
  35. * *** empty log message ***
  36. *
  37. * Revision 1.3 1993/10/05 17:55:27 matt
  38. * Changed default pointer
  39. *
  40. * Revision 1.2 1993/10/05 17:31:33 john
  41. * *** empty log message ***
  42. *
  43. * Revision 1.1 1993/09/20 10:35:25 john
  44. * Initial revision
  45. *
  46. *
  47. */
  48. #pragma off (unreferenced)
  49. static char rcsid[] = "$Id: mouse.c 1.8 1995/03/06 17:54:17 john Exp $";
  50. #pragma on (unreferenced)
  51. #include <stdlib.h>
  52. #include "mem.h"
  53. #include "fix.h"
  54. #include "types.h"
  55. #include "gr.h"
  56. #include "mouse.h"
  57. #include "ui.h"
  58. // 16x16
  59. #define PTR_W 11
  60. #define PTR_H 19
  61. char ui_converted_mouse_pointer[PTR_W*PTR_H];
  62. char ui_mouse_pointer[] = \
  63. //"1111100000000000"\
  64. //"1111111111000000"\
  65. //"1144411111111111"\
  66. //"1144444444111111"\
  67. //"1144444444444110"\
  68. //"0114444444441100"\
  69. //"0114444444411000"\
  70. //"0114444444411000"\
  71. //"0114444444441100"\
  72. //"0114444444444110"\
  73. //"0011444444444411"\
  74. //"0011444444444411"\
  75. //"0011411144444411"\
  76. //"0011111111444111"\
  77. //"0011100011111110"\
  78. //"0011000000111100";
  79. "10000000000"\
  80. "11000000000"\
  81. "14100000000"\
  82. "14410000000"\
  83. "14441000000"\
  84. "14444100000"\
  85. "14444410000"\
  86. "14444441000"\
  87. "14444444100"\
  88. "14444444410"\
  89. "14444411111"\
  90. "14114410000"\
  91. "11014410000"\
  92. "10001441000"\
  93. "00001441000"\
  94. "00001441000"\
  95. "00000144100"\
  96. "00000144100"\
  97. "00000111100";
  98. static grs_bitmap * default_pointer;
  99. UI_MOUSE Mouse;
  100. #define TICKER (*(volatile int *)0x46C)
  101. /*
  102. int ui_mouse_find_gadget(short n)
  103. {
  104. int i;
  105. for (i=1; i<=Window[n].NumItems; i++ ) {
  106. if ((Mouse.x >= (Window[n].Item[i].x1+Window[n].x)) &&
  107. (Mouse.x <= (Window[n].Item[i].x2+Window[n].x)) &&
  108. (Mouse.y >= (Window[n].Item[i].y1+Window[n].y)) &&
  109. (Mouse.y <= (Window[n].Item[i].y2+Window[n].y)) )
  110. return i;
  111. }
  112. return 0;
  113. }
  114. */
  115. void ui_mouse_show()
  116. {
  117. if (Mouse.hidden==1 ) {
  118. Mouse.hidden = 0;
  119. // Save the background under new pointer
  120. Mouse.bg_saved=1;
  121. Mouse.bg_x = Mouse.x; Mouse.bg_y = Mouse.y;
  122. gr_bm_ubitblt( Mouse.background->bm_w, Mouse.background->bm_h, 0, 0, Mouse.bg_x, Mouse.bg_y, &(grd_curscreen->sc_canvas.cv_bitmap),Mouse.background );
  123. // Draw the new pointer
  124. gr_bm_ubitbltm( Mouse.pointer->bm_w, Mouse.pointer->bm_h, Mouse.x, Mouse.y, 0, 0, Mouse.pointer, &(grd_curscreen->sc_canvas.cv_bitmap) );
  125. }
  126. }
  127. void ui_mouse_hide()
  128. {
  129. if (Mouse.hidden==0 ) {
  130. Mouse.hidden = 1;
  131. if (Mouse.bg_saved==1) {
  132. gr_bm_ubitblt( Mouse.background->bm_w, Mouse.background->bm_h, Mouse.bg_x, Mouse.bg_y, 0, 0, Mouse.background,&(grd_curscreen->sc_canvas.cv_bitmap) );
  133. Mouse.bg_saved = 0;
  134. }
  135. }
  136. }
  137. void ui_mouse_process()
  138. { int buttons,w,h;
  139. //if (Mouse.hidden==0)
  140. // mouse_get_pos( &Mouse.x, &Mouse.y );
  141. //else
  142. // mouse_set_pos( Mouse.x, Mouse.y );
  143. Mouse.dx = Mouse.new_dx;
  144. Mouse.dy = Mouse.new_dy;
  145. buttons = Mouse.new_buttons;
  146. Mouse.x += Mouse.dx;
  147. Mouse.y += Mouse.dy;
  148. w = grd_curscreen->sc_w;
  149. h = grd_curscreen->sc_h;
  150. if (Mouse.x < 0 ) Mouse.x = 0;
  151. if (Mouse.y < 0 ) Mouse.y = 0;
  152. // if (Mouse.x > w-Mouse.pointer->bm_w ) Mouse.x = w - Mouse.pointer->bm_w;
  153. // if (Mouse.y > h-Mouse.pointer->bm_h ) Mouse.y = h - Mouse.pointer->bm_h;
  154. if (Mouse.x > w-3 ) Mouse.x = w - 3;
  155. if (Mouse.y > h-3 ) Mouse.y = h - 3;
  156. if ( (Mouse.bg_x!=Mouse.x) || (Mouse.bg_y!=Mouse.y) )
  157. Mouse.moved = 1;
  158. if ( (Mouse.bg_x!=Mouse.x) || (Mouse.bg_y!=Mouse.y) || (Mouse.bg_saved==0) )
  159. {
  160. // Restore the background under old pointer
  161. if (Mouse.bg_saved==1) {
  162. gr_bm_ubitblt( Mouse.background->bm_w, Mouse.background->bm_h, Mouse.bg_x, Mouse.bg_y, 0, 0, Mouse.background, &(grd_curscreen->sc_canvas.cv_bitmap) );
  163. }
  164. Mouse.bg_saved = 0;
  165. if (!Mouse.hidden)
  166. {
  167. // Save the background under new pointer
  168. Mouse.bg_saved=1;
  169. Mouse.bg_x = Mouse.x; Mouse.bg_y = Mouse.y;
  170. gr_bm_ubitblt( Mouse.background->bm_w, Mouse.background->bm_h, 0, 0, Mouse.bg_x, Mouse.bg_y, &(grd_curscreen->sc_canvas.cv_bitmap),Mouse.background );
  171. // Draw the new pointer
  172. gr_bm_ubitbltm( Mouse.pointer->bm_w, Mouse.pointer->bm_h, Mouse.x, Mouse.y, 0, 0, Mouse.pointer, &(grd_curscreen->sc_canvas.cv_bitmap) );
  173. }
  174. }
  175. Mouse.b1_last_status = Mouse.b1_status;
  176. Mouse.b2_last_status = Mouse.b2_status;
  177. if ( Mouse.backwards== 0 )
  178. {
  179. if (buttons & MOUSE_LBTN )
  180. Mouse.b1_status = BUTTON_PRESSED;
  181. else
  182. Mouse.b1_status = BUTTON_RELEASED;
  183. if (buttons & MOUSE_RBTN )
  184. Mouse.b2_status = BUTTON_PRESSED;
  185. else
  186. Mouse.b2_status = BUTTON_RELEASED;
  187. } else {
  188. if (buttons & MOUSE_LBTN )
  189. Mouse.b2_status = BUTTON_PRESSED;
  190. else
  191. Mouse.b2_status = BUTTON_RELEASED;
  192. if (buttons & MOUSE_RBTN )
  193. Mouse.b1_status = BUTTON_PRESSED;
  194. else
  195. Mouse.b1_status = BUTTON_RELEASED;
  196. }
  197. if ((Mouse.b1_status & BUTTON_PRESSED) && (Mouse.b1_last_status & BUTTON_RELEASED) )
  198. {
  199. if ( (TICKER <= Mouse.time_lastpressed+5) ) //&& (Mouse.moved==0)
  200. Mouse.b1_status |= BUTTON_DOUBLE_CLICKED;
  201. Mouse.moved = 0;
  202. Mouse.time_lastpressed = TICKER;
  203. Mouse.b1_status |= BUTTON_JUST_PRESSED;
  204. }
  205. else if ((Mouse.b1_status & BUTTON_RELEASED) && (Mouse.b1_last_status & BUTTON_PRESSED) )
  206. Mouse.b1_status |= BUTTON_JUST_RELEASED;
  207. if ((Mouse.b2_status & BUTTON_PRESSED) && (Mouse.b2_last_status & BUTTON_RELEASED) )
  208. Mouse.b2_status |= BUTTON_JUST_PRESSED;
  209. else if ((Mouse.b2_status & BUTTON_RELEASED) && (Mouse.b2_last_status & BUTTON_PRESSED) )
  210. Mouse.b2_status |= BUTTON_JUST_RELEASED;
  211. }
  212. void ui_mouse_flip_buttons()
  213. { short x;
  214. x = Mouse.b1_status;
  215. Mouse.b1_status = Mouse.b2_status;
  216. Mouse.b2_status = x;
  217. x = Mouse.b1_last_status;
  218. Mouse.b1_last_status = Mouse.b2_last_status;
  219. Mouse.b2_last_status = x;
  220. Mouse.backwards ^= 1;
  221. }
  222. void ui_mouse_init()
  223. {
  224. int i, w,h;
  225. //mouse_init();
  226. w = grd_curscreen->sc_w;
  227. h = grd_curscreen->sc_h;
  228. mouse_set_limits( 0,0, w-1, h-1 );
  229. Mouse.x = w/2;
  230. Mouse.y = h/2;
  231. //mouse_set_pos( w/2, h/2 );
  232. for (i=0; i < PTR_W*PTR_H; i++ ) {
  233. switch (ui_mouse_pointer[i]) {
  234. case '0':
  235. ui_converted_mouse_pointer[i]=255;
  236. break;
  237. case '1':
  238. ui_converted_mouse_pointer[i]=CBLACK;
  239. break;
  240. case '2':
  241. ui_converted_mouse_pointer[i]=CGREY;
  242. break;
  243. case '3':
  244. ui_converted_mouse_pointer[i]=CWHITE;
  245. break;
  246. case '4':
  247. ui_converted_mouse_pointer[i]=CBRIGHT;
  248. break;
  249. case '5':
  250. ui_converted_mouse_pointer[i]=CRED;
  251. break;
  252. }
  253. }
  254. default_pointer = gr_create_bitmap_raw( PTR_W, PTR_H, ui_converted_mouse_pointer );
  255. Mouse.x = Mouse.y = 0;
  256. Mouse.backwards = 0;
  257. Mouse.hidden = 1;
  258. Mouse.b1_status = Mouse.b1_last_status = BUTTON_RELEASED;
  259. Mouse.b2_status = Mouse.b2_last_status = BUTTON_RELEASED;
  260. Mouse.b3_status = Mouse.b3_last_status = BUTTON_RELEASED;
  261. Mouse.bg_x = Mouse.bg_y = 0;
  262. Mouse.bg_saved = 0;
  263. Mouse.pointer = default_pointer;
  264. Mouse.background = gr_create_bitmap( Mouse.pointer->bm_w, Mouse.pointer->bm_h );
  265. Mouse.time_lastpressed = 0;
  266. Mouse.moved = 0;
  267. }
  268. grs_bitmap * ui_mouse_set_pointer( grs_bitmap * new )
  269. {
  270. grs_bitmap * temp = Mouse.pointer;
  271. gr_free_bitmap( Mouse.background );
  272. if (new == NULL ) {
  273. Mouse.pointer = default_pointer;
  274. } else {
  275. Mouse.pointer = new;
  276. }
  277. Mouse.background = gr_create_bitmap( Mouse.pointer->bm_w, Mouse.pointer->bm_h );
  278. return temp;
  279. }
  280. void ui_mouse_close()
  281. {
  282. gr_free_sub_bitmap(default_pointer);
  283. gr_free_bitmap(Mouse.background);
  284. }
  285.