📄 wingdi.c
字号:
int y0 = b;
int a0 = a;
int b0 = b;
int asqr = a0 * a0;
int two_asqr = asqr<<1;
int bsqr = b0 * b0;
int two_bsqr = bsqr<<1;
int d, dx, dy;
d = bsqr - asqr * b0 + (asqr >> 2);
dx = 0;
dy = (long)two_asqr * b0;
do
{ if ( d > 0 )
{ DrawHorLine(dc,x-x0,y+y0,(x0<<1)+1);
DrawHorLine(dc,x-x0,y-y0,(x0<<1)+1);
y0--;
dy -= two_asqr;
d -= dy;
}
x0++;
dx += two_bsqr;
d += (bsqr+dx);
}while ( dx < dy );
d += (3*(asqr-bsqr)/2 - (dx+dy))/2;
do
{ DrawHorLine(dc,x-x0,y+y0,(x0<<1)+1);
DrawHorLine(dc,x-x0,y-y0,(x0<<1)+1);
if ( d < 0 )
{ x0++;
dx += two_bsqr;
d += dx;
}
y0--;
dy -= two_asqr;
d += (asqr-dy);
} while (y0>=0);
}
//---------------------------------------------------------------------------
void FillCircle(HDC dc, int xCenter, int yCenter, int radius)
{ int x, y, d,w;
if(radius<=0)return;
x = xCenter;
y = yCenter + radius;
d = 3 - 2 * radius;
while (x - xCenter <= y - yCenter)
{ w=((y - yCenter)<<1)+1;
DrawHorLine(dc,xCenter - (y - yCenter),yCenter + (x - xCenter ),w) ;
if(x != xCenter)DrawHorLine(dc,xCenter - (y - yCenter),yCenter - (x - xCenter),w) ;
if ( d < 0 )
{ d = d + ((x - xCenter) << 2) + 6;
}
else if(x - xCenter < y - yCenter)
{ w=((x-xCenter)<<1)+1;
DrawHorLine(dc,xCenter - (x - xCenter),y,w);
DrawHorLine(dc,xCenter - (x - xCenter) ,yCenter - (y - yCenter),w) ;
d = d + (((x - xCenter) - (y - yCenter)) << 2 ) + 10;
y--;
}
x++;
}
}
//---------------------------------------------------------------------------
void DrawPatternHorLine(HDC dc, int x,int y,int width,BYTE pattern,BOOL bigEndian)
{ PIXEL *PixelPos;
int i,j;
int OriginLeft=x;
DWORD dwRop=((TWndCanvas *)dc)->Mode&0x03;
PIXEL ForeColorIndex=((TWndCanvas *)dc)->Foreground;
BYTE PtnBits[8];
int BitOffset;
CHECK_CANVAS_HORLINE((TWndCanvas *)dc,x,y,width);
if(bigEndian)
{ for(i=0,j=x-OriginLeft;i<8;i++,j++)
PtnBits[i]=(pattern<<(j&0x7))&0x80;
}
else
{ for(i=0,j=x-OriginLeft;i<8;i++,j++)
PtnBits[i]=(pattern>>(j&0x7))&0x01;
}
GetPixelPosition( &PixelPos, &BitOffset, (TWndCanvas *)dc, x, y );
#if(BITS_PER_PIXEL==PIXEL_UNIT) /* 8 16 32 */
{ for(i=0;i<width;i++)
{ if(PtnBits[i&0x7])
{ SET_PIXEL_LOGIC( PixelPos, *PixelPos, ForeColorIndex, dwRop );
}
PixelPos++;
}
}
#elif(BITS_PER_PIXEL==24)
{ BYTE ForeColorByte1=(BYTE)ForeColorIndex;
BYTE ForeColorByte2=(BYTE)(ForeColorIndex>>8);
BYTE ForeColorByte3=(BYTE)(ForeColorIndex>>16);
for(i=0;i<width;i++)
{ if(PtnBits[i&0x7])
{ SET_3BYTE_LOGIC( PixelPos, ForeColorByte1,ForeColorByte1,ForeColorByte1,dwRop );
}
PixelPos=(PIXEL *)((BYTE *)PixelPos +3);
}
}
#elif(BITS_PER_PIXEL<8)
{ PIXEL srcMask,srcValue;
for(i=0;i<width;i++)
{ if(PtnBits[i&0x7])
{ srcValue=ForeColorIndex;
srcMask=(PIXEL)MASK_OFFSET_OPT(BITS_PER_PIXEL,BitOffset);
PIXEL_OFFSET_OPT(srcValue,BITS_PER_PIXEL,BitOffset);
SET_PIXEL_LOGIC(&srcValue,*PixelPos,srcValue,dwRop);
*PixelPos=(*PixelPos & ~srcMask)|(srcValue & srcMask);
}
GetNextPixelPosition( &PixelPos, &BitOffset, PixelPos, BitOffset );
}
}
#endif
CM_ExposeCanvas((TWndCanvas *)dc,x,y,width,1);
}
//---------------------------------------------------------------------------
void DrawPatternVerLine(HDC dc, int x,int y,int height,BYTE pattern,BOOL bigEndian)
{ VRAM *vram=((TWndCanvas *)dc)->Vram;
PIXEL *PixelPos;
int i,j;
int OriginTop=y;
DWORD dwRop=((TWndCanvas *)dc)->Mode&0x03;
PIXEL ForeColorIndex=((TWndCanvas *)dc)->Foreground;
BYTE PtnBits[8];
int BitOffset;
CHECK_CANVAS_VERLINE((TWndCanvas *)dc,x,y,height);
if(bigEndian)
{ for(i=0,j=y-OriginTop;i<8;i++,j++)
PtnBits[i]=(pattern<<(j&0x7))&0x80;
}
else
{ for(i=0,j=y-OriginTop;i<8;i++,j++)
PtnBits[i]=(pattern>>(j&0x7))&0x01;
}
GetPixelPosition( &PixelPos, &BitOffset, (TWndCanvas *)dc, x, y );
#if(BITS_PER_PIXEL==PIXEL_UNIT) /* 8 16 32 */
{ for(i=0;i<height;i++)
{ if(PtnBits[i&0x7])
{ SET_PIXEL_LOGIC(PixelPos,*PixelPos,ForeColorIndex,dwRop);
}
PixelPos=GetNextLinePos(PixelPos, vram );
}
}
#elif(BITS_PER_PIXEL==24)
{ BYTE ForeColorByte1=(BYTE)ForeColorIndex;
BYTE ForeColorByte2=(BYTE)(ForeColorIndex>>8);
BYTE ForeColorByte3=(BYTE)(ForeColorIndex>>16);
for(i=0;i<height;i++)
{ if(PtnBits[i&0x7])
{ SET_3BYTE_LOGIC(PixelPos,ForeColorByte1,ForeColorByte2,ForeColorByte3,dwRop);
}
PixelPos=GetNextLinePos(PixelPos, vram );
}
}
#elif(BITS_PER_PIXEL<8)
{ PIXEL srcMask=(PIXEL) MASK_OFFSET_OPT(BITS_PER_PIXEL,BitOffset);
PIXEL srcValue,b_srcMask=~srcMask;
PIXEL_OFFSET_OPT(ForeColorIndex,BITS_PER_PIXEL,BitOffset);
ForeColorIndex=ForeColorIndex& srcMask;
if(dwRop==PL_REPLACE)
{ for(i=0;i<height;i++)
{ if(PtnBits[i&0x7])
{ *PixelPos=(*PixelPos & b_srcMask) | ForeColorIndex;
}
PixelPos=GetNextLinePos(PixelPos, vram );
}
}
else
{ for(i=0;i<height;i++)
{ if(PtnBits[i&0x7])
{ SET_PIXEL_LOGIC(&srcValue,*PixelPos,ForeColorIndex,dwRop);
*PixelPos=(*PixelPos & b_srcMask)|(srcValue & srcMask);
}
PixelPos=GetNextLinePos(PixelPos, vram );
}
}
}
#endif
CM_ExposeCanvas((TWndCanvas *)dc,x,y,1,height);
}
//---------------------------------------------------------------------------
void DrawFontMatrix(HDC dc,int xPos,int yPos,int width,int height,BYTE *ptnArray)
{ PIXEL ForeColorIndex,BackColorIndex,*PixelPos,*LineHeadPos;
int OriginPosX=xPos,OriginPosY=yPos;
int i,j,k,dwRop,BitOffset,LineByteOffset,LineHeadBitOffset,BytesPerLine,OpaqueMode;
BYTE pattern;
#if(BITS_PER_PIXEL==24)
BYTE ForeColorByte1,ForeColorByte2,ForeColorByte3;
BYTE BackColorByte1,BackColorByte2,BackColorByte3;
#endif
BytesPerLine=(width+7)>>3;
/*---overrange check------------------------------------*/
CHECK_CANVAS_RECT((TWndCanvas *)dc,xPos,yPos,width,height);
/*---variable initialize------------------------------------*/
dwRop=((TWndCanvas *)dc)->Mode & STYLEMASK_PENLOGIC;
OpaqueMode=((TWndCanvas *)dc)->Mode&FS_OPAQUE;
ForeColorIndex=((TWndCanvas *)dc)->Foreground;
BackColorIndex=((TWndCanvas *)dc)->Background;
#if(BITS_PER_PIXEL==24)
ForeColorByte1=(BYTE)ForeColorIndex;
ForeColorByte2=(BYTE)(ForeColorIndex>>8);
ForeColorByte3=(BYTE)(ForeColorIndex>>16);
if(OpaqueMode)
{ BackColorByte1=(BYTE)BackColorIndex;
BackColorByte2=(BYTE)(BackColorIndex>>8);
BackColorByte3=(BYTE)(BackColorIndex>>16);
}
#endif
if(yPos!=OriginPosY)
{ ptnArray+=(yPos-OriginPosY)*BytesPerLine;
}
if(xPos!=OriginPosX)
{ LineHeadBitOffset=xPos-OriginPosX;
if(LineHeadBitOffset>=8)
{ ptnArray+=(LineHeadBitOffset>>3);
LineHeadBitOffset&=0x7;
}
}
else
{ LineHeadBitOffset=0;
}
GetPixelPosition( &LineHeadPos, &BitOffset, (TWndCanvas *)dc, xPos,yPos);
for(j=0;j<height;j++)
{ PixelPos=LineHeadPos;
LineHeadPos=GetNextLinePos(LineHeadPos,((TWndCanvas *)dc)->Vram);
LineByteOffset=0;
k= LineHeadBitOffset;
pattern=*ptnArray;
#if(BITS_PER_PIXEL==PIXEL_UNIT) /* 8 16 32 */
{ for(i=0;i<width;i++)
{ if((pattern<<k)&0x80)
{ SET_PIXEL_LOGIC( PixelPos, *PixelPos, ForeColorIndex, dwRop );
}
else if(OpaqueMode)
{ SET_PIXEL_LOGIC( PixelPos, *PixelPos, BackColorIndex, dwRop );
}
PixelPos++;
if(k<7)k++;
else {k=0;pattern=ptnArray[++LineByteOffset];}
}
}
#elif(BITS_PER_PIXEL==24)
{ for(i=0;i<width;i++)
{ if((pattern<<k)&0x80)
{ SET_3BYTE_LOGIC( PixelPos,ForeColorByte1,ForeColorByte2,ForeColorByte3,dwRop);;
}
else if(OpaqueMode)
{ SET_3BYTE_LOGIC( PixelPos,BackColorByte1,BackColorByte2,BackColorByte3,dwRop);;
}
PixelPos=(PIXEL *)((BYTE *)PixelPos+3);
if(k<7)k++;
else {k=0;pattern=ptnArray[++LineByteOffset];}
}
}
#else
{ PIXEL srcMask,srcValue,PixelBitOffset=BitOffset;
for(i=0;i<width;i++)
{ if((pattern<<k)&0x80)
{ srcValue=OPT_OFFSET_PIXEL(ForeColorIndex,BITS_PER_PIXEL,PixelBitOffset);
srcMask=(PIXEL)MASK_OFFSET_OPT(BITS_PER_PIXEL,PixelBitOffset);
SET_PIXEL_LOGIC(&srcValue,*PixelPos,srcValue,dwRop);
*PixelPos=(*PixelPos & ~srcMask)|(srcValue & srcMask);
}
else if(OpaqueMode)
{ srcValue=OPT_OFFSET_PIXEL(BackColorIndex,BITS_PER_PIXEL,PixelBitOffset);
srcMask=(PIXEL)MASK_OFFSET_OPT(BITS_PER_PIXEL,PixelBitOffset);
SET_PIXEL_LOGIC(&srcValue,*PixelPos,srcValue,dwRop);
*PixelPos=(*PixelPos & ~srcMask)|(srcValue & srcMask);
}
GetNextPixelPosition( &PixelPos, &PixelBitOffset, PixelPos, PixelBitOffset );
if(k<7)k++;
else {k=0;pattern=ptnArray[++LineByteOffset];}
}
}
#endif
ptnArray+=BytesPerLine;
}
CM_ExposeCanvas((TWndCanvas *)dc,xPos,yPos,width,height);
}
//---------------------------------------------------------------------------
int GetTextSize(HDC dc,LPCSTR text,TSIZE *txtsize)
{ if(text && *text)
{ BYTE ch=*text;
int nPlainText,colspace,rowspace;
int textwidth=0,MaxWidth=0,textheight=SYS_FONT_HEIGHT;
if(dc){colspace=GetColSpace(dc);rowspace=GetRowSpace(dc);nPlainText=!(((TWndCanvas *)dc)->Mode & FS_PLAIN);}
else {colspace=rowspace=0;nPlainText=true;}
while (ch)
{ if(ch>0xa0)
{ if(*++text)
{ textwidth=textwidth+(SYS_FONT_WIDTH+SYS_FONT_WIDTH)+colspace;
}else break;
}
else
{ if((ch=='\r' || ch=='\n') && nPlainText)
{ if(textwidth>MaxWidth)
{ MaxWidth=textwidth;
}
textwidth=0;
textheight+=(SYS_FONT_HEIGHT+rowspace);
if(ch=='\r' && *(text+1)=='\n') text++;
}
else
{ textwidth=textwidth+SYS_FONT_WIDTH+colspace;
}
}
ch=*++text;
}
if(textwidth<MaxWidth) textwidth=MaxWidth;
if(txtsize)
{ txtsize->x=textwidth;
txtsize->y=textheight;
}
return textwidth;
}
else
{ if(txtsize)txtsize->x=txtsize->y=0;
return 0;
}
}
//---------------------------------------------------------------------------
BOOL TextOut(HDC dc, int xPos,int yPos,LPCSTR lptext)
{ BYTE ch,lowch;
int textwidth,colspace,rowspace,hzkoffset,PenPosX,PenPosY,MaxPosX,nPlainText;
if(!lptext || !*lptext) return false;
else ch=*lptext;
PenPosX=xPos;
PenPosY=yPos;
MaxPosX=0;
colspace=GetColSpace(dc);
rowspace=GetRowSpace(dc);
nPlainText=!(((TWndCanvas *)dc)->Mode & FS_PLAIN);
GroupOn(dc);
while (ch)
{ if(ch>0xa0)
{ lowch=*++lptext;
if(lowch)
{ hzkoffset = ((ch - 0xA1) * 94 + (lowch - 0xA1)) * SYS_FONT_HEIGHT * ((SYS_FONT_WIDTH+SYS_FONT_WIDTH+7)>>3);
DrawFontMatrix(dc,PenPosX,PenPosY,SYS_FONT_WIDTH+SYS_FONT_WIDTH,SYS_FONT_HEIGHT,(BYTE *)&SYS_FONT_CHINESE[hzkoffset]) ;
PenPosX=PenPosX+(SYS_FONT_WIDTH+SYS_FONT_WIDTH)+colspace;
}
else break;
}
else
{ if((ch=='\r' || ch=='\n') && nPlainText)
{ if(PenPosX>MaxPosX)
{ MaxPosX=PenPosX;
}
PenPosX=xPos;
PenPosY=PenPosY+SYS_FONT_HEIGHT+rowspace;
if(ch=='\r' && *(lptext+1)=='\n') lptext++;
}
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -