1
0

mouse.c 17 KB

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