找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 948|回复: 0
打印 上一主题 下一主题
收起左侧

单片机彩屏汉字显示程序

[复制链接]
跳转到指定楼层
楼主
ID:301977 发表于 2020-10-12 00:15 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. /*
  2. ================================================================================
  3. File Name : GUI_Basic.c
  4. Author    : LiYOng
  5. Date      : 2008-12-12 15:51
  6. Version   : 1.0
  7. Decription: This file contains some basic functions for GUI, It need the LCD
  8.             Drive functions
  9. ================================================================================
  10. */
  11. #include "GUI_Basic.H"
  12. #include "GUI_Type.H"
  13. #include "fontlib.h"
  14. /*
  15. ================================================================================
  16. Function     : GUI_DrawRectangle( )
  17. Description  : Draw a rectangle
  18. Input        : -pRect, point to a rectangle structure
  19. output       : None
  20. ================================================================================
  21. */
  22. void GUI_DrawRectangle( RECT* pRect )
  23. {
  24.         LINE line;

  25.         line.xs = pRect->xs;
  26.         line.xe = pRect->xe;
  27.         line.ys = pRect->ys;
  28.         line.ye = pRect->ys;
  29.         line.Color = pRect->Color;
  30.         LCDDrawHRLine( &line );

  31.         line.xe = pRect->xs;
  32.         line.ye = pRect->ye;
  33.         LCDDrawHRLine( &line );

  34.         line.xs = pRect->xe;
  35.         line.ys = pRect->ye;
  36.         LCDDrawHRLine( &line );

  37.         line.xe = pRect->xe;
  38.         line.ye = pRect->ys;
  39.         LCDDrawHRLine( &line );
  40. }
  41. /*
  42. ================================================================================
  43. Function     : GUI_DrawLine( )
  44. Description  : Draw a line
  45. Input        : -pLine, point to a line structure
  46. output       : None
  47. ================================================================================
  48. */
  49. void GUI_DrawLine( LINE* pLine )
  50. {
  51.         INT32S   dx;                                                // 直线x轴差值变量
  52.         INT32S   dy;                  // 直线y轴差值变量
  53.         INT32S    dx_sym;                                // x轴增长方向,为-1时减值方向,为1时增值方向
  54.         INT32S    dy_sym;                                // y轴增长方向,为-1时减值方向,为1时增值方向
  55.         INT32S   dx_x2;                                        // dx*2值变量,用于加快运算速度
  56.         INT32S   dy_x2;                                        // dy*2值变量,用于加快运算速度
  57.         INT32S   di;                                                // 决策变量

  58.         POINT    point;
  59.         LINE     line;

  60.         line.xs = pLine->xs;
  61.         line.ys = pLine->ys;
  62.         line.xe = pLine->xe;
  63.         line.ye = pLine->ye;
  64.         line.Color = pLine->Color;

  65.   point.Color = pLine->Color;

  66.         dx = line.xe - line.xs;
  67.   dy = line.ye - line.ys;

  68. /* 判断增长方向,或是否为水平线、垂直线、点 */
  69.         if( dx > 0 )                                        // 判断x轴方向
  70.         {
  71.                 dx_sym = 1;                                        // dx>0,设置dx_sym=1
  72.         }
  73.         else
  74.         {
  75.                 if( dx < 0 )
  76.                 {
  77.                         dx_sym = -1;                  // dx<0,设置dx_sym=-1
  78.                 }
  79.                 else
  80.                 {
  81.                         LCDDrawHRLine( &line );
  82.                         return;
  83.                 }
  84.         }

  85.         if( dy > 0 )                                                        // 判断y轴方向
  86.         {
  87.                 dy_sym = 1;                                        // dy>0,设置dy_sym=1
  88.         }
  89.         else
  90.         {
  91.                 if( dy < 0 )
  92.                 {
  93.                         dy_sym = -1;                                // dy<0,设置dy_sym=-1
  94.                 }
  95.                 else
  96.                 {  // dy==0,画水平线,或一点
  97.                         LCDDrawHRLine( &line );
  98.                         return;
  99.                 }
  100.         }

  101.         /* 将dx、dy取绝对值 */
  102.         dx = dx_sym * dx;
  103.         dy = dy_sym * dy;

  104.         /* 计算2倍的dx及dy值 */
  105.         dx_x2 = dx*2;
  106.         dy_x2 = dy*2;

  107. /* 使用Bresenham法进行画直线 */
  108.         if( dx >= dy )                                                // 对于dx>=dy,则使用x轴为基准
  109.         {
  110.                 di = dy_x2 - dx;
  111.     while( line.xs != line.xe )
  112.     {
  113.                         point.x = line.xs;
  114.                         point.y = line.ys;
  115.                         LCDDrawPoint( &point );
  116.                         line.xs += dx_sym;
  117.                         if( di < 0 )
  118.                         {
  119.                                 di += dy_x2;                        // 计算出下一步的决策值
  120.                         }
  121.                         else
  122.                         {
  123.                                 di += dy_x2 - dx_x2;
  124.                                 line.ys += dy_sym;
  125.                         }
  126.     }
  127.                 LCDDrawPoint( &point );                // 显示最后一点
  128.         }
  129.         else                                                                // 对于dx<dy,则使用y轴为基准
  130.         {
  131.                 di = dx_x2 - dy;
  132.     while( line.ys != line.ye )
  133.     {
  134.                         point.x = line.xs;
  135.                         point.y = line.ys;
  136.                         LCDDrawPoint( &point );
  137.                         line.ys += dy_sym;
  138.                         if(di<0)
  139.                         {
  140.                                 di += dx_x2;
  141.                         }
  142.                         else
  143.                         {
  144.                                 di += dx_x2 - dy_x2;
  145.                                 line.xs += dx_sym;
  146.                         }
  147.     }
  148.                 LCDDrawPoint( &point );                // 显示最后一点
  149.         }
  150. }
  151. /*
  152. ================================================================================
  153. Name: PrintFont
  154. Function: Display a character at a special area
  155. Input:        1.Xs : Start position X
  156.                 2.Ys : Start position Y
  157.                 3.pFont : A pointer of a font structure
  158.                 4.Character : The ASCII code of the character.
  159. Output: None
  160. Note: The start position is inputted as a parameter, And the end position is calculated by the FONT
  161.                 structure.
  162. Author: LiYong
  163. Date  : 2008.08.09
  164. ================================================================================
  165. */
  166. void        GUI_DisplayFont( INT8U        Xs, INT8U Ys, FONT* pFont, char Character )
  167. {
  168.         BitBlock        Block;
  169.         INT32U        Bytes;
  170.         INT8U DataBuffer[64];
  171.         INT8U i;
  172.         const unsigned char *offset;

  173.         Block.Height = pFont->Height;
  174.         Block.Width = pFont->Width;
  175.         Block.Color = pFont->Color;
  176.         Block.BackColor = pFont->BackColor;
  177.         Block.xs = Xs;
  178.         Block.ys = Ys;

  179.         Bytes = pFont->Width >> 3;
  180.         if( pFont->Width & 0x07 )
  181.         {
  182.                  Bytes ++;
  183.         }
  184.         Bytes *= pFont->Height;
  185.         Bytes *= Character - ' ';

  186.         if( pFont->Height == 18 )
  187.         {
  188.                  offset = (const unsigned char*)&FontLib_18;
  189.         }
  190.         else if( pFont->Height == 14 )
  191.         {
  192.                  offset = (const unsigned char*)&FontLib_14;
  193.         }
  194.         else
  195.         {
  196.                 return;
  197.         }
  198.         offset += Bytes;
  199.         for( i = 0; i < 36; i ++ )
  200.         {
  201.                 //DataBuffer[i] = pgm_read_byte( offset + i );        
  202.         }

  203.         
  204.         Block.pData = DataBuffer;

  205.         PrintBitBlock( &Block );
  206. }
  207. /*
  208. ========================================================================================================
  209. Name: DisplayStr
  210. Function: Display a character at a special area
  211. Input:
  212.     1.Xs : Start position X
  213.                 2.Ys : Start position Y
  214.                 3.pFont : A pointer of a font structure
  215.                 4.Str : The start address of a string
  216. Output: None
  217. Note: The start position is inputted as a parameter, And the end position is calculated by the FONT
  218.                 structure.
  219. Author: LiYong
  220. Date  : 2008.08.09
  221. ========================================================================================================
  222. */
  223. void        GUI_DisplayStr( INT8U xs, INT8U ys, FONT* pFont, char* Str )
  224. {
  225.         while( *Str )
  226.         {
  227.                 GUI_DisplayFont( xs, ys, pFont, *Str );
  228.                  Str ++;
  229.                 xs += pFont->Width;
  230.         }
  231. }
  232. /*
  233. ================================================================================
  234. Name: GUI_DrawCircle( )
  235. Function: Display a cycle at a special area
  236. Input:        -pCycle, A pinter point to a cycle structure
  237. Output: None
  238. Author: LiYong
  239. Date  : 2008.08.09
  240. ================================================================================
  241. */
  242. void  GUI_DrawCircle( CIRCLE* pCircle )
  243. {
  244.    INT8S  draw_x0, draw_y0;                        // 刽图点坐标变量
  245.    INT8S  draw_x1, draw_y1;
  246.    INT8S  draw_x2, draw_y2;
  247.    INT8S  draw_x3, draw_y3;
  248.    INT8S  draw_x4, draw_y4;
  249.    INT8S  draw_x5, draw_y5;
  250.    INT8S  draw_x6, draw_y6;
  251.    INT8S  draw_x7, draw_y7;
  252.    INT8S  xx, yy;                                        // 画圆控制变量

  253.    INT8S  di;                                                // 决策变量
  254.    POINT point;

  255.    point.Color = pCircle->Color;

  256.    /* 参数过滤 */
  257.    if(0 == pCircle->r ) return;

  258.    /* 计算出8个特殊点(0、45、90、135、180、225、270度),进行显示 */
  259.    point.x = draw_x0 = draw_x1 = pCircle->x;
  260.    point.y = draw_y0 = draw_y1 = pCircle->y + pCircle->r;

  261.    if( draw_y0 < GUI_LCM_YMAX ) LCDDrawPoint( &point );        // 90度

  262.    point.x = draw_x2 = draw_x3 = pCircle->x;
  263.    point.y = draw_y2 = draw_y3 = pCircle->y - pCircle->r;
  264.    if( draw_y2 >= 0 ) LCDDrawPoint( &point );                        // 270度


  265.    point.x = draw_x4 = draw_x6 = pCircle->x + pCircle->r;
  266.    point.y = draw_y4 = draw_y6 = pCircle->y;
  267.    if(draw_x4<GUI_LCM_XMAX) LCDDrawPoint( &point );        // 0度

  268.    point.x = draw_x5 = draw_x7 = pCircle->x - pCircle->r;
  269.    point.y = draw_y5 = draw_y7 = pCircle->y;
  270.    if(draw_x5>=0) LCDDrawPoint( &point );                        // 180度
  271.    if(1==pCircle->r) return;                                        // 若半径为1,则已圆画完


  272.    /* 使用Bresenham法进行画圆 */
  273.    di = 3 - 2*pCircle->r;                                        // 初始化决策变量

  274.    xx = 0;
  275.    yy = pCircle->r;
  276.    while(xx<yy)
  277.    {  if(di<0)
  278.           {  di += 4*xx + 6;
  279.           }
  280.           else
  281.           {  di += 4*(xx - yy) + 10;

  282.              yy--;
  283.                  draw_y0--;
  284.                  draw_y1--;
  285.                  draw_y2++;
  286.                  draw_y3++;
  287.                  draw_x4--;
  288.                  draw_x5++;
  289.                  draw_x6--;
  290.                  draw_x7++;
  291.           }

  292.           xx++;
  293.           draw_x0++;
  294.           draw_x1--;
  295.           draw_x2++;
  296.           draw_x3--;
  297.           draw_y4++;
  298.           draw_y5++;
  299.           draw_y6--;
  300.           draw_y7--;


  301.           /* 要判断当前点是否在有效范围内 */
  302.           if( (draw_x0<=GUI_LCM_XMAX)&&(draw_y0>=0) )
  303.           {
  304.                   point.x = draw_x0;
  305.                   point.y = draw_y0;
  306.                   LCDDrawPoint( &point );
  307.           }
  308.           if( (draw_x1>=0)&&(draw_y1>=0) )
  309.           {
  310.                   point.x = draw_x1;
  311.                   point.y = draw_y1;
  312.                   LCDDrawPoint( &point );
  313.           }
  314.           if( (draw_x2<=GUI_LCM_XMAX)&&(draw_y2<=GUI_LCM_YMAX) )
  315.           {
  316.                   point.x = draw_x2;
  317.                   point.y = draw_y2;
  318.                   LCDDrawPoint( &point );
  319.           }
  320.           if( (draw_x3>=0)&&(draw_y3<=GUI_LCM_YMAX) )
  321.           {
  322.                   point.x = draw_x3;
  323.                   point.y = draw_y3;
  324.                   LCDDrawPoint( &point );
  325.           }
  326.           if( (draw_x4<=GUI_LCM_XMAX)&&(draw_y4>=0) )
  327.           {
  328.                   point.x = draw_x4;
  329.                   point.y = draw_y4;
  330.                   LCDDrawPoint( &point );
  331.           }
  332.           if( (draw_x5>=0)&&(draw_y5>=0) )
  333.           {
  334.                   point.x = draw_x5;
  335.                   point.y = draw_y5;
  336.                   LCDDrawPoint( &point );
  337.           }
  338.           if( (draw_x6<=GUI_LCM_XMAX)&&(draw_y6<=GUI_LCM_YMAX) )
  339.           {
  340.                   point.x = draw_x6;
  341.                   point.y = draw_y6;
  342.                   LCDDrawPoint( &point );
  343.           }
  344.           if( (draw_x7>=0)&&(draw_y7<=GUI_LCM_YMAX) )
  345.           {
  346.                   point.x = draw_x7;
  347.                   point.y = draw_y7;
  348.                   LCDDrawPoint( &point );
  349.           }
  350.         }
  351. }
  352. /*
  353. ================================================================================
  354. Name: GUI_DrawCircleFill( )
  355. Function: Display a cycle at a special area and fill its area
  356. Input:        -pCycle, A pinter point to a cycle structure
  357. Output: None
  358. Author: LiYong
  359. Date  : 2008.08.09
  360. ================================================================================
  361. */
  362. void  GUI_DrawCircleFill( CIRCLE* pCircle )
  363. {
  364.    INT8S  draw_x0, draw_y0;                        // 刽图点坐标变量
  365.    INT8S  draw_x1, draw_y1;
  366.    INT8S  draw_x2, draw_y2;
  367.    INT8S  draw_x3, draw_y3;
  368.    INT8S  draw_x4, draw_y4;
  369.    INT8S  draw_x5, draw_y5;
  370.    INT8S  draw_x6, draw_y6;
  371.    INT8S  draw_x7, draw_y7;
  372.    INT8S  fill_x0, fill_y0;                        // 填充所需的变量,使用垂直线填充
  373.    INT8S  fill_x1;
  374.    INT8S  xx, yy;                                        // 画圆控制变量

  375.    INT8S  di;                                                // 决策变量
  376.    POINT   point;
  377.    LINE    line;

  378.    point.Color = pCircle->Color;
  379.    line.Color = pCircle->Color;



  380.    /* 参数过滤 */
  381.    if(0==pCircle->r) return;

  382.    /* 计算出4个特殊点(0、90、180、270度),进行显示 */
  383.    point.x = draw_x0 = draw_x1 = pCircle->x;
  384.    point.y = draw_y0 = draw_y1 = pCircle->y + pCircle->r;
  385.    if(draw_y0<GUI_LCM_YMAX)
  386.    {
  387.       LCDDrawPoint( &point );
  388.    }

  389.    point.x = draw_x2 = draw_x3 = pCircle->x;
  390.    point.y = draw_y2 = draw_y3 = pCircle->y - pCircle->r;
  391.    if(draw_y2>=0)
  392.    {
  393.                    LCDDrawPoint( &point );
  394.    }

  395.    point.x = draw_x4 = draw_x6 = pCircle->x + pCircle->r;
  396.    point.y = draw_y4 = draw_y6 = pCircle->y;
  397.    if(draw_x4<GUI_LCM_XMAX)
  398.    {
  399.                    LCDDrawPoint( &point );        // 0度
  400.       fill_x1 = draw_x4;
  401.    }
  402.    else
  403.    {
  404.                    fill_x1 = GUI_LCM_XMAX;
  405.    }
  406.    fill_y0 = pCircle->y;                                                        // 设置填充线条起始点fill_x0
  407.    fill_x0 = pCircle->x - pCircle->r;                                                // 设置填充线条结束点fill_y1
  408.    if(fill_x0<0) fill_x0 = 0;
  409.          line.xs = fill_x0;
  410.          line.ys = fill_y0;
  411.          line.ye = fill_y0;
  412.          line.xe = fill_x1;
  413.    LCDDrawHRLine( &line );

  414.    point.x = draw_x5 = draw_x7 = pCircle->x - pCircle->r;
  415.    point.y = draw_y5 = draw_y7 = pCircle->y;
  416.    if(draw_x5>=0)
  417.    {
  418.                    LCDDrawPoint( &point );        // 180度
  419.    }
  420.    if(1==pCircle->r) return;


  421.    /* 使用Bresenham法进行画圆 */
  422.    di = 3 - 2*pCircle->r;                                                        // 初始化决策变量

  423.    xx = 0;
  424.    yy = pCircle->r;
  425.    while(xx<yy)
  426.    {  if(di<0)
  427.           {  di += 4*xx + 6;
  428.           }
  429.           else
  430.           {  di += 4*(xx - yy) + 10;

  431.              yy--;
  432.                  draw_y0--;
  433.                  draw_y1--;
  434.                  draw_y2++;
  435.                  draw_y3++;
  436.                  draw_x4--;
  437.                  draw_x5++;
  438.                  draw_x6--;
  439.                  draw_x7++;
  440.           }

  441.           xx++;
  442.           draw_x0++;
  443.           draw_x1--;
  444.           draw_x2++;
  445.           draw_x3--;
  446.           draw_y4++;
  447.           draw_y5++;
  448.           draw_y6--;
  449.           draw_y7--;


  450.           /* 要判断当前点是否在有效范围内 */
  451.           if( (draw_x0<=GUI_LCM_XMAX)&&(draw_y0>=0) )
  452.           {
  453.                   point.x = draw_x0;
  454.                   point.y = draw_y0;
  455.                   LCDDrawPoint( &point );
  456.           }
  457.           if( (draw_x1>=0)&&(draw_y1>=0) )
  458.           {
  459.                   point.x = draw_x1;
  460.                   point.y = draw_y1;
  461.                   LCDDrawPoint( &point );
  462.           }

  463.           /* 第二点水直线填充(下半圆的点) */
  464.           if(draw_x1>=0)
  465.           {  /* 设置填充线条起始点fill_x0 */
  466.              fill_x0 = draw_x1;
  467.              /* 设置填充线条起始点fill_y0 */
  468.              fill_y0 = draw_y1;
  469.          if(fill_y0>GUI_LCM_YMAX) fill_y0 = GUI_LCM_YMAX;
  470.          if(fill_y0<0) fill_y0 = 0;
  471.          /* 设置填充线条结束点fill_x1 */
  472.          fill_x1 = pCircle->x*2 - draw_x1;
  473.          if(fill_x1>GUI_LCM_XMAX) fill_x1 = GUI_LCM_XMAX;

  474.                  line.xs = fill_x0;
  475.                  line.xe = fill_x1;
  476.                  line.ys = line.ye = fill_y0;
  477.                  LCDDrawHRLine( &line );
  478.       }


  479.           if( (draw_x2<=GUI_LCM_XMAX)&&(draw_y2<=GUI_LCM_YMAX) )
  480.           {
  481.                   point.x = draw_x2;
  482.                   point.y = draw_y2;
  483.                   LCDDrawPoint( &point );
  484.           }

  485.           if( (draw_x3>=0)&&(draw_y3<=GUI_LCM_YMAX) )
  486.           {
  487.                   point.x = draw_x3;
  488.                   point.y = draw_y3;
  489.                   LCDDrawPoint( &point );
  490.           }

  491.           /* 第四点垂直线填充(上半圆的点) */
  492.           if(draw_x3>=0)
  493.           {  /* 设置填充线条起始点fill_x0 */
  494.              fill_x0 = draw_x3;
  495.              /* 设置填充线条起始点fill_y0 */
  496.              fill_y0 = draw_y3;
  497.          if(fill_y0>GUI_LCM_YMAX) fill_y0 = GUI_LCM_YMAX;
  498.          if(fill_y0<0) fill_y0 = 0;
  499.          /* 设置填充线条结束点fill_x1 */
  500.          fill_x1 = pCircle->x*2 - draw_x3;
  501.          if(fill_x1>GUI_LCM_XMAX) fill_x1 = GUI_LCM_XMAX;

  502.                  line.xs = fill_x0;
  503.                  line.xe = fill_x1;
  504.                  line.ys = line.ye = fill_y0;
  505.                  LCDDrawHRLine( &line );
  506.       }


  507.           if( (draw_x4<=GUI_LCM_XMAX)&&(draw_y4>=0) )
  508.           {
  509.                   point.x = draw_x4;
  510.                   point.y = draw_y4;
  511.                   LCDDrawPoint( &point );
  512.           }
  513.           if( (draw_x5>=0)&&(draw_y5>=0) )
  514.           {
  515.                   point.x = draw_x5;
  516.                   point.y = draw_y5;
  517.                   LCDDrawPoint( &point );
  518.           }

  519.           /* 第六点垂直线填充(上半圆的点) */
  520.           if(draw_x5>=0)
  521.           {  /* 设置填充线条起始点fill_x0 */
  522.              fill_x0 = draw_x5;
  523.              /* 设置填充线条起始点fill_y0 */
  524.              fill_y0 = draw_y5;
  525.          if(fill_y0>GUI_LCM_YMAX) fill_y0 = GUI_LCM_YMAX;
  526.          if(fill_y0<0) fill_y0 = 0;
  527.          /* 设置填充线条结束点fill_x1 */
  528.          fill_x1 = pCircle->x*2 - draw_x5;
  529.          if(fill_x1>GUI_LCM_XMAX) fill_x1 = GUI_LCM_XMAX;
  530.                  line.xs = fill_x0;
  531.                  line.xe = fill_x1;
  532.                  line.ys = line.ye = fill_y0;
  533.                  LCDDrawHRLine( &line );
  534.       }


  535.           if( (draw_x6<=GUI_LCM_XMAX)&&(draw_y6<=GUI_LCM_YMAX) )
  536.           {
  537.                   point.x = draw_x6;
  538.                   point.y = draw_y6;
  539.                   LCDDrawPoint( &point );
  540.           }

  541.           if( (draw_x7>=0)&&(draw_y7<=GUI_LCM_YMAX) )
  542.           {
  543.                   point.x = draw_x7;
  544.                   point.y = draw_y7;
  545.                   LCDDrawPoint( &point );
  546.           }

  547.           /* 第八点垂直线填充(上半圆的点) */
  548.           if(draw_x7>=0)
  549.           {  /* 设置填充线条起始点fill_x0 */
  550.              fill_x0 = draw_x7;
  551.              /* 设置填充线条起始点fill_y0 */
  552.              fill_y0 = draw_y7;
  553.          if(fill_y0>GUI_LCM_YMAX) fill_y0 = GUI_LCM_YMAX;
  554.          if(fill_y0<0) fill_y0 = 0;
  555.          /* 设置填充线条结束点fill_x1 */
  556.          fill_x1 = pCircle->x*2 - draw_x7;
  557.          if(fill_x1>GUI_LCM_XMAX) fill_x1 = GUI_LCM_XMAX;
  558.                  line.xs = fill_x0;
  559.                  line.xe = fill_x1;
  560.                  line.ys = line.ye = fill_y0;
  561.                  LCDDrawHRLine( &line );
  562.       }

  563.    }
  564. }
  565. /*
  566. ================================================================================
  567. Name: GUI_DrawEllipse( )
  568. Function: Display a ellipse at a special area
  569. Input:        -pCycle, A pinter point to a ellipse structure
  570. Output: None
  571. Author: LiYong
  572. Date  : 2008.08.09
  573. ================================================================================
  574. */
  575. void  GUI_DrawEllipse( ELLIPSE* pEllipse )
  576. {
  577.    INT32S  draw_x0, draw_y0;                        // 刽图点坐标变量
  578.    INT32S  draw_x1, draw_y1;
  579.    INT32S  draw_x2, draw_y2;
  580.    INT32S  draw_x3, draw_y3;
  581.    INT32S  xx, yy;                                        // 画图控制变量

  582.    INT32S  center_x, center_y;                // 椭圆中心点坐标变量
  583.    INT32S  radius_x, radius_y;                // 椭圆的半径,x轴半径和y轴半径
  584.    INT32S  radius_xx, radius_yy;                // 半径乘平方值
  585.    INT32S  radius_xx2, radius_yy2;        // 半径乘平方值的两倍
  586.    INT32S  di;                                                // 定义决策变量

  587.    POINT   point;

  588.    point.Color = pEllipse->Color;

  589.    /* 参数过滤 */
  590.    if( (pEllipse->xs == pEllipse->xe ) ||
  591.               (pEllipse->ys == pEllipse->ye ) ) return;

  592.    /* 计算出椭圆中心点坐标 */
  593.    center_x = (pEllipse->xs + pEllipse->xe) >> 1;
  594.    center_y = (pEllipse->ys + pEllipse->ye) >> 1;

  595.    /* 计算出椭圆的半径,x轴半径和y轴半径 */
  596.    if(pEllipse->xs > pEllipse->xe)
  597.    {  radius_x = (pEllipse->xs - pEllipse->xe) >> 1;
  598.    }
  599.    else
  600.    {  radius_x = (pEllipse->xe - pEllipse->xs) >> 1;
  601.    }
  602.    if(pEllipse->ys > pEllipse->ye)
  603.    {  radius_y = (pEllipse->ys - pEllipse->ye) >> 1;
  604.    }
  605.    else
  606.    {  radius_y = (pEllipse->ye - pEllipse->ys) >> 1;
  607.    }

  608.    /* 计算半径平方值 */
  609.    radius_xx = radius_x * radius_x;
  610.    radius_yy = radius_y * radius_y;

  611.    /* 计算半径平方值乘2值 */
  612.    radius_xx2 = radius_xx<<1;
  613.    radius_yy2 = radius_yy<<1;

  614.    /* 初始化画图变量 */
  615.    xx = 0;
  616.    yy = radius_y;

  617.    di = radius_yy2 + radius_xx - radius_xx2*radius_y ;        // 初始化决策变量

  618.    /* 计算出椭圆y轴上的两个端点坐标,作为作图起点 */
  619.    draw_x0 = draw_x1 = draw_x2 = draw_x3 = center_x;
  620.    draw_y0 = draw_y1 = center_y + radius_y;
  621.    draw_y2 = draw_y3 = center_y - radius_y;

  622.          point.x = draw_x0;
  623.          point.y = draw_y0;
  624.          LCDDrawPoint( &point );
  625.          point.x = draw_x2;
  626.          point.y = draw_y2;
  627.          LCDDrawPoint( &point );        // 画y轴上的两个端点

  628.    while( (radius_yy*xx) < (radius_xx*yy) )
  629.    {  if(di<0)
  630.           {  di+= radius_yy2*(2*xx+3);
  631.           }
  632.           else
  633.           {  di += radius_yy2*(2*xx+3) + 4*radius_xx - 4*radius_xx*yy;

  634.              yy--;
  635.                  draw_y0--;
  636.                  draw_y1--;
  637.                  draw_y2++;
  638.                  draw_y3++;
  639.           }

  640.           xx ++;                                                // x轴加1

  641.           draw_x0++;
  642.           draw_x1--;
  643.           draw_x2++;
  644.           draw_x3--;

  645.                 point.x = draw_x0;
  646.                 point.y = draw_y0;
  647.                 LCDDrawPoint( &point );
  648.                 point.x = draw_x1;
  649.                 point.y = draw_y1;
  650.                 LCDDrawPoint( &point );
  651.                 point.x = draw_x2;
  652.                 point.y = draw_y2;
  653.                 LCDDrawPoint( &point );
  654.                 point.x = draw_x3;
  655.                 point.y = draw_y3;
  656.                 LCDDrawPoint( &point );
  657.    }

  658.    di = radius_xx2*(yy-1)*(yy-1) + radius_yy2*xx*xx + radius_yy + radius_yy2*xx - radius_xx2*radius_yy;
  659.    while(yy>=0)
  660.    {  if(di<0)
  661.           {  di+= radius_xx2*3 + 4*radius_yy*xx + 4*radius_yy - 2*radius_xx2*yy;

  662.              xx ++;                                                // x轴加1
  663.              draw_x0++;
  664.              draw_x1--;
  665.              draw_x2++;
  666.              draw_x3--;
  667.           }
  668.           else
  669.           {  di += radius_xx2*3 - 2*radius_xx2*yy;
  670.           }

  671.           yy--;
  672.            draw_y0--;
  673.           draw_y1--;
  674.           draw_y2++;
  675.           draw_y3++;

  676.                 point.x = draw_x0;
  677.                 point.y = draw_y0;
  678.                 LCDDrawPoint( &point );
  679.                 point.x = draw_x1;
  680.                 point.y = draw_y1;
  681.                 LCDDrawPoint( &point );
  682.                 point.x = draw_x2;
  683.                 point.y = draw_y2;
  684.                 LCDDrawPoint( &point );
  685.                 point.x = draw_x3;
  686.                 point.y = draw_y3;
  687.                 LCDDrawPoint( &point );
  688.    }
  689. }
  690. /*
  691. ================================================================================
  692. Name: GUI_DrawEllipseFill( )
  693. Function: Display a ellipse at a special area and fill its area
  694. Input:        -pCycle, A pinter point to a ellipse structure
  695. Output: None
  696. Author: LiYong
  697. Date  : 2008.08.09
  698. ================================================================================
  699. */
  700. void  GUI_DrawEllipseFill( ELLIPSE* pEllipse )
  701. {
  702.         INT32S  draw_x0, draw_y0;                        // 刽图点坐标变量
  703.         INT32S  draw_x1, draw_y1;
  704.         INT32S  draw_x2, draw_y2;
  705.         INT32S  draw_x3, draw_y3;
  706.         INT32S  xx, yy;                                              // 画图控制变量

  707.         INT32S  center_x, center_y;                // 椭圆中心点坐标变量
  708.         INT32S  radius_x, radius_y;                // 椭圆的半径,x轴半径和y轴半径
  709.         INT32S  radius_xx, radius_yy;                // 半径乘平方值
  710.         INT32S  radius_xx2, radius_yy2;        // 半径乘平方值的两倍
  711.         INT32S  di;                                                // 定义决策变量

  712.         POINT point;
  713.         LINE  line;

  714.         point.Color = pEllipse->Color;
  715.         line.Color = pEllipse->Color;

  716.         /* 参数过滤 */
  717.         if( (pEllipse->xs==pEllipse->xe) ||
  718.             (pEllipse->ys==pEllipse->ye) ) return;

  719.         /* 计算出椭圆中心点坐标 */
  720.         center_x = (pEllipse->xs + pEllipse->xe) >> 1;
  721.         center_y = (pEllipse->ys + pEllipse->ye) >> 1;

  722.         /* 计算出椭圆的半径,x轴半径和y轴半径 */
  723.         if(pEllipse->xs > pEllipse->xe)
  724.         {
  725.                 radius_x = (pEllipse->xs - pEllipse->xe) >> 1;
  726.         }
  727.         else
  728.         {
  729.                 radius_x = (pEllipse->xe - pEllipse->xs) >> 1;
  730.         }
  731.         if(pEllipse->ys > pEllipse->ye)
  732.         {
  733.                 radius_y = (pEllipse->ys - pEllipse->ye) >> 1;
  734.         }
  735.         else
  736.         {
  737.                 radius_y = (pEllipse->ye - pEllipse->ys) >> 1;
  738.         }

  739.         /* 计算半径乘平方值 */
  740.         radius_xx = radius_x * radius_x;
  741.         radius_yy = radius_y * radius_y;

  742.         /* 计算半径乘4值 */
  743.         radius_xx2 = radius_xx<<1;
  744.         radius_yy2 = radius_yy<<1;

  745.         /* 初始化画图变量 */
  746.         xx = 0;
  747.         yy = radius_y;

  748.         di = radius_yy2 + radius_xx - radius_xx2*radius_y ;        // 初始化决策变量

  749.         /* 计算出椭圆y轴上的两个端点坐标,作为作图起点 */
  750.         draw_x0 = draw_x1 = draw_x2 = draw_x3 = center_x;
  751.         draw_y0 = draw_y1 = center_y + radius_y;
  752.         draw_y2 = draw_y3 = center_y - radius_y;

  753.         point.x = draw_x0;
  754.         point.y = draw_y0;
  755.         LCDDrawPoint( &point );
  756.         point.x = draw_x2;
  757.         point.y = draw_y2;
  758.         LCDDrawPoint( &point );// 画y轴上的两个端点

  759.    while( (radius_yy*xx) < (radius_xx*yy) )
  760.    {  if(di<0)
  761.           {  di+= radius_yy2*(2*xx+3);
  762.           }
  763.           else
  764.           {  di += radius_yy2*(2*xx+3) + 4*radius_xx - 4*radius_xx*yy;

  765.              yy--;
  766.                  draw_y0--;
  767.                  draw_y1--;
  768.                  draw_y2++;
  769.                  draw_y3++;
  770.           }

  771.           xx ++;                                                // x轴加1

  772.           draw_x0++;
  773.           draw_x1--;
  774.           draw_x2++;
  775.           draw_x3--;

  776.                 point.x = draw_x0;
  777.                 point.y = draw_y0;
  778.                 LCDDrawPoint( &point );
  779.                 point.x = draw_x1;
  780.                 point.y = draw_y1;
  781.                 LCDDrawPoint( &point );
  782.                 point.x = draw_x2;
  783.                 point.y = draw_y2;
  784.                 LCDDrawPoint( &point );
  785.                 point.x = draw_x3;
  786.                 point.y = draw_y3;
  787.                 LCDDrawPoint( &point );

  788.           /* 若y轴已变化,进行填充 */
  789.           if(di>=0)
  790.           {
  791.                   line.xs = draw_x0;
  792.                   line.xe = draw_x1;
  793.                   line.ys = line.ye = draw_y0;
  794.                   LCDDrawHRLine( &line );
  795.                   line.xs = draw_x2;
  796.                   line.xe = draw_x3;
  797.                   line.ys = line.ye = draw_y2;
  798.                   LCDDrawHRLine( &line );

  799.           }
  800.    }

  801.    di = radius_xx2*(yy-1)*(yy-1) + radius_yy2*xx*xx + radius_yy +
  802.         radius_yy2*xx - radius_xx2*radius_yy;
  803.    while(yy>=0)
  804.    {  if(di<0)
  805.           {  di+= radius_xx2*3 + 4*radius_yy*xx + 4*radius_yy - 2*radius_xx2*yy;

  806.              xx ++;                                                // x轴加1
  807.              draw_x0++;
  808.              draw_x1--;
  809.              draw_x2++;
  810.              draw_x3--;
  811.           }
  812.                 else
  813.                 {  di += radius_xx2*3 - 2*radius_xx2*yy;
  814.                 }

  815.                 yy--;
  816.                 draw_y0--;
  817.                 draw_y1--;
  818.                 draw_y2++;
  819.                 draw_y3++;

  820.                 point.x = draw_x0;
  821.                 point.y = draw_y0;
  822.                 LCDDrawPoint( &point );
  823.                 point.x = draw_x1;
  824.                 point.y = draw_y1;
  825.                 LCDDrawPoint( &point );
  826.                 point.x = draw_x2;
  827.                 point.y = draw_y2;
  828.                 LCDDrawPoint( &point );
  829.                 point.x = draw_x3;
  830.                 point.y = draw_y3;
  831.                 LCDDrawPoint( &point );

  832.           /* y轴已变化,进行填充 */
  833.                 line.xs = draw_x0;
  834.                 line.xe = draw_x1;
  835.                 line.ys = line.ye = draw_y0;
  836.                 LCDDrawHRLine( &line );
  837.                 line.xs = draw_x2;
  838.                 line.xe = draw_x3;
  839.                 line.ys = line.ye = draw_y2;
  840.                 LCDDrawHRLine( &line );
  841.    }
  842. }
  843. /*
  844. ================================================================================
  845. Name: GUI_Inital( )
  846. Function: Initialize GUI with single color
  847. Input:        -Color, Initialize color
  848. Output: None
  849. Author: LiYong
  850. Date  : 2008.08.09
  851. ================================================================================
  852. */
  853. void GUI_Inital( TCOLOR Color )
  854. {
  855.         DOLLOP dollop;

  856.         dollop.xs = 0;
  857.         dollop.xe = GUI_LCM_XMAX;
  858.         dollop.ys = 0;
  859.         dollop.ye = GUI_LCM_YMAX;
  860.         dollop.Color = Color;

  861.         LCDDrawDollop( &dollop );
  862. }        
  863. /*
  864. ================================================================================
  865. =======================================End of file==============================
  866. ================================================================================
  867. */
复制代码

彩屏汉字显示一.zip

137.05 KB, 下载次数: 2, 下载积分: 黑币 -5

彩屏汉字显示一

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表