📄 displaydrv.c
字号:
if( ( pPos->y + h ) > disDrv->LogicScreenHigh ) /* check Y*/
{
pPos->x = 0;
pPos->y = 0;
}
}
/*------------------------------------------------------------------------*/
/*
Name: DisplayDrvCheckRect
Desc: -校验窗口
Params: -pRect[in/out]:窗口指针;disDrv[in]:显示属性
Returns: -
Caveats: -
*/
void DisplayDrvCheckRect( OSFRect *pRect, const DisplayDef * disDrv )
{
if( pRect != NULL && disDrv != NULL )
{
if( pRect->x < 0 )
{
pRect->x = 0;
}
if( pRect->y < 0 )
{
pRect->y = 9;
}
if( ( pRect->x + pRect->w ) > disDrv->LogicScreenWidth )
{
pRect->w = disDrv->LogicScreenWidth - pRect->x;
}
if( ( pRect->y + pRect->h ) > disDrv->LogicScreenHigh )
{
pRect->h = disDrv->LogicScreenHigh - pRect->y;
}
}
}
/*------------------------------------------------------------------------*/
/*
Name: DisplayDrvDrawString
Desc: -向逻辑屏描绘一字符串(中英文混合)
Params: -
Returns: -
Caveats: -
*/
void DisplayDrvDrawString( OSFPos* pPos, const char* str, UINT16 Color, OSFFont* pFont, const DisplayDef * disDrv )
{
#define TABLE_KEY 3
UINT16 qh, wh;
UINT32 offset;
UINT8* hzkSource = NULL;
while( ( str != NULL ) && ( *str != '\0' ) )
{
if( *str < 0xa1 ) /* 其它ACSII码 */
{
DisplayDrvCheckPos( pPos, ASCII_FONT_W , pFont->H, disDrv ); /* 检验光标位置 */
if( *str == '\n' ) /* 换行符 */
{
pPos->x = 0;
pPos->y += pFont->H;
}
else if( *str == '\t' ) /* 制表符 */
{
pPos->x += ASCII_FONT_W * TABLE_KEY;
}
else if( *str < 0x80 )
{
DisplayDrvDrawOneASCII( pPos, *str, Color, pFont, disDrv ); /* 检验光标位置 */
pPos->x += ASCII_FONT_W;
}
str++;
}
else
{
DisplayDrvCheckPos( pPos, pFont->W , pFont->H, disDrv ); /* 检验光标位置 */
qh = (*str) - 0xa0; //求区位码的区数
wh = (*( str + 1 )) - 0xa0; //求区位码位数
offset = ( 94 * ( qh - 1 ) + ( wh - 1 ) ) * HZ_MODE_SIZE; //求偏移地址
hzkSource = ( UINT8* )( HZK_BASE_ADD_ON_FLASH )+ offset;
DisplayDrvDrawOneChinese( pPos, hzkSource , Color, pFont, disDrv );
pPos->x += pFont->W;
str += 2;
}
DisplayDrvCheckPos( pPos, pFont->W , pFont->H, disDrv ); /* 检验光标位置 */
}
#undef TABLE_KEY
}
/*------------------------------------------------------------------------*/
/*
Name: DisplayDrvDrawString
Desc: -向逻辑屏描绘一汉字
Params: -
Returns: -
Caveats: -
*/
void DisplayDrvDrawOneChinese(OSFPos* pPos, UINT8* hzkSource, UINT16 fontColor , OSFFont* pFont ,const DisplayDef * disDrv )
{
UINT16 *lpAC = ( UINT16* )( disDrv->pLogicScreen ); // + Pos.y * disDrv->LogicScreenWidth + Pos.x );
UINT8* chfigure = hzkSource;
UINT16 i, j,k,Width;
UINT8 BIT_MASK;
lpAC += pPos->y * disDrv->LogicScreenWidth + pPos->x;
Width = ( pFont->W + 7 ) >> 3;
for( j = 0; j < pFont->H; j++ )
{
for( k = 0; k < Width; k++ ) /* 画一行 */
{
BIT_MASK = 0x80;
for( i = 0 ; i < 8 ; i++ )
{
if( ( *chfigure ) & BIT_MASK )
{
*lpAC = fontColor;
}
lpAC++;
BIT_MASK >>= 1;
}
chfigure++;
}
lpAC = lpAC - ( Width << 3 ) + disDrv->LogicScreenWidth; /*指向逻辑屏的下一行*/
}
}
/*------------------------------------------------------------------------*/
/*
Name: DisplayDrvDrawPixel
Desc: -向逻辑屏描绘一个点
Params: -
Returns: -
Caveats: -
*/
void DisplayDrvDrawPixel( OSFPos * pPos, UINT16 Color, DisplayDef * disDrv )
{
if( disDrv != NULL )
{
UINT16 *lpAC = ( UINT16* )( disDrv->pLogicScreen ) + pPos->y * ( disDrv->LogicScreenWidth ) + pPos->x;
*lpAC = Color;
}
}
/*------------------------------------------------------------------------*/
/*
Name: DisplayDrvDrawLine
Desc: -向逻辑屏描绘任一直线
Params: -
Returns: -
Caveats: -
*/
void DisplayDrvDrawLine( OSFPos *pStartPos, OSFPos *pEndPos, UINT16 Color, DisplayDef * disDrv )
{
#define STEP_TYPE float
if( pStartPos!= NULL && pEndPos != NULL && disDrv != NULL )
{
if( pStartPos->y == pEndPos->y ) /* 水平直线 */
{
DisplayDrvDrawHorizontalLine( pStartPos->x,
pEndPos->x,
pStartPos->y,
Color,
disDrv );
}
else if( pStartPos->x == pEndPos->x ) /* 垂直直线*/
{
DisplayDrvDrawVerticalLine( pStartPos->y,
pEndPos->y,
pStartPos->x,
Color,
disDrv );
}
else /* 斜线 */
{
STEP_TYPE width, height;
STEP_TYPE step, fSum;
OSFPos tempPos = { 0, 0 };
width = ( pEndPos->x >= pStartPos->x ) ? ( STEP_TYPE )( pEndPos->x - pStartPos->x ) : ( STEP_TYPE )( pStartPos->x - pEndPos->x );
height = ( pEndPos->y >= pStartPos->y ) ? ( STEP_TYPE )( pEndPos->y - pStartPos->y ) : ( STEP_TYPE )( pStartPos->y - pEndPos->y );
if( width >= height )
{ /* 直线将以X方向为准 */
if( pEndPos->x < pStartPos->x ) /* make sure Xend >= Xstart */
{
OSFPos* ptempPos = pStartPos;
pStartPos = pEndPos;
pEndPos = ptempPos;
}
}
else
{ /* 直线将以Y方向为准 */
if( pEndPos->y < pStartPos->y ) /* make sure Yend >= Ystart */
{
OSFPos* ptempPos = pStartPos;
pStartPos = pEndPos;
pEndPos = ptempPos;
}
}
if( width >= height )
{ /* X方向逐点画线 */
step = ( pEndPos->y - pStartPos->y ) / width;
for( tempPos.x = pStartPos->x, tempPos.y = pStartPos->y , fSum = pStartPos->y ; tempPos.x <= pEndPos->x; tempPos.x++ )
{
tempPos.y = ( UINT16 )fSum;
DisplayDrvDrawPixel( &tempPos, Color, disDrv );
fSum += step;
}
}
else /* Y方向逐点画线 */
{
step = ( pEndPos->x - pStartPos->x ) / height;
for( tempPos.x = pStartPos->x, tempPos.y = pStartPos->y, fSum = pStartPos->x ; tempPos.y <= pEndPos->y; tempPos.y++ )
{
tempPos.x = ( UINT16 )fSum;
DisplayDrvDrawPixel( &tempPos, Color, disDrv );
fSum += step;
}
}
}
}
#undef STEP_TYPE
}
/*------------------------------------------------------------------------*/
/*
Name: DisplayDrvDrawHorizontalLine
Desc: -向逻辑屏描绘一条水平方向的直线
Params: -
Returns: -
Caveats: -
*/
void DisplayDrvDrawHorizontalLine( UINT16 sx, UINT16 ex, UINT16 y, UINT16 Color, DisplayDef * disDrv )
{
if( disDrv != NULL )
{
UINT16 PixelCounter = 0;
UINT16 *lpAC = NULL;
if( sx > ex )
{
UINT16 temp = sx;
sx = ex;
ex = temp;
}
if( sx > ( disDrv->LogicScreenWidth - 1 ) ) return;
if( ex > ( disDrv->LogicScreenWidth - 1 ) )
{
ex = disDrv->LogicScreenWidth - 1;
}
PixelCounter = ex - sx + 1;
lpAC = ( UINT16* )disDrv->pLogicScreen + y * disDrv->LogicScreenWidth
+ sx ;
while( PixelCounter-- )
{
*lpAC++ = Color;
}
}
}
/*------------------------------------------------------------------------*/
/*
Name: DisplayDrvDrawVerticalLine
Desc: -向逻辑屏描绘一条垂直方向的直线
Params: -
Returns: -
Caveats: -
*/
void DisplayDrvDrawVerticalLine( UINT16 sy, UINT16 ey, UINT16 x, UINT16 Color, DisplayDef * disDrv )
{
if( disDrv != NULL )
{
UINT16 PixelCounter = 0;
UINT16 *lpAC = NULL;
if( sy > ey )
{
UINT16 temp = sy;
sy = ey;
ey = temp;
}
if( sy > ( disDrv->LogicScreenHigh - 1 ) ) return;
if( ey > ( disDrv->LogicScreenHigh - 1 ) )
{
ey = disDrv->LogicScreenWidth - 1;
}
PixelCounter = ey - sy + 1;
lpAC = ( UINT16* )disDrv->pLogicScreen + sy * disDrv->LogicScreenWidth
+ x ;
while( PixelCounter-- )
{
*lpAC = Color;
lpAC += disDrv->LogicScreenWidth;
}
}
}
/*------------------------------------------------------------------------*/
/*
Name: DisplayDrvDrawCircle
Desc: -画圆函数
Params: -pPoint[in]:圆心,r[in]:半径,frameColor[in]:圆框颜色,fillColor[in]:填充色,disDrv[in]:显示属性
Returns: -
Caveats: -
*/
void DisplayDrvDrawCircle( OSFPos *pCenter, UINT16 r , UINT32 frameColor , UINT32 fillColor, DisplayDef * DispDrv )
{
if( ( pCenter != NULL || DispDrv != NULL )
&& ( pCenter->x >= r || pCenter->y >= r )
&& ( pCenter->x + r <= DispDrv->LogicScreenWidth )
&& ( pCenter->y + r <= DispDrv->LogicScreenHigh ) )
{
OSFPos currentPt;
UINT32 xsq,
ysq,
rsq,
dxsq,
dysq;
/* 画圆 */
if ( r > 0 )
{
/* Initialize the DDA */
currentPt.x = ( INT16 ) r;
xsq = r * r;
dxsq = 2 * r - 1;
currentPt.y = 0;
ysq = 0;
dysq = 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -