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

📄 images.cpp

📁 DOS游戏编程中处理Int 13的工具包
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		in al, dx                 // second test, in vbi
		test al,0x8
		jz test_22
		}
	drawloop2:
	asm {
		push cx                  // save the inner loop counter
		push di                  // save the base offset
		mov ax, base_line        // calculate the drawing offset from base
		mul bx
		sub di, ax               // subtract the offset from the base pointer
		push ax                  // save the offset
		xor ax, ax               // clear ax for use in stosw instruction
		mov cx, 160
		rep stosw                // clear the first line
		pop ax                   // restore the offset
		pop di                   // restore the base pointer
		push di                  // save it again
		add di, ax               // add the offset to the base pointer
		xor ax, ax               // clear ax for use in stosw instruction
		mov cx, 160
		rep stosw                // clear the second line
		pop di                   // restore the base pointer
		pop cx                   // restore inner loop counter
		sub di, 6400             // adjust base pointer to 20 lines up screen
		loop drawloop2           // process the next section
		inc base_line            // increment the offset factor
		pop cx                   // restore the outer loop counter
		loop clearscr
		}
	done:                        // finished
	asm pop ds;                  // restore ds value
	}



void  doSparkleDissolve(void far *pic_buf)
	{
	}



// *************************************************************************
// member function definitions for class font, declared in images.hpp
// *************************************************************************

// *************************************************************************
// constructor takes a char * filepath. It opens the fontfile, gets the
// font header into the member structure font_hdr, then allocates memory
// and reads the font data into it. Errors cause the constructor set the
// font status to 0, then return.  The status can be checked via the
// font::getstatus() method.
// *************************************************************************

font::font(char *f_spec)
	{
	int handle;
	int readsize;
	int bytes_read=0;
	char cursor_size;

	if ((handle=open(f_spec,O_RDONLY|O_BINARY))==-1)
		{
		status = FileOpenErr;
		return;
		}
	bytes_read+=(read(handle,&f_hdr,sizeof(f_hdr)));
	bytes_read+=(read(handle,&width[0],sizeof(width)));
	cursor_size=(f_hdr.fram_wid*f_hdr.fram_hit);
	if (((void far *)cursor_mask=malloc(cursor_size)) ==NULL)
		{
		status = MemErr;
		return;
		}
	bytes_read+=(read(handle,(void far*)cursor_mask,cursor_size));
	readsize=(filelength(handle)-bytes_read);
	if (((void far *)font_ptr=malloc(readsize)) ==NULL)
		{
		free(cursor_mask);
		status = MemErr;
		return;
		}
	read(handle,(void far *)font_ptr,readsize);
	close(handle);
	fore_color=0;
	setstyle(0,15,1,opaque,4);
	status=1;
}

// *************************************************************************
// destructor disposes of the memory allocated to the font
// *************************************************************************

font::~font()
	{
	free(font_ptr);
	font_ptr=NULL;
	free(cursor_mask);
	cursor_mask=NULL;
	}

// *************************************************************************
// get_width() returns the proportional width in pixels of char c
// *************************************************************************

char font::get_width(char c)
	{
	if ((c>=f_hdr.ascii_first)&&(c<=f_hdr.ascii_last))
		return(width[c-f_hdr.ascii_first]);
	else
		return(0);
	}

// *************************************************************************
// put_char displays one bitmapped character at the passed x,y location
// *************************************************************************

void font::put_char(int x, int y, char c)
	{
	int j;
	int i;
	unsigned char src,dst;
	char far *p;
	int char_ofs;
	char_ofs=(c-f_hdr.ascii_first)*((f_hdr.fram_wid*f_hdr.fram_hit));
	(void far *)p=MK_FP(FP_SEG(font_ptr),FP_OFF(font_ptr)+char_ofs);
	for(j=0;j<f_hdr.fram_hit;j++)
		{
		for (i=0;i<f_hdr.fram_wid;i++)
			{
			src=p[(j*f_hdr.fram_wid)+i];
			if (src==f_hdr.f_color)
				{
				dst=fore_color;
				writepixel(x+i,y+j,dst);
				}
			else
				{
				if (see_thru==opaque)
					{
					dst=back_color;
					writepixel(x+i,y+j,dst);
					}
				}
			}
		}
	}

