View Single Post
Old 3rd June 2011, 23:27   #21  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
A VERY minor mod to InfoF.h, the Info.h companion for printing
formatted text, no real need to change it but here it is anyway.

These are the lines as they were:

Code:
	const unsigned char *se, *ss;			        // unsigned
	for(ss=(unsigned char*)s; *ss; ss=se) {		        // while, some to do
		int n;
		for(se=ss; n = *se, n>=' ' && n <= 223; ++se);	// Find end+1 of printable
		int len = se - ss;				// Len of printable
		if (len) {					// Some to print
			DrawStringPlanar(dst,x,y,(const char*)ss,len);
And here is the entire mod:
Code:
void  __stdcall DrawFStringPlanar(PVideoFrame &dst,int x,int y,const char *s,bool pix = true)
{ // Draw formatted string at pixel or character coords, pix == false = character coords
	if(pix == false) {x *= 10;	y *= 20;}		// To Chars
	int in_x = x;						// REM x for '\r'
	const unsigned char *se=(unsigned char*)s;	        // unsigned
	while(*se) {						// while, some to do
		int n;
		for(s=(char*)se; n = *se, n>=' ' && n <= 223; ++se);	// Find end+1 of printable
		int len = (char*)se - s;			// Len of printable
		if (len) {					// Some to print
			DrawStringPlanar(dst,x,y,s,len);	// do the biz
			x += len * 10;				// update x coord
		} else {				        // Ctrl code OR nonsense;
			if(n == '\n') {
				x = 0; y+=20;			// Newline, down 1, LHS
			} else if (n == '\r') {
				x = in_x; y +=20;		// Newline Special, Down 1, orig x coord
			} else if(n == '\b') {
				x -= 10;			// Backward Space
			} else if (n == '\f') {
				x += 10;			// Forward Space
			} else if (n == '\t') {
				x+= ((4*10)-(x%(4*10)));	// H-Tab (step 4)
			}
			++se;	// skip ctrl code (and unknowns, outer loop detects nul sentinel)
		}
	}
}

void  __stdcall DrawFStrPlanar(PVideoFrame &dst,int x,int y,const char *s)
{	// Formatted Print @ character coords
	DrawFStringPlanar(dst,x,y,s,false);
}
The mod just saves a bit of swapping about of pointers.
The above code is for the Planar rendering function only,
amend the other 3 also.

EDIT:- shall within minutes of this edit, add (above modified) "InfoF.H"
to the 1st post for those that might want to try the companion header that
allows formatted print at both pixel and character coords via the standard
Info.h, (of course no color control is possible). Just include the
InfoF.h header after Info.h and call the InfoF.h functions when
either character or formatted print is required.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 5th June 2011 at 19:54. Reason: Adding Infoh.h to 1st post.
StainlessS is offline   Reply With Quote