⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 object.c

📁 DOS游戏界面的设计
💻 C
📖 第 1 页 / 共 2 页
字号:

}

void Fill_Screen(int value)
{
_fmemset(video_buffer,(char)value,SCREEN_WIDTH*SCREEN_HEIGHT+1);
}

void Fill_Screen_Size(int value,int x0,int y0,int x1,int y1)
{
int x,y;
long i=0,height,width;
height=y1-y0+1;
width=x1-x0+1;
x=x0;
while(i<height*width)
{
	y=y0+i/width;
	i=i+width;
	_fmemset(video_buffer+x+y*SCREEN_WIDTH,(char)value,width);
}
}



void Blit_Char(int xc,int yc,char c,int color,int trans_flag)
{
int offset,x,y;
char far *work_char;
unsigned char bit_mask=0x80;
work_char=rom_char_set+c*CHAR_HEIGHT;
offset=(yc<<8)+(yc<<6)+xc;
for(y=0;y<CHAR_HEIGHT;y++)
{
bit_mask=0x80;
for(x=0;x<CHAR_WIDTH;x++)
{
if((*work_char&bit_mask))
video_buffer[offset+x]=color;
else if(!trans_flag)
video_buffer[offset+x]=0;
bit_mask=(bit_mask>>1);
}
offset+=SCREEN_WIDTH;
work_char++;
}
}


void Blit_String(int x,int y,int color,char *string,int trans_flag)
{
int index;
for(index=0;string[index]!=0;index++)
{
Blit_Char(x+(index<<3),y,string[index],color,trans_flag);
}
}

void Draw_Windows(windows_ptr win)
{
	switch(win->kind)
	{
		case WINDOWS:
		{
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,WINDOWS_COLOR_DARK);
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,WINDOWS_COLOR_LIGHT);
			Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,WINDOWS_COLOR_OUT);
			Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+10,WINDOWS_COLOR_TITLE);
			if(win->active==ACTIVE)
				Blit_String(win->top.x+2,win->top.y+2,win->color,win->word,1);
			else
				Blit_String(win->top.x+2,win->top.y+2,NOACTIVE_COLOR,win->word,1);
			Fill_Rectangle(win->top.x+2,win->top.y+22,win->top.x+win->move.x-2,win->top.y+win->move.y-2,WINDOWS_COLOR_LIGHT);
			Fill_Rectangle(win->top.x+2,win->top.y+22,win->top.x+win->move.x-3,win->top.y+win->move.y-3,WINDOWS_COLOR_DARK);
			Fill_Rectangle(win->top.x+3,win->top.y+23,win->top.x+win->move.x-3,win->top.y+win->move.y-3,WINDOWS_COLOR_IN);

			break;
		}
		case BUTTON_MENU:
		{
			if(win->active==ACTIVE)
				Blit_String(win->top.x+2,win->top.y+1,win->color,win->word,1);
			else
				Blit_String(win->top.x+2,win->top.y+1,NOACTIVE_COLOR,win->word,1);
			break;
		}
		case BUTTON:
		{
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,BUTTON_COLOR_DARK);
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR_LIGHT);
			Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR);
			if(win->active==ACTIVE)
				Blit_String(win->top.x+2,win->top.y+1,win->color,win->word,1);
			else
				Blit_String(win->top.x+2,win->top.y+1,NOACTIVE_COLOR,win->word,1);
			break;
		}
		case BUTTON_PRESS:
		{
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,BUTTON_COLOR_LIGHT);
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR_DARK);
			Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR);
			Blit_String(win->top.x+2,win->top.y+1,win->color,win->word,1);
			break;
		}
		case BUTTON_CLOSE:
		{
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,BUTTON_COLOR_DARK);
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR_LIGHT);
			Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR);
			if(win->active==ACTIVE)
			{
				Bline(win->top.x+2,win->top.y+2,win->top.x+win->move.x-2,win->top.y+win->move.y-2,win->color);
				Bline(win->top.x+win->move.x-2,win->top.y+2,win->top.x+2,win->top.y+win->move.y-2,win->color);
			}
			else
			{
				Bline(win->top.x+2,win->top.y+2,win->top.x+win->move.x-2,win->top.y+win->move.y-2,NOACTIVE_COLOR);
				Bline(win->top.x+win->move.x-2,win->top.y+2,win->top.x+2,win->top.y+win->move.y-2,NOACTIVE_COLOR);
			}
			break;
		}
		case BUTTON_CLOSE_PRESS:
		{
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,BUTTON_COLOR_LIGHT);
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR_DARK);
			Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR);
			Bline(win->top.x+2,win->top.y+2,win->top.x+win->move.x-2,win->top.y+win->move.y-2,win->color);
			Bline(win->top.x+win->move.x-2,win->top.y+2,win->top.x+2,win->top.y+win->move.y-2,win->color);
			break;
		}
		case BUTTON_SMALL:
		{
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,BUTTON_COLOR_DARK);
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR_LIGHT);
			Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR);
			if(win->active==ACTIVE)
				H_Line(win->top.x+2,win->top.x+win->move.x-2,win->top.y+win->move.y-2,win->color);
			else
				H_Line(win->top.x+2,win->top.x+win->move.x-2,win->top.y+win->move.y-2,NOACTIVE_COLOR);
			break;
		}
		case BUTTON_SMALL_PRESS:
		{
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,BUTTON_COLOR_LIGHT);
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR_DARK);
			Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR);
			H_Line(win->top.x+2,win->top.x+win->move.x-2,win->top.y+win->move.y-2,win->color);
			break;
		}
		default:break;
	}
}

void Object_Init(windows_ptr ptr,int kind,int x,int y,int move_x,int move_y,char *word,int color,int bk_color,int status,char *hotkey,int bk_flag,void (far *windows),int active)
{
	ptr->kind=kind;
	ptr->top.x=x;
	ptr->top.y=y;
	ptr->move.x=move_x;
	ptr->move.y=move_y;
	ptr->word=word;
	ptr->color=color;
	ptr->bk_color=bk_color;
	ptr->status=status;
	ptr->hotkey=hotkey;
	ptr->windows=windows;
	ptr->bk_flag=bk_flag;
	if(bk_flag==1)
		ptr->background=(char far *)malloc( (move_x+1)* (move_y+1)+1);
	ptr->active=active;
}

void Behind_Button(windows_ptr win)
{

char far *work_back;
int work_offset=0,offset,y;


work_back = win->background;


offset = (win->top.y << 8) + (win->top.y << 6) + win->top.x;

for (y=0; y<BUTTON_Y; y++)
    {

    _fmemmove((void far *)&work_back[work_offset],
	     (void far *)&video_buffer[offset],
	     BUTTON_X);


    offset      += SCREEN_WIDTH;
    work_offset += BUTTON_X;

    }

}

void Erase_Button(windows_ptr win)
{

char far *work_back;
int work_offset=0,offset,y;


work_back = win->background;


offset = (win->top.y << 8) + (win->top.y << 6) + win->top.x;

for (y=0; y<BUTTON_Y; y++)
    {

    _fmemmove((void far *)&video_buffer[offset],
	     (void far *)&work_back[work_offset],
	     BUTTON_X);


    offset      += SCREEN_WIDTH;
    work_offset += BUTTON_X;

    }

}

void Object_Delete(windows_ptr win)
{

	int index;

	if(win->bk_flag==1)
		free(win->background);
	free(&win);
}


void win(windows_ptr win)
{
//	printf("\n\n\n\n\nwindows fuction is in use\n");
}

void clo(windows_ptr win)
{
	win->kind=BUTTON_CLOSE_PRESS;
	Draw_Windows(win);
	Delay(5);
	win->kind=BUTTON_CLOSE;
	Draw_Windows(win);
	Delay(5);
	Set_Video_Mode(TEXT_MODE);
	exit(1);
}

void bt1(windows_ptr win)
{
	int x,y,fcolor;
	long i;
	win->kind=BUTTON_PRESS;
	Draw_Windows(win);
	Delay(5);
	win->kind=BUTTON;
	Draw_Windows(win);
	men(win->father);
	for(i=0;i<1000000;i++)
	{
		x=rand()%(WINDOWS_X_MOVE-20);
		y=rand()%(WINDOWS_Y_MOVE-40);
		fcolor=rand()%(256)+1;
		Plot_Pixel_Fast(WINDOWS_X+10+x,WINDOWS_Y+30+y,fcolor);
	}

}

void bt2(windows_ptr win)
{
	win->kind=BUTTON_PRESS;
	Draw_Windows(win);
	Delay(5);
	win->kind=BUTTON;
	Draw_Windows(win);
	Delay(5);
	Set_Video_Mode(TEXT_MODE);
	exit(1);
}

void sma(windows_ptr win)
{
	win->kind=BUTTON_SMALL_PRESS;
	Draw_Windows(win);
	Delay(5);
	win->kind=BUTTON_SMALL;
	Draw_Windows(win);
	Blit_String(WINDOWS_X+10,WINDOWS_Y+30,0,"small button is in use",1);
/*	if(win->status==MAX)
	{
		Fill_Screen_Size(0,win_now.top.x,win_now.top.y,win_now.top.x+win_now.move.x,win_now.top.y+win_now.move.y);
		win->status=MIN;
	}
	else(win->status==MIN);
*/
}

void men(windows_ptr win)
{
	windows *restore;
	if(win->status==MIN)
	{
		now=(struct windows *)malloc(sizeof(struct windows));
		Object_Init(now,BUTTON,WINDOWS_X+4,WINDOWS_Y+BUTTON_Y+13,BUTTON_X-1,BUTTON_Y-1,"game",0,24,0,"",1,bt1,ACTIVE);
		now->father=win;
		Behind_Button(now);
		Draw_Windows(now);
		last->next=now;
		pre=now;
		now=(struct windows *)malloc(sizeof(struct windows));
		Object_Init(now,BUTTON,WINDOWS_X+4,WINDOWS_Y+BUTTON_Y*2+13,BUTTON_X-1,BUTTON_Y-1,"exit",0,24,0,"",1,bt2,ACTIVE);
		now->father=win;
		Behind_Button(now);
		Draw_Windows(now);
//		getch();
//		Erase_Button(*now);
//		getch();
		pre->next=now;
		pre=now;
		pre->next=NULL;

		win->status=MAX;

	}
	else if(win->status==MAX)
	{
		restore=head;
		if(restore->bk_flag==1)
		{
			Erase_Button(restore);
			Object_Delete(restore);
		}
		do{
			restore=restore->next;
			if(restore->bk_flag==1)
			{
				Erase_Button(restore);
				Object_Delete(restore);
			}
		}while(restore->next!=NULL);
		last->next=NULL;
		win->status=MIN;
	}
}

void Judge_Object(void)
{
	int xmouse,ymouse,btnmouse;
	static int btn=-1;
	windows_ptr test;
	Squeeze_Mouse(MOUSE_BUTT_POS,&xmouse,&ymouse,&btnmouse);
	if(btnmouse==btn)
		return;
	else
		btn=btnmouse;
	xmouse=xmouse/2;
	ymouse=ymouse;
	if(btnmouse==1)
	{
		test=head;
		if((xmouse>=test->top.x&&xmouse<=test->top.x+test->move.x)&&
		(ymouse>=test->top.y&&ymouse<=test->top.y+test->move.y))
		{
			Squeeze_Mouse(MOUSE_HIDE,0,0,0);
			if(test->active==ACTIVE)
				test->windows(test);
			Squeeze_Mouse(MOUSE_SHOW,0,0,0);
		}
		do{
			test=test->next;
			if((xmouse>=test->top.x&&xmouse<=test->top.x+test->move.x)&&
			(ymouse>=test->top.y&&ymouse<=test->top.y+test->move.y))
			{
				Squeeze_Mouse(MOUSE_HIDE,0,0,0);
				if(test->active==ACTIVE)
					test->windows(test);
				Squeeze_Mouse(MOUSE_SHOW,0,0,0);
			}
		}while(test->next!=NULL);

	}
}

void main(void)
{
	windows_ptr test;
	Set_Video_Mode(VGA256);
	now=pre=(struct windows *)malloc(sizeof(struct windows));
	Object_Init(now,WINDOWS,WINDOWS_X,WINDOWS_Y,WINDOWS_X_MOVE,WINDOWS_Y_MOVE,"This is a game desktop",0,24,0,"",0,win,ACTIVE);
	win_now=now;
	Draw_Windows(now);
	head=now;
	now=(struct windows *)malloc(sizeof(struct windows));
	Object_Init(now,BUTTON_MENU,WINDOWS_X+2,WINDOWS_Y+11,BUTTON_X-1,BUTTON_Y-1,"Menu",0,24,MIN,"",0,men,ACTIVE);
	Draw_Windows(now);
	pre->next=now;
	pre=now;
	now=(struct windows *)malloc(sizeof(struct windows));
	Object_Init(now,BUTTON_SMALL,WINDOWS_X+WINDOWS_X_MOVE-(BUTTON_XY+2)*2,WINDOWS_Y+2,BUTTON_XY-1,BUTTON_XY-1,"",0,24,MAX,"",0,sma,NOACTIVE);
	Draw_Windows(now);
	pre->next=now;
	pre=now;
	now=(struct windows *)malloc(sizeof(struct windows));
	Object_Init(now,BUTTON_CLOSE,WINDOWS_X+WINDOWS_X_MOVE-BUTTON_XY-2,WINDOWS_Y+2,BUTTON_XY-1,BUTTON_XY-1,"",0,24,0,"",0,clo,ACTIVE);
	Draw_Windows(now);
	pre->next=now;
	pre=now;
	pre->next=NULL;
	last=pre;
/*
	getch();
	test=head;
	test->windows(*test);
	getch();

	do{
		test=test->next;
		test->windows(*test);
		getch();
	}while(test->next!=NULL);
*/
	Squeeze_Mouse(MOUSE_RESET,0,0,0);
	mscurson(handcurs);

	while(1){
		Judge_Object();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -