Ugh, it doesn't work at all.

This commit is contained in:
Julie Marchant 2019-06-03 21:05:38 -04:00
parent 1f3f1d46b1
commit 0a522faea6
3 changed files with 59 additions and 10 deletions

View File

@ -30,6 +30,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "SDL.h"
#ifndef NOFONT
#include "SDL_ttf.h"
#endif
#ifndef NOSOUND
#include "SDL_mixer.h"
#endif
@ -403,6 +407,18 @@ void engine_cleanup()
char filename[PATH_MAX];
strcpy(filename, "");
#ifndef NOFONT
if (gfx_unicodeFont != NULL)
{
TTF_CloseFont(gfx_unicodeFont);
gfx_unicodeFont = NULL;
}
if (TTF_WasInit())
{
TTF_Quit();
}
#endif
#ifndef NOSOUND
if (engine.useAudio)
{

View File

@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "SDL.h"
#include "SDL_image.h"
#ifndef NOFONT
#include "SDL_ttf.h"
#include "utf8proc.h"
@ -82,6 +83,12 @@ void gfx_init()
screen = NULL;
#ifndef NOFONT
if (TTF_Init() < 0)
{
printf("ERROR: Could not initialize TTF: %s\n", TTF_GetError());
exit(1);
}
gfx_unicodeFont = TTF_OpenFont("data/DroidSansFallbackFull.ttf", 14);
if (gfx_unicodeFont == NULL)
{
@ -214,6 +221,9 @@ int gfx_renderString(const char *in, int x, int y, int fontColor, int wrap, SDL_
return gfx_renderStringBase(in, x, y, fontColor, wrap, dest);
}
// TODO
#define NOFONT
#ifdef NOFONT
int gfx_renderUnicode(const char *in, int x, int y, int fontColor, int wrap, SDL_Surface *dest)
{
@ -225,6 +235,7 @@ int gfx_renderUnicodeBase(const char *in, int x, int y, int fontColor, int wrap,
SDL_Surface *textSurf;
SDL_Color color;
int w, h;
int changed;
utf8proc_int32_t buf;
utf8proc_int32_t prev;
int breakPoints[STRMAX];
@ -247,7 +258,8 @@ int gfx_renderUnicodeBase(const char *in, int x, int y, int fontColor, int wrap,
engine_error(TTF_GetError());
}
while (w > dest->w)
changed = 1;
while (changed && (w > dest->w))
{
i = 0;
j = 0;
@ -274,9 +286,12 @@ int gfx_renderUnicodeBase(const char *in, int x, int y, int fontColor, int wrap,
prev = buf;
}
changed = 0;
for (i = nBreakPoints - 1; i >= 0; i--)
{
printf("Breakpoint %d (%c)\n", i, remainingStr[breakPoints[i]]);
strncpy(testStr, remainingStr, breakPoints[i]);
printf("Checking '%s'...\n", testStr);
if (TTF_SizeUTF8(gfx_unicodeFont, testStr, &w, &h) < 0)
{
engine_error(TTF_GetError());
@ -296,6 +311,7 @@ int gfx_renderUnicodeBase(const char *in, int x, int y, int fontColor, int wrap,
y += TTF_FontHeight(gfx_unicodeFont);
memmove(remainingStr, remainingStr + breakPoints[i], strlen(remainingStr) - breakPoints[i] + 1);
changed = 1;
break;
}
}
@ -305,6 +321,22 @@ int gfx_renderUnicodeBase(const char *in, int x, int y, int fontColor, int wrap,
engine_error(TTF_GetError());
}
}
printf("Done splitting. Render '%s'\n", remainingStr);
textSurf = TTF_RenderUTF8_Solid(gfx_unicodeFont, remainingStr, color);
area.x = x;
area.y = y;
area.w = textSurf->w;
area.h = textSurf->h;
if (SDL_BlitSurface(textSurf, NULL, dest, &area) < 0)
{
printf("BlitSurface error: %s\n", SDL_GetError());
engine_showError(2, "");
}
y += TTF_FontHeight(gfx_unicodeFont);
}
else
{
engine_warn("gfx_unicodeFont is NULL!");
}
return y;
@ -537,7 +569,7 @@ void gfx_createMessageBox(SDL_Surface *face, const char *message, int transparen
x = 10;
}
gfx_renderString(message, x, 5, FONT_WHITE, 1, gfx_messageBox);
gfx_renderUnicode(message, x, 5, FONT_WHITE, 1, gfx_messageBox);
}
SDL_Surface *gfx_loadImage(const char *filename)
@ -616,14 +648,6 @@ void gfx_free()
SDL_FreeSurface(gfx_messageBox);
gfx_messageBox = NULL;
}
#ifndef NOFONT
if (gfx_unicodeFont != NULL)
{
TTF_CloseFont(gfx_unicodeFont);
gfx_unicodeFont = NULL;
}
#endif
}
void gfx_scaleBackground()

View File

@ -22,6 +22,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "SDL.h"
#ifndef NOFONT
#include "SDL_ttf.h"
#endif
#include "defs.h"
#include "structs.h"
@ -35,10 +39,15 @@ extern SDL_Surface *gfx_shopSprites[SHOP_S_MAX];
extern TextObject gfx_textSprites[TS_MAX];
extern SDL_Surface *gfx_messageBox;
#ifndef NOFONT
extern TTF_Font *gfx_unicodeFont;
#endif
void gfx_init();
SDL_Surface *gfx_setTransparent(SDL_Surface *sprite);
void gfx_blit(SDL_Surface *image, int x, int y, SDL_Surface *dest);
int gfx_renderString(const char *in, int x, int y, int fontColor, int wrap, SDL_Surface *dest);
int gfx_renderUnicode(const char *in, int x, int y, int fontColor, int wrap, SDL_Surface *dest);
void gfx_putPixel(SDL_Surface *surface, int x, int y, Uint32 pixel);
void gfx_drawCircle(int xc, int yc, int R, SDL_Surface *PIX, int col);
void gfx_drawRect(SDL_Surface *dest, int x, int y, int w, int h, Uint8 red, Uint8 green, Uint8 blue);