Improvements to text display.

Starfighter uses an absurdly crude method for wrapping text which
basically fails very frequently when large words are chosen. The only
reason it got away with it is because text strings don't vary. Well,
I've been quite annoyed by having to test for this and rework my
text so much, so I've added in a secondary system: if it's really
close to the edge, and the next three characters are going to be
letters, it adds a hyphen and moves on to the next line. This still
isn't 100% fool-proof, but it should catch most problems.

Also removed the "temp fix" which shifted the letters by a pixel in
code, and just shifted them in the actual image. I don't understand
why the "temp fix" was there in the first place, to be honest.
This commit is contained in:
onpon4 2015-06-15 23:56:20 -04:00
parent 049ba0f1db
commit e95f55565c
2 changed files with 36 additions and 7 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 849 B

After

Width:  |  Height:  |  Size: 849 B

View File

@ -17,6 +17,8 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <ctype.h>
#include "Starfighter.h" #include "Starfighter.h"
Star star[200]; Star star[200];
@ -243,27 +245,29 @@ that constantly needs updating (eg - the main game screen)
*/ */
static int renderString(const char *in, int x, int y, int fontColor, signed char wrap, SDL_Surface *dest) static int renderString(const char *in, int x, int y, int fontColor, signed char wrap, SDL_Surface *dest)
{ {
int i;
int splitword;
SDL_Rect area; SDL_Rect area;
SDL_Rect letter;
area.x = x; area.x = x;
area.y = y; area.y = y;
area.w = 8; area.w = 8;
area.h = 14; area.h = 14;
SDL_Rect letter;
letter.y = 0; letter.y = 0;
letter.w = 8; letter.w = 8;
letter.h = 14; letter.h = 14;
while (*in != '\0') while (*in != '\0')
{ {
if (*in != 32) if (*in != ' ')
{ {
letter.x = (*in - 33); letter.x = (*in - 33);
letter.x *= 8; letter.x *= 8;
letter.x--; // Temp fix
/* Blit onto the screen surface */ /* Blit onto the screen surface */
if(SDL_BlitSurface(fontShape[fontColor], &letter, dest, &area) < 0) if (SDL_BlitSurface(fontShape[fontColor], &letter, dest, &area) < 0)
{ {
printf("BlitSurface error: %s\n", SDL_GetError()); printf("BlitSurface error: %s\n", SDL_GetError());
showErrorAndExit(2, ""); showErrorAndExit(2, "");
@ -274,11 +278,36 @@ static int renderString(const char *in, int x, int y, int fontColor, signed char
if (wrap) if (wrap)
{ {
if ((area.x > (dest->w - 70)) && (*in == 32)) if ((area.x > (dest->w - 70)) && (*in == ' '))
{ {
area.y += 16; area.y += 16;
area.x = x; area.x = x;
} }
else if (area.x > (dest->w - 31))
{
splitword = 1;
for (i = 0 ; i < 4 ; i++)
{
if (!isalpha(*(in + i)))
{
splitword = 0;
break;
}
}
if (splitword)
{
letter.x = (int)('-') - 33;
letter.x *= 8;
if (SDL_BlitSurface(fontShape[fontColor], &letter, dest, &area) < 0)
{
printf("BlitSurface error: %s\n", SDL_GetError());
showErrorAndExit(2, "");
}
area.y += 16;
area.x = x;
}
}
} }
in++; in++;