📄 gui.c
字号:
#include "GUI.h"
#include "stdio.h"
#include "Queue.h"
#include "Message.h"
#include "String.h"
unsigned short VESA_X_MAX=800;
unsigned short VESA_Y_MAX=600;
unsigned long *VGAMEM;
#define ASC_WIDTH 8
#define CHS_WIDTH 16
#define SPACING 2
#define CHAR_HEIGHT 16
#define ASC_NUM 256
extern unsigned char ASC[ASC_NUM][CHAR_HEIGHT];
int CurrentWinNum=24;
static unsigned char ws_btn_close_A[16*16] ={
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x00,
0x0F, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00,
0x0F, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00,
0x0F, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00,
0x0F, 0x07, 0x07, 0x07, 0x00, 0x07, 0x07, 0x07,0x07, 0x07, 0x07, 0x00, 0x07, 0x07, 0x07, 0x00,
0x0F, 0x07, 0x07, 0x07, 0x07, 0x00, 0x07, 0x07,0x07, 0x07, 0x00, 0x07, 0x07, 0x07, 0x07, 0x00,
0x0F, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00, 0x07,0x07, 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00,
0x0F, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00,0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00,
0x0F, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00,0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00,
0x0F, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00, 0x07,0x07, 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00,
0x0F, 0x07, 0x07, 0x07, 0x07, 0x00, 0x07, 0x07,0x07, 0x07, 0x00, 0x07, 0x07, 0x07, 0x07, 0x00,
0x0F, 0x07, 0x07, 0x07, 0x00, 0x07, 0x07, 0x07,0x07, 0x07, 0x07, 0x00, 0x07, 0x07, 0x07, 0x00,
0x0F, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00,
0x0F, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00,
0x0F, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
/*
static unsigned char ws_btn_close_B[16*16] ={
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x0F,
0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x0F,
0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x0F,
0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x0F,
0x00, 0x07, 0x07, 0x07, 0x07, 0x00, 0x07, 0x07,0x07, 0x07, 0x07, 0x07, 0x00, 0x07, 0x07, 0x0F,
0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00, 0x07,0x07, 0x07, 0x07, 0x00, 0x07, 0x07, 0x07, 0x0F,
0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00,0x07, 0x07, 0x00, 0x07, 0x07, 0x07, 0x07, 0x0F,
0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,0x00, 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x0F,
0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,0x00, 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x0F,
0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00,0x07, 0x07, 0x00, 0x07, 0x07, 0x07, 0x07, 0x0F,
0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00, 0x07,0x07, 0x07, 0x07, 0x00, 0x07, 0x07, 0x07, 0x0F,
0x00, 0x07, 0x07, 0x07, 0x07, 0x00, 0x07, 0x07,0x07, 0x07, 0x07, 0x07, 0x00, 0x07, 0x07, 0x0F,
0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x0F,
0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x0F,
0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
};
*/
//--------------------------------------------------------------------------------------------
//
//
//
//
//--------------------------------------------------------------------------------------------
void InitScreen(void)
{
VGAMEM = (unsigned long *)0xFFC00000;
}
//--------------------------------------------------------------------------------------------
//
//
//
//
//--------------------------------------------------------------------------------------------
void VesaPutPixel(unsigned short x,unsigned short y,unsigned long color)
{
VGAMEM[y*VESA_X_MAX+x]=color;
}
//--------------------------------------------------------------------------------------------
//
//
//
//
//--------------------------------------------------------------------------------------------
unsigned long VESAChangeColor24( unsigned char* p)
{
unsigned long ColorR;
unsigned long ColorG;
unsigned long ColorB;
unsigned long Color32;
ColorR=p[2];
ColorR=ColorR<<16;
ColorG=p[1];
ColorG=ColorG<<8;
ColorB=p[0];
ColorB=ColorB;
Color32=ColorR+ColorG+ColorB;
return Color32;
}
//--------------------------------------------------------------------------------------------
//
//
//
//
//--------------------------------------------------------------------------------------------
void VesaShowBmp(unsigned long FileAddr,unsigned int x , unsigned int y)
{
typedef struct{
unsigned short FileType;
unsigned long FileSize;
unsigned long Reserved;
unsigned long DataStart;
unsigned long HeaderSize;
unsigned long ImageWidth;
unsigned long ImageHeight;
unsigned short Planes;
unsigned short Bpp;
unsigned long Compression;
} __attribute__ ((packed)) BmpFileHeader;
unsigned long temp_color;
BmpFileHeader *BmpHeader = (BmpFileHeader *) FileAddr;
int width = BmpHeader[0].ImageWidth ;
int height = BmpHeader[0].ImageHeight ;
int j,i;
unsigned char *color = ( unsigned char*)(FileAddr + BmpHeader[0].DataStart ) ;
int fill_length = width*3 % 4;
LockProc(1);
for( i = height-1 ; i >0 ; i-- ){
for( j = 0 ; j < width ; j++ ){
temp_color = VESAChangeColor24(color) ;
// 画出每个点
VesaPutPixel(x+j,y+i,temp_color) ;
color+=3 ;
}
color+=fill_length;
}
LockProc(0);
}
void HdcSetPixel(HDC hdc,int x,int y);
//--------------------------------------------------------------------------------------------
//
//
//
//
//--------------------------------------------------------------------------------------------
void HdcShowBmp(HDC hdc,unsigned int x , unsigned int y,unsigned long FileAddr)
{
typedef struct{
unsigned short FileType;
unsigned long FileSize;
unsigned long Reserved;
unsigned long DataStart;
unsigned long HeaderSize;
unsigned long ImageWidth;
unsigned long ImageHeight;
unsigned short Planes;
unsigned short Bpp;
unsigned long Compression;
} __attribute__ ((packed)) BmpFileHeader;
unsigned long temp_color;
BmpFileHeader *BmpHeader = (BmpFileHeader *) FileAddr;
int width = BmpHeader[0].ImageWidth ;
int height = BmpHeader[0].ImageHeight ;
int j,i;
unsigned char *color = (unsigned char*)(FileAddr + BmpHeader[0].DataStart) ;
int fill_length = width*3 % 4;
LockProc(1);
for( i = height-1 ; i >0 ; i-- ){
for( j = 0 ; j < width; j++ ){
temp_color = VESAChangeColor24(color) ;
// 画出每个点
hdc->penColor=temp_color;
HdcSetPixel(hdc,x+j,y+i);
color+=3 ;
}
color+=fill_length;
}
LockProc(0);
}
//--------------------------------------------------------------------------------------------
//
//
//
//
//--------------------------------------------------------------------------------------------
HDC CreateBmpHdc(char* bmpfilename,int w,int h,int flag)
{
FILE* fp;
unsigned char* buf;
HDC hdc=(HDC)kmalloc(sizeof(DC));
hdc->mBuf=(unsigned long*)kmalloc(w*h*sizeof(unsigned long));
hdc->Bounds=SetRect(0,0,w,h);
fp=OpenFile(bmpfilename);
buf=(unsigned char*)kmalloc(fp->f_size);
ReadFile(fp,buf,fp->f_size);
HdcShowBmp(hdc,0,0,(unsigned long)buf);
kfree((unsigned long)buf,fp->f_size);
return hdc;
}
//--------------------------------------------------------------------------------------------
//
//
//
//
//--------------------------------------------------------------------------------------------
BOOL BitBlt(HDC hdcDest,int nXDest,int nYDest,int nWidth,int nHeight,
HDC hdcSrc, int nXSrc,int nYSrc)
{
int ScanLineW=nWidth;
int ScanLineH=nHeight;
int SrcWidth= hdcSrc->Bounds.right- hdcSrc->Bounds.left;
int SrcHeight=hdcSrc->Bounds.bottom-hdcSrc->Bounds.top;
int DestWidth= hdcDest->Bounds.right- hdcDest->Bounds.left;
int DestHeight=hdcDest->Bounds.bottom-hdcDest->Bounds.top;
unsigned long DestStart=nYDest*DestWidth+nXDest;
unsigned long SrcStart =nYSrc*SrcWidth+nXSrc;
register int i,j;
RECT eRect;
if(nXSrc+ScanLineW > SrcWidth) ScanLineW=SrcWidth- nXSrc;
if(nYSrc+ScanLineH > SrcHeight) ScanLineH=SrcHeight-nYSrc;
if(nXDest+ScanLineW > DestWidth) ScanLineW=DestWidth- nXDest;
if(nYDest+ScanLineH > DestHeight) ScanLineH=DestHeight- nYDest;
LockProc(TRUE);
for(j=0;j<ScanLineH;j++)
{
for(i=0;i<ScanLineW;i++)
hdcDest->mBuf[DestStart+i]=hdcSrc->mBuf[SrcStart+i];
DestStart+=DestWidth;
SrcStart +=SrcWidth;
}
LockProc(FALSE);
eRect=SetRect(0,0,DestWidth,DestHeight);
InvalidRectToVram(hdcDest,&eRect);
return TRUE;
}
//--------------------------------------------------------------------------------------------
//
//
//
//
//--------------------------------------------------------------------------------------------
__inline RGB GetRGB(unsigned char r,unsigned char g,unsigned char b)
{
register unsigned long RGBr;
register unsigned long RGBg;
register unsigned long RGBb;
RGBr=(unsigned long)r;
RGBr=RGBr<<16;
RGBg=(unsigned long)g;
RGBg=RGBg<<8;
RGBb=(unsigned long)b;
return (unsigned long)(RGBr | RGBg | RGBb);
}
//--------------------------------------------------------------------------------------------
//
//
//
//
//--------------------------------------------------------------------------------------------
RECT SetRect(int left,int top,int right,int bottom)
{
RECT rc;
rc.left=left;
rc.top=top;
rc.right=right;
rc.bottom=bottom;
return rc;
}
//--------------------------------------------------------------------------------------------
//
//
//
//
//--------------------------------------------------------------------------------------------
BOOL IsNullRect(RECT rc)
{
if(rc.left==0 && rc.right==0 && rc.top==0 && rc.bottom==0) return TRUE;
return FALSE;
}
//--------------------------------------------------------------------------------------------
//
//
//
//
//--------------------------------------------------------------------------------------------
void HdcSetPixel(HDC hdc,int x,int y)
{
int sw=hdc->Bounds.right-hdc->Bounds.left;
int sh=hdc->Bounds.bottom-hdc->Bounds.top;
if(x<0 || x>sw-1 || y<0 || y>sh-1) return;
hdc->mBuf[y*sw+x]=hdc->penColor;
}
//--------------------------------------------------------------------------------------------
//
//
//
//
//--------------------------------------------------------------------------------------------
void HdcDrawVline(HDC hdc,int x1,int x2,int y)
{
register int i;
for(i=x1;i<x2;i++)
HdcSetPixel(hdc,i,y);
}
//--------------------------------------------------------------------------------------------
//
//
//
//
//--------------------------------------------------------------------------------------------
void HdcDrawHline(HDC hdc,int y1,int y2,int x)
{
register int i;
for(i=y1;i<y2;i++)
HdcSetPixel(hdc,x,i);
}
//--------------------------------------------------------------------------------------------
//
//
//
//
//--------------------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -