Andrew Reed / Mbed OS CITY1082-i2c_master_wifi_mqtt
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AA_HiResPixels.c Source File

AA_HiResPixels.c

00001 /*********************************************************************
00002 *                SEGGER Microcontroller GmbH                         *
00003 *        Solutions for real time microcontroller applications        *
00004 **********************************************************************
00005 *                                                                    *
00006 *        (c) 1996 - 2018  SEGGER Microcontroller GmbH                *
00007 *                                                                    *
00008 *        Internet: www.segger.com    Support:  support@segger.com    *
00009 *                                                                    *
00010 **********************************************************************
00011 
00012 ** emWin V5.48 - Graphical user interface for embedded applications **
00013 All  Intellectual Property rights  in the Software belongs to  SEGGER.
00014 emWin is protected by  international copyright laws.  Knowledge of the
00015 source code may not be used to write a similar product.  This file may
00016 only be used in accordance with the following terms:
00017 
00018 The software  has been licensed to  Cypress Semiconductor Corporation,
00019 whose registered  office is situated  at 198 Champion Ct. San Jose, CA 
00020 95134 USA  solely for the  purposes of creating  libraries for Cypress
00021 PSoC3 and  PSoC5 processor-based devices,  sublicensed and distributed
00022 under  the  terms  and  conditions  of  the  Cypress  End User License
00023 Agreement.
00024 Full source code is available at: www.segger.com
00025 
00026 We appreciate your understanding and fairness.
00027 ----------------------------------------------------------------------
00028 Licensing information
00029 Licensor:                 SEGGER Microcontroller Systems LLC
00030 Licensed to:              Cypress Semiconductor Corp, 198 Champion Ct., San Jose, CA 95134, USA
00031 Licensed SEGGER software: emWin
00032 License number:           GUI-00319
00033 License model:            Services and License Agreement, signed June 10th, 2009
00034 Licensed platform:        Any Cypress platform (Initial targets are: PSoC3, PSoC5)
00035 ----------------------------------------------------------------------
00036 Support and Update Agreement (SUA)
00037 SUA period:               2009-06-12 - 2022-07-27
00038 Contact to extend SUA:    sales@segger.com
00039 ----------------------------------------------------------------------
00040 File        : AA_HiResPixels.c
00041 Purpose     : Demonstrates high resolution pixels
00042 Requirements: WindowManager - (x)
00043               MemoryDevices - (x)
00044               AntiAliasing  - (x)
00045               VNC-Server    - ( )
00046               PNG-Library   - ( )
00047               TrueTypeFonts - ( )
00048 ----------------------------------------------------------------------
00049 */
00050 
00051 #include "GUI.h"
00052 #include "WM.h"
00053 
00054 /*******************************************************************
00055 *
00056 *       Defines
00057 *
00058 ********************************************************************
00059 */
00060 #define AA_FACTOR    4
00061 #define POLY_SIZE   19
00062 #define POLY_POINTS  3
00063 
00064 #define COORD_0(Plus, AA_Factor) (I16)(((I32)((Plus ? POLY_SIZE : -POLY_SIZE) * AA_Factor * 0.7071f * 10000)) / 10000)
00065 #define COORD_1(Plus, AA_Factor) (I16)(((I32)((Plus ? POLY_SIZE : -POLY_SIZE) * AA_Factor * 1.2247f * 10000)) / 10000)
00066 #define COORD_2(Plus, AA_Factor) (I16)(((I32)((Plus ? POLY_SIZE : -POLY_SIZE) * AA_Factor * 1.4142f * 10000)) / 10000)
00067 
00068 //
00069 // Recommended memory to run the sample with adequate performance
00070 //
00071 #define RECOMMENDED_MEMORY (1024L * 15)
00072 
00073 /*******************************************************************
00074 *
00075 *       Static variables
00076 *
00077 ********************************************************************
00078 */
00079 static int _pos_x1         = 30;
00080 static int _pos_y1         = 30;
00081 static int _pos_x2         = 125;
00082 static int _pos_y2         = 30;
00083 static int _pos_x3         = 220 * AA_FACTOR;
00084 static int _pos_y3         = 30  * AA_FACTOR;
00085 static int _color_d        = -1;
00086 static GUI_COLOR _color_a  = 0xFF00FE;
00087 static GUI_COLOR _color_b  = 0x00FEFF;
00088 static GUI_COLOR _color_c  = 0xFEFFFE;
00089 
00090 static const GUI_POINT _aPolygon_src[] = {
00091   {             0, COORD_2(0, 1) },
00092   { COORD_1(1, 1), COORD_0(1, 1) },
00093   { COORD_1(0, 1), COORD_0(1, 1) }
00094 };
00095 
00096 static const GUI_POINT _aPolygonHiRes_src[] = {
00097   {                     0, COORD_2(0, AA_FACTOR) },
00098   { COORD_1(1, AA_FACTOR), COORD_0(1, AA_FACTOR) },
00099   { COORD_1(0, AA_FACTOR), COORD_0(1, AA_FACTOR) }
00100 };
00101 
00102 static GUI_POINT _aPolygon[POLY_POINTS];
00103 static GUI_POINT _aPolygonHiRes[POLY_POINTS];
00104 
00105 /*******************************************************************
00106 *
00107 *       Static code
00108 *
00109 ********************************************************************
00110 */
00111 /*******************************************************************
00112 *
00113 *       _cbWindow
00114 *
00115 * Function description
00116 *   This is the callback for the window. A callback was used
00117 *   for memory devices.
00118 */
00119 static void _cbWindow(WM_MESSAGE * pMsg) {
00120   switch (pMsg->MsgId) {
00121   case WM_PAINT:
00122     GUI_SetBkColor(_color_a);
00123     GUI_ClearRect( 0, 0, 250, 14);
00124     GUI_SetBkColor(_color_b);
00125     GUI_ClearRect( 0, 15, 250, 29);
00126     GUI_SetBkColor(GUI_BLACK);
00127     GUI_ClearRect( 0, 30, 250, 60);
00128     GUI_SetColor(_color_c);
00129     GUI_FillPolygon(_aPolygon, POLY_POINTS, _pos_x1, _pos_y1);
00130     GUI_AA_FillPolygon(_aPolygon, POLY_POINTS, _pos_x2, _pos_y2);
00131     GUI_AA_EnableHiRes();
00132     GUI_AA_FillPolygon(_aPolygonHiRes, POLY_POINTS, _pos_x3, _pos_y3);
00133     GUI_AA_DisableHiRes();
00134     break;
00135   default:
00136     WM_DefaultProc(pMsg);
00137   }
00138 }
00139 
00140 /*******************************************************************
00141 *
00142 *       _CalcColor
00143 *
00144 * Function description
00145 *   Calculates the color-fading.
00146 */
00147 static void _CalcColor(void) {
00148   _color_a += 0x000002 * _color_d;
00149   _color_b += 0x000200 * _color_d;
00150   _color_c += 0x020002 * _color_d;
00151   if (_color_c == 0xFEFFFE || _color_c == 0x00FF00) {
00152     _color_d = -_color_d;
00153   }
00154 }
00155 
00156 /*******************************************************************
00157 *
00158 *       _ShowHiResPixels
00159 *
00160 * Function description
00161 *   This is frame-function for the callback. It creates the window
00162 *   and handles the rotation of polygons and colors.
00163 */
00164 static void _ShowHiResPixels(void) {
00165   const GUI_FONT * FontOld;
00166   WM_HWIN          hWindow;
00167   float            pi;
00168   float            Step;
00169   float            Angle;
00170   int              i;
00171 
00172   pi   = 3.1415926f;
00173   Step = pi / 180;
00174   GUI_SetBkColor(GUI_BLACK);
00175   GUI_Clear();
00176   GUI_SetColor(GUI_WHITE);
00177   GUI_SetTextAlign(GUI_TA_HCENTER);
00178   FontOld = GUI_SetFont(&GUI_Font24_ASCII);
00179   GUI_DispStringAt("AA_HiResPixels - Sample", 160, 5);
00180   GUI_SetFont(FontOld);
00181   GUI_SetColor(GUI_RED);
00182   GUI_DispStringHCenterAt("not\nantialised", 65, 100);
00183   GUI_SetColor(GUI_GREEN);
00184   GUI_DispStringHCenterAt("antialised", 160, 100);
00185   GUI_SetColor(GUI_BLUE);
00186   GUI_DispStringHCenterAt("antialised\nwith high\nresolution", 255, 100);
00187   hWindow = WM_CreateWindow(35, 140, 250, 60, WM_CF_SHOW | WM_CF_MEMDEV, _cbWindow, 0);
00188   WM_SelectWindow(hWindow);
00189   GUI_AA_SetFactor(AA_FACTOR);
00190   while (1) {
00191     for (i = 0, Angle = 0; i < 360; i++) {
00192       Angle += Step;
00193       GUI_RotatePolygon(_aPolygonHiRes, _aPolygonHiRes_src, POLY_POINTS, Angle);
00194       GUI_RotatePolygon(_aPolygon,      _aPolygon_src,      POLY_POINTS, Angle);
00195       _CalcColor();
00196       WM_InvalidateWindow(hWindow);
00197       GUI_Delay(50);
00198     }
00199   }
00200 }
00201 
00202 /*********************************************************************
00203 *
00204 *       Public code
00205 *
00206 **********************************************************************
00207 */
00208 /*********************************************************************
00209 *
00210 *       MainTask
00211 */
00212 void MainTask(void) {
00213   GUI_Init();
00214   //
00215   // Check if recommended memory for the sample is available
00216   //
00217   if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) {
00218     GUI_ErrorOut("Not enough memory available."); 
00219     return;
00220   }
00221   _ShowHiResPixels();
00222 }
00223 
00224 /*************************** End of file ****************************/
00225