📄 displaydrv.c
字号:
rsq = xsq + r;
/* Draw the circle */
while ( xsq >= ysq )
{
DisplayDrvPlot8( currentPt, pCenter , frameColor , fillColor ,DispDrv );
currentPt.y++;
ysq += dysq;
dysq += 2;
if ( xsq + ysq > rsq )
{
currentPt.x--;
xsq -= dxsq;
dxsq -= 2;
}
}
}
else /* 产径为零时为一个点 */
{
DisplayDrvDrawPixel( pCenter, frameColor, DispDrv );
}
}
}
static void DisplayDrvPlot8( OSFPos current, OSFPos *pCenter , UINT32 frameColor , UINT32 fillColor, DisplayDef * DispDrv )
{
OSFPos pos;
static UINT16 LastY = 0xffff;
UINT16 fColor = frameColor & 0xffff;
pos.x = pCenter->x + current.x;
pos.y = pCenter->y + current.y;
if( LastY != current.y )
{
UINT16 bColor = fillColor & 0xffff;
LastY = current.y;
DisplayDrvDrawHorizontalLine( pCenter->x - current.x, pos.x, pos.y, bColor, DispDrv );
DisplayDrvDrawHorizontalLine( pCenter->x - current.x, pos.x, pCenter->y - current.y,bColor, DispDrv );
if ( current.x > current.y )
{
/* 高超的算法!!! */
DisplayDrvDrawHorizontalLine( pCenter->x - current.y,pCenter->x + current.y, pCenter->y + current.x - 1,bColor, DispDrv );
DisplayDrvDrawHorizontalLine( pCenter->x - current.y,pCenter->x + current.y, pCenter->y - current.x + 1,bColor, DispDrv );
}
}
DisplayDrvDrawPixel( &pos, fColor, DispDrv );
/* leave pos.y as is for this point */
pos.x = pCenter->x - current.x;
DisplayDrvDrawPixel( &pos, fColor, DispDrv );
if ( current.y > 0 )
{
pos.x = pCenter->x + current.x;
pos.y = pCenter->y - current.y;
DisplayDrvDrawPixel( &pos, fColor, DispDrv );
/* leave pos.y as is for this point */
pos.x = pCenter->x - current.x;
DisplayDrvDrawPixel( &pos, fColor, DispDrv );
}
if ( current.x > current.y )
{
pos.x = pCenter->x + current.y;
pos.y = pCenter->y + current.x;
DisplayDrvDrawPixel( &pos, fColor, DispDrv );
/* leave pos.x as is for this point */
pos.y = pCenter->y - current.x;
DisplayDrvDrawPixel( &pos, fColor, DispDrv );
}
if ( current.y > 0 && current.x > current.y )
{
pos.x = pCenter->x - current.y;
pos.y = pCenter->y + current.x;
DisplayDrvDrawPixel( &pos, fColor, DispDrv );
/* leave pos.x as is for this point */
pos.y = pCenter->y - current.x;
DisplayDrvDrawPixel( &pos, fColor, DispDrv );
}
}
/*------------------------------------------------------------------------*/
/*
Name: DisplayDrvDrawEllipse
Desc: -向逻辑屏描绘任一椭圆(只能画圆)
Params: -rect:与圆内切的矩形窗口;frameColor:边框色;fillColor:填充色;DispDrv:显示属性
Returns: -
Caveats: -
*/
void DisplayDrvDrawEllipse( UHRECT * rect, UINT32 frameColor , UINT32 fillColor, DisplayDef * DispDrv )
{
OSFPos centerPt,
currentPt;
UINT16 r;
UINT32 xsq,
ysq,
rsq,
dxsq,
dysq;
DisplayDrvCheckRect( rect, DispDrv ); /* 校验窗口区域 */
/* 求圆心坐标 */
centerPt.x = rect->x + ( rect->w >> 1 );
centerPt.y = rect->y + ( rect->h >> 1 );
/* 求长半径 */
r = ( ( rect->w >> 1 ) < ( rect->h >> 1 ) ) ? ( rect->w >> 1 ) : ( rect->h >> 1 ); /* MIN( w/2, h/2 ) */
/* 画圆 */
if ( r > 0 )
{
/* Initialize the DDA */
currentPt.x = ( INT16 ) r;
xsq = r * r;
dxsq = 2 * r - 1;
currentPt.y = 0;
ysq = 0;
dysq = 1;
rsq = xsq + r;
/* Draw the circle */
while ( xsq >= ysq )
{
DisplayDrvPlot8( currentPt, ¢erPt , frameColor , fillColor ,DispDrv );
currentPt.y++;
ysq += dysq;
dysq += 2;
if ( xsq + ysq > rsq )
{
currentPt.x--;
xsq -= dxsq;
dxsq -= 2;
}
}
}
else /* 产径为零时为一个点 */
{
DisplayDrvDrawPixel( ¢erPt, frameColor, DispDrv );
}
}
/*------------------------------------------------------------------------*/
/*
Name: DisplayDrvDrawBitmap
Desc: -向逻辑屏描绘一位图
Params: -pPos:起始坐标; pBitmap:位图指针;DispDrv:显示属性
Returns: -
Caveats: -
*/
void DisplayDrvDrawBitmap( OSFPos* pPos, OSFBitmap* pBitmap , DisplayDef * DispDrv )
{
if( DispDrv != NULL && pPos != NULL )
{
UINT16 *lpAC = NULL;
UINT16 *lpSrc = NULL;
UINT16 width = pBitmap->w;
UINT16 height = pBitmap->h;
UINT16 i,j;
if( ( pPos->x + width ) >= DispDrv->LogicScreenWidth ) /* 截掉过宽的图片 */
{
width = DispDrv->LogicScreenWidth - pPos->x;
}
if( ( pPos->y + height ) >= DispDrv->LogicScreenHigh ) /* 截掉过高的图片 */
{
height = DispDrv->LogicScreenHigh - pPos->y;
}
for( j = 0; j < height; j++ )
{
lpAC = ( UINT16* )( DispDrv->pLogicScreen ) + ( j + pPos->y ) * DispDrv->LogicScreenWidth
+ pPos->x; /* 计算逻辑屏上当前行的首地址 */
lpSrc = ( UINT16 * )pBitmap->pixels + pBitmap->w * j; /* 计算位图当前行的首地址 */
for( i = 0; i < width; i++ )/* 复制本行 */
{
*lpAC++ = *lpSrc++;
}
}
}
}
/*------------------------------------------------------------------------*/
/*
Name: DisplayDrvDrawRect
Desc: -向逻辑屏描绘一矩形窗口
Params: -pRect[in]:矩形窗口指针;frameColor[in]:边框色;frameWidth:边框宽度
fillColor[in]:填充色;DispDrv[in]:显示属性
Returns: -
Caveats: -
*/
void DisplayDrvDrawRect( OSFRect* pRect, UINT32 frameColor , UINT16 frameWidth, UINT32 fillColor, DisplayDef * DispDrv )
{
if( pRect != NULL && DispDrv != NULL )
{
OSFPos Pos1,Pos2;
OSFRect TempRect, *pTempRect = &TempRect;
pTempRect->x = pRect->x;pTempRect->y = pRect->y; pTempRect->w = pRect->w; pTempRect->h = pRect->h;
DisplayDrvCheckRect( &TempRect, DispDrv );
if( fillColor <= 0xffff ) /* 画背色 */
{
UINT16 i,j;
UINT16 *lpAC = NULL;
UINT16 bColor = fillColor & 0xffff;
for( j = 0; j < pTempRect->h; j++ )
{
lpAC = ( UINT16 * )DispDrv->pLogicScreen + ( j + pTempRect->y ) * DispDrv->LogicScreenWidth
+ pTempRect->x;
for( i = 0; i < pTempRect->w; i++ )
{
*lpAC++ = bColor;
}
}
}
if( ( frameColor <= 0xffff ) && ( frameWidth > 0 ) ) /* 画边框 */
{
UINT16 fColor = frameColor & 0xffff;
UINT16 minLen = ( pTempRect->w > pTempRect->h ) ? pTempRect->h : pTempRect->w;
if( frameWidth > ( minLen >> 1 ) )
{
frameWidth = minLen >> 1;
}
while( frameWidth-- )
{
Pos1.x = pTempRect->x;
Pos1.y = pTempRect->y;
Pos2.x = Pos1.x + pTempRect->w - 1;
Pos2.y = Pos1.y;
DisplayDrvDrawLine( &Pos1, &Pos2, fColor, DispDrv ); /* 从左上角到右上角 */
Pos1.x = Pos2.x;
Pos1.y = Pos2.y + pTempRect->h - 1;
DisplayDrvDrawLine( &Pos2, &Pos1, fColor, DispDrv ); /* 从右上角到右下角 */
Pos2.y = Pos1.y;
Pos2.x = pTempRect->x;
DisplayDrvDrawLine( &Pos2, &Pos1, fColor, DispDrv ); /* 从左下角到右下角 */
Pos1.x = pTempRect->x;
Pos1.y = pTempRect->y;
DisplayDrvDrawLine( &Pos1, &Pos2, fColor, DispDrv ); /* 从左上角到左下角 */
pTempRect->x++;
pTempRect->y++;
pTempRect->w -= 2;
pTempRect->h -= 2;
}
}
}
}
/*------------------------------------------------------------------------*/
/*
Name: prints
Desc: -格式化输出到Screen上
Params: - x:X坐标; y:Y坐标,color: 字体颜色, fmt...参数表
Returns: -
Caveats: -
*/
void PrintScreen ( INT16 x, INT16 y , UINT16 color, char *fmt,... )
{
OSFFont font = { 16,16 };
OSFPos pos = { 0, 0 };
DisplayDef *pDisDrv = DisplayDrvGetDrv( );
va_list ap;
static char string[ 256 ];
va_start(ap,fmt);
vsprintf(string,fmt,ap); /* 格式化输出到string缓冲区内 */
va_end(ap);
pos.x = x;
pos.y = y;
DisplayDrvDrawString( &pos,string, color , &font, pDisDrv ); /* 将缓冲区的字符串描到逻辑屏上 */
//writeStrUart( 0, string );
}
/*------------------------------------------------------------------------*/
/*
Name: DisplayDrvDrawBK
Desc: -画逻辑屏的背景
Params: - color:背景色
Returns: -
Caveats: -
*/
void DisplayDrvDrawBK( UINT16 Color )
{
DisplayDef *pDisDrv = DisplayDrvGetDrv( );
{
UINT32 i = pDisDrv->LogicScreenWidth * pDisDrv->LogicScreenHigh;
UINT16 *pSource = ( UINT16* )pDisDrv->pLogicScreen;
while( i-- )
{
*pSource++ = Color;
}
}
}
/* 24 * 24 字体的测试程序*/
void TestDrawCh( void )
{
const UINT8 ch[ ] = {
/*-- 文字: 谢 --*/
/*-- 宋体18; 此字体下对应的点阵为:宽x高=24x24 --*/
0x00,0x00,0x00,0x00,0x10,0x00,0x10,0x10,0x18,0x08,0x10,0x10,0x0C,0xA4,0x10,0x04,
0xDE,0x10,0x00,0xC4,0x10,0x00,0xC4,0x14,0x08,0xFC,0xF8,0x78,0xC4,0x10,0x08,0xC4,
0x10,0x08,0xFD,0x10,0x08,0xC4,0x90,0x08,0xC4,0xD0,0x0B,0xFC,0x50,0x08,0x1C,0x10,
0x09,0x14,0x10,0x0A,0x34,0x10,0x0C,0x64,0x10,0x1C,0xC4,0x10,0x09,0x04,0x10,0x02,
0x3C,0x90,0x00,0x04,0x70,0x00,0x00,0x00,
};
DisplayDef *pDisDrv = DisplayDrvGetDrv( );
OSFPos pos = { 0, 0 };
OSFFont font = { 24,24 };
DisplayDrvDrawOneChinese( &pos, ( UINT8* )ch, COLOR_BLACK, &font,pDisDrv );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -