Skip to content

Commit 7f1063f

Browse files
committed
Use UTF-8 for all SDL string parameters
1 parent 18b305a commit 7f1063f

4 files changed

Lines changed: 29 additions & 9 deletions

File tree

kauai/src/appbsdl.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ bool APPB::_FInitOS(void)
7676
// TODO: replace starting position with SDL_WINDOWPOS_UNDEFINED
7777
// TODO: set starting size properly
7878

79-
SDL_Window *wnd = SDL_CreateWindow(stnApp.Psz(), 64, 64, 640, 480, 0);
79+
U8SZ u8szApp;
80+
stnApp.GetUtf8Sz(u8szApp);
81+
SDL_Window *wnd = SDL_CreateWindow(u8szApp, 64, 64, 640, 480, 0);
8082
Assert(wnd != pvNil, "no window returned from SDL_CreateWindow");
8183
if (wnd == pvNil)
8284
{
@@ -506,6 +508,9 @@ bool APPB::FAssertProcApp(PSZS pszsFile, int32_t lwLine, PSZS pszsMsg, void *pv,
506508
stn0.FAppendSz(PszLit("\n"));
507509
stn0.FAppendStn(&stn2);
508510

511+
U8SZ u8szMessage;
512+
stn0.GetUtf8Sz(u8szMessage);
513+
509514
SDL_MessageBoxButtonData rgbutton[3];
510515
FillPb(rgbutton, SIZEOF(rgbutton), 0);
511516

@@ -519,7 +524,7 @@ bool APPB::FAssertProcApp(PSZS pszsFile, int32_t lwLine, PSZS pszsMsg, void *pv,
519524
SDL_MessageBoxData data = {0};
520525
data.buttons = rgbutton;
521526
data.numbuttons = 3;
522-
data.message = stn0.Psz(); // TODO: UTF-8
527+
data.message = u8szMessage;
523528
data.flags = SDL_MessageBoxFlags::SDL_MESSAGEBOX_ERROR;
524529
data.title = "Assertion Failure";
525530

@@ -608,11 +613,17 @@ tribool APPB::TGiveAlertSz(const PCSZ psz, int32_t bk, int32_t cok)
608613
break;
609614
}
610615

616+
// Convert message to UTF-8
617+
U8SZ u8szMessage;
618+
STN stnMessage;
619+
stnMessage.SetSz(psz);
620+
stnMessage.GetUtf8Sz(u8szMessage);
621+
611622
SDL_MessageBoxData data;
612623
ClearPb(&data, sizeof(data));
613624
data.buttons = rgbutton;
614625
data.numbuttons = ibutton;
615-
data.message = psz; // TODO: UTF-8
626+
data.message = u8szMessage;
616627
data.flags = SDL_MessageBoxFlags::SDL_MESSAGEBOX_ERROR;
617628
data.title = "3D Movie Maker";
618629

kauai/src/fontsdl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,10 @@ SDL_RWops *SDLFontFile::GetFontRWops()
319319
{
320320
STN stnFontPath;
321321
_fniFont.GetStnPath(&stnFontPath);
322+
U8SZ u8szFontPath;
323+
stnFontPath.GetUtf8Sz(u8szFontPath);
322324

323-
SDL_RWops *rwops = SDL_RWFromFile(stnFontPath.Psz(), "rb");
325+
SDL_RWops *rwops = SDL_RWFromFile(u8szFontPath, "rb");
324326
Assert(rwops != pvNil, "Opening file failed!");
325327
return rwops;
326328
}

kauai/src/gfxsdl.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ void GPT::UpdateTexture()
239239

240240
void GPT::DumpBitmap(STN *stnBmp)
241241
{
242-
AssertDoSDL(SDL_SaveBMP(_surface, stnBmp->Psz()));
242+
U8SZ u8szFilePath;
243+
stnBmp->GetUtf8Sz(u8szFilePath);
244+
AssertDoSDL(SDL_SaveBMP(_surface, u8szFilePath));
243245
}
244246

245247
/***************************************************************************
@@ -588,8 +590,9 @@ void GPT::DrawRgch(const achar *prgch, int32_t cch, PTS pts, GDD *pgdd, DSF *pds
588590
stnText.SetRgch(prgch, cch);
589591

590592
// Draw text
591-
// TODO: Convert string from CP1252 to a character set supported by SDL_TTF
592-
surRendered = TTF_RenderText_Solid(ttfFont, stnText.Psz(), sdlcFore);
593+
U8SZ u8szText;
594+
stnText.GetUtf8Sz(u8szText);
595+
surRendered = TTF_RenderUTF8_Solid(ttfFont, u8szText, sdlcFore);
593596
Assert(surRendered != pvNil, "TTF_RenderText failed");
594597

595598
if (surRendered != pvNil)
@@ -639,7 +642,9 @@ void GPT::GetRcsFromRgch(RCS *prcs, const achar *prgch, int32_t cch, PTS pts, DS
639642

640643
// Get bounding box of text with current font
641644
stnText.SetRgch(prgch, cch);
642-
TTF_SizeText(ttfFont, stnText.Psz(), &dxpText, &dypText);
645+
U8SZ u8szText;
646+
stnText.GetUtf8Sz(u8szText);
647+
AssertDoSDL(TTF_SizeUTF8(ttfFont, u8szText, &dxpText, &dypText));
643648

644649
tmAscent = TTF_FontAscent(ttfFont);
645650
tmHeight = TTF_FontHeight(ttfFont);

kauai/src/gobsdl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ void GOB::SetHwndName(PSTN pstn)
170170
RawRtn();
171171
}
172172

173-
SDL_SetWindowTitle((SDL_Window *)_hwnd, pstn->Psz());
173+
U8SZ u8szTitle;
174+
pstn->GetUtf8Sz(u8szTitle);
175+
SDL_SetWindowTitle((SDL_Window *)_hwnd, u8szTitle);
174176
}
175177

176178
/***************************************************************************

0 commit comments

Comments
 (0)