From f2dee21063df9e62e73d19b82f593c408f99ca42 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Mon, 19 May 2014 20:57:24 -0400 Subject: [PATCH 1/3] Nuke std::wstring from plDynamicTextMsg --- .../FeatureLib/pfPython/pyDynamicText.cpp | 6 ++-- .../PubUtilLib/plMessage/plDynamicTextMsg.cpp | 33 ++++--------------- .../PubUtilLib/plMessage/plDynamicTextMsg.h | 9 ++--- 3 files changed, 12 insertions(+), 36 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfPython/pyDynamicText.cpp b/Sources/Plasma/FeatureLib/pfPython/pyDynamicText.cpp index 8ca7a801..b0a8328d 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyDynamicText.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyDynamicText.cpp @@ -298,11 +298,11 @@ void pyDynamicText::DrawTextW( int16_t x, int16_t y, std::wstring text ) // 2) clip // 3) just draw if ( fWrap ) - pMsg->DrawWrappedString(x,y,fWrapWidth,fWrapHeight,text.c_str()); + pMsg->DrawWrappedString(x,y,fWrapWidth,fWrapHeight,plString::FromWchar(text.c_str())); else if ( fClip ) - pMsg->DrawClippedString(x,y,fClipLeft,fClipTop,fClipRight,fClipBottom,text.c_str()); + pMsg->DrawClippedString(x,y,fClipLeft,fClipTop,fClipRight,fClipBottom,plString::FromWchar(text.c_str())); else - pMsg->DrawString(x,y,text.c_str()); + pMsg->DrawString(x,y,plString::FromWchar(text.c_str())); plgDispatch::MsgSend( pMsg ); // whoosh... off it goes } diff --git a/Sources/Plasma/PubUtilLib/plMessage/plDynamicTextMsg.cpp b/Sources/Plasma/PubUtilLib/plMessage/plDynamicTextMsg.cpp index de8b22b3..28044cf4 100644 --- a/Sources/Plasma/PubUtilLib/plMessage/plDynamicTextMsg.cpp +++ b/Sources/Plasma/PubUtilLib/plMessage/plDynamicTextMsg.cpp @@ -112,38 +112,24 @@ void plDynamicTextMsg::FrameRect( uint16_t left, uint16_t top, uint16_t right fColor = c; } -void plDynamicTextMsg::DrawString( int16_t x, int16_t y, const char *text ) -{ - wchar_t *wString = hsStringToWString(text); - DrawString(x,y,wString); - delete [] wString; -} - -void plDynamicTextMsg::DrawString( int16_t x, int16_t y, const wchar_t *text ) +void plDynamicTextMsg::DrawString( int16_t x, int16_t y, const plString& text ) { hsAssert( ( fCmd & ( kStringCmds | kPosCmds ) ) == 0, "Attempting to issue conflicting drawText commands" ); fCmd &= ~( kStringCmds | kPosCmds ); fCmd |= kDrawString; - fString = plString::FromWchar(text); + fString = text; fX = x; fY = y; } -void plDynamicTextMsg::DrawClippedString( int16_t x, int16_t y, uint16_t clipLeft, uint16_t clipTop, uint16_t clipRight, uint16_t clipBottom, const char *text ) -{ - wchar_t *wString = hsStringToWString(text); - DrawClippedString(x,y,clipLeft,clipTop,clipRight,clipBottom,wString); - delete [] wString; -} - -void plDynamicTextMsg::DrawClippedString( int16_t x, int16_t y, uint16_t clipLeft, uint16_t clipTop, uint16_t clipRight, uint16_t clipBottom, const wchar_t *text ) +void plDynamicTextMsg::DrawClippedString( int16_t x, int16_t y, uint16_t clipLeft, uint16_t clipTop, uint16_t clipRight, uint16_t clipBottom, const plString& text ) { hsAssert( ( fCmd & ( kStringCmds | kPosCmds | kRectCmds ) ) == 0, "Attempting to issue conflicting drawText commands" ); fCmd &= ~( kStringCmds | kPosCmds | kRectCmds ); fCmd |= kDrawClippedString; - fString = plString::FromWchar(text); + fString = text; fX = x; fY = y; @@ -153,20 +139,13 @@ void plDynamicTextMsg::DrawClippedString( int16_t x, int16_t y, uint16_t clip fBottom = clipBottom; } -void plDynamicTextMsg::DrawWrappedString( int16_t x, int16_t y, uint16_t wrapWidth, uint16_t wrapHeight, const char *text ) -{ - wchar_t *wString = hsStringToWString(text); - DrawWrappedString(x,y,wrapWidth,wrapHeight,wString); - delete [] wString; -} - -void plDynamicTextMsg::DrawWrappedString( int16_t x, int16_t y, uint16_t wrapWidth, uint16_t wrapHeight, const wchar_t *text ) +void plDynamicTextMsg::DrawWrappedString( int16_t x, int16_t y, uint16_t wrapWidth, uint16_t wrapHeight, const plString& text ) { hsAssert( ( fCmd & ( kStringCmds | kPosCmds | kRectCmds ) ) == 0, "Attempting to issue conflicting drawText commands" ); fCmd &= ~( kStringCmds | kPosCmds | kRectCmds ); fCmd |= kDrawWrappedString; - fString = plString::FromWchar(text); + fString = text; fX = x; fY = y; diff --git a/Sources/Plasma/PubUtilLib/plMessage/plDynamicTextMsg.h b/Sources/Plasma/PubUtilLib/plMessage/plDynamicTextMsg.h index 9f800450..77c5de8d 100644 --- a/Sources/Plasma/PubUtilLib/plMessage/plDynamicTextMsg.h +++ b/Sources/Plasma/PubUtilLib/plMessage/plDynamicTextMsg.h @@ -128,12 +128,9 @@ public: void SetLineSpacing( int16_t spacing ); void FillRect( uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, hsColorRGBA &c ); void FrameRect( uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, hsColorRGBA &c ); - void DrawString( int16_t x, int16_t y, const char *text ); - void DrawString( int16_t x, int16_t y, const wchar_t *text ); - void DrawClippedString( int16_t x, int16_t y, uint16_t clipLeft, uint16_t clipTop, uint16_t clipRight, uint16_t clipBottom, const char *text ); - void DrawClippedString( int16_t x, int16_t y, uint16_t clipLeft, uint16_t clipTop, uint16_t clipRight, uint16_t clipBottom, const wchar_t *text ); - void DrawWrappedString( int16_t x, int16_t y, uint16_t wrapWidth, uint16_t wrapHeight, const char *text ); - void DrawWrappedString( int16_t x, int16_t y, uint16_t wrapWidth, uint16_t wrapHeight, const wchar_t *text ); + void DrawString( int16_t x, int16_t y, const plString& text ); + void DrawClippedString( int16_t x, int16_t y, uint16_t clipLeft, uint16_t clipTop, uint16_t clipRight, uint16_t clipBottom, const plString& text ); + void DrawWrappedString( int16_t x, int16_t y, uint16_t wrapWidth, uint16_t wrapHeight, const plString& text ); void DrawImage( int16_t x, int16_t y, plKey &image, bool respectAlpha = false ); void DrawClippedImage( int16_t x, int16_t y, plKey &image, uint16_t clipX, uint16_t clipY, uint16_t clipWidth, uint16_t clipHeight, bool respectAlpha = false ); void SetJustify( uint8_t justifyFlags ); From 305308db90a97b29f9c239c0840a99f69bbdb145 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Mon, 19 May 2014 21:29:43 -0400 Subject: [PATCH 2/3] pyDynamicMap plString-ification We now no longer care if the scripter hands us a string object or a unicode object! Please note that drawTextW was thrown away because it is now redundant. --- .../FeatureLib/pfPython/pyDynamicText.cpp | 31 ++---------- .../FeatureLib/pfPython/pyDynamicText.h | 8 ++- .../FeatureLib/pfPython/pyDynamicTextGlue.cpp | 50 +++---------------- 3 files changed, 13 insertions(+), 76 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfPython/pyDynamicText.cpp b/Sources/Plasma/FeatureLib/pfPython/pyDynamicText.cpp index b0a8328d..1b127aa8 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyDynamicText.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyDynamicText.cpp @@ -266,7 +266,7 @@ void pyDynamicText::UnsetWrapping() // // Draw text paying attention to Clipping and Wrapping if user wanted it // -void pyDynamicText::DrawText( int16_t x, int16_t y, const char *text ) +void pyDynamicText::DrawText( int16_t x, int16_t y, const plString& text ) { // create message plDynamicTextMsg* pMsg = ICreateDTMsg(); @@ -287,27 +287,6 @@ void pyDynamicText::DrawText( int16_t x, int16_t y, const char *text ) } } -void pyDynamicText::DrawTextW( int16_t x, int16_t y, std::wstring text ) -{ - // create message - plDynamicTextMsg* pMsg = ICreateDTMsg(); - if ( pMsg ) - { - // The priority is: - // 1) wrap (if you wrap you probably don't need to clip) - // 2) clip - // 3) just draw - if ( fWrap ) - pMsg->DrawWrappedString(x,y,fWrapWidth,fWrapHeight,plString::FromWchar(text.c_str())); - else if ( fClip ) - pMsg->DrawClippedString(x,y,fClipLeft,fClipTop,fClipRight,fClipBottom,plString::FromWchar(text.c_str())); - else - pMsg->DrawString(x,y,plString::FromWchar(text.c_str())); - - plgDispatch::MsgSend( pMsg ); // whoosh... off it goes - } -} - // // Draw an image on the DynamicMap // @@ -370,7 +349,7 @@ uint16_t pyDynamicText::GetHeight( void ) return (uint16_t)dtMap->GetHeight(); } -void pyDynamicText::CalcTextExtents( std::wstring text, unsigned &width, unsigned &height ) +void pyDynamicText::CalcTextExtents(const plString& text, uint16_t& width, uint16_t& height) { width = 0; height = 0; @@ -379,10 +358,8 @@ void pyDynamicText::CalcTextExtents( std::wstring text, unsigned &width, unsigne return; plDynamicTextMap* dtMap = plDynamicTextMap::ConvertNoRef(fReceivers[0]->ObjectIsLoaded()); - if (!dtMap) - return; - - width = dtMap->CalcStringWidth(text.c_str(), (uint16_t*)&height); + if (dtMap) + width = dtMap->CalcStringWidth(text, &height); } void pyDynamicText::SetJustify(uint8_t justify) diff --git a/Sources/Plasma/FeatureLib/pfPython/pyDynamicText.h b/Sources/Plasma/FeatureLib/pfPython/pyDynamicText.h index cb4a01ea..b1ae1761 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyDynamicText.h +++ b/Sources/Plasma/FeatureLib/pfPython/pyDynamicText.h @@ -54,7 +54,6 @@ class pyImage; #include "pyGlueHelpers.h" #include "pnKeyedObject/plKey.h" -#include #include "hsTemplates.h" class pyDynamicText @@ -119,8 +118,7 @@ public: virtual void UnsetClipping(); virtual void SetWrapping( uint16_t wrapWidth, uint16_t wrapHeight ); virtual void UnsetWrapping(); - virtual void DrawText( int16_t x, int16_t y, const char *text ); - virtual void DrawTextW( int16_t x, int16_t y, std::wstring text ); + virtual void DrawText( int16_t x, int16_t y, const plString& text ); virtual void DrawImage( uint16_t x, uint16_t y, pyImage& image, bool respectAlpha ); virtual void DrawImageClipped( uint16_t x, uint16_t y, pyImage& image, uint16_t cx, uint16_t cy, uint16_t cw, uint16_t ch, bool respectAlpha ); @@ -129,8 +127,8 @@ public: // Actually return the visible width and height, since that's what you want to be drawing to virtual uint16_t GetWidth( void ); virtual uint16_t GetHeight( void ); - virtual void CalcTextExtents( std::wstring text, unsigned &width, unsigned &height ); - + virtual void CalcTextExtents(const plString& text, uint16_t& width, uint16_t& height); + virtual void SetJustify(uint8_t justify); virtual void SetLineSpacing(int16_t spacing); diff --git a/Sources/Plasma/FeatureLib/pfPython/pyDynamicTextGlue.cpp b/Sources/Plasma/FeatureLib/pfPython/pyDynamicTextGlue.cpp index e6e6c4ce..c1f2cc00 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyDynamicTextGlue.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyDynamicTextGlue.cpp @@ -260,8 +260,8 @@ PYTHON_BASIC_METHOD_DEFINITION(ptDynamicMap, unsetWrapping, UnsetWrapping) PYTHON_METHOD_DEFINITION(ptDynamicMap, drawText, args) { short x, y; - char* text; - if (!PyArg_ParseTuple(args, "hhs", &x, &y, &text)) + char* text = nullptr; + if (!PyArg_ParseTuple(args, "hhet", &x, &y, "utf8", &text)) { PyErr_SetString(PyExc_TypeError, "drawText expects two short ints and a string"); PYTHON_RETURN_ERROR; @@ -270,19 +270,6 @@ PYTHON_METHOD_DEFINITION(ptDynamicMap, drawText, args) PYTHON_RETURN_NONE; } -PYTHON_METHOD_DEFINITION(ptDynamicMap, drawTextW, args) -{ - short x, y; - wchar_t* text; - if (!PyArg_ParseTuple(args, "hhu", &x, &y, &text)) - { - PyErr_SetString(PyExc_TypeError, "drawTextW expects two short ints and a unicode string"); - PYTHON_RETURN_ERROR; - } - self->fThis->DrawTextW(x, y, text); - PYTHON_RETURN_NONE; -} - PYTHON_METHOD_DEFINITION(ptDynamicMap, drawImage, args) { short x, y; @@ -336,39 +323,15 @@ PYTHON_METHOD_DEFINITION_NOARGS(ptDynamicMap, getHeight) PYTHON_METHOD_DEFINITION(ptDynamicMap, calcTextExtents, args) { - PyObject* textObj = NULL; - if (!PyArg_ParseTuple(args, "O", &textObj)) - { - PyErr_SetString(PyExc_TypeError, "calcTextExtents expects a string"); - PYTHON_RETURN_ERROR; - } - - std::wstring wText; - if (PyUnicode_Check(textObj)) - { - int strLen = PyUnicode_GetSize(textObj); - wchar_t* text = new wchar_t[strLen + 1]; - PyUnicode_AsWideChar((PyUnicodeObject*)textObj, text, strLen); - text[strLen] = L'\0'; - wText = text; - delete [] text; - } - else if (PyString_Check(textObj)) - { - // we'll allow this, just in case something goes weird - char* text = PyString_AsString(textObj); - wchar_t* temp = hsStringToWString(text); - wText = temp; - delete [] temp; - } - else + char* text = nullptr; + if (!PyArg_ParseTuple(args, "et", "utf8", &text)) { PyErr_SetString(PyExc_TypeError, "calcTextExtents expects a string"); PYTHON_RETURN_ERROR; } - unsigned height, width; - self->fThis->CalcTextExtents(wText, width, height); + uint16_t height, width; + self->fThis->CalcTextExtents(text, width, height); PyObject* retVal = PyTuple_New(2); PyTuple_SetItem(retVal, 0, PyInt_FromLong(width)); PyTuple_SetItem(retVal, 1, PyInt_FromLong(height)); @@ -441,7 +404,6 @@ PYTHON_START_METHODS_TABLE(ptDynamicMap) PYTHON_METHOD(ptDynamicMap, drawText, "Params: x,y,text\nDraw text at a specified location\n" "- x,y is the point to start drawing the text\n" "- 'text' is a string of the text to be drawn"), - PYTHON_METHOD(ptDynamicMap, drawTextW, "Params: x,y,text\nUnicode version of drawText"), PYTHON_METHOD(ptDynamicMap, drawImage, "Params: x,y,image,respectAlphaFlag\nDraws a ptImage object on the dynamicTextmap starting at the location x,y"), PYTHON_METHOD(ptDynamicMap, drawImageClipped, "Params: x,y,image,cx,cy,cw,ch,respectAlphaFlag\nDraws a ptImage object clipped to cx,cy with cw(width),ch(height)"), PYTHON_METHOD_NOARGS(ptDynamicMap, getWidth, "Returns the width of the dynamicTextmap"), From 088cf740a6966f419e67d813e189783f5ff39094 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Mon, 19 May 2014 21:32:21 -0400 Subject: [PATCH 3/3] pyDynamicMap header tweaks... More spurious virtual keywords removed --- .../FeatureLib/pfPython/pyDynamicText.h | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfPython/pyDynamicText.h b/Sources/Plasma/FeatureLib/pfPython/pyDynamicText.h index b1ae1761..008f911a 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyDynamicText.h +++ b/Sources/Plasma/FeatureLib/pfPython/pyDynamicText.h @@ -67,7 +67,7 @@ private: bool fNetForce; // clipping - bool fClip; + bool fClip; uint16_t fClipLeft; uint16_t fClipTop; uint16_t fClipRight; @@ -78,8 +78,8 @@ private: uint16_t fWrapWidth; uint16_t fWrapHeight; - virtual plDynamicTextMsg* ICreateDTMsg(); - virtual void IInit(); + plDynamicTextMsg* ICreateDTMsg(); + void IInit(); protected: pyDynamicText(); @@ -90,8 +90,8 @@ public: // required functions for PyObject interoperability PYTHON_CLASS_NEW_FRIEND(ptDynamicMap); PYTHON_CLASS_NEW_DEFINITION; - static PyObject *New(pyKey& key); - static PyObject *New(plKey key); + static PyObject* New(pyKey& key); + static PyObject* New(plKey key); PYTHON_CLASS_CHECK_DEFINITION; // returns true if the PyObject is a pyDynamicText object PYTHON_CLASS_CONVERT_FROM_DEFINITION(pyDynamicText); // converts a PyObject to a pyDynamicText (throws error if not correct type) @@ -100,39 +100,39 @@ public: // methods that will be exposed to Python // message stuff - virtual void SetSender(pyKey& selfKey); - virtual void ClearReceivers(); - virtual void AddReceiver(pyKey& key); - virtual void SetNetPropagate(bool propagate); - virtual void SetNetForce(bool force); + void SetSender(pyKey& selfKey); + void ClearReceivers(); + void AddReceiver(pyKey& key); + void SetNetPropagate(bool propagate); + void SetNetForce(bool force); // dynamicText commands - virtual void ClearToColor( pyColor& color ); - virtual void Flush( void ); - virtual void SetTextColor( pyColor& color ); - virtual void SetTextColor2( pyColor& color, bool blockRGB ); - virtual void SetFont( const char *facename, int16_t size ); - virtual void FillRect( uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, pyColor& color ); - virtual void FrameRect( uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, pyColor& color ); - virtual void SetClipping( uint16_t clipLeft, uint16_t clipTop, uint16_t clipRight, uint16_t clipBottom); - virtual void UnsetClipping(); - virtual void SetWrapping( uint16_t wrapWidth, uint16_t wrapHeight ); - virtual void UnsetWrapping(); - virtual void DrawText( int16_t x, int16_t y, const plString& text ); - virtual void DrawImage( uint16_t x, uint16_t y, pyImage& image, bool respectAlpha ); - virtual void DrawImageClipped( uint16_t x, uint16_t y, pyImage& image, uint16_t cx, uint16_t cy, uint16_t cw, uint16_t ch, - bool respectAlpha ); - virtual void PurgeImage( void ); + void ClearToColor(pyColor& color ); + void Flush(); + void SetTextColor(pyColor& color ); + void SetTextColor2(pyColor& color, bool blockRGB ); + void SetFont(const char *facename, int16_t size ); + void FillRect(uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, pyColor& color ); + void FrameRect(uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, pyColor& color ); + void SetClipping(uint16_t clipLeft, uint16_t clipTop, uint16_t clipRight, uint16_t clipBottom); + void UnsetClipping(); + void SetWrapping(uint16_t wrapWidth, uint16_t wrapHeight); + void UnsetWrapping(); + void DrawText(int16_t x, int16_t y, const plString& text); + void DrawImage(uint16_t x, uint16_t y, pyImage& image, bool respectAlpha); + void DrawImageClipped(uint16_t x, uint16_t y, pyImage& image, uint16_t cx, uint16_t cy, + uint16_t cw, uint16_t ch, bool respectAlpha); + void PurgeImage(); // Actually return the visible width and height, since that's what you want to be drawing to - virtual uint16_t GetWidth( void ); - virtual uint16_t GetHeight( void ); - virtual void CalcTextExtents(const plString& text, uint16_t& width, uint16_t& height); + uint16_t GetWidth(); + uint16_t GetHeight(); + void CalcTextExtents(const plString& text, uint16_t& width, uint16_t& height); - virtual void SetJustify(uint8_t justify); - virtual void SetLineSpacing(int16_t spacing); + void SetJustify(uint8_t justify); + void SetLineSpacing(int16_t spacing); - virtual plKey GetImage(); + plKey GetImage(); }; #endif // _pyDynamicText_h_