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

📄 svgadem2.c

📁 MSC或BC开发的SVGA图形开发库(允许使用300x200,640x480,80x600,1024x768等多种模式) 此开发库特别适合嵌入式系统
💻 C
📖 第 1 页 / 共 3 页
字号:
	 * Show joystickinfo (here we do some joystick calibration
	 */
	sprintf(buf,"joystickinfo(jax,jay,jabuts,jbx,jby,jbbuts);");
	drwstring(1,7,0,buf,10,16);
	switch(joystick) {
		case 1:
			sprintf(buf,"Please move Joystick A as far as it will go in all directions.");
			break;
		case 2:
			sprintf(buf,"Please move Joystick B as far as it will go in all directions.");
			break;
		case 3:
			sprintf(buf,"Please move Joystick A and B as far as they will go in all directions.");
			break;
	}
	drwstring(1,7,0,buf,10,32);
	drwstring(1,7,0,"And then press a key...",10,48);

	maxxa = -1;
	maxya = -1;
	minxa = 10000;
	minya = 10000;
	maxxb = -1;
	maxyb = -1;
	minxb = 10000;
	minyb = 10000;
	do {
		while(!kbhit()) {
			joystickinfo(&jax,&jay,&jabuts,&jbx,&jby,&jbbuts);
			if (joystick & 1) {
				if (jax>maxxa)
					maxxa = jax;
				if (jax<minxa)
					minxa = jax;
				if (jay>maxya)
					maxya = jay;
				if (jay<minya)
					minya = jay;
			}
			if (joystick & 2) {
				if (jbx>maxxb)
					maxxb = jbx;
				if (jbx<minxb)
					minxb = jbx;
				if (jby>maxyb)
					maxyb = jby;
				if (jby<minyb)
					minyb = jby;
			}
		}
		ret = getkey();
	} while ( ((joystick & 1) && ((maxxa==minxa) || (maxya==minya))) || 
		((joystick & 2) && ((maxxb==minxb) || (maxyb==minyb))) );

	if ((ret=='s') || (ret=='q')) {
		setview(0,0,maxx,maxy);
		fillscreen(0);
		return(ret);
	}

	/*
	 * Calculate the center and stuff
	 */
	spcing = maxx / 7;
	dist = spcing * 2;
	x1 = spcing / 2;
	y1 = spcing / 2 + 32;
	x2 = x1 + dist;
	y2 = y1 + dist;
	x4 = maxx - spcing;
	y4 = y2;
	x3 = x4 - dist;
	y3 = y1;
	cntax = (x2 - x1) / 2 + x1;
	cntay = (y2 - y1) / 2 + y1;
	cntbx = (x4 - x3) / 2 + x3;
	cntby = (y4 - y3) / 2 + y3;
	rangexa = maxxa - minxa;
	rangeya = maxya - minya;
	rangexb = maxxb - minxb;
	rangeyb = maxyb - minyb;
	jabax = (x2 - x1) / 4 + x1 - 16;
	jabay = spcing / 4 + y2 - 6;
	jabbx = x2 - (x2 - x1) / 4 - 16;
	jabby = spcing / 4 + y2 - 6;
	jbbax = (x4 - x3) / 4 + x3 - 16;
	jbbay = spcing / 4 + y4 - 6;
	jbbbx = x4 - (x4 - x3) / 4 - 16;
	jbbby = spcing / 4 + y4 - 6;

	/*
	 * Let's move it (or them) around
	 */
	setview(0,32,maxx,maxy);
	fillview(0);
	drwstring(1,7,0,"Joysticks are nonlinear devices and may not appear centered.",10,32);

	if (joystick & 1) {
		drwbox(1,15,x1-1,y1-1,x2+1,y2+1);
		drwbox(1,15,x1-1,y2+1,x2+1,y2+spcing/2);
		drwline(1,15,(x2-x1)/2+x1,y2+1,(x2-x1)/2+x1,y2+spcing/2);
		oax = cntax;
		oay = cntay;
		drwline(1,10,cntax,cntay,oax,oay);
	}
	else {
		drwbox(1,8,x1-1,y1-1,x2+1,y2+1);
		drwbox(1,8,x1-1,y2+1,x2+1,y2+spcing/2);
		drwline(1,8,(x2-x1)/2+x1,y2+1,(x2-x1)/2+x1,y2+spcing/2);
	}
	if (joystick & 2) {
		drwbox(1,15,x3-1,y3-1,x4+1,y4+1);
		drwbox(1,15,x3-1,y4+1,x4+1,y4+spcing/2);
		drwline(1,15,(x4-x3)/2+x3,y4+1,(x4-x3)/2+x3,y4+spcing/2);
		obx = cntbx;
		oby = cntby;
		drwline(1,10,cntbx,cntby,obx,oby);
	}
	else {
		drwbox(1,8,x3-1,y3-1,x4+1,y4+1);
		drwbox(1,8,x3-1,y4+1,x4+1,y4+spcing/2);
		drwline(1,8,(x4-x3)/2+x3,y4+1,(x4-x3)/2+x3,y4+spcing/2);
	}
	while(!kbhit()) {
		joystickinfo(&jax,&jay,&jabuts,&jbx,&jby,&jbbuts);
		if (joystick & 1) {
			setview(x1,y1,x2,y2);
			jax = jax - minxa;
			jax = jax * dist / rangexa + x1;
			jay = jay - minya;
			jay = jay * dist / rangeya + y1;
			drwline(1,0,cntax,cntay,oax,oay);
			oax = jax;
			oay = jay;
			drwline(1,10,cntax,cntay,oax,oay);
			setview(0,0,maxx,maxy);
			sprintf(buf,"ButA");
			if (jabuts & 1)
				drwstring(1,10,0,buf,jabax,jabay);
			else
				drwstring(1,8,0,buf,jabax,jabay);
			sprintf(buf,"ButB");
			if (jabuts & 2)
				drwstring(1,10,0,buf,jabbx,jabby);
			else
				drwstring(1,8,0,buf,jabbx,jabby);
		}
		if (joystick & 2) {
			setview(x3,y3,x4,y4);
			jbx = jbx - minxb;
			jbx = jbx * dist / rangexb + x3;
			jby = jby - minyb;
			jby = jby * dist / rangeyb + y3;
			drwline(1,0,cntbx,cntby,obx,oby);
			obx = jbx;
			oby = jby;
			drwline(1,10,cntbx,cntby,obx,oby);
			setview(0,0,maxx,maxy);
			sprintf(buf,"ButA");
			if (jbbuts & 1)
				drwstring(1,10,0,buf,jbbax,jbbay);
			else
				drwstring(1,8,0,buf,jbbax,jbbay);
			sprintf(buf,"ButB");
			if (jbbuts & 2)
				drwstring(1,10,0,buf,jbbbx,jbbby);
			else
				drwstring(1,8,0,buf,jbbbx,jbbby);
		}
	}
	ret = getkey();
	fillscreen(0);
	setview(0,0,maxx,maxy);
	return(ret);
}


/***********
 * SHOWGIF *
 ***********/

char showgif(char fname[])
{
	int i, ok;
	int min, max, mincolor, maxcolor;
	int xsize, ysize, numcol;
	int xloc, yloc;
	int fixit, t;
	PaletteData gifpal;
	char ret;
	char *buf;

	buf = malloc(TITLEN);

	mincolor = maxcolor = 0;

	/*
	 * Show gifgetinfo
	 */
	palset(orgpal,0,255);
	setview(0,0,maxx,maxy);
	fillscreen(0);
	drwstring(1,7,0,"DEMO 8: GIF functions",10,0);
	sprintf(buf,"gifgetinfo(filename,gifxsize,gifysize,numcolors,palette);");
	drwstring(1,7,0,buf,10,16);
	ok = gifgetinfo(fname,&xsize,&ysize,&numcol,gifpal);
	min = 255 * 3;
	max = 0;
	if (ok == 1) {
		/*
		 * We need to check the GIF color palette entries to see if any colors
		 * are greater than six bits in length as the VGA color palette
		 * registers are only six bits wide.  We also look for the brightest
		 * and darkest colors to use as our text and background colors.
		 */
		fixit = 0;
		for(i=0;i<numcol;i++) {
			if((gifpal[i].r>63) || (gifpal[i].g>63) || (gifpal[i].b>63))
				fixit = 1;
			t = gifpal[i].r + gifpal[i].g + gifpal[i].b;
			if(t<min) {
				min = t;
				mincolor = i;
			}
			if(t>max) {
				max = t;
				maxcolor = i;
			}
		}
		/*
		 * If the GIF uses more than 6 bit color, then we shift each color entry
		 * right by 2 bits.  (This reduces it to 6 bits of color.)
		 */
		if (fixit)
			for(i=0;i<numcol;i++) {
				gifpal[i].r>>=2;
				gifpal[i].g>>=2;
				gifpal[i].b>>=2;
			}
		/*
		 * If the GIF has a palette of 128 colors or less, then we can use
		 * our own colors for the text and background.
		 */
		if (numcol<=128) {
			gifpal[254].r = gifpal[254].g = gifpal[254].b = 0;
			mincolor = 254;
			gifpal[255].r = gifpal[255].g = gifpal[255].b = 32;
			maxcolor = 255;
		}

		sprintf(buf,"'%s' is identified as a 'Non-interlaced' type 'GIF87a' GIF image.",fname);
		drwstring(1,15,0,buf,10,64);
		sprintf(buf,"Dimensions are: %d pixels wide and %d pixels high.",xsize,ysize);
		drwstring(1,15,0,buf,10,80);
		sprintf(buf,"Number of colors: %d.",numcol);
		drwstring(1,15,0,buf,10,96);

		ret = getkey();
		if ((ret=='s') || (ret=='q')) {
			fillscreen(0);
			setview(0,0,maxx,maxy);
			palset(orgpal,0,255);
			free(buf);
			return(ret);
		}

		/*
		 * Show gifput
		 */
		palset(gifpal,0,255);
		overscanset(mincolor);
		fillscreen(mincolor);
		drwstring(1,maxcolor,mincolor,"DEMO 8: GIF functions",10,0);
		sprintf(buf,"gifput(mode,x,y,filename);");
		drwstring(1,maxcolor,mincolor,buf,10,16);
		setview(0,32,maxx,maxy);
		xloc = maxx / 2 - xsize / 2;
		yloc = (maxy - 32) / 2 - ysize / 2 + 32;
		ok = gifput(1,xloc,yloc,fname);
		if (ok!=1) {
			palset(orgpal,0,255);
			sprintf(buf,"The file '%s'",fname);
			switch (ok) {
				case 0:
					strcat(buf," does not exist in the specified directory.");
					break;
				case -1:
					strcat(buf," does not have the 'GIF87a' signature.");
					break;
				case -2:
					strcat(buf," is an interlaced GIF.");
					break;
				case -3:
					strcat(buf," does not use a global color map.");
					break;
				default: /* should have a value of -4 */
					strcat(buf," has some general error.");
			}
			drwstring(1,15,0,buf,10,64);
		}
	}
	else {
		palset(orgpal,0,255);
		sprintf(buf,"The file '%s'",fname);
		switch (ok) {
			case 0:
				strcat(buf," does not exist in the specified directory.");
				break;
			case -1:
				strcat(buf," does not have the 'GIF87a' signature.");
				break;
			case -2:
				strcat(buf," is an interlaced GIF.");
				break;
			case -3:
				strcat(buf," does not use a global color map.");
				break;
			default: /* should have a value of -4 */
				strcat(buf," has some general error.");
		}
		drwstring(1,15,0,buf,10,64);
	}

	ret = getkey();

	palset(orgpal,0,255);
	overscanset(0);
	fillscreen(0);
	setview(0,0,maxx,maxy);
	free(buf);
	return(ret);
}


