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

📄 gui_basic.c

📁 完整的周立功公司的LPC213X开发板的光盘内容
💻 C
📖 第 1 页 / 共 4 页
字号:
   /* 设置起始点及终点 */
   if(endangle>stangle) draw_on = 1;		// 若终点大于起点,则从一开始即画点(359)
   stangle = (360-stangle)*pno_angle/45;
   endangle = (360-endangle)*pno_angle/45;
   if(stangle==0) stangle=1;
   if(endangle==0) endangle=1;
   
   /* 开始顺时针画弧,从359度开始(第4像限) */
   pno_angle = 0;
   
   draw_x = x+r;
   draw_y = y;         
   op_x = r;
   op_y = 0;
   while(1)
   {  /* 计算下一点 */
      op_y++;
      draw_y--;
      if( (2*op_x*op_x + 2*op_y*op_y - op_2rr - 2*op_x +1)>0 ) 	// 使用逐点比较法实现画圆弧
      {  op_x--;
         draw_x--;
      }
      if(draw_on==1) GUI_Point(draw_x, draw_y, color);			// 开始画图
      pno_angle++;
      if( (pno_angle==stangle)||(pno_angle==endangle) )			// 若遇到起点或终点,画点开关取反
      {  draw_on = 1-draw_on;
         if(draw_on==1) GUI_Point(draw_x, draw_y, color);
      } 
      if(op_y>=op_x)
      {  if(draw_on==1) GUI_Point(draw_x, draw_y, color);
         break;
      }
   }
   
   while(1)
   {  /* 计算下一点 */
      op_x--;
      draw_x--;
      if( (2*op_x*op_x + 2*op_y*op_y - op_2rr + 2*op_y +1)<=0 ) // 使用逐点比较法实现画圆弧
      {  op_y++;
         draw_y--;
      }
      if(draw_on==1) GUI_Point(draw_x, draw_y, color);			// 开始画图
      pno_angle++;
      if( (pno_angle==stangle)||(pno_angle==endangle) )			// 若遇到起点或终点,画点开关取反
      {  draw_on = 1-draw_on;
         if(draw_on==1) GUI_Point(draw_x, draw_y, color);
      } 
      
      if(op_x<=0)
      {  if(draw_on==1) GUI_Point(draw_x, draw_y, color);		// 开始画图
         break;
      }
   }
    
    
   /* 开始顺时针画弧,从269度开始(第3像限) */
   draw_y = y-r;
   draw_x = x;         
   op_y = r;
   op_x = 0;
   while(1)
   {  /* 计算下一点 */
      op_x++;
      draw_x--;
      if( (2*op_x*op_x + 2*op_y*op_y - op_2rr - 2*op_y +1)>0 ) // 使用逐点比较法实现画圆弧
      {  op_y--;
         draw_y++;
      }
      if(draw_on==1) GUI_Point(draw_x, draw_y, color);			// 开始画图
      pno_angle++;
      if( (pno_angle==stangle)||(pno_angle==endangle) )			// 若遇到起点或终点,画点开关取反
      {  draw_on = 1-draw_on;
         if(draw_on==1) GUI_Point(draw_x, draw_y, color);
      } 
      
      if(op_x>=op_y)
      {  if(draw_on==1) GUI_Point(draw_x, draw_y, color);		// 开始画图
         break;
      }
   }
   
   while(1)
   {  /* 计算下一点 */
      op_y--;
      draw_y++;
      if( (2*op_x*op_x + 2*op_y*op_y - op_2rr + 2*op_x +1)<=0 ) // 使用逐点比较法实现画圆弧
      {  op_x++;
         draw_x--;
      }
      if(draw_on==1) GUI_Point(draw_x, draw_y, color);			// 开始画图
      pno_angle++;
      if( (pno_angle==stangle)||(pno_angle==endangle) )			// 若遇到起点或终点,画点开关取反
      {  draw_on = 1-draw_on;
         if(draw_on==1) GUI_Point(draw_x, draw_y, color);
      } 
      if(op_y<=0)
      {  if(draw_on==1) GUI_Point(draw_x, draw_y, color);
         break;
      }
   }
   
   
   /* 开始顺时针画弧,从179度开始(第2像限) */
   draw_x = x-r;
   draw_y = y;         
   op_x = r;
   op_y = 0;
   while(1)
   {  /* 计算下一点 */
      op_y++;
      draw_y++;
      if( (2*op_x*op_x + 2*op_y*op_y - op_2rr - 2*op_x +1)>0 ) 	// 使用逐点比较法实现画圆弧
      {  op_x--;
         draw_x++;
      }
      if(draw_on==1) GUI_Point(draw_x, draw_y, color);			// 开始画图
      pno_angle++;
      if( (pno_angle==stangle)||(pno_angle==endangle) )			// 若遇到起点或终点,画点开关取反
      {  draw_on = 1-draw_on;
         if(draw_on==1) GUI_Point(draw_x, draw_y, color);
      } 
      if(op_y>=op_x)
      {  if(draw_on==1) GUI_Point(draw_x, draw_y, color);
         break;
      }
   }
   
   while(1)
   {  /* 计算下一点 */
      op_x--;
      draw_x++;
      if( (2*op_x*op_x + 2*op_y*op_y - op_2rr + 2*op_y +1)<=0 ) // 使用逐点比较法实现画圆弧
      {  op_y++;
         draw_y++;
      }
      if(draw_on==1) GUI_Point(draw_x, draw_y, color);			// 开始画图
      pno_angle++;
      if( (pno_angle==stangle)||(pno_angle==endangle) )			// 若遇到起点或终点,画点开关取反
      {  draw_on = 1-draw_on;
         if(draw_on==1) GUI_Point(draw_x, draw_y, color);
      } 
      
      if(op_x<=0)
      {  if(draw_on==1) GUI_Point(draw_x, draw_y, color);		// 开始画图
         break;
      }
   }
  
  
   /* 开始顺时针画弧,从89度开始(第1像限) */
   draw_y = y+r;
   draw_x = x;         
   op_y = r;
   op_x = 0;
   while(1)
   {  /* 计算下一点 */
      op_x++;
      draw_x++;
      if( (2*op_x*op_x + 2*op_y*op_y - op_2rr - 2*op_y +1)>0 ) // 使用逐点比较法实现画圆弧
      {  op_y--;
         draw_y--;
      }
      if(draw_on==1) GUI_Point(draw_x, draw_y, color);			// 开始画图
      pno_angle++;
      if( (pno_angle==stangle)||(pno_angle==endangle) )			// 若遇到起点或终点,画点开关取反
      {  draw_on = 1-draw_on;
         if(draw_on==1) GUI_Point(draw_x, draw_y, color);
      } 
      
      if(op_x>=op_y)
      {  if(draw_on==1) GUI_Point(draw_x, draw_y, color);		// 开始画图
         break;
      }
   }
   
   while(1)
   {  /* 计算下一点 */
      op_y--;
      draw_y--;
      if( (2*op_x*op_x + 2*op_y*op_y - op_2rr + 2*op_x +1)<=0 ) // 使用逐点比较法实现画圆弧
      {  op_x++;
         draw_x++;
      }
      if(draw_on==1) GUI_Point(draw_x, draw_y, color);			// 开始画图
      pno_angle++;
      if( (pno_angle==stangle)||(pno_angle==endangle) )			// 若遇到起点或终点,画点开关取反
      {  draw_on = 1-draw_on;
         if(draw_on==1) GUI_Point(draw_x, draw_y, color);
      } 
      if(op_y<=0)
      {  if(draw_on==1) GUI_Point(draw_x, draw_y, color);
         break;
      }
   }
   
}
#endif




#if  GUI_Pieslice_EN==1
/****************************************************************************
* 名称:GUI_Pieslice()
* 功能:指定起点、终点及半径扇形(不能画圆)。使用的是顺时针方向画图。
* 入口参数: x			圆心的x轴坐标值
*           y			圆心的y轴坐标值
*           stangle 	起始角度(0-359度)
*           endangle	终止角度(0-359度)
*           r  			圆的半径终点
*           color		显示颜色
* 出口参数:无
* 说明:操作失败原因是指定地址超出有效范围。
****************************************************************************/
void  GUI_Pieslice(uint32 x, uint32 y, uint32 r, uint32 stangle, uint32 endangle, TCOLOR color)
{  int32  draw_x, draw_y;					// 画图坐标变量
   int32  op_x, op_y;						// 操作坐标
   int32  op_2rr;							// 2*r*r值变量
   
   int32  pno_angle;						// 度角点的个数
   uint8  draw_on;							// 画点开关,为1时画点,为0时不画
   
   
   /* 参数过滤 */
   if(r==0) return;							// 半径为0则直接退出
   if(stangle==endangle) return;			// 起始角度与终止角度相同,退出
   if( (stangle>=360) || (endangle>=360) ) return;

   op_2rr = 2*r*r;							// 计算r平方乖以2
   pno_angle = 0;
   /* 先计算出在此半径下的45度的圆弧的点数 */       
   op_x = r;
   op_y = 0;
   while(1)
   {  pno_angle++; 							// 画点计数         
      /* 计算下一点 */
      op_y++;
      if( (2*op_x*op_x + 2*op_y*op_y - op_2rr - 2*op_x +1)>0 ) 	// 使用逐点比较法实现画圆弧
      {  op_x--;
      }
      if(op_y>=op_x) break;
   }
   
   draw_on = 0;								// 最开始关画点开关
   /* 设置起始点及终点 */
   if(endangle>stangle) draw_on = 1;		// 若终点大于起点,则从一开始即画点(359)
   stangle = (360-stangle)*pno_angle/45;
   endangle = (360-endangle)*pno_angle/45;
   if(stangle==0) stangle=1;
   if(endangle==0) endangle=1;
   
   /* 开始顺时针画弧,从359度开始(第4像限) */
   pno_angle = 0;
   
   draw_x = x+r;
   draw_y = y;         
   op_x = r;
   op_y = 0;
   while(1)
   {  /* 计算下一点 */
      op_y++;
      draw_y--;
      if( (2*op_x*op_x + 2*op_y*op_y - op_2rr - 2*op_x +1)>0 ) 	// 使用逐点比较法实现画圆弧
      {  op_x--;
         draw_x--;
      }
      if(draw_on==1) GUI_Point(draw_x, draw_y, color);			// 开始画图
      pno_angle++;
      if( (pno_angle==stangle)||(pno_angle==endangle) )			// 若遇到起点或终点,画点开关取反
      {  draw_on = 1-draw_on;
         if(draw_on==1) GUI_Point(draw_x, draw_y, color);
         GUI_Line(x, y, draw_x, draw_y, color);
      } 
      if(op_y>=op_x)
      {  if(draw_on==1) GUI_Point(draw_x, draw_y, color);
         break;
      }
   }
   
   while(1)
   {  /* 计算下一点 */
      op_x--;
      draw_x--;
      if( (2*op_x*op_x + 2*op_y*op_y - op_2rr + 2*op_y +1)<=0 ) // 使用逐点比较法实现画圆弧
      {  op_y++;
         draw_y--;
      }
      if(draw_on==1) GUI_Point(draw_x, draw_y, color);			// 开始画图
      pno_angle++;
      if( (pno_angle==stangle)||(pno_angle==endangle) )			// 若遇到起点或终点,画点开关取反
      {  draw_on = 1-draw_on;
         if(draw_on==1) GUI_Point(draw_x, draw_y, color);
         GUI_Line(x, y, draw_x, draw_y, color);
      } 
      
      if(op_x<=0)
      {  if(draw_on==1) GUI_Point(draw_x, draw_y, color);		// 开始画图
         break;
      }
   }
    
    
   /* 开始顺时针画弧,从269度开始(第3像限) */
   draw_y = y-r;
   draw_x = x;         
   op_y = r;
   op_x = 0;
   while(1)
   {  /* 计算下一点 */
      op_x++;
      draw_x--;
      if( (2*op_x*op_x + 2*op_y*op_y - op_2rr - 2*op_y +1)>0 ) // 使用逐点比较法实现画圆弧
      {  op_y--;
         draw_y++;
      }
      if(draw_on==1) GUI_Point(draw_x, draw_y, color);			// 开始画图
      pno_angle++;
      if( (pno_angle==stangle)||(pno_angle==endangle) )			// 若遇到起点或终点,画点开关取反
      {  draw_on = 1-draw_on;
         if(draw_on==1) GUI_Point(draw_x, draw_y, color);
         GUI_Line(x, y, draw_x, draw_y, color);
      } 
      
      if(op_x>=op_y)
      {  if(draw_on==1) GUI_Point(draw_x, draw_y, color);		// 开始画图
         break;
      }
   }
   
   while(1)
   {  /* 计算下一点 */
      op_y--;
      draw_y++;
      if( (2*op_x*op_x + 2*op_y*op_y - op_2rr + 2*op_x +1)<=0 ) // 使用逐点比较法实现画圆弧
      {  op_x++;
         draw_x--;
      }
      if(draw_on==1) GUI_Point(draw_x, draw_y, color);			// 开始画图
      pno_angle++;
      if( (pno_angle==stangle)||(pno_angle==endangle) )			// 若遇到起点或终点,画点开关取反
      {  draw_on = 1-draw_on;
         if(draw_on==1) GUI_Point(draw_x, draw_y, color);
         GUI_Line(x, y, draw_x, draw_y, color);
      } 
      if(op_y<=0)
      {  if(draw_on==1) GUI_Point(draw_x, draw_y, color);
         break;
      }
   }
   
   
   /* 开始顺时针画弧,从179度开始(第2像限) */
   draw_x = x-r;
   draw_y = y;         
   op_x = r;
   op_y = 0;
   while(1)
   {  /* 计算下一点 */
      op_y++;
      draw_y++;
      if( (2*op_x*op_x + 2*op_y*op_y - op_2rr - 2*op_x +1)>0 ) 	// 使用逐点比较法实现画圆弧
      {  op_x--;
         draw_x++;
      }
      if(draw_on==1) GUI_Point(draw_x, draw_y, color);			// 开始画图
      pno_angle++;
      if( (pno_angle==stangle)||(pno_angle==endangle) )			// 若遇到起点或终点,画点开关取反
      {  draw_on = 1-draw_on;
         if(draw_on==1) GUI_Point(draw_x, draw_y, color);
         GUI_Line(x, y, draw_x, draw_y, color);
      } 
      if(op_y>=op_x)
      {  if(draw_on==1) GUI_Point(draw_x, draw_y, color);
         break;
      }
   }
   
   while(1)
   {  /* 计算下一点 */
      op_x--;
      draw_x++;
      if( (2*op_x*op_x + 2*op_y*op_y - op_2rr + 2*op_y +1)<=0 ) // 使用逐点比较法实现画圆弧
      {  op_y++;
         draw_y++;
      }
      if(draw_on==1) GUI_Point(draw_x, draw_y, color);			// 开始画图
      pno_angle++;
      if( (pno_angle==stangle)||(pno_angle==endangle) )			// 若遇到起点或终点,画点开关取反
      {  draw_on = 1-draw_on;
         if(draw_on==1) GUI_Point(draw_x, draw_y, color);
         GUI_Line(x, y, draw_x, draw_y, color);
      } 
      
      if(op_x<=0)
      {  if(draw_on==1) GUI_Point(draw_x, draw_y, color);		// 开始画图
         break;
      }
   }
  
  
   /* 开始顺时针画弧,从89度开始(第1像限) */
   draw_y = y+r;
   draw_x = x;         
   op_y = r;
   op_x = 0;
   while(1)
   {  /* 计算下一点 */
      op_x++;
      draw_x++;
      if( (2*op_x*op_x + 2*op_y*op_y - op_2rr - 2*op_y +1)>0 ) // 使用逐点比较法实现画圆弧
      {  op_y--;
         draw_y--;
      }
      if(draw_on==1) GUI_Point(draw_x, draw_y, color);			// 开始画图
      pno_angle++;
      if( (pno_angle==stangle)||(pno_angle==endangle) )			// 若遇到起点或终点,画点开关取反
      {  draw_on = 1-draw_on;
         if(draw_on==1) GUI_Point(draw_x, draw_y, color);
         GUI_Line(x, y, draw_x, draw_y, color);
      } 
      
      if(op_x>=op_y)
      {  if(draw_on==1) GUI_Point(draw_x, draw_y, color);		// 开始画图
         break;
      }
   }
   
   while(1)
   {  /* 计算下一点 */
      op_y--;
      draw_y--;
      if( (2*op_x*op_x + 2*op_y*op_y - op_2rr + 2*op_x +1)<=0 ) // 使用逐点比较法实现画圆弧
      {  op_x++;
         draw_x++;
      }
      if(draw_on==1) GUI_Point(draw_x, draw_y, color);			// 开始画图
      pno_angle++;
      if( (pno_angle==stangle)||(pno_angle==endangle) )			// 若遇到起点或终点,画点开关取反
      {  draw_on = 1-draw_on;
         if(draw_on==1) GUI_Point(draw_x, draw_y, color);
         GUI_Line(x, y, draw_x, draw_y, color);
      } 
      if(op_y<=0)
      {  if(draw_on==1) GUI_Point(draw_x, draw_y, color);
         break;
      }
   }
   
}
#endif





















⌨️ 快捷键说明

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