mouse.c 17 KB

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