📄 draw.c
字号:
}
/*******************************************************************************
*
* DRAW_GetBGndColor
*
*******************************************************************************/
/**
*
* Return current background color.
*
* @return The current RGB color used for the background.
*
**/
/******************************************************************************/
u16 DRAW_GetBGndColor( void )
{
return BGndColor;
}
/*******************************************************************************
*
* DRAW_SetBGndColor
*
*******************************************************************************/
/**
*
* Set current background color
*
* @param[in] Color The new RGB color for background.
*
**/
/******************************************************************************/
void DRAW_SetBGndColor(u16 Color)
{
BGndColor = Color;
}
/*******************************************************************************
*
* DRAW_SetImage
*
*******************************************************************************/
/**
*
* The provided bitmap is made width * height 2 byte words. Each 2 byte word contains
* the RGB color of a pixel.
*
* @brief Draw a color bitmap at the provided coordinates.
* @param[in] imageptr A pointer to an array of width * height 2 byte words.
* @param[in] x The horizontal coordinate of the low left corner of the bitmap.
* @param[in] y The vertical coordinate of the low left corner of the bitmap.
* @param[in] width The bitmap width.
* @param[in] height The bitmap height.
*
* @warning The (0x0) point in on the low left corner.
*
**/
/******************************************************************************/
void DRAW_SetImage( const u16* imageptr, u8 x, u8 y, u8 width, u8 height )
{
int i;
// Select screen area to access.
LCD_SetRect_For_Cmd( x, y, width, height );
// Send command to write data on the LCD screen.
LCD_SendLCDCmd(ST7637_RAMWR);
for( i = 0; i < ( width * height ); i++ )
{
LCD_SendLCDData( imageptr[ i ] & 0xff );
LCD_SendLCDData( ( imageptr[ i ] >> 8 ) & 0xff );
}
}
/*******************************************************************************
*
* DRAW_DisplayString
*
*******************************************************************************/
/**
*
* This function is used to display a 17 character max string of
* characters on the LCD display at the provided coordinates.
*
* @param[in] x The horizontal coordinate of the displayed string.
* @param[in] y The vertical coordinate of the display string.
* @param[in] *ptr Pointer to the string to display on LCD.
* @param[in] len String length.
*
* @warning The (0x0) point in on the low left corner.
*
**/
/******************************************************************************/
void DRAW_DisplayString( u8 x, u8 y, const u8* ptr, u8 len )
{
DRAW_DisplayStringWithMode( x, y, ptr, len, 0 );
}
/*******************************************************************************
*
* DRAW_DisplayStringInverted
*
*******************************************************************************/
/**
*
* This function is used to display a 17 character max string of
* characters on the LCD display at the provided coordinates with inverted colors.
*
* @param[in] x The horizontal coordinate of the displayed string.
* @param[in] y The vertical coordinate of the display string.
* @param[in] *ptr Pointer to the string to display on LCD.
* @param[in] len String length.
*
* @warning The (0x0) point in on the low left corner.
*
**/
/******************************************************************************/
void DRAW_DisplayStringInverted( u8 x, u8 y, const u8* ptr, u8 len )
{
//BackGround and Text Colors are inverted
DRAW_DisplayStringWithMode( x, y, ptr, len, 1 );
}
/*******************************************************************************
*
* DRAW_SetDefaultColor
*
*******************************************************************************/
/**
*
* Reset text and background colors to their default values.
*
**/
/******************************************************************************/
void DRAW_SetDefaultColor (void)
{
BGndColor = RGB_WHITE;
TextColor = RGB_BLACK;
}
/*******************************************************************************
*
* DRAW_DisplayTemp
*
*******************************************************************************/
/**
*
* This function is used to display the current temperature in ascii.
* The choice between Celcius and Fahrenheit is fixed by UTIL_SetModeTemp()
*
* @param[in] x The horizontal coordinate of the displayed string.
* @param[in] y The vertical coordinate of the display string.
*
* @warning The (0x0) point in on the low left corner.
*
**/
/******************************************************************************/
void DRAW_DisplayTemp( u8 x, u8 y )
{
u32 Temp = 0;
u8 TextBuffer[5] = { 0,0,0,0,0};
// Get Time
Temp = UTIL_GetTemp() ;
if( Temp != OldTemp )
{
// Display C (if modified).
UTIL_uint2str( TextBuffer, Temp/10, 2, 1 );
TextBuffer[ 2 ] = '.';
DRAW_DisplayString( x + ( 0 * CharMagniCoeff * 7 ), y, TextBuffer, 3 );
// Display C/10 (if modified).
UTIL_uint2str( TextBuffer, Temp%10, 1, 1 );
TextBuffer[ 1 ] = fTemperatureInFahrenheit ? 'F' : 'C'; TextBuffer[ 2 ] = 0;
DRAW_DisplayString( x + ( 3 * CharMagniCoeff * 7 ), y, TextBuffer, 2 );
}
OldTemp = Temp;
}
/*******************************************************************************
*
* DRAW_Line
*
*******************************************************************************/
/**
* Draw a line on the LCD screen. Optimized for horizontal/vertical lines,
* and use the Bresenham algorithm for other cases.
*
* @param[in] x1 The x-coordinate of the first line endpoint.
* @param[in] x2 The x-coordinate of the second line endpoint.
* @param[in] y1 The y-coordinate of the first line endpoint.
* @param[in] y2 The y-coordinate of the second line endpoint.
* @param[in] color The line color.
*
**/
void DRAW_Line (s16 x1, s16 y1, s16 x2, s16 y2, u16 color )
{
int i,dx,dy,sdx,sdy,dxabs,dyabs,x,y,px,py;
#define abs(X) ( ( (X) < 0 ) ? -(X) : (X) )
#define sgn(X) ( ( (X) < 0 ) ? -1 : 1 )
if ( x1==x2 ) //Vertical Line
{
if ( y1 > y2 ) //We assume y2>y1 and invert if not
{
i = y2;
y2 = y1;
y1 = i;
}
LCD_FillRect( x1, y1, 1, y2-y1+1, color );
return;
}
else if ( y1==y2 ) //Horizontal Line
{
if ( x1 > x2 ) //We assume x2>x1 and we swap them if not
{
i = x2;
x2 = x1;
x1 = i;
}
LCD_FillRect( x1, y1, x2-x1+1, 1, color );
return;
}
dx=x2-x1; /* the horizontal distance of the line */
dy=y2-y1; /* the vertical distance of the line */
dxabs=abs(dx);
dyabs=abs(dy);
sdx=sgn(dx);
sdy=sgn(dy);
x=dyabs>>1;
y=dxabs>>1;
px=x1;
py=y1;
if (dxabs>=dyabs) /* the line is more horizontal than vertical */
{
for(i=0;i<dxabs;i++)
{
y+=dyabs;
if (y>=dxabs)
{
y-=dxabs;
py+=sdy;
}
px+=sdx;
LCD_DrawPixel(px,py,color);
}
}
else /* the line is more vertical than horizontal */
{
for(i=0;i<dyabs;i++)
{
x+=dxabs;
if (x>=dyabs)
{
x-=dyabs;
px+=sdx;
}
py+=sdy;
LCD_DrawPixel(px,py,color);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -