Skip to content

Commit

Permalink
Merge pull request H-uru#1489 from dgelessus/pltextfont_non_ascii
Browse files Browse the repository at this point in the history
Support Unicode in `plTextFont` (avatar tooltips, console, etc.)
  • Loading branch information
Hoikas authored Oct 1, 2023
2 parents 6bc8f55 + 27744db commit e780361
Show file tree
Hide file tree
Showing 36 changed files with 293 additions and 344 deletions.
4 changes: 2 additions & 2 deletions Sources/Plasma/FeatureLib/pfAnimation/plAnimDebugList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void plAnimDebugList::ShowReport()

x = startX;
y = startY;
txt.DrawString(x, y, "Material Animations:", 255, 255, 255, 255, plDebugText::kStyleBold);
txt.DrawString(x, y, ST_LITERAL("Material Animations:"), 255, 255, 255, 255, plDebugText::kStyleBold);
y += yOff;
for (const plKey& matKey : fMaterialKeys)
{
Expand All @@ -141,7 +141,7 @@ void plAnimDebugList::ShowReport()
}
}
y += yOff;
txt.DrawString(x, y, "AGMaster Anims", 255, 255, 255, 255, plDebugText::kStyleBold);
txt.DrawString(x, y, ST_LITERAL("AGMaster Anims"), 255, 255, 255, 255, plDebugText::kStyleBold);
y += yOff;

for (const plKey& soKey : fSOKeys)
Expand Down
14 changes: 7 additions & 7 deletions Sources/Plasma/FeatureLib/pfAudio/plListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ bool plListener::IEval(double secs, float del, uint32_t dirty)

int y = 16 + 12, x = 400;
if( fPrintDbgInfo )
plDebugText::Instance().DrawString( x, 16, "Listener:", (uint32_t)0xffffffff, plDebugText::kStyleBold );
plDebugText::Instance().DrawString(x, 16, ST_LITERAL("Listener:"), (uint32_t)0xffffffff, plDebugText::kStyleBold);

// Get the avatar's SceneObject
plKey key = plNetClientApp::GetInstance()->GetLocalPlayerKey();
Expand All @@ -86,7 +86,7 @@ bool plListener::IEval(double secs, float del, uint32_t dirty)
{
// We don't have a position to init by, so do NOT eval yet!!!
if( fPrintDbgInfo )
plDebugText::Instance().DrawString( x, y, "Not eval-ing yet", (uint32_t)0xffffffff );
plDebugText::Instance().DrawString(x, y, ST_LITERAL("Not eval-ing yet"), (uint32_t)0xffffffff);
return true;
}

Expand Down Expand Up @@ -171,7 +171,7 @@ bool plListener::IEval(double secs, float del, uint32_t dirty)
if( facingType == kInvalid || posType == kInvalid || velType == kInvalid )
{
if( fPrintDbgInfo )
plDebugText::Instance().DrawString( x, y, "Not eval-ing: missing one or more parameter bases", (uint32_t)0xff0000ff );
plDebugText::Instance().DrawString(x, y, ST_LITERAL("Not eval-ing: missing one or more parameter bases"), (uint32_t)0xff0000ff);
return true;
}

Expand All @@ -191,22 +191,22 @@ bool plListener::IEval(double secs, float del, uint32_t dirty)
ST::string str;
str = ST::format("Direction: ({3.2f},{3.2f},{3.2f}) from {}", dir.fX, dir.fY, dir.fZ,
(facingType == kObject) ? pRefObject->GetKeyName() : "VCam");
plDebugText::Instance().DrawString( x, y, str.c_str(), (uint32_t)0xffffffff );
plDebugText::Instance().DrawString(x, y, str, (uint32_t)0xffffffff);
y += 12;

str = ST::format("Up: ({3.2f},{3.2f},{3.2f}) from {}", up.fX, up.fY, up.fZ,
(facingType == kObject) ? pRefObject->GetKeyName() : "VCam");
plDebugText::Instance().DrawString( x, y, str.c_str(), (uint32_t)0xffffffff );
plDebugText::Instance().DrawString(x, y, str, (uint32_t)0xffffffff);
y += 12;

str = ST::format("Position: ({3.2f},{3.2f},{3.2f}) from {}", position.fX, position.fY, position.fZ,
(posType == kObject) ? pRefObject->GetKeyName() : "VCam");
plDebugText::Instance().DrawString( x, y, str.c_str(), (uint32_t)0xffffffff );
plDebugText::Instance().DrawString(x, y, str, (uint32_t)0xffffffff);
y += 12;

str = ST::format("Velocity: ({3.2f},{3.2f},{3.2f}) from {}", velocity.fX, velocity.fY, velocity.fZ,
(velType == kObject) ? pRefObject->GetKeyName() : "VCam");
plDebugText::Instance().DrawString( x, y, str.c_str(), (uint32_t)0xffffffff );
plDebugText::Instance().DrawString(x, y, str, (uint32_t)0xffffffff);
y += 12;
}
plgDispatch::MsgSend( msg );
Expand Down
66 changes: 31 additions & 35 deletions Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,8 +770,6 @@ void pfConsole::IClear()
void pfConsole::Draw( plPipeline *p )
{
int i, yOff, y, x, eOffset, height;
char *line;
char tmp[ kMaxCharsWide ];
bool showTooltip = false;
float thisTime; // For making the console FX speed konstant regardless of framerate
const float kEffectDuration = 0.5f;
Expand All @@ -786,7 +784,7 @@ void pfConsole::Draw( plPipeline *p )
if( fMsgTimeoutTimer > 0 )
{
/// Message hint--draw the last line of the console for a bit
drawText.DrawString( 10, 4, fDisplayBuffer + kMaxCharsWide * ( fNumDisplayLines - 1 ), fConsoleTextColor );
drawText.DrawString(10, 4, ST::string::from_latin_1(fDisplayBuffer + kMaxCharsWide * (fNumDisplayLines - 1)), fConsoleTextColor);
fMsgTimeoutTimer--;
}
fLastTime = thisTime;
Expand Down Expand Up @@ -827,28 +825,28 @@ void pfConsole::Draw( plPipeline *p )
if( fMode == kModeSingleLine )
{
// Bgnd (TEMP ONLY)
x = kMaxCharsWide * drawText.CalcStringWidth( "W" ) + 4;
x = kMaxCharsWide * drawText.CalcStringWidth(ST_LITERAL("W")) + 4;
y = height - eOffset;
drawText.DrawRect( 4, 0, x, y, /*color*/0, 0, 0, 127 );

/// Actual text
if( fEffectCounter == 0 )
drawText.DrawString( 10, 4, "Plasma 2.0 Console", 255, 255, 255, 255 );
drawText.DrawString(10, 4, ST_LITERAL("Plasma 2.0 Console"), 255, 255, 255, 255);

if( !showTooltip )
drawText.DrawString( 10, 4 + yOff - eOffset, fDisplayBuffer + kMaxCharsWide * ( fNumDisplayLines - 1 ), fConsoleTextColor );
drawText.DrawString(10, 4 + yOff - eOffset, ST::string::from_latin_1(fDisplayBuffer + kMaxCharsWide * (fNumDisplayLines - 1)), fConsoleTextColor);

y = 4 + yOff + yOff - eOffset;
}
else
{
// Bgnd (TEMP ONLY)
x = kMaxCharsWide * drawText.CalcStringWidth( "W" ) + 4;
x = kMaxCharsWide * drawText.CalcStringWidth(ST_LITERAL("W")) + 4;
y = yOff * ( fNumDisplayLines + 2 ) + 14 - eOffset;
drawText.DrawRect( 4, 0, x, y, /*color*/0, 0, 0, 127 );

/// Actual text
drawText.DrawString( 10, 4, "Plasma 2.0 Console", 255, 255, 255, 255 );
drawText.DrawString(10, 4, ST_LITERAL("Plasma 2.0 Console"), 255, 255, 255, 255);

static int countDown = 3000;
if( fHelpTimer > 0 || fEffectCounter > 0 || fMode != kModeFull )
Expand All @@ -861,7 +859,6 @@ void pfConsole::Draw( plPipeline *p )
static char tmpSrc[ kMaxCharsWide ];
if( !rezLoaded )
{
memset( tmp, 0, sizeof( tmp ) );
memset( tmpSrc, 0, sizeof( tmpSrc ) );
// Our concession to windows
#ifdef HS_BUILD_FOR_WIN32
Expand All @@ -886,23 +883,23 @@ void pfConsole::Draw( plPipeline *p )
// Need to define for other platforms?
#endif
}
memcpy( tmp, tmpSrc, sizeof( tmp ) );

if( countDown <= 0 )
{
y = 4 + yOff - eOffset;
if( countDown <= -480 )
{
tmp[ ( (-countDown - 480)>> 4 ) + 1 ] = 0;
ST::string tmp = ST::string::from_latin_1(tmpSrc).left(((-countDown - 480) >> 4) + 1);
drawText.DrawString( 10, y, tmp, fConsoleTextColor );
}
y += yOff * ( fNumDisplayLines - ( showTooltip ? 1 : 0 ) );
}
else
{
for( i = 0, y = 4 + yOff - eOffset, line = fDisplayBuffer; i < fNumDisplayLines - ( showTooltip ? 1 : 0 ); i++ )
{
drawText.DrawString( 10, y, line, fConsoleTextColor );
y = 4 + yOff - eOffset;
const char* line = fDisplayBuffer;
for (i = 0; i < fNumDisplayLines - (showTooltip ? 1 : 0); i++) {
drawText.DrawString(10, y, ST::string::from_latin_1(line), fConsoleTextColor);
y += yOff;
line += kMaxCharsWide;
}
Expand All @@ -912,38 +909,37 @@ void pfConsole::Draw( plPipeline *p )
y += yOff;
}

// strcpy( tmp, fHelpMode ? "Get Help On:" : "]" );
if ( fHelpMode )
strcpy( tmp, "Get Help On:");
else if (fPythonMode )
if ( fPythonMultiLines == 0 )
strcpy( tmp, ">>>");
else
strcpy( tmp, "...");
else
strcpy( tmp, "]" );
ST::string prompt;
if (fHelpMode) {
prompt = ST_LITERAL("Get Help On:");
} else if (fPythonMode) {
if (fPythonMultiLines == 0) {
prompt = ST_LITERAL(">>>");
} else {
prompt = ST_LITERAL("...");
}
} else {
prompt = ST_LITERAL("]");
}

drawText.DrawString( 10, y, tmp, 255, 255, 255, 255 );
i = 19 + drawText.CalcStringWidth( tmp );
drawText.DrawString( i, y, fWorkingLine, fConsoleTextColor );
drawText.DrawString(10, y, prompt, 255, 255, 255, 255);
i = 19 + drawText.CalcStringWidth(prompt);
drawText.DrawString(i, y, IGetWorkingLine(), fConsoleTextColor);

if( fCursorTicks >= 0 )
{
strcpy( tmp, fWorkingLine );
tmp[ fWorkingCursor ] = 0;
x = drawText.CalcStringWidth( tmp );
drawText.DrawString( i + x, y + 2, "_", 255, 255, 255 );
ST::string lineUpToCursor = ST::string::from_latin_1(fWorkingLine, fWorkingCursor);
x = drawText.CalcStringWidth(lineUpToCursor);
drawText.DrawString(i + x, y + 2, ST_LITERAL("_"), 255, 255, 255);
}
fCursorTicks--;
if( fCursorTicks < -kCursorBlinkRate )
fCursorTicks = kCursorBlinkRate;

if (showTooltip) {
ST::char_buffer helpMsgBuf = fLastHelpMsg.to_latin_1();
if (helpMsgBuf.size() > kMaxCharsWide - 2) {
helpMsgBuf[kMaxCharsWide - 2] = 0;
}
drawText.DrawString(i, y - yOff, helpMsgBuf.c_str(), 255, 255, 0);
ST::string helpMsg = ST::string::from_latin_1(helpMsgBuf.data(), std::min(helpMsgBuf.size(), static_cast<size_t>(kMaxCharsWide - 2)));
drawText.DrawString(i, y - yOff, helpMsg, 255, 255, 0);
} else {
fHelpTimer--;
}
Expand Down
3 changes: 1 addition & 2 deletions Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1247,8 +1247,7 @@ PF_CONSOLE_CMD( Graphics_DebugText, // Group name
"string face, int size", // Params
"Sets the font face and size used for drawing debug text" ) // Help string
{
const ST::string& face = params[0];
plDebugText::Instance().SetFont(face.c_str(), (uint16_t)(int)params[1]);
plDebugText::Instance().SetFont(params[0], (uint16_t)(int)params[1]);
}

PF_CONSOLE_CMD( Graphics_DebugText, // Group name
Expand Down
21 changes: 8 additions & 13 deletions Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ You can contact Cyan Worlds, Inc. by email [email protected]

#include <algorithm>
#include <string_theory/string>
#include <utility>

//#define MF_TOSSER

Expand Down Expand Up @@ -2280,15 +2281,15 @@ void plDXPipeline::Resize( uint32_t width, uint32_t height )

//// MakeTextFont /////////////////////////////////////////////////////////////

plTextFont *plDXPipeline::MakeTextFont( char *face, uint16_t size )
plTextFont* plDXPipeline::MakeTextFont(ST::string face, uint16_t size)
{
plTextFont *font;


font = new plDXTextFont( this, fD3DDevice );
if (font == nullptr)
return nullptr;
font->Create( face, size );
font->Create(std::move(face), size);
font->Link( &fTextFontRefList );

return font;
Expand Down Expand Up @@ -9811,9 +9812,8 @@ void plDXPlateManager::IDrawToDevice( plPipeline *pipe )
{
dxPipe->IDrawPlate( plate );

const char *title = plate->GetTitle();
if( plDebugText::Instance().IsEnabled() && title[ 0 ] != 0 )
{
ST::string title = plate->GetTitle();
if (plDebugText::Instance().IsEnabled() && !title.empty()) {
hsPoint3 pt;
pt.Set( 0, -0.5, 0 );
pt = plate->GetTransform() * pt;
Expand All @@ -9829,26 +9829,21 @@ void plDXPlateManager::IDrawToDevice( plPipeline *pipe )
hsPoint3 pt, pt2;
int i;

if( graph->GetLabelText( 0 )[ 0 ] != 0 )
{
uint32_t numLabels = graph->GetNumLabels();
if (numLabels > 0) {
/// Draw key
const char *str;

pt.Set( -0.5, -0.5, 0 );
pt = plate->GetTransform() * pt;
pt.fX = pt.fX * scrnWidthDiv2 + scrnWidthDiv2;
pt.fY = pt.fY * scrnHeightDiv2 + scrnHeightDiv2;
pt.fY += plDebugText::Instance().GetFontHeight();

uint32_t numLabels = graph->GetNumLabels();
if (numLabels > graph->GetNumColors())
numLabels = graph->GetNumColors();

for( i = 0; i < numLabels; i++ )
{
str = graph->GetLabelText( i );
if( str[ 0 ] == 0 )
break;
ST::string str = graph->GetLabelText(i);

pt2 = pt;
pt2.fX -= plDebugText::Instance().CalcStringWidth( str );
Expand Down
2 changes: 1 addition & 1 deletion Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ class plDXPipeline : public pl3DPipeline<plDXDevice>
void LoadResources() override; // Tells us where it's a good time to load in unmanaged resources.

// Create a debug text font object
plTextFont *MakeTextFont(char *face, uint16_t size) override;
plTextFont* MakeTextFont(ST::string face, uint16_t size) override;

// Create and/or Refresh geometry buffers
void CheckVertexBufferRef(plGBufferGroup* owner, uint32_t idx) override;
Expand Down
4 changes: 3 additions & 1 deletion Sources/Plasma/FeatureLib/pfGLPipeline/plGLPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#include "HeadSpin.h"
#include "hsWindows.h"

#include <string_theory/string>

#include "plPipeline/hsWinRef.h"

#include "plGLPipeline.h"
Expand Down Expand Up @@ -79,7 +81,7 @@ bool plGLPipeline::PrepForRender(plDrawable* drawable, std::vector<int16_t>& vis
void plGLPipeline::Render(plDrawable* d, const std::vector<int16_t>& visList)
{}

plTextFont* plGLPipeline::MakeTextFont(char* face, uint16_t size)
plTextFont* plGLPipeline::MakeTextFont(ST::string face, uint16_t size)
{
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Plasma/FeatureLib/pfGLPipeline/plGLPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class plGLPipeline : public pl3DPipeline<plGLDevice>
bool PreRender(plDrawable* drawable, std::vector<int16_t>& visList, plVisMgr* visMgr=nullptr) override;
bool PrepForRender(plDrawable* drawable, std::vector<int16_t>& visList, plVisMgr* visMgr=nullptr) override;
void Render(plDrawable* d, const std::vector<int16_t>& visList) override;
plTextFont* MakeTextFont(char* face, uint16_t size) override;
plTextFont* MakeTextFont(ST::string face, uint16_t size) override;
void CheckVertexBufferRef(plGBufferGroup* owner, uint32_t idx) override;
void CheckIndexBufferRef(plGBufferGroup* owner, uint32_t idx) override;
bool OpenAccess(plAccessSpan& dst, plDrawableSpans* d, const plVertexSpan* span, bool readOnly) override;
Expand Down
6 changes: 2 additions & 4 deletions Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIDialogMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,7 @@ static bool showBounds = false;
float x = sW * ctrl->fBoundsPoints[j].fX;
float y = sH * ctrl->fBoundsPoints[j].fY;
plDebugText::Instance().DrawRect( (uint16_t)(x - 2), (uint16_t)(y - 2), (uint16_t)(x + 2), (uint16_t)(y + 2), color );
char str[24];
snprintf(str, std::size(str), "%zu", j);
plDebugText::Instance().DrawString( (uint16_t)(x + 8), (uint16_t)(y - 8), str, color );
plDebugText::Instance().DrawString((uint16_t)(x + 8), (uint16_t)(y - 8), ST::string::from_uint(j), color);
}
}
else
Expand Down Expand Up @@ -484,7 +482,7 @@ static bool showBounds = false;
{
const hsBounds3 &bnds = fMousedCtrl->GetBounds();
plDebugText::Instance().DrawString((uint16_t)(bnds.GetMins().fX), (uint16_t)(bnds.GetMins().fY),
fMousedCtrl->GetKeyName().c_str(), (uint32_t)0xffffff00);
fMousedCtrl->GetKeyName(), (uint32_t)0xffffff00);
}
#endif

Expand Down
3 changes: 2 additions & 1 deletion Sources/Plasma/NucleusLib/inc/plPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class plVisMgr;

class plViewTransform;

namespace ST { class string; }

struct PipelineParams
{
Expand Down Expand Up @@ -169,7 +170,7 @@ class plPipeline : public plCreatable
virtual void Draw(plDrawable* d) = 0;

// Device-specific ref creation. Includes buffers and fonts
virtual plTextFont *MakeTextFont( char *face, uint16_t size ) = 0;
virtual plTextFont* MakeTextFont(ST::string face, uint16_t size) = 0;

// Create and/or Refresh geometry buffers
virtual void CheckVertexBufferRef(plGBufferGroup* owner, uint32_t idx) = 0;
Expand Down
4 changes: 2 additions & 2 deletions Sources/Plasma/PubUtilLib/plAudio/plSound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ void plSound::IUpdateDebugPlate()
fDebugPlate->SetPosition( -0.5, 0 );
fDebugPlate->SetDataRange( 0, 100, 100 );
fDebugPlate->SetColors( 0x80202000 );
fDebugPlate->SetLabelText( "Desired", "Curr", "Soft", "Dist" );
fDebugPlate->SetLabelText({ST_LITERAL("Desired"), ST_LITERAL("Curr"), ST_LITERAL("Soft"), ST_LITERAL("Dist")});
}

fDebugPlate->SetTitle(GetKeyName().c_str()); // Bleah
fDebugPlate->SetTitle(GetKeyName()); // Bleah
fDebugPlate->SetVisible( true );
fDebugPlate->AddData( (int32_t)( fDesiredVol * 100.f ),
(int32_t)( fCurrVolume * 100.f ),
Expand Down
Loading

0 comments on commit e780361

Please sign in to comment.