#include "stdafx.h" #include "fontagent.h" #include "RenderSystem.h" #include "D3DXFont.h" #include "Application.h" cFontAgent* cFontAgent::mpFontAgent = NULL; cFontAgent::cFontAgent() { mpFontAgent = this; mpSprite = 0; mpSpriteTemp = 0; //AddFontResourceEx( _T("./2002_EYA.ttf"), FR_PRIVATE, 0 ); //* cFileLoader loader; cString path; path.Format("./language/%s/iris_gamefont.ttf", cApplication::mLangaugeFolder.Cstr() ); if( loader.Open( path.Cstr(), true ) == false ) { return; } DWORD cnt; mhFont = AddFontMemResourceEx( (PVOID)loader.GetBufferPtr(), loader.GetSize(), 0, &cnt ); if( mhFont == 0 ) { assert(0); return; } //*/ // mFontArray.Reserve( eFont_Max ); } cFontAgent::~cFontAgent() { SAFE_RELEASE( mpSprite ); // RemoveFontResourceEx( _T("./2002_EYA.ttf"), FR_PRIVATE, 0 ); if( mhFont ) RemoveFontMemResourceEx( mhFont ); } /* ------------------------------------------------------------------ * ÇÔ¼öÀ̸§ : * ¸ñ Àû : * ÁÖÀÇ»çÇ× : * ------------------------------------------------------------------ */ bool cFontAgent::Init() { sCacheInfo info; cFontObject* pFont = 0; HWND hwnd = RENDERSYS->GetHWND(); HDC dc = GetDC( hwnd ); HRESULT hr = D3DXCreateSprite( RENDERSYS->GetRenderer()->GetD3DDevice(), &mpSprite ); if( FAILED(hr) ) { assert(0); ReleaseDC( hwnd, dc ); return false; } ////////////////////////////////////////////////////////////////////////// /// UI¿ë ÆùÆ® ( UI¿ë, °íÁ¤ SystemMsg ) pFont = new cD3DXFont; // pFont = new cCacheFont; info.texNum = 2; if( pFont && pFont->CreateFont( hwnd, NULL, info ) == true ) { mFontArray.PushBack( pFont ); } else { assert(0); ReleaseDC( hwnd, dc ); return false; } ////////////////////////////////////////////////////////////////////////// /// UI¿ë BOLD pFont = new cD3DXFont; // pFont = new cCacheFont; int fontHeight = -MulDiv( 9, GetDeviceCaps( dc, LOGPIXELSY ), 72 ); LOGFONT font; font.lfHeight = fontHeight; font.lfWidth = -font.lfHeight / 2; font.lfEscapement = 0; font.lfOrientation = 0; font.lfWeight = FW_BOLD; font.lfItalic = 0; font.lfUnderline = 0; font.lfStrikeOut = 0; font.lfCharSet = DEFAULT_CHARSET; font.lfOutPrecision = OUT_DEFAULT_PRECIS; font.lfClipPrecision = CLIP_DEFAULT_PRECIS; font.lfQuality = PROOF_QUALITY; font.lfPitchAndFamily = 0; ::lstrcpy( font.lfFaceName, _T("M+2P+IPAG Regular") ); // ::lstrcpy( font.lfFaceName, _T("2002_EYA") ); info.texNum = 1; if( pFont && pFont->CreateFont( hwnd, &font, info ) == true ) { mFontArray.PushBack( pFont ); } else { assert(0); ReleaseDC( hwnd, dc ); return false; } ////////////////////////////////////////////////////////////////////////// /// ½Ã½ºÅÛ ÆùÆ® (Tooltip, Name, GameInfo, À¯µ¿SystemMsg) pFont = new cD3DXFont; // pFont = new cCacheFont; info.texNum = 2; if( pFont && pFont->CreateFont( hwnd, NULL, info ) ) { mFontArray.PushBack( pFont ); } else { assert(0); ReleaseDC( hwnd, dc ); return false; } ////////////////////////////////////////////////////////////////////////// /// äÆÃ¿ë pFont = new cD3DXFont; // pFont = new cCacheFont; info.texNum = 2; if( pFont && pFont->CreateFont( hwnd, NULL, info ) ) { mFontArray.PushBack( pFont ); } else { assert(0); ReleaseDC( hwnd, dc ); return false; } ////////////////////////////////////////////////////////////////////////// /// °øÁö¿ë pFont = new cD3DXFont; // pFont = new cCacheFont; if( !pFont ) { ReleaseDC( hwnd, dc ); return false; } fontHeight = -MulDiv( 15, GetDeviceCaps( dc, LOGPIXELSY ), 72 ); font.lfHeight = fontHeight; font.lfWidth = -font.lfHeight / 2; font.lfEscapement = 0; font.lfOrientation = 0; font.lfWeight = FW_NORMAL; font.lfItalic = 0; font.lfUnderline = 0; font.lfStrikeOut = 0; font.lfCharSet = DEFAULT_CHARSET; font.lfOutPrecision = OUT_DEFAULT_PRECIS; font.lfClipPrecision = CLIP_DEFAULT_PRECIS; font.lfQuality = PROOF_QUALITY; font.lfPitchAndFamily = 0; ::lstrcpy( font.lfFaceName, _T("M+2P+IPAG Regular") ); // ::lstrcpy( font.lfFaceName, _T("2002_EYA") ); info.texNum = 1; if( pFont && pFont->CreateFont( hwnd, &font, info ) == true ) { mFontArray.PushBack( pFont ); } else { assert(0); ReleaseDC( hwnd, dc ); return false; } ////////////////////////////////////////////////////////////////////////// /// ±íÀ̰¡ ÀÖ´Â ¸é¿¡ ±×·ÁÁú ÆùÆ®¿ë pFont = new cD3DXFont; // pFont = new cCacheFont; fontHeight = -MulDiv( 9, GetDeviceCaps( dc, LOGPIXELSY ), 72 ); font.lfHeight = fontHeight; font.lfWidth = -font.lfHeight / 2; font.lfEscapement = 0; font.lfOrientation = 0; font.lfWeight = FW_NORMAL; font.lfItalic = 0; font.lfUnderline = 0; font.lfStrikeOut = 0; font.lfCharSet = DEFAULT_CHARSET; font.lfOutPrecision = OUT_DEFAULT_PRECIS; font.lfClipPrecision = CLIP_DEFAULT_PRECIS; font.lfQuality = PROOF_QUALITY; font.lfPitchAndFamily = 0; ::lstrcpy( font.lfFaceName, _T("M+2P+IPAG Regular") ); // ::lstrcpy( font.lfFaceName, _T("2002_EYA") ); info.texNum = 2; if( pFont && pFont->CreateFont( hwnd, &font, info ) == true ) { mFontArray.PushBack( pFont ); pFont->SetAlpha( false ); } else { assert(0); ReleaseDC( hwnd, dc ); return false; } ////////////////////////////////////////////////////////////////////////// /// NPC ´ëȭâ UI¿¡ ¾²ÀÏ ÆùÆ®!! pFont = new cD3DXFont; // pFont = new cCacheFont; fontHeight = -MulDiv( 13, GetDeviceCaps( dc, LOGPIXELSY ), 72 ); font.lfHeight = fontHeight; font.lfWidth = -font.lfHeight / 2; font.lfEscapement = 0; font.lfOrientation = 0; font.lfWeight = FW_NORMAL; font.lfItalic = 0; font.lfUnderline = 0; font.lfStrikeOut = 0; font.lfCharSet = DEFAULT_CHARSET; font.lfOutPrecision = OUT_DEFAULT_PRECIS; font.lfClipPrecision = CLIP_DEFAULT_PRECIS; font.lfQuality = PROOF_QUALITY; font.lfPitchAndFamily = 0; ::lstrcpy( font.lfFaceName, _T("M+2P+IPAG Regular") ); // ::lstrcpy( font.lfFaceName, _T("2002_EYA") ); info.texNum = 2; if( pFont && pFont->CreateFont( hwnd, &font, info ) == true ) { mFontArray.PushBack( pFont ); pFont->SetAlpha( false ); } else { assert(0); ReleaseDC( hwnd, dc ); return false; } ReleaseDC( hwnd, dc ); return true; } /* ------------------------------------------------------------------ * ÇÔ¼öÀ̸§ : cFontAgent::Exit() * ¸ñ Àû : Á¾·áºÎ * ÁÖÀÇ»çÇ× : * ------------------------------------------------------------------ */ void cFontAgent::Exit() { SAFE_RELEASE( mpSprite ); if( mFontArray.GetSize() ) { for( unsigned int i=0; iOnLostDevice(); for( unsigned int i=0; iInvalidate(); } } } /* ------------------------------------------------------------------ * ÇÔ¼öÀ̸§ : cFontAgent::Restore() * ¸ñ Àû : ÀåÄ¡ ¼Ò½Ç½Ã À¯È¿ÇÏÁö ¾ÊÀº ¸Þ¸ð¸® Àç»ý¼º * ÁÖÀÇ»çÇ× : * ------------------------------------------------------------------ */ void cFontAgent::Restore() { if( mpSprite ) mpSprite->OnResetDevice(); for( unsigned int i=0; iRestore(); } } } /* ------------------------------------------------------------------ * ÇÔ¼öÀ̸§ : * ¸ñ Àû : * ÁÖÀÇ»çÇ× : * ------------------------------------------------------------------ */ void cFontAgent::DrawText( unsigned short fontIdx, LPTSTR text, int textLen, unsigned int posX, unsigned int posY, unsigned long textColor, bool outerLine ) { POINT ps; ps.x = (LONG)posX; ps.y = (LONG)posY; DrawText( fontIdx, text, textLen, &ps, textColor, outerLine ); } void cFontAgent::DrawText( unsigned short fontIdx, LPTSTR text, int textLen, POINT* textPos, unsigned long textColor, bool outerLine ) { /// ¿¹¿Ü ó¸® if( fontIdx >= eFont_Max ) return; if( textPos->x<0 || textPos->y<0 ) return; if( textPos->x >= (int)RENDERSYS->GetScreenWidth() || textPos->y >= (int)RENDERSYS->GetScreenHeight() ) return; cFontObject* pFont = (cFontObject*)mFontArray[fontIdx]; if( pFont == NULL ) return; if( textLen == -1 ) textLen = ::_tcslen( text ); else if( textLen == 0 ) return; /// ±×·ÁÁú ¿µ¿ª °è»ê RECT rect = { textPos->x, textPos->y, 0, 0 }; rect.right = rect.left + GetTextExtent( fontIdx, text, textLen ) + GetTextWidth( fontIdx ) / 4; rect.bottom = rect.top + GetTextHeight( fontIdx ); /// ¿µ¿ªÀÌ È­¸é ¹ÛÀ̸é if( rect.right < 0 || rect.bottom < 0 ) return; if( rect.right > (LONG)RENDERSYS->GetScreenWidth() || rect.bottom > (LONG)RENDERSYS->GetScreenHeight() ) return; BeginRender(); /// ÅØ½ºÆ® µî·Ï.. pFont->DrawText( text, textLen, &rect, textColor, mpSpriteTemp, outerLine ); EndRender(); } /* ------------------------------------------------------------------ * ÇÔ¼öÀ̸§ : GetTextExtent( unsigned short fontIdx, char* text, unsigned int textLen ) * ¸ñ Àû : UI¿¡¼­ ¹®ÀÚ¿­ÀÇ ±æÀ̸¦ ¾Ë°íÀÚ ÇÒ¶§ »ç¿ëÇÑ´Ù. * ÁÖÀÇ»çÇ× : * ------------------------------------------------------------------ */ long cFontAgent::GetTextExtent( unsigned short fontIdx, LPCTSTR text, unsigned int textLen ) { cFontObject* pFont = (cFontObject*)mFontArray[fontIdx]; if( !pFont ) { return 0; } return pFont->GetTextExtent( RENDERSYS->GetHWND(), text, textLen); } /* ------------------------------------------------------------------ * ÇÔ¼öÀ̸§ : GetTextWidth( unsigned short fontIdx ) * ¸ñ Àû : ±Û²Ã¿¡¼­ ¹®ÀÚÀÇ Æò±Õ ³Êºñ¸¦ ¹Ýȯ * ÁÖÀÇ»çÇ× : * ------------------------------------------------------------------ */ long cFontAgent::GetTextWidth( unsigned short fontIdx ) { cFontObject* pFont = (cFontObject*)mFontArray[fontIdx]; if( !pFont ) { return 0; } return pFont->GetTextWidth(); } /* ------------------------------------------------------------------ * ÇÔ¼öÀ̸§ : GetTextHeight( unsigned short fontIdx ) * ¸ñ Àû : ¹®ÀÚ ¼¿ ¶Ç´Â ±Û²Ã ¹®ÀÚÀÇ ³ôÀ̸¦ ¹Ýȯ * ÁÖÀÇ»çÇ× : * ------------------------------------------------------------------ */ long cFontAgent::GetTextHeight( unsigned short fontIdx ) { cFontObject* pFont = (cFontObject*)mFontArray[fontIdx]; if( !pFont ) { return 0; } /// 1Àº ¹ØÁ٠ǥ½Ã¸¦ À§Çؼ­ ´õÇØÁØ´Ù. return pFont->GetTextHeight() + 1; } void cFontAgent::BeginRender() { mpSprite->Begin( D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_TEXTURE ); mpSpriteTemp = mpSprite; } void cFontAgent::EndRender() { mpSprite->End(); mpSpriteTemp = NULL; }