🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.os.msdos.programmer
1 messages
1 total messages Started by Steve Resnick Wed, 08 Aug 1990 00:32
gcgets - Turbo C fun. to read strings in grafix
#1810
Author: Steve Resnick
Date: Wed, 08 Aug 1990 00:32
91 lines
2888 bytes
For those of you who requested my post of gcgets, here it is!
Bear in mind this was written for a specific application and there
are some short-comings to it, but the general idea is expressed.

   -------<Cut Here>---------------------------------<Cut Here>--------------
/* gcgets (C) Copyright 1990 Steve Resnick
*/
gcgets(int Xstart, int Ystart, char * buffer, int size)
{
	char *tmp, *start;
	char CurBuf[512];
	int i, c, x, y, Hue, curx, cury;
	x = Xstart; y = Ystart;
	curx = x; cury = y+(textheight("[")-2);
	if ((tmp = calloc(size,1)) == NULL)
	{
		restorecrtmode();
		perror("Cannot allocate memory for console I/O!");
		exit(0);
	}
	start = tmp;
	for ( i = 0; i < (size - 1); )
	{
		Hue = getcolor();
		setcolor(8);
		getimage(curx,cury,curx+10,cury,CurBuf);
		line(curx,cury,curx+10,cury);
		c = getch();
		putimage(curx,cury,CurBuf,COPY_PUT);
		setcolor(Hue);
		switch(c)
		{
			case 0 :
				getch();
				break ;
			case 27:
				*buffer = 0;
				free(start);
				return(0);
			case 13:
				strncpy(buffer,start,size);
				free(start);
				return(strlen(buffer));
			case  8:
				if ((tmp - 1) >= start)
				{
					x-=8;
					setcolor(CYAN);
					gprintf(x,y,"[");
					setcolor(15);
					i-- ;
					*tmp-- = 0;
					*tmp = 0;
				}
				else
				{
					sound(2500);
					delay(10);
					nosound();
				}
				break ;
			default :		
				gprintf(x,y,"%c",c);
				x+=8;
				*tmp++ = c;
				i ++ ;
		}
		curx =  Xstart + textwidth(start);
	}
	strncpy(buffer,start,size);
	free(start);
	return(strlen(buffer));
}
/* This was taken and hacked from the BGIDEMO program */
int gprintf( int xloc, int yloc, char *fmt, ... )
{
  va_list  argptr;			/* Argument list pointer	*/
  char str[140];			/* Buffer to build sting into	*/
  int cnt;				/* Result of SPRINTF for return */
  va_start( argptr, format );		/* Initialize va_ functions	*/
  cnt = vsprintf( str, fmt, argptr );	/* prints string to buffer	*/
  outtextxy( xloc, yloc, str );		/* Send string in graphics mode */
  va_end( argptr );			/* Close va_ functions		*/
  return( cnt );			/* Return the conversion count	*/
}

-- 
----------------------------------------------------------------------------
steve.resnick@f105.n143.z1@FIDONET.ORG #include<std_disclaimer.h>
Flames, grammar errors, spelling errrors >/dev/nul
----------------------------------------------------------------------------
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads