單片機(jī)C語(yǔ)言實(shí)例-205-彩屏圖片顯示
/*
================================================================================
File Name : GUI_Basic.c
Author : LiYOng
Date : 2008-12-12 15:51
Version : 1.0
Decription: This file contains some basic functions for GUI, It need the LCD
Drive functions
================================================================================
*/
#include "GUI_Basic.H"
#include "GUI_Type.H"
#include "fontlib.h"
/*
================================================================================
Function : GUI_DrawRectangle( )
Description : Draw a rectangle
Input : -pRect, point to a rectangle structure
output : None
================================================================================
*/
void GUI_DrawRectangle( RECT* pRect )
{
LINE line;
line.xs = pRect->xs;
line.xe = pRect->xe;
line.ys = pRect->ys;
line.ye = pRect->ys;
line.Color = pRect->Color;
LCDDrawHRLine( &line );
line.xe = pRect->xs;
line.ye = pRect->ye;
LCDDrawHRLine( &line );
line.xs = pRect->xe;
line.ys = pRect->ye;
LCDDrawHRLine( &line );
line.xe = pRect->xe;
line.ye = pRect->ys;
LCDDrawHRLine( &line );
}
/*
================================================================================
Function : GUI_DrawLine( )
Description : Draw a line
Input : -pLine, point to a line structure
output : None
================================================================================
*/
void GUI_DrawLine( LINE* pLine )
{
INT32S dx; // 直線(xiàn)x軸差值變量
INT32S dy; // 直線(xiàn)y軸差值變量
INT32S dx_sym; // x軸增長(zhǎng)方向,為-1時(shí)減值方向,為1時(shí)增值方向
INT32S dy_sym; // y軸增長(zhǎng)方向,為-1時(shí)減值方向,為1時(shí)增值方向
INT32S dx_x2; // dx*2值變量,用于加快運(yùn)算速度
INT32S dy_x2; // dy*2值變量,用于加快運(yùn)算速度
INT32S di; // 決策變量
POINT point;
LINE line;
line.xs = pLine->xs;
line.ys = pLine->ys;
line.xe = pLine->xe;
line.ye = pLine->ye;
line.Color = pLine->Color;
point.Color = pLine->Color;
dx = line.xe - line.xs;
dy = line.ye - line.ys;
/* 判斷增長(zhǎng)方向,或是否為水平線(xiàn)、垂直線(xiàn)、點(diǎn) */
if( dx > 0 ) // 判斷x軸方向
{
dx_sym = 1; // dx>0,設(shè)置dx_sym=1
}
else
{
if( dx < 0 )
{
dx_sym = -1; // dx<0,設(shè)置dx_sym=-1
}
else
{
LCDDrawHRLine( &line );
return;
}
}
if( dy > 0 ) // 判斷y軸方向
{
dy_sym = 1; // dy>0,設(shè)置dy_sym=1
}
else
{
if( dy < 0 )
{
dy_sym = -1; // dy<0,設(shè)置dy_sym=-1
}
else
{ // dy==0,畫(huà)水平線(xiàn),或一點(diǎn)
LCDDrawHRLine( &line );
return;
}
}
/* 將dx、dy取絕對(duì)值 */
dx = dx_sym * dx;
dy = dy_sym * dy;
/* 計(jì)算2倍的dx及dy值 */
dx_x2 = dx*2;
dy_x2 = dy*2;
/* 使用Bresenham法進(jìn)行畫(huà)直線(xiàn) */
if( dx >= dy ) // 對(duì)于dx>=dy,則使用x軸為基準(zhǔn)
{
di = dy_x2 - dx;
while( line.xs != line.xe )
{
point.x = line.xs;
point.y = line.ys;
LCDDrawPoint( &point );
line.xs += dx_sym;
if( di < 0 )
{
di += dy_x2; // 計(jì)算出下一步的決策值
}
else
{
di += dy_x2 - dx_x2;
line.ys += dy_sym;
}
}
LCDDrawPoint( &point ); // 顯示最后一點(diǎn)
}
else // 對(duì)于dx<dy,則使用y軸為基準(zhǔn)
{
di = dx_x2 - dy;
while( line.ys != line.ye )
{
point.x = line.xs;
point.y = line.ys;
LCDDrawPoint( &point );
line.ys += dy_sym;
if(di<0)
{
di += dx_x2;
}
else
{
di += dx_x2 - dy_x2;
line.xs += dx_sym;
}
}
LCDDrawPoint( &point ); // 顯示最后一點(diǎn)
}
}
/*
更多詳情參考附件文檔
+08:00C299聯(lián)盟網(wǎng)3842.png (63.58 KB, 下載次數(shù): 3)
下載附件
保存到相冊(cè)
2022-2-23 14:10 上傳
游客,如果您要查看本帖隱藏內(nèi)容請(qǐng) 回復(fù)
|