/*************
 * SHOWHOUSE *
 *************/

void showhouse(D2Point *plotarray, D2Point *oplotarray)
{
	int i;

	/* Erase old axes */
	drwline(1,0,(oplotarray+10)->x,(oplotarray+10)->y,(oplotarray+11)->x,(oplotarray+11)->y);
	drwline(1,0,(oplotarray+10)->x,(oplotarray+10)->y,(oplotarray+12)->x,(oplotarray+12)->y);
	drwline(1,0,(oplotarray+10)->x,(oplotarray+10)->y,(oplotarray+13)->x,(oplotarray+13)->y);
	
	/* Erase old house */
	for(i=0;i<3;i++) {
		drwline(1,0,(oplotarray+i)->x,(oplotarray+i)->y,(oplotarray+i+1)->x,(oplotarray+i+1)->y);
		drwline(1,0,(oplotarray+i+4)->x,(oplotarray+i+4)->y,(oplotarray+i+4+1)->x,(oplotarray+i+4+1)->y);
		drwline(1,0,(oplotarray+i)->x,(oplotarray+i)->y,(oplotarray+i+4)->x,(oplotarray+i+4)->y);
	}
	drwline(1,0,(oplotarray+3)->x,(oplotarray+3)->y,(oplotarray+7)->x,(oplotarray+7)->y);
	drwline(1,0,(oplotarray+0)->x,(oplotarray+0)->y,(oplotarray+3)->x,(oplotarray+3)->y);
	drwline(1,0,(oplotarray+4)->x,(oplotarray+4)->y,(oplotarray+7)->x,(oplotarray+7)->y);
	drwline(1,0,(oplotarray+3)->x,(oplotarray+3)->y,(oplotarray+8)->x,(oplotarray+8)->y);
	drwline(1,0,(oplotarray+8)->x,(oplotarray+8)->y,(oplotarray+2)->x,(oplotarray+2)->y);
	drwline(1,0,(oplotarray+9)->x,(oplotarray+9)->y,(oplotarray+7)->x,(oplotarray+7)->y);
	drwline(1,0,(oplotarray+9)->x,(oplotarray+9)->y,(oplotarray+6)->x,(oplotarray+6)->y);
	drwline(1,0,(oplotarray+8)->x,(oplotarray+8)->y,(oplotarray+9)->x,(oplotarray+9)->y);

	/* Draw new axes */
	drwline(1,8,(plotarray+10)->x,(plotarray+10)->y,(plotarray+11)->x,(plotarray+11)->y);
	drwline(1,8,(plotarray+10)->x,(plotarray+10)->y,(plotarray+12)->x,(plotarray+12)->y);
	drwline(1,8,(plotarray+10)->x,(plotarray+10)->y,(plotarray+13)->x,(plotarray+13)->y);
	
	/* Draw new house */
	for(i=0;i<3;i++) {
		drwline(1,10,(plotarray+i)->x,(plotarray+i)->y,(plotarray+i+1)->x,(plotarray+i+1)->y);
		drwline(1,10,(plotarray+i+4)->x,(plotarray+i+4)->y,(plotarray+i+4+1)->x,(plotarray+i+4+1)->y);
		drwline(1,10,(plotarray+i)->x,(plotarray+i)->y,(plotarray+i+4)->x,(plotarray+i+4)->y);
	}
	drwline(1,10,(plotarray+3)->x,(plotarray+3)->y,(plotarray+7)->x,(plotarray+7)->y);
	drwline(1,10,(plotarray+0)->x,(plotarray+0)->y,(plotarray+3)->x,(plotarray+3)->y);
	drwline(1,10,(plotarray+4)->x,(plotarray+4)->y,(plotarray+7)->x,(plotarray+7)->y);
	drwline(1,10,(plotarray+3)->x,(plotarray+3)->y,(plotarray+8)->x,(plotarray+8)->y);
	drwline(1,10,(plotarray+8)->x,(plotarray+8)->y,(plotarray+2)->x,(plotarray+2)->y);
	drwline(1,10,(plotarray+9)->x,(plotarray+9)->y,(plotarray+7)->x,(plotarray+7)->y);
	drwline(1,10,(plotarray+9)->x,(plotarray+9)->y,(plotarray+6)->x,(plotarray+6)->y);
	drwline(1,10,(plotarray+8)->x,(plotarray+8)->y,(plotarray+9)->x,(plotarray+9)->y);

	/* Save old points */
	bytecopy(plotarray,oplotarray,14*sizeof(*plotarray));

	return;
}

/************
 * SHOWSTAR *
 ************/

void showstar(D2Point *plotarray, D2Point *oplotarray)
{
	int i;

	for(i=0;i<8;i++)
		drwline(1,0,(oplotarray+i)->x,(oplotarray+i)->y,((oplotarray+i)+1)->x,((oplotarray+i)+1)->y);
	for(i=0;i<8;i++)
		drwline(1,10,(plotarray+i)->x,(plotarray+i)->y,((plotarray+i)+1)->x,((plotarray+i)+1)->y);
	bytecopy(plotarray,oplotarray,9*sizeof(*plotarray));
	return;
}

⌨️ 快捷键说明

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