mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-18 11:19:10 +00:00
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.
This commit is contained in:
@ -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)
|
||||
|
@ -54,7 +54,6 @@ class pyImage;
|
||||
|
||||
#include "pyGlueHelpers.h"
|
||||
#include "pnKeyedObject/plKey.h"
|
||||
#include <string>
|
||||
#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);
|
||||
|
||||
|
@ -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))
|
||||
char* text = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "et", "utf8", &text))
|
||||
{
|
||||
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
|
||||
{
|
||||
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"),
|
||||
|
Reference in New Issue
Block a user