mouse.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /*
  2. * File : mouse.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2009-10-16 Bernard first version
  13. */
  14. #include "mouse.h"
  15. #include <rtgui/region.h>
  16. #include <rtgui/driver.h>
  17. #include <rtgui/rtgui_system.h>
  18. struct rtgui_cursor
  19. {
  20. /* screen byte per pixel */
  21. rt_uint16_t bpp;
  22. /* screen pitch */
  23. rt_uint16_t screen_pitch;
  24. /* current cursor x and y */
  25. rt_uint16_t cx, cy;
  26. #ifdef RTGUI_USING_MOUSE_CURSOR
  27. /* cursor pitch */
  28. rt_uint16_t cursor_pitch;
  29. /* show cursor and show cursor count */
  30. rt_bool_t show_cursor;
  31. rt_base_t show_cursor_count;
  32. /* cursor rect info */
  33. rtgui_rect_t rect;
  34. /* cursor image and saved cursor */
  35. rtgui_image_t *cursor_image;
  36. rt_uint8_t *cursor_saved;
  37. #endif
  38. #ifdef RTGUI_USING_WINMOVE
  39. /* move window rect and border */
  40. struct rtgui_topwin *topwin;
  41. rtgui_rect_t win_rect;
  42. rt_uint8_t *win_left, *win_right;
  43. rt_uint8_t *win_top, *win_bottom;
  44. rt_bool_t win_rect_show, win_rect_has_saved;
  45. #endif
  46. };
  47. struct rtgui_cursor *_rtgui_cursor;
  48. #ifdef RTGUI_USING_MOUSE_CURSOR
  49. struct rt_mutex cursor_mutex;
  50. static const rt_uint8_t *cursor_xpm[] =
  51. {
  52. "16 16 35 1",
  53. " c None",
  54. ". c #A0B8D0",
  55. "+ c #F0F0F0",
  56. "@ c #FFFFFF",
  57. "# c #F0F8F0",
  58. "$ c #A0B0D0",
  59. "% c #90A8C0",
  60. "& c #A0B0C0",
  61. "* c #E0E8F0",
  62. "= c #8090B0",
  63. "- c #D0D8E0",
  64. "; c #7080A0",
  65. "> c #90A0B0",
  66. ", c #FFF8FF",
  67. "' c #F0F8FF",
  68. ") c #607090",
  69. "! c #8098B0",
  70. "~ c #405060",
  71. "{ c #405070",
  72. "] c #506070",
  73. "^ c #607080",
  74. "/ c #708090",
  75. "( c #7088A0",
  76. "_ c #D0D0E0",
  77. ": c #607890",
  78. "< c #C0D0E0",
  79. "[ c #C0C8D0",
  80. "} c #506880",
  81. "| c #5F778F",
  82. "1 c #D0D8F0",
  83. "2 c #506080",
  84. "3 c #C0C8E0",
  85. "4 c #A0A8C0",
  86. "5 c #405870",
  87. "6 c #5F6F8F",
  88. " . ",
  89. " .. ",
  90. " .+. ",
  91. " .@#$ ",
  92. " $@@+% ",
  93. " &@@@*= ",
  94. " %@@@@-; ",
  95. " >@@,''-) ",
  96. " !,''+)~{] ",
  97. " ='-^*/ ",
  98. " (_{:<[^ ",
  99. " ;} |:12 ",
  100. " / )345 ",
  101. " 6}${ ",
  102. " 5{ ",
  103. " "
  104. };
  105. static void rtgui_cursor_restore(void);
  106. static void rtgui_cursor_save(void);
  107. static void rtgui_cursor_show(void);
  108. #endif
  109. #ifdef RTGUI_USING_WINMOVE
  110. static void rtgui_winrect_restore(void);
  111. static void rtgui_winrect_save(void);
  112. static void rtgui_winrect_show(void);
  113. #endif
  114. #define WIN_MOVE_BORDER 4
  115. void rtgui_mouse_init(void)
  116. {
  117. const struct rtgui_graphic_driver *gd = rtgui_graphic_driver_get_default();
  118. if (_rtgui_cursor != RT_NULL) rtgui_mouse_fini();
  119. _rtgui_cursor = (struct rtgui_cursor *) rtgui_malloc(sizeof(struct rtgui_cursor));
  120. rt_memset(_rtgui_cursor, 0, sizeof(struct rtgui_cursor));
  121. #ifdef RTGUI_USING_MOUSE_CURSOR
  122. rt_mutex_init(&cursor_mutex, "cursor", RT_IPC_FLAG_FIFO);
  123. #endif
  124. /* init cursor */
  125. _rtgui_cursor->bpp = gd->bits_per_pixel / 8;
  126. _rtgui_cursor->screen_pitch = _rtgui_cursor->bpp * gd->width;
  127. #ifdef RTGUI_USING_MOUSE_CURSOR
  128. /* init cursor image */
  129. _rtgui_cursor->cursor_image = rtgui_image_create_from_mem("xpm",
  130. (rt_uint8_t *)cursor_xpm,
  131. sizeof(cursor_xpm),
  132. RT_TRUE);
  133. if (_rtgui_cursor->cursor_image == RT_NULL)
  134. {
  135. rtgui_free(_rtgui_cursor);
  136. _rtgui_cursor = RT_NULL;
  137. return;
  138. }
  139. /* init rect */
  140. _rtgui_cursor->rect.x1 = _rtgui_cursor->rect.y1 = 0;
  141. _rtgui_cursor->rect.x2 = _rtgui_cursor->cursor_image->w;
  142. _rtgui_cursor->rect.y2 = _rtgui_cursor->cursor_image->h;
  143. _rtgui_cursor->cursor_pitch = _rtgui_cursor->cursor_image->w * _rtgui_cursor->bpp;
  144. _rtgui_cursor->show_cursor = RT_TRUE;
  145. _rtgui_cursor->show_cursor_count = 0;
  146. _rtgui_cursor->cursor_saved = rtgui_malloc(_rtgui_cursor->cursor_image->w *
  147. _rtgui_cursor->cursor_image->h * _rtgui_cursor->bpp);
  148. #endif
  149. #ifdef RTGUI_USING_WINMOVE
  150. /* init window move save image */
  151. _rtgui_cursor->win_rect_has_saved = RT_FALSE;
  152. _rtgui_cursor->win_rect_show = RT_FALSE;
  153. _rtgui_cursor->win_left = rtgui_malloc(_rtgui_cursor->bpp * gd->height * WIN_MOVE_BORDER);
  154. _rtgui_cursor->win_right = rtgui_malloc(_rtgui_cursor->bpp * gd->height * WIN_MOVE_BORDER);
  155. _rtgui_cursor->win_top = rtgui_malloc(_rtgui_cursor->bpp * gd->width * WIN_MOVE_BORDER);
  156. _rtgui_cursor->win_bottom = rtgui_malloc(_rtgui_cursor->bpp * gd->width * WIN_MOVE_BORDER);
  157. #endif
  158. }
  159. void rtgui_mouse_fini(void)
  160. {
  161. if (_rtgui_cursor != RT_NULL)
  162. {
  163. #ifdef RTGUI_USING_WINMOVE
  164. rtgui_free(_rtgui_cursor->win_left);
  165. rtgui_free(_rtgui_cursor->win_right);
  166. rtgui_free(_rtgui_cursor->win_top);
  167. rtgui_free(_rtgui_cursor->win_bottom);
  168. #endif
  169. #ifdef RTGUI_USING_MOUSE_CURSOR
  170. rt_mutex_detach(&cursor_mutex);
  171. rtgui_image_destroy(_rtgui_cursor->cursor_image);
  172. rtgui_free(_rtgui_cursor->cursor_saved);
  173. #endif
  174. rtgui_free(_rtgui_cursor);
  175. _rtgui_cursor = RT_NULL;
  176. }
  177. }
  178. void rtgui_mouse_moveto(int x, int y)
  179. {
  180. #ifdef RTGUI_USING_MOUSE_CURSOR
  181. rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER);
  182. #endif
  183. if (x != _rtgui_cursor->cx ||
  184. y != _rtgui_cursor->cy)
  185. {
  186. #ifdef RTGUI_USING_WINMOVE
  187. if (_rtgui_cursor->win_rect_show)
  188. {
  189. if (_rtgui_cursor->win_rect_has_saved == RT_TRUE)
  190. {
  191. rtgui_winrect_restore();
  192. }
  193. #ifdef RTGUI_USING_MOUSE_CURSOR
  194. rtgui_mouse_hide_cursor();
  195. #endif
  196. /* move winrect */
  197. rtgui_rect_moveto(&(_rtgui_cursor->win_rect), x - _rtgui_cursor->cx,
  198. y - _rtgui_cursor->cy);
  199. rtgui_winrect_save();
  200. /* move current cursor */
  201. _rtgui_cursor->cx = x;
  202. _rtgui_cursor->cy = y;
  203. #ifdef RTGUI_USING_MOUSE_CURSOR
  204. /* show cursor */
  205. rtgui_mouse_show_cursor();
  206. #endif
  207. /* show winrect */
  208. rtgui_winrect_show();
  209. }
  210. else
  211. #endif
  212. {
  213. #ifdef RTGUI_USING_MOUSE_CURSOR
  214. rtgui_mouse_hide_cursor();
  215. #endif
  216. /* move current cursor */
  217. _rtgui_cursor->cx = x;
  218. _rtgui_cursor->cy = y;
  219. #ifdef RTGUI_USING_MOUSE_CURSOR
  220. /* show cursor */
  221. rtgui_mouse_show_cursor();
  222. #endif
  223. }
  224. }
  225. #ifdef RTGUI_USING_MOUSE_CURSOR
  226. rt_mutex_release(&cursor_mutex);
  227. #endif
  228. }
  229. #ifdef RTGUI_USING_MOUSE_CURSOR
  230. void rtgui_mouse_set_cursor_enable(rt_bool_t enable)
  231. {
  232. _rtgui_cursor->show_cursor = enable;
  233. }
  234. /* set current cursor image */
  235. void rtgui_mouse_set_cursor(rtgui_image_t *cursor)
  236. {
  237. }
  238. void rtgui_mouse_get_cursor_rect(rtgui_rect_t *rect)
  239. {
  240. if (rect != RT_NULL)
  241. {
  242. *rect = _rtgui_cursor->rect;
  243. }
  244. }
  245. void rtgui_mouse_show_cursor()
  246. {
  247. if (_rtgui_cursor->show_cursor == RT_FALSE)
  248. return;
  249. _rtgui_cursor->show_cursor_count ++;
  250. if (_rtgui_cursor->show_cursor_count == 1)
  251. {
  252. /* save show mouse area */
  253. rtgui_cursor_save();
  254. /* show mouse cursor */
  255. rtgui_cursor_show();
  256. }
  257. }
  258. void rtgui_mouse_hide_cursor()
  259. {
  260. if (_rtgui_cursor->show_cursor == RT_FALSE)
  261. return;
  262. if (_rtgui_cursor->show_cursor_count == 1)
  263. {
  264. /* display the cursor coverage area */
  265. rtgui_cursor_restore();
  266. }
  267. _rtgui_cursor->show_cursor_count --;
  268. }
  269. rt_bool_t rtgui_mouse_is_intersect(rtgui_rect_t *r)
  270. {
  271. return rtgui_rect_is_intersect(&(_rtgui_cursor->rect), r) == RT_EOK ? RT_TRUE : RT_FALSE;
  272. }
  273. /* display the saved cursor area to screen */
  274. static void rtgui_cursor_restore()
  275. {
  276. rt_base_t idx, height, cursor_pitch;
  277. rt_uint8_t *cursor_ptr, *fb_ptr;
  278. fb_ptr = rtgui_graphic_driver_get_default_framebuffer() + _rtgui_cursor->cy * _rtgui_cursor->screen_pitch
  279. + _rtgui_cursor->cx * _rtgui_cursor->bpp;
  280. cursor_ptr = _rtgui_cursor->cursor_saved;
  281. height = (_rtgui_cursor->cy + _rtgui_cursor->cursor_image->h <
  282. rtgui_graphic_driver_get_default()->height) ? _rtgui_cursor->cursor_image->h :
  283. rtgui_graphic_driver_get_default()->height - _rtgui_cursor->cy;
  284. cursor_pitch = (_rtgui_cursor->cx + _rtgui_cursor->cursor_image->w <
  285. rtgui_graphic_driver_get_default()->width) ? _rtgui_cursor->cursor_pitch :
  286. (rtgui_graphic_driver_get_default()->width - _rtgui_cursor->cx) * _rtgui_cursor->bpp;
  287. for (idx = 0; idx < height; idx ++)
  288. {
  289. rt_memcpy(fb_ptr, cursor_ptr, cursor_pitch);
  290. fb_ptr += _rtgui_cursor->screen_pitch;
  291. cursor_ptr += _rtgui_cursor->cursor_pitch;
  292. }
  293. }
  294. /* save the cursor coverage area from screen */
  295. static void rtgui_cursor_save()
  296. {
  297. rt_base_t idx, height, cursor_pitch;
  298. rt_uint8_t *cursor_ptr, *fb_ptr;
  299. fb_ptr = rtgui_graphic_driver_get_default_framebuffer() + _rtgui_cursor->cy * _rtgui_cursor->screen_pitch +
  300. _rtgui_cursor->cx * _rtgui_cursor->bpp;
  301. cursor_ptr = _rtgui_cursor->cursor_saved;
  302. height = (_rtgui_cursor->cy + _rtgui_cursor->cursor_image->h <
  303. rtgui_graphic_driver_get_default()->height) ? _rtgui_cursor->cursor_image->h :
  304. rtgui_graphic_driver_get_default()->height - _rtgui_cursor->cy;
  305. cursor_pitch = (_rtgui_cursor->cx + _rtgui_cursor->cursor_image->w <
  306. rtgui_graphic_driver_get_default()->width) ? _rtgui_cursor->cursor_pitch :
  307. (rtgui_graphic_driver_get_default()->width - _rtgui_cursor->cx) * _rtgui_cursor->bpp;
  308. for (idx = 0; idx < height; idx ++)
  309. {
  310. rt_memcpy(cursor_ptr, fb_ptr, cursor_pitch);
  311. fb_ptr += _rtgui_cursor->screen_pitch;
  312. cursor_ptr += _rtgui_cursor->cursor_pitch;
  313. }
  314. }
  315. static void rtgui_cursor_show()
  316. {
  317. // FIXME: the prototype of set_pixel is using int so we have to use int
  318. // as well. Might be uniformed with others in the future
  319. int x, y;
  320. rtgui_color_t *ptr;
  321. rtgui_rect_t rect;
  322. void (*set_pixel)(rtgui_color_t * c, int x, int y);
  323. ptr = (rtgui_color_t *) _rtgui_cursor->cursor_image->data;
  324. set_pixel = rtgui_graphic_driver_get_default()->ops->set_pixel;
  325. rtgui_mouse_get_cursor_rect(&rect);
  326. rtgui_rect_moveto(&rect, _rtgui_cursor->cx, _rtgui_cursor->cy);
  327. /* draw each point */
  328. for (y = rect.y1; y < rect.y2; y ++)
  329. {
  330. for (x = rect.x1; x < rect.x2; x++)
  331. {
  332. /* not alpha */
  333. if ((*ptr >> 24) != 255)
  334. {
  335. set_pixel(ptr, x, y);
  336. }
  337. /* move to next color buffer */
  338. ptr ++;
  339. }
  340. }
  341. /* update rect */
  342. rtgui_graphic_driver_screen_update(rtgui_graphic_driver_get_default(), &rect);
  343. }
  344. #endif
  345. #ifdef RTGUI_USING_WINMOVE
  346. void rtgui_winrect_set(struct rtgui_topwin *topwin)
  347. {
  348. /* set win rect show */
  349. _rtgui_cursor->win_rect_show = RT_TRUE;
  350. /* set win rect */
  351. _rtgui_cursor->win_rect = topwin->title == RT_NULL ? topwin->extent : RTGUI_WIDGET(topwin->title)->extent;
  352. _rtgui_cursor->topwin = topwin;
  353. }
  354. rt_bool_t rtgui_winrect_moved_done(rtgui_rect_t *winrect, struct rtgui_topwin **topwin)
  355. {
  356. rt_bool_t moved = RT_FALSE;
  357. /* no win rect */
  358. if (winrect == RT_NULL) return RT_FALSE;
  359. /* restore winrect */
  360. if (_rtgui_cursor->win_rect_has_saved)
  361. {
  362. rtgui_winrect_restore();
  363. moved = RT_TRUE;
  364. }
  365. /* clear win rect show */
  366. _rtgui_cursor->win_rect_show = RT_FALSE;
  367. _rtgui_cursor->win_rect_has_saved = RT_FALSE;
  368. /* return win rect */
  369. *winrect = _rtgui_cursor->win_rect;
  370. *topwin = _rtgui_cursor->topwin;
  371. return moved;
  372. }
  373. rt_bool_t rtgui_winrect_is_moved()
  374. {
  375. return _rtgui_cursor->win_rect_show;
  376. }
  377. /* show winrect */
  378. static void rtgui_winrect_show()
  379. {
  380. rt_uint16_t x, y;
  381. rtgui_color_t c;
  382. rtgui_rect_t screen_rect, win_rect, win_rect_inner;
  383. void (*set_pixel)(rtgui_color_t * c, int x, int y);
  384. c = black;
  385. set_pixel = rtgui_graphic_driver_get_default()->ops->set_pixel;
  386. win_rect = _rtgui_cursor->win_rect;
  387. win_rect_inner = win_rect;
  388. rtgui_rect_inflate(&win_rect_inner, -WIN_MOVE_BORDER);
  389. rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(),
  390. &screen_rect);
  391. rtgui_rect_intersect(&screen_rect, &win_rect);
  392. rtgui_rect_intersect(&screen_rect, &win_rect_inner);
  393. /* draw left */
  394. for (y = win_rect.y1; y < win_rect.y2; y ++)
  395. {
  396. for (x = win_rect.x1; x < win_rect_inner.x1; x++)
  397. if ((x + y) & 0x01) set_pixel(&c, x, y);
  398. }
  399. /* draw right */
  400. for (y = win_rect.y1; y < win_rect.y2; y ++)
  401. {
  402. for (x = win_rect_inner.x2; x < win_rect.x2; x++)
  403. if ((x + y) & 0x01) set_pixel(&c, x, y);
  404. }
  405. /* draw top border */
  406. for (y = win_rect.y1; y < win_rect_inner.y1; y ++)
  407. {
  408. for (x = win_rect_inner.x1; x < win_rect_inner.x2; x++)
  409. if ((x + y) & 0x01) set_pixel(&c, x, y);
  410. }
  411. /* draw bottom border */
  412. for (y = win_rect_inner.y2; y < win_rect.y2; y ++)
  413. {
  414. for (x = win_rect_inner.x1; x < win_rect_inner.x2; x++)
  415. if ((x + y) & 0x01) set_pixel(&c, x, y);
  416. }
  417. /* update rect */
  418. rtgui_graphic_driver_screen_update(rtgui_graphic_driver_get_default(), &win_rect);
  419. }
  420. #define display_direct_memcpy(src, dest, src_pitch, dest_pitch, height, len) \
  421. for (idx = 0; idx < height; idx ++) \
  422. { \
  423. rt_memcpy(dest, src, len); \
  424. src += src_pitch; \
  425. dest += dest_pitch; \
  426. }
  427. static void rtgui_winrect_restore()
  428. {
  429. rt_uint8_t *winrect_ptr, *fb_ptr, *driver_fb;
  430. int winrect_pitch, idx;
  431. rtgui_rect_t screen_rect, win_rect;
  432. driver_fb = rtgui_graphic_driver_get_default_framebuffer();
  433. win_rect = _rtgui_cursor->win_rect;
  434. rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(),
  435. &screen_rect);
  436. rtgui_rect_intersect(&screen_rect, &win_rect);
  437. /* restore winrect left */
  438. fb_ptr = driver_fb + win_rect.y1 * _rtgui_cursor->screen_pitch +
  439. win_rect.x1 * _rtgui_cursor->bpp;
  440. winrect_ptr = _rtgui_cursor->win_left;
  441. winrect_pitch = WIN_MOVE_BORDER * _rtgui_cursor->bpp;
  442. display_direct_memcpy(winrect_ptr, fb_ptr, winrect_pitch, _rtgui_cursor->screen_pitch,
  443. (win_rect.y2 - win_rect.y1), winrect_pitch);
  444. /* restore winrect right */
  445. fb_ptr = driver_fb + win_rect.y1 * _rtgui_cursor->screen_pitch +
  446. (win_rect.x2 - WIN_MOVE_BORDER) * _rtgui_cursor->bpp;
  447. winrect_ptr = _rtgui_cursor->win_right;
  448. winrect_pitch = WIN_MOVE_BORDER * _rtgui_cursor->bpp;
  449. display_direct_memcpy(winrect_ptr, fb_ptr, winrect_pitch, _rtgui_cursor->screen_pitch,
  450. (win_rect.y2 - win_rect.y1), winrect_pitch);
  451. /* restore winrect top */
  452. fb_ptr = driver_fb + win_rect.y1 * _rtgui_cursor->screen_pitch +
  453. (win_rect.x1 + WIN_MOVE_BORDER) * _rtgui_cursor->bpp;
  454. winrect_ptr = _rtgui_cursor->win_top;
  455. winrect_pitch = (win_rect.x2 - win_rect.x1 - 2 * WIN_MOVE_BORDER) * _rtgui_cursor->bpp;
  456. display_direct_memcpy(winrect_ptr, fb_ptr, winrect_pitch, _rtgui_cursor->screen_pitch,
  457. WIN_MOVE_BORDER, winrect_pitch);
  458. /* restore winrect bottom */
  459. fb_ptr = driver_fb + (win_rect.y2 - WIN_MOVE_BORDER) * _rtgui_cursor->screen_pitch +
  460. (win_rect.x1 + WIN_MOVE_BORDER) * _rtgui_cursor->bpp;
  461. winrect_ptr = _rtgui_cursor->win_bottom;
  462. display_direct_memcpy(winrect_ptr, fb_ptr, winrect_pitch, _rtgui_cursor->screen_pitch,
  463. WIN_MOVE_BORDER, winrect_pitch);
  464. }
  465. static void rtgui_winrect_save()
  466. {
  467. rt_uint8_t *winrect_ptr, *fb_ptr, *driver_fb;
  468. int winrect_pitch, idx;
  469. rtgui_rect_t screen_rect, win_rect;
  470. driver_fb = rtgui_graphic_driver_get_default_framebuffer();
  471. win_rect = _rtgui_cursor->win_rect;
  472. rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(),
  473. &screen_rect);
  474. rtgui_rect_intersect(&screen_rect, &win_rect);
  475. /* set winrect has saved */
  476. _rtgui_cursor->win_rect_has_saved = RT_TRUE;
  477. /* save winrect left */
  478. fb_ptr = driver_fb + win_rect.y1 * _rtgui_cursor->screen_pitch +
  479. win_rect.x1 * _rtgui_cursor->bpp;
  480. winrect_ptr = _rtgui_cursor->win_left;
  481. winrect_pitch = WIN_MOVE_BORDER * _rtgui_cursor->bpp;
  482. display_direct_memcpy(fb_ptr, winrect_ptr, _rtgui_cursor->screen_pitch, winrect_pitch,
  483. (win_rect.y2 - win_rect.y1), winrect_pitch);
  484. /* save winrect right */
  485. fb_ptr = driver_fb + win_rect.y1 * _rtgui_cursor->screen_pitch +
  486. (win_rect.x2 - WIN_MOVE_BORDER) * _rtgui_cursor->bpp;
  487. winrect_ptr = _rtgui_cursor->win_right;
  488. winrect_pitch = WIN_MOVE_BORDER * _rtgui_cursor->bpp;
  489. display_direct_memcpy(fb_ptr, winrect_ptr, _rtgui_cursor->screen_pitch, winrect_pitch,
  490. (win_rect.y2 - win_rect.y1), winrect_pitch);
  491. /* save winrect top */
  492. fb_ptr = driver_fb + win_rect.y1 * _rtgui_cursor->screen_pitch +
  493. (win_rect.x1 + WIN_MOVE_BORDER) * _rtgui_cursor->bpp;
  494. winrect_ptr = _rtgui_cursor->win_top;
  495. winrect_pitch = (win_rect.x2 - win_rect.x1 - 2 * WIN_MOVE_BORDER) * _rtgui_cursor->bpp;
  496. display_direct_memcpy(fb_ptr, winrect_ptr, _rtgui_cursor->screen_pitch, winrect_pitch,
  497. WIN_MOVE_BORDER, winrect_pitch);
  498. /* save winrect bottom */
  499. fb_ptr = driver_fb + (win_rect.y2 - WIN_MOVE_BORDER) * _rtgui_cursor->screen_pitch +
  500. (win_rect.x1 + WIN_MOVE_BORDER) * _rtgui_cursor->bpp;
  501. winrect_ptr = _rtgui_cursor->win_bottom;
  502. display_direct_memcpy(fb_ptr, winrect_ptr, _rtgui_cursor->screen_pitch, winrect_pitch,
  503. WIN_MOVE_BORDER, winrect_pitch);
  504. }
  505. #endif
  506. void rtgui_mouse_monitor_append(rtgui_list_t *head, rtgui_rect_t *rect)
  507. {
  508. struct rtgui_mouse_monitor *mmonitor;
  509. /* check parameters */
  510. if (head == RT_NULL || rect == RT_NULL) return;
  511. /* create a mouse monitor node */
  512. mmonitor = (struct rtgui_mouse_monitor *) rtgui_malloc(sizeof(struct rtgui_mouse_monitor));
  513. if (mmonitor == RT_NULL) return; /* no memory */
  514. /* set mouse monitor node */
  515. mmonitor->rect = *rect;
  516. rtgui_list_init(&(mmonitor->list));
  517. /* append to list */
  518. rtgui_list_append(head, &(mmonitor->list));
  519. }
  520. void rtgui_mouse_monitor_remove(rtgui_list_t *head, rtgui_rect_t *rect)
  521. {
  522. struct rtgui_list_node *node;
  523. struct rtgui_mouse_monitor *mmonitor;
  524. /* check parameters */
  525. if (head == RT_NULL || rect == RT_NULL) return;
  526. for (node = head->next; node != RT_NULL; node = node->next)
  527. {
  528. mmonitor = rtgui_list_entry(node, struct rtgui_mouse_monitor, list);
  529. if (mmonitor->rect.x1 == rect->x1 &&
  530. mmonitor->rect.x2 == rect->x2 &&
  531. mmonitor->rect.y1 == rect->y1 &&
  532. mmonitor->rect.y2 == rect->y2)
  533. {
  534. /* found node */
  535. rtgui_list_remove(head, node);
  536. rtgui_free(mmonitor);
  537. return ;
  538. }
  539. }
  540. }
  541. rt_bool_t rtgui_mouse_monitor_contains_point(rtgui_list_t *head, int x, int y)
  542. {
  543. struct rtgui_list_node *node;
  544. /* check parameter */
  545. if (head == RT_NULL) return RT_FALSE;
  546. rtgui_list_foreach(node, head)
  547. {
  548. struct rtgui_mouse_monitor *monitor = rtgui_list_entry(node,
  549. struct rtgui_mouse_monitor, list);
  550. if (rtgui_rect_contains_point(&(monitor->rect), x, y) == RT_EOK)
  551. {
  552. return RT_TRUE;
  553. }
  554. }
  555. return RT_FALSE;
  556. }