📄 nd_bitmap.cpp
字号:
#include <windows.h>
#include "nd_bitmap.h"
#include "c3_capscreen.h"
#include "basefunc.h"
#include "GameDataSet.h"
#include <direct.h>
// globle
int _SCR_WIDTH =1024;
int _SCR_HEIGHT =768;
const int _EMOTION_SIZE = 22;
// static
C3Font* CMyBitmap::s_GameFont =NULL;
deque <C3Font*>* CMyBitmap::s_pOtherFontSet = NULL;
C3Camera* CMyBitmap::s_pCamera = NULL;
DWORD CMyBitmap::s_dwFontSize =12;
int CMyBitmap::s_nShowMode =modeNone;
float CMyBitmap::s_fZoom = 1.0;
#ifdef _ANALYSIS_ON
DWORD g_dwBitmapLoadAmount = 0;
DWORD g_dwBitmapLoadTime = 0;
DWORD g_dwBitmapLoadTimeMax = 0;
DWORD g_dwBitmapLoadTimeFrame = 0;
DWORD g_dw3DObjLoadAmount = 0;
DWORD g_dw3DObjLoadTime = 0;
DWORD g_dw3DObjLoadTimeMax = 0;
DWORD g_dw3DObjLoadTimeFrame = 0;
DWORD g_dw3DMotionLoadAmount = 0;
DWORD g_dw3DMotionLoadTime = 0;
DWORD g_dw3DMotionLoadTimeMax = 0;
DWORD g_dw3DMotionLoadTimeFrame = 0;
DWORD g_dw3DTextureLoadAmount = 0;
DWORD g_dw3DTextureLoadTime = 0;
DWORD g_dw3DTextureLoadTimeMax = 0;
DWORD g_dw3DTextureLoadTimeFrame = 0;
DWORD g_dwFrameInterval = 0;
DWORD g_dwBigTexture = 0;
#endif
//------------------------------------------------------
CMyBitmap::CMyBitmap ( void )
{
m_sprite = 0;
m_pMask = NULL;
}
CMyBitmap::~CMyBitmap ( void )
{
Destroy ();
}
//------------------------------------------------------
void CMyBitmap::Destroy ( void )
{
Sprite_Unload ( &m_sprite );
SAFE_DELETE(m_pMask);
}
//------------------------------------------------------
BOOL CMyBitmap::Load(char* pszBmpFile,DWORD dwLoadWay)
{
#ifdef _ANALYSIS_ON
g_dwBitmapLoadAmount++;
DWORD dwTimeAnalysis = ::TimeGet();
#endif
if( !pszBmpFile )
return false;
SAFE_DELETE(m_pMask);
char szBmpFile[256];
strcpy(szBmpFile, pszBmpFile);
strupr(szBmpFile);
if(strstr(szBmpFile, ".MSK"))
{
m_pMask = new CAlphaMask;
if(!m_pMask)
return false;
char szPicFileName[256];
strcpy(szPicFileName, pszBmpFile);
int nLength = strlen(pszBmpFile);
szPicFileName[nLength-3] = 'D';
szPicFileName[nLength-2] = 'D';
szPicFileName[nLength-1] = 'S';
if(!Sprite_Load ( &m_sprite, szPicFileName ))
{
int nLength = strlen(pszBmpFile);
szPicFileName[nLength-3] = 'T';
szPicFileName[nLength-2] = 'G';
szPicFileName[nLength-1] = 'A';
if(!Sprite_Load ( &m_sprite, szPicFileName ))
return false;
}
CMySize sizeInfo;
this->GetSize(sizeInfo.iWidth, sizeInfo.iHeight);
if(!m_pMask->Load(sizeInfo, pszBmpFile))
{
this->Destroy();
return false;
}
#ifdef _ANALYSIS_ON
if(m_sprite->lpTex->Info.Width > 256 || m_sprite->lpTex->Info.Height > 256)
{
g_dwBigTexture ++;
}
#endif
return true;
}
BOOL bReturn = Sprite_Load( &m_sprite, pszBmpFile ,D3DPOOL_MANAGED , 0, dwLoadWay);
#ifdef _ANALYSIS_ON
if(m_sprite->lpTex->Info.Width > 256 || m_sprite->lpTex->Info.Height > 256)
{
g_dwBigTexture ++;
}
DWORD dwTimePass = ::TimeGet() - dwTimeAnalysis;
g_dwBitmapLoadTime += dwTimePass;
g_dwBitmapLoadTimeFrame += dwTimePass;
if(g_dwBitmapLoadTimeMax < dwTimePass)
g_dwBitmapLoadTimeMax = dwTimePass;
#endif
return bReturn;
}
//------------------------------------------------------
void CMyBitmap::Show ( int x, int y, int alpha, DWORD dwShowWay )
{
if(s_fZoom == 1.0)
{
if (CMyBitmap::s_nShowMode != modeSprite)
CMyBitmap::PrepareSprite();
if (alpha != 0)
Sprite_SetColor ( m_sprite, alpha, 255, 255, 255 );
Sprite_SetCoor ( m_sprite, 0, x, y );
Sprite_Draw ( m_sprite,dwShowWay );
}
else
{
CMySize sizeBitmap = {0, 0};
this->GetSize(sizeBitmap.iWidth, sizeBitmap.iHeight);
sizeBitmap.iHeight *= s_fZoom;
sizeBitmap.iWidth *= s_fZoom;
this->ShowEx(x, y, NULL, sizeBitmap.iWidth, sizeBitmap.iHeight, dwShowWay);
}
}
//------------------------------------------------------
void CMyBitmap::ShowEx ( int x, int y, RECT *lpSrc, DWORD dwWidth, DWORD dwHeight, int alpha, DWORD dwShowWay )
{
int nWidth = 0, nHeight = 0;
if(!lpSrc && (nWidth == dwWidth) && (nHeight == dwHeight) && (s_fZoom == 1.0))
{
if (CMyBitmap::s_nShowMode != modeSprite)
CMyBitmap::PrepareSprite();
if (alpha != 0)
Sprite_SetColor ( m_sprite, alpha, 255, 255, 255 );
Sprite_SetCoor ( m_sprite, 0, x, y );
Sprite_Draw ( m_sprite,dwShowWay );
return;
}
if (CMyBitmap::s_nShowMode != modeSprite)
CMyBitmap::PrepareSprite();
if (alpha != 0)
Sprite_SetColor ( m_sprite, alpha, 255, 255, 255 );
Sprite_SetCoor ( m_sprite, lpSrc, x, y, dwWidth, dwHeight );
Sprite_Draw ( m_sprite,dwShowWay );
}
//------------------------------------------------------
void CMyBitmap::Show(CMyBitmap* pBmpUp, CMyBitmap* pBmpDn,
UCHAR uAlphaA, UCHAR uAlphaB, UCHAR uAlphaC, UCHAR uAlphaD,
int x, int y, RECT *lpSrc, DWORD dwWidth, DWORD dwHeight)
{
CMyBitmap::s_nShowMode = modeNone;
int nWidth = 0, nHeight = 0;
if(!pBmpUp || !pBmpDn || !pBmpUp->m_sprite || !pBmpDn->m_sprite)
return;
if(!lpSrc && (nWidth == dwWidth) && (nHeight == dwHeight) && (s_fZoom == 1.0))
{
Sprite_SetCoor ( pBmpUp->m_sprite, 0, x, y );
Sprite_Draw ( pBmpUp->m_sprite, pBmpDn->m_sprite, uAlphaA, uAlphaB, uAlphaC, uAlphaD);
return;
}
Sprite_SetCoor ( pBmpUp->m_sprite, lpSrc, x, y, dwWidth, dwHeight );
Sprite_Draw ( pBmpUp->m_sprite, pBmpDn->m_sprite, uAlphaA, uAlphaB, uAlphaC, uAlphaD);
}
//------------------------------------------------------
void CMyBitmap::GetSize ( int& nWidth, int& nHeight)
{
nWidth = m_sprite->lpTex->Info.Width;
nHeight = m_sprite->lpTex->Info.Height;
}
//------------------------------------------------------
DWORD CMyBitmap::GetSize ( void )
{
DWORD dwWidth = m_sprite->lpTex->Info.Width;
DWORD dwHeight = m_sprite->lpTex->Info.Height;
return dwWidth*dwHeight;
}
//------------------------------------------------------
int CMyBitmap::GetWidth ( void )
{
return m_sprite->lpTex->Info.Width;;
}
//------------------------------------------------------
int CMyBitmap::GetHeight ( void )
{
return m_sprite->lpTex->Info.Height;
}
//------------------------------------------------------
void CMyBitmap::SetColor ( BYTE a, BYTE r, BYTE g, BYTE b )
{
Sprite_SetColor ( m_sprite, a, r, g, b );
}
void CMyBitmap::SetVertexColor ( DWORD ltColor, DWORD rtColor, DWORD lbColor, DWORD rbColor )
{
Sprite_SetVertexColor ( m_sprite, ltColor,rtColor,lbColor,rbColor );
}
//------------------------------------------------------
BOOL CMyBitmap::IsbTransparentFormat()
{
if(!m_sprite->lpTex)
return false;
if((m_sprite->lpTex->Info.Format == D3DFMT_A8R8G8B8) ||
(m_sprite->lpTex->Info.Format == D3DFMT_DXT3))
return true;
return false;
}
//------------------------------------------------------
BOOL CMyBitmap::GameCameraCreate()
{
if(s_pCamera)
CMyBitmap::GameCameraDestroy();
s_pCamera = new C3Camera;
if(!s_pCamera)
return false;
Camera_Clear ( s_pCamera );
s_pCamera->lpFrom = new D3DXVECTOR3[1];
s_pCamera->lpFrom[0].x = _SCR_WIDTH/2;
s_pCamera->lpFrom[0].y = -1000;
s_pCamera->lpFrom[0].z = _SCR_HEIGHT/2;
s_pCamera->lpTo = new D3DXVECTOR3[1];
s_pCamera->lpTo[0].x = _SCR_WIDTH/2;
s_pCamera->lpTo[0].y = 0;
s_pCamera->lpTo[0].z = _SCR_HEIGHT/2;
s_pCamera->fNear = 1.0f;
s_pCamera->fFar = 10000.0f;
return true;
}
//------------------------------------------------------
void CMyBitmap::GameCameraDestroy()
{
if ( s_pCamera )
{
SafeDeleteEx ( s_pCamera->lpFrom );
SafeDeleteEx ( s_pCamera->lpTo );
SafeDelete ( s_pCamera );
s_pCamera = NULL;
}
}
//------------------------------------------------------
void CMyBitmap::GameCameraBuild(CMySize sizeScr)
{
if(s_pCamera)
{
Camera_BuildView ( s_pCamera, true );
Camera_BuildOrtho ( s_pCamera, sizeScr.iWidth, sizeScr.iHeight, true );
// Camera_BuildMix ( s_pCamera );
}
}
//------------------------------------------------------
void CMyBitmap::GameCameraSet(float fX, float fZ)
{
if(s_pCamera)
{
s_pCamera->lpFrom[0].x = fX;
s_pCamera->lpFrom[0].z = fZ;
s_pCamera->lpTo[0].x = fX;
s_pCamera->lpTo[0].z = fZ;
}
}
//------------------------------------------------------
BOOL CMyBitmap::GameFontCreate()
{
s_GameFont =CMyBitmap::CreateFont(g_objGameDataSet.GetStr(10049), 12);
s_dwFontSize =12;
return (s_GameFont != NULL);
}
//------------------------------------------------------
void CMyBitmap::GameFontDestroy()
{
CMyBitmap::DestroyFont(s_GameFont);
s_GameFont = NULL;
if(s_pOtherFontSet)
{
int nAmount = s_pOtherFontSet->size();
for(int i = 0; i < nAmount; i ++)
{
C3Font* pfont = (*s_pOtherFontSet)[i];
if(pfont)
Font_Release(&pfont);
}
s_pOtherFontSet->clear();
}
SAFE_DELETE(s_pOtherFontSet);
}
//------------------------------------------------------
C3Font* CMyBitmap::CreateFont ( const char* pszFontName, int nSize )
{
C3Font *font = 0;
Font_Create ( &font, ( char* )pszFontName, nSize );
return font;
}
//------------------------------------------------------
void CMyBitmap::DestroyFont ( C3Font *font )
{
if (font)
Font_Release(&font);
}
//------------------------------------------------------
void CMyBitmap::GetFontSize(CMySize& infoSize)
{
infoSize.iHeight = s_dwFontSize;
infoSize.iWidth = s_dwFontSize/2;
}
//------------------------------------------------------
void CMyBitmap::ShowTString ( int iPosX, int iPosY, DWORD color, const char* pszString, char* pszFont, int nFontSize, BOOL bAlpha)
{
if (!pszString)
return;
::RepairString((char*)pszString);
if (strlen(pszString) == 0)
return;
if (CMyBitmap::s_nShowMode != modeText)
{
Font_Prepare();
CMyBitmap::s_nShowMode =modeText;
}
C3Font *pMyFont = NULL;
if (!pszFont)
{
pMyFont =CMyBitmap::s_GameFont;
}
else
{
if(!s_pOtherFontSet)
{
s_pOtherFontSet = new (deque <C3Font*>);
MYASSERT(s_pOtherFontSet);
}
// search ...
BOOL bFound = false;
int nAmount = s_pOtherFontSet->size();
for(int i = 0; i < nAmount; i ++)
{
C3Font* pFont = (*s_pOtherFontSet)[i];
int nSize = nFontSize;
if(nSize <= 16)
nSize = 16;
else if(nSize <= 32)
nSize = 32;
else
nSize = 64;
if(pFont && strcmp(pFont->szName, pszFont) == 0 && pFont->nSize == nSize)
{
// found ...
bFound = true;
pMyFont = pFont;
break;
}
}
// create ...
if(!bFound)
{
pMyFont = CMyBitmap::CreateFont(pszFont, nFontSize);
if(pMyFont)
s_pOtherFontSet->push_back(pMyFont);
else
return;
}
pMyFont->nRealSize = nFontSize;
}
if(bAlpha == false)
color |= 0xff000000;
int step=iPosY;
int temp = 0;
char ss[2];
for ( int n = 0; n < strlen ( pszString ); n++ )
{
ss[0] = pszString[n];
ss[1] = pszString[n + 1];
Font_Draw ( pMyFont, iPosX, step, color, ss );
// if ( ( BYTE )ss[0] > 0x80 && ( BYTE )ss[0] < 0xfe)
step += pMyFont->nRealSize;
if ( ( BYTE )pszString[n] > 0x80 && ( BYTE )ss[0] < 0xfe)
n++;
temp++;
}
}
//------------------------------------------------------
void CMyBitmap::ShowString ( int iPosX, int iPosY, DWORD color, const char* pszString, char* pszFont, int nFontSize, BOOL bAlpha)
{
if (!pszString)
return;
::RepairString((char*)pszString);
if (strlen(pszString) == 0)
return;
if (CMyBitmap::s_nShowMode != modeText)
{
Font_Prepare();
CMyBitmap::s_nShowMode =modeText;
}
C3Font *pMyFont = NULL;
if (!pszFont)
{
pMyFont =CMyBitmap::s_GameFont;
}
else
{
if(!s_pOtherFontSet)
{
s_pOtherFontSet = new (deque <C3Font*>);
MYASSERT(s_pOtherFontSet);
}
// search ...
BOOL bFound = false;
int nAmount = s_pOtherFontSet->size();
for(int i = 0; i < nAmount; i ++)
{
C3Font* pFont = (*s_pOtherFontSet)[i];
int nSize = nFontSize;
if(nSize <= 16)
nSize = 16;
else if(nSize <= 32)
nSize = 32;
else
nSize = 64;
if(pFont && strcmp(pFont->szName, pszFont) == 0 && pFont->nSize == nSize)
{
// found ...
bFound = true;
pMyFont = pFont;
break;
}
}
// create ...
if(!bFound)
{
pMyFont = CMyBitmap::CreateFont(pszFont, nFontSize);
if(pMyFont)
s_pOtherFontSet->push_back(pMyFont);
else
return;
}
pMyFont->nRealSize = nFontSize;
}
if(bAlpha == false)
color |= 0xff000000;
int step=iPosX;
int temp = 0;
char ss[2];
for ( int n = 0; n < strlen ( pszString ); n++ )
{
ss[0] = pszString[n];
ss[1] = pszString[n + 1];
Font_Draw ( pMyFont, step, iPosY, color, ss );
if ( ( BYTE )ss[0] > 0x80 && ( BYTE )ss[0] < 0xfe)
step += pMyFont->nRealSize;
else
step += ( int )( ( float )pMyFont->nRealSize / 2.0f + 0.5f );
if ( ( BYTE )pszString[n] > 0x80 && ( BYTE )ss[0] < 0xfe)
n++;
temp++;
}
}
//------------------------------------------------------
void CMyBitmap::ShowEmotionString (int iPosX, int iPosY, DWORD color, const char* pszString, DWORD dwBeginTime, BOOL bEmotion /* = true */, char* pszFont, int nFontSize)
{
if (!pszString || strlen( pszString ) <= 0)
return;
if ( CMyBitmap::s_nShowMode != modeText )
{
Font_Prepare();
CMyBitmap::s_nShowMode =modeText;
}
C3Font *pMyFont = NULL;
if (!pszFont)
{
pMyFont =CMyBitmap::s_GameFont;
}
else
{
if(!s_pOtherFontSet)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -