⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gui_fillpolygon.lst

📁 Keil C下通过的UCGUI,UCGUI的移植源代码
💻 LST
字号:
C51 COMPILER V8.05a   GUI_FILLPOLYGON                                                      04/11/2008 14:18:38 PAGE 1   


C51 COMPILER V8.05a, COMPILATION OF MODULE GUI_FILLPOLYGON
OBJECT MODULE PLACED IN GUI_FillPolygon.obj
COMPILER INVOKED BY: D:\Program Files\keil\C51\BIN\C51.EXE gui\Core\GUI_FillPolygon.c LARGE BROWSE MDU_F120 DEBUG OBJECT
                    -EXTEND PRINT(.\GUI_FillPolygon.lst) OBJECT(GUI_FillPolygon.obj)

line level    source

   1          /*
   2          *********************************************************************************************************
   3          *                                                uC/GUI
   4          *                        Universal graphic software for embedded applications
   5          *
   6          *                       (c) Copyright 2002, Micrium Inc., Weston, FL
   7          *                       (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH
   8          *
   9          *              礐/GUI is protected by international copyright laws. Knowledge of the
  10          *              source code may not be used to write a similar product. This file may
  11          *              only be used in accordance with a license and should not be redistributed
  12          *              in any way. We appreciate your understanding and fairness.
  13          *
  14          ----------------------------------------------------------------------
  15          File        : GUI_FillPolygon.C
  16          Purpose     : Fill polygon routine
  17          ---------------------------END-OF-HEADER------------------------------
  18          */
  19          
  20          
  21          #include <stddef.h>           /* needed for definition of NULL */
  22          #include "gui\Core\GUI_Protected.h"
  23          #include "gui\Core\GUIDebug.h"
  24          
  25          
  26          
  27          /********************************************************
  28          *
  29          *       defines, Configs
  30          *
  31          *********************************************************
  32          */
  33          
  34          #define GUI_FP_MAXCOUNT 12
  35          
  36          /********************************************************
  37          *
  38          *        static data
  39          *
  40          *********************************************************
  41          */
  42          static int GL_FP_Cnt;
  43          static I16 _aX[GUI_FP_MAXCOUNT];
  44          
  45          
  46          /********************************************************
  47          *
  48          *        static code
  49          *
  50          *********************************************************
  51          */
  52          
  53          /********************************************************
  54          *
C51 COMPILER V8.05a   GUI_FILLPOLYGON                                                      04/11/2008 14:18:38 PAGE 2   

  55          *        _DrawHLine
  56          */
  57          static void _DrawHLine(int x0, int y, int x1) {
  58   1        if (x0 < x1) {
  59   2          LCD_HL_DrawHLine(x0, y, x1);
  60   2        } else {
  61   2          LCD_HL_DrawHLine(x1, y, x0);
  62   2        }
  63   1      }
  64          
  65          
  66          /********************************************************
  67          *
  68          *        _CheckYInterSect
  69          
  70            This function returns the x-coordinate of the intersection
  71            of the given line at the given y-coordinate.
  72            If there is no intersection, GUI_XMAX is returned.
  73            This routine does not work for horizontal lines, as there
  74            would be more than a single point as intersection. This situation
  75            needs to be checked prior to calling the routine.
  76            Returns:
  77              0 if no intersection
  78              1 if we have an intersection
  79          */
  80          static int _CheckYInterSect(int y, int* px, const GUI_POINT*paPoint0, const GUI_POINT*paPoint1) {
  81   1        int x0, y0, x1, y1;
  82   1        if (paPoint0->y <= (paPoint1)->y) {
  83   2          y0 = paPoint0->y;
  84   2          if (y0 > y)      /* Check if there is an intersection ... (early out) */
  85   2            return 0;
  86   2          y1 = paPoint1->y;
  87   2          if (y1 < y)      /* Check if there is an intersection ... (early out) */
  88   2            return 0;
  89   2          x0 = paPoint0->x;
  90   2          x1 = paPoint1->x;
  91   2        } else {
  92   2          y0 = paPoint1->y;
  93   2          if (y0 > y)      /* Check if there is an intersection ... (early out) */
  94   2            return 0;
  95   2          y1 = paPoint0->y;
  96   2          if (y1 < y)      /* Check if there is an intersection ... (early out) */
  97   2            return 0;
  98   2          x0 = paPoint1->x;
  99   2          x1 = paPoint0->x;
 100   2        }
 101   1      /* Calculate intersection */
 102   1        {
 103   2          I32 Mul = (I32)(x1 - x0) * (I32)(y - y0);
 104   2          if (Mul > 0) {
 105   3            Mul += (y1 - y0) >> 1;              /* for proper rounding */
 106   3          } else {
 107   3            Mul -= ((y1 - y0) >> 1) - 1;          /* for proper rounding */
 108   3          }
 109   2          x0 += Mul / (y1 - y0);
 110   2        }
 111   1        *px = x0;
 112   1        return 1;
 113   1      } 
 114          
 115          
 116          /********************************************************
C51 COMPILER V8.05a   GUI_FILLPOLYGON                                                      04/11/2008 14:18:38 PAGE 3   

 117          *
 118          *        _Add
 119          
 120            This function adds a point into the sorted array
 121          */
 122          static void _Add(int x) {
 123   1        if (GL_FP_Cnt < GUI_FP_MAXCOUNT) {
 124   2          int i;
 125   2          /* Move all entries to the right (bigger x-value) */
 126   2          for (i=GL_FP_Cnt; i ; i--) {
 127   3            if (_aX[i-1] < x)
 128   3              break;
 129   3            _aX[i] = _aX[i-1];
 130   3          }
 131   2          /* Insert new entry */
 132   2          _aX[i]    = x;
 133   2          GL_FP_Cnt++;
 134   2        }
 135   1      }
 136          
 137          
 138          /********************************************************
 139          *
 140          *        _Init
 141          
 142            This function initialise the sorted array
 143          */
 144          static void _Init(void) {
 145   1        GL_FP_Cnt = 0;
 146   1      }
 147          
 148          
 149          /********************************************************
 150          *
 151          *        _Flush
 152          
 153            This function draw lines between points in the array
 154          */
 155          static void _Flush(int x0, int y) {
 156   1        int i, x;
 157   1        char On=0;
 158   1        for (i=0; i<GL_FP_Cnt; i++) {
 159   2          int xNew = _aX[i];
 160   2          if (On) {
 161   3            LCD_HL_DrawHLine(x0 + x, y, x0 + xNew);
 162   3          }
 163   2          On ^= 1;
 164   2          x = xNew;
 165   2        }
 166   1      }
 167          
 168          
 169          /********************************************************
 170          *
 171          *        _AddPoint
 172          
 173            This function decides either if there a V-point or a
 174            X-point. An X-point is added to the array, a V-point
 175            is drawn.
 176          */
 177          static void _AddPoint(int x, int y, int y0, int y1, int xOff, int yOff) {
 178   1        if ((y0 ^ y1) >= 0) {
C51 COMPILER V8.05a   GUI_FILLPOLYGON                                                      04/11/2008 14:18:38 PAGE 4   

 179   2          x += xOff;
 180   2          LCD_HL_DrawHLine(x, y + yOff, x);    // V-point, not crossing the polygon
 181   2        } else {
 182   2          _Add(x);
 183   2        }
 184   1      }
 185          
 186          
 187          /********************************************************
 188          *
 189          *        _GetPrevPointDiffy
 190          
 191            Find previous point which is not on the same height
 192          */
 193          static int _GetPrevPointDiffy(const GUI_POINT* paPoint, int i,
 194                                        const int NumPoints, const int y0) {
 195   1        int j, y1;
 196   1        for (j = 0; j < (NumPoints - 1) ; j++) {
 197   2          i = (i != 0) ? i - 1 : NumPoints - 1;
 198   2          y1 = (paPoint + i)->y;
 199   2          if (y1 != y0) {
 200   3            return y1;
 201   3          }
 202   2        }
 203   1        return y0;
 204   1      }
 205          
 206          
 207          /********************************************************
 208          *
 209          *        code
 210          *
 211          *********************************************************
 212          */
 213          
 214          /********************************************************
 215          *
 216          *        GL_FillPolygon
 217          
 218            This function calculates the polygon
 219          */
 220          void GL_FillPolygon  (const GUI_POINT*paPoint, int NumPoints, int xOff, int yOff) {
 221   1        int i, y;
 222   1        int yMin = GUI_YMAX;
 223   1        int yMax = GUI_YMIN;
 224   1      /* First step : find uppermost and lowermost coordinates */
 225   1        for (i=0; i<NumPoints; i++) {
 226   2          y = (paPoint + i)->y;
 227   2          if (y < yMin)
 228   2            yMin = y;
 229   2          if (y > yMax)
 230   2            yMax = y;
 231   2        }
 232   1      /* Use Clipping rect to reduce calculation (if possible) */
 233   1        if (GUI_Context.pClipRect_HL) {
 234   2          if (yMax > (GUI_Context.pClipRect_HL->y1 - yOff))
 235   2            yMax = (GUI_Context.pClipRect_HL->y1 - yOff);
 236   2          if (yMin < (GUI_Context.pClipRect_HL->y0 - yOff))
 237   2            yMin = (GUI_Context.pClipRect_HL->y0 - yOff);
 238   2        }
 239   1      /* Second step: Calculate and draw horizontal lines */
 240   1        for (y=yMin; y<=yMax; y++) {
C51 COMPILER V8.05a   GUI_FILLPOLYGON                                                      04/11/2008 14:18:38 PAGE 5   

 241   2          _Init();
 242   2          /* find next intersection and count lines*/
 243   2          for (i=0; i<NumPoints; i++) {
 244   3            int i1 = (i < (NumPoints - 1)) ? i + 1 : 0;
 245   3            int y0 = (paPoint + i )->y;
 246   3            int y1 = (paPoint + i1)->y;
 247   3            /* Check if starting point is on line */
 248   3            if (y0 == y) {
 249   4              if (y1 == y) {  /* Add the entire line */
 250   5                _DrawHLine((paPoint + i )->x + xOff , y + yOff, (paPoint + i1)->x + xOff);
 251   5              } else {        /* Add only one point */
 252   5                int yPrev = _GetPrevPointDiffy(paPoint, i, NumPoints, y);
 253   5                if (yPrev != y) {
 254   6                  _AddPoint((paPoint + i)->x, y, yPrev - y, y1 - y, xOff, yOff);
 255   6                } 
 256   5              }
 257   4            } else if (y1 != y) {  /* Ignore if end-point is on the line */
 258   4              if (((y1 >= y) && (y0 <= y)) || ((y0 >= y) && (y1 <= y))) {
 259   5                int xIntersect;
 260   5                if (_CheckYInterSect(y, &xIntersect, paPoint + i, paPoint + i1)) {
 261   6                  _Add(xIntersect);
 262   6                }
 263   5              }
 264   4            }
 265   3          }
 266   2          _Flush(xOff, y + yOff);
 267   2        }  
 268   1      }
 269          
 270          void GUI_FillPolygon  (const GUI_POINT* pPoints, int NumPoints, int x0, int y0) {
 271   1        GUI_LOCK();
 272   1        #if (GUI_WINSUPPORT)
                  WM_ADDORG(x0,y0);
                  WM_ITERATE_START(NULL); {
                #endif
 276   1        GL_FillPolygon (pPoints, NumPoints, x0, y0);
 277   1        #if (GUI_WINSUPPORT)
                  } WM_ITERATE_END();
                #endif
 280   1        GUI_UNLOCK();
 281   1      }
 282          
 283          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   2565    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =     26      99
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -