mirror of
https://github.com/1dot13/source.git
synced 2026-08-05 14:00:23 +02:00
let the text drawing path take a string it will not write to
DrawTextToScreen takes STR16, a mutable wchar_t*, for a string it only
measures and prints. Quest Debug System.cpp picks its text with a conditional:
DrawTextToScreen( gubFact[ usLoop1 ] ? L"True" : L"False", ... );
which has type const wchar_t*. clang-cl's MSVC compatibility lets a bare
string literal decay to wchar_t*, but not a const wchar_t* expression, so it
reports
error: no matching function for call to 'DrawTextToScreen'
note: candidate function not viable: 1st argument ('const wchar_t *')
would lose const qualifier
The parameter is const-correct in every function DrawTextToScreen hands the
string on to, so the change follows the string down the call chain rather
than stopping at the top:
DrawTextToScreen, ShadowText Utils/WordWrap.h
WFStringPixLength Utils/Font Control.h
mprintf, StringPixLength, sgp/Font.h
VarFindFontCenterCoordinates,
VarFindFontRightCoordinates
WinFontStringPixLength sgp/WinFont.h
gprintfdirty TileEngine/Render Dirty.h
The varargs members of that list copy the format string into a local buffer
before doing anything with it, and the measuring ones walk it and return a
width; none of the nine assigns through the parameter. Where StringPixLength
casts the string to UINT16* to walk it, the cast and the local now carry the
const rather than dropping it.
Callers are unaffected: every one already passes something that converts to
const CHAR16*. Both configurations build with no new diagnostics, and the
parse sweep drops from 9 error sites in 7 files to 5 in 3.
To check the claim that nothing writes through these parameters, read the
nine bodies; each is short.
This commit is contained in:
committed by
majcosta
parent
c6a4fdb393
commit
b147e47856
+7
-6
@@ -584,10 +584,11 @@ INT16 StringNPixLength(STR16 string, UINT32 uiMaxCount, INT32 UseFont)
|
||||
// Returns the length of a string in pixels, depending on the font given.
|
||||
//
|
||||
//*****************************************************************************
|
||||
INT16 StringPixLength(const STR16 string, INT32 UseFont)
|
||||
INT16 StringPixLength(const CHAR16* string, INT32 UseFont)
|
||||
{
|
||||
UINT32 Cur;
|
||||
UINT16 *curletter,transletter;
|
||||
const UINT16 *curletter;
|
||||
UINT16 transletter;
|
||||
if ( iUseWinFonts ) {
|
||||
INT32 MapFont;
|
||||
MapFont = WinFontMap[UseFont];
|
||||
@@ -602,7 +603,7 @@ INT16 StringPixLength(const STR16 string, INT32 UseFont)
|
||||
}
|
||||
|
||||
Cur=0;
|
||||
curletter = (UINT16 *)string;
|
||||
curletter = (const UINT16 *)string;
|
||||
|
||||
while((*curletter) != L'\0')
|
||||
{
|
||||
@@ -813,7 +814,7 @@ BOOLEAN SetFontDestBuffer(UINT32 DestBuffer, INT32 x1, INT32 y1, INT32 x2, INT32
|
||||
// the parameters are identical to printf. The resulting string may be no longer
|
||||
// than 512 word-characters. Uses monochrome font color settings
|
||||
//*****************************************************************************
|
||||
UINT32 mprintf(INT32 x, INT32 y, const STR16 pFontString, ...)
|
||||
UINT32 mprintf(INT32 x, INT32 y, const CHAR16* pFontString, ...)
|
||||
{
|
||||
INT32 destx, desty;
|
||||
CHAR16 *curletter, transletter;
|
||||
@@ -864,7 +865,7 @@ UINT8 *pDestBuf;
|
||||
return(0);
|
||||
}
|
||||
|
||||
void VarFindFontRightCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY, const STR16 pFontString, ... )
|
||||
void VarFindFontRightCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY, const CHAR16* pFontString, ... )
|
||||
{
|
||||
CHAR16 string[512];
|
||||
va_list argptr;
|
||||
@@ -876,7 +877,7 @@ void VarFindFontRightCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 s
|
||||
FindFontRightCoordinates( sLeft, sTop, sWidth, sHeight, string, iFontIndex, psNewX, psNewY );
|
||||
}
|
||||
|
||||
void VarFindFontCenterCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY, const STR16 pFontString, ... )
|
||||
void VarFindFontCenterCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY, const CHAR16* pFontString, ... )
|
||||
{
|
||||
CHAR16 string[512];
|
||||
va_list argptr;
|
||||
|
||||
Reference in New Issue
Block a user