dc.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952
  1. /*
  2. * File : dc.c
  3. * This file is part of RT-Thread GUI Engine
  4. * COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2009-10-16 Bernard first version
  23. * 2010-09-20 richard modified rtgui_dc_draw_round_rect
  24. * 2010-09-27 Bernard fix draw_mono_bmp issue
  25. * 2011-04-25 Bernard fix fill polygon issue, which found by loveic
  26. */
  27. /* for sin/cos etc */
  28. #include <math.h>
  29. #include <rtgui/dc.h>
  30. #include <rtgui/rtgui_system.h>
  31. #include <rtgui/rtgui_server.h>
  32. #include <rtgui/widgets/window.h>
  33. #include <rtgui/widgets/title.h>
  34. #include <string.h> /* for strlen */
  35. #include <stdlib.h> /* fir qsort */
  36. static int _int_compare(const void *a, const void *b)
  37. {
  38. return (*(const int *) a) - (*(const int *) b);
  39. }
  40. void rtgui_dc_destory(struct rtgui_dc *dc)
  41. {
  42. if (dc == RT_NULL) return;
  43. dc->engine->fini(dc);
  44. rtgui_free(dc);
  45. }
  46. RTM_EXPORT(rtgui_dc_destory);
  47. void rtgui_dc_draw_line(struct rtgui_dc *dc, int x1, int y1, int x2, int y2)
  48. {
  49. if (dc == RT_NULL) return;
  50. if (y1 == y2)
  51. {
  52. rtgui_dc_draw_hline(dc, x1, x2, y1);
  53. }
  54. else if (x1 == x2)
  55. {
  56. rtgui_dc_draw_vline(dc, x1, y1, y2);
  57. }
  58. else
  59. {
  60. int dx, dy, sdx, sdy, dxabs, dyabs, x, y, px, py;
  61. register rt_base_t i;
  62. /* rtgui_rect_t rect; */
  63. dx = x2 - x1; /* the horizontal distance of the line */
  64. dy = y2 - y1; /* the vertical distance of the line */
  65. #define rtgui_sgn(x) ((x<0)?-1:((x>0)?1:0)) /* macro to return the sign of a number */
  66. dxabs = _UI_ABS(dx);
  67. dyabs = _UI_ABS(dy);
  68. sdx = rtgui_sgn(dx);
  69. sdy = rtgui_sgn(dy);
  70. x = dyabs >> 1;
  71. y = dxabs >> 1;
  72. px = x1;
  73. py = y1;
  74. if (dxabs >= dyabs) /* the line is more horizontal than vertical */
  75. {
  76. for (i = 0; i < dxabs; i++)
  77. {
  78. y += dyabs;
  79. if (y >= dxabs)
  80. {
  81. y -= dxabs;
  82. py += sdy;
  83. }
  84. px += sdx;
  85. /* draw this point */
  86. rtgui_dc_draw_point(dc, px, py);
  87. }
  88. }
  89. else /* the line is more vertical than horizontal */
  90. {
  91. for (i = 0; i < dyabs; i++)
  92. {
  93. x += dxabs;
  94. if (x >= dyabs)
  95. {
  96. x -= dyabs;
  97. px += sdx;
  98. }
  99. py += sdy;
  100. /* draw this point */
  101. rtgui_dc_draw_point(dc, px, py);
  102. }
  103. }
  104. }
  105. }
  106. RTM_EXPORT(rtgui_dc_draw_line);
  107. void rtgui_dc_draw_horizontal_line(struct rtgui_dc *dc, int x1, int x2, int y)
  108. {
  109. rtgui_color_t color;
  110. if (dc == RT_NULL) return ;
  111. /* save old color */
  112. color = RTGUI_DC_FC(dc);
  113. RTGUI_DC_FC(dc) = dark_grey;
  114. rtgui_dc_draw_hline(dc, x1, x2, y);
  115. y ++;
  116. RTGUI_DC_FC(dc) = high_light;
  117. rtgui_dc_draw_hline(dc, x1, x2, y);
  118. /* restore color */
  119. RTGUI_DC_FC(dc) = color;
  120. }
  121. RTM_EXPORT(rtgui_dc_draw_horizontal_line);
  122. void rtgui_dc_draw_vertical_line(struct rtgui_dc *dc, int x, int y1, int y2)
  123. {
  124. rtgui_color_t color;
  125. if (dc == RT_NULL) return ;
  126. /* save old color */
  127. color = RTGUI_DC_FC(dc);
  128. RTGUI_DC_FC(dc) = dark_grey;
  129. rtgui_dc_draw_vline(dc, x, y1, y2);
  130. x ++;
  131. RTGUI_DC_FC(dc) = high_light;
  132. rtgui_dc_draw_vline(dc, x, y1, y2);
  133. /* restore color */
  134. RTGUI_DC_FC(dc) = color;
  135. }
  136. RTM_EXPORT(rtgui_dc_draw_vertical_line);
  137. void rtgui_dc_draw_rect(struct rtgui_dc *dc, struct rtgui_rect *rect)
  138. {
  139. rtgui_dc_draw_hline(dc, rect->x1, rect->x2, rect->y1);
  140. rtgui_dc_draw_hline(dc, rect->x1, rect->x2, rect->y2 - 1);
  141. rtgui_dc_draw_vline(dc, rect->x1, rect->y1, rect->y2);
  142. rtgui_dc_draw_vline(dc, rect->x2 - 1, rect->y1, rect->y2);
  143. }
  144. RTM_EXPORT(rtgui_dc_draw_rect);
  145. void rtgui_dc_fill_rect_forecolor(struct rtgui_dc *dc, struct rtgui_rect *rect)
  146. {
  147. rtgui_color_t save_color;
  148. /*save the background color of dc*/
  149. save_color = RTGUI_DC_BC(dc);
  150. /*set the background color to fore color*/
  151. RTGUI_DC_BC(dc) = RTGUI_DC_FC(dc);
  152. dc->engine->fill_rect(dc, rect);
  153. /*restore the background color of dc*/
  154. RTGUI_DC_BC(dc) = save_color;
  155. }
  156. RTM_EXPORT(rtgui_dc_fill_rect_forecolor);
  157. void rtgui_dc_draw_round_rect(struct rtgui_dc *dc, struct rtgui_rect *rect, int r)
  158. {
  159. RT_ASSERT(((rect->x2 - rect->x1) / 2 >= r) && ((rect->y2 - rect->y1) / 2 >= r));
  160. if (r < 0)
  161. {
  162. return;
  163. }
  164. if (r == 0)
  165. {
  166. rtgui_dc_draw_rect(dc, rect);
  167. return;
  168. }
  169. if (((rect->x2 - rect->x1) / 2 >= r) && ((rect->y2 - rect->y1) / 2 >= r))
  170. {
  171. rtgui_dc_draw_arc(dc, rect->x1 + r, rect->y1 + r, r, 180, 270);
  172. rtgui_dc_draw_arc(dc, rect->x2 - r, rect->y1 + r, r, 270, 360);
  173. rtgui_dc_draw_arc(dc, rect->x1 + r, rect->y2 - r, r, 90, 180);
  174. rtgui_dc_draw_arc(dc, rect->x2 - r, rect->y2 - r, r, 0, 90);
  175. rtgui_dc_draw_hline(dc, rect->x1 + r, rect->x2 - r, rect->y1);
  176. rtgui_dc_draw_hline(dc, rect->x1 + r, rect->x2 - r, rect->y2);
  177. rtgui_dc_draw_vline(dc, rect->x1, rect->y1 + r, rect->y2 - r);
  178. rtgui_dc_draw_vline(dc, rect->x2, rect->y1 + r, rect->y2 - r);
  179. }
  180. }
  181. RTM_EXPORT(rtgui_dc_draw_round_rect);
  182. void rtgui_dc_fill_round_rect(struct rtgui_dc *dc, struct rtgui_rect *rect, int r)
  183. {
  184. struct rtgui_rect rect_temp;
  185. RT_ASSERT(((rect->x2 - rect->x1) / 2 >= r) && ((rect->y2 - rect->y1) / 2 >= r));
  186. if (((rect->x2 - rect->x1) / 2 >= r) && ((rect->y2 - rect->y1) / 2 >= r))
  187. {
  188. rect_temp.x1 = rect->x1 + r;
  189. rect_temp.y1 = rect->y1;
  190. rect_temp.x2 = rect->x2 - r;
  191. rect_temp.y2 = rect->y2;
  192. rtgui_dc_fill_rect_forecolor(dc, &rect_temp);//fill rect with foreground
  193. rect_temp.x1 = rect->x1;
  194. rect_temp.y1 = rect->y1 + r;
  195. rect_temp.x2 = rect->x1 + r;
  196. rect_temp.y2 = rect->y2 - r;
  197. rtgui_dc_fill_rect_forecolor(dc, &rect_temp);//fill rect with foreground
  198. rect_temp.x1 = rect->x2 - r;
  199. rect_temp.y1 = rect->y1 + r;
  200. rect_temp.x2 = rect->x2;
  201. rect_temp.y2 = rect->y2 - r;
  202. rtgui_dc_fill_rect_forecolor(dc, &rect_temp);//fill rect with foreground
  203. rtgui_dc_fill_circle(dc, rect->x1 + r, rect->y1 + r, r);
  204. rtgui_dc_fill_circle(dc, rect->x2 - r, rect->y2 - r, r);
  205. rtgui_dc_fill_circle(dc, rect->x2 - r, rect->y1 + r, r);
  206. rtgui_dc_fill_circle(dc, rect->x1 + r, rect->y2 - r, r);
  207. }
  208. }
  209. RTM_EXPORT(rtgui_dc_fill_round_rect);
  210. void rtgui_dc_draw_shaded_rect(struct rtgui_dc *dc, rtgui_rect_t *rect,
  211. rtgui_color_t c1, rtgui_color_t c2)
  212. {
  213. RT_ASSERT(dc != RT_NULL);
  214. RTGUI_DC_FC(dc) = c1;
  215. rtgui_dc_draw_vline(dc, rect->x1, rect->y1, rect->y2);
  216. rtgui_dc_draw_hline(dc, rect->x1 + 1, rect->x2, rect->y1);
  217. RTGUI_DC_FC(dc) = c2;
  218. rtgui_dc_draw_vline(dc, rect->x2 - 1, rect->y1, rect->y2);
  219. rtgui_dc_draw_hline(dc, rect->x1, rect->x2, rect->y2 - 1);
  220. }
  221. RTM_EXPORT(rtgui_dc_draw_shaded_rect);
  222. void rtgui_dc_fill_gradient_rectv(struct rtgui_dc *dc, rtgui_rect_t *rect,
  223. rtgui_color_t c1, rtgui_color_t c2)
  224. {
  225. int y, step;
  226. rtgui_color_t fc;
  227. RT_ASSERT(dc != RT_NULL);
  228. RT_ASSERT(rect != RT_NULL);
  229. step = rtgui_rect_height(*rect);
  230. fc = RTGUI_DC_FC(dc);
  231. for (y = rect->y1; y < rect->y2; y++)
  232. {
  233. RTGUI_DC_FC(dc) = RTGUI_ARGB(((int)RTGUI_RGB_A(c2) - RTGUI_RGB_A(c1)) * (y - rect->y1) / step + RTGUI_RGB_A(c1),
  234. ((int)RTGUI_RGB_R(c2) - RTGUI_RGB_R(c1)) * (y - rect->y1) / step + RTGUI_RGB_R(c1),
  235. ((int)RTGUI_RGB_G(c2) - RTGUI_RGB_G(c1)) * (y - rect->y1) / step + RTGUI_RGB_G(c1),
  236. ((int)RTGUI_RGB_B(c2) - RTGUI_RGB_B(c1)) * (y - rect->y1) / step + RTGUI_RGB_B(c1));
  237. rtgui_dc_draw_hline(dc, rect->x1, rect->x2, y);
  238. }
  239. RTGUI_DC_FC(dc) = fc;
  240. }
  241. RTM_EXPORT(rtgui_dc_fill_gradient_rectv);
  242. void rtgui_dc_draw_focus_rect(struct rtgui_dc *dc, rtgui_rect_t *rect)
  243. {
  244. int x, y;
  245. for (x = rect->x1; x < rect->x2 - 1; x += 2)
  246. {
  247. rtgui_dc_draw_point(dc, x, rect->y1);
  248. rtgui_dc_draw_point(dc, x, rect->y2 - 1);
  249. }
  250. for (y = rect->y1; y < rect->y2; y += 2)
  251. {
  252. rtgui_dc_draw_point(dc, rect->x1, y);
  253. rtgui_dc_draw_point(dc, rect->x2 - 1, y);
  254. }
  255. }
  256. RTM_EXPORT(rtgui_dc_draw_focus_rect);
  257. void rtgui_dc_draw_text(struct rtgui_dc *dc, const char *text, struct rtgui_rect *rect)
  258. {
  259. rt_uint32_t len;
  260. struct rtgui_font *font;
  261. struct rtgui_rect text_rect;
  262. RT_ASSERT(dc != RT_NULL);
  263. font = RTGUI_DC_FONT(dc);
  264. if (font == RT_NULL)
  265. {
  266. /* use system default font */
  267. font = rtgui_font_default();
  268. }
  269. /* text align */
  270. rtgui_font_get_metrics(font, text, &text_rect);
  271. rtgui_rect_moveto_align(rect, &text_rect, RTGUI_DC_TEXTALIGN(dc));
  272. len = strlen((const char *)text);
  273. rtgui_font_draw(font, dc, text, len, &text_rect);
  274. }
  275. RTM_EXPORT(rtgui_dc_draw_text);
  276. void rtgui_dc_draw_text_stroke(struct rtgui_dc *dc, const char *text, struct rtgui_rect *rect,
  277. rtgui_color_t color_stroke, rtgui_color_t color_core)
  278. {
  279. int x, y;
  280. rtgui_rect_t r;
  281. rtgui_color_t fc;
  282. RT_ASSERT(dc != RT_NULL);
  283. fc = RTGUI_DC_FC(dc);
  284. RTGUI_DC_FC(dc) = color_stroke;
  285. for (x = -1; x < 2; x++)
  286. {
  287. for (y = -1; y < 2; y++)
  288. {
  289. r = *rect;
  290. rtgui_rect_moveto(&r, x, y);
  291. rtgui_dc_draw_text(dc, text, &r);
  292. }
  293. }
  294. RTGUI_DC_FC(dc) = color_core;
  295. rtgui_dc_draw_text(dc, text, rect);
  296. RTGUI_DC_FC(dc) = fc;
  297. }
  298. RTM_EXPORT(rtgui_dc_draw_text_stroke);
  299. /*
  300. * draw a monochrome color bitmap data
  301. */
  302. void rtgui_dc_draw_mono_bmp(struct rtgui_dc *dc, int x, int y, int w, int h, const rt_uint8_t *data)
  303. {
  304. int i, j, k;
  305. /* get word bytes */
  306. w = (w + 7) / 8;
  307. /* draw mono bitmap data */
  308. for (i = 0; i < h; i ++)
  309. for (j = 0; j < w; j++)
  310. for (k = 0; k < 8; k++)
  311. if (((data[i * w + j] >> (7 - k)) & 0x01) != 0)
  312. rtgui_dc_draw_point(dc, x + 8 * j + k, y + i);
  313. }
  314. RTM_EXPORT(rtgui_dc_draw_mono_bmp);
  315. void rtgui_dc_draw_byte(struct rtgui_dc *dc, int x, int y, int h, const rt_uint8_t *data)
  316. {
  317. rtgui_dc_draw_mono_bmp(dc, x, y, 8, h, data);
  318. }
  319. RTM_EXPORT(rtgui_dc_draw_byte);
  320. void rtgui_dc_draw_word(struct rtgui_dc *dc, int x, int y, int h, const rt_uint8_t *data)
  321. {
  322. rtgui_dc_draw_mono_bmp(dc, x, y, 16, h, data);
  323. }
  324. RTM_EXPORT(rtgui_dc_draw_word);
  325. void rtgui_dc_draw_border(struct rtgui_dc *dc, rtgui_rect_t *rect, int flag)
  326. {
  327. rtgui_rect_t r;
  328. rtgui_color_t color;
  329. if (dc == RT_NULL) return ;
  330. /* save old color */
  331. color = RTGUI_DC_FC(dc);
  332. r = *rect;
  333. switch (flag)
  334. {
  335. case RTGUI_BORDER_RAISE:
  336. rtgui_dc_draw_shaded_rect(dc, &r, high_light, black);
  337. rtgui_rect_inflate(&r, -1);
  338. rtgui_dc_draw_shaded_rect(dc, &r, light_grey, dark_grey);
  339. break;
  340. case RTGUI_BORDER_SUNKEN:
  341. rtgui_dc_draw_shaded_rect(dc, &r, dark_grey, high_light);
  342. rtgui_rect_inflate(&r, -1);
  343. rtgui_dc_draw_shaded_rect(dc, &r, black, light_grey);
  344. break;
  345. case RTGUI_BORDER_BOX:
  346. rtgui_dc_draw_shaded_rect(dc, &r, dark_grey, high_light);
  347. rtgui_rect_inflate(&r, -1);
  348. rtgui_dc_draw_shaded_rect(dc, &r, high_light, dark_grey);
  349. break;
  350. case RTGUI_BORDER_STATIC:
  351. rtgui_dc_draw_shaded_rect(dc, &r, dark_grey, high_light);
  352. break;
  353. case RTGUI_BORDER_EXTRA:
  354. RTGUI_DC_FC(dc) = light_grey;
  355. rtgui_dc_draw_rect(dc, &r);
  356. break;
  357. case RTGUI_BORDER_SIMPLE:
  358. RTGUI_DC_FC(dc) = black;
  359. rtgui_dc_draw_rect(dc, &r);
  360. break;
  361. default:
  362. break;
  363. }
  364. /* restore color */
  365. RTGUI_DC_FC(dc) = color;
  366. }
  367. RTM_EXPORT(rtgui_dc_draw_border);
  368. void rtgui_dc_draw_polygon(struct rtgui_dc *dc, const int *vx, const int *vy, int count)
  369. {
  370. int i;
  371. const int *x1, *y1, *x2, *y2;
  372. /*
  373. * Sanity check
  374. */
  375. if (count < 3) return;
  376. /*
  377. * Pointer setup
  378. */
  379. x1 = x2 = vx;
  380. y1 = y2 = vy;
  381. x2++;
  382. y2++;
  383. /*
  384. * Draw
  385. */
  386. for (i = 1; i < count; i++)
  387. {
  388. rtgui_dc_draw_line(dc, *x1, *y1, *x2, *y2);
  389. x1 = x2;
  390. y1 = y2;
  391. x2++;
  392. y2++;
  393. }
  394. rtgui_dc_draw_line(dc, *x1, *y1, *vx, *vy);
  395. }
  396. RTM_EXPORT(rtgui_dc_draw_polygon);
  397. void rtgui_dc_fill_polygon(struct rtgui_dc *dc, const int *vx, const int *vy, int count)
  398. {
  399. int i;
  400. int y, xa, xb;
  401. int miny, maxy;
  402. int x1, y1;
  403. int x2, y2;
  404. int ind1, ind2;
  405. int ints;
  406. int *poly_ints = RT_NULL;
  407. /*
  408. * Sanity check number of edges
  409. */
  410. if (count < 3) return;
  411. /*
  412. * Allocate temp array, only grow array
  413. */
  414. poly_ints = (int *) rtgui_malloc(sizeof(int) * count);
  415. if (poly_ints == RT_NULL) return ; /* no memory, failed */
  416. /*
  417. * Determine Y maximal
  418. */
  419. miny = vy[0];
  420. maxy = vy[0];
  421. for (i = 1; (i < count); i++)
  422. {
  423. if (vy[i] < miny) miny = vy[i];
  424. else if (vy[i] > maxy) maxy = vy[i];
  425. }
  426. /*
  427. * Draw, scanning y
  428. */
  429. for (y = miny; (y <= maxy); y++)
  430. {
  431. ints = 0;
  432. for (i = 0; (i < count); i++)
  433. {
  434. if (!i)
  435. {
  436. ind1 = count - 1;
  437. ind2 = 0;
  438. }
  439. else
  440. {
  441. ind1 = i - 1;
  442. ind2 = i;
  443. }
  444. y1 = vy[ind1];
  445. y2 = vy[ind2];
  446. if (y1 < y2)
  447. {
  448. x1 = vx[ind1];
  449. x2 = vx[ind2];
  450. }
  451. else if (y1 > y2)
  452. {
  453. y2 = vy[ind1];
  454. y1 = vy[ind2];
  455. x2 = vx[ind1];
  456. x1 = vx[ind2];
  457. }
  458. else
  459. {
  460. continue;
  461. }
  462. if (((y >= y1) && (y < y2)) || ((y == maxy) && (y > y1) && (y <= y2)))
  463. {
  464. poly_ints[ints++] = ((65536 * (y - y1)) / (y2 - y1)) * (x2 - x1) + (65536 * x1);
  465. }
  466. }
  467. qsort(poly_ints, ints, sizeof(int), _int_compare);
  468. for (i = 0; (i < ints); i += 2)
  469. {
  470. xa = poly_ints[i] + 1;
  471. xa = (xa >> 16) + ((xa & 32768) >> 15);
  472. xb = poly_ints[i + 1] - 1;
  473. xb = (xb >> 16) + ((xb & 32768) >> 15);
  474. rtgui_dc_draw_hline(dc, xa, xb, y);
  475. }
  476. }
  477. /* release memory */
  478. rtgui_free(poly_ints);
  479. }
  480. RTM_EXPORT(rtgui_dc_fill_polygon);
  481. void rtgui_dc_draw_circle(struct rtgui_dc *dc, int x, int y, int r)
  482. {
  483. rtgui_dc_draw_ellipse(dc, x, y, r, r);
  484. }
  485. RTM_EXPORT(rtgui_dc_draw_circle);
  486. enum
  487. {
  488. QUARTER_BTM,
  489. QUARTER_BTM_LEFT,
  490. QUARTER_BTM_RIGHT,
  491. QUARTER_TOP,
  492. QUARTER_TOP_LEFT,
  493. QUARTER_TOP_RIGHT,
  494. QUARTER_FULL,
  495. };
  496. static void _fill_quarter_circle(struct rtgui_dc *dc,
  497. rt_int16_t ox, rt_int16_t oy,
  498. rt_int16_t rad, int quadrant)
  499. {
  500. /* Midpoint circle algorithm. */
  501. int dk, x, y;
  502. dk = 1 - rad;
  503. x = 0;
  504. y = rad;
  505. while (x <= y)
  506. {
  507. switch (quadrant)
  508. {
  509. case QUARTER_BTM:
  510. rtgui_dc_draw_hline(dc, ox - x, ox + x, oy + y);
  511. rtgui_dc_draw_hline(dc, ox - y, ox + y, oy + x);
  512. break;
  513. case QUARTER_BTM_LEFT:
  514. rtgui_dc_draw_hline(dc, ox, ox + x, oy + y);
  515. rtgui_dc_draw_hline(dc, ox, ox + y, oy + x);
  516. break;
  517. case QUARTER_BTM_RIGHT:
  518. rtgui_dc_draw_hline(dc, ox, ox - x, oy + y);
  519. rtgui_dc_draw_hline(dc, ox, ox - y, oy + x);
  520. break;
  521. case QUARTER_TOP_RIGHT:
  522. rtgui_dc_draw_hline(dc, ox, ox - x, oy - y);
  523. rtgui_dc_draw_hline(dc, ox, ox - y, oy - x);
  524. break;
  525. case QUARTER_TOP_LEFT:
  526. rtgui_dc_draw_hline(dc, ox, ox + x, oy - y);
  527. rtgui_dc_draw_hline(dc, ox, ox + y, oy - x);
  528. break;
  529. case QUARTER_TOP:
  530. rtgui_dc_draw_hline(dc, ox - x, ox + x, oy - y);
  531. rtgui_dc_draw_hline(dc, ox - y, ox + y, oy - x);
  532. break;
  533. case QUARTER_FULL:
  534. rtgui_dc_draw_hline(dc, ox - x, ox + x, oy + y);
  535. rtgui_dc_draw_hline(dc, ox - y, ox + y, oy + x);
  536. rtgui_dc_draw_hline(dc, ox - x, ox + x, oy - y);
  537. rtgui_dc_draw_hline(dc, ox - y, ox + y, oy - x);
  538. break;
  539. default:
  540. RT_ASSERT(0);
  541. };
  542. if (dk > 0)
  543. {
  544. y--;
  545. dk += 2 * (x - y) + 5;
  546. }
  547. else
  548. {
  549. dk += 2 * x + 3;
  550. }
  551. x++;
  552. }
  553. }
  554. void rtgui_dc_fill_circle(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r)
  555. {
  556. /*
  557. * Sanity check radius
  558. */
  559. if (r < 0)
  560. return;
  561. /*
  562. * Special case for r=0 - draw a point
  563. */
  564. if (r == 0)
  565. {
  566. rtgui_dc_draw_point(dc, x, y);
  567. return;
  568. }
  569. _fill_quarter_circle(dc, x, y, r, QUARTER_FULL);
  570. }
  571. RTM_EXPORT(rtgui_dc_fill_circle);
  572. void rtgui_dc_draw_arc(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r, rt_int16_t start, rt_int16_t end)
  573. {
  574. rt_int16_t cx = 0;
  575. rt_int16_t cy = r;
  576. rt_int16_t df = 1 - r;
  577. rt_int16_t d_e = 3;
  578. rt_int16_t d_se = -2 * r + 5;
  579. rt_int16_t xpcx, xmcx, xpcy, xmcy;
  580. rt_int16_t ypcy, ymcy, ypcx, ymcx;
  581. rt_uint8_t drawoct;
  582. int startoct, endoct, oct, stopval_start, stopval_end;
  583. double temp;
  584. stopval_start = 0;
  585. stopval_end = 0;
  586. temp = 0;
  587. /* Sanity check radius */
  588. if (r < 0) return ;
  589. /* Special case for r=0 - draw a point */
  590. if (r == 0)
  591. {
  592. rtgui_dc_draw_point(dc, x, y);
  593. return;
  594. }
  595. /*
  596. * Draw arc
  597. * Octant labelling
  598. *
  599. * \ 5 | 6 /
  600. * \ | /
  601. * 4 \ | / 7
  602. * \|/
  603. *------+------ +x
  604. * /|\
  605. * 3 / | \ 0
  606. * / | \
  607. * / 2 | 1 \
  608. * +y
  609. */
  610. drawoct = 0; // 0x00000000
  611. // whether or not to keep drawing a given octant.
  612. // For example: 0x00111100 means we're drawing in octants 2-5
  613. // 0 <= start & end < 360; note that sometimes start > end - if so, arc goes back through 0.
  614. while (start < 0) start += 360;
  615. while (end < 0) end += 360;
  616. /* Fixup angles */
  617. start = start % 360;
  618. end = end % 360;
  619. // now, we find which octants we're drawing in.
  620. startoct = start / 45;
  621. endoct = end / 45;
  622. oct = startoct - 1; // we increment as first step in loop
  623. //stopval_start, stopval_end; // what values of cx to stop at.
  624. do
  625. {
  626. oct = (oct + 1) % 8;
  627. if (oct == startoct)
  628. {
  629. // need to compute stopval_start for this octant. Look at picture above if this is unclear
  630. switch (oct)
  631. {
  632. case 0:
  633. case 3:
  634. temp = sin(start * M_PI / 180);
  635. break;
  636. case 1:
  637. case 6:
  638. temp = cos(start * M_PI / 180);
  639. break;
  640. case 2:
  641. case 5:
  642. temp = -cos(start * M_PI / 180);
  643. break;
  644. case 4:
  645. case 7:
  646. temp = -sin(start * M_PI / 180);
  647. break;
  648. }
  649. temp *= r;
  650. stopval_start = (int)temp; // always round down.
  651. // This isn't arbitrary, but requires graph paper to explain well.
  652. // The basic idea is that we're always changing drawoct after we draw, so we
  653. // stop immediately after we render the last sensible pixel at x = ((int)temp).
  654. // and whether to draw in this octant initially
  655. if (oct % 2) drawoct |= (1 << oct); // this is basically like saying drawoct[oct] = true, if drawoct were a bool array
  656. else drawoct &= 255 - (1 << oct); // this is basically like saying drawoct[oct] = false
  657. }
  658. if (oct == endoct)
  659. {
  660. // need to compute stopval_end for this octant
  661. switch (oct)
  662. {
  663. case 0:
  664. case 3:
  665. temp = sin(end * M_PI / 180);
  666. break;
  667. case 1:
  668. case 6:
  669. temp = cos(end * M_PI / 180);
  670. break;
  671. case 2:
  672. case 5:
  673. temp = -cos(end * M_PI / 180);
  674. break;
  675. case 4:
  676. case 7:
  677. temp = -sin(end * M_PI / 180);
  678. break;
  679. }
  680. temp *= r;
  681. stopval_end = (int)temp;
  682. // and whether to draw in this octant initially
  683. if (startoct == endoct)
  684. {
  685. // note: we start drawing, stop, then start again in this case
  686. // otherwise: we only draw in this octant, so initialize it to false, it will get set back to true
  687. if (start > end)
  688. {
  689. // unfortunately, if we're in the same octant and need to draw over the whole circle,
  690. // we need to set the rest to true, because the while loop will end at the bottom.
  691. drawoct = 255;
  692. }
  693. else
  694. {
  695. drawoct &= 255 - (1 << oct);
  696. }
  697. }
  698. else if (oct % 2) drawoct &= 255 - (1 << oct);
  699. else drawoct |= (1 << oct);
  700. }
  701. else if (oct != startoct) // already verified that it's != endoct
  702. {
  703. drawoct |= (1 << oct); // draw this entire segment
  704. }
  705. }
  706. while (oct != endoct);
  707. // so now we have what octants to draw and when to draw them. all that's left is the actual raster code.
  708. do
  709. {
  710. ypcy = y + cy;
  711. ymcy = y - cy;
  712. if (cx > 0)
  713. {
  714. xpcx = x + cx;
  715. xmcx = x - cx;
  716. // always check if we're drawing a certain octant before adding a pixel to that octant.
  717. if (drawoct & 4) rtgui_dc_draw_point(dc, xmcx, ypcy); // drawoct & 4 = 22; drawoct[2]
  718. if (drawoct & 2) rtgui_dc_draw_point(dc, xpcx, ypcy);
  719. if (drawoct & 32) rtgui_dc_draw_point(dc, xmcx, ymcy);
  720. if (drawoct & 64) rtgui_dc_draw_point(dc, xpcx, ymcy);
  721. }
  722. else
  723. {
  724. if (drawoct & 6) rtgui_dc_draw_point(dc, x, ypcy); // 4 + 2; drawoct[2] || drawoct[1]
  725. if (drawoct & 96) rtgui_dc_draw_point(dc, x, ymcy); // 32 + 64
  726. }
  727. xpcy = x + cy;
  728. xmcy = x - cy;
  729. if (cx > 0 && cx != cy)
  730. {
  731. ypcx = y + cx;
  732. ymcx = y - cx;
  733. if (drawoct & 8) rtgui_dc_draw_point(dc, xmcy, ypcx);
  734. if (drawoct & 1) rtgui_dc_draw_point(dc, xpcy, ypcx);
  735. if (drawoct & 16) rtgui_dc_draw_point(dc, xmcy, ymcx);
  736. if (drawoct & 128) rtgui_dc_draw_point(dc, xpcy, ymcx);
  737. }
  738. else if (cx == 0)
  739. {
  740. if (drawoct & 24) rtgui_dc_draw_point(dc, xmcy, y); // 8 + 16
  741. if (drawoct & 129) rtgui_dc_draw_point(dc, xpcy, y); // 1 + 128
  742. }
  743. /*
  744. * Update whether we're drawing an octant
  745. */
  746. if (stopval_start == cx)
  747. {
  748. // works like an on-off switch because start & end may be in the same octant.
  749. if (drawoct & (1 << startoct)) drawoct &= 255 - (1 << startoct);
  750. else drawoct |= (1 << startoct);
  751. }
  752. if (stopval_end == cx)
  753. {
  754. if (drawoct & (1 << endoct)) drawoct &= 255 - (1 << endoct);
  755. else drawoct |= (1 << endoct);
  756. }
  757. /*
  758. * Update pixels
  759. */
  760. if (df < 0)
  761. {
  762. df += d_e;
  763. d_e += 2;
  764. d_se += 2;
  765. }
  766. else
  767. {
  768. df += d_se;
  769. d_e += 2;
  770. d_se += 4;
  771. cy--;
  772. }
  773. cx++;
  774. }
  775. while (cx <= cy);
  776. }
  777. RTM_EXPORT(rtgui_dc_draw_arc);
  778. void rtgui_dc_draw_annulus(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r1, rt_int16_t r2, rt_int16_t start, rt_int16_t end)
  779. {
  780. rt_int16_t start_x, start_y;
  781. rt_int16_t end_x, end_y;
  782. double temp;
  783. rt_int16_t temp_val = 0;
  784. /* Sanity check radius */
  785. if ((r1 < 0) || (r2 < 0)) return ;
  786. /* Special case for r=0 - draw a point */
  787. if ((r1 == 0) && (r2 == 0))
  788. {
  789. rtgui_dc_draw_point(dc, x, y);
  790. return;
  791. }
  792. while (start < 0) start += 360;
  793. while (end < 0) end += 360;
  794. rtgui_dc_draw_arc(dc, x, y, r1, start, end);
  795. rtgui_dc_draw_arc(dc, x, y, r2, start, end);
  796. temp = cos(start * M_PI / 180);
  797. temp_val = (int)(temp * r1);
  798. start_x = x + temp_val;
  799. temp_val = (int)(temp * r2);
  800. end_x = x + temp_val;
  801. temp = sin(start * M_PI / 180);
  802. temp_val = (int)(temp * r1);
  803. start_y = y + temp_val;
  804. temp_val = (int)(temp * r2);
  805. end_y = y + temp_val;
  806. rtgui_dc_draw_line(dc, start_x, start_y, end_x, end_y);
  807. temp = cos(end * M_PI / 180);
  808. temp_val = (int)(temp * r1);
  809. start_x = x + temp_val;
  810. temp_val = (int)(temp * r2);
  811. end_x = x + temp_val;
  812. temp = sin(end * M_PI / 180);
  813. temp_val = (int)(temp * r1);
  814. start_y = y + temp_val;
  815. temp_val = (int)(temp * r2);
  816. end_y = y + temp_val;
  817. rtgui_dc_draw_line(dc, start_x, start_y, end_x, end_y);
  818. }
  819. RTM_EXPORT(rtgui_dc_draw_annulus);
  820. void rtgui_dc_draw_ellipse(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t rx, rt_int16_t ry)
  821. {
  822. int ix, iy;
  823. int h, i, j, k;
  824. int oh, oi, oj, ok;
  825. int xmh, xph, ypk, ymk;
  826. int xmi, xpi, ymj, ypj;
  827. int xmj, xpj, ymi, ypi;
  828. int xmk, xpk, ymh, yph;
  829. /*
  830. * Sanity check radii
  831. */
  832. if ((rx < 0) || (ry < 0)) return;
  833. /*
  834. * Special case for rx=0 - draw a vline
  835. */
  836. if (rx == 0)
  837. {
  838. rtgui_dc_draw_vline(dc, x, y - ry, y + ry);
  839. return;
  840. }
  841. /*
  842. * Special case for ry=0 - draw a hline
  843. */
  844. if (ry == 0)
  845. {
  846. rtgui_dc_draw_hline(dc, x - rx, x + rx, y);
  847. return;
  848. }
  849. /*
  850. * Init vars
  851. */
  852. oh = oi = oj = ok = 0xFFFF;
  853. if (rx > ry)
  854. {
  855. ix = 0;
  856. iy = rx * 64;
  857. do
  858. {
  859. h = (ix + 32) >> 6;
  860. i = (iy + 32) >> 6;
  861. j = (h * ry) / rx;
  862. k = (i * ry) / rx;
  863. if (((ok != k) && (oj != k)) || ((oj != j) && (ok != j)) || (k != j))
  864. {
  865. xph = x + h;
  866. xmh = x - h;
  867. if (k > 0)
  868. {
  869. ypk = y + k;
  870. ymk = y - k;
  871. rtgui_dc_draw_point(dc, xmh, ypk);
  872. rtgui_dc_draw_point(dc, xph, ypk);
  873. rtgui_dc_draw_point(dc, xmh, ymk);
  874. rtgui_dc_draw_point(dc, xph, ymk);
  875. }
  876. else
  877. {
  878. rtgui_dc_draw_point(dc, xmh, y);
  879. rtgui_dc_draw_point(dc, xph, y);
  880. }
  881. ok = k;
  882. xpi = x + i;
  883. xmi = x - i;
  884. if (j > 0)
  885. {
  886. ypj = y + j;
  887. ymj = y - j;
  888. rtgui_dc_draw_point(dc, xmi, ypj);
  889. rtgui_dc_draw_point(dc, xpi, ypj);
  890. rtgui_dc_draw_point(dc, xmi, ymj);
  891. rtgui_dc_draw_point(dc, xpi, ymj);
  892. }
  893. else
  894. {
  895. rtgui_dc_draw_point(dc, xmi, y);
  896. rtgui_dc_draw_point(dc, xpi, y);
  897. }
  898. oj = j;
  899. }
  900. ix = ix + iy / rx;
  901. iy = iy - ix / rx;
  902. }
  903. while (i > h);
  904. }
  905. else
  906. {
  907. ix = 0;
  908. iy = ry * 64;
  909. do
  910. {
  911. h = (ix + 32) >> 6;
  912. i = (iy + 32) >> 6;
  913. j = (h * rx) / ry;
  914. k = (i * rx) / ry;
  915. if (((oi != i) && (oh != i)) || ((oh != h) && (oi != h) && (i != h)))
  916. {
  917. xmj = x - j;
  918. xpj = x + j;
  919. if (i > 0)
  920. {
  921. ypi = y + i;
  922. ymi = y - i;
  923. rtgui_dc_draw_point(dc, xmj, ypi);
  924. rtgui_dc_draw_point(dc, xpj, ypi);
  925. rtgui_dc_draw_point(dc, xmj, ymi);
  926. rtgui_dc_draw_point(dc, xpj, ymi);
  927. }
  928. else
  929. {
  930. rtgui_dc_draw_point(dc, xmj, y);
  931. rtgui_dc_draw_point(dc, xpj, y);
  932. }
  933. oi = i;
  934. xmk = x - k;
  935. xpk = x + k;
  936. if (h > 0)
  937. {
  938. yph = y + h;
  939. ymh = y - h;
  940. rtgui_dc_draw_point(dc, xmk, yph);
  941. rtgui_dc_draw_point(dc, xpk, yph);
  942. rtgui_dc_draw_point(dc, xmk, ymh);
  943. rtgui_dc_draw_point(dc, xpk, ymh);
  944. }
  945. else
  946. {
  947. rtgui_dc_draw_point(dc, xmk, y);
  948. rtgui_dc_draw_point(dc, xpk, y);
  949. }
  950. oh = h;
  951. }
  952. ix = ix + iy / ry;
  953. iy = iy - ix / ry;
  954. }
  955. while (i > h);
  956. }
  957. }
  958. RTM_EXPORT(rtgui_dc_draw_ellipse);
  959. void rtgui_dc_fill_ellipse(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t rx, rt_int16_t ry)
  960. {
  961. int ix, iy;
  962. int h, i, j, k;
  963. int oh, oi, oj, ok;
  964. int xmh, xph;
  965. int xmi, xpi;
  966. int xmj, xpj;
  967. int xmk, xpk;
  968. /*
  969. * Special case for rx=0 - draw a vline
  970. */
  971. if (rx == 0)
  972. {
  973. rtgui_dc_draw_vline(dc, x, y - ry, y + ry);
  974. return;
  975. }
  976. /* special case for ry=0 - draw a hline */
  977. if (ry == 0)
  978. {
  979. rtgui_dc_draw_hline(dc, x - rx, x + rx, y);
  980. return;
  981. }
  982. /*
  983. * Init vars
  984. */
  985. oh = oi = oj = ok = 0xFFFF;
  986. /*
  987. * Draw
  988. */
  989. if (rx > ry)
  990. {
  991. ix = 0;
  992. iy = rx * 64;
  993. do
  994. {
  995. h = (ix + 32) >> 6;
  996. i = (iy + 32) >> 6;
  997. j = (h * ry) / rx;
  998. k = (i * ry) / rx;
  999. if ((ok != k) && (oj != k))
  1000. {
  1001. xph = x + h;
  1002. xmh = x - h;
  1003. if (k > 0)
  1004. {
  1005. rtgui_dc_draw_hline(dc, xmh, xph, y + k);
  1006. rtgui_dc_draw_hline(dc, xmh, xph, y - k);
  1007. }
  1008. else
  1009. {
  1010. rtgui_dc_draw_hline(dc, xmh, xph, y);
  1011. }
  1012. ok = k;
  1013. }
  1014. if ((oj != j) && (ok != j) && (k != j))
  1015. {
  1016. xmi = x - i;
  1017. xpi = x + i;
  1018. if (j > 0)
  1019. {
  1020. rtgui_dc_draw_hline(dc, xmi, xpi, y + j);
  1021. rtgui_dc_draw_hline(dc, xmi, xpi, y - j);
  1022. }
  1023. else
  1024. {
  1025. rtgui_dc_draw_hline(dc, xmi, xpi, y);
  1026. }
  1027. oj = j;
  1028. }
  1029. ix = ix + iy / rx;
  1030. iy = iy - ix / rx;
  1031. }
  1032. while (i > h);
  1033. }
  1034. else
  1035. {
  1036. ix = 0;
  1037. iy = ry * 64;
  1038. do
  1039. {
  1040. h = (ix + 32) >> 6;
  1041. i = (iy + 32) >> 6;
  1042. j = (h * rx) / ry;
  1043. k = (i * rx) / ry;
  1044. if ((oi != i) && (oh != i))
  1045. {
  1046. xmj = x - j;
  1047. xpj = x + j;
  1048. if (i > 0)
  1049. {
  1050. rtgui_dc_draw_hline(dc, xmj, xpj, y + i);
  1051. rtgui_dc_draw_hline(dc, xmj, xpj, y - i);
  1052. }
  1053. else
  1054. {
  1055. rtgui_dc_draw_hline(dc, xmj, xpj, y);
  1056. }
  1057. oi = i;
  1058. }
  1059. if ((oh != h) && (oi != h) && (i != h))
  1060. {
  1061. xmk = x - k;
  1062. xpk = x + k;
  1063. if (h > 0)
  1064. {
  1065. rtgui_dc_draw_hline(dc, xmk, xpk, y + h);
  1066. rtgui_dc_draw_hline(dc, xmk, xpk, y - h);
  1067. }
  1068. else
  1069. {
  1070. rtgui_dc_draw_hline(dc, xmk, xpk, y);
  1071. }
  1072. oh = h;
  1073. }
  1074. ix = ix + iy / ry;
  1075. iy = iy - ix / ry;
  1076. }
  1077. while (i > h);
  1078. }
  1079. }
  1080. RTM_EXPORT(rtgui_dc_fill_ellipse);
  1081. void rtgui_dc_draw_pie(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t rad, rt_int16_t start, rt_int16_t end)
  1082. {
  1083. double angle, start_angle, end_angle;
  1084. double deltaAngle;
  1085. double dr;
  1086. int numpoints, i;
  1087. int *vx, *vy;
  1088. /* Sanity check radii */
  1089. if (rad < 0) return ;
  1090. /*
  1091. * Fixup angles
  1092. */
  1093. start = start % 360;
  1094. end = end % 360;
  1095. /*
  1096. * Special case for rad=0 - draw a point
  1097. */
  1098. if (rad == 0)
  1099. {
  1100. rtgui_dc_draw_point(dc, x, y);
  1101. return;
  1102. }
  1103. /*
  1104. * Variable setup
  1105. */
  1106. dr = (double) rad;
  1107. deltaAngle = 3.0 / dr;
  1108. start_angle = (double) start * (2.0 * M_PI / 360.0);
  1109. end_angle = (double) end * (2.0 * M_PI / 360.0);
  1110. if (start > end)
  1111. {
  1112. end_angle += (2.0 * M_PI);
  1113. }
  1114. /* We will always have at least 2 points */
  1115. numpoints = 2;
  1116. /* Count points (rather than calculating it) */
  1117. angle = start_angle;
  1118. while (angle < end_angle)
  1119. {
  1120. angle += deltaAngle;
  1121. numpoints++;
  1122. }
  1123. /* Allocate combined vertex array */
  1124. vx = vy = (int *) rtgui_malloc(2 * sizeof(int) * numpoints);
  1125. if (vx == RT_NULL) return ;
  1126. /* Update point to start of vy */
  1127. vy += numpoints;
  1128. /* Center */
  1129. vx[0] = x;
  1130. vy[0] = y;
  1131. /* First vertex */
  1132. angle = start_angle;
  1133. vx[1] = x + (int)(dr * cos(angle));
  1134. vy[1] = y + (int)(dr * sin(angle));
  1135. if (numpoints < 3)
  1136. {
  1137. rtgui_dc_draw_line(dc, vx[0], vy[0], vx[1], vy[1]);
  1138. }
  1139. else
  1140. {
  1141. /* Calculate other vertices */
  1142. i = 2;
  1143. angle = start_angle;
  1144. while (angle < end_angle)
  1145. {
  1146. angle += deltaAngle;
  1147. if (angle > end_angle)
  1148. {
  1149. angle = end_angle;
  1150. }
  1151. vx[i] = x + (int)(dr * cos(angle));
  1152. vy[i] = y + (int)(dr * sin(angle));
  1153. i++;
  1154. }
  1155. /* Draw */
  1156. rtgui_dc_draw_polygon(dc, vx, vy, numpoints);
  1157. }
  1158. /* Free combined vertex array */
  1159. rtgui_free(vx);
  1160. return;
  1161. }
  1162. RTM_EXPORT(rtgui_dc_draw_pie);
  1163. /*
  1164. * Octant labelling
  1165. *
  1166. * \ 5 | 6 /
  1167. * \ | /
  1168. * 4 \ | / 7
  1169. * \|/
  1170. *------+------ +x
  1171. * /|\
  1172. * 3 / | \ 0
  1173. * / | \
  1174. * / 2 | 1 \
  1175. * +y
  1176. */
  1177. static void _draw_octant(struct rtgui_dc *dc,
  1178. rt_int16_t ox, rt_int16_t oy,
  1179. rt_int16_t y1, rt_int16_t y2, rt_int16_t x, int oct)
  1180. {
  1181. switch (oct % 8)
  1182. {
  1183. case 0:
  1184. rtgui_dc_draw_line(dc, ox + x, oy + y1, ox + x, oy + y2);
  1185. break;
  1186. case 1:
  1187. /* Ugly hack to get the edge right. */
  1188. y2 += 1;
  1189. y1 += 1;
  1190. x -= 1;
  1191. rtgui_dc_draw_line(dc, ox + y1, oy + x, ox + y2, oy + x);
  1192. break;
  1193. case 2:
  1194. y2 -= 1;
  1195. y1 -= 1;
  1196. x -= 1;
  1197. rtgui_dc_draw_line(dc, ox - y2, oy + x, ox - y1, oy + x);
  1198. break;
  1199. case 3:
  1200. x -= 1;
  1201. rtgui_dc_draw_line(dc, ox - x, oy + y1, ox - x, oy + y2);
  1202. break;
  1203. case 4:
  1204. x -= 1;
  1205. rtgui_dc_draw_line(dc, ox - x, oy - y2, ox - x, oy - y1);
  1206. break;
  1207. case 5:
  1208. y2 -= 1;
  1209. y1 -= 1;
  1210. rtgui_dc_draw_line(dc, ox - y2, oy - x, ox - y1, oy - x);
  1211. break;
  1212. case 6:
  1213. y2 += 1;
  1214. y1 += 1;
  1215. rtgui_dc_draw_line(dc, ox + y1, oy - x, ox + y2, oy - x);
  1216. break;
  1217. case 7:
  1218. rtgui_dc_draw_line(dc, ox + x, oy - y2, ox + x, oy - y1);
  1219. break;
  1220. };
  1221. }
  1222. static void _fill_small_pie(struct rtgui_dc *dc,
  1223. rt_int16_t ox, rt_int16_t oy,
  1224. rt_int16_t rad, rt_int16_t start, rt_int16_t end,
  1225. int oct)
  1226. {
  1227. /* Midpoint circle algorithm. */
  1228. int dk, x, y;
  1229. /* Start X, end X, */
  1230. rt_int16_t sx, ex, ty, my;
  1231. enum {ST_NONE, ST_ARC, ST_TRI} st;
  1232. RT_ASSERT(0 <= start && start <= 45);
  1233. RT_ASSERT(0 <= end && end <= 45);
  1234. if (start == end)
  1235. return;
  1236. RT_ASSERT(start < end);
  1237. RT_ASSERT(rad > 0);
  1238. /* cos(90 - start) == sin(start) */
  1239. sx = rad * sin(start * M_PI / 180);
  1240. ex = rad * sin(end * M_PI / 180);
  1241. dk = 1 - rad;
  1242. x = 0;
  1243. y = rad;
  1244. st = ST_NONE;
  1245. my = ex;
  1246. while (x <= y)
  1247. {
  1248. rt_int16_t lx;
  1249. if (x < sx)
  1250. {
  1251. }
  1252. else if (x == sx)
  1253. {
  1254. /* Start point. */
  1255. st = ST_ARC;
  1256. ty = y;
  1257. }
  1258. else if (x <= ex)
  1259. {
  1260. /* Between the pie. */
  1261. RT_ASSERT(st == ST_ARC);
  1262. }
  1263. else /* x > ex */
  1264. {
  1265. /* End. */
  1266. st = ST_TRI;
  1267. my = y;
  1268. break;
  1269. }
  1270. /* Drawing. */
  1271. if (st == ST_ARC)
  1272. {
  1273. lx = y * sx / ty;
  1274. /* Change from math coordinate to plot coordinate. */
  1275. _draw_octant(dc, ox, oy, lx, x, y, oct);
  1276. }
  1277. /* Midpoint increment. */
  1278. if (dk > 0)
  1279. {
  1280. y--;
  1281. dk += 2 * (x - y) + 5;
  1282. }
  1283. else
  1284. {
  1285. dk += 2 * x + 3;
  1286. }
  1287. x++;
  1288. }
  1289. /* Draw bottom part. */
  1290. for (; y >= 0; y--)
  1291. {
  1292. rt_int16_t lx, rx;
  1293. lx = y * sx / ty;
  1294. rx = y * ex / my;
  1295. _draw_octant(dc, ox, oy, lx, rx, y, oct);
  1296. }
  1297. }
  1298. void rtgui_dc_fill_pie(struct rtgui_dc *dc,
  1299. rt_int16_t x, rt_int16_t y, rt_int16_t rad,
  1300. rt_int16_t start, rt_int16_t end)
  1301. {
  1302. /* Sanity check radii */
  1303. if (rad < 0)
  1304. return;
  1305. if (rad == 0)
  1306. {
  1307. rtgui_dc_draw_point(dc, x, y);
  1308. return;
  1309. }
  1310. if (end - start >= 360)
  1311. {
  1312. rtgui_dc_fill_circle(dc, x, y, rad);
  1313. return;
  1314. }
  1315. if (start == end)
  1316. return;
  1317. /*
  1318. * Fixup angles
  1319. */
  1320. while (start < 0)
  1321. {
  1322. start += 360;
  1323. end += 360;
  1324. }
  1325. while (start >= 360)
  1326. {
  1327. start -= 360;
  1328. end -= 360;
  1329. }
  1330. if (end < start)
  1331. end += 360;
  1332. while (start / 45 != end / 45)
  1333. {
  1334. /* The start and end are not in the same piece. */
  1335. if ((start / 45) % 2)
  1336. {
  1337. _fill_small_pie(dc, x, y, rad,
  1338. 0, 45 - start % 45, start / 45);
  1339. start += 45 - start % 45;
  1340. }
  1341. else
  1342. {
  1343. _fill_small_pie(dc, x, y, rad,
  1344. start % 45, 45, start / 45);
  1345. start += 45 - start % 45;
  1346. }
  1347. }
  1348. if ((start / 45) % 2)
  1349. {
  1350. _fill_small_pie(dc, x, y, rad,
  1351. 90 - end % 90, 90 - start % 90, start / 45);
  1352. }
  1353. else
  1354. {
  1355. _fill_small_pie(dc, x, y, rad,
  1356. start % 45, end % 45, start / 45);
  1357. }
  1358. return;
  1359. }
  1360. RTM_EXPORT(rtgui_dc_fill_pie);
  1361. /*
  1362. * set gc of dc
  1363. */
  1364. void rtgui_dc_set_gc(struct rtgui_dc *dc, rtgui_gc_t *gc)
  1365. {
  1366. RT_ASSERT(dc != RT_NULL);
  1367. switch (dc->type)
  1368. {
  1369. case RTGUI_DC_CLIENT:
  1370. {
  1371. rtgui_widget_t *owner;
  1372. /* get owner */
  1373. owner = RTGUI_CONTAINER_OF(dc, struct rtgui_widget, dc_type);
  1374. owner->gc = *gc;
  1375. break;
  1376. }
  1377. case RTGUI_DC_HW:
  1378. {
  1379. struct rtgui_dc_hw *dc_hw;
  1380. dc_hw = (struct rtgui_dc_hw *) dc;
  1381. RT_ASSERT(dc_hw->owner != RT_NULL);
  1382. dc_hw->owner->gc = *gc;
  1383. break;
  1384. }
  1385. case RTGUI_DC_BUFFER:
  1386. {
  1387. struct rtgui_dc_buffer *dc_buffer;
  1388. dc_buffer = (struct rtgui_dc_buffer *)dc;
  1389. dc_buffer->gc = *gc;
  1390. break;
  1391. }
  1392. }
  1393. }
  1394. RTM_EXPORT(rtgui_dc_set_gc);
  1395. /*
  1396. * get gc of dc
  1397. */
  1398. rtgui_gc_t *rtgui_dc_get_gc(struct rtgui_dc *dc)
  1399. {
  1400. rtgui_gc_t *gc = RT_NULL;
  1401. RT_ASSERT(dc != RT_NULL);
  1402. switch (dc->type)
  1403. {
  1404. case RTGUI_DC_CLIENT:
  1405. {
  1406. rtgui_widget_t *owner;
  1407. /* get owner */
  1408. owner = RTGUI_CONTAINER_OF(dc, struct rtgui_widget, dc_type);
  1409. gc = &owner->gc;
  1410. break;
  1411. }
  1412. case RTGUI_DC_HW:
  1413. {
  1414. struct rtgui_dc_hw *dc_hw;
  1415. dc_hw = (struct rtgui_dc_hw *) dc;
  1416. RT_ASSERT(dc_hw->owner != RT_NULL);
  1417. gc = &dc_hw->owner->gc;
  1418. break;
  1419. }
  1420. case RTGUI_DC_BUFFER:
  1421. {
  1422. struct rtgui_dc_buffer *dc_buffer;
  1423. dc_buffer = (struct rtgui_dc_buffer *)dc;
  1424. gc = &dc_buffer->gc;
  1425. break;
  1426. }
  1427. }
  1428. return gc;
  1429. }
  1430. RTM_EXPORT(rtgui_dc_get_gc);
  1431. /*
  1432. * get visible status of dc
  1433. */
  1434. rt_bool_t rtgui_dc_get_visible(struct rtgui_dc *dc)
  1435. {
  1436. rt_bool_t result = RT_TRUE;
  1437. RT_ASSERT(dc != RT_NULL);
  1438. if (rtgui_graphic_driver_is_vmode())
  1439. return RT_TRUE;
  1440. switch (dc->type)
  1441. {
  1442. case RTGUI_DC_CLIENT:
  1443. {
  1444. rtgui_widget_t *owner;
  1445. /* get owner */
  1446. owner = RTGUI_CONTAINER_OF(dc, struct rtgui_widget, dc_type);
  1447. if (!RTGUI_WIDGET_IS_DC_VISIBLE(owner)) result = RT_FALSE;
  1448. break;
  1449. }
  1450. case RTGUI_DC_HW:
  1451. {
  1452. struct rtgui_dc_hw *dc_hw;
  1453. dc_hw = (struct rtgui_dc_hw *) dc;
  1454. if (!RTGUI_WIDGET_IS_DC_VISIBLE(dc_hw->owner)) result = RT_FALSE;
  1455. break;
  1456. }
  1457. default:
  1458. /* use default value */
  1459. break;
  1460. }
  1461. return result;
  1462. }
  1463. RTM_EXPORT(rtgui_dc_get_visible);
  1464. /*
  1465. * get rect of dc
  1466. */
  1467. void rtgui_dc_get_rect(struct rtgui_dc *dc, rtgui_rect_t *rect)
  1468. {
  1469. RT_ASSERT(dc != RT_NULL);
  1470. switch (dc->type)
  1471. {
  1472. case RTGUI_DC_CLIENT:
  1473. {
  1474. rtgui_widget_t *owner;
  1475. /* get owner */
  1476. owner = RTGUI_CONTAINER_OF(dc, struct rtgui_widget, dc_type);
  1477. /* we should return the clipped rectangular information */
  1478. rect->x1 = owner->clip.extents.x1 - owner->extent.x1;
  1479. rect->y1 = owner->clip.extents.y1 - owner->extent.y1;
  1480. rect->x2 = rect->x1 + owner->clip.extents.x2 - owner->clip.extents.x1;
  1481. rect->y2 = rect->y1 + owner->clip.extents.y2 - owner->clip.extents.y1;
  1482. // rtgui_widget_get_rect(owner, rect);
  1483. break;
  1484. }
  1485. case RTGUI_DC_HW:
  1486. {
  1487. rtgui_widget_t *owner;
  1488. struct rtgui_dc_hw *dc_hw;
  1489. dc_hw = (struct rtgui_dc_hw *) dc;
  1490. owner = dc_hw->owner;
  1491. rtgui_widget_get_rect(owner, rect);
  1492. break;
  1493. }
  1494. case RTGUI_DC_BUFFER:
  1495. {
  1496. struct rtgui_dc_buffer *dc_buffer;
  1497. dc_buffer = (struct rtgui_dc_buffer *)dc;
  1498. rtgui_rect_init(rect, 0, 0, dc_buffer->width, dc_buffer->height);
  1499. break;
  1500. }
  1501. }
  1502. return;
  1503. }
  1504. RTM_EXPORT(rtgui_dc_get_rect);
  1505. rt_uint8_t rtgui_dc_get_pixel_format(struct rtgui_dc *dc)
  1506. {
  1507. rt_uint8_t pixel_fmt;
  1508. RT_ASSERT(dc != RT_NULL);
  1509. switch (dc->type)
  1510. {
  1511. case RTGUI_DC_CLIENT:
  1512. case RTGUI_DC_HW:
  1513. {
  1514. struct rtgui_graphic_driver *hw_driver;
  1515. hw_driver = rtgui_graphic_driver_get_default();
  1516. pixel_fmt = hw_driver->pixel_format;
  1517. break;
  1518. }
  1519. case RTGUI_DC_BUFFER:
  1520. {
  1521. struct rtgui_dc_buffer *dc_buffer;
  1522. dc_buffer = (struct rtgui_dc_buffer *)dc;
  1523. pixel_fmt = dc_buffer->pixel_format;
  1524. break;
  1525. }
  1526. default:
  1527. RT_ASSERT(0);
  1528. }
  1529. return pixel_fmt;
  1530. }
  1531. RTM_EXPORT(rtgui_dc_get_pixel_format);
  1532. void rtgui_dc_logic_to_device(struct rtgui_dc *dc, struct rtgui_point *point)
  1533. {
  1534. switch (dc->type)
  1535. {
  1536. case RTGUI_DC_CLIENT:
  1537. {
  1538. rtgui_widget_t *owner;
  1539. /* get owner */
  1540. owner = RTGUI_CONTAINER_OF(dc, struct rtgui_widget, dc_type);
  1541. point->x += owner->extent.x1;
  1542. point->y += owner->extent.y1;
  1543. break;
  1544. }
  1545. case RTGUI_DC_HW:
  1546. {
  1547. rtgui_widget_t *owner;
  1548. struct rtgui_dc_hw *dc_hw;
  1549. dc_hw = (struct rtgui_dc_hw *) dc;
  1550. owner = dc_hw->owner;
  1551. point->x += owner->extent.x1;
  1552. point->y += owner->extent.y1;
  1553. break;
  1554. }
  1555. case RTGUI_DC_BUFFER: /* no conversion */
  1556. break;
  1557. }
  1558. }
  1559. RTM_EXPORT(rtgui_dc_logic_to_device);
  1560. void rtgui_dc_rect_to_device(struct rtgui_dc *dc, struct rtgui_rect *rect)
  1561. {
  1562. switch (dc->type)
  1563. {
  1564. case RTGUI_DC_CLIENT:
  1565. {
  1566. rtgui_widget_t *owner;
  1567. /* get owner */
  1568. owner = RTGUI_CONTAINER_OF(dc, struct rtgui_widget, dc_type);
  1569. rtgui_rect_moveto(rect, owner->extent.x1, owner->extent.y1);
  1570. break;
  1571. }
  1572. case RTGUI_DC_HW:
  1573. {
  1574. rtgui_widget_t *owner;
  1575. struct rtgui_dc_hw *dc_hw;
  1576. dc_hw = (struct rtgui_dc_hw *) dc;
  1577. owner = dc_hw->owner;
  1578. rtgui_rect_moveto(rect, owner->extent.x1, owner->extent.y1);
  1579. break;
  1580. }
  1581. case RTGUI_DC_BUFFER: /* no conversion */
  1582. break;
  1583. }
  1584. }
  1585. RTM_EXPORT(rtgui_dc_rect_to_device);
  1586. extern struct rt_mutex cursor_mutex;
  1587. extern void rtgui_mouse_show_cursor(void);
  1588. extern void rtgui_mouse_hide_cursor(void);
  1589. struct rtgui_dc *rtgui_dc_begin_drawing(rtgui_widget_t *owner)
  1590. {
  1591. struct rtgui_dc *dc;
  1592. struct rtgui_widget *widget;
  1593. struct rtgui_win *win;
  1594. RT_ASSERT(owner != RT_NULL);
  1595. win = owner->toplevel;
  1596. if (win == RT_NULL)
  1597. return RT_NULL;
  1598. if (!(win->flag & RTGUI_WIN_FLAG_ACTIVATE) &&
  1599. (win->outer_clip.extents.x1 == win->outer_clip.extents.x2 ||
  1600. win->outer_clip.extents.y1 == win->outer_clip.extents.y2))
  1601. return RT_NULL;
  1602. /* increase drawing count */
  1603. if (win->drawing == 0)
  1604. {
  1605. memset(&(win->drawing_rect), 0x0, sizeof(struct rtgui_rect));
  1606. }
  1607. win->drawing ++;
  1608. /* always drawing on the virtual mode */
  1609. if (rtgui_graphic_driver_is_vmode() == RT_FALSE)
  1610. {
  1611. /* set the initial visible as true */
  1612. RTGUI_WIDGET_DC_SET_VISIBLE(owner);
  1613. /* check the visible of widget */
  1614. widget = owner;
  1615. while (widget != RT_NULL)
  1616. {
  1617. if (RTGUI_WIDGET_IS_HIDE(widget))
  1618. {
  1619. RTGUI_WIDGET_DC_SET_UNVISIBLE(owner);
  1620. win->drawing --;
  1621. return RT_NULL;
  1622. }
  1623. widget = widget->parent;
  1624. }
  1625. }
  1626. rtgui_screen_lock(RT_WAITING_FOREVER);
  1627. /* create client or hardware DC */
  1628. if ((rtgui_region_is_flat(&owner->clip) == RT_EOK) &&
  1629. rtgui_rect_is_equal(&(owner->extent), &(owner->clip.extents)) == RT_EOK)
  1630. dc = rtgui_dc_hw_create(owner);
  1631. else
  1632. dc = rtgui_dc_client_create(owner);
  1633. if (dc == RT_NULL)
  1634. {
  1635. /* restore drawing counter */
  1636. win->drawing--;
  1637. rtgui_screen_unlock();
  1638. }
  1639. else if (win->drawing == 1 && rtgui_graphic_driver_is_vmode() == RT_FALSE)
  1640. {
  1641. #ifdef RTGUI_USING_MOUSE_CURSOR
  1642. rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER);
  1643. rtgui_mouse_hide_cursor();
  1644. #endif
  1645. if (! RTGUI_IS_WINTITLE(win))
  1646. {
  1647. /* send draw begin to server */
  1648. struct rtgui_event_update_begin eupdate;
  1649. RTGUI_EVENT_UPDATE_BEGIN_INIT(&(eupdate));
  1650. eupdate.rect = RTGUI_WIDGET(win)->extent;
  1651. rtgui_server_post_event((struct rtgui_event *)&eupdate, sizeof(eupdate));
  1652. }
  1653. }
  1654. return dc;
  1655. }
  1656. RTM_EXPORT(rtgui_dc_begin_drawing);
  1657. void rtgui_dc_end_drawing(struct rtgui_dc *dc, rt_bool_t update)
  1658. {
  1659. struct rtgui_widget *owner;
  1660. struct rtgui_win *win;
  1661. RT_ASSERT(dc != RT_NULL);
  1662. /* get owner */
  1663. if (dc->type == RTGUI_DC_CLIENT)
  1664. owner = RTGUI_CONTAINER_OF(dc, struct rtgui_widget, dc_type);
  1665. else if (dc->type == RTGUI_DC_HW)
  1666. owner = ((struct rtgui_dc_hw *)dc)->owner;
  1667. else return ; /* bad DC type */
  1668. /* get window */
  1669. win = owner->toplevel;
  1670. /* union drawing rect */
  1671. rtgui_rect_union(&(owner->extent_visiable), &(win->drawing_rect));
  1672. /* decrease drawing counter */
  1673. win->drawing--;
  1674. if (win->drawing == 0)
  1675. {
  1676. /* notify window to handle window update done */
  1677. if (RTGUI_OBJECT(win)->event_handler)
  1678. {
  1679. struct rtgui_event_win_update_end ewin_update;
  1680. RTGUI_EVENT_WIN_UPDATE_END_INIT(&(ewin_update));
  1681. ewin_update.rect = win->drawing_rect;
  1682. RTGUI_OBJECT(win)->event_handler(RTGUI_OBJECT(win), (struct rtgui_event *)&ewin_update);
  1683. }
  1684. if (rtgui_graphic_driver_is_vmode() == RT_FALSE && update)
  1685. {
  1686. #ifdef RTGUI_USING_MOUSE_CURSOR
  1687. rt_mutex_release(&cursor_mutex);
  1688. /* show cursor */
  1689. rtgui_mouse_show_cursor();
  1690. #endif
  1691. if (RTGUI_IS_WINTITLE(win))
  1692. {
  1693. /* update screen */
  1694. rtgui_graphic_driver_screen_update(rtgui_graphic_driver_get_default(),
  1695. &(owner->extent));
  1696. }
  1697. else
  1698. {
  1699. /* send to server for window update */
  1700. struct rtgui_event_update_end eupdate;
  1701. RTGUI_EVENT_UPDATE_END_INIT(&(eupdate));
  1702. eupdate.rect = owner->extent;
  1703. rtgui_server_post_event((struct rtgui_event *)&eupdate, sizeof(eupdate));
  1704. }
  1705. }
  1706. }
  1707. dc->engine->fini(dc);
  1708. rtgui_screen_unlock();
  1709. }
  1710. RTM_EXPORT(rtgui_dc_end_drawing);