void Draw_Ascii6X8_Downline(unsigned char x,unsigned char y,char asc)// 画6X8的下划线字符 { unsigned char i,n; unsigned char byte; if(asc > 'z' || asc < ' ') asc = 'z'+1; asc -= 0x20; for(i=0;i<6;i++)// 6列 { byte = FONT6x8[asc][i]; for(n=0;n<7;n++) { if(byte&1) { Draw_Point(x+i,y+n,1); } else { Draw_Point(x+i,y+n,0); } byte >>= 1; } Draw_Point(x+i,y+7,1);// 下划线 } }
static void Draw_StraightLine( const int x1, const int y1, const int x2, const int y2, color_t c) { register int i; register int start, end; if (x1 == x2) { /* vertical line */ if (y2 > y1) { start = y1; end = y2; } else { start = y2; end = y1; } for (i = start; i <= end; i++) { Draw_Point(x1, i, c); } } else if (y1 == y2) { /* horizontal line */ if (x2 > x1) { start = x1; end = x2; } else { start = x2; end = x1; } for (i = start; i <= end; i++) { Draw_Point(i, y1, c); } } return; }
void Draw_Ascii6X8(unsigned char x,unsigned char y,char asc)// 画6X8的字符 { unsigned char i,n; unsigned char byte; if(asc > 'z' || asc < ' ') asc = 'z'+1; asc -= 0x20; for(i=0;i<6;i++)// 6列 { byte = FONT6x8[asc][i]; for(n=0;n<8;n++)// 每列8个点 { if(byte&1) { Draw_Point(x+i,y+n,1); } else { Draw_Point(x+i,y+n,0); } byte >>= 1; } } }
/***************************************** 名称:Draw_Circle (在任意位置画圆) 说明:使用Bresenham法画1/8个圆,在用对称性画出其他的7/8个圆 按下图把圆分为8份 0 7 1 6 2 5 3 4 *****************************************/ void Draw_Circle(u16 x0,u16 y0,u16 r,u16 color) { u16 a,b; s16 di; a = 0; b = r; di = 3-2*r; //判断下个点位置的标志 while(a <= b) { Draw_Point(x0-b,y0-a,color); //3 Draw_Point(x0+b,y0-a,color); //0 Draw_Point(x0-a,y0+b,color); //1 Draw_Point(x0-b,y0-a,color); //7 Draw_Point(x0-a,y0-b,color); //2 Draw_Point(x0+b,y0+a,color); //4 Draw_Point(x0+a,y0-b,color); //5 Draw_Point(x0+a,y0+b,color); //6 Draw_Point(x0-b,y0+a,color); a++; //使用Bresenham算法画圆 if(di<0) { di += 4*a+6; } else { di += 10 + 4 * (a-b); b--; } Draw_Point(x0+a,y0+b,color); } }
/******************************************************** * 名称:Draw_Line(u16 x0,u16 y0,u16 x1,u16 y1,u16 color) * * 功能:任意两点间的直线。根据硬件特点,实现加速。 * * 入口参数:x0 直线起点所在行的位置 * y0 直线起点所在列的位置 * x1 直线终点所在行的位置 * y1 直线终点所在列的位置 * 出口参数:无 * 说明:操作失败原因是指定地址超出缓冲区范围 *********************************************************/ void Draw_Line(u16 x0,u16 y0,u16 x1,u16 y1,u16 color) { s16 delta_x,delta_y; s16 incx,incy; s16 x=0,y=0; s16 distance,t; delta_x = x1 - x0; delta_y = y1 - y0; if(delta_x > 0) { incx = 1; }else if(delta_x == 0) { Draw_YLine(x0,y0,y1,color);//画条竖线再退出 return; }else { incx = -1; } if(delta_y > 0) { incy = 1; }else if(delta_y == 0) { Draw_XLine(x0,y0,x1,color);//画条横线再退出 return; }else { incy = -1; } delta_x = abs(delta_x); delta_y = abs(delta_y); if( delta_x > delta_y ) { distance = delta_x ; } else { distance = delta_y ; } Draw_Point(x0,y0,color);//发现没用! //开始画线 for(t = 0; t <= distance+1; t++) { Draw_Point(x0,y0,color); x += delta_x; y += delta_y; if(x > distance) { x -= distance; x0 += incx; } if(y > distance) { y -= distance; y0 += incy; } } }
void Draw_Circle(unsigned int x0,unsigned int y0,unsigned int r, unsigned int color) { int x=0,y=r,f=0; while(x<=y) { if ((x0+x<240)&&(x0+x>=0)&&(y0+y<320)&&(y0+y>=0)) Draw_Point(x0+x,y0+y,color); if ((x0+x<240)&&(x0+x>=0)&&(y0-y<320)&&(y0-y>=0)) Draw_Point(x0+x,y0-y,color); if ((x0-x<240)&&(x0-x>=0)&&(y0+y<320)&&(y0+y>=0)) Draw_Point(x0-x,y0+y,color); if ((x0-x<240)&&(x0-x>=0)&&(y0-y<320)&&(y0-y>=0)) Draw_Point(x0-x,y0-y,color); if ((x0+y<240)&&(x0+y>=0)&&(y0+x<320)&&(y0+x>=0)) Draw_Point(x0+y,y0+x,color); if ((x0+y<240)&&(x0+y>=0)&&(y0-x<320)&&(y0-x>=0)) Draw_Point(x0+y,y0-x,color); if ((x0-y<240)&&(x0-y>=0)&&(y0+x<320)&&(y0+x>=0)) Draw_Point(x0-y,y0+x,color); if ((x0-y<240)&&(x0-y>=0)&&(y0-x<320)&&(y0-x>=0)) Draw_Point(x0-y,y0-x,color); if(f<=0) { f=f+2*x+1; x++; } else { f=f-2*y+1; y--; } } }
static void DrawGuideImage( DrawBuffer *b, SDL_Surface *guideImage, Uint8 alpha) { SDL_LockSurface(guideImage); // Scale based on ratio between map size and guide image size, // so that the guide image stretches to the map size double xScale = (double)guideImage->w / (gMap.Size.x * TILE_WIDTH); double yScale = (double)guideImage->h / (gMap.Size.y * TILE_HEIGHT); for (int j = 0; j < b->g->cachedConfig.Res.y; j++) { int y = (int)round((j + b->yTop) * yScale); for (int i = 0; i < b->g->cachedConfig.Res.x; i++) { int x = (int)round((i + b->xTop) * xScale); if (x >= 0 && x < guideImage->w && y >= 0 && y < guideImage->h) { int imgIndex = y * guideImage->w + x; Uint32 p = ((Uint32 *)guideImage->pixels)[imgIndex]; color_t c = PixelToColor(b->g, p); c.a = alpha; Draw_Point(i, j, c); } } } SDL_UnlockSurface(guideImage); }
void Draw_Lump_fb(uint8_t xs,uint8_t ys,uint8_t xe,uint8_t ye)// 指定块大小的反白 { uint8_t len,n; if((xs>xe)||(ys>ye))return ;// 超界,不处理 for(len=xs;len<=xe;len++)// 每行 { for(n=ys;n<=ye;n++)// 每竖8点 { if(Draw_GetPointColor(len,n))// 点颜色 为有效1 { Draw_Point(len,n,0);// 空点 } else { Draw_Point(len,n,1);// 实点 } } } }
void DrawRectangle( GraphicsDevice *device, Vec2i pos, Vec2i size, color_t color, int flags) { int y; if (size.x < 3 || size.y < 3) { flags &= ~DRAW_FLAG_ROUNDED; } for (y = MAX(pos.y, device->clipping.top); y < MIN(pos.y + size.y, device->clipping.bottom + 1); y++) { int isFirstOrLastLine = y == pos.y || y == pos.y + size.y - 1; if (isFirstOrLastLine && (flags & DRAW_FLAG_ROUNDED)) { int x; for (x = MAX(pos.x + 1, device->clipping.left); x < MIN(pos.x + size.x - 1, device->clipping.right + 1); x++) { Draw_Point(x, y, color); } } else if (!isFirstOrLastLine && (flags & DRAW_FLAG_LINE)) { Draw_Point(pos.x, y, color); Draw_Point(pos.x + size.x - 1, y, color); } else { int x; for (x = MAX(pos.x, device->clipping.left); x < MIN(pos.x + size.x, device->clipping.right + 1); x++) { Draw_Point(x, y, color); } } } }
/***************************************************************** 画一条竖线 */ void Draw_YLine(u16 x0,u16 y0,u16 y1,u16 color) { u16 temp; if(y0 > y1) { temp = y1; y1 = y0; y0 = temp; } for(;y0 <= y1; y0++) { Draw_Point(x0,y0,color); } }
/***************************************************************** 画一条横线 */ void Draw_XLine(u16 x0,u16 y0,u16 x1,u16 color) { u16 temp; if(x0 > x1) { temp = x1; x1 = x0; x0 = temp; } for(;x0 <= x1; x0++) { Draw_Point(x0,y0,color); } }
/************************************************************************** 此函数为一图片显示函数 输入参数说明: sx 表示图片显示位置的起始x坐标 sy 表示y坐标 Pic 表示图片数据来源 size_x 表示图片横向大小 size_y 表示图片竖向大小 注意: 图片数据的格式必须是:( 取模方式=逐行 取模走向=逆向 ) */ void Show_Picture(u8 sx,u8 sy,u8 const *Pic,u8 size_x,u8 size_y)// 显示图片函数,Pic数据指针必须指向 *特定格式图片 { u8 i,h,n,tp; for(h=sy;h<(sy+size_y);h++) { for(i=sx;i<(sx+size_x);) { tp = *Pic++; for(n=0;n<8;n++) { if(tp&1) { Draw_Point(i++,h,1); } else { Draw_Point(i++,h,0); } tp >>= 1; } } } }
static void Draw_DiagonalLine(const int x1, const int x2, color_t c) { register int i; register int start, end; if (x1 < x2) { start = x1; end = x2; } else { start = x2; end = x1; } for (i = start; i < end; i++) { Draw_Point(i, i, c); } return; }
/******************************************************** * 名称 Draw_Line() 采用布兰森汉姆(Bresenham)算法画线 * 功能:任意两点间的直线。根据硬件特点,实现加速。 * 入口参数:x0 直线起点所在行的位置 * y0 直线起点所在列的位置 * x1 直线终点所在行的位置 ' y1 直线终点所在列的位置 * 出口参数: 无 * 说明:操作失败原因是指定地址超出缓冲区范围。 *********************************************************/ void Draw_Line(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, unsigned int color) { signed int temp; signed int dx,dy; //定义起点到终点的横、纵坐标增加值 signed int s1,s2,status,i; signed int Dx,Dy,sub; dx=x1-x0; if(dx>=0) //X的方向是增加的 s1=1; else //X的方向是降低的 s1=-1; dy=y1-y0; //判断Y的方向是增加还是降到的 if(dy>=0) s2=1; else s2=-1; Dx=(x1-x0)*s1; //计算横、纵标志增加值的绝对值 Dy=(y1-y0)*s2; if(Dy>Dx) { //以45度角为分界线,靠进Y轴是status=1,靠近X轴是status=0 temp=Dx; Dx=Dy; Dy=temp; status=1; } else status=0; /********判断垂直线和水平线********/ if(dx==0) //横向上没有增量,画一条垂直线 { Draw_Vline(x0,y0,y1,color); return; } if(dy==0) //纵向上没有增量,画一条水平线 { Draw_Hline(x0,x1,y1,color); return; } /*********Bresenham算法画任意两点间的直线********/ sub=(Dy<<1)-Dx; //第1次判断下个点的位置 for(i=0;i<Dx;i++) { Draw_Point(x0, y0, color); //画点 if(sub>=0) { if(status==1) //在靠近Y轴区,x值加1 x0+=s1; else //在靠近X轴区,y值加1 y0+=s2; sub-=Dx<<1; //判断下下个点的位置 } if(status==1) y0+=s2; else x0+=s1; sub+=Dy<<1; } Draw_Point(x1, y1, color); }
static void DrawPointFunc(void *data, const Vec2i pos) { const color_t *c = data; Draw_Point(pos.x, pos.y, *c); }
void Draw_Oval(unsigned int x, unsigned int y, unsigned int a, unsigned int b, unsigned int color) //中点算法绘制椭圆 { unsigned int xc=300,yc=200; double d1,d2; x=0;y=b; d1=b*b+a*a*(-b+0.25); Draw_Point(x+300,y+200,color); Draw_Point(-x+300,y+200,color); Draw_Point(x+300,-y+200,color); Draw_Point(-x+300,-y+200,color); while(b*b*(x+1)<a*a*(y-0.5)) { if(d1<0) { d1+=b*b*(2*x+3); x++; } else { d1+=b*b*(2*x+3)+a*a*(-2*y+2); x++;y--; } Draw_Point(x+xc,y+yc,color); Draw_Point(-x+xc,y+yc,color); Draw_Point(x+xc,-y+yc,color); Draw_Point(-x+xc,-y+yc,color); } d2=sqrt(b*(x+0.5))+a*(y-1)-a*b; while(y>0) { if(d2<0) { d2+=b*b*(2*x+2)+a*a*(-2*y+3); x++; y--; } else { d2+=a*a*(-2*y+3); y--; } Draw_Point(x+xc,y+yc,color); Draw_Point(-x+xc,y+yc,color); Draw_Point(x+xc,-y+yc,color); Draw_Point(-x+xc,-y+yc,color); } }