mouse.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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. /* move window rect and border */
  39. struct rtgui_topwin *topwin;
  40. rtgui_rect_t win_rect;
  41. rt_uint8_t *win_left, *win_right;
  42. rt_uint8_t *win_top, *win_bottom;
  43. rt_bool_t win_rect_show, win_rect_has_saved;
  44. /* screen framebuffer */
  45. rt_uint8_t* framebuffer;
  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. static void rtgui_winrect_restore (void);
  108. static void rtgui_winrect_save (void);
  109. static void rtgui_winrect_show (void);
  110. #define WIN_MOVE_BORDER 4
  111. void rtgui_mouse_init()
  112. {
  113. struct rtgui_graphic_driver* gd = rtgui_graphic_driver_get_default();
  114. _rtgui_cursor = (struct rtgui_cursor*) rtgui_malloc(sizeof(struct rtgui_cursor));
  115. rt_memset(_rtgui_cursor, 0, sizeof(struct rtgui_cursor));
  116. #ifdef RTGUI_USING_MOUSE_CURSOR
  117. rt_mutex_init(&cursor_mutex, "cursor", RT_IPC_FLAG_FIFO);
  118. #endif
  119. /* init cursor */
  120. _rtgui_cursor->bpp = gd->byte_per_pixel;
  121. _rtgui_cursor->framebuffer = gd->get_framebuffer();
  122. _rtgui_cursor->screen_pitch = _rtgui_cursor->bpp * gd->width;
  123. #ifdef RTGUI_USING_MOUSE_CURSOR
  124. /* init cursor image */
  125. _rtgui_cursor->cursor_image = rtgui_image_create_from_mem("xpm", cursor_xpm, sizeof(cursor_xpm));
  126. if (_rtgui_cursor->cursor_image == RT_NULL)
  127. {
  128. rtgui_free(_rtgui_cursor);
  129. _rtgui_cursor = RT_NULL;
  130. return;
  131. }
  132. /* init rect */
  133. _rtgui_cursor->rect.x1 = _rtgui_cursor->rect.y1 = 0;
  134. _rtgui_cursor->rect.x2 = _rtgui_cursor->cursor_image->w;
  135. _rtgui_cursor->rect.y2 = _rtgui_cursor->cursor_image->h;
  136. _rtgui_cursor->cursor_pitch = _rtgui_cursor->cursor_image->w * _rtgui_cursor->bpp;
  137. _rtgui_cursor->show_cursor = RT_TRUE;
  138. _rtgui_cursor->show_cursor_count = 0;
  139. _rtgui_cursor->cursor_saved = rtgui_malloc(_rtgui_cursor->cursor_image->w *
  140. _rtgui_cursor->cursor_image->h * _rtgui_cursor->bpp);
  141. #endif
  142. /* init window move save image */
  143. _rtgui_cursor->win_rect_has_saved = RT_FALSE;
  144. _rtgui_cursor->win_rect_show = RT_FALSE;
  145. _rtgui_cursor->win_left = rtgui_malloc(_rtgui_cursor->bpp * gd->height * WIN_MOVE_BORDER);
  146. _rtgui_cursor->win_right = rtgui_malloc(_rtgui_cursor->bpp * gd->height * WIN_MOVE_BORDER);
  147. _rtgui_cursor->win_top = rtgui_malloc(_rtgui_cursor->bpp * gd->width * WIN_MOVE_BORDER);
  148. _rtgui_cursor->win_bottom = rtgui_malloc(_rtgui_cursor->bpp * gd->width * WIN_MOVE_BORDER);
  149. }
  150. void rtgui_mouse_moveto(int x, int y)
  151. {
  152. #ifdef RTGUI_USING_MOUSE_CURSOR
  153. rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER);
  154. #endif
  155. if (x != _rtgui_cursor->cx ||
  156. y != _rtgui_cursor->cy)
  157. {
  158. if (_rtgui_cursor->win_rect_show)
  159. {
  160. if (_rtgui_cursor->win_rect_has_saved == RT_TRUE)
  161. {
  162. rtgui_winrect_restore();
  163. }
  164. #ifdef RTGUI_USING_MOUSE_CURSOR
  165. rtgui_mouse_hide_cursor();
  166. #endif
  167. /* move winrect */
  168. rtgui_rect_moveto(&(_rtgui_cursor->win_rect), x - _rtgui_cursor->cx,
  169. y - _rtgui_cursor->cy);
  170. rtgui_winrect_save();
  171. /* move current cursor */
  172. _rtgui_cursor->cx = x;
  173. _rtgui_cursor->cy = y;
  174. #ifdef RTGUI_USING_MOUSE_CURSOR
  175. /* show cursor */
  176. rtgui_mouse_show_cursor();
  177. #endif
  178. /* show winrect */
  179. rtgui_winrect_show();
  180. }
  181. else
  182. {
  183. #ifdef RTGUI_USING_MOUSE_CURSOR
  184. rtgui_mouse_hide_cursor();
  185. #endif
  186. /* move current cursor */
  187. _rtgui_cursor->cx = x;
  188. _rtgui_cursor->cy = y;
  189. #ifdef RTGUI_USING_MOUSE_CURSOR
  190. /* show cursor */
  191. rtgui_mouse_show_cursor();
  192. #endif
  193. }
  194. }
  195. #ifdef RTGUI_USING_MOUSE_CURSOR
  196. rt_mutex_release(&cursor_mutex);
  197. #endif
  198. }
  199. #ifdef RTGUI_USING_MOUSE_CURSOR
  200. void rtgui_mouse_set_cursor_enable(rt_bool_t enable)
  201. {
  202. _rtgui_cursor->show_cursor = enable;
  203. }
  204. /* set current cursor image */
  205. void rtgui_mouse_set_cursor(rtgui_image_t* cursor)
  206. {
  207. }
  208. void rtgui_mouse_get_cursor_rect(rtgui_rect_t* rect)
  209. {
  210. if (rect != RT_NULL)
  211. {
  212. *rect = _rtgui_cursor->rect;
  213. }
  214. }
  215. void rtgui_mouse_show_cursor()
  216. {
  217. if (_rtgui_cursor->show_cursor == RT_FALSE)
  218. return;
  219. _rtgui_cursor->show_cursor_count ++;
  220. if (_rtgui_cursor->show_cursor_count == 1)
  221. {
  222. /* save show mouse area */
  223. rtgui_cursor_save();
  224. /* show mouse cursor */
  225. rtgui_cursor_show();
  226. }
  227. }
  228. void rtgui_mouse_hide_cursor()
  229. {
  230. if (_rtgui_cursor->show_cursor == RT_FALSE)
  231. return;
  232. if (_rtgui_cursor->show_cursor_count == 1)
  233. {
  234. /* display the cursor coverage area */
  235. rtgui_cursor_restore();
  236. }
  237. _rtgui_cursor->show_cursor_count --;
  238. }
  239. rt_bool_t rtgui_mouse_is_intersect(rtgui_rect_t* r)
  240. {
  241. return rtgui_rect_is_intersect(&(_rtgui_cursor->rect), r) == RT_EOK? RT_TRUE : RT_FALSE;
  242. }
  243. /* display the saved cursor area to screen */
  244. static void rtgui_cursor_restore()
  245. {
  246. rt_base_t idx, height, cursor_pitch;
  247. rt_uint8_t *cursor_ptr, *fb_ptr;
  248. fb_ptr = _rtgui_cursor->framebuffer + _rtgui_cursor->cy * _rtgui_cursor->screen_pitch
  249. + _rtgui_cursor->cx * _rtgui_cursor->bpp;
  250. cursor_ptr = _rtgui_cursor->cursor_saved;
  251. height = (_rtgui_cursor->cy + _rtgui_cursor->cursor_image->h <
  252. rtgui_graphic_driver_get_default()->height)? _rtgui_cursor->cursor_image->h :
  253. rtgui_graphic_driver_get_default()->height - _rtgui_cursor->cy;
  254. cursor_pitch = (_rtgui_cursor->cx + _rtgui_cursor->cursor_image->w <
  255. rtgui_graphic_driver_get_default()->width)? _rtgui_cursor->cursor_pitch :
  256. (rtgui_graphic_driver_get_default()->width - _rtgui_cursor->cx) * _rtgui_cursor->bpp;
  257. for (idx = 0; idx < height; idx ++)
  258. {
  259. rt_memcpy(fb_ptr, cursor_ptr, cursor_pitch);
  260. fb_ptr += _rtgui_cursor->screen_pitch;
  261. cursor_ptr += _rtgui_cursor->cursor_pitch;
  262. }
  263. }
  264. /* save the cursor coverage area from screen */
  265. static void rtgui_cursor_save()
  266. {
  267. rt_base_t idx, height, cursor_pitch;
  268. rt_uint8_t *cursor_ptr, *fb_ptr;
  269. fb_ptr = _rtgui_cursor->framebuffer + _rtgui_cursor->cy * _rtgui_cursor->screen_pitch +
  270. _rtgui_cursor->cx * _rtgui_cursor->bpp;
  271. cursor_ptr = _rtgui_cursor->cursor_saved;
  272. height = (_rtgui_cursor->cy + _rtgui_cursor->cursor_image->h <
  273. rtgui_graphic_driver_get_default()->height)? _rtgui_cursor->cursor_image->h :
  274. rtgui_graphic_driver_get_default()->height - _rtgui_cursor->cy;
  275. cursor_pitch = (_rtgui_cursor->cx + _rtgui_cursor->cursor_image->w <
  276. rtgui_graphic_driver_get_default()->width)? _rtgui_cursor->cursor_pitch :
  277. (rtgui_graphic_driver_get_default()->width - _rtgui_cursor->cx) * _rtgui_cursor->bpp;
  278. for (idx = 0; idx < height; idx ++)
  279. {
  280. rt_memcpy(cursor_ptr, fb_ptr, cursor_pitch);
  281. fb_ptr += _rtgui_cursor->screen_pitch;
  282. cursor_ptr += _rtgui_cursor->cursor_pitch;
  283. }
  284. }
  285. static void rtgui_cursor_show()
  286. {
  287. rt_uint16_t x, y;
  288. rtgui_color_t* ptr;
  289. rtgui_rect_t rect;
  290. void (*set_pixel) (rtgui_color_t *c, rt_uint16_t x, rt_uint16_t y);
  291. ptr = (rtgui_color_t*) _rtgui_cursor->cursor_image->data;
  292. set_pixel = rtgui_graphic_driver_get_default()->set_pixel;
  293. rtgui_mouse_get_cursor_rect(&rect);
  294. rtgui_rect_moveto(&rect, _rtgui_cursor->cx, _rtgui_cursor->cy);
  295. /* draw each point */
  296. for (y = rect.y1; y < rect.y2; y ++)
  297. {
  298. for (x = rect.x1; x < rect.x2; x++)
  299. {
  300. /* not alpha */
  301. if ((*ptr >> 24) != 255)
  302. {
  303. set_pixel(ptr, x, y);
  304. }
  305. /* move to next color buffer */
  306. ptr ++;
  307. }
  308. }
  309. /* update rect */
  310. rtgui_graphic_driver_get_default()->screen_update(&rect);
  311. }
  312. #endif
  313. void rtgui_winrect_set(struct rtgui_topwin* topwin)
  314. {
  315. /* set win rect show */
  316. _rtgui_cursor->win_rect_show = RT_TRUE;
  317. /* set win rect */
  318. _rtgui_cursor->win_rect = topwin->title == RT_NULL? topwin->extent : RTGUI_WIDGET(topwin->title)->extent;
  319. _rtgui_cursor->topwin = topwin;
  320. }
  321. rt_bool_t rtgui_winrect_moved_done(rtgui_rect_t* winrect, struct rtgui_topwin** topwin)
  322. {
  323. rt_bool_t moved = RT_FALSE;
  324. /* no win rect */
  325. if (winrect == RT_NULL) return RT_FALSE;
  326. /* restore winrect */
  327. if (_rtgui_cursor->win_rect_has_saved)
  328. {
  329. rtgui_winrect_restore();
  330. moved = RT_TRUE;
  331. }
  332. /* clear win rect show */
  333. _rtgui_cursor->win_rect_show = RT_FALSE;
  334. _rtgui_cursor->win_rect_has_saved = RT_FALSE;
  335. /* return win rect */
  336. *winrect = _rtgui_cursor->win_rect;
  337. *topwin = _rtgui_cursor->topwin;
  338. return moved;
  339. }
  340. rt_bool_t rtgui_winrect_is_moved()
  341. {
  342. return _rtgui_cursor->win_rect_show;
  343. }
  344. /* show winrect */
  345. static void rtgui_winrect_show()
  346. {
  347. rt_uint16_t x, y;
  348. rtgui_color_t c;
  349. rtgui_rect_t screen_rect, win_rect, win_rect_inner;
  350. void (*set_pixel) (rtgui_color_t *c, rt_base_t x, rt_base_t y);
  351. c = black;
  352. set_pixel = rtgui_graphic_driver_get_default()->set_pixel;
  353. win_rect = _rtgui_cursor->win_rect;
  354. win_rect_inner = win_rect;
  355. rtgui_rect_inflate(&win_rect_inner, -WIN_MOVE_BORDER);
  356. rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(),
  357. &screen_rect);
  358. rtgui_rect_intersect(&screen_rect, &win_rect);
  359. rtgui_rect_intersect(&screen_rect, &win_rect_inner);
  360. /* draw left */
  361. for (y = win_rect.y1; y < win_rect.y2; y ++)
  362. {
  363. for (x = win_rect.x1; x < win_rect_inner.x1; x++)
  364. if ((x + y) & 0x01) set_pixel(&c, x, y);
  365. }
  366. /* draw right */
  367. for (y = win_rect.y1; y < win_rect.y2; y ++)
  368. {
  369. for (x = win_rect_inner.x2; x < win_rect.x2; x++)
  370. if ((x + y) & 0x01) set_pixel(&c, x, y);
  371. }
  372. /* draw top border */
  373. for (y = win_rect.y1; y < win_rect_inner.y1; y ++)
  374. {
  375. for (x = win_rect_inner.x1; x < win_rect_inner.x2; x++)
  376. if ((x + y) & 0x01) set_pixel(&c, x, y);
  377. }
  378. /* draw bottom border */
  379. for (y = win_rect_inner.y2; y < win_rect.y2; y ++)
  380. {
  381. for (x = win_rect_inner.x1; x < win_rect_inner.x2; x++)
  382. if ((x + y) & 0x01) set_pixel(&c, x, y);
  383. }
  384. /* update rect */
  385. rtgui_graphic_driver_get_default()->screen_update(&win_rect);
  386. }
  387. #define display_direct_memcpy(src, dest, src_pitch, dest_pitch, height, len) \
  388. for (idx = 0; idx < height; idx ++) \
  389. { \
  390. rt_memcpy(dest, src, len); \
  391. src += src_pitch; \
  392. dest += dest_pitch; \
  393. }
  394. static void rtgui_winrect_restore()
  395. {
  396. rt_uint8_t *winrect_ptr, *fb_ptr;
  397. int winrect_pitch, idx;
  398. rtgui_rect_t screen_rect, win_rect;
  399. win_rect = _rtgui_cursor->win_rect;
  400. rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(),
  401. &screen_rect);
  402. rtgui_rect_intersect(&screen_rect, &win_rect);
  403. /* restore winrect left */
  404. fb_ptr = _rtgui_cursor->framebuffer + win_rect.y1 * _rtgui_cursor->screen_pitch +
  405. win_rect.x1 * _rtgui_cursor->bpp;
  406. winrect_ptr = _rtgui_cursor->win_left;
  407. winrect_pitch = WIN_MOVE_BORDER * _rtgui_cursor->bpp;
  408. display_direct_memcpy(winrect_ptr, fb_ptr, winrect_pitch, _rtgui_cursor->screen_pitch,
  409. (win_rect.y2 - win_rect.y1), winrect_pitch);
  410. /* restore winrect right */
  411. fb_ptr = _rtgui_cursor->framebuffer + win_rect.y1 * _rtgui_cursor->screen_pitch +
  412. (win_rect.x2 - WIN_MOVE_BORDER) * _rtgui_cursor->bpp;
  413. winrect_ptr = _rtgui_cursor->win_right;
  414. winrect_pitch = WIN_MOVE_BORDER * _rtgui_cursor->bpp;
  415. display_direct_memcpy(winrect_ptr, fb_ptr, winrect_pitch, _rtgui_cursor->screen_pitch,
  416. (win_rect.y2 - win_rect.y1), winrect_pitch);
  417. /* restore winrect top */
  418. fb_ptr = _rtgui_cursor->framebuffer + win_rect.y1 * _rtgui_cursor->screen_pitch +
  419. (win_rect.x1 + WIN_MOVE_BORDER)* _rtgui_cursor->bpp;
  420. winrect_ptr = _rtgui_cursor->win_top;
  421. winrect_pitch = (win_rect.x2 - win_rect.x1 - 2 * WIN_MOVE_BORDER) * _rtgui_cursor->bpp;
  422. display_direct_memcpy(winrect_ptr, fb_ptr, winrect_pitch, _rtgui_cursor->screen_pitch,
  423. WIN_MOVE_BORDER, winrect_pitch);
  424. /* restore winrect bottom */
  425. fb_ptr = _rtgui_cursor->framebuffer + (win_rect.y2 - WIN_MOVE_BORDER) * _rtgui_cursor->screen_pitch +
  426. (win_rect.x1 + WIN_MOVE_BORDER) * _rtgui_cursor->bpp;
  427. winrect_ptr = _rtgui_cursor->win_bottom;
  428. display_direct_memcpy(winrect_ptr, fb_ptr, winrect_pitch, _rtgui_cursor->screen_pitch,
  429. WIN_MOVE_BORDER, winrect_pitch);
  430. }
  431. static void rtgui_winrect_save()
  432. {
  433. rt_uint8_t *winrect_ptr, *fb_ptr;
  434. int winrect_pitch, idx;
  435. rtgui_rect_t screen_rect, win_rect;
  436. win_rect = _rtgui_cursor->win_rect;
  437. rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(),
  438. &screen_rect);
  439. rtgui_rect_intersect(&screen_rect, &win_rect);
  440. /* set winrect has saved */
  441. _rtgui_cursor->win_rect_has_saved = RT_TRUE;
  442. /* save winrect left */
  443. fb_ptr = _rtgui_cursor->framebuffer + win_rect.y1 * _rtgui_cursor->screen_pitch +
  444. win_rect.x1 * _rtgui_cursor->bpp;
  445. winrect_ptr = _rtgui_cursor->win_left;
  446. winrect_pitch = WIN_MOVE_BORDER * _rtgui_cursor->bpp;
  447. display_direct_memcpy(fb_ptr, winrect_ptr, _rtgui_cursor->screen_pitch, winrect_pitch,
  448. (win_rect.y2 - win_rect.y1), winrect_pitch);
  449. /* save winrect right */
  450. fb_ptr = _rtgui_cursor->framebuffer + win_rect.y1 * _rtgui_cursor->screen_pitch +
  451. (win_rect.x2 - WIN_MOVE_BORDER) * _rtgui_cursor->bpp;
  452. winrect_ptr = _rtgui_cursor->win_right;
  453. winrect_pitch = WIN_MOVE_BORDER * _rtgui_cursor->bpp;
  454. display_direct_memcpy(fb_ptr, winrect_ptr, _rtgui_cursor->screen_pitch, winrect_pitch,
  455. (win_rect.y2 - win_rect.y1), winrect_pitch);
  456. /* save winrect top */
  457. fb_ptr = _rtgui_cursor->framebuffer + win_rect.y1 * _rtgui_cursor->screen_pitch +
  458. (win_rect.x1 + WIN_MOVE_BORDER)* _rtgui_cursor->bpp;
  459. winrect_ptr = _rtgui_cursor->win_top;
  460. winrect_pitch = (win_rect.x2 - win_rect.x1 - 2 * WIN_MOVE_BORDER) * _rtgui_cursor->bpp;
  461. display_direct_memcpy(fb_ptr, winrect_ptr, _rtgui_cursor->screen_pitch, winrect_pitch,
  462. WIN_MOVE_BORDER, winrect_pitch);
  463. /* save winrect bottom */
  464. fb_ptr = _rtgui_cursor->framebuffer + (win_rect.y2 - WIN_MOVE_BORDER) * _rtgui_cursor->screen_pitch +
  465. (win_rect.x1 + WIN_MOVE_BORDER) * _rtgui_cursor->bpp;
  466. winrect_ptr = _rtgui_cursor->win_bottom;
  467. display_direct_memcpy(fb_ptr, winrect_ptr, _rtgui_cursor->screen_pitch, winrect_pitch,
  468. WIN_MOVE_BORDER, winrect_pitch);
  469. }
  470. void rtgui_mouse_monitor_append(rtgui_list_t* head, rtgui_rect_t* rect)
  471. {
  472. struct rtgui_mouse_monitor* mmonitor;
  473. /* check parameters */
  474. if (head == RT_NULL || rect == RT_NULL) return;
  475. /* create a mouse monitor node */
  476. mmonitor = (struct rtgui_mouse_monitor*) rtgui_malloc (sizeof(struct rtgui_mouse_monitor));
  477. if (mmonitor == RT_NULL) return; /* no memory */
  478. /* set mouse monitor node */
  479. mmonitor->rect = *rect;
  480. rtgui_list_init(&(mmonitor->list));
  481. /* append to list */
  482. rtgui_list_append(head, &(mmonitor->list));
  483. }
  484. void rtgui_mouse_monitor_remove(rtgui_list_t* head, rtgui_rect_t* rect)
  485. {
  486. struct rtgui_list_node* node;
  487. struct rtgui_mouse_monitor* mmonitor;
  488. /* check parameters */
  489. if (head == RT_NULL || rect == RT_NULL) return;
  490. for (node = head->next; node != RT_NULL; node = node->next)
  491. {
  492. mmonitor = rtgui_list_entry(node, struct rtgui_mouse_monitor, list);
  493. if (mmonitor->rect.x1 == rect->x1 &&
  494. mmonitor->rect.x2 == rect->x2 &&
  495. mmonitor->rect.y1 == rect->y1 &&
  496. mmonitor->rect.y2 == rect->y2)
  497. {
  498. /* found node */
  499. rtgui_list_remove(head, node);
  500. rtgui_free(mmonitor);
  501. return ;
  502. }
  503. }
  504. }
  505. rt_bool_t rtgui_mouse_monitor_contains_point(rtgui_list_t* head, int x, int y)
  506. {
  507. struct rtgui_list_node* node;
  508. /* check parameter */
  509. if (head == RT_NULL) return RT_FALSE;
  510. rtgui_list_foreach(node, head)
  511. {
  512. struct rtgui_mouse_monitor* monitor = rtgui_list_entry(node,
  513. struct rtgui_mouse_monitor, list);
  514. if (rtgui_rect_contains_point(&(monitor->rect), x, y) == RT_EOK)
  515. {
  516. return RT_TRUE;
  517. }
  518. }
  519. return RT_FALSE;
  520. }