GUIDEMO_AntialiasedText.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /*********************************************************************
  2. * SEGGER Microcontroller GmbH & Co. KG *
  3. * Solutions for real time microcontroller applications *
  4. **********************************************************************
  5. * *
  6. * (c) 1996 - 2015 SEGGER Microcontroller GmbH & Co. KG *
  7. * *
  8. * Internet: www.segger.com Support: support@segger.com *
  9. * *
  10. **********************************************************************
  11. ** emWin V5.32 - Graphical user interface for embedded applications **
  12. All Intellectual Property rights in the Software belongs to SEGGER.
  13. emWin is protected by international copyright laws. Knowledge of the
  14. source code may not be used to write a similar product. This file may
  15. only be used in accordance with the following terms:
  16. The software has been licensed to STMicroelectronics International
  17. N.V. a Dutch company with a Swiss branch and its headquarters in Plan-
  18. les-Ouates, Geneva, 39 Chemin du Champ des Filles, Switzerland for the
  19. purposes of creating libraries for ARM Cortex-M-based 32-bit microcon_
  20. troller products commercialized by Licensee only, sublicensed and dis_
  21. tributed under the terms and conditions of the End User License Agree_
  22. ment supplied by STMicroelectronics International N.V.
  23. Full source code is available at: www.segger.com
  24. We appreciate your understanding and fairness.
  25. ----------------------------------------------------------------------
  26. Licensing information
  27. Licensor: SEGGER Software GmbH
  28. Licensed to: STMicroelectronics International NV
  29. Licensed SEGGER software: emWin
  30. License number: GUI-00429
  31. License model: Buyout SRC [Buyout Source Code License, signed November 29th 2012]
  32. Licensed product: -
  33. Licensed platform: STMs ARM Cortex-M based 32 BIT CPUs
  34. Licensed number of seats: -
  35. ----------------------------------------------------------------------
  36. File : AA_Text.c
  37. Purpose : Shows text with different antialiasing qualities
  38. ----------------------------------------------------------------------
  39. */
  40. #include "GUIDEMO.h"
  41. #if (SHOW_GUIDEMO_AATEXT)
  42. /*********************************************************************
  43. *
  44. * Defines
  45. *
  46. **********************************************************************
  47. */
  48. #define BORDER 3
  49. /*********************************************************************
  50. *
  51. * Static code
  52. *
  53. **********************************************************************
  54. */
  55. /*********************************************************************
  56. *
  57. * _DrawAlphaCircles
  58. */
  59. static void _DrawAlphaCircles(int mx, int my, int r, int a, int FactorAA) {
  60. int Index;
  61. int x;
  62. int y;
  63. I32 SinHQ;
  64. I32 CosHQ;
  65. U32 a1000;
  66. U32 i;
  67. const GUI_COLOR aColor[] = {
  68. #if (GUI_USE_ARGB)
  69. 0x3F38FF0F,
  70. 0x3F8EFF00,
  71. 0x3FEAFC00,
  72. 0x3FFFB400,
  73. 0x3FFF4E00,
  74. 0x3FFF0413,
  75. 0x3FFF006E,
  76. 0x3FFF00D2,
  77. 0x3FD200FF,
  78. 0x3F6E00FF,
  79. 0x3F1304FF,
  80. 0x3F004EFF,
  81. 0x3F00B4FF,
  82. 0x3F00FCEA,
  83. 0x3F00FF8E,
  84. 0x3F0FFF38
  85. #else
  86. 0xC00FFF38,
  87. 0xC000FF8E,
  88. 0xC000FCEA,
  89. 0xC000B4FF,
  90. 0xC0004EFF,
  91. 0xC01304FF,
  92. 0xC06E00FF,
  93. 0xC0D200FF,
  94. 0xC0FF00D2,
  95. 0xC0FF006E,
  96. 0xC0FF0413,
  97. 0xC0FF4E00,
  98. 0xC0FFB400,
  99. 0xC0EAFC00,
  100. 0xC08EFF00,
  101. 0xC038FF0F
  102. #endif
  103. };
  104. mx *= FactorAA;
  105. my *= FactorAA;
  106. r *= FactorAA;
  107. a1000 = a * -1000;
  108. GUI_AA_EnableHiRes();
  109. GUI_AA_SetFactor(FactorAA);
  110. for (i = 0, Index = 0; i < 360000; i += 22500, Index++) {
  111. SinHQ = GUI__SinHQ(i + a1000);
  112. CosHQ = GUI__CosHQ(i + a1000);
  113. x = SHIFT_RIGHT_16(r * CosHQ);
  114. y = SHIFT_RIGHT_16(r * SinHQ);
  115. GUI_SetColor(
  116. aColor[Index % (int)GUI_COUNTOF(aColor)]);
  117. GUI_AA_FillCircle(mx + x, my + y, r);
  118. }
  119. GUI_AA_DisableHiRes();
  120. }
  121. /*********************************************************************
  122. *
  123. * _DrawSample
  124. */
  125. static void _DrawSample(GUI_RECT Rect, const GUI_FONT * pFont, const char * pText) {
  126. GUI_RECT CurrentRect;
  127. int yDistDiv3;
  128. Rect.x0 += BORDER;
  129. Rect.y0 += BORDER;
  130. Rect.x1 -= BORDER;
  131. Rect.y1 -= BORDER;
  132. yDistDiv3 = (Rect.y1 - Rect.y0) / 3;
  133. CurrentRect.x0 = Rect.x0;
  134. CurrentRect.y0 = Rect.y0;
  135. CurrentRect.x1 = Rect.x0 + 59;
  136. CurrentRect.y1 = Rect.y0 + 3 * yDistDiv3;
  137. //
  138. // Display info text
  139. //
  140. GUI_SetFont(GUI_FONT_13_ASCII);
  141. GUI_SetColor(GUI_WHITE);
  142. GUI_DispStringInRectWrap(pText, &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER, GUI_WRAPMODE_WORD);
  143. //
  144. // Alpha circles
  145. //
  146. GUI_MoveRect(&CurrentRect, 63, 0);
  147. GUI_SetColor(GUI_BLACK);
  148. GUI_FillRectEx(&CurrentRect);
  149. GUI_SetClipRect(&CurrentRect);
  150. _DrawAlphaCircles((CurrentRect.x0 + CurrentRect.x1) / 2, (CurrentRect.y0 + CurrentRect.y1) / 2, 35, 0, 4);
  151. GUI_SetClipRect(NULL);
  152. GUI_SetColor(GUI_WHITE);
  153. GUI_SetFont(pFont);
  154. CurrentRect.y1 = CurrentRect.y0 + yDistDiv3;
  155. GUI_DispStringInRect("ABC", &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  156. GUI_MoveRect(&CurrentRect, 0, yDistDiv3);
  157. GUI_DispStringInRect("ABC", &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  158. GUI_MoveRect(&CurrentRect, 0, yDistDiv3);
  159. GUI_DispStringInRect("ABC", &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  160. //
  161. // Black to white gradient
  162. //
  163. CurrentRect.y0 = Rect.y0;
  164. CurrentRect.y1 = Rect.y0 + 3 * yDistDiv3;
  165. GUI_MoveRect(&CurrentRect, 63, 0);
  166. GUI_DrawGradientH(CurrentRect.x0, CurrentRect.y0, CurrentRect.x1, CurrentRect.y1, GUI_BLACK, GUI_WHITE);
  167. CurrentRect.y1 = CurrentRect.y0 + yDistDiv3;
  168. GUI_SetColor(GUI_RED);
  169. GUI_DispStringInRect("ABC", &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  170. GUI_MoveRect(&CurrentRect, 0, yDistDiv3);
  171. GUI_SetColor(GUI_GREEN);
  172. GUI_DispStringInRect("ABC", &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  173. GUI_MoveRect(&CurrentRect, 0, yDistDiv3);
  174. GUI_SetColor(GUI_BLUE);
  175. GUI_DispStringInRect("ABC", &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  176. //
  177. // RGB
  178. //
  179. CurrentRect.y0 = Rect.y0;
  180. CurrentRect.y1 = CurrentRect.y0 + yDistDiv3;
  181. GUI_MoveRect(&CurrentRect, 63, 0);
  182. GUI_SetColor(GUI_RED);
  183. GUI_FillRectEx(&CurrentRect);
  184. GUI_MoveRect(&CurrentRect, 0, yDistDiv3);
  185. GUI_SetColor(GUI_GREEN);
  186. GUI_FillRectEx(&CurrentRect);
  187. GUI_MoveRect(&CurrentRect, 0, yDistDiv3);
  188. GUI_SetColor(GUI_BLUE);
  189. GUI_FillRectEx(&CurrentRect);
  190. GUI_SetColor(GUI_WHITE);
  191. CurrentRect.y0 = Rect.y0;
  192. CurrentRect.y1 = CurrentRect.y0 + yDistDiv3;
  193. GUI_DispStringInRect("ABC", &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  194. GUI_MoveRect(&CurrentRect, 0, yDistDiv3);
  195. GUI_DispStringInRect("ABC", &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  196. GUI_MoveRect(&CurrentRect, 0, yDistDiv3);
  197. GUI_DispStringInRect("ABC", &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  198. //
  199. // RGB gradients
  200. //
  201. CurrentRect.y0 = Rect.y0;
  202. CurrentRect.y1 = CurrentRect.y0 + yDistDiv3;
  203. GUI_MoveRect(&CurrentRect, 63, 0);
  204. GUI_DrawGradientV(CurrentRect.x0, CurrentRect.y0, CurrentRect.x1, CurrentRect.y1, GUI_RED, GUI_BLACK);
  205. GUI_MoveRect(&CurrentRect, 0, yDistDiv3);
  206. GUI_DrawGradientV(CurrentRect.x0, CurrentRect.y0, CurrentRect.x1, CurrentRect.y1, GUI_GREEN, GUI_BLACK);
  207. GUI_MoveRect(&CurrentRect, 0, yDistDiv3);
  208. GUI_DrawGradientV(CurrentRect.x0, CurrentRect.y0, CurrentRect.x1, CurrentRect.y1, GUI_BLUE, GUI_BLACK);
  209. CurrentRect.y0 = Rect.y0;
  210. CurrentRect.y1 = CurrentRect.y0 + yDistDiv3;
  211. GUI_SetColor(GUI_WHITE);
  212. GUI_DispStringInRect("ABC", &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  213. GUI_MoveRect(&CurrentRect, 0, yDistDiv3);
  214. GUI_DispStringInRect("ABC", &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  215. GUI_MoveRect(&CurrentRect, 0, yDistDiv3);
  216. GUI_DispStringInRect("ABC", &CurrentRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
  217. //
  218. // Disable application defined clip rectangle
  219. //
  220. GUI_SetClipRect(NULL);
  221. }
  222. /*********************************************************************
  223. *
  224. * _DrawScreen
  225. */
  226. static void _DrawScreen(void) {
  227. GUI_RECT Rect;
  228. int TitleSize;
  229. int xSize;
  230. int ySize;
  231. int xOff;
  232. int yOff;
  233. xSize = LCD_GetXSize();
  234. ySize = LCD_GetYSize();
  235. if ((xSize < XSIZE_MIN) || (ySize < YSIZE_MIN)) {
  236. GUIDEMO_ConfigureDemo("Antialiased text", "This demo requires a screen\r\nresolution of QVGA at least.\r\n\r\nThe next demo will start in a moment...", GUIDEMO_SHOW_CURSOR | GUIDEMO_SHOW_CONTROL);
  237. return;
  238. }
  239. GUIDEMO_ConfigureDemo("Antialiased text", "Output antialiased text\non different backgrounds.", GUIDEMO_SHOW_CURSOR | GUIDEMO_SHOW_CONTROL);
  240. GUIDEMO_DrawBk();
  241. GUIDEMO_DispTitle("Antialiased text");
  242. TitleSize = GUIDEMO_GetTitleSizeY();
  243. xOff = (xSize - XSIZE_MIN) / 2;
  244. yOff = ((ySize - TitleSize) - (YSIZE_MIN - TitleSize)) / 2;
  245. //
  246. // 4 bit anti-aliasing sample
  247. //
  248. Rect.x0 = xOff;
  249. Rect.y0 = TitleSize + yOff;
  250. Rect.x1 = xSize - xOff;
  251. Rect.y1 = TitleSize + (ySize - TitleSize) / 2 - 1;
  252. _DrawSample(Rect, &GUI_FontAA4_32, "Antialiased text\n(4 bpp)");
  253. //
  254. // 2 bit anti-aliasing sample
  255. //
  256. Rect.y0 = Rect.y1 + 1;
  257. Rect.y1 = ySize - yOff;
  258. _DrawSample(Rect, &GUI_FontAA2_32, "Antialiased text\n(2 bpp)");
  259. GUIDEMO_Wait(4000);
  260. }
  261. /*********************************************************************
  262. *
  263. * Public code
  264. *
  265. **********************************************************************
  266. */
  267. /*********************************************************************
  268. *
  269. * GUIDEMO_AntialiasedText
  270. */
  271. void GUIDEMO_AntialiasedText(void) {
  272. unsigned OldAlphaState;
  273. OldAlphaState = GUI_EnableAlpha(1);
  274. _DrawScreen();
  275. GUI_EnableAlpha(OldAlphaState);
  276. }
  277. #else
  278. void GUIDEMO_AntialiasedText_C(void);
  279. void GUIDEMO_AntialiasedText_C(void) {}
  280. #endif // SHOW_GUIDEMO_AATEXT
  281. /*************************** End of file ****************************/