Jump to content
  • Advertisement
Sign in to follow this  
Thevenin

Working with text.

This topic is 4867 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

lol, I'm really kicking myself over this one. I'm writing a channel display and I cannot get my text to align properly. Here is what it looks like... Image Hosted by ImageShack.us When the server speaks to the client, it sends message (Max 200 char) to the client, which the client has to break into smaller messages that fit in each display row with set amount of characters. eg... A channel is composed of about 100 rows, where each row is drawn individually from all the others. Each row holds flag_FCharacters number of characters.
/* This procedure appends the message on the channel. */
void sDealWithMessage (char lcChannel, struct gtRGB loColor, char *lacMessage)
{
	struct gtChannelRow *laoChannel;
	int liX, liLength, liOffset, liShifter;
	
	/* Get which channel we are appending to. */
	if(lcChannel == flag_ChnDefault)
		laoChannel = gaoChannelDefault;
	else if(lcChannel == flag_ChnGamechat)
		laoChannel = gaoChannelGamechat;
	else if(lcChannel == flag_ChnTradechat)
		laoChannel = gaoChannelTradechat;

	/* Append the message onto the given channel. */
	for(liX=0;liX<100;liX++)
	{
		if(laoChannel[liX].lucUsed == 0)
		{
lblFill:
			/* We need to continously post until all of the message is gone. */
			liLength = strlen(lacMessage);
			liOffset = 0;
			while(liLength > 0)
			{
				/* If its the first line, no padding. */
				if(liOffset == 0)
				{
					laoChannel[liX].lucUsed = 1;
					laoChannel[liX].loColor = loColor;
					for(liShifter = 0; liShifter < 10; liShifter++)
						if(lacMessage[flag_FCharacters - liShifter-1] == ' ' ||
						   lacMessage[flag_FCharacters - liShifter-1] == 0)
							break;
					strncpy(laoChannel[liX].lacMessage, &lacMessage[0], flag_FCharacters - liShifter);
					liLength -= (flag_FCharacters - liShifter);
					liOffset += (flag_FCharacters - liShifter);
					liX++;
				}
				/* If this text took up multiple lines, than pad! */
				else
				{
					strcpy(laoChannel[liX].lacMessage, "     ");
					laoChannel[liX].lucUsed = 1;
					laoChannel[liX].loColor = loColor;
					for(liShifter = 0; liShifter < 10; liShifter++)
						if(lacMessage[liOffset + flag_FCharacters - liShifter-1] == ' ' ||
						   lacMessage[liOffset + flag_FCharacters - liShifter-1] == 0)
							break;
					strncpy(&laoChannel[liX].lacMessage[5], &lacMessage[liOffset], flag_FCharacters - 5 - liShifter);
					liLength -= flag_FCharacters - 5 - liShifter;
					liOffset += flag_FCharacters - 5 - liShifter;
					liX++;
				}
			}
			break;
		}
		if(liX >= 89)
		{
			/* If we are approaching the end, memmove the bottom up. */
			memset(&laoChannel[0], 0, sizeof(struct gtChannelRow) * 10);
			memmove(&laoChannel[0],&laoChannel[10], 89*sizeof(struct gtChannelRow));
			goto lblFill;
		}

	}
}

The problem is that, every line after the second isn't separating the edges properly, as shown in the screenshot. What am I doing wrong? [bawling]

Share this post


Link to post
Share on other sites
Advertisement
Thevein,

After a quick look at your code I suspect the problem is when you're trying to find the 'shifter' for your second and subsequent lines. I believe you scan backwards from (index) flag_FCharacters-1 to flag_FCharacters-10 looking to break the line, however in this case you've already used the first 5 characters (as your padding). This means you only have flag_FCharacters-5 characters for use in the line, therefore start and end your scan in the wrong place.

Cheers,

Tom


// Original
if(lacMessage[liOffset + flag_FCharacters - liShifter-1] == ' ' ||
lacMessage[liOffset + flag_FCharacters - liShifter-1] == 0)

// Adjusted for padding
if(lacMessage[liOffset + (flag_FCharacters-5) - liShifter-1] == ' ' ||
lacMessage[liOffset + (flag_FCharacters-5) - liShifter-1] == 0)


Share this post


Link to post
Share on other sites
I cannot give any advice, but I like the layout of your game! Nice'n'tidy...

Share this post


Link to post
Share on other sites
Quote:
Original post by TomH

After a quick look at your code I suspect the problem is when you're trying to find the 'shifter' for your second and subsequent lines. I believe you scan backwards from (index) flag_FCharacters-1 to flag_FCharacters-10 looking to break the line, however in this case you've already used the first 5 characters (as your padding). This means you only have flag_FCharacters-5 characters for use in the line, therefore start and end your scan in the wrong place.


You solved it! [wow]

Many many thanks: I wish I could give you more ratings than just a mere 8, since you clearly deserve more. [smile]

See you all in a few weeks when I make post asking why my Firefields arn't burning the objects as they are suppose to.. (Just kidding of course)[rolleyes]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!