GUIDEMO_Cursor.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*********************************************************************
  2. * Portions COPYRIGHT 2016 STMicroelectronics *
  3. * Portions SEGGER Microcontroller GmbH & Co. KG *
  4. * Solutions for real time microcontroller applications *
  5. **********************************************************************
  6. * *
  7. * (c) 1996 - 2015 SEGGER Microcontroller GmbH & Co. KG *
  8. * *
  9. * Internet: www.segger.com Support: support@segger.com *
  10. * *
  11. **********************************************************************
  12. ** emWin V5.28 - Graphical user interface for embedded applications **
  13. All Intellectual Property rights in the Software belongs to SEGGER.
  14. emWin is protected by international copyright laws. Knowledge of the
  15. source code may not be used to write a similar product. This file may
  16. only be used in accordance with the following terms:
  17. The software has been licensed to STMicroelectronics International
  18. N.V. a Dutch company with a Swiss branch and its headquarters in Plan-
  19. les-Ouates, Geneva, 39 Chemin du Champ des Filles, Switzerland for the
  20. purposes of creating libraries for ARM Cortex-M-based 32-bit microcon_
  21. troller products commercialized by Licensee only, sublicensed and dis_
  22. tributed under the terms and conditions of the End User License Agree_
  23. ment supplied by STMicroelectronics International N.V.
  24. Full source code is available at: www.segger.com
  25. We appreciate your understanding and fairness.
  26. ----------------------------------------------------------------------
  27. File : GUIDEMO_Cursor.c
  28. Purpose : shows Cursor-API
  29. ----------------------------------------------------------------------
  30. */
  31. /**
  32. ******************************************************************************
  33. * @file GUIDEMO_Cursor.c
  34. * @author MCD Application Team
  35. * @brief shows Cursor-API
  36. ******************************************************************************
  37. * @attention
  38. *
  39. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics International N.V.
  40. * All rights reserved.</center></h2>
  41. *
  42. * Redistribution and use in source and binary forms, with or without
  43. * modification, are permitted, provided that the following conditions are met:
  44. *
  45. * 1. Redistribution of source code must retain the above copyright notice,
  46. * this list of conditions and the following disclaimer.
  47. * 2. Redistributions in binary form must reproduce the above copyright notice,
  48. * this list of conditions and the following disclaimer in the documentation
  49. * and/or other materials provided with the distribution.
  50. * 3. Neither the name of STMicroelectronics nor the names of other
  51. * contributors to this software may be used to endorse or promote products
  52. * derived from this software without specific written permission.
  53. * 4. This software, including modifications and/or derivative works of this
  54. * software, must execute solely and exclusively on microcontroller or
  55. * microprocessor devices manufactured by or for STMicroelectronics.
  56. * 5. Redistribution and use of this software other than as permitted under
  57. * this license is void and will automatically terminate your rights under
  58. * this license.
  59. *
  60. * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
  61. * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
  62. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  63. * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  64. * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
  65. * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  66. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  67. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  68. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  69. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  70. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  71. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  72. *
  73. ******************************************************************************
  74. */
  75. #include "GUIDEMO.h"
  76. #if (SHOW_GUIDEMO_CURSOR && GUI_SUPPORT_CURSOR && GUI_SUPPORT_TOUCH)
  77. /*********************************************************************
  78. *
  79. * defines
  80. *
  81. **********************************************************************
  82. */
  83. #define countof(Obj) (sizeof(Obj)/sizeof(Obj[0]))
  84. #define NUM_CURSORS 3
  85. #define XMAX 28
  86. /*********************************************************************
  87. *
  88. * types
  89. *
  90. **********************************************************************
  91. */
  92. typedef struct {
  93. const GUI_CURSOR* pCursor;
  94. char Size;
  95. } CURSOR_INFO;
  96. typedef struct {
  97. const CURSOR_INFO aCursor[NUM_CURSORS];
  98. const char* pType;
  99. } CURSORTYPE_INFO;
  100. /*********************************************************************
  101. *
  102. * static data
  103. *
  104. **********************************************************************
  105. */
  106. static const CURSORTYPE_INFO _CursorArrow = {
  107. &GUI_CursorArrowS, 'S',
  108. &GUI_CursorArrowM, 'M',
  109. #if (NUM_CURSORS == 3)
  110. &GUI_CursorArrowL, 'L',
  111. "arrow cursors"
  112. #else
  113. "arrow\ncursors"
  114. #endif
  115. };
  116. static const CURSORTYPE_INFO _CursorArrowI = {
  117. &GUI_CursorArrowSI, 'S',
  118. &GUI_CursorArrowMI, 'M',
  119. #if (NUM_CURSORS == 3)
  120. &GUI_CursorArrowLI, 'L',
  121. "inverted arrow cursors"
  122. #else
  123. "inverted\narrow cursors"
  124. #endif
  125. };
  126. static const CURSORTYPE_INFO _CursorCross = {
  127. &GUI_CursorCrossS, 'S',
  128. &GUI_CursorCrossM, 'M',
  129. #if (NUM_CURSORS == 3)
  130. &GUI_CursorCrossL, 'L',
  131. "cross cursors"
  132. #else
  133. "cross\ncursors"
  134. #endif
  135. };
  136. static const CURSORTYPE_INFO _CursorCrossI = {
  137. &GUI_CursorCrossSI, 'S',
  138. &GUI_CursorCrossMI, 'M',
  139. #if (NUM_CURSORS == 3)
  140. &GUI_CursorCrossLI, 'L',
  141. "inverted cross cursors"
  142. #else
  143. "inverted\ncross cursors"
  144. #endif
  145. };
  146. /*********************************************************************
  147. *
  148. * static code
  149. *
  150. **********************************************************************
  151. */
  152. /*********************************************************************
  153. *
  154. * _ShowCursorType
  155. */
  156. static void _ShowCursorType(const CURSORTYPE_INFO* pCursorType, int x0, int y0) {
  157. const GUI_CURSOR * pCursor;
  158. char Char;
  159. int i, x, y;
  160. int yMax = 0;
  161. int yHot = 0;
  162. //
  163. // Calculate height and width of biggest cursor
  164. //
  165. for (i = 0; i < NUM_CURSORS; i++) {
  166. pCursor = pCursorType->aCursor[i].pCursor;
  167. if (pCursor->pBitmap->YSize > yMax) {
  168. yMax = pCursor->pBitmap->YSize;
  169. yHot = pCursor->yHot;
  170. }
  171. }
  172. GUI_SetFont(&GUI_FontRounded16);
  173. #if (NUM_CURSORS != 3)
  174. GUI_SetLBorder(x0);
  175. #endif
  176. GUI_DispStringAt(pCursorType->pType, x0, y0);
  177. y0 += GUI_GetFontDistY() + 1;
  178. GUI_SetFont(&GUI_Font13B_ASCII);
  179. for (i = 0; i < NUM_CURSORS; i++) {
  180. pCursor = pCursorType->aCursor[i].pCursor;
  181. Char = pCursorType->aCursor[i].Size;
  182. y = y0 + yHot - pCursor->yHot;
  183. x = ((pCursor->pBitmap->XSize - GUI_GetCharDistX(Char)) >> 1);
  184. GUI_DrawBitmap(pCursor->pBitmap, x0 + XMAX * i + 5, y);
  185. GUI_DispCharAt(Char, x0 + XMAX * i + 5 + x, y0 + yMax + 2);
  186. }
  187. }
  188. /*********************************************************************
  189. *
  190. * _DispCursor
  191. */
  192. static void _DispCursor(void) {
  193. int y0, dx, dy, xSize;
  194. xSize = LCD_GetXSize();
  195. GUI_SetTextMode(GUI_TM_TRANS);
  196. GUI_SetFont(&GUI_FontRounded22);
  197. GUI_DispStringHCenterAt("Available cursors", xSize >> 1, 12);
  198. //
  199. // Display the cursors
  200. //
  201. y0 = 68;
  202. dx = (int)(xSize / 2.5);
  203. dy = 75;
  204. _ShowCursorType(&_CursorArrow, 5, y0);
  205. _ShowCursorType(&_CursorCross, 5, y0 + dy);
  206. _ShowCursorType(&_CursorArrowI, dx, y0);
  207. _ShowCursorType(&_CursorCrossI, dx, y0 + dy);
  208. }
  209. /*********************************************************************
  210. *
  211. * public code
  212. *
  213. **********************************************************************
  214. */
  215. /*********************************************************************
  216. *
  217. * GUIDEMO_Cursor
  218. */
  219. void GUIDEMO_Cursor(void) {
  220. GUIDEMO_ShowIntro("Cursor",
  221. "STemWin supports\n"
  222. "software cursor");
  223. GUIDEMO_DrawBk(1);
  224. GUI_CURSOR_Hide();
  225. _DispCursor();
  226. GUIDEMO_Wait(4000);
  227. GUI_CURSOR_Show();
  228. GUI_CURSOR_SetPosition(0,0);
  229. GUI_CURSOR_Select(&GUI_CursorArrowM);
  230. }
  231. #else
  232. void GUIDEMO_Cursor(void) {}
  233. #endif
  234. /*************************** End of file ****************************/