简介
对鼠标移动后局部刷新图层窗口后,系统效率实现了质的飞跃。电脑上看到的图形界面都是操作系统提供相关窗口绘制功能绘制出来的。
目标
实现一个简单的消息小窗口,以窥见GUI的本质。
1.win_sheet.c
//在特定窗口上绘制矩形
void sheet_fillRect(int x,int y,int width,int height,char col,SHEET *sht){
for(int i=y;i<y+height;i++){
for(int j=x;j<x+width;j++){
sht->buf[i*sht->width+j] = col;
}
}
}
修改以前os.c 中的fillRect 函数实现在指定窗口上绘制矩形的操作,其中绘制的x、y坐标都是相对窗口本身,即矩形最左上角坐标是从(0,0) 开始的。
2.os.c
申明消息窗口指针
//消息窗口
static SHEET *_shtMsg;
初始化窗口数据信息,init_main 函数中创建消息窗口。
//消息框
_shtMsg = sheet_alloc(_shtctl);
mem = (unsigned char *)mem_alloc(_memman,160*80);
sheet_setRect(20,20,160,80,COLOR_INVISIBLE,_shtMsg,mem);
makeWindow(_shtctl,_shtMsg);
sheet_setWeight(_shtctl,_shtMsg,2);
编写绘制窗口函数makeWindow
static void makeWindow(SHTCTL *shtctl,SHEET *sht) {
//这个数组,对应的是小窗口右上角的X按钮,这