mouse.c 17 KB

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