This commit is contained in:
nephacks
2025-06-04 03:22:50 +02:00
parent f234f23848
commit f12416cffd
14243 changed files with 6446499 additions and 26 deletions

209
scaleformui/scaleformui.vpc Normal file
View File

@@ -0,0 +1,209 @@
//-----------------------------------------------------------------------------
// SCALEFORMUI.VPC
//
// Project Script
//-----------------------------------------------------------------------------
$macro SRCDIR ".."
$Macro OUTBINDIR "$SRCDIR\..\game\bin"
$include "$SRCDIR\vpc_scripts\source_dll_base.vpc"
$IgnoreRedundancyWarning "ON"
// @wge: Because vpc make file generator doesn't care about $AdditionalDependencies, we need to manually switch the lib for OSX.
// NOTE: This can only be "Shipping" or "Debug" and the value of GFXBUILDSHIPPING_OSX must match or things will fail horribly.
$Macro GFXCONFIG_OSX "Shipping"
$Conditional GFXBUILDSHIPPING_OSX 1
$Macro GFXCONFIG_LINUX "shipping" // On linux we need to help with the path
$Conditional GFXBUILDSHIPPING_LINUX 1 // 1 Turns off AMP and pix markers
// Set the following to 1 to link including Scaleform AMP profiling tools (game must be launched with "-sfstats")
// If 0 then in Release we define SF_BUILD_SHIPPING and link to the Shipping libs.
// Set to 0 in pc-beta! It is set to 1 in trunk so that we can track SFVALUE still holding reference to AS object when releasing a movie
$Conditional ENABLE_AMP_SERVER 1 [$WINDOWS]
$Conditional ENABLE_AMP_SERVER 0 [!$WINDOWS]
$Macro WINPLATDIR win32 [$WIN32]
$Macro WINPLATDIR x64 [$WIN64]
//-----------------------------------------------------------------------------
// Scaleform defines
$Macro GFXLIB "$SRCDIR\thirdparty\scaleform\sdk42\Lib\$WINPLATDIR\msvc10" [$WINDOWS]
$Macro GFXLIB "$SRCDIR\thirdparty\scaleform\sdk42\Lib\MacOS-i686" [$OSX32]
$Macro GFXLIB "$SRCDIR\thirdparty\scaleform\sdk42\Lib\MacOS-x86_64" [$OSX64]
$Macro GFXLIB "$SRCDIR\thirdparty\scaleform\sdk42\Lib\i386-linux" [$LINUX32]
$Macro GFXLIB "$SRCDIR\thirdparty\scaleform\sdk42\Lib\x86_64-linux" [$LINUX64]
$Macro LIBJPEG "$SRCDIR\thirdparty\scaleform\sdk42\3rdParty\jpeg-8d\lib\$WINPLATDIR\msvc10" [$WINDOWS && !$VS2015]
$Macro LIBJPEG "$SRCDIR\thirdparty\scaleform\sdk42\3rdParty\jpeg-8d\lib\$WINPLATDIR\msvc15" [$WINDOWS && $VS2015]
$Macro LIBPNG "$SRCDIR\thirdparty\scaleform\sdk42\3rdParty\libpng-1.5.13\Lib\$WINPLATDIR\msvc10" [$WINDOWS && !$VS2015]
$Macro LIBPNG "$SRCDIR\thirdparty\scaleform\sdk42\3rdParty\libpng-1.5.13\Lib\$WINPLATDIR\msvc15" [$WINDOWS && $VS2015]
$Macro ZLIB "$SRCDIR\thirdparty\scaleform\sdk42\3rdParty\zlib-1.2.7\Lib\$WINPLATDIR\msvc10" [$WINDOWS]
//-----------------------------------------------------------------------------
$Configuration
{
$Compiler
{
$AdditionalIncludeDirectories "$BASE;$SRCDIR\scaleformui;$SRCDIR\thirdparty\scaleform\sdk42\Include;$SRCDIR\thirdparty\scaleform\sdk42\Src;$SRCDIR\thirdparty"
$AdditionalIncludeDirectories "$BASE;$SRCDIR\dx9sdk\Include" [$WINDOWS && !$GL]
$AdditionalIncludeDirectories "$BASE;$SRCDIR\common\gl" [$GL]
$PreprocessorDefinitions "$BASE;INCLUDE_SCALEFORM;ENABLE_AMP_SERVER=$ENABLE_AMP_SERVER"
$PreprocessorDefinitions "$BASE;VERSION_SAFE_STEAM_API_INTERFACES"
$PreprocessorDefinitions "$BASE;USE_ACTUAL_DX" [( $WINDOWS || $X360 ) && !$GL]
$PreprocessorDefinitions "$BASE;strncpy=use_Q_strncpy_instead;_snprintf=use_Q_snprintf_instead" [!$POSIX]
$PreprocessorDefinitions "$BASE;GL_GLEXT_PROTOTYPES;DX_TO_GL_ABSTRACTION" [$GL]
$PreprocessorDefinitions "$BASE;ALLOW_TEXT_MODE=1" [$CSTRIKE_TRUNK_BUILD||$CSTRIKE_STAGING_BUILD]
$EnableC++Exceptions "Yes (/EHsc)"
}
$Linker
{
$AdditionalDependencies "$BASE winmm.lib libgfx.lib libgfx_as2.lib libgfx_as3.lib libgfxexpat.lib libgfx_ime.lib libgfxvideo.lib libjpeg.lib zlib.lib libpng.lib Ws2_32.lib imm32.lib oleaut32.lib" [$WINDOWS]
$AdditionalDependencies "$BASE libgfxplatform_d3d9.lib libgfxrender_d3d9.lib" [$WINDOWS && !$GL]
$AdditionalDependencies "$BASE OpenGL32.lib libgfxplatform_GL.lib libgfxrender_GL.lib" [$GL]
$AdditionalDependencies "$BASE legacy_stdio_definitions.lib" [$WINDOWS && $VS2015]
$AdditionalLibraryDirectories "$BASE;$GFXLIB" [$PS3 || $OSXALL || $LINUX]
$SystemLibraries "GL" [$LINUXALL]
}
}
$Configuration "Debug"
{
$Compiler [($LINUX && $GFXBUILDSHIPPING_LINUX) || ($OSXALL && $GFXBUILDSHIPPING_OSX)]
{
$PreprocessorDefinitions "$BASE;SF_BUILD_SHIPPING"
}
$Compiler [($LINUX && !$GFXBUILDSHIPPING_LINUX) || ($OSXALL && !$GFXBUILDSHIPPING_OSX)]
{
$PreprocessorDefinitions "$BASE;SF_BUILD_DEBUG"
}
$Linker [$WINDOWS]
{
$AdditionalLibraryDirectories "$BASE;$GFXLIB\debug;$LIBJPEG\debug;$LIBPNG\debug;$ZLIB\debug"
}
}
$Configuration "Release"
{
$Compiler [($LINUX && $GFXBUILDSHIPPING_LINUX) || ($OSXALL && $GFXBUILDSHIPPING_OSX)]
{
$PreprocessorDefinitions "$BASE;SF_BUILD_SHIPPING"
}
$Compiler [($LINUX && !$GFXBUILDSHIPPING_LINUX) || ($OSXALL && !$GFXBUILDSHIPPING_OSX)]
{
$PreprocessorDefinitions "$BASE;SF_BUILD_RELEASE"
}
$Compiler [$WINDOWS]
{
$PreprocessorDefinitions "$BASE;SF_BUILD_SHIPPING" [!$ENABLE_AMP_SERVER]
}
$Linker [$WINDOWS]
{
$AdditionalLibraryDirectories "$BASE;$GFXLIB\release" [$ENABLE_AMP_SERVER]
$AdditionalLibraryDirectories "$BASE;$GFXLIB\shipping" [!$ENABLE_AMP_SERVER]
$AdditionalLibraryDirectories "$BASE;$LIBJPEG\release;$LIBPNG\release;$ZLIB\release"
}
}
$Configuration
{
$Linker [$OSXALL]
{
$SystemFrameworks "Carbon;OpenGL;Quartz;Cocoa;IOKit"
$SystemLibraries "iconv;z"
$AdditionalLibraryDirectories "$BASE;$GFXLIB\$GFXCONFIG_OSX"
$AdditionalDependencies "$BASE $GFXLIB\$GFXCONFIG_OSX\libgfx.a $GFXLIB\libjpeg.a $GFXLIB\libpng.a"
}
}
$Project "ScaleformUI"
{
$Folder "Public Header Files"
{
}
$Folder "Scaleform" [!$DEDICATED]
{
$Folder "Public Header Files"
{
$File "$SRCDIR\public\scaleformui\scaleformui.h"
$File "$SRCDIR\public\tier1\interface.h"
}
$Folder "Precompiled Header Files"
{
$File "stdafx.h"
$File "stdafx.cpp"
}
$Folder "ScaleformUIImpl"
{
$File "scaleformuiimpl\sfuimemoryfile.h"
$File "scaleformuiimpl\movieslot.h"
$File "scaleformuiimpl\movieslot.cpp"
$File "scaleformuiimpl\scaleformuiimpl.h"
$File "scaleformuiimpl\scaleformuicursorimpl.cpp"
$File "scaleformuiimpl\scaleformuihighlevelimpl.cpp"
$File "scaleformuiimpl\scaleformuiinitimpl.cpp"
$File "scaleformuiimpl\scaleformuimovieimpl.cpp"
$File "scaleformuiimpl\scaleformuimovieslotimpl.cpp"
$File "scaleformuiimpl\scaleformuiparamsimpl.cpp"
$File "scaleformuiimpl\scaleformuirendererimpl.cpp"
$File "scaleformuiimpl\scaleformuitranslationimpl.cpp"
$File "scaleformuiimpl\scaleformuivalueimpl.cpp"
$File "scaleformuiimpl\scaleformuiintegration.cpp"
$File "scaleformuiimpl\scaleformuitextobjimpl.cpp"
$File "scaleformuiimpl\scaleformuiintegration.h"
$File "scaleformuiimpl\scaleformuiimage.cpp"
$File "scaleformuiimpl\scaleformuiimage.h"
$File "scaleformuiimpl\sfuiavatarimage.cpp"
$File "scaleformuiimpl\sfuiavatarimage.h"
$File "scaleformuiimpl\sfuichromehtmlimage.cpp"
$File "scaleformuiimpl\sfuichromehtmlimage.h"
$File "scaleformuiimpl\sfuiinventoryimage.cpp"
$File "scaleformuiimpl\sfuiinventoryimage.h"
$File "$SRCDIR\game\shared\cstrike15\dlchelper.h"
}
}
$Folder "Link Libraries"
{
$Lib "mathlib"
$Lib "bitmap"
$Lib "tier2"
$Lib "tier3"
$Lib "vtf"
$LibExternal "$GFXLIB\$GFXCONFIG_LINUX\libgfx" [$LINUX && !$DEDICATED]
$LibExternal "$GFXLIB\$GFXCONFIG_LINUX\libgfxplatform" [$LINUX && !$DEDICATED]
$LibExternal "$GFXLIB\$GFXCONFIG_LINUX\libgfx_as2" [$LINUX && !$DEDICATED]
$LibExternal "$GFXLIB\$GFXCONFIG_LINUX\libgfxexpat" [$LINUX && !$DEDICATED]
$LibExternal "$GFXLIB\$GFXCONFIG_LINUX\libgfxrender_gl" [$LINUX && !$DEDICATED]
$LibExternal "$GFXLIB\$GFXCONFIG_OSX\libgfx" [$OSXALL]
$LibExternal "$GFXLIB\$GFXCONFIG_OSX\libgfxplatform" [$OSXALL]
$LibExternal "$GFXLIB\$GFXCONFIG_OSX\libgfx_as2" [$OSXALL]
$LibExternal "$GFXLIB\$GFXCONFIG_OSX\libgfxrender_gl" [$OSXALL]
$LibExternal "$GFXLIB\libjpeg" [($OSXALL || $LINUX) && !$DEDICATED]
$LibExternal "$GFXLIB\libpng" [($OSXALL || $LINUX) && !$DEDICATED]
$LibExternal "$GFXLIB\libz" [$LINUX && !$DEDICATED]
$Lib "videocfg" [$OSXALL]
$ImplibExternal steam_api [ ( $WIN32 || $POSIX || $PS3 ) && !$NO_STEAM ]
$ImplibExternal steam_api64 [ $WIN64 && !$NO_STEAM ]
$ImpLib togl [!$IS_LIB_PROJECT && $GL && !$DEDICATED]
$File "$SRCDIR\dx9sdk\lib$PLATSUBDIR\d3d9.lib" [$WINDOWS && !$GL]
$File "$SRCDIR\dx9sdk\lib$PLATSUBDIR\d3dx9.lib" [$WINDOWS && !$GL]
$File "$SRCDIR\dx9sdk\lib$PLATSUBDIR\dxguid.lib" [$WINDOWS && !$GL]
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,207 @@
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#if !defined( MOVIESLOT_H_ )
#define MOVIESLOT_H_
class ScaleformUIImpl;
#include "UtlStringMap.h"
class BaseSlot
{
public:
SF::GFx::MovieDef* m_pMovieDef;
SF::GFx::Movie* m_pMovieView;
SF::GFx::Value m_GlobalValue;
SF::GFx::Value m_GameAPI;
CUtlStringMap< SF::GFx::Value * > m_mapGlobalObjects;
int m_iSlot;
int m_iRefCount;
bool m_bControllerUI;
float m_fChangeControllerTimeout;
protected:
enum CVAR_TYPE_WANTED
{
CVAR_WANT_NUMBER,
CVAR_WANT_NUMBER_MIN,
CVAR_WANT_NUMBER_MAX,
CVAR_WANT_STRING,
CVAR_WANT_BOOL,
};
void GetConvar( SF::GFx::FunctionHandler::Params* params, CVAR_TYPE_WANTED typeWanted );
bool ConvertValue( SF::GFx::Value *value, KeyValues* kv );
void PopulateObject( SF::GFx::Value* value, KeyValues* kv );
const char* PopulateArray( SF::GFx::Value* value, KeyValues* kv );
public:
BaseSlot();
void CreateKeyTable();
void Init( const char* movieName, int slot );
void UpdateSafeZone( void );
void UpdateTint( void );
void AddRef( void );
bool Release( void );
void LoadKVFile( SCALEFORM_CALLBACK_ARGS_DECL );
void SaveKVFile( SCALEFORM_CALLBACK_ARGS_DECL );
void GetConvarNumber( SCALEFORM_CALLBACK_ARGS_DECL );
void GetConvarNumberMin( SCALEFORM_CALLBACK_ARGS_DECL );
void GetConvarNumberMax( SCALEFORM_CALLBACK_ARGS_DECL );
void GetConvarString( SCALEFORM_CALLBACK_ARGS_DECL );
void GetConvarBoolean( SCALEFORM_CALLBACK_ARGS_DECL );
void GetPlayerColorObject( SCALEFORM_CALLBACK_ARGS_DECL );
void SetConvar( SCALEFORM_CALLBACK_ARGS_DECL );
void Translate( SCALEFORM_CALLBACK_ARGS_DECL );
void ReplaceGlyphs( SCALEFORM_CALLBACK_ARGS_DECL );
void GetPAXAvatarFromName(SCALEFORM_CALLBACK_ARGS_DECL);
void SendUIEvent( SCALEFORM_CALLBACK_ARGS_DECL );
void GetClipboardText( SCALEFORM_CALLBACK_ARGS_DECL );
void SetClipboardText( SCALEFORM_CALLBACK_ARGS_DECL );
void MakeStringSafe( SCALEFORM_CALLBACK_ARGS_DECL );
bool HandleCharTyped( const wchar_t* typed, int slost );
bool HandleKeyEvent( bool keyDown, ButtonCode_t code, ButtonCode_t vkey, const char* binding, int slot );
void LockInputToSlot( int slot );
void UnlockInput( void );
bool SetToControllerUI( bool value, bool isKeyOrButtonPress );
bool IsSetToControllerUI( void );
void Advance( float time );
void LockMostRecentInputDevice( void );
void ConsoleCommand( SCALEFORM_CALLBACK_ARGS_DECL );
void ConsoleCommandExecute( SCALEFORM_CALLBACK_ARGS_DECL );
void ForceCollectGarbage( void );
virtual void RequestElement( const char* elementName, ScaleformUIFunctionHandlerObject* object, const IScaleformUIFunctionHandlerDefinitionTable* tableObject )
{
}
virtual void RemoveElement( SF::GFx::Value* element )
{
}
virtual void InstallGlobalObject( const char* elementName, ScaleformUIFunctionHandlerObject* object, const IScaleformUIFunctionHandlerDefinitionTable* tableObject, SF::GFx::Value* *pInstalledGlobalObjectResult )
{
}
virtual void RemoveGlobalObject( SF::GFx::Value* element )
{
}
virtual const ScaleformUIFunctionHandlerDefinition* GetSlotAPITable( void )
{
return NULL;
}
virtual bool ConsumesInputEvents( void )
{
return true;
}
// SF4 TODO
// We create slot 2 while loading the map and start calling advance on it. However, the qms doesn't call
// render very often during this phase so the advance gets too far ahead of the renderer which causes SF
// internal buffers to fill up. This is a hack to work around this and might need to be done differently
volatile uint32 m_advanceCount;
protected:
virtual void Unload( void );
};
class MovieSlot: public BaseSlot
{
public:
int m_iNumInputConsumers;
bool m_bDisableAnalogNavigation;
public:
MovieSlot();
public:
void RequestElement( const char* elementName, ScaleformUIFunctionHandlerObject* object, const IScaleformUIFunctionHandlerDefinitionTable* tableObject );
void RemoveElement( SF::GFx::Value* element );
void InstallGlobalObject( const char* elementName, ScaleformUIFunctionHandlerObject* object, const IScaleformUIFunctionHandlerDefinitionTable* tableObject, SF::GFx::Value* *pInstalledGlobalObjectResult );
void RemoveGlobalObject( SF::GFx::Value* element );
const ScaleformUIFunctionHandlerDefinition* GetSlotAPITable();
bool ConsumesInputEvents( void )
{
return m_iNumInputConsumers > 0;
}
public:
void AddInputConsumer( SCALEFORM_CALLBACK_ARGS_DECL );
void RemoveInputConsumer( SCALEFORM_CALLBACK_ARGS_DECL );
void DenyInputToGameFromFlash( SCALEFORM_CALLBACK_ARGS_DECL );
void SetCursorShape( SCALEFORM_CALLBACK_ARGS_DECL );
void ShowCursor( SCALEFORM_CALLBACK_ARGS_DECL );
void HideCursor( SCALEFORM_CALLBACK_ARGS_DECL );
void PlaySoundScaleform( SCALEFORM_CALLBACK_ARGS_DECL );
void DisableAnalogStickNavigation( SCALEFORM_CALLBACK_ARGS_DECL );
bool AnalogStickNavigationDisabled( void );
#if defined( _PS3 )
void PS3UseMoveCursor( SCALEFORM_CALLBACK_ARGS_DECL );
void PS3UseStandardCursor( SCALEFORM_CALLBACK_ARGS_DECL );
void PS3ForceCursorStart( SCALEFORM_CALLBACK_ARGS_DECL );
void PS3ForceCursorEnd( SCALEFORM_CALLBACK_ARGS_DECL );
#endif
};
class CursorSlot: public BaseSlot
{
bool m_bUIHidden;
public:
CursorSlot() :
m_bUIHidden( true )
{
}
void SetCursorShape( int shape );
void Hide( void );
void Show( void );
virtual bool IsHidden( void )
{
return m_bUIHidden;
}
virtual bool IsVisible( void )
{
return !m_bUIHidden;
}
};
#endif /* MOVIESLOT_H_ */

View File

@@ -0,0 +1,239 @@
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "stdafx.h"
#if defined( _OSX )
//#include "appframework/icocoamgr.h"
//extern ICocoaMgr *g_extCocoaMgr;
#endif
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
using namespace SF::GFx;
ConVar sfcursortimeout( "cursortimeout", "60.0", FCVAR_ARCHIVE, "Seconds before mouse cursor hides itself due to inactivity" );
void ScaleformUIImpl::InitCursorImpl( void )
{
m_fCursorTimeUntilHide = sfcursortimeout.GetFloat();
m_iWantCursorShown = 0;
m_loadedCursorImage = CURSOR_IMAGE_NONE;
m_isCursorForced = false;
}
void ScaleformUIImpl::ShutdownCursorImpl( void )
{
}
void ScaleformUIImpl::InitCursor( const char* cursorMovie )
{
// gurjeets - locks commented out, left here for reference, see comment in LockSlotPtr
//m_SlotMutexes[SF_RESERVED_CURSOR_SLOT].Lock();
if ( !m_SlotPtrs[SF_RESERVED_CURSOR_SLOT] )
{
CursorSlot* slotPtr = new CursorSlot();
m_SlotPtrs[SF_RESERVED_CURSOR_SLOT] = slotPtr;
slotPtr->Init( cursorMovie, SF_RESERVED_CURSOR_SLOT );
if ( ConsumesInputEvents() )
{
slotPtr->Hide();
slotPtr->Show();
m_fCursorTimeUntilHide = sfcursortimeout.GetFloat();
}
else
{
slotPtr->Show();
slotPtr->Hide();
m_fCursorTimeUntilHide = 0;
}
}
else
{
m_SlotPtrs[SF_RESERVED_CURSOR_SLOT]->AddRef();
}
// gurjeets - locks commented out, left here for reference, see comment in LockSlotPtr
//m_SlotMutexes[SF_RESERVED_CURSOR_SLOT].Unlock();
}
void ScaleformUIImpl::SetCursorViewport( int x, int y, int width, int height )
{
SetSlotViewport( SF_RESERVED_CURSOR_SLOT, x, y, width, height );
}
void ScaleformUIImpl::ReleaseCursor( void )
{
SlotRelease( SF_RESERVED_CURSOR_SLOT );
}
bool ScaleformUIImpl::IsCursorVisible( void )
{
bool result = false;
CursorSlot* pslot = ( CursorSlot* )m_SlotPtrs[ SF_RESERVED_CURSOR_SLOT ];
if ( pslot )
{
result = pslot->IsVisible();
}
return result;
}
void ScaleformUIImpl::RenderCursor( void )
{
RenderSlot( SF_RESERVED_CURSOR_SLOT );
}
void ScaleformUIImpl::AdvanceCursor( void )
{
AdvanceSlot( SF_RESERVED_CURSOR_SLOT );
}
void ScaleformUIImpl::SetCursorShape( int shapeIndex )
{
CursorSlot* pslot = ( CursorSlot* ) LockSlotPtr( SF_RESERVED_CURSOR_SLOT );
if ( pslot )
{
pslot->SetCursorShape( shapeIndex );
}
UnlockSlotPtr( SF_RESERVED_CURSOR_SLOT );
}
void ScaleformUIImpl::UpdateCursorWaitTime( float newTime )
{
if ( ( m_fCursorTimeUntilHide > 0 ) != ( newTime > 0 ) )
{
if ( ( newTime > 0 ) )
{
if ( m_iWantCursorShown )
InnerShowCursor();
}
else
InnerHideCursor();
}
m_fCursorTimeUntilHide = newTime;
}
void ScaleformUIImpl::CursorMoved( void )
{
UpdateCursorWaitTime( sfcursortimeout.GetFloat() );
}
void ScaleformUIImpl::ControllerMoved( void )
{
// the motion calibration screen requires the cursor to remain visible even though it is a 'controller'
if ( !m_isCursorForced )
{
UpdateCursorWaitTime( 0 );
}
}
void ScaleformUIImpl::UpdateCursorLazyHide( float time )
{
UpdateCursorWaitTime( m_fCursorTimeUntilHide - time );
}
void ScaleformUIImpl::InnerShowCursor( void )
{
#if defined( USE_SDL ) || defined( OSX )
m_pLauncherMgr->SetMouseVisible( true );
#endif
m_fCursorTimeUntilHide = sfcursortimeout.GetFloat();
#if defined( _PS3 )
// use hardware cursor, and skip the show call for the standard scaleform cursor
g_pInputSystem->EnableHardwareCursor();
#else
CursorSlot* pslot = ( CursorSlot* ) LockSlotPtr( SF_RESERVED_CURSOR_SLOT );
if ( pslot )
{
pslot->Show();
}
UnlockSlotPtr( SF_RESERVED_CURSOR_SLOT );
#endif
}
void ScaleformUIImpl::InnerHideCursor( void )
{
#if defined( USE_SDL ) || defined( OSX )
m_pLauncherMgr->SetMouseVisible( false );
#endif
MouseEvent mevent( Event::MouseMove, 0, -100, -100 );
DistributeEvent( mevent, 0, true, false );
CursorSlot* pslot = ( CursorSlot* ) LockSlotPtr( SF_RESERVED_CURSOR_SLOT );
if ( pslot )
{
pslot->Hide();
}
#if defined( _OSX )
// [will] - Grab the delta to clear the mouse delta accumulator.
// int x, y;
// g_extCocoaMgr->GetMouseDelta( x, y, true );
#endif
UnlockSlotPtr( SF_RESERVED_CURSOR_SLOT );
}
void ScaleformUIImpl::ShowCursor( void )
{
m_iWantCursorShown++;
ConVarRef cl_mouseenable( "cl_mouseenable" );
cl_mouseenable.SetValue( false );
if ( m_iWantCursorShown && m_fCursorTimeUntilHide > 0 )
{
InnerShowCursor();
SFDevMsg( "ScaleformUIImpl::ShowCursor want=%d cl_mouseenable=false InnerShowCursor\n", m_iWantCursorShown);
}
else
{
SFDevMsg( "ScaleformUIImpl::ShowCursor want=%d cl_mouseenable=false\n", m_iWantCursorShown);
}
}
void ScaleformUIImpl::HideCursor( void )
{
Assert( m_iWantCursorShown > 0 );
m_iWantCursorShown--;
if ( !m_iWantCursorShown )
{
ConVarRef cl_mouseenable( "cl_mouseenable" );
cl_mouseenable.SetValue( true );
InnerHideCursor();
SFDevMsg( "ScaleformUIImpl::HideCursor want=%d cl_mouseenable=true InnerHideCursor\n", m_iWantCursorShown);
}
else
{
ConVarRef cl_mouseenable( "cl_mouseenable" );
SFDevMsg( "ScaleformUIImpl::HideCursor want=%d cl_mouseenable=%s\n", m_iWantCursorShown, cl_mouseenable.GetBool() ? "TRUE" : "FALSE");
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,142 @@
//========= Copyright <20> 1996-2008, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=====================================================================================//
#include "stdafx.h"
#include "scaleformuiimage.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#pragma warning( disable: 4355 ) // disables ' 'this' : used in base member initializer list'
using namespace SF::Render;
//-----------------------------------------------------------------------------
// Purpose: Convert Valve ImageFormat to Scaleform ImageFormat
//-----------------------------------------------------------------------------
SF::Render::ImageFormat ScaleformUIImage::ConvertImageFormat( ::ImageFormat format )
{
SF::Render::ImageFormat dstFormat = Image_R8G8B8A8;
switch ( format )
{
case IMAGE_FORMAT_RGBA8888:
dstFormat = Image_R8G8B8A8;
break;
case IMAGE_FORMAT_BGRA8888:
dstFormat = Image_B8G8R8A8;
break;
case IMAGE_FORMAT_DXT5:
dstFormat = Image_DXT5;
break;
default:
DevMsg("ImageFormat %d not supported by ScaleformUIImage, using RGBA8888!", format);
break;
}
return dstFormat;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
ScaleformUIImage::ScaleformUIImage( const byte* defaultRgba, int defaultWidth, int defaultHeight, ::ImageFormat defaultFormat, SF::GFx::TextureManager* pTextureManager )
{
m_nWidth = defaultWidth;
m_nHeight = defaultHeight;
m_format = defaultFormat;
m_nRefCount = 0;
m_pImage = NULL;
m_pTextureManager = pTextureManager;
// Set the default bits for the texture so we have something to show while the real icon is loading
if ( defaultRgba )
{
InitFromBuffer( defaultRgba, defaultWidth, defaultHeight, defaultFormat );
}
}
ScaleformUIImage::~ScaleformUIImage( void )
{
if ( m_pImage )
{
m_pImage->pImage->Release();
m_pImage->Release();
}
}
void ScaleformUIImage::OnFinalRelease()
{
delete this;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
Image* ScaleformUIImage::GetImage( void )
{
m_pImage->AddRef();
return m_pImage;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void ScaleformUIImage::InitFromBuffer( const byte *rgba, int width, int height, ::ImageFormat format )
{
// Check image updates properly if Steam persona changes
Assert( rgba && width && height );
// See if we need to create a new texture
if ( m_pImage == NULL || width != m_nWidth || height != m_nHeight || format != m_format )
{
const SF::Render::ImageFormat sfFormat = ConvertImageFormat( format );
const unsigned int mipLevelCount = 1;
if ( m_pImage )
{
m_pImage->pImage->Release();
m_pImage->pImage = RawImage::Create( sfFormat, mipLevelCount, ImageSize( width, height), ImageUse_Update, 0, m_pTextureManager );
// apply scaling matrix
SF::GFx::Size<float> scaleParameters( ( (float) m_nWidth ) / width, ( (float) m_nHeight ) / height );
SF::GFx::Matrix2F textureMatrix = SF::GFx::Matrix2F::Scaling( scaleParameters.Width, scaleParameters.Height );
m_pImage->SetMatrix( textureMatrix );
ScaleformUIImpl::m_Instance.ForceUpdateImages();
}
else
{
m_pImage = new ImageDelegate( RawImage::Create( sfFormat, mipLevelCount, ImageSize( width, height), ImageUse_Update, 0, m_pTextureManager ) );
}
m_nWidth = width;
m_nHeight = height;
m_format = format;
}
if ( m_pImage )
{
// Copy data
ImageData imageData;
((RawImage*)(m_pImage->GetAsImage()))->GetImageData( &imageData );
ImagePlane &imagePlane = imageData.GetPlaneRef( 0 );
memcpy( imagePlane.pData, rgba, imagePlane.DataSize );
m_pImage->Update();
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void ScaleformUIImage::Update( void )
{
#ifdef _X360
X360_UpdateImageState();
#endif
}

View File

@@ -0,0 +1,61 @@
//========= Copyright © 1996-2009, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=====================================================================================//
#ifndef __SCALEFORMUIIMAGE_H__
#define __SCALEFORMUIIMAGE_H__
#include "tier1/utlbuffer.h"
#include "bitmap/imageformat_declarations.h"
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class ScaleformUIImage
{
public:
ScaleformUIImage( const byte* defaultRgba, int defaultWidth, int defaultHeight, ::ImageFormat defaultFormat, SF::GFx::TextureManager* pTextureManager );
virtual ~ScaleformUIImage( void );
// Tick any loading task that needs to be updated
virtual void Update( void );
virtual int GetWidth( void ) const { return m_nWidth; }
virtual int GetHeight( void ) const { return m_nHeight; }
virtual SF::Render::Image* GetImage( void );
virtual int AddRef()
{
return ThreadInterlockedIncrement( &m_nRefCount );
}
virtual int Release()
{
int refCount = ThreadInterlockedDecrement( &m_nRefCount );
if ( refCount == 0 )
{
OnFinalRelease();
}
return refCount;
}
virtual void OnFinalRelease();
protected:
SF::Render::ImageFormat ConvertImageFormat( ::ImageFormat format );
virtual void InitFromBuffer( const byte *rgba, int width, int height, ::ImageFormat format );
volatile int32 m_nRefCount;
int m_nWidth;
int m_nHeight;
ImageFormat m_format;
SF::GFx::ImageDelegate* m_pImage;
SF::GFx::TextureManager* m_pTextureManager;
};
#endif // __SCALEFORMUIIMAGE_H__

View File

@@ -0,0 +1,877 @@
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#if !defined( __SCALEFFORMUIIMPL_H__ )
#define __SCALEFFORMUIIMPL_H__
#include "scaleformuiintegration.h"
#include "movieslot.h"
#include "sfuiavatarimage.h"
#include "sfuiinventoryimage.h"
#include "sfuichromehtmlimage.h"
#include "tier1/utlmap.h"
#include "igameevents.h"
#include "cdll_int.h"
#if defined( USE_SDL ) || defined( OSX )
#include "appframework/ilaunchermgr.h"
#endif
#if defined( SF_ENABLE_IME ) && defined( SF_ENABLE_IME_WIN32 )
#include "GFx/IME/GFx_IMEManager.h"
#include "GFxIME/GFx_IMEManagerWin32.h"
#endif
#if ( defined( WIN32 ) && !defined( DX_TO_GL_ABSTRACTION ) ) || defined( _X360 )
#include <d3d9.h>
#endif
class DeviceCallbacks;
class ScaleformUIAvatarImage;
class IShaderAPI;
#define MAX_VALUES_IN_ARRAY 20
#define NUM_VALUEARRAY_SLOTS ( MAX_VALUES_IN_ARRAY-1 )
#define MAX_BOUND_COMMAND_LENGTH 64
#define TEMPORARY_BUFFER_SIZE 4086
#define MAX_AXIS_PER_JOYSTICK 2
#define MAX_JOYSTICKS_PER_SLOT 2
#define MAX_SLOTS_WITH_JOYSTICKS 2
#define JOY_VALUE_INDEX( slot, stick, axis ) ( ( slot * MAX_JOYSTICKS_PER_SLOT + stick ) * MAX_AXIS_PER_JOYSTICK + axis )
// [HPE] Removing the extra splitscreen slot - we no longer support local multiplayer on CS:GO
#define MAX_SLOTS ( SF_SS_SLOT( 0 ) + 1 )
#if defined( _WIN32 )
#define ALLOCA _alloca
#elif defined( _PS3 )
#define ALLOCA alloca
#endif
#if defined( _PS3 )
struct IDirect3DDevice9;
struct D3DPRESENT_PARAMETERS;
#endif
enum CURSOR_IMAGE_TYPE
{
CURSOR_IMAGE_NONE,
CURSOR_IMAGE_MOVE_CROSSHAIR,
CURSOR_IMAGE_MOUSE,
};
inline SFPARAMS ToSFPARAMS( SF::GFx::FunctionHandler::Params* ptr )
{
return reinterpret_cast<SFPARAMS>( ptr );
}
inline SF::GFx::FunctionHandler::Params* FromSFPARAMS( SFPARAMS ptr )
{
return reinterpret_cast< SF::GFx::FunctionHandler::Params* >( ptr );
}
inline SFVALUE ToSFVALUE( SF::GFx::Value* ptr )
{
return reinterpret_cast<SFVALUE>( ptr );
}
inline SF::GFx::Value* FromSFVALUE( SFVALUE ptr )
{
return reinterpret_cast<SF::GFx::Value*>( ptr );
}
inline SFMOVIE ToSFMOVIE( Scaleform::GFx::Movie *ptr )
{
return reinterpret_cast< SFMOVIE >( ptr );
}
inline SF::GFx::Movie* FromSFMOVIE( SFMOVIE ptr )
{
return reinterpret_cast< SF::GFx::Movie* >( ptr );
}
inline SFMOVIEDEF ToSFMOVIEDEF( Scaleform::GFx::MovieDef *ptr )
{
return reinterpret_cast< SFMOVIEDEF >( ptr );
}
inline SF::GFx::MovieDef* FromSFMOVIEDEF( SFMOVIEDEF ptr )
{
return reinterpret_cast< SF::GFx::MovieDef* >( ptr );
}
class CScaleFormThreadCommandQueue: public SF::Render::ThreadCommandQueue
{
public:
virtual void GetRenderInterfaces( SF::Render::Interfaces* p )
{
p->pHAL = pHAL;
p->pRenderer2D = pR2D;
p->pTextureManager = pHAL->GetTextureManager();
p->RenderThreadID = 0;
}
virtual void PushThreadCommand( SF::Render::ThreadCommand* command )
{
if (command) {
MaterialLock_t hMaterialLock = materials->Lock();
command->Execute();
materials->Unlock( hMaterialLock );
}
}
SF::Render::HAL* pHAL;
SF::Render::Renderer2D* pR2D;
};
#if defined( SF_ENABLE_IME ) && defined( SF_ENABLE_IME_WIN32 )
class ScaleformeUIIMEManager : public SF::GFx::IME::GFxIMEManagerWin32
{
public:
ScaleformeUIIMEManager( HWND hwnd, IGameEventManager2* pGameEventManager )
: SF::GFx::IME::GFxIMEManagerWin32( hwnd ), m_pGameEventManager( pGameEventManager ) {}
virtual void FinalizeComposition( const wchar_t* pstr, SF::UPInt len = SF_MAX_UPINT )
{
IGameEvent* pEvent = m_pGameEventManager->CreateEventA( "cs_handle_ime_event" );
if ( pEvent )
{
pEvent->SetString( "eventtype", "addchars" );
pEvent->SetWString( "eventdata", pstr );
m_pGameEventManager->FireEventClientSide( pEvent );
}
}
virtual void SetCompositionText( const wchar_t* pstr, SF::UPInt len = SF_MAX_UPINT )
{
IGameEvent* pEvent = m_pGameEventManager->CreateEventA( "cs_handle_ime_event" );
if ( pEvent )
{
pEvent->SetString( "eventtype", "setcomposition" );
pEvent->SetWString( "eventdata", pstr );
m_pGameEventManager->FireEventClientSide( pEvent );
}
}
virtual void HighlightText( SF::UPInt pos, SF::UPInt len, TextHighlightStyle style, bool clause )
{}
virtual void ClearComposition()
{
IGameEvent* pEvent = m_pGameEventManager->CreateEventA( "cs_handle_ime_event" );
if ( pEvent )
{
pEvent->SetString( "eventtype", "cancelcomposition" );
pEvent->SetWString( "eventdata", L"" );
m_pGameEventManager->FireEventClientSide( pEvent );
}
}
private:
IGameEventManager2* m_pGameEventManager;
};
#endif
class ScaleformUIImpl: public CTier3AppSystem<IScaleformUI>
{
typedef CTier3AppSystem<IScaleformUI> BaseClass;
/**********************
* These are the basic singleton support functions
* the are in ScaleformUIInitImpl.cpp
*/
/* singleton support */
public:
static ScaleformUIImpl m_Instance;
/* normal class */
protected:
SF::GFx::System* m_pSystem;
SF::GFx::Loader* m_pLoader;
#if defined( WIN32 ) && !defined( DX_TO_GL_ABSTRACTION )
SF::Ptr<SF::Render::D3D9::HAL> m_pRenderHAL;
#else
SF::Ptr<SF::Render::GL::HAL> m_pRenderHAL;
#endif
SF::Ptr<SF::Render::Renderer2D> m_pRenderer2D;
CScaleFormThreadCommandQueue *m_pThreadCommandQueue;
IDirect3DDevice9* m_pDevice;
#if defined( _WIN32 ) && !defined( DX_TO_GL_ABSTRACTION )
IDirect3DStateBlock9* m_pD3D9Stateblock;
DWORD m_srgbRenderState;
DWORD m_pSavedSrgbSamplerStates[16];
#endif
#if defined( _WIN32 )
SF::Ptr<ScaleformeUIIMEManager> m_pIMEManager;
#endif
SF::Ptr<ScaleformTranslatorAdapter> m_pTranslatorAdapter;
SF::Ptr<ScaleformFunctionHandlerAdapter> m_pFunctionAdapter;
SF::SysAlloc* m_pAllocator;
#if defined( USE_SDL ) || defined( OSX )
ILauncherMgr *m_pLauncherMgr;
#endif
IShaderDeviceMgr* m_pShaderDeviceMgr;
DeviceCallbacks* m_pDeviceCallbacks;
IShaderAPI* m_pShaderAPI;
IGameUIFuncs* m_pGameUIFuncs;
IVEngineClient* m_pEngine;
IGameEventManager2* m_pGameEventManager;
wchar_t m_wcControllerButtonToBindingTable[BUTTON_CODE_COUNT][MAX_BOUND_COMMAND_LENGTH];
BaseSlot* m_SlotPtrs[MAX_SLOTS];
// gurjeets - locks commented out, left here for reference, see comment in LockSlotPtr
// CThreadMutex m_SlotMutexes[MAX_SLOTS];
int m_SlotDeniesInputRefCount[MAX_SLOTS];
CUtlVector<SF::GFx::Movie*> m_MovieViews;
CUtlVector<const wchar_t*> m_LocalizableCommandNames;
CUtlVector<const char*> m_LocalizableCommandKeys;
CUtlVector<const char*> m_MovieDefNameCache;
CUtlVector<SF::GFx::MovieDef*> m_MovieDefCache;
CUtlVector<SF::GFx::Value*> m_ValueCache;
CUtlVector<SF::GFx::Value*> m_ValueArrayCaches[NUM_VALUEARRAY_SLOTS];
#ifdef _DEBUG
CUtlVector<SF::GFx::Value*> m_ValuesInUse;
CUtlVector<SF::GFx::Value*> m_ValueArraysInUse[NUM_VALUEARRAY_SLOTS];
#endif
float m_fJoyValues[MAX_AXIS_PER_JOYSTICK * MAX_JOYSTICKS_PER_SLOT * MAX_SLOTS_WITH_JOYSTICKS];
int m_iJoyAxisButtonsDown[MAX_SLOTS_WITH_JOYSTICKS];
int m_iScreenWidth;
int m_iScreenHeight;
int m_iLastMouseX;
int m_iLastMouseY;
float m_fCursorTimeUntilHide;
char m_cTemporaryBuffer[TEMPORARY_BUFFER_SIZE];
bool m_bTrySWFFirst;
bool m_bPumpScaleformStats;
bool m_bForcePS3;
bool m_bDenyAllInputToGame;
bool m_bShowActionNameIfUnbound;
bool m_bEatPS3MouseEvent;
int m_iWantCursorShown;
bool m_bIMEEnabled;
int m_iIMEFocusSlot;
CUtlMap< XUID, ScaleformUIAvatarImage * > m_mapUserXuidToAvatar;
IVTFTexture* m_pDefaultAvatarTexture;
ScaleformUIAvatarImage* m_pDefaultAvatarImage;
#if !defined( NO_STEAM )
bool m_bSteamCallbacksConfigured;
void EnsureSteamCallbacksConfigured();
STEAM_CALLBACK_MANUAL( ScaleformUIImpl, Steam_OnPersonaStateChanged, PersonaStateChange_t, m_CallbackPersonaStateChanged );
STEAM_CALLBACK_MANUAL( ScaleformUIImpl, Steam_OnAvatarImageLoaded, AvatarImageLoaded_t, m_CallbackAvatarImageLoaded );
#endif // NO_STEAM
CUtlMap< uint64, ScaleformUIInventoryImage * > m_mapItemIdToImage;
IVTFTexture* m_pDefaultInventoryTexture;
ScaleformUIInventoryImage* m_pDefaultInventoryImage;
struct DefaultInventoryIcon_t
{
IVTFTexture* m_pTexture;
ScaleformUIInventoryImage* m_pImage;
};
#ifdef USE_DEFAULT_INVENTORY_ICON_BACKGROUNDS
CUtlHashFast< DefaultInventoryIcon_t > m_defaultInventoryIcons;
#endif
CUtlMap< uint64, ScaleformUIChromeHTMLImage* > m_mapImageIdToChromeImage;
ScaleformUIChromeHTMLImage* m_pDefaultChromeHTMLImage;
int m_iKeyboardSlot;
CURSOR_IMAGE_TYPE m_loadedCursorImage;
bool m_isCursorForced;
// Time updated in RunFrame and used in AdvanceSlot
float m_fTime;
#if defined( _PS3 )
InputDevice_t m_preForcedInputType;
#endif
// Set to true if advance and render are running on the same thread
bool m_bSingleThreaded;
// ScaleformUI::ClearCache will queue the call to clear the scaleform mesh cache
// to ensure the mesh cache being cleared on the render thread
bool m_bClearMeshCacheQueued;
protected:
ScaleformUIImpl( void );
void ClearMembers( void );
void InitMovieImpl( void );
void ShutdownMovieImpl( void );
void InitRendererImpl( void );
void ShutdownRendererImpl( void );
void InitValueImpl( void );
void ShutdownValueImpl( void );
void InitHighLevelImpl( void );
void ShutdownHighLevelImpl( void );
void InitMovieSlotImpl( void );
void ShutdownMovieSlotImpl( void );
void InitCursorImpl( void );
void ShutdownCursorImpl( void );
void InitTranslationImpl( void );
void ShutdownTranslationImpl( void );
void InitFonts( void );
bool DistributeEvent( SF::GFx::Event& event, int slotNumber, bool toAllSlots, bool clearControllerUI = true );
bool DistributeKeyEvent( bool keyDown, bool fromController, const char* binding, ButtonCode_t code, ButtonCode_t vkey, int slotNumber, bool toAllSlots );
bool DistributeCharTyped( wchar_t code );
bool TallyAxisButtonEvent( int slot, int code, bool down );
bool HitTest( int x, int y );
BaseSlot* LockSlotPtr( int slot );
void UnlockSlotPtr( int slot );
bool AnalogStickNavigationDisabled( int slot );
void UpdateUIAvatarImages( void );
void SetJoyValue( int slot, int stick, int axis, int value );
#if defined( _PS3 )
void InitCursorPS3( bool usingMoveCrosshair );
#endif
public:
// the following are for the system callbacks from flash
void AddAPIFunctionToObject( SFVALUE pAPI, SFMOVIE pMovie, ScaleformUIFunctionHandlerObject* object, const ScaleformUIFunctionHandlerDefinition* pFunctionDef );
int GetScreenWidth( void )
{
return m_iScreenWidth;
}
int GetScreenHeight( void )
{
return m_iScreenHeight;
}
bool OwnsAtLeastOneMutex( void );
void DebugBreakIfNotLocked( void );
bool GetVerbose( void );
void SetVerbose( bool bVerbose );
// IAppSystem implementation
public:
virtual bool Connect( CreateInterfaceFn factory );
virtual void Disconnect( void );
// Here's where systems can access other interfaces implemented by this m_pObject
// Returns NULL if it doesn't implement the requested interface
virtual void *QueryInterface( const char *pInterfaceName );
// Init, shutdown
virtual InitReturnVal_t Init( void );
virtual void Shutdown( void );
// Returns all dependent libraries
virtual const AppSystemInfo_t* GetDependencies( void );
// Returns the tier
virtual AppSystemTier_t GetTier( void )
{
return APP_SYSTEM_TIER3;
}
// Reconnect to a particular interface
virtual void Reconnect( CreateInterfaceFn factory, const char *pInterfaceName )
{
BaseClass::Reconnect( factory, pInterfaceName );
}
void LogPrintf( const char *format, ... );
IVEngineClient* GetEnginePtr()
{
return m_pEngine;
}
// IScaleformUI implementation
/**************************
* common, high-level functions and are implemented in ScaleformUIHighLevelImpl.cpp
*/
bool GetForcePS3( void ) { return m_bForcePS3; }
#if defined( _PS3 )
void PS3UseMoveCursor( void );
void PS3UseStandardCursor( void );
void PS3ForceCursorStart( void );
void PS3ForceCursorEnd( void );
#endif
public:
// called when the safezone convar is changed
// tells all the slots to change their safe zone
void UpdateSafeZone( void );
// called when the UI tint convar is changed - applies the new tint to all slots
void UpdateTint( void );
// virtual void Render();
virtual void SetSingleThreadedMode( bool bSingleThreded );
virtual void RunFrame( float time );
void AdvanceSlot( int slot );
virtual bool HandleInputEvent( const InputEvent_t &event );
virtual bool HandleIMEEvent( size_t hwnd, unsigned int uMsg, unsigned int wParam, long lParam );
virtual bool PreProcessKeyboardEvent( size_t hwnd, unsigned int uMsg, unsigned int wParam, long lParam );
virtual void SetIMEEnabled( bool bEnabled );
virtual void SetIMEFocus( int slot );
virtual void ShutdownIME();
virtual float GetJoyValue( int slot, int stickIndex, int axis );
void SetScreenSize( int x, int y );
const char* CorrectFlashFileName( const char * name );
ScaleformUIAvatarImage* GetAvatarImage( XUID playerID );
void UpdateAvatarImages( void );
virtual bool AvatarImageAddRef( XUID playerID );
virtual void AvatarImageRelease( XUID playerID );
virtual void AvatarImageReload( XUID playerID, IScaleformAvatarImageProvider *pProvider );
virtual void AddDeviceDependentObject( IShaderDeviceDependentObject * pObject );
virtual void RemoveDeviceDependentObject( IShaderDeviceDependentObject * pObject );
ScaleformUIInventoryImage* GetInventoryImage( uint64 iItemId );
virtual bool InventoryImageAddRef( uint64 iItemId, IScaleformInventoryImageProvider *pGlobalInventoryImageProvider );
virtual void InventoryImageUpdate( uint64 iItemId, IScaleformInventoryImageProvider *pGlobalInventoryImageProvider );
virtual void InventoryImageRelease( uint64 iItemId );
#ifdef USE_DEFAULT_INVENTORY_ICON_BACKGROUNDS
virtual void InitInventoryDefaultIcons( CUtlVector< const char * > *vecIconDefaultNames );
#endif
ScaleformUIChromeHTMLImage* GetChromeHTMLImage( uint64 imageID );
virtual bool ChromeHTMLImageAddRef( uint64 imageID );
virtual void ChromeHTMLImageUpdate( uint64 imageID, const byte* rgba, int width, int height, ::ImageFormat format );
virtual void ChromeHTMLImageRelease( uint64 imageID );
virtual void ForceUpdateImages();
SF::Render::Image* CreateImageFromFile( const char *pszFileName, const SF::GFx::ImageCreateInfo& info, int width, int height );
/**********************************
* slot stuff. This is all in ScaleformUIImplMovieSlot.cpp
*/
virtual void SetSlotViewport( int slot, int x, int y, int width, int height );
virtual void RenderSlot( int slot );
virtual void ForkRenderSlot( int slot );
virtual void JoinRenderSlot( int slot );
virtual void InitSlot( int slotID, const char* rootMovie, IScaleformSlotInitController *pController );
virtual void SlotAddRef( int slot );
virtual void SlotRelease( int slotID );
virtual void LockSlot( int slot );
virtual void UnlockSlot( int slot );
virtual void RequestElement( int slot, const char* elementName, ScaleformUIFunctionHandlerObject* object, const IScaleformUIFunctionHandlerDefinitionTable* tableObject );
virtual void RemoveElement( int slot, SFVALUE element );
virtual void InstallGlobalObject( int slot, const char* elementName, ScaleformUIFunctionHandlerObject* object, const IScaleformUIFunctionHandlerDefinitionTable* tableObject, SFVALUE *pInstalledGlobalObjectResult );
virtual void RemoveGlobalObject( int slot, SFVALUE element );
virtual bool SlotConsumesInputEvents( int slot );
virtual bool ConsumesInputEvents( void );
virtual bool SlotDeniesInputToGame( int slot );
virtual void DenyInputToGame( bool value );
virtual void DenyInputToGameFromFlash( int slot, bool value );
virtual void SendUIEvent( const char* action, const char* eventData, int slot = 0 );
virtual void LockInputToSlot( int slot );
virtual void UnlockInput( void );
virtual void ForceCollectGarbage( int slot );
virtual void ClearCache( void );
virtual void LockMostRecentInputDevice( int slot );
/************************************
* Cursor stuff. in ScaleformUIImplCursor.cpp
*/
protected:
void UpdateCursorLazyHide( float time );
void UpdateCursorWaitTime( float newTime );
void InnerShowCursor( void );
void InnerHideCursor( void );
void CursorMoved( void );
void ControllerMoved( void );
bool IsSetToControllerUI( int slot );
void SetToControllerUI( int slot, bool value );
public:
void MaybeShowCursor( void );
bool IsSlotKeyboardAccessible( int slot );
virtual void InitCursor( const char* cursorMovie );
virtual void ReleaseCursor( void );
virtual bool IsCursorVisible( void );
virtual void RenderCursor( void );
virtual void AdvanceCursor( void );
virtual void SetCursorViewport( int x, int y, int width, int height );
virtual void ShowCursor( void );
virtual void HideCursor( void );
virtual void SetCursorShape( int shapeIndex );
/*******
* Renderer stuff
* These are in ScaleformUIRendererImpl.cpp
*/
void FinishInitializingRenderer( void );
void SetRenderingDevice( IDirect3DDevice9 *pDevice, D3DPRESENT_PARAMETERS *pPresentParameters, HWND hWnd );
void NotifyRenderingDeviceLost();
void SaveRenderingState( void );
void RestoreRenderingState( void );
void SetRenderTargets( void );
void DumpMeshCacheStats( void );
/*********
* Movie Def related stuff
* These are in ScaleformMovieImpl.cpp
*/
virtual SFMOVIEDEF CreateMovieDef( const char* pfilename, unsigned int loadConstants = 0, size_t memoryArena = 0 );
virtual void ReleaseMovieDef( SFMOVIEDEF movieDef );
virtual SFMOVIE MovieDef_CreateInstance( SFMOVIEDEF movieDef, bool initFirstFrame = true, size_t memoryArena = 0 );
virtual void ReleaseMovieView( SFMOVIE movieView );
virtual void MovieView_Advance( SFMOVIE movieView, float time, unsigned int frameCatchUpCount = 2 );
virtual void MovieView_SetBackgroundAlpha( SFMOVIE movieView, float alpha );
virtual void MovieView_SetViewport( SFMOVIE movieView, int bufw, int bufh, int left, int top, int w, int h, unsigned int flags = 0 );
virtual void MovieView_Display( SFMOVIE movieView );
virtual void MovieView_SetViewScaleMode( SFMOVIE movieView, IScaleformUI::_ScaleModeType type );
virtual IScaleformUI::_ScaleModeType MovieView_GetViewScaleMode( SFMOVIE movieView );
virtual void MovieView_SetViewAlignment( SFMOVIE movieView, IScaleformUI::_AlignType type );
virtual IScaleformUI::_AlignType MovieView_GetViewAlignment( SFMOVIE movieView );
virtual SFVALUE MovieView_CreateObject( SFMOVIE movieView, const char* className = NULL, SFVALUEARRAY args = SFVALUEARRAY(0, NULL), int numArgs = 0 );
virtual SFVALUE MovieView_GetVariable( SFMOVIE movieView, const char* variablePath );
virtual SFVALUE MovieView_CreateString( SFMOVIE movieView, const char *str );
virtual SFVALUE MovieView_CreateStringW( SFMOVIE movieView, const wchar_t *str );
virtual SFVALUE MovieView_CreateArray( SFMOVIE movieView, int size = -1 );
virtual bool MovieView_HitTest( SFMOVIE movieView, float x, float y, IScaleformUI::_HitTestType testCond = IScaleformUI::HitTest_Shapes, unsigned int controllerIdx = 0 );
/*************************
* keycode stuff.
* these are in ScaleformUIKeymapImpl.cpp
*/
void DecodeButtonandSlotFromButtonCode( ButtonCode_t inCode, ButtonCode_t &outcode, int &outSlot );
/***************************
* translation and button glyph functionality.
* These are in ScaleformUITranslationImpl.cpp
*/
protected:
void RemoveKeyBindings( void );
const wchar_t* LocalizeCommand( const wchar_t* command );
ButtonCode_t LookupButtonFromBinding( const wchar_t* binding, bool bForceControllerLookup = false );
void BindCommandToControllerButton( ButtonCode_t code, const char* binding );
IScaleformUI::ControllerButton::Enum ValveButtonToControllerButton( ButtonCode_t b );
public:
virtual void RefreshKeyBindings( void );
virtual void ShowActionNameWhenActionIsNotBound( bool value );
virtual void UpdateBindingForButton( ButtonCode_t bt, const char* pbinding );
virtual const wchar_t* Translate( const char *key, bool* pIsHTML );
virtual const wchar_t* ReplaceGlyphKeywordsWithHTML( const wchar_t* pin, int fontSize, bool bForceControllerGlyph = false );
virtual const wchar_t* ReplaceGlyphKeywordsWithHTML( const char* text, int fontSize, bool bForceControllerGlyph = false );
virtual void MakeStringSafe( const wchar_t* stringin, wchar_t* stringout, int outlength );
/*************************
* value stuff
* these are in ScaleformUIValueImpl.cpp
*/
protected:
SFVALUE CreateGFxValue( SFVALUE pValue = NULL );
void ReleaseGFxValue( SFVALUE pValue );
public:
virtual SFVALUE CreateValue( SFVALUE value );
virtual SFVALUE CreateValue( const char* value );
virtual SFVALUE CreateValue( const wchar_t* value );
virtual SFVALUE CreateValue( int value );
virtual SFVALUE CreateValue( float value );
virtual SFVALUE CreateValue( bool value );
virtual SFVALUE CreateNewObject( int slot );
virtual SFVALUE CreateNewString( int slot, const char* value );
virtual SFVALUE CreateNewString( int slot, const wchar_t* value );
virtual SFVALUE CreateNewArray( int slot, int size = -1 );
virtual void Value_SetValue( SFVALUE obj, SFVALUE value );
virtual void Value_SetValue( SFVALUE obj, int value );
virtual void Value_SetValue( SFVALUE obj, float value );
virtual void Value_SetValue( SFVALUE obj, bool value );
virtual void Value_SetValue( SFVALUE obj, const char* value );
virtual void Value_SetValue( SFVALUE obj, const wchar_t* value );
virtual void Value_SetColor( SFVALUE obj, int color );
virtual void Value_SetColor( SFVALUE obj, float r, float g, float b, float a );
virtual void Value_SetTint( SFVALUE obj, int color );
virtual void Value_SetTint( SFVALUE obj, float r, float g, float b, float a );
virtual void Value_SetColorTransform( SFVALUE obj, int colorMultiply, int colorAdd );
virtual void Value_SetColorTransform( SFVALUE obj, float r, float g, float b, float a, int colorAdd );
virtual void Value_SetText( SFVALUE obj, const char* value );
virtual void Value_SetText( SFVALUE obj, const wchar_t* value );
virtual void Value_SetTextHTML( SFVALUE obj, const char* value );
virtual void Value_SetTextHTML( SFVALUE obj, const wchar_t* value );
virtual int Value_SetFormattedText( SFVALUE obj, const char* pFormat, ... );
virtual void Value_SetArraySize( SFVALUE obj, int size );
virtual int Value_GetArraySize( SFVALUE obj );
virtual void Value_ClearArrayElements( SFVALUE obj );
virtual void Value_RemoveArrayElement( SFVALUE obj, int index );
virtual void Value_RemoveArrayElements( SFVALUE obj, int index, int count );
virtual SFVALUE Value_GetArrayElement( SFVALUE obj, int index );
virtual void Value_SetArrayElement( SFVALUE obj, int index, SFVALUE value );
virtual void Value_SetArrayElement( SFVALUE obj, int index, int value );
virtual void Value_SetArrayElement( SFVALUE obj, int index, float value );
virtual void Value_SetArrayElement( SFVALUE obj, int index, bool value );
virtual void Value_SetArrayElement( SFVALUE obj, int index, const char* value );
virtual void Value_SetArrayElement( SFVALUE obj, int index, const wchar_t* value );
void SetVisible( SFVALUE pgfx, bool visible );
virtual void Value_SetVisible( SFVALUE obj, bool visible );
virtual void Value_GetDisplayInfo( SFVALUE obj, ScaleformDisplayInfo* dinfo );
virtual void Value_SetDisplayInfo( SFVALUE obj, const ScaleformDisplayInfo* dinfo );
virtual void ReleaseValue( SFVALUE value );
virtual void CreateValueArray( SFVALUEARRAY& valueArray, int length );
virtual SFVALUEARRAY CreateValueArray( int length );
virtual void ReleaseValueArray( SFVALUEARRAY& valueArray );
virtual void ReleaseValueArray( SFVALUEARRAY& valueArray, int count ); // DEPRECATED
virtual SFVALUE ValueArray_GetElement( SFVALUEARRAY, int index );
virtual IScaleformUI::_ValueType ValueArray_GetType( SFVALUEARRAY array, int index );
virtual double ValueArray_GetNumber( SFVALUEARRAY array, int index );
virtual bool ValueArray_GetBool( SFVALUEARRAY array, int index );
virtual const char* ValueArray_GetString( SFVALUEARRAY array, int index );
virtual const wchar_t* ValueArray_GetStringW( SFVALUEARRAY array, int index );
virtual void ValueArray_SetElement( SFVALUEARRAY, int index, SFVALUE value );
virtual void ValueArray_SetElement( SFVALUEARRAY, int index, int value );
virtual void ValueArray_SetElement( SFVALUEARRAY, int index, float value );
virtual void ValueArray_SetElement( SFVALUEARRAY, int index, bool value );
virtual void ValueArray_SetElement( SFVALUEARRAY, int index, const char* value );
virtual void ValueArray_SetElement( SFVALUEARRAY, int index, const wchar_t* value );
virtual void ValueArray_SetElementText( SFVALUEARRAY, int index, const char* value );
virtual void ValueArray_SetElementText( SFVALUEARRAY, int index, const wchar_t* value );
virtual void ValueArray_SetElementTextHTML( SFVALUEARRAY, int index, const char* value );
virtual void ValueArray_SetElementTextHTML( SFVALUEARRAY, int index, const wchar_t* value );
virtual bool Value_HasMember( SFVALUE value, const char* name );
virtual SFVALUE Value_GetMember( SFVALUE value, const char* name );
virtual bool Value_SetMember( SFVALUE obj, const char *name, SFVALUE value );
virtual bool Value_SetMember( SFVALUE obj, const char *name, int value );
virtual bool Value_SetMember( SFVALUE obj, const char *name, float value );
virtual bool Value_SetMember( SFVALUE obj, const char *name, bool value );
virtual bool Value_SetMember( SFVALUE obj, const char *name, const char* value );
virtual bool Value_SetMember( SFVALUE obj, const char *name, const wchar_t* value );
virtual ISFTextObject* TextObject_MakeTextObject( SFVALUE value );
virtual ISFTextObject* TextObject_MakeTextObjectFromMember( SFVALUE value, const char* pName );
virtual bool Value_InvokeWithoutReturn( SFVALUE obj, const char* methodName, const SFVALUEARRAY& args );
virtual SFVALUE Value_Invoke( SFVALUE obj, const char* methodName, const SFVALUEARRAY& args );
virtual bool Value_InvokeWithoutReturn( SFVALUE obj, const char* methodName, SFVALUE args, int numArgs );
virtual SFVALUE Value_Invoke( SFVALUE obj, const char* methodName, SFVALUE args, int numArgs );
virtual bool Value_InvokeWithoutReturn( SFVALUE obj, const char* methodName, const SFVALUEARRAY& args, int numArgs ); // DEPRECATED
virtual SFVALUE Value_Invoke( SFVALUE obj, const char* methodName, const SFVALUEARRAY& args, int numArgs ); // DEPRECATED
virtual IScaleformUI::_ValueType Value_GetType( SFVALUE obj );
virtual double Value_GetNumber( SFVALUE obj );
virtual bool Value_GetBool( SFVALUE obj );
virtual const char* Value_GetString( SFVALUE obj );
virtual const wchar_t* Value_GetStringW( SFVALUE obj );
virtual SFVALUE Value_GetText( SFVALUE obj );
virtual SFVALUE Value_GetTextHTML( SFVALUE obj );
/************************************
* m_Callback parameter stuff
* These are in ScaleformUIParamsImpl.cpp
*/
virtual SFVALUEARRAY Params_GetArgs( SFPARAMS params );
virtual unsigned int Params_GetNumArgs( SFPARAMS params );
virtual bool Params_ArgIs( SFPARAMS params, unsigned int index, IScaleformUI::_ValueType v );
virtual SFVALUE Params_GetArg( SFPARAMS params, int index = 0 );
virtual IScaleformUI::_ValueType Params_GetArgType( SFPARAMS params, int index = 0 );
virtual double Params_GetArgAsNumber( SFPARAMS params, int index = 0 );
virtual bool Params_GetArgAsBool( SFPARAMS params, int index = 0 );
virtual const char* Params_GetArgAsString( SFPARAMS params, int index = 0 );
virtual const wchar_t* Params_GetArgAsStringW( SFPARAMS params, int index = 0 );
virtual void Params_DebugSpew( SFPARAMS params );
virtual void Params_SetResult( SFPARAMS params, SFVALUE value );
virtual void Params_SetResult( SFPARAMS params, int value );
virtual void Params_SetResult( SFPARAMS params, float value );
virtual void Params_SetResult( SFPARAMS params, bool value );
virtual void Params_SetResult( SFPARAMS params, const char* value, bool bMakeNewValue = true );
virtual void Params_SetResult( SFPARAMS params, const wchar_t* value, bool bMakeNewValue = true );
virtual SFVALUE Params_CreateNewObject( SFPARAMS params );
virtual SFVALUE Params_CreateNewString( SFPARAMS params, const char* value );
virtual SFVALUE Params_CreateNewString( SFPARAMS params, const wchar_t* value );
virtual SFVALUE Params_CreateNewArray( SFPARAMS params, int size = -1 );
ButtonCode_t GetCurrentKey() { return m_CurrentKey; }
protected:
ButtonCode_t m_CurrentKey;
protected:
/************************************
* helper functions to map to and from SFUI and SDK enums
*/
SF::GFx::Movie::ScaleModeType ScaleModeType_SFUI_to_SDK( IScaleformUI::_ScaleModeType scaleModeType );
IScaleformUI::_ScaleModeType ScaleModeType_SDK_to_SFUI( SF::GFx::Movie::ScaleModeType scaleModeType );
SF::GFx::Value::ValueType ValueType_SFUI_to_SDK( IScaleformUI::_ValueType valueType );
IScaleformUI::_ValueType ValueType_SDK_to_SFUI( SF::GFx::Value::ValueType ValueType );
SF::GFx::Movie::AlignType AlignType_SFUI_to_SDK( IScaleformUI::_AlignType alignType );
IScaleformUI::_AlignType AlignType_SDK_to_SFUI( SF::GFx::Movie::AlignType alignType );
SF::GFx::Movie::HitTestType HitTestType_SFUI_to_SDK( IScaleformUI::_HitTestType hitTestType );
IScaleformUI::_HitTestType HitTestType_SDK_to_SFUI( SF::GFx::Movie::HitTestType hitTestType );
};
#define SFINST ( ScaleformUIImpl::m_Instance )
class DeviceCallbacks: public IShaderDeviceDependentObject
{
public:
int m_iRefCount;
ScaleformUIImpl* m_pScaleform;
DeviceCallbacks( void ) :
m_iRefCount( 1 ), m_pScaleform( NULL )
{
}
virtual void DeviceLost( void )
{
m_pScaleform->NotifyRenderingDeviceLost();
}
virtual void DeviceReset( void *pDevice, void *pPresentParameters, void *pHWnd )
{
m_pScaleform->SetRenderingDevice( ( IDirect3DDevice9* )pDevice, ( D3DPRESENT_PARAMETERS* )pPresentParameters, ( HWND )pHWnd );
}
virtual void ScreenSizeChanged( int width, int height )
{
m_pScaleform->SetScreenSize( width, height );
}
};
class ScaleformCallbackHolder: public SF::GFx::ASUserData
{
public:
ScaleformUIFunctionHandlerObject* m_pObject;
ScaleformUIFunctionHandler m_Callback;
inline ScaleformCallbackHolder( ScaleformUIFunctionHandlerObject* object, ScaleformUIFunctionHandler callback ) :
SF::GFx::ASUserData(), m_pObject( object ), m_Callback( callback )
{
}
inline void Execute( SF::GFx::FunctionHandler::Params *params )
{
( m_pObject->*m_Callback )( &SFINST, ToSFPARAMS( params ) );
}
virtual void OnDestroy( SF::GFx::Movie* pmovie, void* pobject );
};
#endif

View File

@@ -0,0 +1,459 @@
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "stdafx.h"
#include "scaleformuiintegration.h"
#include "tier1/keyvalues.h"
#include "vgui/ILocalize.h"
#include "matchmaking/imatchframework.h"
#include "shaderapi/ishaderapi.h"
#if !defined( NO_STEAM )
#include "steam/steam_api.h"
#endif
#include "Render/ImageFiles/PNG_ImageFile.h"
#include "Render/ImageFiles/DDS_ImageFile.h"
// NOTE: This must be the last file included!!!
#include "tier0/memdbgon.h"
using namespace Scaleform::GFx;
#if !defined( NO_STEAM )
static CSteamAPIContext g_SteamAPIContext;
CSteamAPIContext *steamapicontext = &g_SteamAPIContext;
#endif
/********************************************
* This is the singleton that will be exposed to all other DLLs
* through the valve dll system
*/
ScaleformUIImpl ScaleformUIImpl::m_Instance;
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( ScaleformUIImpl, IScaleformUI, SCALEFORMUI_INTERFACE_VERSION, ScaleformUIImpl::m_Instance )
static const char* defSafeZone = "1.0";
static const char* defHudScaling = "0.85";
ConVar safezonex( "safezonex", defSafeZone, FCVAR_ARCHIVE | FCVAR_ARCHIVE_GAMECONSOLE, "The percentage of the screen width that is considered safe from overscan", true, 0.2f, true, 1.0f );
ConVar safezoney( "safezoney", defSafeZone, FCVAR_ARCHIVE | FCVAR_ARCHIVE_GAMECONSOLE, "The percentage of the screen height that is considered safe from overscan", true, 0.85f, true, 1.0f );
ConVar hud_scaling( "hud_scaling", defHudScaling, FCVAR_ARCHIVE, "Scales hud elements", true, .5f, true, 0.95f );
void safezonechanged( IConVar *var, const char *pOldValue, float flOldValue )
{
ConVarRef varOption( "safezonex" );
float fNewSafe = varOption.GetFloat();
fNewSafe = clamp( fNewSafe, SFINST.GetEnginePtr()->GetSafeZoneXMin(), varOption.GetMax() );
if ( fNewSafe != varOption.GetFloat() )
varOption.SetValue( fNewSafe );
SFINST.UpdateSafeZone();
}
// Defaults to a typically unused value, so that a fresh user profile detects the load and initializes the UI tint properly
ConVar sf_ui_tint( "sf_ui_tint", "8", FCVAR_ARCHIVE, "The current tint applied to the Scaleform UI" );
void ui_tint_changed( IConVar *var, const char *pOldValue, float flOldValue )
{
SFINST.UpdateTint();
}
ScaleformUIImpl::ScaleformUIImpl()
{
ClearMembers();
}
void ScaleformUIImpl::ClearMembers( void )
{
#if defined( USE_SDL ) || defined( OSX )
m_pLauncherMgr = NULL;
#endif
m_pSystem = NULL;
m_pLoader = NULL;
m_pAllocator = NULL;
m_pShaderDeviceMgr = NULL;
m_pDeviceCallbacks = NULL;
m_pGameUIFuncs = NULL;
m_bTrySWFFirst = false;
m_iScreenWidth = 0;
m_iScreenHeight = 0;
m_iLastMouseX = 0;
m_iLastMouseY = 0;
m_pDefaultAvatarImage = NULL;
m_pDefaultAvatarTexture = NULL;
m_pDefaultInventoryImage = NULL;
m_pDefaultInventoryTexture = NULL;
#ifdef USE_DEFAULT_INVENTORY_ICON_BACKGROUNDS
m_defaultInventoryIcons.Init( 64 );
#endif
m_pDefaultChromeHTMLImage = NULL;
m_pEngine = NULL;
m_pGameEventManager = NULL;
m_pShaderAPI = NULL;
m_bPumpScaleformStats = false;
m_bForcePS3 = false;
m_bDenyAllInputToGame = false;
m_pRenderHAL.Clear();
m_pRenderer2D.Clear();
m_pThreadCommandQueue = NULL;
m_bIMEEnabled = false;
m_iIMEFocusSlot = SF_FULL_SCREEN_SLOT;
m_pDevice = NULL;
#if defined( WIN32 ) && !defined( DX_TO_GL_ABSTRACTION )
m_pD3D9Stateblock = NULL;
#endif
m_bSingleThreaded = true;
m_bClearMeshCacheQueued = false;
m_fTime = 0.0f;
}
bool ScaleformUIImpl::Connect( CreateInterfaceFn factory )
{
if ( !factory )
{
return false;
}
if ( !BaseClass::Connect( factory ) )
{
return false;
}
int result;
#if defined( USE_SDL )
m_pLauncherMgr = (ILauncherMgr *)factory( SDLMGR_INTERFACE_VERSION, NULL);
#elif defined( OSX )
m_pLauncherMgr = (ILauncherMgr *)factory( COCOAMGR_INTERFACE_VERSION, NULL);
#endif
m_pShaderDeviceMgr = ( IShaderDeviceMgr* ) factory( SHADER_DEVICE_MGR_INTERFACE_VERSION, &result );
m_pGameUIFuncs = ( IGameUIFuncs* ) factory( VENGINE_GAMEUIFUNCS_VERSION, &result );
m_pEngine = ( IVEngineClient* )factory( VENGINE_CLIENT_INTERFACE_VERSION, NULL );
m_pGameEventManager = ( IGameEventManager2* )factory ( INTERFACEVERSION_GAMEEVENTSMANAGER2, &result );
m_pShaderAPI = ( IShaderAPI * )factory( SHADERAPI_INTERFACE_VERSION, &result );
if ( !m_pShaderDeviceMgr || !m_pGameUIFuncs || !m_pEngine || !m_pGameEventManager || !m_pShaderAPI )
{
Warning( "ScaleformUI missing expected interface\n" );
return false;
}
// Initialize the console variables.
ConVar_Register();
RefreshKeyBindings();
return m_pShaderDeviceMgr != NULL;
}
void ScaleformUIImpl::Disconnect( void )
{
ShutdownRendererImpl();
m_pShaderDeviceMgr = NULL;
m_pGameUIFuncs = NULL;
m_pEngine = NULL;
m_pGameEventManager = NULL;
m_pShaderAPI = NULL;
BaseClass::Disconnect();
}
void ScaleformUIImpl::InitFonts( void )
{
MEM_ALLOC_CREDIT();
// get the file that defines the font mapping
KeyValues* pkeyValueData = new KeyValues( "english" );
KeyValues::AutoDelete autodelete( pkeyValueData );
// Load the config data
if ( !pkeyValueData )
{
return;
}
pkeyValueData->LoadFromFile( g_pFullFileSystem, "resource/flash/fontmapping.cfg", "game" );
// PC uses one font library containing all languages.
const char *fontLib = pkeyValueData->GetString( "fontlib", "resource/flash/fontlib.swf" );
SF::Ptr<FontLib> pFontLib = *new FontLib;
m_pLoader->SetFontLib( pFontLib );
SF::Ptr<MovieDef> pFontMovie = *m_pLoader->CreateMovie( fontLib );
pFontLib->AddFontsFrom( pFontMovie, true );
pFontMovie = *m_pLoader->CreateMovie( "resource/flash/fontlib_extra.swf" );
pFontLib->AddFontsFrom( pFontMovie, true );
SF::Ptr<FontMap> pFontMap = *new FontMap();
// now connect each of the fonts with its exported name
for ( KeyValues* piter = pkeyValueData->GetFirstTrueSubKey(); piter; piter = piter->GetNextTrueSubKey() )
{
const char* exportedName = piter->GetName();
const char* fontName = piter->GetString( "font", "Arial" );
const char* fontStyle = piter->GetString( "style", "Normal" );
FontMap::MapFontFlags fontFlags = FontMap::MFF_Original;
if ( !V_stricmp( fontStyle, "bold" ) )
{
fontFlags = FontMap::MFF_Bold;
}
else if ( !V_stricmp( fontStyle, "italic" ) )
{
fontFlags = FontMap::MFF_Bold;
}
else if ( !V_stricmp( fontStyle, "bolditalic" ) || !V_stricmp( fontStyle, "italicbold" ) )
{
fontFlags = FontMap::MFF_BoldItalic;
}
pFontMap->MapFont( exportedName, fontName, fontFlags );
}
m_pLoader->SetFontMap( pFontMap );
}
InitReturnVal_t ScaleformUIImpl::Init( void )
{
MEM_ALLOC_CREDIT();
InitReturnVal_t nRetVal = BaseClass::Init();
if ( nRetVal != INIT_OK )
{
return nRetVal;
}
Assert( m_pAllocator == NULL );
m_pAllocator = new CScaleformSysAlloc();
Assert( m_pSystem == NULL );
m_pSystem = new System( m_pAllocator );
Assert( m_pLoader == NULL );
m_pLoader = new Loader();
m_pLoader->SetLog( SF::Ptr<Log> ( *new ScaleformUILogging() ) );
m_pLoader->SetFileOpener( SF::Ptr<ScaleformFileOpener> ( *new ScaleformFileOpener() ) );
m_pLoader->SetTextClipboard( SF::Ptr<ScaleformClipboard> ( *new ScaleformClipboard() ) );
m_pLoader->SetTranslator( SF::Ptr<ScaleformTranslatorAdapter> ( *new ScaleformTranslatorAdapter() ) );
m_pLoader->SetAS2Support( SF::Ptr<AS2Support>( *new AS2Support() ) );
SF::Log::SetGlobalLog( m_pLoader->GetLog() );
// setup image handlers
SF::Ptr<SF::GFx::ImageFileHandlerRegistry> pimgReg = *new SF::GFx::ImageFileHandlerRegistry();
#ifdef SF_ENABLE_LIBJPEG
pimgReg->AddHandler( &SF::Render::JPEG::FileReader::Instance );
#endif
#ifdef SF_ENABLE_LIBPNG
pimgReg->AddHandler( &SF::Render::PNG::FileReader::Instance );
#endif
pimgReg->AddHandler( &SF::Render::TGA::FileReader::Instance );
pimgReg->AddHandler( &SF::Render::DDS::FileReader::Instance );
m_pLoader->SetImageFileHandlerRegistry( pimgReg );
#if defined( PLATFORM_WINDOWS_PC )
m_bTrySWFFirst = true;
#elif defined( _CERT )
if ( CommandLine()->FindParm( "-tryswf" ) )
{
m_bTrySWFFirst = true;
}
else
{
m_bTrySWFFirst = false;
}
#else
if ( CommandLine()->FindParm( "-ignoreswf" ) )
{
m_bTrySWFFirst = false;
}
else
{
m_bTrySWFFirst = true;
}
#endif
#if !defined( _CERT )
if ( CommandLine()->FindParm( "-sfstats" ) )
m_bPumpScaleformStats = true;
#endif
#if !defined( NO_STEAM )
SteamAPI_InitSafe();
g_SteamAPIContext.Init();
#endif // NO_STEAM
InitValueImpl();
InitTranslationImpl();
InitRendererImpl();
InitMovieImpl();
InitHighLevelImpl();
InitMovieSlotImpl();
safezonex.InstallChangeCallback( safezonechanged, false );
safezoney.InstallChangeCallback( safezonechanged, false );
hud_scaling.InstallChangeCallback( safezonechanged, false );
sf_ui_tint.InstallChangeCallback( ui_tint_changed, false );
return nRetVal;
}
void ScaleformUIImpl::Shutdown( void )
{
// On Ps3, we crash on exit here.
// Should revisit to ensure it's not related to the IB/VB mesh cacheing optimisation
// But for pre-cert this hack will get us much better coverage testing at this point
#ifdef _PS3
return;
#endif
if ( m_pSystem )
{
safezonex.RemoveChangeCallback( safezonechanged );
safezoney.RemoveChangeCallback( safezonechanged );
hud_scaling.RemoveChangeCallback( safezonechanged );
sf_ui_tint.RemoveChangeCallback( ui_tint_changed );
ShutdownTranslationImpl();
ShutdownMovieSlotImpl();
ShutdownHighLevelImpl();
ShutdownMovieImpl();
ShutdownRendererImpl();
ShutdownValueImpl();
m_pTranslatorAdapter = NULL;
delete m_pLoader;
delete m_pSystem;
delete m_pAllocator;
ClearMembers();
ConVar_Unregister();
#if !defined( NO_STEAM )
g_SteamAPIContext.Clear(); // Steam API context shutdown
#endif
}
BaseClass::Shutdown();
}
void* ScaleformUIImpl::QueryInterface( const char *pInterfaceName )
{
if ( !Q_strncmp( pInterfaceName, SCALEFORMUI_INTERFACE_VERSION, Q_strlen( SCALEFORMUI_INTERFACE_VERSION ) + 1 ) )
{
return ( IScaleformUI* ) &ScaleformUIImpl::m_Instance;
}
return BaseClass::QueryInterface( pInterfaceName );
}
const AppSystemInfo_t* ScaleformUIImpl::GetDependencies( void )
{
return BaseClass::GetDependencies();
}
void ScaleformUIImpl::LogPrintf( const char *format, ... )
{
#if !defined( _CERT )
va_list al;
va_start( al, format );
SF::Ptr<Log> pLog = m_pLoader->GetLog();
if ( pLog )
{
pLog->LogMessageVarg( SF::Log_Message, format, al );
}
pLog = NULL;
#endif
}
void SF_VerboseToggle( void );
void SF_VerboseOn( void );
void SF_VerboseOff( void );
static ConCommand dev_scaleform_verbose_toggle("dev_scaleform_verbose_toggle", SF_VerboseToggle, "Enable/disable Scaleform verbose mode.", FCVAR_DONTRECORD | FCVAR_DEVELOPMENTONLY );
static ConCommand dev_scaleform_verbose_on("dev_scaleform_verbose_on", SF_VerboseOn, "Enable Scaleform verbose mode.", FCVAR_DONTRECORD | FCVAR_DEVELOPMENTONLY );
static ConCommand dev_scaleform_verbose_off("dev_scaleform_verbose_off", SF_VerboseOff, "Disable Scaleform verbose mode.", FCVAR_DONTRECORD | FCVAR_DEVELOPMENTONLY );
bool ScaleformUIImpl::GetVerbose( void )
{
if ( m_pLoader )
{
SF::Ptr<ActionControl> pActionControl = m_pLoader->GetActionControl();
if ( pActionControl )
{
return ( ( pActionControl->GetActionFlags() & ActionControl::Action_Verbose ) != 0 );
}
}
return false;
}
void ScaleformUIImpl::SetVerbose( bool bVerbose )
{
if ( m_pLoader )
{
SF::Ptr<ActionControl> pActionControl = m_pLoader->GetActionControl();
if ( !pActionControl )
{
pActionControl = *new ActionControl();
m_pLoader->SetActionControl(pActionControl);
}
pActionControl->SetVerboseAction( bVerbose );
pActionControl->SetLogAllFilenames( true );
}
}
void SF_VerboseToggle( void )
{
bool bWasVerbose = SFINST.GetVerbose();
SFINST.SetVerbose( !bWasVerbose );
}
void SF_VerboseOn( void )
{
SFINST.SetVerbose( true );
}
void SF_VerboseOff( void )
{
SFINST.SetVerbose( false );
}

View File

@@ -0,0 +1,439 @@
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "stdafx.h"
#include "vgui/ILocalize.h"
#include "vgui/ISystem.h"
#include "sfuimemoryfile.h"
#include <vstdlib/vstrtools.h>
#if defined( _PS3 )
#include "ps3/ps3_win32stubs.h"
#endif
#include "../../game/shared/econ/econ_item_view_helpers.h"
// NOTE: This must be the last file included!!!
#include "tier0/memdbgon.h"
using namespace SF::GFx;
ConVar dev_scaleform_debug( "dev_scaleform_debug", "0", FCVAR_DEVELOPMENTONLY );
/*************************************
* memory allocation wrapper
*/
void* CScaleformSysAlloc::Alloc( SF::UPInt size, SF::UPInt align )
{
return MemAlloc_AllocAlignedUnattributed( size, align );
}
void CScaleformSysAlloc::Free( void* ptr, SF::UPInt size, SF::UPInt align )
{
MemAlloc_FreeAligned( ptr );
}
void* CScaleformSysAlloc::Realloc( void* oldPtr, SF::UPInt oldSize, SF::UPInt newSize, SF::UPInt align )
{
return MemAlloc_ReallocAligned( oldPtr, newSize, align );
}
/*****************************************************
* This redirects the scaleform logging calls to CSTrike
*/
DEFINE_LOGGING_CHANNEL_NO_TAGS( LOG_SCALEFORM, "Scaleform" );
DEFINE_LOGGING_CHANNEL_NO_TAGS( LOG_SCALEFORM_SCRIPT, "ScaleformScript" );
DEFINE_LOGGING_CHANNEL_NO_TAGS( LOG_SCALEFORM_PARSE, "ScaleformParse" );
DEFINE_LOGGING_CHANNEL_NO_TAGS( LOG_SCALEFORM_AS, "ScaleformAS" );
#define SCALEFORM_LOG_COLOR (::Color(180,180,255, 255))
void ScaleformUILogging::LogMessageVarg( SF::LogMessageId messageId, const char* pfmt, va_list argList )
{
if ( !dev_scaleform_debug.GetBool() )
return;
const char *pPrefix = "SF: ";
LoggingChannelID_t logChannel = LOG_SCALEFORM;
switch ( messageId & SF::LogChannel_Mask )
{
case SF::LogChannel_Debug:
pPrefix = "SF (Debug): ";
break;
case SF::LogChannel_Render:
pPrefix = "SF (Render): ";
break;
case SF::LogChannel_Script:
logChannel = LOG_SCALEFORM_SCRIPT;
pPrefix = "SF (Script): ";
break;
case SF::LogChannel_Parse:
logChannel = LOG_SCALEFORM_PARSE;
pPrefix = "SF (Parse): ";
break;
case SF::LogChannel_Action:
logChannel = LOG_SCALEFORM_AS;
pPrefix = "SF (Action): ";
break;
}
LoggingSeverity_t logSeverity;
switch ( messageId.GetMessageType() )
{
case SF::LogMessage_Error:
logSeverity = LS_WARNING;
break;
case SF::LogMessage_Warning:
logSeverity = LS_WARNING;
break;
case SF::LogMessage_Text:
logSeverity = LS_MESSAGE;
break;
default:
logSeverity = LS_MESSAGE;
break;
}
if ( LoggingSystem_IsChannelEnabled( logChannel, logSeverity ) )
{
tchar formattedMessage[MAX_LOGGING_MESSAGE_LENGTH];
Tier0Internal_vsntprintf( formattedMessage, sizeof( formattedMessage )-1, pfmt, argList );
formattedMessage[sizeof( formattedMessage ) - 1] = 0;
// optional categorizing prefix
if ( pPrefix )
{
LoggingSystem_LogDirect( logChannel, logSeverity, SCALEFORM_LOG_COLOR, pPrefix );
}
LoggingSystem_LogDirect( logChannel, logSeverity, SCALEFORM_LOG_COLOR, formattedMessage );
// scaleform messages randomly lack terminal \n, add to prevent undesired joined spew
int len = _tcslen( formattedMessage );
if ( len > 0 && formattedMessage[len-1] != '\n' )
{
LoggingSystem_LogDirect( logChannel, logSeverity, SCALEFORM_LOG_COLOR, "\n" );
}
}
}
/****************************************************************
* contains the adapter methods for clipboard
*/
void ScaleformClipboard::OnTextStore( const wchar_t* ptext, SF::UPInt len )
{
if ( ptext && len )
{
g_pVGuiSystem->SetClipboardText( ptext, len );
}
}
/****************************************************************
* contains the adapter methods for translations
*/
unsigned int ScaleformTranslatorAdapter::GetCaps( void ) const
{
return Cap_StripTrailingNewLines;
}
void ScaleformTranslatorAdapter::Translate( TranslateInfo* tinfo )
{
const wchar_t* pkey = tinfo->GetKey();
if ( pkey && ( *pkey == L'#' ) )
{
int len = Q_wcslen( pkey );
char *asciiString = ( char * ) stackalloc( len + 1 );
V_UnicodeToUTF8( pkey, asciiString, len + 1 );
bool isHTML = false;
const wchar_t* translated = SFINST.Translate( asciiString, &isHTML );
tinfo->SetResultHtml( translated );
}
}
/********************
* used by CreateAPI. It attaches the movieview to the GFxValue of the api
*/
void ScaleformMovieUserData::OnDestroy( Movie* pmovie, void* pobject )
{
m_pMovie = NULL;
Release();
}
/*******************************
* this defines the actual m_Callback function for the function handler class
*/
void ScaleformFunctionHandlerAdapter::Call( const Params& params )
{
ScaleformCallbackHolder* pCallback = ( ScaleformCallbackHolder* ) params.pUserData;
if ( pCallback )
{
pCallback->Execute(const_cast<Params*>(&params ));
}
}
void ScaleformCallbackHolder::OnDestroy( Movie* pmovie, void* pobject )
{
Release();
}
/********************************
* this lets scaleform use the valve file location stuff
*/
SF::File* ScaleformFileOpener::OpenFile( const char *purl, int flags, int modes )
{
MEM_ALLOC_CREDIT();
return OpenFileEx( purl, NULL, flags, modes );
}
SF::SInt64 ScaleformFileOpener::GetFileModifyTime( const char *purl )
{
SF::SInt64 result = g_pFullFileSystem->GetFileTime( purl, "GAME" );
return !result ? -1 : 0;
}
// Implementation that allows us to override the log.
SF::File* ScaleformFileOpener::OpenFileEx( const char *pfilename, Log *plog, int flags, int modes )
{
MEM_ALLOC_CREDIT();
if ( ( flags & ~SF::FileConstants::Open_Buffered ) != SF::FileConstants::Open_Read )
{
if ( plog )
{
plog->LogError( "Error: GFxLoader cannot open '%s' for writing. writing is not supported\n", pfilename );
}
return NULL;
}
SFUIMemoryFile* pin = new SFUIMemoryFile( pfilename );
const char* realName = SFINST.CorrectFlashFileName( pfilename );
extern IScaleformSlotInitController *g_pExternalScaleformSlotInitController;
// is this an image stored in the stringtables?
if ( char const *szExternalImg = StringAfterPrefix( realName, "img://stringtables:" ) )
{
// skip width and height attributes if they exist "(64x128):"
const char * szExternalImgPostSizeParm = strstr( szExternalImg, "):" );
if ( szExternalImgPostSizeParm != NULL )
{
szExternalImg = szExternalImgPostSizeParm + 2;
}
int length = 0;
const void * pImageData = NULL;
if ( g_pExternalScaleformSlotInitController )
{
pImageData = g_pExternalScaleformSlotInitController->GetStringUserData( "InfoPanel", szExternalImg, &length );
if ( pImageData )
{
pin->GetBuffer().SetExternalBuffer( (void *)pImageData, length, 0, pin->GetBuffer().READ_ONLY );
pin->Init();
}
else
{
pin->Release();
pin = NULL;
}
}
}
else if ( g_pFullFileSystem->ReadFile( realName, "GAME", pin->GetBuffer() ) )
{
if ( g_pExternalScaleformSlotInitController )
g_pExternalScaleformSlotInitController->OnFileLoadedByScaleform( realName, pin->GetBuffer().Base(), pin->GetBuffer().TellPut() );
pin->Init();
}
else
{
if ( g_pExternalScaleformSlotInitController )
g_pExternalScaleformSlotInitController->OnFileLoadedByScaleform( realName, NULL, 0 );
pin->Release();
pin = NULL;
if ( plog )
{
plog->LogError( "Error: GFxLoader failed to open '%s'\n", realName );
}
}
return pin;
}
/********************************
* this lets scaleform use our gamer icons and any other dynamic textures
*/
CScaleformImageCreator::CScaleformImageCreator( IScaleformUI *pSFUI, TextureManager* textureManager /* = 0 */)
: ImageCreator( textureManager ), m_pScaleformUI( pSFUI )
{
}
Image* CScaleformImageCreator::LoadProtocolImage(const ImageCreateInfo& info, const SF::String& url)
{
MEM_ALLOC_CREDIT();
// We use this to handle loadMovie calls from action script that
// we can use to load player avatar icons, inventory item images, Chrome HTML images, or extern files on disk.
// The url coming in should be something like this: img://<type>_<data>
//
// This is for loading external image sitting on disk
// Syntax1: img://loadfile:mylocalfile.jpg - loads the file, can be JPG, PNG, PGA, or DDS (must be uncompressed)
// Syntax2: img://loadfile:(64x64):mylocalfile.jpg - loads the file, returns a transparent texture of given size if doesn't exist
//
char const *szExternalImg = StringAfterPrefix( url, "img://loadfile:" );
// allow loadjpeg until flash is updated to use loadfile
if ( !szExternalImg )
{
szExternalImg = StringAfterPrefix( url, "img://loadjpeg:" );
}
if ( szExternalImg )
{
// Parse width and height attributes
uint width = 0, height = 0;
if ( szExternalImg[0] == '(' )
{
width = Q_atoi( szExternalImg + 1 );
szExternalImg = strchr( szExternalImg, 'x' );
if ( !szExternalImg )
return NULL;
height = Q_atoi( szExternalImg + 1 );
szExternalImg = strstr( szExternalImg, "):" );
if ( !szExternalImg )
return NULL;
szExternalImg += 2;
}
char chLocalPath[ 2*MAX_PATH + 1 ] = {};
const char *pchFullImgPath = szExternalImg[0] ? g_pFullFileSystem->RelativePathToFullPath( szExternalImg, "GAME", chLocalPath, Q_ARRAYSIZE( chLocalPath ) - 1 ) : NULL;
if ( pchFullImgPath )
{
Image *pImage = ( ( ScaleformUIImpl* )m_pScaleformUI )->CreateImageFromFile( pchFullImgPath, info, width, height );
return pImage;
}
}
// "img://avatar_[xuid]" where [xuid] is the xuid of the player whose avatar we want to load.
else if ( char const *szAvatarXuid = StringAfterPrefix( url, "img://avatar_" ) )
{
int64 xuid = Q_atoi64( szAvatarXuid );
ScaleformUIAvatarImage* pAvatarImage = ( ( ScaleformUIImpl* )m_pScaleformUI )->GetAvatarImage( xuid );
if ( pAvatarImage )
{
return pAvatarImage->GetImage();
}
}
// "img://inventory_[itemid]" where [itemid] is the item's id from GetItemIDbyIndex() in the inventory component.
else if ( char const *szInventoryItemId = StringAfterPrefix( url, "img://inventory_" ) )
{
uint64 itemid = Q_atoi64( szInventoryItemId );
// look up image here using xuid and itemid and return it
ScaleformUIInventoryImage* pInventoryImage = ( ( ScaleformUIImpl* )m_pScaleformUI )->GetInventoryImage( itemid );
if ( pInventoryImage )
{
return pInventoryImage->GetImage();
}
}
// "img://itemdata_[defindex]_[paintindex]" where [defindex] & [paintindex] are econ item definition and paint indices.
else if ( StringHasPrefix( url, "img://itemdata_" ) )
{
uint16 iDefIndex = 0;
uint16 iPaintIndex = 0;
{
CUtlVector< char* > urlFragments;
V_SplitString( url, "_", urlFragments );
iDefIndex = ( uint16 ) atoi( urlFragments[1] );
iPaintIndex = ( uint16 ) atoi( urlFragments[2] );
urlFragments.PurgeAndDeleteElements();
}
uint64 ullItemId = CombinedItemIdMakeFromDefIndexAndPaint( iDefIndex, iPaintIndex );
// look up image here using defindex and paintindex and return it
ScaleformUIInventoryImage* pInventoryImage = ( ( ScaleformUIImpl* )m_pScaleformUI )->GetInventoryImage( ullItemId );
if ( pInventoryImage )
{
return pInventoryImage->GetImage();
}
}
else if ( char const *szBilinearChromeImg = StringAfterPrefix( url, "img://chrome_" ) ) // using bilinear filtering
{
int64 imageid = Q_atoi64( szBilinearChromeImg );
// look up image here using xuid and itemid and return it
ScaleformUIChromeHTMLImage* pChromeImage = ( ( ScaleformUIImpl* )m_pScaleformUI )->GetChromeHTMLImage( imageid );
if ( pChromeImage )
{
return pChromeImage->GetImage();
}
}
else if ( char const *szPointSampleChromeImg = StringAfterPrefix( url, "imgps://chrome_" ) ) // point sampling filtering
{
int64 imageid = Q_atoi64( szPointSampleChromeImg );
// look up image here using xuid and itemid and return it
ScaleformUIChromeHTMLImage* pChromeImage = ( ( ScaleformUIImpl* )m_pScaleformUI )->GetChromeHTMLImage( imageid );
if ( pChromeImage )
{
return pChromeImage->GetImage();
}
}
else if ( char const *szExternalImg = StringAfterPrefix( url, "img://stringtables:" ) )
{
// Parse width and height attributes
uint width = 0, height = 0;
if ( szExternalImg[ 0 ] == '(' )
{
width = Q_atoi( szExternalImg + 1 );
szExternalImg = strchr( szExternalImg, 'x' );
if ( !szExternalImg )
return NULL;
height = Q_atoi( szExternalImg + 1 );
szExternalImg = strstr( szExternalImg, "):" );
if ( !szExternalImg )
return NULL;
szExternalImg += 2;
}
if ( !szExternalImg || !szExternalImg[ 0 ] )
return NULL;
// we're going to pass in the whole url because the prefix will signal to the file loader to get the data from stringtables rather than from the filesystem
Image *pImage = ( ( ScaleformUIImpl* )m_pScaleformUI )->CreateImageFromFile( url, info, width, height );
if ( pImage )
return pImage;
}
return NULL;
}

View File

@@ -0,0 +1,138 @@
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#if !defined( __SCALEFORMUIINTEGRATION_H__ )
#define __SCALEFORMUIINTEGRATION_H__
/****************************
* This is the wrapper around the valve memory manager
*/
class CScaleformSysAlloc: public SF::SysAlloc
{
public:
virtual void* Alloc( SF::UPInt size, SF::UPInt align );
virtual void Free( void* ptr, SF::UPInt size, SF::UPInt align );
virtual void* Realloc( void* oldPtr, SF::UPInt oldSize, SF::UPInt newSize, SF::UPInt align );
};
/*****************************************************
* This redirects the scaleform logging calls to CSTrike
*/
class ScaleformUILogging: public SF::Log
{
public:
virtual void LogMessageVarg( SF::LogMessageId messageId, const char* pfmt, va_list argList );
};
/******************************************************
* gives scaleform access tot he clipboard
*/
class ScaleformClipboard: public SF::GFx::TextClipboard
{
public:
virtual void OnTextStore( const wchar_t* ptext, SF::UPInt len );
};
/************************
* wraps the scaleform translation functions
*/
class ScaleformTranslatorAdapter: public SF::GFx::Translator
{
public:
virtual unsigned GetCaps( void ) const;
virtual void Translate( TranslateInfo* tinfo );
};
/********************
* used by CreateAPI. It attaches the movieview to the GFxValue of the api
*/
class ScaleformMovieUserData: public SF::GFx::ASUserData
{
public:
// this is a weak link
SF::GFx::Movie* m_pMovie;
virtual void OnDestroy( SF::GFx::Movie* pmovie, void* pobject );
};
/*****************************
* serves as a thunk between the scaleform code and the game code
*/
class ScaleformFunctionHandlerAdapter: public SF::GFx::FunctionHandler
{
public:
virtual void Call( const Params& params );
};
/********************************
* this lets scaleform use the valve file location stuff
*/
class ScaleformFileOpener : public SF::GFx::FileOpenerBase
{
public:
// Override to opens a file using user-defined function and/or GFile class.
// The default implementation uses buffer-wrapped GSysFile, but only
// if GFC_USE_SYSFILE is defined.
// The 'purl' should be encoded as UTF-8 to support international file names.
virtual SF::File* OpenFile(const char* purl,
int flags = SF::FileConstants::Open_Read|SF::FileConstants::Open_Buffered,
int mode = SF::FileConstants::Mode_ReadWrite);
// Returns last modified date/time required for file change detection.
// Can be implemented to return 0 if no change detection is desired.
// Default implementation checks file time if GFC_USE_SYSFILE is defined.
// The 'purl' should be encoded as UTF-8 to support international file names.
virtual SF::SInt64 GetFileModifyTime(const char* purl);
// Open file with customizable log, by relying on OpenFile.
// If not null, log will receive error messages on failure.
// The 'purl' should be encoded as UTF-8 to support international file names.
virtual SF::File* OpenFileEx(const char* purl, SF::GFx::Log *plog,
int flags = SF::FileConstants::Open_Read|SF::FileConstants::Open_Buffered,
int mode = SF::FileConstants::Mode_ReadWrite);
};
/********************************
* this lets scaleform use our gamer icons and any other dynamic textures
*/
class CScaleformImageCreator : public SF::GFx::ImageCreator
{
public:
CScaleformImageCreator( IScaleformUI *pSFUI, SF::GFx::TextureManager* textureManager = 0);
// Looks up image for "img://" protocol.
virtual SF::GFx::Image* LoadProtocolImage(const SF::GFx::ImageCreateInfo& info, const SF::String& url);
private:
IScaleformUI* m_pScaleformUI;
};
#endif

View File

@@ -0,0 +1,465 @@
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "stdafx.h"
// NOTE: This must be the last file included!!!
#include "tier0/memdbgon.h"
using namespace SF::GFx;
// Some utility functions to map SFUI enums to SF enums
Movie::ScaleModeType ScaleformUIImpl::ScaleModeType_SFUI_to_SDK( IScaleformUI::_ScaleModeType scaleModeType )
{
switch ( scaleModeType )
{
case IScaleformUI::SM_NoScale: return Movie::SM_NoScale;
case IScaleformUI::SM_ShowAll: return Movie::SM_ShowAll;
case IScaleformUI::SM_ExactFit: return Movie::SM_ExactFit;
case IScaleformUI::SM_NoBorder: return Movie::SM_NoBorder;
default:
AssertMsg( 0, "Unknown ScaleModeType\n");
return Movie::SM_NoScale;
}
};
IScaleformUI::_ScaleModeType ScaleformUIImpl::ScaleModeType_SDK_to_SFUI( Movie::ScaleModeType scaleModeType )
{
switch ( scaleModeType )
{
case Movie::SM_NoScale: return IScaleformUI::SM_NoScale;
case Movie::SM_ShowAll: return IScaleformUI::SM_ShowAll;
case Movie::SM_ExactFit: return IScaleformUI::SM_ExactFit;
case Movie::SM_NoBorder: return IScaleformUI::SM_NoBorder;
default:
AssertMsg( 0, "Unknown ScaleModeType\n");
return IScaleformUI::SM_NoScale;
}
};
Value::ValueType ScaleformUIImpl::ValueType_SFUI_to_SDK( IScaleformUI::_ValueType valueType )
{
switch ( valueType )
{
case IScaleformUI::VT_Undefined : return Value::VT_Undefined ;
case IScaleformUI::VT_Null : return Value::VT_Null ;
case IScaleformUI::VT_Boolean : return Value::VT_Boolean ;
case IScaleformUI::VT_Int : return Value::VT_Int ;
case IScaleformUI::VT_UInt : return Value::VT_UInt ;
case IScaleformUI::VT_Number : return Value::VT_Number ;
case IScaleformUI::VT_String : return Value::VT_String ;
case IScaleformUI::VT_StringW : return Value::VT_StringW ;
case IScaleformUI::VT_Object : return Value::VT_Object ;
case IScaleformUI::VT_Array : return Value::VT_Array ;
case IScaleformUI::VT_DisplayObject : return Value::VT_DisplayObject ;
case IScaleformUI::VT_Closure : return Value::VT_Closure ;
case IScaleformUI::VT_ConvertBoolean : return Value::VT_ConvertBoolean ;
case IScaleformUI::VT_ConvertInt : return Value::VT_ConvertInt ;
case IScaleformUI::VT_ConvertUInt : return Value::VT_ConvertUInt ;
case IScaleformUI::VT_ConvertNumber : return Value::VT_ConvertNumber ;
case IScaleformUI::VT_ConvertString : return Value::VT_ConvertString ;
case IScaleformUI::VT_ConvertStringW : return Value::VT_ConvertStringW ;
default:
AssertMsg( 0, "Unknown ValueType\n");
return Value::VT_Undefined;
}
}
IScaleformUI::_ValueType ScaleformUIImpl::ValueType_SDK_to_SFUI( Value::ValueType valueType )
{
switch ( valueType )
{
case Value::VT_Undefined : return IScaleformUI::VT_Undefined ;
case Value::VT_Null : return IScaleformUI::VT_Null ;
case Value::VT_Boolean : return IScaleformUI::VT_Boolean ;
case Value::VT_Int : return IScaleformUI::VT_Int ;
case Value::VT_UInt : return IScaleformUI::VT_UInt ;
case Value::VT_Number : return IScaleformUI::VT_Number ;
case Value::VT_String : return IScaleformUI::VT_String ;
case Value::VT_StringW : return IScaleformUI::VT_StringW ;
case Value::VT_Object : return IScaleformUI::VT_Object ;
case Value::VT_Array : return IScaleformUI::VT_Array ;
case Value::VT_DisplayObject : return IScaleformUI::VT_DisplayObject ;
case Value::VT_Closure : return IScaleformUI::VT_Closure ;
case Value::VT_ConvertBoolean : return IScaleformUI::VT_ConvertBoolean ;
case Value::VT_ConvertInt : return IScaleformUI::VT_ConvertInt ;
case Value::VT_ConvertUInt : return IScaleformUI::VT_ConvertUInt ;
case Value::VT_ConvertNumber : return IScaleformUI::VT_ConvertNumber ;
case Value::VT_ConvertString : return IScaleformUI::VT_ConvertString ;
case Value::VT_ConvertStringW : return IScaleformUI::VT_ConvertStringW ;
default:
AssertMsg( 0, "Unknown ValueType\n");
return IScaleformUI::VT_Undefined;
}
}
Movie::AlignType ScaleformUIImpl::AlignType_SFUI_to_SDK( IScaleformUI::_AlignType alignType )
{
switch ( alignType )
{
case IScaleformUI::Align_Center: return Movie::Align_Center;
case IScaleformUI::Align_TopCenter: return Movie::Align_TopCenter;
case IScaleformUI::Align_BottomCenter: return Movie::Align_BottomCenter;
case IScaleformUI::Align_CenterLeft: return Movie::Align_CenterLeft;
case IScaleformUI::Align_CenterRight: return Movie::Align_CenterRight;
case IScaleformUI::Align_TopLeft: return Movie::Align_TopLeft;
case IScaleformUI::Align_TopRight: return Movie::Align_TopRight;
case IScaleformUI::Align_BottomLeft: return Movie::Align_BottomLeft;
case IScaleformUI::Align_BottomRight: return Movie::Align_BottomRight;
default:
AssertMsg( 0, "Unknown AlignType\n");
return Movie::Align_Center;
}
}
IScaleformUI::_AlignType ScaleformUIImpl::AlignType_SDK_to_SFUI( Movie::AlignType alignType )
{
switch ( alignType )
{
case Movie::Align_Center: return IScaleformUI::Align_Center;
case Movie::Align_TopCenter: return IScaleformUI::Align_TopCenter;
case Movie::Align_BottomCenter: return IScaleformUI::Align_BottomCenter;
case Movie::Align_CenterLeft: return IScaleformUI::Align_CenterLeft;
case Movie::Align_CenterRight: return IScaleformUI::Align_CenterRight;
case Movie::Align_TopLeft: return IScaleformUI::Align_TopLeft;
case Movie::Align_TopRight: return IScaleformUI::Align_TopRight;
case Movie::Align_BottomLeft: return IScaleformUI::Align_BottomLeft;
case Movie::Align_BottomRight: return IScaleformUI::Align_BottomRight;
default:
AssertMsg( 0, "Unknown AlignType\n");
return IScaleformUI::Align_Center;
}
}
Movie::HitTestType ScaleformUIImpl::HitTestType_SFUI_to_SDK( IScaleformUI::_HitTestType hitTestType )
{
switch ( hitTestType )
{
case IScaleformUI::HitTest_Bounds: return Movie::HitTest_Bounds;
case IScaleformUI::HitTest_Shapes: return Movie::HitTest_Shapes;
case IScaleformUI::HitTest_ButtonEvents: return Movie::HitTest_ButtonEvents;
case IScaleformUI::HitTest_ShapesNoInvisible: return Movie::HitTest_ShapesNoInvisible;
default:
AssertMsg( 0, "Unknown HitTestType\n");
return Movie::HitTest_Bounds;
}
}
IScaleformUI::_HitTestType ScaleformUIImpl::HitTestType_SDK_to_SFUI( Movie::HitTestType hitTestType )
{
switch ( hitTestType )
{
case Movie::HitTest_Bounds: return IScaleformUI::HitTest_Bounds;
case Movie::HitTest_Shapes: return IScaleformUI::HitTest_Shapes;
case Movie::HitTest_ButtonEvents: return IScaleformUI::HitTest_ButtonEvents;
case Movie::HitTest_ShapesNoInvisible: return IScaleformUI::HitTest_ShapesNoInvisible;
default:
AssertMsg( 0, "Unknown HitTestType\n");
return IScaleformUI::HitTest_Bounds;
}
}
class ScaleformMovieDefHolder: public ASUserData
{
public:
// this is a weak pointer
MovieDef* m_pMovieDef;
inline ScaleformMovieDefHolder( MovieDef *pdef ) :
ASUserData(), m_pMovieDef( pdef )
{
}
virtual void OnDestroy( Movie* pmovie, void* pobject )
{
Release();
}
};
void ScaleformUIImpl::InitMovieImpl( void )
{
}
void ScaleformUIImpl::ShutdownMovieImpl( void )
{
#if defined( _DEBUG )
if ( m_MovieViews.Count() )
{
LogPrintf( "Scaleform: Some movie views were not released\n" );
for ( int i = 0; i < m_MovieViews.Count(); i++ )
{
ASUserData* pud = ( ASUserData* )m_MovieViews[i]->GetUserData();
ScaleformMovieDefHolder* pDef = ( ScaleformMovieDefHolder* ) pud;
if ( pDef )
{
LogPrintf( " %s\n", pDef->m_pMovieDef->GetFileURL() );
}
else
{
LogPrintf( " unknown slot movie\n" );
}
if ( pud )
{
pud->OnDestroy( m_MovieViews[i],NULL );
}
m_MovieViews[i]->SetUserData( NULL );
}
}
if ( m_MovieDefNameCache.Count() )
{
LogPrintf( "Scaleform: Some movie defs were not released\n" );
for ( int i = 0; i < m_MovieDefNameCache.Count(); i++ )
{
LogPrintf( " %s\n", m_MovieDefNameCache[i] );
}
}
#endif
}
SFMOVIEDEF ScaleformUIImpl::CreateMovieDef( const char* pfilename, unsigned int loadConstants, size_t memoryArena )
{
// first see if we've already got the guy loaded
MovieDef* presult = NULL;
for ( int i = 0; i < m_MovieDefNameCache.Count(); i++ )
{
if ( !V_stricmp( m_MovieDefNameCache[i], pfilename ) )
{
presult = m_MovieDefCache[i];
presult->AddRef();
break;
}
}
if ( presult == NULL )
{
presult = m_pLoader->CreateMovie( pfilename, loadConstants, memoryArena );
m_MovieDefCache.AddToTail( presult );
char* newString = new char[V_strlen( pfilename )+1];
V_strcpy( newString, pfilename );
m_MovieDefNameCache.AddToTail( newString );
}
return ToSFMOVIEDEF( presult );
}
void ScaleformUIImpl::ReleaseMovieDef( SFMOVIEDEF movieDef )
{
MovieDef* pdef = FromSFMOVIEDEF( movieDef );
int refcount = pdef->GetRefCount();
pdef->Release();
// we actually removed this
if ( refcount == 1 )
{
for ( int i = 0; i < m_MovieDefCache.Count(); i++ )
{
if ( m_MovieDefCache[i] == pdef )
{
delete[] m_MovieDefNameCache[i];
m_MovieDefCache.FastRemove( i );
m_MovieDefNameCache.FastRemove( i );
break;
}
}
}
}
SFMOVIE ScaleformUIImpl::MovieDef_CreateInstance( SFMOVIEDEF movieDef, bool initFirstFrame, size_t memoryArena )
{
MovieDef* pDef = FromSFMOVIEDEF( movieDef );
Movie* pView = pDef->CreateInstance( initFirstFrame, memoryArena, 0, m_pThreadCommandQueue );
if ( pView )
{
#if defined( _DEBUG )
// only need this so we can print the name of the movie if we don't release it
ScaleformMovieDefHolder* def = new ScaleformMovieDefHolder( pDef );
pView->SetUserData( def );
#endif // _DEBUG
m_MovieViews.AddToTail( pView );
}
return ToSFMOVIE( pView );
}
void ScaleformUIImpl::ReleaseMovieView( SFMOVIE movieView )
{
if ( movieView )
{
m_MovieViews.FindAndFastRemove( FromSFMOVIE( movieView ) );
#if defined( _DEBUG )
ScaleformMovieDefHolder* def = ( ScaleformMovieDefHolder* )FromSFMOVIE( movieView )->GetUserData();
if ( def )
{
def->OnDestroy( FromSFMOVIE( movieView ), NULL );
}
FromSFMOVIE( movieView )->SetUserData( NULL );
#endif
// This needs to execute on the render thread via a command queue. It only works here
// because typically when we free movies either QMS is off, or the qms is not very active
// because we are loading/unloading maps
Movie *pMovie = FromSFMOVIE( movieView );
pMovie->ShutdownRendering( false );
while ( !pMovie->IsShutdownRenderingComplete() )
{
if ( m_pRenderer2D->GetContextNotify() )
{
MovieDisplayHandle hMovieDisplay = pMovie->GetDisplayHandle();
hMovieDisplay.NextCapture( m_pRenderer2D->GetContextNotify() );
m_pRenderer2D->GetContextNotify()->EndFrameContextNotify();
}
}
pMovie->Release();
}
}
void ScaleformUIImpl::MovieView_Advance( SFMOVIE movieView, float time, unsigned int frameCatchUpCount )
{
FromSFMOVIE( movieView )->Advance( time, frameCatchUpCount );
}
void ScaleformUIImpl::MovieView_SetBackgroundAlpha( SFMOVIE movieView, float alpha )
{
FromSFMOVIE( movieView )->SetBackgroundAlpha( alpha );
}
void ScaleformUIImpl::MovieView_SetViewport( SFMOVIE movieView, int bufw, int bufh, int left, int top, int w, int h, unsigned int flags )
{
FromSFMOVIE( movieView )->SetViewport( bufw, bufh, left, top, w, h, flags );
}
void ScaleformUIImpl::MovieView_Display( SFMOVIE movieView )
{
MovieDisplayHandle hMovieDisplay = FromSFMOVIE( movieView )->GetDisplayHandle();
if ( hMovieDisplay.NextCapture( m_pRenderer2D->GetContextNotify() ) )
{
m_pRenderer2D->Display( hMovieDisplay );
}
}
/***
* view alignment and scaling
*/
void ScaleformUIImpl::MovieView_SetViewScaleMode( SFMOVIE movieView, IScaleformUI::_ScaleModeType type )
{
FromSFMOVIE( movieView )->SetViewScaleMode( ScaleModeType_SFUI_to_SDK( type ) );
}
IScaleformUI::_ScaleModeType ScaleformUIImpl::MovieView_GetViewScaleMode( SFMOVIE movieView )
{
return ScaleModeType_SDK_to_SFUI( FromSFMOVIE( movieView )->GetViewScaleMode() );
}
void ScaleformUIImpl::MovieView_SetViewAlignment( SFMOVIE movieView, IScaleformUI::_AlignType type )
{
FromSFMOVIE( movieView )->SetViewAlignment( AlignType_SFUI_to_SDK( type ) );
}
IScaleformUI::_AlignType ScaleformUIImpl::MovieView_GetViewAlignment( SFMOVIE movieView )
{
return AlignType_SDK_to_SFUI( FromSFMOVIE( movieView )->GetViewAlignment() );
}
/***************************
* values
*/
SFVALUE ScaleformUIImpl::MovieView_CreateString( SFMOVIE movieView, const char *str )
{
Value* pResult = FromSFVALUE( CreateGFxValue() );
FromSFMOVIE( movieView )->CreateString( pResult, str );
return ToSFVALUE( pResult );
}
SFVALUE ScaleformUIImpl::MovieView_CreateStringW( SFMOVIE movieView, const wchar_t *str )
{
Value* pResult = FromSFVALUE( CreateGFxValue() );
FromSFMOVIE( movieView )->CreateStringW( pResult, str );
return ToSFVALUE( pResult );
}
SFVALUE ScaleformUIImpl::MovieView_CreateObject( SFMOVIE movieView, const char* className, SFVALUEARRAY args, int numArgs )
{
Assert(numArgs == args.Count());
if ( numArgs != args.Count() )
{
Warning("MovieView_CreateObject(%s) called with numArgs different than SFVALUEARRAY size\n", className);
}
Value* pResult = FromSFVALUE( CreateGFxValue() );
FromSFMOVIE( movieView )->CreateObject( pResult, className, FromSFVALUE( args.GetValues() ), args.Count() );
return ToSFVALUE( pResult );
}
SFVALUE ScaleformUIImpl::MovieView_CreateArray( SFMOVIE movieView, int size )
{
Value* pResult = FromSFVALUE( CreateGFxValue() );
FromSFMOVIE( movieView )->CreateArray( pResult );
if ( size != -1 )
pResult->SetArraySize( size );
return ToSFVALUE( pResult );
}
SFVALUE ScaleformUIImpl::MovieView_GetVariable( SFMOVIE movieView, const char* variablePath )
{
Value var;
Value* pResult = NULL;
bool worked = FromSFMOVIE( movieView )->GetVariable( &var, variablePath );
if ( worked )
{
pResult = FromSFVALUE( CreateGFxValue( ToSFVALUE( &var ) ) );
}
return ToSFVALUE( pResult );
}
/***********
* hit testing
*/
bool ScaleformUIImpl::MovieView_HitTest( SFMOVIE movieView, float x, float y, IScaleformUI::_HitTestType testCond, unsigned int controllerIdx )
{
return FromSFMOVIE( movieView )->HitTest( x, y, HitTestType_SFUI_to_SDK(testCond), controllerIdx );
}

View File

@@ -0,0 +1,713 @@
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "stdafx.h"
#if defined( DX_TO_GL_ABSTRACTION )
#include "tier1/keyvalues.h"
#endif
#include "shaderapi/ishaderapi.h"
// NOTE: This has to be the last file included!
#include "tier0/memdbgon.h"
using namespace SF::GFx;
using namespace SF::Render;
#if (defined(_DEBUG) || defined(USE_MEM_DEBUG))
#define MEM_ALLOC_CREDIT_FORMATF( formatStr, slotNumber ) \
char szName[64]; \
V_snprintf( szName, ARRAYSIZE(szName), formatStr, slotNumber ); \
MEM_ALLOC_CREDIT_( szName );
#else
#define MEM_ALLOC_CREDIT_FORMATF (void)
#endif
#if defined( _PS3 ) || defined( _X360 )
ConVar scaleform_mesh_caching_enable( "scaleform_mesh_caching_enable", "1" );
static void scaleform_dump_mesh_caching_stats_f( const CCommand &args );
ConCommand scaleform_dump_mesh_caching_stats( "scaleform_dump_mesh_caching_stats", scaleform_dump_mesh_caching_stats_f, "Dumps stats about scaleform mesh caching" );
bool g_bScaleformMeshCaching = true; // Cache VBs & IBs for scaleform batches to reuse across frames
// Counters to track usage of scaleform mesh caching
int g_nScaleformCachedVBAlive = 0; // number of VBs currently allocated for mesh caching
int g_nScaleformCachedIBAlive = 0; // number of IBs currently allocated for mesh caching
int g_nScaleformCachedVBDead = 0; // number of cached VBs that have been cleaned up (add to # alive to get total ever allocated)
int g_nScaleformCachedIBDead = 0; // number of cached IBs that have been cleaned up (add to # alive to get total ever allocated)
static void scaleform_dump_mesh_caching_stats_f( const CCommand &args )
{
Msg( "VBs alive: %d\nIBs alive: %d\nVBs dead: %d\nIBs dead: %d\n", g_nScaleformCachedVBAlive, g_nScaleformCachedIBAlive, g_nScaleformCachedVBDead, g_nScaleformCachedIBDead );
}
#endif
ConVar r_drawscaleform( "r_drawscaleform", "1",
#if defined( DEVELOPMENT_ONLY ) || defined( ALLOW_TEXT_MODE )
FCVAR_RELEASE
#else
0
#endif
);
void ScaleformUIImpl::InitMovieSlotImpl( void )
{
V_memset( m_SlotPtrs, 0, sizeof( m_SlotPtrs ) );
V_memset( m_SlotDeniesInputRefCount, 0, sizeof( m_SlotDeniesInputRefCount ) );
}
void ScaleformUIImpl::ShutdownMovieSlotImpl( void )
{
#if defined ( _DEBUG )
for ( int i = 0; i < MAX_SLOTS; i++ )
{
const char* slotName;
if ( m_SlotPtrs[i] != NULL )
{
switch( i )
{
case SF_RESERVED_CURSOR_SLOT:
slotName = "Cursor";
break;
case SF_FULL_SCREEN_SLOT:
slotName = "Full Screen";
break;
case SF_FIRST_SS_SLOT:
slotName = "Base Client";
break;
default:
slotName= "Other Split Screen";
break;
}
LogPrintf( "Scaleform: UI slot \"%s Slot\" ( #%d ) not released\n", slotName, i );
}
}
#endif
}
BaseSlot* ScaleformUIImpl::LockSlotPtr( int slot )
{
AssertMsg( slot >= 0 && slot < MAX_SLOTS, "Invalid slot index in LockSlotPtr" );
// gurjeets - locks commented out, left here for reference
// Currently we only queue a couple of SF-related functions to be called from the render thread (see cmatqueuedrendercontext.h)
// These are RenderSlot() and SetSlotViewport(). It's safe to call these in parallel along with whatever's
// happening on the main thread. They are also called from the main thread but only at times when when QMS is not enabled
// The Lock/Unlock slot ptr functions are effectively just for ref counting, which is thread safe
//m_SlotMutexes[slot].Lock();
BaseSlot* presult = m_SlotPtrs[slot];
if ( presult )
{
presult->AddRef();
}
return presult;
}
void ScaleformUIImpl::UnlockSlotPtr( int slot )
{
AssertMsg( slot >= 0 && slot < MAX_SLOTS, "Invalid slot index in UnlockSlotPtr" );
if ( m_SlotPtrs[slot] && m_SlotPtrs[slot]->Release() )
{
m_SlotPtrs[slot] = NULL;
}
// gurjeets - locks commented out, left here for reference, see comment in LockSlotPtr
//m_SlotMutexes[slot].Unlock();
}
void ScaleformUIImpl::LockSlot( int slot )
{
AssertMsg( slot >= 0 && slot < MAX_SLOTS, "Invalid slot index in LockSlot" );
// gurjeets - locks commented out, left here for reference, see comment in LockSlotPtr
//m_SlotMutexes[slot].Lock();
}
void ScaleformUIImpl::UnlockSlot( int slot )
{
AssertMsg( slot >= 0 && slot < MAX_SLOTS, "Invalid slot index in UnlockSlot" );
// gurjeets - locks commented out, left here for reference, see comment in LockSlotPtr
//m_SlotMutexes[slot].Unlock();
}
void ScaleformUIImpl::SlotAddRef( int slot )
{
AssertMsg( slot >= 0 && slot < MAX_SLOTS, "Invalid slot index in SlotAddRef" );
LockSlotPtr( slot );
// gurjeets - locks commented out, left here for reference, see comment in LockSlotPtr
//m_SlotMutexes[slot].Unlock();
}
void ScaleformUIImpl::SlotRelease( int slot )
{
AssertMsg( slot >= 0 && slot < MAX_SLOTS, "Invalid slot index in SlotRelease" );
// gurjeets - locks commented out, left here for reference, see comment in LockSlotPtr
//m_SlotMutexes[slot].Lock();
UnlockSlotPtr( slot );
}
IScaleformSlotInitController *g_pExternalScaleformSlotInitController = NULL;
void ScaleformUIImpl::InitSlot( int slotID, const char* rootMovie, IScaleformSlotInitController *pController )
{
g_pExternalScaleformSlotInitController = pController;
MEM_ALLOC_CREDIT_FORMATF( "ScaleformUIImpl::InitSlot%d", slotID );
// gurjeets - locks commented out, left here for reference, see comment in LockSlotPtr
//m_SlotMutexes[slotID].Lock();
if ( !m_SlotPtrs[slotID] )
{
MovieSlot* slotptr = new MovieSlot();
m_SlotPtrs[slotID] = slotptr;
m_SlotDeniesInputRefCount[slotID] = 0;
slotptr->Init( rootMovie, slotID );
if ( pController )
pController->ConfigureNewSlotPostInit( slotID );
}
else
{
m_SlotPtrs[slotID]->AddRef();
}
SFDevMsg("ScaleformUIImpl::InitSlot( %d, %s) refcount=%d\n", slotID, rootMovie, m_SlotPtrs[slotID]->m_iRefCount);
// gurjeets - locks commented out, left here for reference, see comment in LockSlotPtr
//m_SlotMutexes[slotID].Unlock();
}
void ScaleformUIImpl::RequestElement( int slot, const char* elementName, ScaleformUIFunctionHandlerObject* object, const IScaleformUIFunctionHandlerDefinitionTable* tableObject )
{
MEM_ALLOC_CREDIT();
BaseSlot* pslot = LockSlotPtr( slot );
if ( pslot )
{
SFDevMsg("ScaleformUIImpl::RequestElement( %d, %s)\n", slot, elementName);
pslot->RequestElement( elementName, object, tableObject );
}
UnlockSlotPtr( slot );
}
void ScaleformUIImpl::RemoveElement( int slot, SFVALUE element )
{
MEM_ALLOC_CREDIT();
BaseSlot* pslot = LockSlotPtr( slot );
if ( pslot )
{
pslot->RemoveElement( (Scaleform::GFx::Value*)element );
}
UnlockSlotPtr( slot );
}
void ScaleformUIImpl::InstallGlobalObject( int slot, const char* elementName, ScaleformUIFunctionHandlerObject* object, const IScaleformUIFunctionHandlerDefinitionTable* tableObject, SFVALUE *pInstalledGlobalObjectResult )
{
MEM_ALLOC_CREDIT();
BaseSlot* pslot = LockSlotPtr( slot );
if ( pslot )
{
SFDevMsg("ScaleformUIImpl::InstallGlobalObject( %d, %s)\n", slot, elementName);
pslot->InstallGlobalObject( elementName, object, tableObject, (Scaleform::GFx::Value* *) pInstalledGlobalObjectResult );
}
UnlockSlotPtr( slot );
}
void ScaleformUIImpl::RemoveGlobalObject( int slot, SFVALUE element )
{
MEM_ALLOC_CREDIT();
BaseSlot* pslot = LockSlotPtr( slot );
if ( pslot )
{
pslot->RemoveGlobalObject( (Scaleform::GFx::Value*)element );
}
UnlockSlotPtr( slot );
}
void ScaleformUIImpl::SetSlotViewport( int slot, int x, int y, int width, int height )
{
MEM_ALLOC_CREDIT();
BaseSlot* pslot = LockSlotPtr( slot );
if ( pslot )
{
pslot->m_pMovieView->SetViewport( m_iScreenWidth, m_iScreenHeight, x, y, width, height );
}
UnlockSlotPtr( slot );
}
static bool s_bScaleformInFrame = false;
void ScaleformUIImpl::RenderSlot( int slot )
{
if ( !r_drawscaleform.GetBool() )
return;
MEM_ALLOC_CREDIT_FORMATF( "ScaleformUIImpl::RenderSlot%d", slot );
if (slot == SF_RESERVED_BEGINFRAME_SLOT)
{
m_pShaderAPI->ResetRenderState( false );
#if defined( DX_TO_GL_ABSTRACTION )
// Removed for Linux merge (trunk in 2002 -> //console/csgo/trunk in 2001) - do we need these
// m_pDevice->FlushStates( 0xFFFFFFFF );
// m_pDevice->FlushSamplers();
#endif
s_bScaleformInFrame = m_pRenderer2D->BeginFrame();
return;
}
if (slot == SF_RESERVED_ENDFRAME_SLOT)
{
m_pRenderer2D->EndFrame();
m_pShaderAPI->ResetRenderState( false );
#if defined( DX_TO_GL_ABSTRACTION )
// Removed for Linux merge (trunk in 2002 -> //console/csgo/trunk in 2001) - do we need these
// m_pDevice->FlushStates( 0xFFFFFFFF );
// m_pDevice->FlushSamplers();
#endif
return;
}
if ( !s_bScaleformInFrame )
{
// Device lost, but still need to call NextCapture to avoid leaking memory
BaseSlot* pslot = LockSlotPtr( slot );
if (pslot)
{
MovieDisplayHandle hMovieDisplay = ((Movie*)pslot->m_pMovieView)->GetDisplayHandle();
hMovieDisplay.NextCapture( m_pRenderer2D->GetContextNotify() );
}
UnlockSlotPtr( slot );
return;
}
SaveRenderingState();
if ( m_pRenderHAL )
{
m_pRenderHAL->GetTextureManager()->SetRenderThreadIdToCurrentThread();
if ( m_bClearMeshCacheQueued )
{
// Clear the mesh cache to recover memory. The mesh cache will clear itself after hitting a threshold,
// but in practice this threshold can large enough that it bleeds a lot of memory on console.
// We also want to avoid performance spikes caused by clearing and refilling this cache in the middle
// of gameplay. So this accessor allows us to reset the cache on demand at a less noticeable point,
// e.g. the end of a round, or when we transition between maps.
MeshCache& meshCache = m_pRenderHAL->GetMeshCache();
meshCache.ClearCache();
m_bClearMeshCacheQueued = false;
}
#ifdef DX_TO_GL_ABSTRACTION
// On Linux, we have to flip the display.
SF::Render::Matrix2F matrix;
matrix.Sy() = -1.0f;
matrix.Ty() = m_iScreenHeight;
m_pRenderHAL->SetUserMatrix(matrix);
#endif
}
BaseSlot* pslot = LockSlotPtr( slot );
if ( pslot )
{
MovieView_Display( ToSFMOVIE( pslot->m_pMovieView ) );
}
UnlockSlotPtr( slot );
RestoreRenderingState();
}
void ScaleformUIImpl::ForkRenderSlot( int slot )
{
}
void ScaleformUIImpl::JoinRenderSlot( int slot )
{
}
void ScaleformUIImpl::AdvanceSlot( int slot )
{
if ( !r_drawscaleform.GetBool() )
return;
MEM_ALLOC_CREDIT_FORMATF( "ScaleformUIImpl::AdvanceSlot%d", slot );
BaseSlot* pslot = LockSlotPtr( slot );
if ( pslot )
{
// Using m_fTime set in RunFrame
pslot->Advance( m_fTime );
}
UnlockSlotPtr( slot );
}
bool ScaleformUIImpl::SlotConsumesInputEvents( int slot )
{
MEM_ALLOC_CREDIT_FORMATF( "ScaleformUIImpl::SlotConsumesInputEvents%d", slot );
bool result = false;
BaseSlot* pslot = m_SlotPtrs[ slot ];
if ( pslot )
{
result = pslot->ConsumesInputEvents();
}
return result;
}
bool ScaleformUIImpl::SlotDeniesInputToGame( int slot )
{
MEM_ALLOC_CREDIT_FORMATF( "ScaleformUIImpl::SlotDeniesInputToGame%d", slot );
if ( m_bDenyAllInputToGame )
return true;
if ( slot < MAX_SLOTS )
return ( m_SlotDeniesInputRefCount[slot] > 0 );
else
return false;
}
void ScaleformUIImpl::DenyInputToGameFromFlash( int slot, bool value )
{
if ( value )
{
m_SlotDeniesInputRefCount[slot]++;
}
else
{
Assert( m_SlotDeniesInputRefCount[slot] > 0 );
m_SlotDeniesInputRefCount[slot]--;
}
SFDevMsg( "ScaleformUIImpl::DenyInputToGameFromFlash(%d,%d) m_SlotDeniesInputRefCount[%d]=%d \n", slot, value?1:0, slot, m_SlotDeniesInputRefCount[slot] );
}
bool ScaleformUIImpl::AnalogStickNavigationDisabled( int slot )
{
MEM_ALLOC_CREDIT_FORMATF( "ScaleformUIImpl::AnalogStickNavigationDisabled%d", slot );
bool result = false;
if ( slot < MAX_SLOTS )
{
BaseSlot* pslot = m_SlotPtrs[ slot ];
if ( pslot )
{
MovieSlot* pMovieSlot = dynamic_cast<MovieSlot*>( pslot );
if ( pMovieSlot )
{
result = pMovieSlot->AnalogStickNavigationDisabled();
}
}
}
return result;
}
void ScaleformUIImpl::UpdateSafeZone( void )
{
MEM_ALLOC_CREDIT();
for ( int i = SF_FIRST_UNRESERVED_SLOT; i < MAX_SLOTS; i++ )
{
BaseSlot* pslot = LockSlotPtr( i );
if ( pslot )
{
pslot->UpdateSafeZone();
}
UnlockSlotPtr( i );
}
}
void ScaleformUIImpl::UpdateTint( void )
{
MEM_ALLOC_CREDIT();
for ( int i = SF_FIRST_UNRESERVED_SLOT; i < MAX_SLOTS; i++ )
{
BaseSlot* pslot = LockSlotPtr( i );
if ( pslot )
{
pslot->UpdateTint();
}
UnlockSlotPtr( i );
}
}
bool ScaleformUIImpl::ConsumesInputEvents( void )
{
MEM_ALLOC_CREDIT();
if ( m_bDenyAllInputToGame )
return true;
for ( int i = SF_FIRST_UNRESERVED_SLOT; i < MAX_SLOTS; i++ )
{
if ( SlotConsumesInputEvents( i ) )
{
return true;
}
}
return false;
}
void ScaleformUIImpl::ForceUpdateImages()
{
MEM_ALLOC_CREDIT();
for ( int i = SF_FIRST_UNRESERVED_SLOT; i < MAX_SLOTS; i++ )
{
BaseSlot* pSlot = LockSlotPtr( i );
if ( pSlot && pSlot->m_pMovieView )
{
pSlot->m_pMovieView->ForceUpdateImages();
}
UnlockSlotPtr( i );
}
}
void ScaleformUIImpl::DenyInputToGame( bool value )
{
m_bDenyAllInputToGame = value;
SFDevMsg( "ScaleformUIImpl::DenyInputToGame(%d)\n", value?1:0 );
}
SFVALUE ScaleformUIImpl::CreateNewObject( int slot )
{
MEM_ALLOC_CREDIT();
SFVALUE result = NULL;
BaseSlot* pslot = LockSlotPtr( slot );
if ( pslot )
{
Movie* pmovie = pslot->m_pMovieView;
Value* pResult = (Value*)CreateGFxValue();
pmovie->CreateObject( pResult );
result = ( SFVALUE )pResult;
}
UnlockSlotPtr( slot );
return result;
}
SFVALUE ScaleformUIImpl::CreateNewArray( int slot, int size )
{
MEM_ALLOC_CREDIT();
SFVALUE result = NULL;
BaseSlot* pslot = LockSlotPtr( slot );
if ( pslot )
{
Movie* pmovie = pslot->m_pMovieView;
Value* pResult = (Value*)CreateGFxValue();
pmovie->CreateArray( pResult );
if ( size != -1 )
pResult->SetArraySize( size );
result = ( SFVALUE )pResult;
}
UnlockSlotPtr( slot );
return result;
}
SFVALUE ScaleformUIImpl::CreateNewString( int slot, const char* value )
{
MEM_ALLOC_CREDIT();
SFVALUE result = NULL;
BaseSlot* pslot = LockSlotPtr( slot );
if ( pslot )
{
Movie* pmovie = pslot->m_pMovieView;
Value* pResult = (Value*)CreateGFxValue();
pmovie->CreateString( pResult, value );
result = ( SFVALUE )pResult;
}
UnlockSlotPtr( slot );
return result;
}
SFVALUE ScaleformUIImpl::CreateNewString( int slot, const wchar_t* value )
{
MEM_ALLOC_CREDIT();
SFVALUE result = NULL;
BaseSlot* pslot = LockSlotPtr( slot );
if ( pslot )
{
Movie* pmovie = pslot->m_pMovieView;
Value* pResult = (Value*)CreateGFxValue();
pmovie->CreateStringW( pResult, value );
result = ( SFVALUE )pResult;
}
UnlockSlotPtr( slot );
return result;
}
void ScaleformUIImpl::LockInputToSlot( int slot )
{
MEM_ALLOC_CREDIT_FORMATF( "ScaleformUIImpl::LockInputToSlot%d", slot );
BaseSlot* pslot = LockSlotPtr( SF_FULL_SCREEN_SLOT );
if ( pslot )
{
pslot->LockInputToSlot( slot );
}
UnlockSlotPtr( SF_FULL_SCREEN_SLOT );
}
void ScaleformUIImpl::UnlockInput( void )
{
MEM_ALLOC_CREDIT();
BaseSlot* pslot = LockSlotPtr( SF_FULL_SCREEN_SLOT );
if ( pslot )
{
pslot->UnlockInput();
}
UnlockSlotPtr( SF_FULL_SCREEN_SLOT );
}
void ScaleformUIImpl::ForceCollectGarbage( int slot )
{
BaseSlot* pslot = m_SlotPtrs[ slot ];
if ( pslot )
{
pslot->ForceCollectGarbage( );
}
}
void ScaleformUIImpl::SetToControllerUI( int slot, bool value )
{
BaseSlot* pslot = LockSlotPtr( slot );
if ( pslot )
{
pslot->SetToControllerUI( value, true );
}
UnlockSlotPtr( slot );
}
void ScaleformUIImpl::LockMostRecentInputDevice( int slot )
{
BaseSlot* pslot = m_SlotPtrs[ slot ];
if ( pslot )
{
pslot->LockMostRecentInputDevice();
}
}
bool ScaleformUIImpl::IsSetToControllerUI( int slot )
{
bool result = false;
BaseSlot* pslot = m_SlotPtrs[ slot ];
if ( pslot == NULL || !pslot->ConsumesInputEvents() )
{
// Specified slot does not consume input events, or does not exist. Test the full screen slot instead.
slot = SF_FULL_SCREEN_SLOT;
pslot = m_SlotPtrs[ slot ];
}
if ( pslot )
{
result = pslot->IsSetToControllerUI();
}
return result;
}

View File

@@ -0,0 +1,215 @@
//========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "stdafx.h"
// NOTE: This must be the last file included!!!
#include "tier0/memdbgon.h"
using namespace Scaleform::GFx;
// Uncomment this to check you are not trying to access an invalid params and the
// type is correct
// Comment in pc-beta
//#define SF_CHECK_PARAMS_VALID
#if defined( SF_CHECK_PARAMS_VALID )
#define SF_PARAMS_ASSERT( _exp, _msg ) AssertMsgAlways( _exp, _msg )
#else
#define SF_PARAMS_ASSERT( _exp, _msg ) ((void)0)
#endif
SFVALUEARRAY ScaleformUIImpl::Params_GetArgs( SFPARAMS sfparams )
{
FunctionHandler::Params* pParams = FromSFPARAMS(sfparams);
return SFVALUEARRAY( pParams->ArgCount, ToSFVALUE( pParams->pArgs ) );
}
unsigned int ScaleformUIImpl::Params_GetNumArgs( SFPARAMS params )
{
return FromSFPARAMS(params)->ArgCount;
}
SFVALUE ScaleformUIImpl::Params_GetArg( SFPARAMS params, int index )
{
FunctionHandler::Params* pParams = FromSFPARAMS(params);
SF_PARAMS_ASSERT( (uint)index < pParams->ArgCount, "SF param out of range!" );
return ToSFVALUE( &( pParams->pArgs[index] ) );
}
IScaleformUI::_ValueType ScaleformUIImpl::Params_GetArgType( SFPARAMS params, int index )
{
FunctionHandler::Params* pParams = FromSFPARAMS(params);
SF_PARAMS_ASSERT( (uint)index < pParams->ArgCount, "SF param out of range!" );
return ((uint)index < pParams->ArgCount) ? ValueType_SDK_to_SFUI( pParams->pArgs[index].GetType() ) : IScaleformUI::VT_Undefined;
}
bool ScaleformUIImpl::Params_ArgIs( SFPARAMS params, unsigned int index, IScaleformUI::_ValueType v )
{
if ( index < ( FromSFPARAMS(params) )->ArgCount )
{
return ( ValueType_SDK_to_SFUI( FromSFPARAMS(params)->pArgs[index].GetType() ) == v );
}
else
{
return false;
}
}
double ScaleformUIImpl::Params_GetArgAsNumber( SFPARAMS params, int index )
{
FunctionHandler::Params* pParams = FromSFPARAMS(params);
SF_PARAMS_ASSERT( (uint)index < pParams->ArgCount, "SF param out of range!" );
SF_PARAMS_ASSERT( pParams->pArgs[index].IsNumber(), "SF param is not a number!" );
return ( double ) pParams->pArgs[index].GetNumber();
}
bool ScaleformUIImpl::Params_GetArgAsBool( SFPARAMS params, int index )
{
FunctionHandler::Params* pParams = FromSFPARAMS(params);
SF_PARAMS_ASSERT( (uint)index < pParams->ArgCount, "SF param out of range!" );
SF_PARAMS_ASSERT( pParams->pArgs[index].IsBool(), "SF param is not a boolean!" );
return pParams->pArgs[index].GetBool();
}
const char* ScaleformUIImpl::Params_GetArgAsString( SFPARAMS params, int index )
{
FunctionHandler::Params* pParams = FromSFPARAMS(params);
SF_PARAMS_ASSERT( (uint)index < pParams->ArgCount, "SF param out of range!" );
SF_PARAMS_ASSERT( pParams->pArgs[index].IsString(), "SF param is not a string!" );
return pParams->pArgs[index].GetString();
}
const wchar_t* ScaleformUIImpl::Params_GetArgAsStringW( SFPARAMS params, int index )
{
FunctionHandler::Params* pParams = FromSFPARAMS(params);
SF_PARAMS_ASSERT( (uint)index < pParams->ArgCount, "SF param out of range!" );
SF_PARAMS_ASSERT( pParams->pArgs[index].IsStringW(), "SF param is not a StringW!" );
return pParams->pArgs[index].GetStringW();
}
const char* Helper_SFTypeToCString( Value::ValueType type )
{
switch ( type )
{
case Value::VT_Undefined: return "undefined";
case Value::VT_Null: return "null";
case Value::VT_Boolean: return "boolean";
case Value::VT_Int: return "int";
case Value::VT_UInt: return "uint";
case Value::VT_Number: return "number";
case Value::VT_String: return "string";
case Value::VT_StringW: return "stringw";
case Value::VT_Object: return "object";
case Value::VT_Array: return "array";
case Value::VT_DisplayObject: return "displayobject";
case Value::VT_Closure: return "closure";
case Value::VT_ConvertBoolean: return "convertboolean";
case Value::VT_ConvertInt: return "convertint";
case Value::VT_ConvertUInt: return "convertuint";
case Value::VT_ConvertNumber: return "convertnumber";
case Value::VT_ConvertString: return "convertstring";
case Value::VT_ConvertStringW: return "convertstringw";
default:
AssertMsg( 0, "Unknown ValueType\n" );
return "undefined";
}
}
void ScaleformUIImpl::Params_DebugSpew( SFPARAMS params )
{
FunctionHandler::Params* pParams = FromSFPARAMS( params );
for ( unsigned i = 0; i < pParams->ArgCount; ++i )
{
Msg( "Param %d: %s (%s) \n", i, pParams->pArgs[ i ].ToString().ToCStr(), Helper_SFTypeToCString( pParams->pArgs[ i ].GetType() ) );
}
}
void ScaleformUIImpl::Params_SetResult( SFPARAMS params, SFVALUE value )
{
*FromSFPARAMS( params )->pRetVal = *FromSFVALUE( value );
}
void ScaleformUIImpl::Params_SetResult( SFPARAMS params, int value )
{
FromSFPARAMS(params)->pRetVal->SetNumber( ( SF::Double ) value );
}
void ScaleformUIImpl::Params_SetResult( SFPARAMS params, float value )
{
FromSFPARAMS(params)->pRetVal->SetNumber( ( SF::Double ) value );
}
void ScaleformUIImpl::Params_SetResult( SFPARAMS params, bool value )
{
FromSFPARAMS(params)->pRetVal->SetBoolean( value );
}
void ScaleformUIImpl::Params_SetResult( SFPARAMS params, const char* value, bool bMakeNewValue /* = true */ )
{
char dummy_value;
const char* stack_addr = &dummy_value;
const intp diff = value - stack_addr;
if ( ( diff > -128*1024 && diff < 128*1024 ) || bMakeNewValue )
{
// This string looks like it is on the stack. Make a Scaleform-managed string
// to duplicate it into.
SFVALUE managed_value = Params_CreateNewString( params, value );
Params_SetResult( params, managed_value );
ReleaseValue( managed_value );
}
else
{
( reinterpret_cast<FunctionHandler::Params*>(params)->pRetVal )->SetString( value );
}
}
void ScaleformUIImpl::Params_SetResult( SFPARAMS params, const wchar_t* value, bool bMakeNewValue /* = true */ )
{
wchar_t dummy_value;
const wchar_t* stack_addr = &dummy_value;
const intp diff = value - stack_addr;
if ( ( diff > -128*1024 && diff < 128*1024 ) || bMakeNewValue )
{
// This string looks like it is on the stack. Make a Scaleform-managed string
// to duplicate it into.
SFVALUE managed_value = Params_CreateNewString( params, value );
Params_SetResult( params, managed_value );
ReleaseValue( managed_value );
}
else
{
( ( ( FunctionHandler::Params* ) params )->pRetVal )->SetStringW( value );
}
}
SFVALUE ScaleformUIImpl::Params_CreateNewObject( SFPARAMS params )
{
return MovieView_CreateObject( ToSFMOVIE( FromSFPARAMS(params)->pMovie ) );
}
SFVALUE ScaleformUIImpl::Params_CreateNewArray( SFPARAMS params, int size )
{
return MovieView_CreateArray( ToSFMOVIE( FromSFPARAMS(params)->pMovie ), size );
}
SFVALUE ScaleformUIImpl::Params_CreateNewString( SFPARAMS params, const char* value )
{
return MovieView_CreateString( ToSFMOVIE( FromSFPARAMS(params)->pMovie ), value );
}
SFVALUE ScaleformUIImpl::Params_CreateNewString( SFPARAMS params, const wchar_t* value )
{
return MovieView_CreateStringW( ToSFMOVIE( FromSFPARAMS(params)->pMovie ), value );
}

View File

@@ -0,0 +1,236 @@
//========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "stdafx.h"
// NOTE: This must be the last file included!!!
#include "tier0/memdbgon.h"
using namespace SF::GFx;
using namespace SF::Render;
void ScaleformUIImpl::InitRendererImpl( void )
{
if ( m_pShaderDeviceMgr )
{
m_pDeviceCallbacks = new DeviceCallbacks();
m_pDeviceCallbacks->m_pScaleform = this;
m_pShaderDeviceMgr->AddDeviceDependentObject( m_pDeviceCallbacks );
}
m_iScreenHeight = 768;
m_iScreenWidth = 1024;
}
void ScaleformUIImpl::ShutdownRendererImpl( void )
{
if ( m_pShaderDeviceMgr )
{
if ( m_pDeviceCallbacks )
{
m_pShaderDeviceMgr->RemoveDeviceDependentObject( m_pDeviceCallbacks );
delete m_pDeviceCallbacks;
m_pDeviceCallbacks = NULL;
}
}
#if defined( WIN32 ) && !defined( DX_TO_GL_ABSTRACTION )
if ( m_pD3D9Stateblock )
{
m_pD3D9Stateblock->Release();
m_pD3D9Stateblock = NULL;
}
#endif
if ( m_pRenderHAL )
{
m_pRenderHAL->ShutdownHAL();
m_pRenderer2D.Clear();
m_pRenderHAL.Clear();
}
}
void ScaleformUIImpl::SaveRenderingState( void )
{
#if defined( WIN32 ) && !defined( DX_TO_GL_ABSTRACTION )
if ( m_pD3D9Stateblock )
{
m_pD3D9Stateblock->Capture();
}
// SF does not touch SRGB settings so make sure they are consistent
m_pDevice->GetRenderState( D3DRS_SRGBWRITEENABLE, &m_srgbRenderState );
m_pDevice->SetRenderState( D3DRS_SRGBWRITEENABLE, FALSE );
for ( int i = 0; i < 16; i++ )
{
m_pDevice->GetSamplerState( i, D3DSAMP_SRGBTEXTURE, &m_pSavedSrgbSamplerStates[i] );
m_pDevice->SetSamplerState( i, D3DSAMP_SRGBTEXTURE, FALSE );
}
#elif defined( DX_TO_GL_ABSTRACTION )
if (m_pDevice)
{
m_pDevice->SaveGLState();
}
#endif
}
void ScaleformUIImpl::RestoreRenderingState( void )
{
#if defined( WIN32 ) && !defined( DX_TO_GL_ABSTRACTION )
if ( m_pD3D9Stateblock )
{
m_pD3D9Stateblock->Apply();
}
// Restore srgb render and sampler states
// (Looks like state block capture/apply didn't work, should investigate at a later state)
m_pDevice->SetRenderState( D3DRS_SRGBWRITEENABLE, m_srgbRenderState );
for ( int i = 0; i < 16; i++ )
{
m_pDevice->SetSamplerState( i, D3DSAMP_SRGBTEXTURE, m_pSavedSrgbSamplerStates[i] );
}
#elif defined( DX_TO_GL_ABSTRACTION )
if (m_pDevice)
{
m_pDevice->RestoreGLState();
}
#endif
}
void ScaleformUIImpl::SetRenderingDevice( IDirect3DDevice9 *pDevice, D3DPRESENT_PARAMETERS *pPresentParameters, HWND hWnd )
{
#if defined(DX_TO_GL_ABSTRACTION)
if ( !m_pThreadCommandQueue )
{
m_pThreadCommandQueue = new CScaleFormThreadCommandQueue;
}
#endif
if ( !m_pRenderHAL )
{
// This is startup initialisation
m_pDevice = pDevice;
#if defined( WIN32 ) && !defined( DX_TO_GL_ABSTRACTION )
m_pRenderHAL = *new D3D9::HAL();
m_pRenderHAL->InitHAL( D3D9::HALInitParams( m_pDevice, *pPresentParameters, D3D9::HALConfig_NoSceneCalls ) );
#else
m_pRenderHAL = *new GL::HAL( m_pThreadCommandQueue );
m_pRenderHAL->InitHAL( GL::HALInitParams( GL::HALConfig_DisableBinaryShaders | GL::HALConfig_DisableShaderPipelines, SF::ThreadId(), SF::String(), true ) );
if ( m_pThreadCommandQueue )
{
m_pThreadCommandQueue->pHAL = m_pRenderHAL;
}
#endif
Assert ( !m_pRenderer2D );
m_pRenderer2D = *new Renderer2D( m_pRenderHAL.GetPtr() );
if ( m_pThreadCommandQueue )
{
m_pThreadCommandQueue->pR2D = m_pRenderer2D;
}
InitFonts();
SF::Ptr<CScaleformImageCreator> pImageCreator = *new CScaleformImageCreator( this, (TextureManager*)m_pRenderHAL->GetTextureManager() );
m_pLoader->SetImageCreator( pImageCreator );
}
else
{
#if defined( WIN32 ) && !defined( DX_TO_GL_ABSTRACTION )
m_pRenderHAL->RestoreAfterReset();
#else
m_pRenderHAL->ResetContext();
#endif
}
#if defined( WIN32 ) && !defined( DX_TO_GL_ABSTRACTION )
pDevice->CreateStateBlock( D3DSBT_ALL, &m_pD3D9Stateblock );
#endif
#if defined( SF_ENABLE_IME ) && defined( SF_ENABLE_IME_WIN32 )
if ( !m_pIMEManager )
{
m_pIMEManager = *new ScaleformeUIIMEManager( hWnd, m_pGameEventManager );
if ( m_pIMEManager )
{
m_pIMEManager->Init( m_pLoader->GetLog(), static_cast<Scaleform::GFx::FileOpener*>(m_pLoader->GetFileOpener().GetPtr()), NULL, false );
m_pIMEManager->SetIMEMoviePath( "ime.swf" );
m_pLoader->SetIMEManager( m_pIMEManager );
m_pIMEManager->EnableIME( m_bIMEEnabled );
}
}
#else
NOTE_UNUSED( hWnd );
#endif
D3DVIEWPORT9 viewport;
pDevice->GetViewport( &viewport );
m_iScreenWidth = viewport.Width;
m_iScreenHeight = viewport.Height;
SetScreenSize( m_iScreenWidth, m_iScreenHeight );
}
void ScaleformUIImpl::NotifyRenderingDeviceLost( void )
{
#if defined( WIN32 ) && !defined( DX_TO_GL_ABSTRACTION )
if ( !m_pRenderHAL )
return;
m_pRenderHAL->PrepareForReset();
m_pD3D9Stateblock->Release();
m_pD3D9Stateblock = NULL;
#endif
}
#if defined( _WIN32 ) && !defined( DX_TO_GL_ABSTRACTION )
void DumpMeshBufferSetStats( D3D9::MeshBufferSet *pMBSet )
{
int totalMem = 0;
for ( int i = 0; i < MC_NUM_BUFFER_BUCKETS; i++ )
{
D3D9::MeshBufferBucket *pBucket = &pMBSet->m_buckets[i];
Msg("Bucket %2d: created = %3d, free = %3d, total = %6d bytes (%4d KB)\n",
i, pBucket->m_numCreated, pBucket->m_numFree,
pBucket->m_totalMemUsed, pBucket->m_totalMemUsed / 1024 );
totalMem += pBucket->m_totalMemUsed;
}
Msg( "Total = %d KB\n", totalMem/1024 );
}
#endif
void ScaleformUIImpl::DumpMeshCacheStats( void )
{
#if defined( _WIN32 ) && !defined( DX_TO_GL_ABSTRACTION )
if ( !m_pRenderHAL )
{
Msg( "No renderer, no HAL, no stats.\n" );
return;
}
D3D9::MeshCache *mc = &m_pRenderHAL->GetMeshCache();
// Log stats
Msg( "SF MeshBufferSet, VB mem summary\n" );
DumpMeshBufferSetStats( &mc->VertexBuffers );
Msg( "SF MeshBufferSet, IB mem summary\n" );
DumpMeshBufferSetStats( &mc->IndexBuffers );
#endif
}

View File

@@ -0,0 +1,174 @@
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "stdafx.h"
#include "tier1/fmtstr.h"
// NOTE: This must be the last file included!!!
#include "tier0/memdbgon.h"
using namespace Scaleform::GFx;
#define TEMP_BUFFER_LENGTH 1024
class TextBoxArrayVisitor: public Value::ArrayVisitor
{
public:
CUtlBlockVector<Value> *m_pTextBoxes;
void Visit( unsigned int idx, const Value& val )
{
m_pTextBoxes->AddToTail( val );
}
};
/**********************************************
* Implementation of the text object. It accepts
* an SFText object or a TextBox from flash
* and keeps referenes to all the text boxes so
* that they can be set directly without needing
* to invoke the SetText function.
*/
class SFTextObjectImpl: public ISFTextObject
{
protected:
// Using a CUtlBlockVector to avoid realloc (memcpy of Scaleform::Value)
// when the vector grow which would perform a shallow copy
// (Need to use Scaleform::Value copy constructor performing a deep copy)
CUtlBlockVector<Value> m_TextBoxes;
public:
SFTextObjectImpl()
{
}
SFTextObjectImpl( Value &value )
{
Init( value );
}
bool Init( Value &value )
{
m_TextBoxes.RemoveAll();
if ( value.GetType() != Value::VT_DisplayObject )
{
return false;
}
Value boxArray;
if ( value.GetMember( "SFText_TextBoxList", &boxArray ) )
{
TextBoxArrayVisitor vis;
vis.m_pTextBoxes = &m_TextBoxes;
boxArray.VisitElements( &vis );
}
else
{
m_TextBoxes.AddToTail( value );
}
return true;
}
virtual void SetText( int value )
{
SetText( CFmtStr( "%d", value ) );
}
virtual void SetText( float value )
{
SetText( CFmtStr( "%0.f", value ) );
}
virtual void SetText( const char* pszText )
{
FOR_EACH_VEC( m_TextBoxes, i )
{
m_TextBoxes[i].SetText( pszText );
}
}
virtual void SetTextHTML( const char* pszText )
{
FOR_EACH_VEC( m_TextBoxes, i )
{
m_TextBoxes[i].SetTextHTML( pszText );
}
}
virtual void SetText( const wchar_t* pwszText )
{
FOR_EACH_VEC( m_TextBoxes, i )
{
m_TextBoxes[i].SetText( pwszText );
}
}
virtual void SetTextHTML( const wchar_t* pwszText )
{
FOR_EACH_VEC( m_TextBoxes, i )
{
m_TextBoxes[i].SetTextHTML( pwszText );
}
}
virtual void SetVisible( bool visible )
{
FOR_EACH_VEC( m_TextBoxes, i )
{
SFINST.SetVisible( ToSFVALUE( &m_TextBoxes[i] ), visible);
}
}
virtual bool IsValid( void )
{
return m_TextBoxes.Count() > 0;
}
virtual void Release( void )
{
delete this;
}
};
/************************************************
* methods in IScalformUI for creating these objects
*/
ISFTextObject* ScaleformUIImpl::TextObject_MakeTextObject( SFVALUE value )
{
SFTextObjectImpl* pResult = new SFTextObjectImpl( *FromSFVALUE( value ) );
if ( !pResult->IsValid() )
{
pResult->Release();
pResult = NULL;
}
return pResult;
}
ISFTextObject* ScaleformUIImpl::TextObject_MakeTextObjectFromMember( SFVALUE value, const char * pName )
{
Value* pValue = FromSFVALUE( value );
Value member;
if ( pValue->GetMember( pName, &member ) )
{
return TextObject_MakeTextObject( ToSFVALUE( &member ) );
}
else
{
return NULL;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,146 @@
//========= Copyright © 1996-2008, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=====================================================================================//
#include "stdafx.h"
#include "sfuiavatarimage.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#ifndef NO_STEAM
extern CSteamAPIContext *steamapicontext;
#endif
#pragma warning( disable: 4355 ) // disables ' 'this' : used in base member initializer list'
using namespace SF::Render;
IScaleformAvatarImageProvider * ScaleformUIAvatarImage::sm_pProvider = NULL; // static provider initialized upon first available avatar data arriving
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
ScaleformUIAvatarImage::ScaleformUIAvatarImage( XUID xuid, const byte* defaultRgba, int defaultWidth, int defaultHeight, ::ImageFormat defaultFormat, SF::GFx::TextureManager* pTextureManager )
: ScaleformUIImage( defaultRgba, defaultWidth, defaultHeight, defaultFormat, pTextureManager )
{
m_xXUID = xuid;
if ( ( m_xXUID & 0xFFFFFFFFull ) == m_xXUID )
{
static EUniverse eUniverse = steamapicontext->SteamUtils()->GetConnectedUniverse();
m_xXUID = CSteamID( uint32( m_xXUID ), eUniverse, k_EAccountTypeIndividual ).ConvertToUint64();
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool ScaleformUIAvatarImage::LoadAvatarImage( IScaleformAvatarImageProvider *pProvider /* = NULL */ )
{
#ifndef NO_STEAM
if ( steamapicontext->SteamFriends() && steamapicontext->SteamUtils() && steamapicontext->SteamUser() )
{
static XUID s_myXuid = steamapicontext->SteamUser()->GetSteamID().ConvertToUint64();
bool bLarge = ( s_myXuid == m_xXUID );
#if 0
// For debugging we can set to always use entity avatar data to test our own avatar
// and always keep own avatar the same size
bLarge = false;
#endif
static ConVarRef sv_reliableavatardata( "sv_reliableavatardata", true );
if ( bLarge && sv_reliableavatardata.IsValid() && ( sv_reliableavatardata.GetInt() == 2 ) )
bLarge = false; // Server is overriding all avatars, force update own avatar from server data too
if ( pProvider && !sm_pProvider )
sm_pProvider = pProvider;
if ( !pProvider && sm_pProvider )
pProvider = sm_pProvider;
IScaleformAvatarImageProvider::ImageInfo_t ii = {};
if ( !bLarge && pProvider && pProvider->GetImageInfo( m_xXUID, &ii ) )
{
// Expect 64x64 RGB images here
if ( ii.m_cbImageData == 64*64*3 )
{
uint32 wide = 64, tall = 64;
int cubImage = wide * tall * 4;
m_bufRgbaBuffer.EnsureCapacity( cubImage );
memset( m_bufRgbaBuffer.Base(), 0xFF, cubImage );
for ( int y = 0; y < 64; ++ y ) for ( int x = 0; x < 64; ++ x )
{ // Explode RGB into RGBA
V_memcpy( ( ( byte * ) m_bufRgbaBuffer.Base() ) + y*64*4 + x*4, ( ( byte const * ) ii.m_pvImageData ) + y*64*3 + x*3, 3 );
}
InitFromBuffer( ( byte* ) m_bufRgbaBuffer.Base(), wide, tall, IMAGE_FORMAT_RGBA8888 );
return true;
}
}
#if 0
// For debugging we never use Steam avatars, always try to use engine.dll provider
return true;
#endif
if ( bLarge )
{
// For the local user force to download the local medium avatar as well as large
int iAvatar = steamapicontext->SteamFriends()->GetMediumFriendAvatar( m_xXUID );
if ( !iAvatar || ( iAvatar == -1 ) )
{
( void ) steamapicontext->SteamFriends()->RequestUserInformation( m_xXUID, false );
}
}
int iAvatar = bLarge
? steamapicontext->SteamFriends()->GetLargeFriendAvatar( m_xXUID )
: steamapicontext->SteamFriends()->GetMediumFriendAvatar( m_xXUID );
if ( !iAvatar || ( iAvatar == -1 ) )
{
bool bRequestEnqueuedAsync = steamapicontext->SteamFriends()->RequestUserInformation( m_xXUID, false );
if ( !bRequestEnqueuedAsync ) // try again one more time, Steam says everything is available
iAvatar = bLarge
? steamapicontext->SteamFriends()->GetLargeFriendAvatar( m_xXUID )
: steamapicontext->SteamFriends()->GetMediumFriendAvatar( m_xXUID );
}
if ( iAvatar != 0 )
{
/*
// See if it's in our list already
*/
uint32 wide, tall;
if ( steamapicontext->SteamUtils()->GetImageSize( iAvatar, &wide, &tall ) )
{
bool bUseSteamImage = true;
if ( wide == 0 || tall == 0 )
{
// attempt to handle rare data integrity issue, avatar got lost
bUseSteamImage = false;
// mock up solid white as 64x64
wide = tall = 64;
}
int cubImage = wide * tall * 4;
m_bufRgbaBuffer.EnsureCapacity( cubImage );
memset( m_bufRgbaBuffer.Base(), 0xFF, cubImage );
if ( bUseSteamImage )
{
steamapicontext->SteamUtils()->GetImageRGBA( iAvatar, (byte*)m_bufRgbaBuffer.Base(), cubImage );
}
InitFromBuffer( (byte*)m_bufRgbaBuffer.Base(), wide, tall, IMAGE_FORMAT_RGBA8888 );
}
}
}
#elif defined( _X360 )
X360_ResetAsyncImageState();
return true;
#endif
return true;
}

View File

@@ -0,0 +1,38 @@
//========= Copyright © 1996-2009, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=====================================================================================//
#ifndef __SFUIAVATARIMAGE_H__
#define __SFUIAVATARIMAGE_H__
#include "scaleformuiimage.h"
#ifndef NO_STEAM
#include "steam/steam_api.h"
#endif
#if !defined( _X360 )
typedef uint64 XUID;
#endif
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class ScaleformUIAvatarImage : public ScaleformUIImage
{
public:
static IScaleformAvatarImageProvider *sm_pProvider;
public:
ScaleformUIAvatarImage( XUID xuid, const byte* defaultRgba, int defaultWidth, int defaultHeight, ::ImageFormat defaultFormat, SF::GFx::TextureManager* pTextureManager );
bool LoadAvatarImage( IScaleformAvatarImageProvider *pProvider = NULL );
private:
XUID m_xXUID;
CUtlBuffer m_bufRgbaBuffer;
};
#endif // __SFUIAVATARIMAGE_H__

View File

@@ -0,0 +1,32 @@
//========= Copyright © 1996-2013, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=====================================================================================//
#include "stdafx.h"
#include "sfuichromehtmlimage.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace SF::Render;
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
ScaleformUIChromeHTMLImage::ScaleformUIChromeHTMLImage( uint64 imageID, const byte* defaultRgba, int defaultWidth, int defaultHeight, ::ImageFormat defaultFormat, SF::GFx::TextureManager* pTextureManager )
: ScaleformUIImage( defaultRgba, defaultWidth, defaultHeight, defaultFormat, pTextureManager )
{
m_imageID = imageID;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool ScaleformUIChromeHTMLImage::LoadChromeHTMLImage( const byte* rgba, int width, int height, ::ImageFormat format )
{
InitFromBuffer( rgba, width, height, format );
return true;
}

View File

@@ -0,0 +1,26 @@
//========= Copyright © 1996-2013, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=====================================================================================//
#ifndef __SFUICHROMEHTMLIMAGE_H__
#define __SFUICHROMEHTMLIMAGE_H__
#include "scaleformuiimage.h"
//-----------------------------------------------------------------------------
// Purpose: sfuia
//-----------------------------------------------------------------------------
class ScaleformUIChromeHTMLImage : public ScaleformUIImage
{
public:
ScaleformUIChromeHTMLImage( uint64 imageID, const byte* defaultRgba, int defaultWidth, int defaultHeight, ::ImageFormat defaultFormat, SF::GFx::TextureManager* pTextureManager );
bool LoadChromeHTMLImage( const byte* rgba, int width, int height, ::ImageFormat format );
private:
uint64 m_imageID;
};
#endif // __SFUICHROMEHTMLIMAGE_H__

View File

@@ -0,0 +1,110 @@
//========= Copyright © 1996-2013, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=====================================================================================//
#include "stdafx.h"
#include "sfuiinventoryimage.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace SF::Render;
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
ScaleformUIInventoryImage::ScaleformUIInventoryImage( uint64 itemid, const byte* defaultRgba, int defaultWidth, int defaultHeight, ::ImageFormat defaultFormat, SF::GFx::TextureManager* pTextureManager )
: ScaleformUIImage( defaultRgba, defaultWidth, defaultHeight, defaultFormat, pTextureManager )
{
m_itemid = itemid;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool ScaleformUIInventoryImage::LoadInventoryImage( const CUtlBuffer* rawImageData, int nWidth, int nHeight, ::ImageFormat format )
{
if ( rawImageData && rawImageData->TellPut() >= ( nWidth * nHeight * 4 ) )
{
#ifdef USE_OVERLAY_ON_INVENTORY_ICONS
OverlayFromBuffer( (byte*)(rawImageData->Base()), nWidth, nHeight, format );
#else
InitFromBuffer( (byte*)(rawImageData->Base()), nWidth, nHeight, format );
#endif
}
return true;
}
#ifdef USE_OVERLAY_ON_INVENTORY_ICONS
void ScaleformUIInventoryImage::OverlayFromBuffer( const byte *rgba, int width, int height, ::ImageFormat format )
{
Assert( rgba && width && height );
bool bForceOverwrite = false;
// See if we need to create a new texture
if ( m_pImage == NULL || width != m_nWidth || height != m_nHeight || format != m_format )
{
const SF::Render::ImageFormat sfFormat = ConvertImageFormat( format );
const unsigned int mipLevelCount = 1;
if ( m_pImage )
{
m_pImage->pImage->Release();
m_pImage->pImage = RawImage::Create( sfFormat, mipLevelCount, ImageSize( width, height), ImageUse_Update, 0, m_pTextureManager );
// apply scaling matrix
SF::GFx::Size<float> scaleParameters( ( (float) m_nWidth ) / width, ( (float) m_nHeight ) / height );
SF::GFx::Matrix2F textureMatrix = SF::GFx::Matrix2F::Scaling( scaleParameters.Width, scaleParameters.Height );
m_pImage->SetMatrix( textureMatrix );
ScaleformUIImpl::m_Instance.ForceUpdateImages();
}
else
{
m_pImage = new ImageDelegate( RawImage::Create( sfFormat, mipLevelCount, ImageSize( width, height), ImageUse_Update, 0, m_pTextureManager ) );
}
m_nWidth = width;
m_nHeight = height;
m_format = format;
bForceOverwrite = true;
}
if ( m_pImage )
{
// Copy data
ImageData imageData;
((RawImage*)(m_pImage->GetAsImage()))->GetImageData( &imageData );
ImagePlane &imagePlane = imageData.GetPlaneRef( 0 );
if ( bForceOverwrite )
{
memcpy( imagePlane.pData, rgba, imagePlane.DataSize );
}
else
{
Assert( ( width * height * 4 ) <= imagePlane.DataSize );
// pixel by pixel copy overlaying the input rgba onto the pre-existing image data wherever the input is not 0
for ( int y = 0; y < height; y++ )
{
for ( int x = 0; x < width; x++ )
{
if ( *( ( uint * )&( rgba[ ( y * ( width * 4 ) ) + ( x * 4 ) ] ) ) != 0 )
{
*( ( uint * )&( imagePlane.pData[ ( y * ( width * 4 ) ) + ( x * 4 ) ] ) ) = *( ( uint * )&( rgba[ ( y * ( width * 4 ) ) + ( x * 4 ) ] ) );
}
}
}
}
m_pImage->Update();
}
}
#endif

View File

@@ -0,0 +1,35 @@
//========= Copyright © 1996-2013, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=====================================================================================//
#ifndef __SFUIINVENTORYIMAGE_H__
#define __SFUIINVENTORYIMAGE_H__
#include "scaleformuiimage.h"
#if !defined( _X360 )
typedef uint64 XUID;
#endif
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class ScaleformUIInventoryImage : public ScaleformUIImage
{
public:
ScaleformUIInventoryImage( uint64 itemid, const byte* defaultRgba, int defaultWidth, int defaultHeight, ::ImageFormat defaultFormat, SF::GFx::TextureManager* pTextureManager );
bool LoadInventoryImage( const CUtlBuffer* rawImageData, int nWidth, int nHeight, ::ImageFormat format );
private:
#ifdef USE_OVERLAY_ON_INVENTORY_ICONS
void OverlayFromBuffer( const byte *rgba, int width, int height, ::ImageFormat format );
#endif
uint64 m_itemid;
};
#endif // __SFUIINVENTORYIMAGE_H__

View File

@@ -0,0 +1,151 @@
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#if !defined( SFUIMEMORYFILE_H_ )
#define SFUIMEMORYFILE_H_
class SFUIMemoryFile : public SF::File
{
public:
const char* GetFilePath( void ) { return m_filePath.ToCStr(); }
bool IsValid( void ) { return m_valid; }
bool IsWritable( void ) { return false; }
bool Flush( void ) { return true; }
int GetErrorCode( void ) { return 0; }
int Tell( void ) { return m_fileIndex; }
SF::SInt64 LTell( void ) { return (SF::SInt64) m_fileIndex; }
int GetLength( void ) { return m_fileSize; }
SF::SInt64 LGetLength( void ) { return (SF::SInt64) m_fileSize; }
bool Close( void )
{
m_valid = false;
return false;
}
int CopyFromStream( SF::File *pstream, int byteSize )
{
return 0;
}
int Write( const SF::UByte *pbuffer, int numBytes )
{
return 0;
}
int Read( SF::UByte *pbufer, int numBytes )
{
if ( m_fileIndex + numBytes > m_fileSize )
{
numBytes = m_fileSize - m_fileIndex;
}
if ( numBytes > 0 )
{
V_memcpy( pbufer, &m_fileData[m_fileIndex], numBytes );
m_fileIndex += numBytes;
}
return numBytes;
}
int SkipBytes( int numBytes )
{
if ( m_fileIndex + numBytes > m_fileSize )
{
numBytes = m_fileSize - m_fileIndex;
}
m_fileIndex += numBytes;
return numBytes;
}
int BytesAvailable( void )
{
return ( m_fileSize - m_fileIndex );
}
int Seek( int offset, int origin = Seek_Set )
{
switch ( origin )
{
case Seek_Set:
m_fileIndex = offset;
break;
case Seek_Cur:
m_fileIndex += offset;
break;
case Seek_End:
m_fileIndex = m_fileSize - offset;
break;
default:
break;
}
return m_fileIndex;
}
SF::SInt64 LSeek( SF::SInt64 offset, int origin = Seek_Set )
{
return ( SF::SInt64 ) Seek( ( int ) offset, origin );
}
bool ChangeSize( int newSize )
{
if ( newSize <= m_buffer.Size() )
{
m_fileSize = newSize;
return true;
}
else
{
return false;
}
}
CUtlBuffer& GetBuffer( void )
{
return m_buffer;
}
public:
// pfileName should be encoded as UTF-8 to support international file names.
SFUIMemoryFile( const char* pfileName ) :
m_filePath( pfileName )
{
}
void Init( void )
{
m_fileData = ( const SF::UByte * ) m_buffer.Base();
m_fileSize = m_buffer.Size();
m_fileIndex = 0;
m_valid = ( !m_filePath.IsEmpty() && m_fileData != NULL && m_fileSize > 0 ) ? true : false;
}
private:
SF::String m_filePath;
CUtlBuffer m_buffer;
const SF::UByte *m_fileData;
SF::SInt32 m_fileSize;
SF::SInt32 m_fileIndex;
bool m_valid;
};
#endif /* SFUIMEMORYFILE_H_ */

12
scaleformui/stdafx.cpp Normal file
View File

@@ -0,0 +1,12 @@
// stdafx.cpp : source file that includes just the standard includes
// scaleformui.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// NOTE: This must be the last file included!!!
#include "tier0/memdbgon.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

59
scaleformui/stdafx.h Normal file
View File

@@ -0,0 +1,59 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if defined( COMPILER_MSVC )
#pragma once
#endif
#if defined ( DX_TO_GL_ABSTRACTION )
#include "togl/rendermechanism.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#if ( defined( WIN32 ) && !defined( DX_TO_GL_ABSTRACTION ) ) || defined( _X360 )
#include <d3d9.h>
#endif
#include "GFx.h"
// Disable "_force_inline not inlined" warning
#pragma warning(disable : 4714)
#include "Kernel/SF_Types.h"
#include "Kernel/SF_RefCount.h"
#if defined( WIN32 ) && !defined( DX_TO_GL_ABSTRACTION )
#include "GFx_Renderer_D3D9.h"
#else
#include "GFx_Renderer_GL.h"
#endif
#include "tier0/platform.h"
#include "tier0/dbg.h"
#include "vprof.h"
#pragma warning(disable : 4267)
#include "tier1/strtools.h"
#include "tier1/utlvector.h"
#include "tier3/tier3dm.h"
#include "vstdlib/random.h"
#include "interfaces/interfaces.h"
#include "shaderapi/IShaderDevice.h"
#include "inputsystem/ButtonCode.h"
#include "inputsystem/AnalogCode.h"
#include "inputsystem/iinputsystem.h"
#include "filesystem.h"
#include "IGameUIFuncs.h"
namespace SF = Scaleform;
#pragma warning(default : 4267)
#include "scaleformui/scaleformui.h"
#include "scaleformuiimpl/scaleformuiimpl.h"