// ------------------------------------------------------------------------------------------------ // ___ __ ___ ___ ® // Copyright © 2009-2010, All rights reserved __)| /\ \__|| / \ / | / // Playlogic games factory, Breda | |___/__\ __||___\__/ \__| | \___ // // ------------------------------------------------------------------------------------------------ #include "PLBase.h" #include "PLTextTextureResource.h" FPLTextTextureResource::FPLTextTextureResource( const class UPLTextTexture* InOwner ) : FTextureRenderTarget2DResource( InOwner ) , Owner( InOwner ) { if ( InOwner != NULL ) { TextLines = InOwner->TextLines; TextSizeX = appTrunc( InOwner->TextSize.X ); TextSizeY = appTrunc( InOwner->TextSize.Y ); TextColor = FLinearColor( InOwner->TextColor ); BackgroundColor = FLinearColor( InOwner->BackgroundColor ); bMaskedText = InOwner->bMaskedText; } } void FPLTextTextureResource::UpdateResource() { // clear the target surface RHISetRenderTarget(RenderTargetSurfaceRHI,FSurfaceRHIRef()); RHISetViewport(0,0,0.0f,TextSizeX,TextSizeY,1.0f); RHIClear(TRUE,BackgroundColor,FALSE,0.f,FALSE,0); FCanvas Canvas( this, NULL ); if ( Owner != NULL && Owner->TextFont != NULL ) { // Render the text onto the canvas UFont* TextFont = Owner->TextFont; FLOAT Y = 0.0f; for ( TArray< FString >::TIterator Text( TextLines ); Text; ++Text ) { INT Size = TextFont->GetStringSize( **Text ); DrawString( &Canvas, TextSizeX * 0.5f - Size * 0.5f, Y, **Text, TextFont, TextColor, 1.0, 1.0, 0.0, NULL, bMaskedText ? SE_BLEND_Masked : SE_BLEND_Translucent ); Y += TextFont->GetMaxCharHeight(); } } // Flush the canvas Canvas.Flush(); // copy surface to the texture for use RHICopyToResolveTarget(RenderTargetSurfaceRHI, TRUE, FResolveParams()); }