Polygon (Sample)

From SEGGER Wiki
Jump to: navigation, search
GUI_Polygon.c
Drawing of polygons.
File(s) required
  • GUI_Polygon.c
Runs in simulation Yes
Runs on target Yes
Download GUI_Polygon.c

This sample demonstrates how to draw polygons in emWin and what can be done with them.

Code

/*********************************************************************
*                    SEGGER Microcontroller GmbH                     *
*        Solutions for real time microcontroller applications        *
**********************************************************************
*                                                                    *
*        (c) 1996 - 2020  SEGGER Microcontroller GmbH                *
*                                                                    *
*        Internet: www.segger.com    Support:  support@segger.com    *
*                                                                    *
**********************************************************************

** emWin V6.10 - Graphical user interface for embedded applications **
emWin is protected by international copyright laws.   Knowledge of the
source code may not be used to write a similar product.  This file may
only  be used  in accordance  with  a license  and should  not be  re-
distributed in any way. We appreciate your understanding and fairness.
----------------------------------------------------------------------
File        : GUI_Polygon.c
Purpose     : Sample that demonstrates how to draw polygons and what
              can be done with them.
Requirements: WindowManager - ( )
              MemoryDevices - ( )
              AntiAliasing  - ( )
              VNC-Server    - ( )
              PNG-Library   - ( )
              TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/

#include "DIALOG.h"

/*********************************************************************
*
*       Defines
*
**********************************************************************
*/

/*********************************************************************
*
*       Static data
*
**********************************************************************
*/
/*********************************************************************
*
*       aPoints: Array that stores the polygon's points on the screen.
*/
static const GUI_POINT aPoints[] = {
  { 65,  35 },
  { 85,  35 },
  { 100, 50 },
  { 100, 70 },
  { 85,  85 },
  { 65,  85 },
  { 50,  70 },
  { 50,  50 }
};

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       MainTask
*/
void MainTask(void) {
  int       i;
  GUI_POINT aTemp[8];

  //
  // Init emWin.
  //
  GUI_Init();
  //
  // Draw polygon.
  //
  GUI_DrawPolygon(aPoints, GUI_COUNTOF(aPoints), 0, 0);
  //
  // Enlarge the polygon a few times by 10, 20... pixels.
  //
  for(i = 1; i < 4; i++) {
    GUI_EnlargePolygon(aTemp, aPoints, GUI_COUNTOF(aPoints), i * 10);
    GUI_DrawPolygon(aTemp, GUI_COUNTOF(aTemp), 0, 0);
  }
  //
  // Magnify the polygon by the factor 2, which multiplies all the coordinates by 2.
  //
  GUI_MagnifyPolygon(aTemp, aPoints, GUI_COUNTOF(aPoints), 2);
  GUI_DrawPolygon(aTemp, GUI_COUNTOF(aTemp), 0, 0);

  while (1) {
    GUI_Delay(100);
  }
}

/*************************** End of file ****************************/