From db5e451622713b94bb40e32951686e5bf2321ebd Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Thu, 4 Jul 2013 18:14:58 -0400 Subject: [PATCH 01/14] Fix #303 --- .../pfGameGUIMgr/pfGUIControlMod.cpp | 21 ++++++++++++------- .../plMessage/plDeviceRecreateMsg.h | 13 +++++++++++- .../PubUtilLib/plPipeline/plDXPipeline.cpp | 6 +++--- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp index 0f539c32..6742891f 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp @@ -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 ) diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plMessage/plDeviceRecreateMsg.h b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plMessage/plDeviceRecreateMsg.h index a83c0263..a97fa530 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plMessage/plDeviceRecreateMsg.h +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plMessage/plDeviceRecreateMsg.h @@ -51,15 +51,26 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "../pnMessage/plMessage.h" +class plPipeline; + class plDeviceRecreateMsg : public plMessage { + plPipeline* fPipe; + public: - plDeviceRecreateMsg() : plMessage( nil, nil, nil ) { SetBCastFlag( kBCastByExactType ); } + plDeviceRecreateMsg(plPipeline* pipe=nil) + : plMessage(nil, nil, nil), fPipe(pipe) + { + SetBCastFlag(kBCastByExactType); + } + ~plDeviceRecreateMsg() {} CLASSNAME_REGISTER( plDeviceRecreateMsg ); GETINTERFACE_ANY( plDeviceRecreateMsg, plMessage ); + plPipeline* Pipeline() const { return fPipe; } + // IO void Read(hsStream* stream, hsResMgr* mgr) { plMessage::IMsgRead( stream, mgr ); } void Write(hsStream* stream, hsResMgr* mgr) { plMessage::IMsgWrite( stream, mgr ); } diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plPipeline/plDXPipeline.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plPipeline/plDXPipeline.cpp index d7ed9043..684bea34 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plPipeline/plDXPipeline.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plPipeline/plDXPipeline.cpp @@ -2278,7 +2278,7 @@ hsBool plDXPipeline::IResetDevice() /// Broadcast a message letting everyone know that we were recreated and that /// all device-specific stuff needs to be recreated - plDeviceRecreateMsg* clean = TRACKED_NEW plDeviceRecreateMsg(); + plDeviceRecreateMsg* clean = TRACKED_NEW plDeviceRecreateMsg(this); plgDispatch::MsgSend(clean); } fDevWasLost = true; @@ -2552,7 +2552,7 @@ void plDXPipeline::Resize( UInt32 width, UInt32 height ) /// Broadcast a message letting everyone know that we were recreated and that /// all device-specific stuff needs to be recreated - plDeviceRecreateMsg* clean = TRACKED_NEW plDeviceRecreateMsg(); + plDeviceRecreateMsg* clean = TRACKED_NEW plDeviceRecreateMsg(this); plgDispatch::MsgSend(clean); } @@ -3834,7 +3834,7 @@ hsBool plDXPipeline::BeginRender() { /// Broadcast a message letting everyone know that we were recreated and that /// all device-specific stuff needs to be recreated -// plDeviceRecreateMsg* clean = TRACKED_NEW plDeviceRecreateMsg(); +// plDeviceRecreateMsg* clean = TRACKED_NEW plDeviceRecreateMsg(this); // plgDispatch::MsgSend(clean); fDevWasLost = false; From 1f0277e3e0b845aa92d2a26844107a6a0e05fab5 Mon Sep 17 00:00:00 2001 From: Christian Walther Date: Thu, 3 Apr 2014 22:17:45 +0200 Subject: [PATCH 02/14] Pixel-accurately clip characters to the available space instead of omitting whole characters that stick out. In addition to being a prerequisite for shadowed text, this also fixes an issue sometimes seen at the bottom of the mini KI player list where characters with a descender were missing. --- .../pfGameGUIMgr/pfGUIEditBoxMod.cpp | 4 +- .../PubUtilLib/plGImage/plDynamicTextMap.cpp | 1 + .../Plasma/PubUtilLib/plGImage/plFont.cpp | 104 +++++++++++++----- 3 files changed, 80 insertions(+), 29 deletions(-) diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.cpp index 10083906..df0c8fb6 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.cpp @@ -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 ) { diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp index 262244a5..c489e491 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp @@ -517,6 +517,7 @@ void plDynamicTextMap::DrawString( UInt16 x, UInt16 y, const wchar_t *text ) SetJustify( fJustify ); fCurrFont->SetRenderFlag( plFont::kRenderWrap | plFont::kRenderClip, false ); + fCurrFont->SetRenderClipRect( 0, 0, fVisWidth, fVisHeight ); fCurrFont->SetRenderColor( fFontColor.ToARGB32() ); fCurrFont->SetRenderFlag( plFont::kRenderIntoAlpha, fFontBlockRGB ); fCurrFont->RenderString( this, x, y, text ); diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp index efdf8384..8e581617 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp @@ -659,11 +659,16 @@ void plFont::IRenderString( plMipmap *mip, UInt16 x, UInt16 y, const wchar_t *st // Advance left past any clipping area CharRenderFunc oldFunc = fRenderInfo.fRenderFunc; fRenderInfo.fRenderFunc = &plFont::IRenderCharNull; - while( fRenderInfo.fX < fRenderInfo.fClipRect.fX && *string != 0 ) + Int16 prevX; + do { + prevX = fRenderInfo.fX; IRenderLoop( string, 1 ); - string++; } + while( fRenderInfo.fX <= fRenderInfo.fClipRect.fX && *++string != 0 ); + fRenderInfo.fMaxWidth += fRenderInfo.fX - prevX; + fRenderInfo.fDestPtr -= (fRenderInfo.fX - prevX) * fRenderInfo.fDestBPP; + fRenderInfo.fX = prevX; fRenderInfo.fRenderFunc = oldFunc; } @@ -672,10 +677,10 @@ void plFont::IRenderString( plMipmap *mip, UInt16 x, UInt16 y, const wchar_t *st { // See note at top of file plCharacter &ch = fCharacters[ (UInt16)string[ 0 ] - fFirstChar ]; - Int32 newX = x - (Int16)ch.fLeftKern; - if( newX < 0 ) - newX = 0; - fRenderInfo.fX = fRenderInfo.fFarthestX = (Int16)newX; + fRenderInfo.fX -= (Int16)ch.fLeftKern; + fRenderInfo.fMaxWidth += (Int16)ch.fLeftKern; + fRenderInfo.fDestPtr -= (Int16)ch.fLeftKern * fRenderInfo.fDestBPP; + fRenderInfo.fFarthestX = fRenderInfo.fX; } fRenderInfo.fVolatileStringPtr = string; // Just so we can keep track of when we clip @@ -715,9 +720,6 @@ void plFont::IRenderLoop( const wchar_t *string, Int32 maxCount ) if( fRenderInfo.fFlags & kRenderScaleAA ) thisWidth >>= 1; - if( thisWidth >= fRenderInfo.fMaxWidth ) - break; - (this->*(fRenderInfo.fRenderFunc))( fCharacters[ c ] ); fRenderInfo.fX += thisWidth; @@ -848,8 +850,8 @@ void plFont::IRenderChar8To32( const plFont::plCharacter &c ) { UInt8 *src = fBMapData + c.fBitmapOff; UInt32 *destPtr, *destBasePtr = (UInt32 *)( fRenderInfo.fDestPtr - c.fBaseline * fRenderInfo.fDestStride ); - UInt16 x, y; - UInt32 srcAlpha, oneMinusAlpha, r, g, b, dR, dG, dB, destAlpha, thisWidth; + Int16 x, y, thisHeight, xstart, thisWidth; + UInt32 srcAlpha, oneMinusAlpha, r, g, b, dR, dG, dB, destAlpha; UInt8 srcR, srcG, srcB; @@ -861,18 +863,34 @@ void plFont::IRenderChar8To32( const plFont::plCharacter &c ) // should already be in the cache. If it does, time to upgrade the font // format (again) thisWidth = fWidth;// + (Int32)c.fRightKern; + if( thisWidth >= fRenderInfo.fMaxWidth ) + thisWidth = fRenderInfo.fMaxWidth; - if( (Int32)c.fHeight - (Int32)c.fBaseline >= fRenderInfo.fMaxHeight || thisWidth >= fRenderInfo.fMaxWidth || c.fBaseline > fRenderInfo.fY ) - return; + xstart = fRenderInfo.fClipRect.fX - fRenderInfo.fX; + if( xstart < 0 ) + xstart = 0; srcR = (UInt8)(( fRenderInfo.fColor >> 16 ) & 0x000000ff); srcG = (UInt8)(( fRenderInfo.fColor >> 8 ) & 0x000000ff); srcB = (UInt8)(( fRenderInfo.fColor ) & 0x000000ff); - for( y = 0; y < c.fHeight; y++ ) + y = fRenderInfo.fClipRect.fY - fRenderInfo.fY + (Int16)c.fBaseline; + if( y < 0 ) + y = 0; + else + { + destBasePtr = (UInt32 *)( (UInt8 *)destBasePtr + y*fRenderInfo.fDestStride ); + src += y*fRenderInfo.fNumCols; + } + + thisHeight = fRenderInfo.fMaxHeight + (Int16)c.fBaseline; + if( thisHeight > (Int16)c.fHeight ) + thisHeight = (Int16)c.fHeight; + + for( ; y < thisHeight; y++ ) { destPtr = destBasePtr; - for( x = 0; x < thisWidth; x++ ) + for( x = xstart; x < thisWidth; x++ ) { if( src[ x ] == 255 ) destPtr[ x ] = fRenderInfo.fColor; @@ -907,8 +925,8 @@ void plFont::IRenderChar8To32FullAlpha( const plFont::plCharacter &c ) { UInt8 *src = fBMapData + c.fBitmapOff; UInt32 *destPtr, *destBasePtr = (UInt32 *)( fRenderInfo.fDestPtr - c.fBaseline * fRenderInfo.fDestStride ); - UInt16 x, y; - UInt32 destColorOnly, thisWidth; + Int16 x, y, thisHeight, xstart, thisWidth; + UInt32 destColorOnly; // Unfortunately for some fonts, their right kern value actually is @@ -919,16 +937,32 @@ void plFont::IRenderChar8To32FullAlpha( const plFont::plCharacter &c ) // should already be in the cache. If it does, time to upgrade the font // format (again) thisWidth = fWidth;// + (Int32)c.fRightKern; + if( thisWidth >= fRenderInfo.fMaxWidth ) + thisWidth = fRenderInfo.fMaxWidth; - if( (Int32)c.fHeight - (Int32)c.fBaseline >= fRenderInfo.fMaxHeight || thisWidth >= fRenderInfo.fMaxWidth || c.fBaseline > fRenderInfo.fY ) - return; + xstart = fRenderInfo.fClipRect.fX - fRenderInfo.fX; + if( xstart < 0 ) + xstart = 0; destColorOnly = fRenderInfo.fColor & 0x00ffffff; - for( y = 0; y < c.fHeight; y++ ) + y = fRenderInfo.fClipRect.fY - fRenderInfo.fY + (Int16)c.fBaseline; + if( y < 0 ) + y = 0; + else + { + destBasePtr = (UInt32 *)( (UInt8 *)destBasePtr + y*fRenderInfo.fDestStride ); + src += y*fRenderInfo.fNumCols; + } + + thisHeight = fRenderInfo.fMaxHeight + (Int16)c.fBaseline; + if( thisHeight > (Int16)c.fHeight ) + thisHeight = (Int16)c.fHeight; + + for( ; y < thisHeight; y++ ) { destPtr = destBasePtr; - for( x = 0; x < thisWidth; x++ ) + for( x = xstart; x < thisWidth; x++ ) { if( src[ x ] != 0 ) destPtr[ x ] = ( src[ x ] << 24 ) | destColorOnly; @@ -942,8 +976,8 @@ void plFont::IRenderChar8To32Alpha( const plFont::plCharacter &c ) { UInt8 val, *src = fBMapData + c.fBitmapOff; UInt32 *destPtr, *destBasePtr = (UInt32 *)( fRenderInfo.fDestPtr - c.fBaseline * fRenderInfo.fDestStride ); - UInt16 x, y; - UInt32 destColorOnly, alphaMult, fullAlpha, thisWidth; + Int16 x, y, thisHeight, xstart, thisWidth; + UInt32 destColorOnly, alphaMult, fullAlpha; // Unfortunately for some fonts, their right kern value actually is @@ -954,9 +988,12 @@ void plFont::IRenderChar8To32Alpha( const plFont::plCharacter &c ) // should already be in the cache. If it does, time to upgrade the font // format (again) thisWidth = fWidth;// + (Int32)c.fRightKern; + if( thisWidth >= fRenderInfo.fMaxWidth ) + thisWidth = fRenderInfo.fMaxWidth; - if( (Int32)c.fHeight - (Int32)c.fBaseline >= fRenderInfo.fMaxHeight || thisWidth >= fRenderInfo.fMaxWidth || c.fBaseline > fRenderInfo.fY ) - return; + xstart = fRenderInfo.fClipRect.fX - fRenderInfo.fX; + if( xstart < 0 ) + xstart = 0; destColorOnly = fRenderInfo.fColor & 0x00ffffff; // alphaMult should come out to be a value to satisfy (fontAlpha * alphaMult >> 8) as the right alpha, @@ -964,10 +1001,23 @@ void plFont::IRenderChar8To32Alpha( const plFont::plCharacter &c ) fullAlpha = fRenderInfo.fColor & 0xff000000; alphaMult = fullAlpha / 255; - for( y = 0; y < c.fHeight; y++ ) + y = fRenderInfo.fClipRect.fY - fRenderInfo.fY + (Int16)c.fBaseline; + if( y < 0 ) + y = 0; + else + { + destBasePtr = (UInt32 *)( (UInt8 *)destBasePtr + y*fRenderInfo.fDestStride ); + src += y*fRenderInfo.fNumCols; + } + + thisHeight = fRenderInfo.fMaxHeight + (Int16)c.fBaseline; + if( thisHeight > (Int16)c.fHeight ) + thisHeight = (Int16)c.fHeight; + + for( ; y < thisHeight; y++ ) { destPtr = destBasePtr; - for( x = 0; x < thisWidth; x++ ) + for( x = xstart; x < thisWidth; x++ ) { val = src[ x ]; if( val == 0xff ) From e02141055a7336bb8bf617bfb985631ff2b22e44 Mon Sep 17 00:00:00 2001 From: Christian Walther Date: Fri, 30 Dec 2011 15:10:47 +0100 Subject: [PATCH 03/14] Use premultiplied alpha for plDynamicTextMaps on GUI controls. This fixes the irregular dark fringes around light text when not exactly pixel-aligned that are caused by independent interpolation of color and alpha. It also makes calculations simpler for things to come. --- .../Sources/Plasma/CoreLib/hsColorRGBA.h | 9 +++ .../pfGameGUIMgr/pfGUIControlMod.cpp | 3 +- .../Plasma/NucleusLib/inc/hsGMatState.h | 3 +- .../PubUtilLib/plGImage/plDynamicTextMap.cpp | 45 ++++++------- .../PubUtilLib/plGImage/plDynamicTextMap.h | 6 +- .../Plasma/PubUtilLib/plGImage/plFont.cpp | 63 ++++++++++++++++++- .../Plasma/PubUtilLib/plGImage/plFont.h | 2 + .../Plasma/PubUtilLib/plGImage/plMipmap.cpp | 22 ++++++- .../Plasma/PubUtilLib/plGImage/plMipmap.h | 13 ++-- .../PubUtilLib/plPipeline/plDXPipeline.cpp | 18 +++++- 10 files changed, 149 insertions(+), 35 deletions(-) diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/CoreLib/hsColorRGBA.h b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/CoreLib/hsColorRGBA.h index 115cb0a0..4522181f 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/CoreLib/hsColorRGBA.h +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/CoreLib/hsColorRGBA.h @@ -71,6 +71,7 @@ struct hsColorRGBA { hsColorRGBA& FromARGB32(UInt32 c); UInt32 ToARGB32() const; + UInt32 ToARGB32Premultiplied() const; void Read(hsStream *stream); void Write(hsStream *stream) const; @@ -109,6 +110,14 @@ inline UInt32 hsColorRGBA::ToARGB32() const | (UInt32(b * 255.99f) << 0); } +inline UInt32 hsColorRGBA::ToARGB32Premultiplied() const +{ + return (UInt32(a * 255.0f + 0.5f) << 24) + | (UInt32(a * r * 255.0f + 0.5f) << 16) + | (UInt32(a * g * 255.0f + 0.5f) << 8) + | (UInt32(a * b * 255.0f + 0.5f) << 0); +} + inline hsColorRGBA operator+(const hsColorRGBA& s, const hsColorRGBA& t) { hsColorRGBA res; diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp index 6742891f..1bd7b2ba 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.cpp @@ -695,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 ); @@ -706,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(); diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/NucleusLib/inc/hsGMatState.h b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/NucleusLib/inc/hsGMatState.h index 4298f245..8b7288f3 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/NucleusLib/inc/hsGMatState.h +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/NucleusLib/inc/hsGMatState.h @@ -85,7 +85,8 @@ enum hsGMatBlendFlags { kBlendEnvBumpNext = 0x800000, kBlendSubtract = 0x1000000, kBlendRevSubtract = 0x2000000, - kBlendAlphaTestHigh = 0x4000000 + kBlendAlphaTestHigh = 0x4000000, + kBlendAlphaPremultiplied = 0x8000000 }; enum hsGMatClampFlags { diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp index c489e491..ca70c356 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp @@ -75,20 +75,12 @@ plProfile_Extern(MemMipmaps); //// Constructor & Destructor ///////////////////////////////////////////////// -plDynamicTextMap::plDynamicTextMap() : plMipmap() +plDynamicTextMap::plDynamicTextMap() + : fVisWidth(0), fVisHeight(0), fHasAlpha(false), fPremultipliedAlpha(false), fJustify(kLeftJustify), + fInitBuffer(nil), fFontFace(nil), fFontSize(0), fFontFlags(0), + fFontAntiAliasRGB(false), fFontBlockRGB(false), fHasCreateBeenCalled(false) { - fVisWidth = fVisHeight = 0; - fHasAlpha = false; - fJustify = kLeftJustify; - fInitBuffer = nil; - fFontFace = nil; - fFontSize = 0; - fFontFlags = 0; - fFontAntiAliasRGB = false; - fFontColor.Set( 0, 0, 0, 1 ); - fFontBlockRGB = false; - fHasCreateBeenCalled = false; - + fFontColor.Set(0, 0, 0, 1); } plDynamicTextMap::~plDynamicTextMap() @@ -96,11 +88,10 @@ plDynamicTextMap::~plDynamicTextMap() Reset(); } -plDynamicTextMap::plDynamicTextMap( UInt32 width, UInt32 height, hsBool hasAlpha, UInt32 extraWidth, UInt32 extraHeight ) : plMipmap() +plDynamicTextMap::plDynamicTextMap( UInt32 width, UInt32 height, hsBool hasAlpha, UInt32 extraWidth, UInt32 extraHeight, hsBool premultipliedAlpha ) + : fInitBuffer(nil), fFontFace(nil) { - fInitBuffer = nil; - fFontFace = nil; - Create( width, height, hasAlpha, extraWidth, extraHeight ); + Create( width, height, hasAlpha, extraWidth, extraHeight, premultipliedAlpha ); } //// SetNoCreate ////////////////////////////////////////////////////////////// @@ -122,7 +113,7 @@ void plDynamicTextMap::SetNoCreate( UInt32 width, UInt32 height, hsBool hasAlpha //// Create /////////////////////////////////////////////////////////////////// -void plDynamicTextMap::Create( UInt32 width, UInt32 height, hsBool hasAlpha, UInt32 extraWidth, UInt32 extraHeight ) +void plDynamicTextMap::Create( UInt32 width, UInt32 height, hsBool hasAlpha, UInt32 extraWidth, UInt32 extraHeight, hsBool premultipliedAlpha ) { SetConfig( hasAlpha ? kARGB32Config : kRGB32Config ); @@ -130,6 +121,7 @@ void plDynamicTextMap::Create( UInt32 width, UInt32 height, hsBool hasAlpha, UIn fVisWidth = (UInt16)width; fVisHeight = (UInt16)height; fHasAlpha = hasAlpha; + fPremultipliedAlpha = premultipliedAlpha; for( fWidth = 1; fWidth < width + extraWidth; fWidth <<= 1 ); for( fHeight = 1; fHeight < height + extraHeight; fHeight <<= 1 ); @@ -395,7 +387,7 @@ void plDynamicTextMap::ClearToColor( hsColorRGBA &color ) if( !IIsValid() ) return; - UInt32 i, hex = color.ToARGB32(); + UInt32 i, hex = fPremultipliedAlpha ? color.ToARGB32Premultiplied() : color.ToARGB32(); UInt32 *data = (UInt32 *)fImage; // Buffer is of size fVisWidth x fVisHeight, so we need a bit of work to do this right @@ -520,6 +512,7 @@ void plDynamicTextMap::DrawString( UInt16 x, UInt16 y, const wchar_t *text ) fCurrFont->SetRenderClipRect( 0, 0, fVisWidth, fVisHeight ); fCurrFont->SetRenderColor( fFontColor.ToARGB32() ); fCurrFont->SetRenderFlag( plFont::kRenderIntoAlpha, fFontBlockRGB ); + fCurrFont->SetRenderFlag( plFont::kRenderAlphaPremultiplied, fPremultipliedAlpha ); fCurrFont->RenderString( this, x, y, text ); } @@ -541,6 +534,7 @@ void plDynamicTextMap::DrawClippedString( Int16 x, Int16 y, const wchar_t *text, fCurrFont->SetRenderClipping( x, y, width, height ); fCurrFont->SetRenderColor( fFontColor.ToARGB32() ); fCurrFont->SetRenderFlag( plFont::kRenderIntoAlpha, fFontBlockRGB ); + fCurrFont->SetRenderFlag( plFont::kRenderAlphaPremultiplied, fPremultipliedAlpha ); fCurrFont->RenderString( this, x, y, text ); } @@ -561,6 +555,7 @@ void plDynamicTextMap::DrawClippedString( Int16 x, Int16 y, const wchar_t *text, SetJustify( fJustify ); fCurrFont->SetRenderClipping( clipX, clipY, width, height ); fCurrFont->SetRenderColor( fFontColor.ToARGB32() ); + fCurrFont->SetRenderFlag( plFont::kRenderAlphaPremultiplied, fPremultipliedAlpha ); fCurrFont->RenderString( this, x, y, text ); } @@ -582,6 +577,7 @@ void plDynamicTextMap::DrawWrappedString( UInt16 x, UInt16 y, const wchar_t *tex fCurrFont->SetRenderWrapping( x, y, width, height ); fCurrFont->SetRenderColor( fFontColor.ToARGB32() ); fCurrFont->SetRenderFlag( plFont::kRenderIntoAlpha, fFontBlockRGB ); + fCurrFont->SetRenderFlag( plFont::kRenderAlphaPremultiplied, fPremultipliedAlpha ); fCurrFont->RenderString( this, x, y, text, lastX, lastY ); } @@ -665,7 +661,7 @@ void plDynamicTextMap::FillRect( UInt16 x, UInt16 y, UInt16 width, UInt16 height width = (UInt16)(fWidth - x); // Gee, how hard can it REALLY be? - UInt32 i, hex = color.ToARGB32(); + UInt32 i, hex = fPremultipliedAlpha ? color.ToARGB32Premultiplied() : color.ToARGB32(); height += y; if( height > fHeight ) height = (UInt16)fHeight; @@ -690,7 +686,7 @@ void plDynamicTextMap::FrameRect( UInt16 x, UInt16 y, UInt16 width, UInt16 heigh height = (UInt16)(fHeight - y); // Shouldn't be much harder - UInt32 i, hex = color.ToARGB32(); + UInt32 i, hex = fPremultipliedAlpha ? color.ToARGB32Premultiplied() : color.ToARGB32(); UInt32 *dest1, *dest2; dest1 = GetAddr32( x, y ); @@ -725,6 +721,9 @@ void plDynamicTextMap::DrawImage( UInt16 x, UInt16 y, plMipmap *image, DrawMetho else if( method == kImgSprite ) opts.fFlags = plMipmap::kCopySrcAlpha; + if( fPremultipliedAlpha ) + opts.fFlags |= plMipmap::kDestPremultiplied; + Composite( image, x, y, &opts ); /// HACK for now, since the alpha in the mipmap gets copied straight into the @@ -763,6 +762,9 @@ void plDynamicTextMap::DrawClippedImage( UInt16 x, UInt16 y, plMipmap *image, else if( method == kImgSprite ) opts.fFlags = plMipmap::kCopySrcAlpha; + if( fPremultipliedAlpha ) + opts.fFlags |= plMipmap::kDestPremultiplied; + opts.fSrcClipX = srcClipX; opts.fSrcClipY = srcClipY; opts.fSrcClipWidth = srcClipWidth; @@ -909,6 +911,7 @@ void plDynamicTextMap::Swap( plDynamicTextMap *other ) // Swap DTMap info SWAP_ME( hsBool, fHasAlpha, other->fHasAlpha ); + SWAP_ME( hsBool, fPremultipliedAlpha, other->fPremultipliedAlpha ); SWAP_ME( hsBool, fShadowed, other->fShadowed ); SWAP_ME( Justify, fJustify, other->fJustify ); diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h index 7b38c7fb..b8162ef7 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h @@ -113,14 +113,14 @@ class plDynamicTextMap : public plMipmap plDynamicTextMap(); - plDynamicTextMap( UInt32 width, UInt32 height, hsBool hasAlpha = false, UInt32 extraWidth = 0, UInt32 extraHeight = 0 ); + plDynamicTextMap( UInt32 width, UInt32 height, hsBool hasAlpha = false, UInt32 extraWidth = 0, UInt32 extraHeight = 0, hsBool premultipliedAlpha = false ); virtual ~plDynamicTextMap(); CLASSNAME_REGISTER( plDynamicTextMap ); GETINTERFACE_ANY( plDynamicTextMap, plMipmap ); - void Create( UInt32 width, UInt32 height, hsBool hasAlpha, UInt32 extraWidth = 0, UInt32 extraHeight = 0 ); + void Create( UInt32 width, UInt32 height, hsBool hasAlpha, UInt32 extraWidth = 0, UInt32 extraHeight = 0, hsBool premultipliedAlpha = false ); void SetNoCreate( UInt32 width, UInt32 height, hsBool hasAlpha ); virtual void Reset( void ); @@ -222,7 +222,7 @@ class plDynamicTextMap : public plMipmap UInt32 *IAllocateOSSurface( UInt16 width, UInt16 height ); void IDestroyOSSurface( void ); - hsBool fHasAlpha, fShadowed; + hsBool fHasAlpha, fPremultipliedAlpha, fShadowed; Justify fJustify; char *fFontFace; diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp index 8e581617..ebc8fb6d 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp @@ -345,7 +345,9 @@ void plFont::IRenderString( plMipmap *mip, UInt16 x, UInt16 y, const wchar_t *st { if( fRenderInfo.fFlags & kRenderIntoAlpha ) { - if( ( fRenderInfo.fColor & 0xff000000 ) != 0xff000000 ) + if( fRenderInfo.fFlags & kRenderAlphaPremultiplied ) + fRenderInfo.fRenderFunc = &plFont::IRenderChar8To32AlphaPremultiplied; + else if( ( fRenderInfo.fColor & 0xff000000 ) != 0xff000000 ) fRenderInfo.fRenderFunc = &plFont::IRenderChar8To32Alpha; else fRenderInfo.fRenderFunc = &plFont::IRenderChar8To32FullAlpha; @@ -1032,6 +1034,65 @@ void plFont::IRenderChar8To32Alpha( const plFont::plCharacter &c ) } } +void plFont::IRenderChar8To32AlphaPremultiplied( const plFont::plCharacter &c ) +{ + UInt8 *src = fBMapData + c.fBitmapOff; + UInt32 *destPtr, *destBasePtr = (UInt32 *)( fRenderInfo.fDestPtr - c.fBaseline * fRenderInfo.fDestStride ); + Int16 x, y, thisHeight, xstart, thisWidth; + UInt8 srcA, srcR, srcG, srcB; + + + // Unfortunately for some fonts, their right kern value actually is + // farther left than the right edge of the bitmap (think of overlapping + // script fonts). Ideally, we should store the actual width of each char's + // bitmap and use that here. However, it really shouldn't make too big of a + // difference, especially since the dest pixels that we end up overlapping + // should already be in the cache. If it does, time to upgrade the font + // format (again) + thisWidth = fWidth;// + (Int32)c.fRightKern; + if( thisWidth >= fRenderInfo.fMaxWidth ) + thisWidth = fRenderInfo.fMaxWidth; + + xstart = fRenderInfo.fClipRect.fX - fRenderInfo.fX; + if( xstart < 0 ) + xstart = 0; + + srcA = (UInt8)(( fRenderInfo.fColor >> 24 ) & 0x000000ff); + srcR = (UInt8)(( fRenderInfo.fColor >> 16 ) & 0x000000ff); + srcG = (UInt8)(( fRenderInfo.fColor >> 8 ) & 0x000000ff); + srcB = (UInt8)(( fRenderInfo.fColor ) & 0x000000ff); + + y = fRenderInfo.fClipRect.fY - fRenderInfo.fY + (Int16)c.fBaseline; + if( y < 0 ) + y = 0; + else + { + destBasePtr = (UInt32 *)( (UInt8 *)destBasePtr + y*fRenderInfo.fDestStride ); + src += y*fRenderInfo.fNumCols; + } + + thisHeight = fRenderInfo.fMaxHeight + (Int16)c.fBaseline; + if( thisHeight > (Int16)c.fHeight ) + thisHeight = (Int16)c.fHeight; + + for( ; y < thisHeight; y++ ) + { + destPtr = destBasePtr; + for( x = xstart; x < thisWidth; x++ ) + { + UInt32 a = src[ x ]; + if (a != 0) + { + if (srcA != 0xff) + a = (srcA*a + 127)/255; + destPtr[ x ] = ( a << 24 ) | (((srcR*a + 127)/255) << 16) | (((srcG*a + 127)/255) << 8) | ((srcB*a + 127)/255); + } + } + destBasePtr = (UInt32 *)( (UInt8 *)destBasePtr + fRenderInfo.fDestStride ); + src += fWidth; + } +} + void plFont::IRenderCharNull( const plCharacter &c ) { diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.h b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.h index d2b7dd7a..11e38ca3 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.h +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.h @@ -116,6 +116,7 @@ class plFont : public hsKeyedObject // value between the renderColor and the destColor and // leave the alpha as-is // This flag has no effect on monochrome fonts + kRenderAlphaPremultiplied = 0x00001000, // Destination has color values premultiplied by alpha }; enum Flags @@ -231,6 +232,7 @@ class plFont : public hsKeyedObject void IRenderChar8To32( const plCharacter &c ); void IRenderChar8To32Alpha( const plCharacter &c ); void IRenderChar8To32FullAlpha( const plCharacter &c ); + void IRenderChar8To32AlphaPremultiplied( const plCharacter &c ); void IRenderCharNull( const plCharacter &c ); public: diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plMipmap.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plMipmap.cpp index a7c30af0..93786dfa 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plMipmap.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plMipmap.cpp @@ -1745,6 +1745,18 @@ void plMipmap::Composite( plMipmap *source, UInt16 x, UInt16 y, plMipmap::Compos for( pY = (UInt16)srcHeight; pY > 0; pY-- ) { memcpy( dstPtr, srcPtr, srcRowBytesToCopy ); + if( options->fFlags & kDestPremultiplied ) + { + // multiply color values by alpha + for( pX = 0; pX < srcWidth; pX++ ) + { + srcAlpha = ((dstPtr[ pX ] >> 24) & 0x000000ff); + dstPtr[ pX ] = ( srcAlpha << 24 ) + | (((((dstPtr[ pX ] >> 16) & 0xff)*srcAlpha + 127)/255) << 16) + | (((((dstPtr[ pX ] >> 8) & 0xff)*srcAlpha + 127)/255) << 8) + | (((((dstPtr[ pX ] ) & 0xff)*srcAlpha + 127)/255) ); + } + } dstPtr += dstRowBytes >> 2; srcPtr += srcRowBytes >> 2; } @@ -1776,7 +1788,15 @@ void plMipmap::Composite( plMipmap *source, UInt16 x, UInt16 y, plMipmap::Compos { srcAlpha = options->fOpacity * ( ( srcPtr[ pX ] >> 16 ) & 0x0000ff00 ) / 255 / 256; if( srcAlpha != 0 ) - dstPtr[ pX ] = ( srcPtr[ pX ] & 0x00ffffff ) | ( srcAlpha << 24 ); + { + if( options->fFlags & kDestPremultiplied ) + dstPtr[ pX ] = ( srcAlpha << 24 ) + | (((((srcPtr[ pX ] >> 16) & 0xff)*srcAlpha + 127)/255) << 16) + | (((((srcPtr[ pX ] >> 8) & 0xff)*srcAlpha + 127)/255) << 8) + | (((((srcPtr[ pX ] ) & 0xff)*srcAlpha + 127)/255) ); + else + dstPtr[ pX ] = ( srcPtr[ pX ] & 0x00ffffff ) | ( srcAlpha << 24 ); + } } dstPtr += dstRowBytes >> 2; srcPtr += srcRowBytes >> 2; diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plMipmap.h b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plMipmap.h index 720b8838..79b3568c 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plMipmap.h +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plMipmap.h @@ -233,11 +233,14 @@ class plMipmap : public plBitmap enum CompositeFlags { - kForceOpaque = 0x0001, // Copy src pixels raw, force dest alphas to opaque - kCopySrcAlpha = 0x0002, // Copy the src pixels raw, including alphas, overwrite dest - kBlendSrcAlpha = 0x0004, // Blend src pixels onto dest using src alpha, dest alpha = src alpha - kMaskSrcAlpha = 0x0008, // Same as copySrcAlpha, but dest is untouched when src alpha = 0 - kBlendWriteAlpha= 0x0010 // Like default (0), but writes dest alpha values + kForceOpaque = 0x0001, // Copy src pixels raw, force dest alphas to opaque + kCopySrcAlpha = 0x0002, // Copy the src pixels raw, including alphas, overwrite dest + kBlendSrcAlpha = 0x0004, // Blend src pixels onto dest using src alpha, dest alpha = src alpha + kMaskSrcAlpha = 0x0008, // Same as copySrcAlpha, but dest is untouched when src alpha = 0 + kBlendWriteAlpha = 0x0010, // Like default (0), but writes dest alpha values + + kDestPremultiplied = 0x0020, // Dest has color premultiplied by alpha + // (src always assumed nonpremultiplied for now) }; class CompositeOptions diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plPipeline/plDXPipeline.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plPipeline/plDXPipeline.cpp index 684bea34..0e1fd56c 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plPipeline/plDXPipeline.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plPipeline/plDXPipeline.cpp @@ -7229,12 +7229,26 @@ void plDXPipeline::IHandleFirstStageBlend() fD3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE ); if( fLayerState[0].fBlendFlags & hsGMatState::kBlendInvertFinalAlpha ) { - fD3DDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_INVSRCALPHA ); + if( fLayerState[0].fBlendFlags & hsGMatState::kBlendAlphaPremultiplied ) + { + fD3DDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE ); + } + else + { + fD3DDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_INVSRCALPHA ); + } fD3DDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_SRCALPHA ); } else { - fD3DDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA ); + if( fLayerState[0].fBlendFlags & hsGMatState::kBlendAlphaPremultiplied ) + { + fD3DDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE ); + } + else + { + fD3DDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA ); + } fD3DDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); } break; From b343e389abac3b04fd86305447ada2341e7cd7c5 Mon Sep 17 00:00:00 2001 From: Christian Walther Date: Wed, 25 Jan 2012 22:16:19 +0100 Subject: [PATCH 04/14] Implement shadowed text rendering. Intended to make KI text (player list and chat) better readable on light and patterned backgrounds. In this WIP, all text on GUI controls is rendered shadowed. --- .../Plasma/PubUtilLib/plGImage/plFont.cpp | 86 ++++++++++++++++++- .../Plasma/PubUtilLib/plGImage/plFont.h | 7 ++ 2 files changed, 90 insertions(+), 3 deletions(-) diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp index ebc8fb6d..f5761216 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp @@ -346,7 +346,12 @@ void plFont::IRenderString( plMipmap *mip, UInt16 x, UInt16 y, const wchar_t *st if( fRenderInfo.fFlags & kRenderIntoAlpha ) { if( fRenderInfo.fFlags & kRenderAlphaPremultiplied ) - fRenderInfo.fRenderFunc = &plFont::IRenderChar8To32AlphaPremultiplied; + { + if (1)//( ( fRenderInfo.fColor & 0x00ffffff ) == 0x00ffffff ) //FIXME + fRenderInfo.fRenderFunc = &plFont::IRenderChar8To32AlphaPremShadow; + else + fRenderInfo.fRenderFunc = &plFont::IRenderChar8To32AlphaPremultiplied; + } else if( ( fRenderInfo.fColor & 0xff000000 ) != 0xff000000 ) fRenderInfo.fRenderFunc = &plFont::IRenderChar8To32Alpha; else @@ -1059,8 +1064,8 @@ void plFont::IRenderChar8To32AlphaPremultiplied( const plFont::plCharacter &c ) srcA = (UInt8)(( fRenderInfo.fColor >> 24 ) & 0x000000ff); srcR = (UInt8)(( fRenderInfo.fColor >> 16 ) & 0x000000ff); - srcG = (UInt8)(( fRenderInfo.fColor >> 8 ) & 0x000000ff); - srcB = (UInt8)(( fRenderInfo.fColor ) & 0x000000ff); + srcG = (UInt8)(( fRenderInfo.fColor >> 8 ) & 0x000000ff); + srcB = (UInt8)(( fRenderInfo.fColor ) & 0x000000ff); y = fRenderInfo.fClipRect.fY - fRenderInfo.fY + (Int16)c.fBaseline; if( y < 0 ) @@ -1093,6 +1098,81 @@ void plFont::IRenderChar8To32AlphaPremultiplied( const plFont::plCharacter &c ) } } +void plFont::IRenderChar8To32AlphaPremShadow( const plFont::plCharacter &c ) +{ + UInt32 *destPtr, *destBasePtr = (UInt32 *)( fRenderInfo.fDestPtr - c.fBaseline * fRenderInfo.fDestStride ); + Int16 x, y, thisHeight, xstart, thisWidth; + UInt8 srcA, srcR, srcG, srcB; + + + // Unfortunately for some fonts, their right kern value actually is + // farther left than the right edge of the bitmap (think of overlapping + // script fonts). Ideally, we should store the actual width of each char's + // bitmap and use that here. However, it really shouldn't make too big of a + // difference, especially since the dest pixels that we end up overlapping + // should already be in the cache. If it does, time to upgrade the font + // format (again) + thisWidth = fWidth + 2;// + (Int32)c.fRightKern; + if( thisWidth >= fRenderInfo.fMaxWidth ) + thisWidth = fRenderInfo.fMaxWidth; + + xstart = fRenderInfo.fClipRect.fX - fRenderInfo.fX; + if( xstart < -2 ) + xstart = -2; + + srcA = (UInt8)(( fRenderInfo.fColor >> 24 ) & 0x000000ff); + srcR = (UInt8)(( fRenderInfo.fColor >> 16 ) & 0x000000ff); + srcG = (UInt8)(( fRenderInfo.fColor >> 8 ) & 0x000000ff); + srcB = (UInt8)(( fRenderInfo.fColor ) & 0x000000ff); + + static const UInt32 kernel[5][5] = { + {1, 2, 2, 2, 1}, + {1, 13, 13, 13, 1}, + {1, 10, 10, 10, 1}, + {1, 7, 7, 7, 1}, + {1, 1, 1, 1, 1} + }; + + UInt32 clamp = 220 - ((2 * srcR + 4 * srcG + srcB) >> 4); + + y = fRenderInfo.fClipRect.fY - fRenderInfo.fY + (Int16)c.fBaseline; + if( y < -2 ) + y = -2; + destBasePtr = (UInt32 *)( (UInt8 *)destBasePtr + y*fRenderInfo.fDestStride ); + + thisHeight = fRenderInfo.fMaxHeight + (Int16)c.fBaseline; + if( thisHeight > (Int16)c.fHeight + 2 ) + thisHeight = (Int16)c.fHeight + 2; + + for( ; y < thisHeight; y++ ) + { + destPtr = destBasePtr; + for( x = xstart; x < thisWidth; x++ ) + { + UInt32 sa = 0; + for (Int32 i = -2; i <= 2; i++) { + for (Int32 j = -2; j <= 2; j++) { + UInt32 m = kernel[j+2][i+2]; + if (m != 0) + sa += m * IGetCharPixel(c, x+i, y+j); + } + } + sa = (sa * clamp) >> 13; + if (sa > clamp) + sa = clamp; + UInt32 a = IGetCharPixel(c, x, y); + if (srcA != 0xff) + a = (srcA * a + 127) / 255; + UInt32 ta = a + sa - ((a*sa + 127) / 255); + if (ta > (destPtr[ x ] >> 24)) + destPtr[ x ] = ( ta << 24 ) | (((srcR * a + 127) / 255) << 16) | + (((srcG * a + 127) / 255) << 8) | + (((srcB * a + 127) / 255) << 0); + } + destBasePtr = (UInt32 *)( (UInt8 *)destBasePtr + fRenderInfo.fDestStride ); + } +} + void plFont::IRenderCharNull( const plCharacter &c ) { diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.h b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.h index 11e38ca3..ff69be5b 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.h +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.h @@ -233,8 +233,15 @@ class plFont : public hsKeyedObject void IRenderChar8To32Alpha( const plCharacter &c ); void IRenderChar8To32FullAlpha( const plCharacter &c ); void IRenderChar8To32AlphaPremultiplied( const plCharacter &c ); + void IRenderChar8To32AlphaPremShadow( const plCharacter &c ); void IRenderCharNull( const plCharacter &c ); + UInt32 IGetCharPixel( const plCharacter &c, Int32 x, Int32 y ) + { + // only for 8-bit characters + return (x < 0 || y < 0 || (UInt32)x >= fWidth || (UInt32)y >= c.fHeight) ? 0 : *(fBMapData + c.fBitmapOff + y*fWidth + x); + } + public: plFont(); From 3825317e5e46898f257656b91bab6a51b2a2af7b Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Thu, 4 Jul 2013 20:13:03 -0400 Subject: [PATCH 05/14] Link shadowed text rendering to the plDynamicTextMap::kFontShadowed flag. Conveniently enough, this existing but unimplemented flag is already set mostly the way we want it in the current PRPs. --- .../PubUtilLib/plGImage/plDynamicTextMap.cpp | 32 ++++++++++--------- .../PubUtilLib/plGImage/plDynamicTextMap.h | 2 ++ .../Plasma/PubUtilLib/plGImage/plFont.cpp | 2 +- .../Plasma/PubUtilLib/plGImage/plFont.h | 1 + 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp index ca70c356..2ab6565c 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp @@ -380,6 +380,17 @@ void plDynamicTextMap::IClearFromBuffer( UInt32 *clearBuffer ) } } +//// IPropagateFlags ////////////////////////////////////////////////////////// + +void plDynamicTextMap::IPropagateFlags() +{ + SetJustify(fJustify); + fCurrFont->SetRenderFlag(plFont::kRenderShadow, fFontFlags & kFontShadowed); + fCurrFont->SetRenderFlag(plFont::kRenderIntoAlpha, fFontBlockRGB); + fCurrFont->SetRenderFlag(plFont::kRenderAlphaPremultiplied, fPremultipliedAlpha); + fCurrFont->SetRenderColor(fFontColor.ToARGB32()); +} + //// ClearToColor ///////////////////////////////////////////////////////////// void plDynamicTextMap::ClearToColor( hsColorRGBA &color ) @@ -454,6 +465,8 @@ void plDynamicTextMap::SetFont( const char *face, UInt16 size, UInt8 fontFlags, // This will be nil if we're just running the page optimizer. if (fCurrFont) { + if (fFontFlags & kFontShadowed) + fCurrFont->SetRenderFlag(plFont::kRenderShadow, true); fCurrFont->SetRenderYJustify( plFont::kRenderJustYTop ); SetJustify( fJustify ); } @@ -507,12 +520,9 @@ void plDynamicTextMap::DrawString( UInt16 x, UInt16 y, const wchar_t *text ) if( !IIsValid() ) return; - SetJustify( fJustify ); + IPropagateFlags(); fCurrFont->SetRenderFlag( plFont::kRenderWrap | plFont::kRenderClip, false ); fCurrFont->SetRenderClipRect( 0, 0, fVisWidth, fVisHeight ); - fCurrFont->SetRenderColor( fFontColor.ToARGB32() ); - fCurrFont->SetRenderFlag( plFont::kRenderIntoAlpha, fFontBlockRGB ); - fCurrFont->SetRenderFlag( plFont::kRenderAlphaPremultiplied, fPremultipliedAlpha ); fCurrFont->RenderString( this, x, y, text ); } @@ -530,11 +540,8 @@ void plDynamicTextMap::DrawClippedString( Int16 x, Int16 y, const wchar_t *text, if( !IIsValid() ) return; - SetJustify( fJustify ); + IPropagateFlags(); fCurrFont->SetRenderClipping( x, y, width, height ); - fCurrFont->SetRenderColor( fFontColor.ToARGB32() ); - fCurrFont->SetRenderFlag( plFont::kRenderIntoAlpha, fFontBlockRGB ); - fCurrFont->SetRenderFlag( plFont::kRenderAlphaPremultiplied, fPremultipliedAlpha ); fCurrFont->RenderString( this, x, y, text ); } @@ -552,10 +559,8 @@ void plDynamicTextMap::DrawClippedString( Int16 x, Int16 y, const wchar_t *text, if( !IIsValid() ) return; - SetJustify( fJustify ); + IPropagateFlags(); fCurrFont->SetRenderClipping( clipX, clipY, width, height ); - fCurrFont->SetRenderColor( fFontColor.ToARGB32() ); - fCurrFont->SetRenderFlag( plFont::kRenderAlphaPremultiplied, fPremultipliedAlpha ); fCurrFont->RenderString( this, x, y, text ); } @@ -573,11 +578,8 @@ void plDynamicTextMap::DrawWrappedString( UInt16 x, UInt16 y, const wchar_t *tex if( !IIsValid() ) return; - SetJustify( fJustify ); + IPropagateFlags(); fCurrFont->SetRenderWrapping( x, y, width, height ); - fCurrFont->SetRenderColor( fFontColor.ToARGB32() ); - fCurrFont->SetRenderFlag( plFont::kRenderIntoAlpha, fFontBlockRGB ); - fCurrFont->SetRenderFlag( plFont::kRenderAlphaPremultiplied, fPremultipliedAlpha ); fCurrFont->RenderString( this, x, y, text, lastX, lastY ); } diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h index b8162ef7..453a0afe 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h @@ -222,6 +222,8 @@ class plDynamicTextMap : public plMipmap UInt32 *IAllocateOSSurface( UInt16 width, UInt16 height ); void IDestroyOSSurface( void ); + void IPropagateFlags(); + hsBool fHasAlpha, fPremultipliedAlpha, fShadowed; Justify fJustify; diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp index f5761216..c40fc35f 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp @@ -347,7 +347,7 @@ void plFont::IRenderString( plMipmap *mip, UInt16 x, UInt16 y, const wchar_t *st { if( fRenderInfo.fFlags & kRenderAlphaPremultiplied ) { - if (1)//( ( fRenderInfo.fColor & 0x00ffffff ) == 0x00ffffff ) //FIXME + if (fRenderInfo.fFlags & kRenderShadow) fRenderInfo.fRenderFunc = &plFont::IRenderChar8To32AlphaPremShadow; else fRenderInfo.fRenderFunc = &plFont::IRenderChar8To32AlphaPremultiplied; diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.h b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.h index ff69be5b..58911f52 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.h +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.h @@ -117,6 +117,7 @@ class plFont : public hsKeyedObject // leave the alpha as-is // This flag has no effect on monochrome fonts kRenderAlphaPremultiplied = 0x00001000, // Destination has color values premultiplied by alpha + kRenderShadow = 0x00002000, // Render text shadows }; enum Flags From a0bbef1819db7eaae7b3fd7346bf039ac2e9e9be Mon Sep 17 00:00:00 2001 From: Christian Walther Date: Sun, 6 Apr 2014 17:19:42 +0200 Subject: [PATCH 06/14] Undo the kRenderJustXForceLeft bugfix of 4 commits back. The fix (adding adjustment of fRenderInfo.fDestPtr) made kRenderJustXForceLeft behave as intended (left-aligning the edge of the bitmap rather than the side bearing of the first character) but cuts off shadows in some places (e.g. at the left edges of "BUDDIES" and "NEIGHBORS" in the mini KI). To ensure enough space for the shadow, and considering that all content was developed and visually optimized with the bug in place, it seems better to preserve the buggy behavior and make kRenderJustXForceLeft work exactly like kRenderJustXLeft. --- .../Plasma/PubUtilLib/plGImage/plFont.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp index c40fc35f..c651409a 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp @@ -679,16 +679,14 @@ void plFont::IRenderString( plMipmap *mip, UInt16 x, UInt16 y, const wchar_t *st fRenderInfo.fRenderFunc = oldFunc; } - // Adjust for left kern - if( ( fRenderInfo.fFlags & kRenderJustXMask ) == kRenderJustXForceLeft ) - { - // See note at top of file - plCharacter &ch = fCharacters[ (UInt16)string[ 0 ] - fFirstChar ]; - fRenderInfo.fX -= (Int16)ch.fLeftKern; - fRenderInfo.fMaxWidth += (Int16)ch.fLeftKern; - fRenderInfo.fDestPtr -= (Int16)ch.fLeftKern * fRenderInfo.fDestBPP; - fRenderInfo.fFarthestX = fRenderInfo.fX; - } + // There used to be an adjustment of the X coordinate by -ch.fLeftKern for the case + // of kRenderJustXForceLeft here, but it was buggy in that it neglected to adjust + // fRenderInfo.fDestPtr and therefore had no visible effect (or almost none - only + // at the end of the line). Fixing the bug however (making kRenderJustXForceLeft + // work as intended) causes the text shadow to be cut off in some places. To ensure + // enough space for the shadow, and considering that all content was developed and + // visually optimized with the bug in place, it seems better to preserve the buggy + // behavior and make kRenderJustXForceLeft work exactly like kRenderJustXLeft. fRenderInfo.fVolatileStringPtr = string; // Just so we can keep track of when we clip IRenderLoop( string, -1 ); From 39ff487ca8df669fd719ceee22b65fff1d2f0d22 Mon Sep 17 00:00:00 2001 From: Anne Marije v/d Meer Date: Tue, 1 Apr 2014 16:38:12 +0200 Subject: [PATCH 07/14] add python api to set flags Clean up unwanted changes caused by IDE extension -.- Reworked implementation --- .../pfPython/pyGUIControlTextBox.cpp | 30 +++++++++++++++++++ .../FeatureLib/pfPython/pyGUIControlTextBox.h | 2 ++ .../pfPython/pyGUIControlTextBoxGlue.cpp | 19 ++++++++++++ 3 files changed, 51 insertions(+) diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBox.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBox.cpp index ff625fe9..961a8f81 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBox.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBox.cpp @@ -214,3 +214,33 @@ UInt8 pyGUIControlTextBox::GetJustify() } return pfGUIListText::kLeftJustify; } + +void pyGUIControlTextBox::SetFontFlags(UInt8 fontFlags) +{ + if (fGCkey) + { + // get the pointer to the modifier + pfGUITextBoxMod* ptbmod = pfGUITextBoxMod::ConvertNoRef(fGCkey->ObjectIsLoaded()); + if (ptbmod) + { + pfGUIColorScheme* colorscheme = ptbmod->GetColorScheme(); + colorscheme->fFontFlags = fontFlags; + ptbmod->UpdateColorScheme(); + } + } +} + +UInt8 pyGUIControlTextBox::GetFontFlags() +{ + if (fGCkey) + { + // get the pointer to the modifier + pfGUITextBoxMod* ptbmod = pfGUITextBoxMod::ConvertNoRef(fGCkey->ObjectIsLoaded()); + if (ptbmod) + { + pfGUIColorScheme* colorscheme = ptbmod->GetColorScheme(); + return colorscheme->fFontFlags; + } + } + return 0; +} diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBox.h b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBox.h index a4e6f97a..a11076fd 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBox.h +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBox.h @@ -88,8 +88,10 @@ public: virtual void SetForeColor( pyColor& color ); virtual void SetBackColor( pyColor& color ); virtual void SetJustify( UInt8 justify ); + virtual void SetFontFlags(UInt8 fontflags); virtual UInt8 GetJustify(); virtual PyObject* GetForeColor(); // returns pyColor + virtual UInt8 GetFontFlags(); }; #endif // _pyGUIControlTextBox_h_ diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBoxGlue.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBoxGlue.cpp index 55d7f973..6dd3ddf3 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBoxGlue.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBoxGlue.cpp @@ -185,6 +185,23 @@ PYTHON_METHOD_DEFINITION(ptGUIControlTextBox, setStringJustify, args) PYTHON_RETURN_NONE; } +PYTHON_METHOD_DEFINITION(ptGUIControlTextBox, 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_NOARGS(ptGUIControlTextBox, getFontFlags) +{ + return PyInt_FromLong(self->fThis->GetFontFlags()); +} + PYTHON_METHOD_DEFINITION_NOARGS(ptGUIControlTextBox, getStringJustify) { return PyInt_FromLong(self->fThis->GetJustify()); @@ -204,8 +221,10 @@ PYTHON_START_METHODS_TABLE(ptGUIControlTextBox) PYTHON_METHOD(ptGUIControlTextBox, setForeColor, "Params: color\nSets the text forecolor to 'color', which is a ptColor object."), PYTHON_METHOD(ptGUIControlTextBox, setBackColor, "Params: color\nSets the text backcolor to 'color', which is a ptColor object."), PYTHON_METHOD(ptGUIControlTextBox, setStringJustify, "Params: justify\nSets current justify"), + PYTHON_METHOD(ptGUIControlTextBox, setFontFlags, "Params: fontflags\nSets current fontflags"), PYTHON_METHOD_NOARGS(ptGUIControlTextBox, getStringJustify, "Returns current justify"), PYTHON_METHOD_NOARGS(ptGUIControlTextBox, getForeColor, "Returns the current forecolor"), + PYTHON_METHOD_NOARGS(ptGUIControlTextBox, getFontFlags, "Returns the current fontflags"), PYTHON_END_METHODS_TABLE; // Type structure definition From 020f8a1ba015ec033cda0f1eb07c30cccc430e01 Mon Sep 17 00:00:00 2001 From: Anne Marije v/d Meer Date: Wed, 9 Apr 2014 11:21:28 +0200 Subject: [PATCH 08/14] Move methods to pyGUIControl to pyGUIControlTextBox. --- .../FeatureLib/pfPython/pyGUIControl.cpp | 30 +++++++++++++++++++ .../Plasma/FeatureLib/pfPython/pyGUIControl.h | 2 ++ .../FeatureLib/pfPython/pyGUIControlGlue.cpp | 19 ++++++++++++ .../pfPython/pyGUIControlTextBox.cpp | 29 ------------------ .../FeatureLib/pfPython/pyGUIControlTextBox.h | 3 +- .../pfPython/pyGUIControlTextBoxGlue.cpp | 17 ----------- 6 files changed, 52 insertions(+), 48 deletions(-) diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControl.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControl.cpp index 2e9abc65..388851bb 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControl.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControl.cpp @@ -444,3 +444,33 @@ 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; + } + } +} + +UInt8 pyGUIControl::GetFontFlags() +{ + 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; +} + diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControl.h b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControl.h index 7444495b..b445a27c 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControl.h +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControl.h @@ -121,12 +121,14 @@ public: virtual PyObject* GetBackColor(); // returns pyColor virtual PyObject* GetBackSelColor(); // returns pyColor virtual UInt32 GetFontSize(); + virtual UInt8 GetFontFlags(); // 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); }; diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlGlue.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlGlue.cpp index 935e8d06..932e771b 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlGlue.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlGlue.cpp @@ -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 diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBox.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBox.cpp index 961a8f81..fecd6c43 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBox.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBox.cpp @@ -215,32 +215,3 @@ UInt8 pyGUIControlTextBox::GetJustify() return pfGUIListText::kLeftJustify; } -void pyGUIControlTextBox::SetFontFlags(UInt8 fontFlags) -{ - if (fGCkey) - { - // get the pointer to the modifier - pfGUITextBoxMod* ptbmod = pfGUITextBoxMod::ConvertNoRef(fGCkey->ObjectIsLoaded()); - if (ptbmod) - { - pfGUIColorScheme* colorscheme = ptbmod->GetColorScheme(); - colorscheme->fFontFlags = fontFlags; - ptbmod->UpdateColorScheme(); - } - } -} - -UInt8 pyGUIControlTextBox::GetFontFlags() -{ - if (fGCkey) - { - // get the pointer to the modifier - pfGUITextBoxMod* ptbmod = pfGUITextBoxMod::ConvertNoRef(fGCkey->ObjectIsLoaded()); - if (ptbmod) - { - pfGUIColorScheme* colorscheme = ptbmod->GetColorScheme(); - return colorscheme->fFontFlags; - } - } - return 0; -} diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBox.h b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBox.h index a11076fd..fdc0565a 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBox.h +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBox.h @@ -88,10 +88,9 @@ public: virtual void SetForeColor( pyColor& color ); virtual void SetBackColor( pyColor& color ); virtual void SetJustify( UInt8 justify ); - virtual void SetFontFlags(UInt8 fontflags); + virtual UInt8 GetJustify(); virtual PyObject* GetForeColor(); // returns pyColor - virtual UInt8 GetFontFlags(); }; #endif // _pyGUIControlTextBox_h_ diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBoxGlue.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBoxGlue.cpp index 6dd3ddf3..c20de702 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBoxGlue.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControlTextBoxGlue.cpp @@ -185,22 +185,7 @@ PYTHON_METHOD_DEFINITION(ptGUIControlTextBox, setStringJustify, args) PYTHON_RETURN_NONE; } -PYTHON_METHOD_DEFINITION(ptGUIControlTextBox, 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_NOARGS(ptGUIControlTextBox, getFontFlags) -{ - return PyInt_FromLong(self->fThis->GetFontFlags()); -} PYTHON_METHOD_DEFINITION_NOARGS(ptGUIControlTextBox, getStringJustify) { @@ -221,10 +206,8 @@ PYTHON_START_METHODS_TABLE(ptGUIControlTextBox) PYTHON_METHOD(ptGUIControlTextBox, setForeColor, "Params: color\nSets the text forecolor to 'color', which is a ptColor object."), PYTHON_METHOD(ptGUIControlTextBox, setBackColor, "Params: color\nSets the text backcolor to 'color', which is a ptColor object."), PYTHON_METHOD(ptGUIControlTextBox, setStringJustify, "Params: justify\nSets current justify"), - PYTHON_METHOD(ptGUIControlTextBox, setFontFlags, "Params: fontflags\nSets current fontflags"), PYTHON_METHOD_NOARGS(ptGUIControlTextBox, getStringJustify, "Returns current justify"), PYTHON_METHOD_NOARGS(ptGUIControlTextBox, getForeColor, "Returns the current forecolor"), - PYTHON_METHOD_NOARGS(ptGUIControlTextBox, getFontFlags, "Returns the current fontflags"), PYTHON_END_METHODS_TABLE; // Type structure definition From c0b63e4237690aeb8f47eca14540d8ef0bec21bb Mon Sep 17 00:00:00 2001 From: Christian Walther Date: Thu, 10 Apr 2014 22:59:37 +0200 Subject: [PATCH 09/14] Fix ptGUIControl.setFontFlags(). Previous revision didn't work, many controls retained their shadows because they never got the new flags from the color scheme and put them into the dynamic text map. I haven't checked if any more of the many control classes are affected, but those that we need in the KI right now are covered. --- .../Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.h | 2 ++ .../Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.cpp | 4 ++++ .../Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.h | 2 ++ .../Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUITextBoxMod.h | 2 -- .../Sources/Plasma/FeatureLib/pfPython/pyGUIControl.cpp | 1 + 5 files changed, 9 insertions(+), 2 deletions(-) diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.h b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.h index ad5f99ce..4cfacfd2 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.h +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIControlMod.h @@ -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() {;} diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.cpp index 0fc191f9..8d88f1a7 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.cpp @@ -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 ) ? false : true ); + ICalcWrapStarts(); ICalcScrollRange(); fReadyToRoll = true; diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.h b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.h index 5cec0570..3e322151 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.h +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMultiLineEditCtrl.h @@ -216,6 +216,8 @@ class pfGUIMultiLineEditCtrl : public pfGUIControlMod virtual void PurgeDynaTextMapImage(); + virtual void UpdateColorScheme() { fFontFlagsSet = 0; pfGUIControlMod::UpdateColorScheme(); } + // Extended event types enum ExtendedEvents { diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUITextBoxMod.h b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUITextBoxMod.h index 232ead11..202a7f6f 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUITextBoxMod.h +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUITextBoxMod.h @@ -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 diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControl.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControl.cpp index 388851bb..5ab48669 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControl.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControl.cpp @@ -455,6 +455,7 @@ void pyGUIControl::SetFontFlags(UInt8 fontFlags) { pfGUIColorScheme* colorscheme = pdmod->GetColorScheme(); colorscheme->fFontFlags = fontFlags; + pdmod->UpdateColorScheme(); } } } From 192e4a252c7d7eee82b0e1811243352892b8f221 Mon Sep 17 00:00:00 2001 From: Anne Marije v/d Meer Date: Fri, 25 Apr 2014 11:57:33 +0200 Subject: [PATCH 10/14] Fix comment Hoikas --- .../Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.cpp index 8d88f1a7..4ab10cab 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIListBoxMod.cpp @@ -182,7 +182,7 @@ void pfGUIListBoxMod::IPostSetUpDynTextMap( void ) { pfGUIColorScheme *scheme = GetColorScheme(); fDynTextMap->SetFont( scheme->fFontFace, scheme->fFontSize, scheme->fFontFlags, - HasFlag( kXparentBgnd ) ? false : true ); + !HasFlag( kXparentBgnd )); ICalcWrapStarts(); ICalcScrollRange(); From 6b2dedf5473bf3fe6cc036ee1d9931aef04bc72a Mon Sep 17 00:00:00 2001 From: Christian Walther Date: Sat, 12 Apr 2014 10:22:07 +0200 Subject: [PATCH 11/14] Make font flags available to Python in PlasmaConstants. --- .../Plasma/FeatureLib/pfPython/pyDynamicTextGlue.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyDynamicTextGlue.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyDynamicTextGlue.cpp index 134809c6..bbdfbd60 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyDynamicTextGlue.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyDynamicTextGlue.cpp @@ -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); } \ No newline at end of file From d1c86267b3fdaab02eaa45a1045cf2f4aa591e3a Mon Sep 17 00:00:00 2001 From: Anne Marije v/d Meer Date: Fri, 25 Apr 2014 12:17:47 +0200 Subject: [PATCH 12/14] Const getters --- .../Plasma/FeatureLib/pfPython/pyGUIControl.cpp | 12 ++++++------ .../Plasma/FeatureLib/pfPython/pyGUIControl.h | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControl.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControl.cpp index 5ab48669..a7160ba4 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControl.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControl.cpp @@ -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 ) { @@ -460,7 +460,7 @@ void pyGUIControl::SetFontFlags(UInt8 fontFlags) } } -UInt8 pyGUIControl::GetFontFlags() +UInt8 pyGUIControl::GetFontFlags() const { if (fGCkey) { diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControl.h b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControl.h index b445a27c..d5b9ee46 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControl.h +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyGUIControl.h @@ -116,12 +116,12 @@ 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 UInt8 GetFontFlags(); + 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 ); From 9c609b9fd818d4ff4c9ff56cf434151e2a8a9ec8 Mon Sep 17 00:00:00 2001 From: Christian Walther Date: Sat, 7 Jun 2014 18:22:41 +0200 Subject: [PATCH 13/14] Modulate text shadow opacity by the alpha of the text color to make the player lists fade properly. Also, the text of the faded-out player list is re-rendered with alpha == 0 every time the mouse enters its area, do a little less needless work in that case. --- .../Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp index c651409a..caeb9606 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp @@ -1119,6 +1119,8 @@ void plFont::IRenderChar8To32AlphaPremShadow( const plFont::plCharacter &c ) xstart = -2; srcA = (UInt8)(( fRenderInfo.fColor >> 24 ) & 0x000000ff); + if (srcA == 0) + return; srcR = (UInt8)(( fRenderInfo.fColor >> 16 ) & 0x000000ff); srcG = (UInt8)(( fRenderInfo.fColor >> 8 ) & 0x000000ff); srcB = (UInt8)(( fRenderInfo.fColor ) & 0x000000ff); @@ -1160,7 +1162,10 @@ void plFont::IRenderChar8To32AlphaPremShadow( const plFont::plCharacter &c ) sa = clamp; UInt32 a = IGetCharPixel(c, x, y); if (srcA != 0xff) + { a = (srcA * a + 127) / 255; + sa = (srcA * sa + 127) / 255; + } UInt32 ta = a + sa - ((a*sa + 127) / 255); if (ta > (destPtr[ x ] >> 24)) destPtr[ x ] = ( ta << 24 ) | (((srcR * a + 127) / 255) << 16) | From 21e2a6de7b327136f241c2c95937c59103597dfc Mon Sep 17 00:00:00 2001 From: Christian Walther Date: Sat, 23 Aug 2014 21:10:55 +0200 Subject: [PATCH 14/14] Fix MSVC7 warnings. --- .../Sources/Plasma/PubUtilLib/plGImage/plFont.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp index caeb9606..4e8eacf3 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp @@ -867,7 +867,7 @@ void plFont::IRenderChar8To32( const plFont::plCharacter &c ) // difference, especially since the dest pixels that we end up overlapping // should already be in the cache. If it does, time to upgrade the font // format (again) - thisWidth = fWidth;// + (Int32)c.fRightKern; + thisWidth = (Int16)fWidth;// + (Int32)c.fRightKern; if( thisWidth >= fRenderInfo.fMaxWidth ) thisWidth = fRenderInfo.fMaxWidth; @@ -941,7 +941,7 @@ void plFont::IRenderChar8To32FullAlpha( const plFont::plCharacter &c ) // difference, especially since the dest pixels that we end up overlapping // should already be in the cache. If it does, time to upgrade the font // format (again) - thisWidth = fWidth;// + (Int32)c.fRightKern; + thisWidth = (Int16)fWidth;// + (Int32)c.fRightKern; if( thisWidth >= fRenderInfo.fMaxWidth ) thisWidth = fRenderInfo.fMaxWidth; @@ -992,7 +992,7 @@ void plFont::IRenderChar8To32Alpha( const plFont::plCharacter &c ) // difference, especially since the dest pixels that we end up overlapping // should already be in the cache. If it does, time to upgrade the font // format (again) - thisWidth = fWidth;// + (Int32)c.fRightKern; + thisWidth = (Int16)fWidth;// + (Int32)c.fRightKern; if( thisWidth >= fRenderInfo.fMaxWidth ) thisWidth = fRenderInfo.fMaxWidth; @@ -1052,7 +1052,7 @@ void plFont::IRenderChar8To32AlphaPremultiplied( const plFont::plCharacter &c ) // difference, especially since the dest pixels that we end up overlapping // should already be in the cache. If it does, time to upgrade the font // format (again) - thisWidth = fWidth;// + (Int32)c.fRightKern; + thisWidth = (Int16)fWidth;// + (Int32)c.fRightKern; if( thisWidth >= fRenderInfo.fMaxWidth ) thisWidth = fRenderInfo.fMaxWidth; @@ -1110,7 +1110,7 @@ void plFont::IRenderChar8To32AlphaPremShadow( const plFont::plCharacter &c ) // difference, especially since the dest pixels that we end up overlapping // should already be in the cache. If it does, time to upgrade the font // format (again) - thisWidth = fWidth + 2;// + (Int32)c.fRightKern; + thisWidth = (Int16)fWidth + 2;// + (Int32)c.fRightKern; if( thisWidth >= fRenderInfo.fMaxWidth ) thisWidth = fRenderInfo.fMaxWidth;