GUIDEMO_ColorBar.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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_ColorBar.c
  28. Purpose : Draws color bars
  29. ----------------------------------------------------------------------
  30. */
  31. /**
  32. ******************************************************************************
  33. * @file GUIDEMO_ColorBar.c
  34. * @author MCD Application Team
  35. * @brief Draws color bars
  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. /*********************************************************************
  77. *
  78. * GUIDEMO_ShowColorBar
  79. *
  80. **********************************************************************
  81. */
  82. #if (SHOW_GUIDEMO_COLORBAR)
  83. #define GRADIENT_START_X 60
  84. #define Y_START 43
  85. #define Y_STEP 10
  86. #define TIME_PAUSE 500
  87. #define TIME_STEP 500
  88. #define TIME_RUN (TIME_PAUSE + TIME_STEP) * 6
  89. void GUIDEMO_ColorBar(void) {
  90. GUI_COLOR ColorStartBlack, ColorStartWhite;
  91. char acText[80] = { 0 };
  92. int NumColors, BitsPerPixel, xSize, ySize;
  93. int Time, TimeStart;
  94. int Dir, Index;
  95. xSize = LCD_GetXSize();
  96. ySize = LCD_GetYSize();
  97. GUIDEMO_ShowIntro("Color bar",
  98. "STemWin features an integrated\n"
  99. "color management which automatically finds\n"
  100. "the best available color for any logical color");
  101. GUIDEMO_DrawBk(1);
  102. //
  103. // Heading
  104. //
  105. GUI_SetColor(GUI_WHITE);
  106. GUI_SetFont(&GUI_FontRounded22);
  107. GUI_DispStringHCenterAt("Color bars", xSize >> 1, 12);
  108. GUI_SetFont(&GUI_Font16_ASCII);
  109. //
  110. // Colors
  111. //
  112. GUI_DispStringAt("Red", 1, Y_START);
  113. GUI_DispStringAt("Green", 1, Y_START + Y_STEP * 2);
  114. GUI_DispStringAt("Blue", 1, Y_START + Y_STEP * 4);
  115. GUI_DispStringAt("Grey", 1, Y_START + Y_STEP * 5 + (Y_STEP >> 1));
  116. GUI_DispStringAt("Yellow", 1, Y_START + Y_STEP * 7);
  117. GUI_DispStringAt("Cyan", 1, Y_START + Y_STEP * 9);
  118. GUI_DispStringAt("Magenta", 1, Y_START + Y_STEP * 11);
  119. //
  120. // Additional Information
  121. //
  122. GUI_SetFont(&GUI_Font8_ASCII);
  123. //
  124. // LCD Controller
  125. //
  126. #ifdef LCD_CONTROLLER
  127. GUIDEMO_AddStringToString(acText, "LCD Controller: ");
  128. GUIDEMO_AddStringToString(acText, LCD_CONTROLLER);
  129. GUI_DispStringAt (acText, 12, ySize - 45);
  130. GUIDEMO_ClearText (acText);
  131. #endif
  132. //
  133. // BPP and number of colors
  134. //
  135. BitsPerPixel = LCD_GetBitsPerPixel();
  136. GUIDEMO_AddIntToString (acText, BitsPerPixel);
  137. GUIDEMO_AddStringToString(acText, " bpp");
  138. NumColors = LCD_GetDevCap(LCD_DEVCAP_NUMCOLORS);
  139. if (NumColors) {
  140. GUIDEMO_AddStringToString(acText, ", ");
  141. GUIDEMO_AddIntToString (acText, NumColors);
  142. GUIDEMO_AddStringToString(acText, " colors");
  143. }
  144. GUI_DispStringAt(acText, 12, ySize - 25);
  145. //
  146. // Gradients
  147. //
  148. TimeStart = GUIDEMO_GetTime();
  149. while (((GUIDEMO_GetTime() - TimeStart) < TIME_RUN) && (GUIDEMO_CheckCancel() == 0)) {
  150. Time = (GUIDEMO_GetTime() - TimeStart) % ((TIME_PAUSE + TIME_STEP) << 1);
  151. Dir = Time / (TIME_PAUSE + TIME_STEP);
  152. Time -= Dir * (TIME_PAUSE + TIME_STEP);
  153. if (Time > TIME_PAUSE) {
  154. continue;
  155. }
  156. Index = ((Time * 0xFF) / TIME_STEP) ^ (Dir * 0xFF);
  157. ColorStartBlack = 0x000000 + 0x010101 * Index;
  158. ColorStartWhite = 0xFFFFFF - ColorStartBlack;
  159. GUI_DrawGradientH(GRADIENT_START_X, Y_START + Y_STEP * 0, xSize, (Y_START + Y_STEP * 1) - 1, GUI_RED, ColorStartBlack);
  160. GUI_DrawGradientH(GRADIENT_START_X, Y_START + Y_STEP * 1, xSize, (Y_START + Y_STEP * 2) - 1, GUI_RED, ColorStartWhite);
  161. GUI_DrawGradientH(GRADIENT_START_X, Y_START + Y_STEP * 2, xSize, (Y_START + Y_STEP * 3) - 1, GUI_GREEN, ColorStartBlack);
  162. GUI_DrawGradientH(GRADIENT_START_X, Y_START + Y_STEP * 3, xSize, (Y_START + Y_STEP * 4) - 1, GUI_GREEN, ColorStartWhite);
  163. GUI_DrawGradientH(GRADIENT_START_X, Y_START + Y_STEP * 4, xSize, (Y_START + Y_STEP * 5) - 1, GUI_BLUE, ColorStartBlack);
  164. GUI_DrawGradientH(GRADIENT_START_X, Y_START + Y_STEP * 5, xSize, (Y_START + Y_STEP * 6) - 1, GUI_BLUE, ColorStartWhite);
  165. GUI_DrawGradientH(GRADIENT_START_X, Y_START + Y_STEP * 6, xSize, (Y_START + Y_STEP * 7) - 1, GUI_GRAY, ColorStartBlack);
  166. GUI_DrawGradientH(GRADIENT_START_X, Y_START + Y_STEP * 7, xSize, (Y_START + Y_STEP * 8) - 1, GUI_YELLOW, ColorStartWhite);
  167. GUI_DrawGradientH(GRADIENT_START_X, Y_START + Y_STEP * 8, xSize, (Y_START + Y_STEP * 9) - 1, GUI_YELLOW, ColorStartBlack);
  168. GUI_DrawGradientH(GRADIENT_START_X, Y_START + Y_STEP * 9, xSize, (Y_START + Y_STEP * 10) - 1, GUI_CYAN, ColorStartWhite);
  169. GUI_DrawGradientH(GRADIENT_START_X, Y_START + Y_STEP * 10, xSize, (Y_START + Y_STEP * 11) - 1, GUI_CYAN, ColorStartBlack);
  170. GUI_DrawGradientH(GRADIENT_START_X, Y_START + Y_STEP * 11, xSize, (Y_START + Y_STEP * 12) - 1, GUI_MAGENTA, ColorStartWhite);
  171. GUI_DrawGradientH(GRADIENT_START_X, Y_START + Y_STEP * 12, xSize, (Y_START + Y_STEP * 13) - 1, GUI_MAGENTA, ColorStartBlack);
  172. GUI_Exec();
  173. }
  174. }
  175. #else
  176. void GUIDEMO_ColorBar(void) {}
  177. #endif
  178. /*************************** End of file ****************************/