GUIDEMO_Cursor.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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 : GUIDEMO_Cursor.c
  37. Purpose : shows Cursor-API
  38. ----------------------------------------------------------------------
  39. */
  40. #include "GUIDEMO.h"
  41. #if (SHOW_GUIDEMO_CURSOR && GUI_SUPPORT_CURSOR)
  42. /*********************************************************************
  43. *
  44. * Defines
  45. *
  46. **********************************************************************
  47. */
  48. #define NUM_CURSORS 3
  49. #define XMAX 28
  50. /*********************************************************************
  51. *
  52. * Types
  53. *
  54. **********************************************************************
  55. */
  56. typedef struct {
  57. const GUI_CURSOR * pCursor;
  58. char Size;
  59. } CURSOR_INFO;
  60. typedef struct {
  61. CURSOR_INFO aCursor[NUM_CURSORS];
  62. const char * pType;
  63. } CURSORTYPE_INFO;
  64. /*********************************************************************
  65. *
  66. * Static data
  67. *
  68. **********************************************************************
  69. */
  70. static const CURSORTYPE_INFO _CursorArrow = {
  71. {
  72. {&GUI_CursorArrowS, 'S'},
  73. {&GUI_CursorArrowM, 'M'},
  74. #if (NUM_CURSORS == 3)
  75. {&GUI_CursorArrowL, 'L'},
  76. },
  77. "arrow cursors"
  78. #else
  79. },
  80. "arrow\ncursors"
  81. #endif
  82. };
  83. static const CURSORTYPE_INFO _CursorArrowI = {
  84. {
  85. {&GUI_CursorArrowSI, 'S'},
  86. {&GUI_CursorArrowMI, 'M'},
  87. #if (NUM_CURSORS == 3)
  88. {&GUI_CursorArrowLI, 'L'},
  89. },
  90. "inverted arrow cursors"
  91. #else
  92. },
  93. "inverted\narrow cursors"
  94. #endif
  95. };
  96. static const CURSORTYPE_INFO _CursorCross = {
  97. {
  98. {&GUI_CursorCrossS, 'S'},
  99. {&GUI_CursorCrossM, 'M'},
  100. #if (NUM_CURSORS == 3)
  101. {&GUI_CursorCrossL, 'L'},
  102. },
  103. "cross cursors"
  104. #else
  105. },
  106. "cross\ncursors"
  107. #endif
  108. };
  109. static const CURSORTYPE_INFO _CursorCrossI = {
  110. {
  111. {&GUI_CursorCrossSI, 'S'},
  112. {&GUI_CursorCrossMI, 'M'},
  113. #if (NUM_CURSORS == 3)
  114. {&GUI_CursorCrossLI, 'L'},
  115. },
  116. "inverted cross cursors"
  117. #else
  118. },
  119. "inverted\ncross cursors"
  120. #endif
  121. };
  122. static int _ScreenX0;
  123. static int _ScreenY0;
  124. /*********************************************************************
  125. *
  126. * Static code
  127. *
  128. **********************************************************************
  129. */
  130. /*********************************************************************
  131. *
  132. * _ShowCursorType
  133. */
  134. static void _ShowCursorType(const CURSORTYPE_INFO* pCursorType, int x0, int y0) {
  135. const GUI_CURSOR * pCursor;
  136. char Char;
  137. int yMax;
  138. int yHot;
  139. int i;
  140. int x;
  141. int y;
  142. yMax = 0;
  143. yHot = 0;
  144. //
  145. // Calculate height and width of biggest cursor
  146. //
  147. for (i = 0; i < NUM_CURSORS; i++) {
  148. pCursor = pCursorType->aCursor[i].pCursor;
  149. if (pCursor->pBitmap->YSize > yMax) {
  150. yMax = pCursor->pBitmap->YSize;
  151. yHot = pCursor->yHot;
  152. }
  153. }
  154. GUI_SetFont(&GUI_FontRounded16);
  155. #if (NUM_CURSORS != 3)
  156. GUI_SetLBorder(x0);
  157. #endif
  158. GUI_DispStringAt(pCursorType->pType, x0, y0);
  159. y0 += GUI_GetFontDistY() + 1;
  160. GUI_SetFont(&GUI_Font13B_ASCII);
  161. for (i = 0; i < NUM_CURSORS; i++) {
  162. pCursor = pCursorType->aCursor[i].pCursor;
  163. Char = pCursorType->aCursor[i].Size;
  164. y = y0 + yHot - pCursor->yHot;
  165. x = ((pCursor->pBitmap->XSize - GUI_GetCharDistX(Char)) / 2);
  166. GUI_DrawBitmap(pCursor->pBitmap, x0 + XMAX * i + 5, y);
  167. GUI_DispCharAt(Char, x0 + XMAX * i + 5 + x, y0 + yMax + 2);
  168. }
  169. }
  170. /*********************************************************************
  171. *
  172. * _DispCursor
  173. */
  174. static void _DispCursor(void) {
  175. int xSize;
  176. int ySize;
  177. xSize = LCD_GetXSize();
  178. ySize = LCD_GetYSize();
  179. _ScreenX0 = (xSize - XSIZE_MIN) / 2;
  180. _ScreenY0 = (ySize - YSIZE_MIN) / 2;
  181. GUIDEMO_DrawBk();
  182. GUI_SetTextMode(GUI_TM_TRANS);
  183. GUI_SetFont(&GUI_FontRounded22);
  184. GUI_DispStringHCenterAt("Available cursors", xSize / 2, 12);
  185. //
  186. // Display the cursors
  187. //
  188. _ShowCursorType(&_CursorArrow, _ScreenX0 + 20, _ScreenY0 + 50);
  189. _ShowCursorType(&_CursorCross, _ScreenX0 + 20, _ScreenY0 + 120);
  190. _ShowCursorType(&_CursorArrowI, _ScreenX0 + 140, _ScreenY0 + 50);
  191. _ShowCursorType(&_CursorCrossI, _ScreenX0 + 140, _ScreenY0 + 120);
  192. GUIDEMO_Wait(4000);
  193. GUI_CURSOR_Select(&GUI_CursorArrowM);
  194. GUI_CURSOR_Hide();
  195. }
  196. /*********************************************************************
  197. *
  198. * Public code
  199. *
  200. **********************************************************************
  201. */
  202. /*********************************************************************
  203. *
  204. * GUIDEMO_Cursor
  205. */
  206. void GUIDEMO_Cursor(void) {
  207. GUIDEMO_ConfigureDemo("Cursor", "STemWin supports\nsoftware cursors", GUIDEMO_SHOW_CURSOR | GUIDEMO_SHOW_CONTROL);
  208. _DispCursor();
  209. }
  210. #else
  211. void GUIDEMO_Cursor_C(void);
  212. void GUIDEMO_Cursor_C(void) {}
  213. #endif // SHOW_GUIDEMO_CURSOR && GUI_SUPPORT_CURSOR
  214. /*************************** End of file ****************************/