Skip to content

Added quality argument for dxCreateFont #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions MTA10/core/CGraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1140,8 +1140,7 @@ bool CGraphics::CreateStandardDXFontWithCustomScale ( eFontType fontType, float
return true;
}


bool CGraphics::LoadAdditionalDXFont ( std::string strFontPath, std::string strFontName, unsigned int uiHeight, bool bBold, ID3DXFont** ppD3DXFont )
bool CGraphics::LoadAdditionalDXFont( std::string strFontPath, std::string strFontName, unsigned int uiHeight, bool bBold, DWORD ulQuality, ID3DXFont** ppD3DXFont )
{
int iLoaded = AddFontResourceEx ( strFontPath.c_str (), FR_PRIVATE, 0 );

Expand All @@ -1151,7 +1150,7 @@ bool CGraphics::LoadAdditionalDXFont ( std::string strFontPath, std::string strF
bool bSuccess = true;
// Normal size
if( !SUCCEEDED ( D3DXCreateFont ( m_pDevice, uiHeight, 0, iWeight, 1,
FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, PROOF_QUALITY, DEFAULT_PITCH | FF_DONTCARE, strFontName.c_str(),
FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ulQuality, DEFAULT_PITCH | FF_DONTCARE, strFontName.c_str(),
ppD3DXFont ) ) )
{
WriteErrorEvent( SString( "Could not create Direct3D font '%s'", strFontName.c_str() ) );
Expand All @@ -1161,6 +1160,12 @@ bool CGraphics::LoadAdditionalDXFont ( std::string strFontPath, std::string strF
return bSuccess && ( iLoaded == 1 );
}


bool CGraphics::LoadAdditionalDXFont ( std::string strFontPath, std::string strFontName, unsigned int uiHeight, bool bBold, ID3DXFont** ppD3DXFont )
{
return this->LoadAdditionalDXFont( strFontPath, strFontName, uiHeight, bBold, PROOF_QUALITY, ppD3DXFont );
}

bool CGraphics::DestroyAdditionalDXFont ( std::string strFontPath, ID3DXFont *pD3DXFont )
{
bool bResult = RemoveFontResourceEx ( strFontPath.c_str (), FR_PRIVATE, 0 ) != 0;
Expand Down
1 change: 1 addition & 0 deletions MTA10/core/CGraphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class CGraphics : public CGraphicsInterface, public CSingleton < CGraphics >
bool CreateStandardDXFontWithCustomScale ( eFontType fontType, float fScale, ID3DXFont** ppD3DXFont );

bool LoadAdditionalDXFont ( std::string strFontPath, std::string strFontName, unsigned int uiHeight, bool bBold, ID3DXFont** ppD3DXFont );
bool LoadAdditionalDXFont ( std::string strFontPath, std::string strFontName, unsigned int uiHeight, bool bBold, DWORD ulQuality, ID3DXFont** ppD3DXFont );
bool DestroyAdditionalDXFont ( std::string strFontPath, ID3DXFont* pD3DXFont );

float GetDXFontHeight ( float fScale = 1.0f, ID3DXFont * pDXFont = NULL );
Expand Down
8 changes: 4 additions & 4 deletions MTA10/core/CRenderItem.DxFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
//
//
////////////////////////////////////////////////////////////////
void CDxFontItem::PostConstruct ( CRenderItemManager* pManager, const SString& strFullFilePath, uint uiSize, bool bBold )
void CDxFontItem::PostConstruct ( CRenderItemManager* pManager, const SString& strFullFilePath, uint uiSize, bool bBold, DWORD ulQuality )
{
Super::PostConstruct ( pManager );
m_strFullFilePath = strFullFilePath;

// Initial creation of d3d data
CreateUnderlyingData ( uiSize, bBold );
CreateUnderlyingData ( uiSize, bBold, ulQuality );
}


Expand Down Expand Up @@ -89,7 +89,7 @@ void CDxFontItem::OnResetDevice ( void )
//
//
////////////////////////////////////////////////////////////////
void CDxFontItem::CreateUnderlyingData ( uint uiSize, bool bBold )
void CDxFontItem::CreateUnderlyingData ( uint uiSize, bool bBold, DWORD ulQuality )
{
assert ( !m_pFntNormal );

Expand All @@ -98,7 +98,7 @@ void CDxFontItem::CreateUnderlyingData ( uint uiSize, bool bBold )
// Create the D3DX fonts
FONT_PROPERTIES sFontProps;
if ( GetFontProperties ( LPCTSTR ( m_strFullFilePath.c_str () ), &sFontProps ) )
CCore::GetSingleton ().GetGraphics()->LoadAdditionalDXFont ( m_strFullFilePath, sFontProps.csName, static_cast < int > ( std::floor ( uiSize * 1.75f ) ), bBold, &m_pFntNormal );
CCore::GetSingleton ().GetGraphics()->LoadAdditionalDXFont ( m_strFullFilePath, sFontProps.csName, static_cast < int > ( std::floor ( uiSize * 1.75f ) ), bBold, ulQuality, &m_pFntNormal );

if ( !m_pFntNormal )
return;
Expand Down
4 changes: 2 additions & 2 deletions MTA10/core/CRenderItemManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,13 @@ CShaderItem* CRenderItemManager::CreateShader ( const SString& strFullFilePath,
// TODO: Make underlying data for fonts shared
//
////////////////////////////////////////////////////////////////
CDxFontItem* CRenderItemManager::CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold )
CDxFontItem* CRenderItemManager::CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold, DWORD ulQuality )
{
if ( !CanCreateRenderItem ( CDxFontItem::GetClassId () ) )
return NULL;

CDxFontItem* pDxFontItem = new CDxFontItem ();
pDxFontItem->PostConstruct ( this, strFullFilePath, uiSize, bBold );
pDxFontItem->PostConstruct ( this, strFullFilePath, uiSize, bBold, ulQuality );

if ( !pDxFontItem->IsValid () )
{
Expand Down
2 changes: 1 addition & 1 deletion MTA10/core/CRenderItemManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CRenderItemManager : public CRenderItemManagerInterface

// CRenderItemManagerInterface
virtual void DoPulse ( void );
virtual CDxFontItem* CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold );
virtual CDxFontItem* CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold, DWORD ulQuality = DEFAULT_QUALITY );
virtual CGuiFontItem* CreateGuiFont ( const SString& strFullFilePath, const SString& strFontName, uint uiSize );
virtual CTextureItem* CreateTexture ( const SString& strFullFilePath, const CPixels* pPixels, bool bMipMaps = true, uint uiSizeX = RDEFAULT, uint uiSizeY = RDEFAULT, ERenderFormat format = RFORMAT_UNKNOWN, ETextureAddress textureAddress = TADDRESS_WRAP, ETextureType textureType = TTYPE_TEXTURE, uint uiVolumeDepth = 1 );
virtual CShaderItem* CreateShader ( const SString& strFullFilePath, const SString& strRootPath, SString& strOutStatus, float fPriority, float fMaxDistance, bool bLayered, bool bDebug, int iTypeMask );
Expand Down
4 changes: 2 additions & 2 deletions MTA10/mods/shared_logic/CClientRenderElementManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ CClientRenderElementManager::~CClientRenderElementManager ( void )
//
//
////////////////////////////////////////////////////////////////
CClientDxFont* CClientRenderElementManager::CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold )
CClientDxFont* CClientRenderElementManager::CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold, const DWORD ulQuality )
{
// Create the item
CDxFontItem* pDxFontItem = m_pRenderItemManager->CreateDxFont ( strFullFilePath, uiSize, bBold );
CDxFontItem* pDxFontItem = m_pRenderItemManager->CreateDxFont ( strFullFilePath, uiSize, bBold, ulQuality );

// Check create worked
if ( !pDxFontItem )
Expand Down
2 changes: 1 addition & 1 deletion MTA10/mods/shared_logic/CClientRenderElementManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CClientRenderElementManager
CClientRenderElementManager ( CClientManager* pClientManager );
~CClientRenderElementManager ( void );

CClientDxFont* CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold );
CClientDxFont* CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold, DWORD ulQuality = DEFAULT_QUALITY );
CClientGuiFont* CreateGuiFont ( const SString& strFullFilePath, const SString& strUniqueName, uint uiSize );
CClientTexture* CreateTexture ( const SString& strFullFilePath, const CPixels* pPixels = NULL, bool bMipMaps = true, uint uiSizeX = RDEFAULT, uint uiSizeY = RDEFAULT, ERenderFormat format = RFORMAT_UNKNOWN, ETextureAddress textureAddress = TADDRESS_WRAP, ETextureType textureType = TTYPE_TEXTURE, uint uiVolumeDepth = 1 );
CClientShader* CreateShader ( const SString& strFullFilePath, const SString& strRootPath, SString& strOutStatus, float fPriority, float fMaxDistance, bool bLayered, bool bDebug, int iTypeMask );
Expand Down
13 changes: 8 additions & 5 deletions MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,12 +852,13 @@ int CLuaFunctionDefs::dxUpdateScreenSource ( lua_State* luaVM )
int CLuaFunctionDefs::dxCreateFont ( lua_State* luaVM )
{
// element dxCreateFont( string filepath [, int size=9, bool bold=false ] )
SString strFilePath; int iSize; bool bBold;
SString strFilePath; int iSize; bool bBold; eFontQuality ulFontQuality;

CScriptArgReader argStream ( luaVM );
argStream.ReadString ( strFilePath );
argStream.ReadNumber ( iSize, 9 );
argStream.ReadBool ( bBold, false );
argStream.ReadEnumString ( ulFontQuality, FONT_QUALITY_PROOF );

if ( !argStream.HasErrors () )
{
Expand All @@ -871,14 +872,16 @@ int CLuaFunctionDefs::dxCreateFont ( lua_State* luaVM )
{
if ( FileExists ( strPath ) )
{
CClientDxFont* pDxFont = g_pClientGame->GetManager ()->GetRenderElementManager ()->CreateDxFont ( strPath, iSize, bBold );
if ( pDxFont )
CClientDxFont* pDxFont = g_pClientGame->GetManager()->GetRenderElementManager()->CreateDxFont( strPath, iSize, bBold, ulFontQuality );

if( pDxFont )
{
// Make it a child of the resource's file root ** CHECK Should parent be pFileResource, and element added to pParentResource's ElementGroup? **
pDxFont->SetParent ( pParentResource->GetResourceDynamicEntity () );
lua_pushelement ( luaVM, pDxFont );
pDxFont->SetParent( pParentResource->GetResourceDynamicEntity() );
lua_pushelement( luaVM, pDxFont );
return 1;
}

argStream.SetCustomError( strFilePath, "Error creating font" );
}
else
Expand Down
14 changes: 14 additions & 0 deletions MTA10/mods/shared_logic/lua/CLuaFunctionParseHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,20 @@ IMPLEMENT_ENUM_BEGIN( eFontType )
ADD_ENUM( FONT_BECKETT, "beckett" )
IMPLEMENT_ENUM_END_DEFAULTS( "font-type", FONT_DEFAULT, "" )

IMPLEMENT_ENUM_BEGIN( eFontQuality )
ADD_ENUM( FONT_QUALITY_DEFAULT, "default" )
ADD_ENUM( FONT_QUALITY_DRAFT, "draft" )
ADD_ENUM( FONT_QUALITY_PROOF, "proof" )
#if( WINVER >= 0x0400 )
ADD_ENUM( FONT_QUALITY_NONANTIALIASED, "nonantialiased" )
ADD_ENUM( FONT_QUALITY_ANTIALIASED, "antialiased" )
#endif
#if( _WIN32_WINNT >= _WIN32_WINNT_WINXP )
ADD_ENUM( FONT_QUALITY_CLEARTYPE, "cleartype" )
ADD_ENUM( FONT_QUALITY_CLEARTYPE_NATURAL, "cleartype_natural" )
#endif
IMPLEMENT_ENUM_END_DEFAULTS( "font-quality", FONT_QUALITY_DEFAULT, "" )

IMPLEMENT_ENUM_BEGIN ( eAudioLookupIndex )
ADD_ENUM ( AUDIO_LOOKUP_FEET, "feet" )
ADD_ENUM ( AUDIO_LOOKUP_GENRL, "genrl" )
Expand Down
1 change: 1 addition & 0 deletions MTA10/mods/shared_logic/lua/CLuaFunctionParseHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ DECLARE_ENUM( eWeaponState );
DECLARE_ENUM( eWeaponFlags );
DECLARE_ENUM( eVehicleComponent );
DECLARE_ENUM( eFontType );
DECLARE_ENUM( eFontQuality );
DECLARE_ENUM( eAudioLookupIndex );
DECLARE_ENUM( eAspectRatio );
DECLARE_ENUM( eRadioStreamIndex );
Expand Down
20 changes: 20 additions & 0 deletions MTA10/sdk/core/CGraphicsInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ enum eFontType
NUM_FONTS
};

enum eFontQuality
{
FONT_QUALITY_DEFAULT = DEFAULT_QUALITY,
FONT_QUALITY_DRAFT = DRAFT_QUALITY,
FONT_QUALITY_PROOF = PROOF_QUALITY,

#if( WINVER >= 0x0400 )
FONT_QUALITY_NONANTIALIASED = NONANTIALIASED_QUALITY,
FONT_QUALITY_ANTIALIASED = ANTIALIASED_QUALITY,
#endif

#if( _WIN32_WINNT >= _WIN32_WINNT_WINXP )
FONT_QUALITY_CLEARTYPE = CLEARTYPE_QUALITY,
FONT_QUALITY_CLEARTYPE_NATURAL = CLEARTYPE_NATURAL_QUALITY,
#endif

NUM_QUALITIES
};

namespace EBlendMode
{
enum EBlendModeType
Expand Down Expand Up @@ -78,6 +97,7 @@ class CGraphicsInterface
virtual float GetDXTextExtent ( const char * szText, float fScale = 1.0f, ID3DXFont * pDXFont = NULL, bool bColorCoded = false ) = 0;

virtual bool LoadAdditionalDXFont ( std::string strFontPath, std::string strFontName, unsigned int uiHeight, bool bBold, ID3DXFont** ppD3DXFont ) = 0;
virtual bool LoadAdditionalDXFont ( std::string strFontPath, std::string strFontName, unsigned int uiHeight, bool bBold, DWORD ulQuality, ID3DXFont** ppD3DXFont ) = 0;
virtual bool DestroyAdditionalDXFont ( std::string strFontPath, ID3DXFont* pD3DXFont ) = 0;

virtual ID3DXFont * GetFont ( eFontType fontType = FONT_DEFAULT, float* pfOutScaleUsed = NULL, float fRequestedScale = 1, const char* szCustomScaleUser = NULL ) = 0;
Expand Down
6 changes: 3 additions & 3 deletions MTA10/sdk/core/CRenderItemManagerInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class CRenderItemManagerInterface

// CRenderItemManagerInterface
virtual void DoPulse ( void ) = 0;
virtual CDxFontItem* CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold ) = 0;
virtual CDxFontItem* CreateDxFont ( const SString& strFullFilePath, uint uiSize, bool bBold, DWORD ulQuality = DEFAULT_QUALITY ) = 0;
virtual CGuiFontItem* CreateGuiFont ( const SString& strFullFilePath, const SString& strFontName, uint uiSize ) = 0;
virtual CTextureItem* CreateTexture ( const SString& strFullFilePath, const CPixels* pPixels = NULL, bool bMipMaps = true, uint uiSizeX = RDEFAULT, uint uiSizeY = RDEFAULT, ERenderFormat format = RFORMAT_UNKNOWN, ETextureAddress textureAddress = TADDRESS_WRAP, ETextureType textureType = TTYPE_TEXTURE, uint uiVolumeDepth = 1 ) = 0;
virtual CShaderItem* CreateShader ( const SString& strFullFilePath, const SString& strRootPath, SString& strOutStatus, float fPriority, float fMaxDistance, bool bLayered, bool bDebug, int iTypeMask ) = 0;
Expand Down Expand Up @@ -263,12 +263,12 @@ class CDxFontItem : public CRenderItem
{
DECLARE_CLASS( CDxFontItem, CRenderItem )
CDxFontItem ( void ) : ClassInit ( this ) {}
virtual void PostConstruct ( CRenderItemManager* pManager, const SString& strFullFilePath, uint uiSize, bool bBold );
virtual void PostConstruct ( CRenderItemManager* pManager, const SString& strFullFilePath, uint uiSize, bool bBold, DWORD ulQuality = DEFAULT_QUALITY );
virtual void PreDestruct ( void );
virtual bool IsValid ( void );
virtual void OnLostDevice ( void );
virtual void OnResetDevice ( void );
void CreateUnderlyingData ( uint uiSize, bool bBold );
void CreateUnderlyingData ( uint uiSize, bool bBold, DWORD ulQuality = DEFAULT_QUALITY );
void ReleaseUnderlyingData ( void );

SString m_strFullFilePath;
Expand Down