📄 gdi.c
字号:
/* MShowTec - www.mshowtec.com
** msGUI gdi.c ver1.0
** 20051221 lmjx create limiao@mshowtec.com
**
*/
#define MSGUI_GDI_C
#include "lcdcfg.h"
#include "gdi.h"
#include "dev.h"
extern unsigned char HZK12[];
extern unsigned char ASCII12[];
unsigned short virtual_screen[LCDHEIGHT][LCDWIDTH];
void gdi_update_rscreen()
{
unsigned short para[4] = {0,0,LCDWIDTH,LCDHEIGHT};
ioctrl(DEV_LCD,IOCTRL_LCD_DRAW,(long)¶);
}
__inline void gdi_set_pixel(unsigned short x,unsigned short y,unsigned short c)
{
virtual_screen[y][x] = c;
}
__inline unsigned short gdi_get_pixel(unsigned short x,unsigned short y)
{
return virtual_screen[y][x];
}
void gdi_draw_h_line(POINT point,unsigned short len,unsigned short c)
{
int i;
unsigned short endX;
if(len == 0)
return;
if(point.x >= LCDWIDTH)
return;
if(point.y >= LCDHEIGHT)
return;
endX = point.x+len-1;
if(endX >= LCDWIDTH)
endX = LCDWIDTH-1;
for(i = point.x;i <= endX;i++){
gdi_set_pixel(i,point.y,c);
}
}
void gdi_draw_v_line(POINT point,unsigned short len,unsigned short c)
{
int i;
unsigned short endY;
if(len == 0)
return;
if(point.x >= LCDWIDTH)
return;
if(point.y >= LCDHEIGHT)
return;
endY = point.y+len-1;
if(endY >= LCDHEIGHT)
endY = LCDHEIGHT-1;
for(i = point.y;i <= endY;i++){
gdi_set_pixel(point.x,i,c);
}
}
void gdi_draw_line(POINT sp,POINT ep,unsigned short c)
{
}
void gdi_draw_rect(RECT rect,unsigned c)
{
POINT spoint,epoint,tpoint;
spoint.x = rect.startX;
spoint.y = rect.startY;
if((spoint.x >= LCDWIDTH)||(spoint.y >= LCDHEIGHT))
return;
if((rect.width == 0)||(rect.height == 0))
return;
epoint.x = spoint.x+rect.width-1;
epoint.y = spoint.y+rect.height-1;
if(epoint.x >= LCDWIDTH)
epoint.x = LCDWIDTH-1;
if(epoint.y >= LCDHEIGHT)
epoint.y = LCDHEIGHT-1;
gdi_draw_h_line(spoint,rect.width,c);
gdi_draw_v_line(spoint,rect.height,c);
tpoint.x = spoint.x;
tpoint.y = epoint.y;
gdi_draw_h_line(tpoint,rect.width,c);
tpoint.x = epoint.x;
tpoint.y = spoint.y;
gdi_draw_v_line(tpoint,rect.height,c);
}
void gdi_draw_picture(RECT rect,unsigned short* ppic)
{
int i,j;
unsigned short width,height;
unsigned short picopt;
unsigned short transc;
unsigned short *ppicd,c;
width = ppic[0];
height = ppic[1];
picopt = ppic[2];
transc = ppic[3];
ppicd = &(ppic[4]);
if((rect.startX >= LCDWIDTH)||(rect.startY >= LCDHEIGHT))
return;
if((rect.width == 0)||(rect.height == 0))
return;
if((rect.startX+rect.width) > LCDWIDTH)
rect.width = LCDWIDTH-rect.startX;
if((rect.startY+rect.height) > LCDHEIGHT)
rect.height = LCDWIDTH-rect.startY;
if(rect.width > width)
rect.width = width;
if(rect.height > height)
rect.height = height;
if(picopt & 0x0001){
for(j = 0;j < rect.height;j++){
for(i = 0;i < rect.width;i++){
c = ppicd[j*width+i];
if(c == transc)
continue;
gdi_set_pixel(i+rect.startX,j+rect.startY,c);
}
}
}else{
for(j = 0;j < rect.height;j++){
for(i = 0;i < rect.width;i++){
gdi_set_pixel(i+rect.startX,j+rect.startY,ppicd[j*width+i]);
}
}
}
}
void test_pic()
{
RECT rect;
rect.startX = 10;
rect.startY = 10;
rect.width = 96;
rect.height = 96;
//gdi_draw_rect(rect,0xffff);
//gdi_draw_picture(rect,(unsigned short*)gpic_0);
gdi_update_rscreen();
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//String function here
//only support font12*12
void gdi_draw_hz(POINT point,unsigned char* str,unsigned short c)
{
unsigned short i,j,k;
unsigned short x,y;
for(i=0;i<12;i++)
{
for(j=0;j<2;j++)
{
for(k=0;k<8;k++)
{
if(((str[i*2+j]>>(7-k))&0x1)!=0)
{
x = point.x+8*j+k;
y = point.y+i;
gdi_set_pixel(x,y,c);
}
}
}
}
}
void gdi_draw_ascii(POINT point,unsigned char* str,unsigned short c)
{
unsigned short i,j;
unsigned short x,y;
for(i=0;i<12;i++)
{
for(j=0;j<8;j++)
{
if(((str[i]>>(7-j))&0x1)!=0)
{
x = point.x + j;
y = point.y + i;
gdi_set_pixel(x,y,c);
}
}
}
}
void gdi_draw_string(POINT point,unsigned char* str,unsigned short c)
{
int i,len;
unsigned long offset;
while(*str){
if(point.x+12 > LCDWIDTH){
point.x = 0;
point.y += 12;
}
if(point.y+12 > LCDHEIGHT){
point.y = 0;
}
if((*str)&0x80){//hzk12
offset = ((((*str-0xa0)-1)*94)+((*(str+1)-0xa0)-1))*24;
gdi_draw_hz(point,(unsigned char*)(HZK12+offset),c);
str += 2;
point.x += 12;
}else{//ASCII
offset = (*str) * 12;
gdi_draw_ascii(point,ASCII12+offset,c);
str++;
point.x += 8;
}
}
}
void gdi_draw_string_border(POINT point,unsigned char* str,unsigned short c)
{
int i,len;
unsigned long offset;
POINT tpoint;
while(*str){
if(point.x+12 > LCDWIDTH){
point.x = 1;
point.y += 12;
}
if(point.y+12 > LCDHEIGHT){
point.y = 1;
}
if(point.x == 0)point.x = 1;
if(point.y == 0)point.y = 1;
if((*str)&0x80){//hzk12
offset = ((((*str-0xa0)-1)*94)+((*(str+1)-0xa0)-1))*24;
tpoint.x = point.x-1;
tpoint.y = point.y;
gdi_draw_hz(tpoint,(unsigned char*)(HZK12+offset),~(c+1));
tpoint.x = point.x+1;
tpoint.y = point.y;
gdi_draw_hz(tpoint,(unsigned char*)(HZK12+offset),~(c+1));
tpoint.x = point.x;
tpoint.y = point.y-1;
gdi_draw_hz(tpoint,(unsigned char*)(HZK12+offset),~(c+1));
tpoint.x = point.x;
tpoint.y = point.y+1;
gdi_draw_hz(tpoint,(unsigned char*)(HZK12+offset),~(c+1));
gdi_draw_hz(point,(unsigned char*)(HZK12+offset),c);
str += 2;
point.x += 14;
}else{//ASCII
offset = (*str) * 12;
tpoint.x = point.x-1;
tpoint.y = point.y;
gdi_draw_ascii(tpoint,ASCII12+offset,~(c+1));
tpoint.x = point.x+1;
tpoint.y = point.y;
gdi_draw_ascii(tpoint,ASCII12+offset,~(c+1));
tpoint.x = point.x;
tpoint.y = point.y-1;
gdi_draw_ascii(tpoint,ASCII12+offset,~(c+1));
tpoint.x = point.x;
tpoint.y = point.y+1;
gdi_draw_ascii(tpoint,ASCII12+offset,~(c+1));
gdi_draw_ascii(point,ASCII12+offset,c);
str++;
point.x += 10;
}
}
}
void gdi_text_out(RECT rect,unsigned char* str,unsigned short c)
{
int i,len;
int x,y,rectw,recth;
unsigned long offset;
POINT point;
x = rect.startX;
y = rect.startY;
rectw = rect.width;
recth = rect.height;
while(*str){
if(x+12 > rect.startX+rect.width){
x = rect.startX;
y += 12;
}
if(y+12 > rect.startY+rect.height){
return;
}
point.x = x;
point.y = y;
if((*str)&0x80){//hzk12
offset = ((((*str-0xa0)-1)*94)+((*(str+1)-0xa0)-1))*24;
gdi_draw_hz(point,(unsigned char*)(HZK12+offset),c);
str += 2;
x += 12;
}else{//ASCII
offset = (*str) * 12;
gdi_draw_ascii(point,ASCII12+offset,c);
str++;
x += 8;
}
}
}
void gdi_text_out_border(RECT rect,unsigned char* str,unsigned short c)
{
int i,len;
int x,y,rectw,recth;
unsigned long offset;
POINT point,tpoint;
x = rect.startX;
y = rect.startY;
rectw = rect.width;
recth = rect.height;
if(x == 0)x = 1;
if(y == 0)y = 1;
while(*str){
if(x+14 > rect.startX+rect.width){
x = rect.startX;
y += 14;
}
if(y+14 > rect.startY+rect.height){
return;
}
point.x = x;
point.y = y;
if((*str)&0x80){//hzk12
offset = ((((*str-0xa0)-1)*94)+((*(str+1)-0xa0)-1))*24;
tpoint.x = point.x-1;
tpoint.y = point.y;
gdi_draw_hz(tpoint,(unsigned char*)(HZK12+offset),~(c));
tpoint.x = point.x+1;
tpoint.y = point.y;
gdi_draw_hz(tpoint,(unsigned char*)(HZK12+offset),~(c));
tpoint.x = point.x;
tpoint.y = point.y-1;
gdi_draw_hz(tpoint,(unsigned char*)(HZK12+offset),~(c));
tpoint.x = point.x;
tpoint.y = point.y+1;
gdi_draw_hz(tpoint,(unsigned char*)(HZK12+offset),~(c));
gdi_draw_hz(point,(unsigned char*)(HZK12+offset),c);
str += 2;
x += 14;
}else{//ASCII
offset = (*str) * 12;
tpoint.x = point.x-1;
tpoint.y = point.y;
gdi_draw_ascii(tpoint,ASCII12+offset,~(c));
tpoint.x = point.x+1;
tpoint.y = point.y;
gdi_draw_ascii(tpoint,ASCII12+offset,~(c));
tpoint.x = point.x;
tpoint.y = point.y-1;
gdi_draw_ascii(tpoint,ASCII12+offset,~(c));
tpoint.x = point.x;
tpoint.y = point.y+1;
gdi_draw_ascii(tpoint,ASCII12+offset,~(c));
gdi_draw_ascii(point,ASCII12+offset,c);
str++;
x += 10;
}
}
}
void test_string()
{
POINT point;
point.x = 20;
point.y = 20;
gdi_draw_string(point,(unsigned char*)"测试aa测试aa测试aa测试aa测试aa测试aa测试aa测试aa测试aa",0xf800);
gdi_update_rscreen();
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -