2
3
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-14 02:27:40 -04:00

Merged in cwalther/cwe/textrendering (pull request #36)

Shadowed Chat and Player List Text

This implements the (existing but unimplemented) plDynamicTextMap::kFontShadowed flag, making the text of the mini KI (player list and chat) better readable on light and patterned backgrounds.

For best results, an additional Python change is recommended: MOULSCRIPT-ou PR #23.

From H-uru/Plasma#392.
This commit is contained in:
Christian Walther
2015-04-03 23:09:00 +02:00
23 changed files with 453 additions and 107 deletions

View File

@ -56,6 +56,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "../pnMessage/plRefMsg.h"
#include "../pnMessage/plEnableMsg.h"
#include "../pfMessage/pfGameGUIMsg.h"
#include "../plMessage/plDeviceRecreateMsg.h"
#include "../pnSceneObject/plDrawInterface.h"
#include "../pnSceneObject/plCoordinateInterface.h"
#include "../pnSceneObject/plAudioInterface.h"
@ -584,14 +585,16 @@ plProfile_CreateTimer("Gui", "RenderSetup", GUITime);
hsBool pfGUIControlMod::MsgReceive( plMessage *msg )
{
plRenderMsg* rend = plRenderMsg::ConvertNoRef( msg );
plDeviceRecreateMsg* device = plDeviceRecreateMsg::ConvertNoRef(msg);
if (rend || device) {
plPipeline* pipe = rend ? rend->Pipeline() : device->Pipeline();
if( rend )
{
plProfile_BeginLap(GUITime, this->GetKey()->GetUoid().GetObjectName());
// Only need it once
if( ISetUpDynTextMap( rend->Pipeline() ) )
plgDispatch::Dispatch()->UnRegisterForExactType( plRenderMsg::Index(), GetKey() );
ISetUpDynTextMap(pipe);
plProfile_EndLap(GUITime, this->GetKey()->GetUoid().GetObjectName());
if (rend)
plgDispatch::Dispatch()->UnRegisterForExactType(plRenderMsg::Index(), GetKey());
return true;
}
@ -603,12 +606,16 @@ hsBool pfGUIControlMod::MsgReceive( plMessage *msg )
if( refMsg->GetContext() & ( plRefMsg::kOnCreate | plRefMsg::kOnRequest | plRefMsg::kOnReplace ) )
{
fDynTextMap = plDynamicTextMap::ConvertNoRef( refMsg->GetRef() );
// Register for a render msg so we can leech the material when we finally
// have a pipeline to work with
// These tell us when we need to (re-)initialize the DTM
plgDispatch::Dispatch()->RegisterForExactType( plRenderMsg::Index(), GetKey() );
plgDispatch::Dispatch()->RegisterForExactType( plDeviceRecreateMsg::Index(), GetKey() );
}
else
{
fDynTextMap = nil;
plgDispatch::Dispatch()->UnRegisterForExactType( plDeviceRecreateMsg::Index(), GetKey() );
}
return true;
}
else if( refMsg->fType == kRefDynTextLayer )
@ -688,7 +695,7 @@ hsBool pfGUIControlMod::ISetUpDynTextMap( plPipeline *pipe )
extraH -= height;
fDynTextMap->Reset();
fDynTextMap->Create( width, height, HasFlag( kXparentBgnd ), extraW, extraH );
fDynTextMap->Create( width, height, HasFlag( kXparentBgnd ), extraW, extraH, true );
fDynTextMap->SetFont( GetColorScheme()->fFontFace, GetColorScheme()->fFontSize, GetColorScheme()->fFontFlags,
HasFlag( kXparentBgnd ) ? false : true );
@ -699,6 +706,7 @@ hsBool pfGUIControlMod::ISetUpDynTextMap( plPipeline *pipe )
// out with 1:1 mapping from textel to pixel
plLayer *layer = (plLayer *)fDynTextLayer;
layer->SetTransform( fDynTextMap->GetLayerTransform() );
layer->SetBlendFlags( layer->GetBlendFlags() | hsGMatState::kBlendAlphaPremultiplied );
// Let the derived classes do their things
IPostSetUpDynTextMap();

View File

@ -247,6 +247,8 @@ class pfGUIControlMod : public plSingleModifier
virtual void SetColorScheme( pfGUIColorScheme *newScheme );
pfGUIColorScheme *GetColorScheme( void ) const;
virtual void UpdateColorScheme() { IPostSetUpDynTextMap(); IUpdate(); }
// should be override by specific GUIcontrol
virtual void PurgeDynaTextMapImage() {;}

View File

@ -197,9 +197,9 @@ void pfGUIEditBoxMod::IUpdate( void )
oldCursorPos = cursorPos;
cursorPos -= (Int16)fScrollPos;
if( 4 + cursorPos > fDynTextMap->GetVisibleWidth() - 18 )
if( 4 + cursorPos > fDynTextMap->GetVisibleWidth() - 4 - 2 )
{
fScrollPos += ( 4 + cursorPos ) - ( fDynTextMap->GetVisibleWidth() - 18 );
fScrollPos += ( 4 + cursorPos ) - ( fDynTextMap->GetVisibleWidth() - 4 - 2 );
}
else if( 4 + cursorPos < 4 )
{

View File

@ -180,6 +180,10 @@ hsBool pfGUIListBoxMod::MsgReceive( plMessage *msg )
void pfGUIListBoxMod::IPostSetUpDynTextMap( void )
{
pfGUIColorScheme *scheme = GetColorScheme();
fDynTextMap->SetFont( scheme->fFontFace, scheme->fFontSize, scheme->fFontFlags,
!HasFlag( kXparentBgnd ));
ICalcWrapStarts();
ICalcScrollRange();
fReadyToRoll = true;

View File

@ -216,6 +216,8 @@ class pfGUIMultiLineEditCtrl : public pfGUIControlMod
virtual void PurgeDynaTextMapImage();
virtual void UpdateColorScheme() { fFontFlagsSet = 0; pfGUIControlMod::UpdateColorScheme(); }
// Extended event types
enum ExtendedEvents
{

View File

@ -102,8 +102,6 @@ class pfGUITextBoxMod : public pfGUIControlMod
void SetLocalizationPath(const wchar_t* path);
void SetLocalizationPath(const char* path);
void SetUseLocalizationPath(bool use);
virtual void UpdateColorScheme() { IPostSetUpDynTextMap(); IUpdate(); }
};
#endif // _pfGUITextBoxMod_h

View File

@ -491,4 +491,10 @@ void pyDynamicText::AddPlasmaConstantsClasses(PyObject *m)
PYTHON_ENUM_ELEMENT(PtJustify, kLeftJustify, plDynamicTextMap::Justify::kLeftJustify);
PYTHON_ENUM_ELEMENT(PtJustify, kRightJustify, plDynamicTextMap::Justify::kRightJustify);
PYTHON_ENUM_END(m, PtJustify);
PYTHON_ENUM_START(PtFontFlags);
PYTHON_ENUM_ELEMENT(PtFontFlags, kFontBold, plDynamicTextMap::kFontBold);
PYTHON_ENUM_ELEMENT(PtFontFlags, kFontItalic, plDynamicTextMap::kFontItalic);
PYTHON_ENUM_ELEMENT(PtFontFlags, kFontShadowed, plDynamicTextMap::kFontShadowed);
PYTHON_ENUM_END(m, PtFontFlags);
}

View File

@ -278,7 +278,7 @@ PyObject* pyGUIControl::GetOwnerDlg( void )
}
// get color schemes
PyObject* pyGUIControl::GetForeColor()
PyObject* pyGUIControl::GetForeColor() const
{
if ( fGCkey )
{
@ -292,7 +292,7 @@ PyObject* pyGUIControl::GetForeColor()
PYTHON_RETURN_NONE;
}
PyObject* pyGUIControl::GetSelColor()
PyObject* pyGUIControl::GetSelColor() const
{
if ( fGCkey )
{
@ -306,7 +306,7 @@ PyObject* pyGUIControl::GetSelColor()
PYTHON_RETURN_NONE;
}
PyObject* pyGUIControl::GetBackColor()
PyObject* pyGUIControl::GetBackColor() const
{
if ( fGCkey )
{
@ -320,7 +320,7 @@ PyObject* pyGUIControl::GetBackColor()
PYTHON_RETURN_NONE;
}
PyObject* pyGUIControl::GetBackSelColor()
PyObject* pyGUIControl::GetBackSelColor() const
{
if ( fGCkey )
{
@ -334,7 +334,7 @@ PyObject* pyGUIControl::GetBackSelColor()
PYTHON_RETURN_NONE;
}
UInt32 pyGUIControl::GetFontSize()
UInt32 pyGUIControl::GetFontSize() const
{
if ( fGCkey )
{
@ -444,3 +444,34 @@ void pyGUIControl::SetFontSize(UInt32 fontsize)
}
}
}
void pyGUIControl::SetFontFlags(UInt8 fontFlags)
{
if (fGCkey)
{
// get the pointer to the modifier
pfGUIControlMod* pdmod = pfGUIControlMod::ConvertNoRef(fGCkey->ObjectIsLoaded());
if (pdmod)
{
pfGUIColorScheme* colorscheme = pdmod->GetColorScheme();
colorscheme->fFontFlags = fontFlags;
pdmod->UpdateColorScheme();
}
}
}
UInt8 pyGUIControl::GetFontFlags() const
{
if (fGCkey)
{
// get the pointer to the modifier
pfGUIControlMod* pdmod = pfGUIControlMod::ConvertNoRef(fGCkey->ObjectIsLoaded());
if (pdmod)
{
pfGUIColorScheme* colorscheme = pdmod->GetColorScheme();
return colorscheme->fFontFlags;
}
}
return 0;
}

View File

@ -116,17 +116,19 @@ public:
virtual PyObject* GetOwnerDlg( void ); // returns pyGUIDialog
// get color schemes
virtual PyObject* GetForeColor(); // returns pyColor
virtual PyObject* GetSelColor(); // returns pyColor
virtual PyObject* GetBackColor(); // returns pyColor
virtual PyObject* GetBackSelColor(); // returns pyColor
virtual UInt32 GetFontSize();
virtual PyObject* GetForeColor() const; // returns pyColor
virtual PyObject* GetSelColor() const; // returns pyColor
virtual PyObject* GetBackColor() const; // returns pyColor
virtual PyObject* GetBackSelColor() const; // returns pyColor
virtual UInt32 GetFontSize() const;
virtual UInt8 GetFontFlags() const;
// set color scheme
virtual void SetForeColor( hsScalar r, hsScalar g, hsScalar b, hsScalar a );
virtual void SetSelColor( hsScalar r, hsScalar g, hsScalar b, hsScalar a );
virtual void SetBackColor( hsScalar r, hsScalar g, hsScalar b, hsScalar a );
virtual void SetBackSelColor( hsScalar r, hsScalar g, hsScalar b, hsScalar a );
virtual void SetFontSize(UInt32 fontsize);
virtual void SetFontFlags(UInt8 fontflags);
};

View File

@ -244,6 +244,23 @@ PYTHON_METHOD_DEFINITION_NOARGS(ptGUIControl, getFontSize)
return PyLong_FromUnsignedLong(self->fThis->GetFontSize());
}
PYTHON_METHOD_DEFINITION_NOARGS(ptGUIControl, getFontFlags)
{
return PyInt_FromLong(self->fThis->GetFontFlags());
}
PYTHON_METHOD_DEFINITION(ptGUIControl, setFontFlags, args)
{
unsigned char fontflags;
if (!PyArg_ParseTuple(args, "b", &fontflags))
{
PyErr_SetString(PyExc_TypeError, "setFontFlags expects an unsigned 8-bit int");
PYTHON_RETURN_ERROR;
}
self->fThis->SetFontFlags(fontflags);
PYTHON_RETURN_NONE;
}
PYTHON_METHOD_DEFINITION(ptGUIControl, setForeColor, args)
{
float r, g, b, a;
@ -329,11 +346,13 @@ PYTHON_START_METHODS_TABLE(ptGUIControl)
PYTHON_METHOD_NOARGS(ptGUIControl, getBackColor, "Returns the background color"),
PYTHON_METHOD_NOARGS(ptGUIControl, getBackSelectColor, "Returns the background selection color"),
PYTHON_METHOD_NOARGS(ptGUIControl, getFontSize, "Returns the font size"),
PYTHON_METHOD_NOARGS(ptGUIControl, getFontFlags, "Returns the current fontflags"),
PYTHON_METHOD(ptGUIControl, setForeColor, "Params: r,g,b,a\nSets the foreground color"),
PYTHON_METHOD(ptGUIControl, setSelectColor, "Params: r,g,b,a\nSets the selection color"),
PYTHON_METHOD(ptGUIControl, setBackColor, "Params: r,g,b,a\nSets the background color"),
PYTHON_METHOD(ptGUIControl, setBackSelectColor, "Params: r,g,b,a\nSets the selection background color"),
PYTHON_METHOD(ptGUIControl, setFontSize, "Params: fontSize\nSets the font size"),
PYTHON_METHOD(ptGUIControl, setFontFlags, "Params: fontflags\nSets current fontflags"),
PYTHON_END_METHODS_TABLE;
// Type structure definition

View File

@ -214,3 +214,4 @@ UInt8 pyGUIControlTextBox::GetJustify()
}
return pfGUIListText::kLeftJustify;
}

View File

@ -88,6 +88,7 @@ public:
virtual void SetForeColor( pyColor& color );
virtual void SetBackColor( pyColor& color );
virtual void SetJustify( UInt8 justify );
virtual UInt8 GetJustify();
virtual PyObject* GetForeColor(); // returns pyColor
};

View File

@ -185,6 +185,8 @@ PYTHON_METHOD_DEFINITION(ptGUIControlTextBox, setStringJustify, args)
PYTHON_RETURN_NONE;
}
PYTHON_METHOD_DEFINITION_NOARGS(ptGUIControlTextBox, getStringJustify)
{
return PyInt_FromLong(self->fThis->GetJustify());