// *************************************************************************
// returns the current foreground color setting for text output
// *************************************************************************

int font::getforecolor()
	{
	return(fore_color);
	}

// *************************************************************************
// returns the current background color setting for text output
// *************************************************************************

int font::getbackcolor()
	{
	return(back_color);
	}

// *************************************************************************
// call this function to set the style parameters for text output. f_grnd=
// foreground color, b_grnd=background color, char_tab=pixels between
// characters, opacity={trans,opaque}, when opacity=trans the background
// pixels in the font are ingored, when opacity=opaque the background pixels
// are set to the color value passed in b_grnd, space_wid=width in pixels
// of ascii character 32 (20h), the space character.
// *************************************************************************

void font::setstyle(int f_grnd,int b_grnd,short char_tab,
					opacity o, char space_wid)
	{
	spacing=char_tab;
	see_thru=o;
	fore_color=f_grnd;
	back_color=b_grnd;
	width[32-f_hdr.ascii_first]=space_wid;
	}

// *************************************************************************
// ouput the string pointed to by str at the given x,y coordinate.
// *************************************************************************

void font::show(int x, int y, char *str)
	{
	int i;
	int j;
	for (j=0;str[j]!=0;j++);   // one line gets length of string
	for (i=0;i<j;i++)
		{
		put_char(x,y,str[i]);
		x += get_width(str[i])+spacing;
		}
	}

// *************************************************************************
// read a string from the keyboard, echo to screen at x,y. Reads until it
// encouters a carriage return <ascii 13>, or the string reaches width
// bytes in length, whichever occurs first. Displays a blinking cursor using
// the cursor mask loaded with the font. Backspace enabled.
// *************************************************************************

void font::readstr(int x, int y, char *str, char length, char mask)
	{
	char c='\0';                   // used in call to getfilteredkey()
	extnd scan=NO_EXT;             // ditto
	int cursor_x=x;                // cursor position/next letter position
	int cursor_y=y;                // ditto
	char cur_toggle=0;             // cursor display state
	unsigned int tick;             // last clock reading
	volatile unsigned int *clock=(unsigned int *)MK_FP(0x0040,0x006C);
	int str_len=0;                 // input string length
	int i,j;                       // generic counters

	str[str_len]='\0';
	while((c!=13)&&(str_len<length))
		{
		do
			{
			tick= *clock;
			while ((*clock<(tick+3))&&(!kbhit()));
			cur_toggle = !cur_toggle;
			for(j=0;j<f_hdr.fram_hit;j++)
				{
				for (i=0;i<(f_hdr.fram_wid-1);i++)
					{
					if ((cur_toggle==0)||(cursor_mask[(j*f_hdr.fram_wid+i)]==0))
						writepixel(cursor_x+i,cursor_y+j,back_color);
					else
						writepixel(cursor_x+i,cursor_y+j,fore_color);
					}
				}
			} while ((!kbhit())||(cur_toggle!=0));
		if (getfilteredkey(mask,&c,&scan))
			{
			if ((c!=13)&&(c!=8)&&(c!=9)&&(c!=27))
				{
				str[str_len++]=c;
				str[str_len]='\0';
				put_char(cursor_x,cursor_y,c);
				cursor_x+=(get_width(c)+spacing);
				}
			else
				{
				if ((c==8)&&(str_len!=0))
					{
					cursor_x-=(get_width(str[str_len-1])+spacing);
					str[--str_len]='\0';
					}
				}
			}
		}
	}

// **************************************************************************
// call installed() immediately after initializing an instance of class font.
// if it returns non-zero (true) the installation was successful. 0 indicates
// a file access or memory error during installation.
// **************************************************************************

int font::installed()
	{
	return(status);
	}

// **************************************************************************
// member function definitions for i_stack pointer stack class
//
// these don't have any specific place in a graphics module, except that they
// were going to be used in a window manager, and I was too lazy to make them
// a module to live in.
// **************************************************************************

// **************************************************************************
// constructor clears the pointer stack to NULL
// **************************************************************************

i_stack::i_stack()
	{
	int i;

	ptr_index=0;
	for (i=0;i<20;i++)
		{
		ptr_array[i]=NULL;
		}
	}

// **************************************************************************
// push a pointer on to the stack. Returns 0 if stack full, 1 if success
// **************************************************************************

char i_stack::push_ptr(void far *ptr)
	{
	if (ptr_index!=20)
		{
		ptr_array[ptr_index++]=ptr;
		return(1);
		}
	else
		{
		return(0);
		}
	}

// **************************************************************************
// pop a pointer from the stack. Returns NULL if stack empty.
// **************************************************************************

void far *i_stack::pop_ptr()
	{
	if (ptr_index!=0)
		return(ptr_array[--ptr_index]);
	else
		return(NULL);
	}

// **************************************************************************
// member function definitions for window class
// **************************************************************************

// **************************************************************************
// Constructor creates the window. See WIN.DOC for more information.
// **************************************************************************

win::win(int tlx, int tly, int xwid, int ywid, char far *bmap,
			   char brdrwid, char shdwwid, char bgrnd, char border)
	{
	if (shdwwid==0)
		{
		shdwon=0;
		if ((backgrnd=new char[xwid*ywid])==NULL)
			{
			status = 0;
			return;
			}
		getimage(tlx,tly,tlx+xwid,tly+ywid,backgrnd);
		}
	else
		{
		shdwon=1;
		if ((backgrnd = new char[(xwid+shdwwid)*(ywid+shdwwid)])==NULL)
			{
			status=0;
			return;
			}
		getimage(tlx,tly,tlx+xwid+shdwwid,tly+ywid+shdwwid,backgrnd);
		barfill(tlx+xwid,tly+shdwwid,tlx+xwid+shdwwid,tly+ywid+shdwwid,0);
		barfill(tlx+shdwwid,tly+ywid,tlx+xwid,tly+ywid+shdwwid,0);
		}
	if (bmap==NULL)
		barfill(tlx,tly,tlx+xwid,tly+ywid,bgrnd);
	else
		putimage(tlx,tly,tlx+xwid,tly+ywid,bmap);
	if (brdrwid!=0)
		{
		if (brdrwid>1)
			{
			barfill(tlx,tly,tlx+xwid,tly+brdrwid,border);
			barfill(tlx+(xwid-brdrwid),tly,tlx+xwid,tly+ywid,border);
			barfill(tlx,tly+(ywid-brdrwid),tlx+xwid,tly+ywid,border);
			barfill(tlx,tly,tlx+brdrwid,tly+ywid,border);
			}
		else
			{
			line(tlx,tly,tlx+xwid,tly,border);
			line(tlx+xwid,tly,tlx+xwid,tly+ywid,border);
			line(tlx,tly+ywid,tlx+xwid,tly+ywid,border);
			line(tlx,tly,tlx,tly+ywid,border);
			}
		}
	origX=tlx;
	origY=tly;
	xsize=xwid;
	ysize=ywid;
	bdrwid=brdrwid;
	shdwid=shdwwid;
	b_grnd=bgrnd;
	brdr=border;
	status=1;
	return;
	}

win::~win()
	{
	if (shdwon)
		putimage(origX,origY,origX+xsize+shdwid,origY+ysize+shdwid,backgrnd);
	else
		putimage(origX,origY,origX+xsize,origY+ysize,backgrnd);
	delete(backgrnd);
	return;
	}

// **************************************************************************
// member function defintions for pcx class
// **************************************************************************

// **************************************************************************

⌨️ 快捷键说明

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