GUIDEMO_ColorBar.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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_ColorBar.c
  37. Purpose : Draws color bars
  38. ----------------------------------------------------------------------
  39. */
  40. #include "GUIDEMO.h"
  41. #if (SHOW_GUIDEMO_COLORBAR)
  42. /*********************************************************************
  43. *
  44. * Define
  45. *
  46. **********************************************************************
  47. */
  48. #define TIME_PAUSE 500
  49. #define TIME_STEP 500
  50. #define TIME_RUN ((TIME_PAUSE + TIME_STEP) * 6)
  51. #define NUM_COLORS 8
  52. /*********************************************************************
  53. *
  54. * GUIDEMO_ColorBar
  55. */
  56. void GUIDEMO_ColorBar(void) {
  57. GUI_COLOR ColorStartBlack;
  58. GUI_COLOR ColorStartWhite;
  59. char acTitle[] = "Color bar";
  60. char acDesc[] = "STemWin features an integrated\ncolor management which automatically finds\nthe best available color for any logical color";
  61. char acText[80] = { 0 };
  62. int BitsPerPixel;
  63. int NumColors;
  64. int TimeStart;
  65. int ScreenX0;
  66. int ScreenY0;
  67. int FontY0;
  68. int Index;
  69. int xSize;
  70. int ySize;
  71. int yStep;
  72. int Time;
  73. int Dir;
  74. xSize = LCD_GetXSize();
  75. ySize = LCD_GetYSize();
  76. ScreenX0 = 60;
  77. ScreenY0 = 60;
  78. yStep = (ySize - ScreenY0 * 2) / (NUM_COLORS * 2);
  79. if (yStep < 10) {
  80. yStep = 10;
  81. }
  82. GUIDEMO_ConfigureDemo(acTitle, acDesc, GUIDEMO_SHOW_CURSOR | GUIDEMO_SHOW_CONTROL);
  83. GUIDEMO_DrawBk();
  84. //
  85. // Heading
  86. //
  87. GUI_SetColor(GUI_WHITE);
  88. GUI_SetFont(&GUI_FontRounded22);
  89. GUI_DispStringHCenterAt("Color bars", xSize / 2, 12);
  90. GUI_SetFont(&GUI_FontSouvenir18);
  91. //
  92. // Colors
  93. //
  94. FontY0 = ScreenY0 + ((yStep * 2 - GUI_GetFontDistY()) / 2);
  95. GUI_DispStringAt("Red", 1, FontY0);
  96. GUI_DispStringAt("Green", 1, FontY0 + yStep * 2);
  97. GUI_DispStringAt("Blue", 1, FontY0 + yStep * 4);
  98. GUI_DispStringAt("Grey", 1, FontY0 + yStep * 6);
  99. GUI_DispStringAt("Yellow", 1, FontY0 + yStep * 8);
  100. GUI_DispStringAt("Cyan", 1, FontY0 + yStep * 10);
  101. GUI_DispStringAt("Magenta", 1, FontY0 + yStep * 12);
  102. GUI_SetFont(&GUI_Font8_ASCII);
  103. //
  104. // LCD Controller
  105. //
  106. #ifdef LCD_CONTROLLER
  107. GUIDEMO_AddStringToString(acText, "LCD Controller: ");
  108. GUIDEMO_AddStringToString(acText, LCD_CONTROLLER);
  109. GUI_DispStringAt (acText, 12, ySize - 45);
  110. GUIDEMO_ClearText (acText);
  111. #endif
  112. //
  113. // BPP and number of colors
  114. //
  115. BitsPerPixel = LCD_GetBitsPerPixel();
  116. GUIDEMO_AddIntToString (acText, BitsPerPixel);
  117. GUIDEMO_AddStringToString(acText, " bpp");
  118. NumColors = LCD_GetDevCap(LCD_DEVCAP_NUMCOLORS);
  119. if (NumColors) {
  120. GUIDEMO_AddStringToString(acText, ", ");
  121. GUIDEMO_AddIntToString (acText, NumColors);
  122. GUIDEMO_AddStringToString(acText, " colors");
  123. }
  124. GUI_DispStringAt(acText, 12, ySize - 25);
  125. //
  126. // Gradients
  127. //
  128. TimeStart = GUIDEMO_GetTime();
  129. while (((GUIDEMO_GetTime() - TimeStart) < TIME_RUN) && (GUIDEMO_CheckCancel() == 0)) {
  130. Time = (GUIDEMO_GetTime() - TimeStart) % ((TIME_PAUSE + TIME_STEP) << 1);
  131. Dir = Time / (TIME_PAUSE + TIME_STEP);
  132. Time -= Dir * (TIME_PAUSE + TIME_STEP);
  133. GUI_Exec();
  134. if (Time > TIME_PAUSE) {
  135. continue;
  136. }
  137. Index = ((Time * 0xFF) / TIME_STEP) ^ (Dir * 0xFF);
  138. ColorStartBlack = 0x000000 + 0x010101 * Index;
  139. ColorStartWhite = 0xFFFFFF - ColorStartBlack;
  140. GUI_DrawGradientH(ScreenX0, ScreenY0 + yStep * 0, xSize - ScreenX0, (ScreenY0 + yStep * 1) - 1, GUI_RED, ColorStartBlack);
  141. GUI_DrawGradientH(ScreenX0, ScreenY0 + yStep * 1, xSize - ScreenX0, (ScreenY0 + yStep * 2) - 1, GUI_RED, ColorStartWhite);
  142. GUI_DrawGradientH(ScreenX0, ScreenY0 + yStep * 2, xSize - ScreenX0, (ScreenY0 + yStep * 3) - 1, GUI_GREEN, ColorStartBlack);
  143. GUI_DrawGradientH(ScreenX0, ScreenY0 + yStep * 3, xSize - ScreenX0, (ScreenY0 + yStep * 4) - 1, GUI_GREEN, ColorStartWhite);
  144. GUI_DrawGradientH(ScreenX0, ScreenY0 + yStep * 4, xSize - ScreenX0, (ScreenY0 + yStep * 5) - 1, GUI_BLUE, ColorStartBlack);
  145. GUI_DrawGradientH(ScreenX0, ScreenY0 + yStep * 5, xSize - ScreenX0, (ScreenY0 + yStep * 6) - 1, GUI_BLUE, ColorStartWhite);
  146. GUI_DrawGradientH(ScreenX0, ScreenY0 + yStep * 6, xSize - ScreenX0, (ScreenY0 + yStep * 7) - 1, GUI_GRAY, ColorStartBlack);
  147. GUI_DrawGradientH(ScreenX0, ScreenY0 + yStep * 7, xSize - ScreenX0, (ScreenY0 + yStep * 8) - 1, GUI_GRAY, ColorStartWhite);
  148. GUI_DrawGradientH(ScreenX0, ScreenY0 + yStep * 8, xSize - ScreenX0, (ScreenY0 + yStep * 9) - 1, GUI_YELLOW, ColorStartBlack);
  149. GUI_DrawGradientH(ScreenX0, ScreenY0 + yStep * 9, xSize - ScreenX0, (ScreenY0 + yStep * 10) - 1, GUI_YELLOW, ColorStartWhite);
  150. GUI_DrawGradientH(ScreenX0, ScreenY0 + yStep * 10, xSize - ScreenX0, (ScreenY0 + yStep * 11) - 1, GUI_CYAN, ColorStartBlack);
  151. GUI_DrawGradientH(ScreenX0, ScreenY0 + yStep * 11, xSize - ScreenX0, (ScreenY0 + yStep * 12) - 1, GUI_CYAN, ColorStartWhite);
  152. GUI_DrawGradientH(ScreenX0, ScreenY0 + yStep * 12, xSize - ScreenX0, (ScreenY0 + yStep * 13) - 1, GUI_MAGENTA, ColorStartBlack);
  153. GUI_DrawGradientH(ScreenX0, ScreenY0 + yStep * 13, xSize - ScreenX0, (ScreenY0 + yStep * 14) - 1, GUI_MAGENTA, ColorStartWhite);
  154. }
  155. }
  156. #else
  157. void GUIDEMO_ColorBar_C(void);
  158. void GUIDEMO_ColorBar_C(void) {}
  159. #endif // SHOW_GUIDEMO_COLORBAR
  160. /*************************** End of file ****************************/