babyos―― 简易图形库(二)
);
set_pixel(center_x + y, center_y - x);
x++;
if (p < 0) p += 2*x + 1;
else
{
y--;
p += 2*x - 2*y + 1;
}
}
return TRUE;
}
BOOL draw_rectangle(s32 left, s32 top, u32 width, u32 height)
{
u8* p_vram1;
u8* p_vram2;
s32 right, bottom, x, y;
right = left + width;
bottom = top + height;
if (left < 0) left = 0;
if (top < 0) top = 0;
if ((u32)left >= screen_cx || (u32)top >= screen_cy)
return FALSE;
if (right < 0 || bottom < 0)
return FALSE;
if ((u32)right > screen_cx) right = screen_cx;
if ((u32)bottom > screen_cy) bottom = screen_cy;
p_vram1 = p_vram_base + top*screen_cx + left;
p_vram2 = p_vram_base + top*screen_cx + right;
for (y = top; y < bottom; y++)
{
*p_vram1 = current_color;
*p_vram2 = current_color;
p_vram1 += screen_cx;
p_vram2 += screen_cx;
}
p_vram1 = p_vram_base + top*screen_cx + left;
p_vram2 = p_vram_base + bottom*screen_cx + left;
for (x = left; x < right; x++)
{
*(p_vram1++) = current_color;
*(p_vram2++) = current_color;
}
return TRUE;
}
BOOL fill_rectangle(s32 left, s32 top, u32 width, u32 height)
{
u8* p_vram;
s32 right, bottom, x, y;
right = left + width;
bottom = top + height;
/* 超出边界,截取在屏幕中的部分 */
if (left < 0) left = 0;
if (top < 0) top = 0;
/* 完全在屏幕外 */
if ((u32)left >= screen_cx || (u32)top >= screen_cy)
return FALSE;
/* 完全在屏幕外 */
if (right < 0 || bottom < 0)
return FALSE;
/* 超出边界,截取在屏幕中的部分 */
if ((u32)right > screen_cx) right = screen_cx;
if ((u32)bottom > screen_cy) bottom = screen_cy;
p_vram = p_vram_base + top*screen_cx;
for (y = top; y < bottom; y++)
{
for (x = left; x < right; x++)
p_vram[x] = current_color;
p_vram += screen_cx;
}
return TRUE;
}
BOOL set_color(color8 color)
{
return set_color8(color);
}
2.绘制字符和汉字的函数放到font.c中
[cpp]
/*************************************************************************
> File: font.c
> Author: 孤舟钓客
> Mail: guzhoudiaoke@126.com
> Time: 2013年01月03日 星期四 16时40分52秒
************************************************************************/
#include
#include
#include
static u8* p_font_asc16_base = (u8*)(FONT_ASC_ADDR);
static u8* p_font_hzk16_base = (u8*)(FONT_HZK_ADDR);
static BOOL draw_asc16(char ch, s32 left, s32 top)
{
u8* p_asc;
s32 x, y;
p_asc = p_font_asc16_base + ch * FONT_ASC16_SIZE;
for (y = 0; y < FONT_ASC16_HEIGHT; y++)
{
u8 test_bit = 1 << 7;
for (x = 0; x < FONT_ASC16_WIDTH; x++)
{
if (*p_asc & test_bit)
set_pixel(left+x, top+y);
test_bit >>= 1;
}
p_asc++;
}
return TRUE;
}
static BOOL draw_hzk16(char ch[3], s32 left, s32 top)
{
u8 qu_no, wei_no;
u32 offset;
s32 y, x;
u8* p_hzk;
qu_no = (u8)ch[0] - 0xa0;
wei_no = (u8)ch[1] - 0xa0;
offset= (94*(qu_no-1) + (wei_no-1)) * FONT_HZK16_SIZE;
p_hzk = p_font_hzk16_base + offset;
for (y = 0; y < FONT_HZK16_HEIGHT; y++)
{
u8 test_bit = 1 << 7;
for (x = 0; x < FONT_HZK16_WIDTH; x++)