ucgui 画扇形

相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#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*o

p_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

相关文档
最新文档