📄 nd_bitmap.cpp
字号:
{
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;
}
color |= 0xff000000;
int step = iPosX;
char ss[2];
int nStrLen = strlen(pszString);
for ( int n = 0; n < nStrLen; n++ )
{
// Jump line
if ( pszString[n] == 0x0a )
{
step = iPosX;
iPosY += pMyFont->nRealSize + pMyFont->nRealSize / 4;
continue;
}
// Test the emotion char '#'
if ( pszString[n] == '#' &&
n + 2 < nStrLen &&
pszString[n + 1] >= '0' &&
pszString[n + 1] <= '9' &&
pszString[n + 2] >= '0' &&
pszString[n + 2] <= '9')
{
char strIndex[3];
strIndex[0] = pszString[n + 1];
strIndex[1] = pszString[n + 2];
strIndex[2] = '\n';
int nIndex = atoi( strIndex );
if ( nIndex >= 0 && nIndex < g_objGameDataSet.GetEmotionAmount() )
{
CAni* pShowAni = g_objGameDataSet.GetEmotionIcon(nIndex);
if ( pShowAni != NULL)
{
int nFrame = (::TimeGet() - dwBeginTime)/ 200 % pShowAni->GetFrameAmount();
if (bEmotion)
pShowAni->ShowEx( nFrame,step,iPosY - 6,NULL,_EMOTION_SIZE,_EMOTION_SIZE);
n += 2;
step += _EMOTION_SIZE;
// step += pMyFont->nRealSize + ( int )( ( float )pMyFont->nRealSize / 2.0f + 0.5f );
continue;
}
}
}
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;
n ++;
}
else
step += ( int )( ( float )pMyFont->nRealSize / 2.0f + 0.5f );
}
}
//------------------------------------------------------
void CMyBitmap::PrepareLine ( void )
{
SetRenderState ( D3DRS_ZENABLE, false );
SetRenderState ( D3DRS_ZWRITEENABLE, false );
SetRenderState ( D3DRS_SHADEMODE, D3DSHADE_GOURAUD );
SetRenderState ( D3DRS_DITHERENABLE, false );
SetRenderState ( D3DRS_CULLMODE, D3DCULL_NONE );
SetRenderState ( D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1 );
SetRenderState ( D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1 );
SetRenderState ( D3DRS_ALPHABLENDENABLE, true );
SetRenderState ( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
SetRenderState ( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
SetTextureStageState ( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
SetTextureStageState ( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
SetTextureStageState ( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG2 );
SetTextureStageState ( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
SetTextureStageState ( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
SetTextureStageState ( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2 );
SetTextureStageState ( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR );
SetTextureStageState ( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );
SetTextureStageState ( 0, D3DTSS_MIPFILTER, D3DTEXF_LINEAR );
SetTextureStageState ( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
SetTextureStageState ( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
SetTextureStageState ( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );
SetTextureStageState ( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
SetTextureStageState ( 1, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
SetTextureStageState ( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
SetTextureStageState ( 1, D3DTSS_MINFILTER, D3DTEXF_NONE );
SetTextureStageState ( 1, D3DTSS_MAGFILTER, D3DTEXF_NONE );
SetTextureStageState ( 1, D3DTSS_MIPFILTER, D3DTEXF_NONE );
// mode
CMyBitmap::s_nShowMode =modeLine;
}
//------------------------------------------------------
void CMyBitmap::ShowLine ( LineVertex *line, DWORD num )
{
if (CMyBitmap::s_nShowMode != modeLine)
CMyBitmap::PrepareLine();
g_D3DDevice->SetVertexShader ( LINE_VERTEX );
g_D3DDevice->DrawPrimitiveUP ( D3DPT_LINELIST,
num,
line,
sizeof ( LineVertex ) );
}
//------------------------------------------------------
void CMyBitmap::ShowLine ( int nPosX1, int nPosY1, int nPosX2, int nPosY2, DWORD dwColor)
{
static LineVertex s_Line[2];
s_Line[0].x = nPosX1;
s_Line[0].y = nPosY1;
s_Line[0].z = 0;
s_Line[0].rhw = 0;
s_Line[0].color = dwColor | 0xff000000;
s_Line[1].x = nPosX2;
s_Line[1].y = nPosY2;
s_Line[1].z = 0;
s_Line[1].rhw = 0;
s_Line[1].color = dwColor | 0xff000000;
ShowLine ( s_Line, 1 ); // 在此位图上画线,可指定透明度
}
//------------------------------------------------------
void CMyBitmap::ShowRect ( int x1, int y1, int x2, int y2, DWORD color )
{
static LineVertex s_line[8];
s_line[0].x = x1;
s_line[0].y = y1;
s_line[0].z = 0;
s_line[0].rhw = 0;
s_line[0].color = color;
s_line[1].x = x1;
s_line[1].y = y2;
s_line[1].z = 0;
s_line[1].rhw = 0;
s_line[1].color = color;
s_line[2].x = x1;
s_line[2].y = y2;
s_line[2].z = 0;
s_line[2].rhw = 0;
s_line[2].color = color;
s_line[3].x = x2;
s_line[3].y = y2;
s_line[3].z = 0;
s_line[3].rhw = 0;
s_line[3].color = color;
s_line[4].x = x2;
s_line[4].y = y2;
s_line[4].z = 0;
s_line[4].rhw = 0;
s_line[4].color = color;
s_line[5].x = x2;
s_line[5].y = y1;
s_line[5].z = 0;
s_line[5].rhw = 0;
s_line[5].color = color;
s_line[6].x = x2;
s_line[6].y = y1;
s_line[6].z = 0;
s_line[6].rhw = 0;
s_line[6].color = color;
s_line[7].x = x1;
s_line[7].y = y1;
s_line[7].z = 0;
s_line[7].rhw = 0;
s_line[7].color = color;
ShowLine ( s_line, 4 ); // 在此位图上画线,可指定透明度
}
//------------------------------------------------------
void CMyBitmap::ShowBlock( int x1, int y1, int x2, int y2, DWORD color1, DWORD color2, DWORD color3, DWORD color4)
{
static LineVertex s_vec[4];
s_vec[0].x = x1;
s_vec[0].y = y1;
s_vec[0].z = 0;
s_vec[0].rhw = 1;
s_vec[0].color = color1;
s_vec[1].x = x1;
s_vec[1].y = y2;
s_vec[1].z = 0;
s_vec[1].rhw = 1;
s_vec[1].color = color2;
s_vec[2].x = x2;
s_vec[2].y = y1;
s_vec[2].z = 0;
s_vec[2].rhw = 1;
s_vec[2].color = color3;
s_vec[3].x = x2;
s_vec[3].y = y2;
s_vec[3].z = 0;
s_vec[3].rhw = 1;
s_vec[3].color = color4;
if (CMyBitmap::s_nShowMode != modeLine)
CMyBitmap::PrepareLine();
g_D3DDevice->SetVertexShader ( LINE_VERTEX );
g_D3DDevice->DrawPrimitiveUP ( D3DPT_TRIANGLESTRIP,
2,
s_vec,
sizeof ( LineVertex ) );
}
//------------------------------------------------------
void CMyBitmap::ShowBlock( CMyPos posA, CMyPos posB, CMyPos posC, CMyPos posD, DWORD color )
{
static LineVertex s_vec[4];
s_vec[0].x = posA.x;
s_vec[0].y = posA.y;
s_vec[0].z = 0;
s_vec[0].rhw = 0;
s_vec[0].color = color;
s_vec[1].x = posB.x;
s_vec[1].y = posB.y;
s_vec[1].z = 0;
s_vec[1].rhw = 0;
s_vec[1].color = color;
s_vec[2].x = posC.x;
s_vec[2].y = posC.y;
s_vec[2].z = 0;
s_vec[2].rhw = 0;
s_vec[2].color = color;
s_vec[3].x = posD.x;
s_vec[3].y = posD.y;
s_vec[3].z = 0;
s_vec[3].rhw = 0;
s_vec[3].color = color;
if (CMyBitmap::s_nShowMode != modeLine)
CMyBitmap::PrepareLine();
g_D3DDevice->SetVertexShader ( LINE_VERTEX );
g_D3DDevice->DrawPrimitiveUP ( D3DPT_TRIANGLESTRIP,
2,
s_vec,
sizeof ( LineVertex ) );
}
//------------------------------------------------------
void CMyBitmap::ShowBlock ( int x1, int y1, int x2, int y2, DWORD color )
{
static LineVertex s_vec[4];
s_vec[0].x = x1;
s_vec[0].y = y1;
s_vec[0].z = 0;
s_vec[0].rhw = 0;
s_vec[0].color = color;
s_vec[1].x = x1;
s_vec[1].y = y2;
s_vec[1].z = 0;
s_vec[1].rhw = 0;
s_vec[1].color = color;
s_vec[2].x = x2;
s_vec[2].y = y1;
s_vec[2].z = 0;
s_vec[2].rhw = 0;
s_vec[2].color = color;
s_vec[3].x = x2;
s_vec[3].y = y2;
s_vec[3].z = 0;
s_vec[3].rhw = 0;
s_vec[3].color = color;
if (CMyBitmap::s_nShowMode != modeLine)
CMyBitmap::PrepareLine();
g_D3DDevice->SetVertexShader ( LINE_VERTEX );
g_D3DDevice->DrawPrimitiveUP ( D3DPT_TRIANGLESTRIP,
2,
s_vec,
sizeof ( LineVertex ) );
}
//------------------------------------------------------
BOOL CMyBitmap::Init3D ( HINSTANCE hInst,
const char *lpTitle,
DWORD dwWidth,
DWORD dwHeight,
BOOL bWindowed,
WNDPROC proc,
DWORD dwBackCount )
{
if ( !::Init3D ( hInst, lpTitle, dwWidth, dwHeight, bWindowed, proc, dwBackCount ) )
return false;
CMyBitmap::GameCameraCreate();
CMySize sizeScr = {_SCR_WIDTH, _SCR_HEIGHT};
CMyBitmap::GameCameraBuild(sizeScr);
//Phy_Init ( "phy2.vsh" );
return true;
}
//------------------------------------------------------
BOOL CMyBitmap::Init3DEx ( HWND hWnd,
DWORD dwWidth,
DWORD dwHeight,
BOOL bWindowed,
DWORD dwBackCount )
{
BOOL bSucInit =false;
int rval = ::Init3DEx ( hWnd, dwWidth, dwHeight, bWindowed, dwBackCount );
switch(rval)
{
case 0:
{
const OBJID idDxError0=500016;
::ErrorMsg(g_objGameDataSet.GetStr(idDxError0));
break;
}
case -1:
{
const OBJID idDxError1=500017;
::ErrorMsg(g_objGameDataSet.GetStr(idDxError1));
break;
}
case -2:
{
const OBJID idDxError2=500018;
::ErrorMsg(g_objGameDataSet.GetStr(idDxError2));
break;
}
case -3:
{
const OBJID idDxError3=500019;
::ErrorMsg(g_objGameDataSet.GetStr(idDxError3));
bSucInit = true;
break;
}
case 1:
{
bSucInit = true;
break;
}
default:
{
const OBJID idDxErrorDef=500020;
::ErrorMsg(g_objGameDataSet.GetStr(idDxErrorDef));
break;
}
}
CMyBitmap::GameCameraCreate();
CMySize sizeScr = {_SCR_WIDTH, _SCR_HEIGHT};
CMyBitmap::GameCameraBuild(sizeScr);
float fX, fZ;
fX = (float)_SCR_WIDTH/2;
fZ = (float)_SCR_HEIGHT/2;
CMyBitmap::GameCameraSet(fX, fZ);
//Phy_Init ( "phy2.vsh" );
return bSucInit;
}
//------------------------------------------------------
void CMyBitmap::Quit3D (void)
{
CMyBitmap::GameCameraDestroy();
CMyBitmap::GameFontDestroy();
::Quit3D();
}
//------------------------------------------------------
BOOL CMyBitmap::Begin3D ( void )
{
return ::Begin3D ();
}
//------------------------------------------------------
BOOL CMyBitmap::End3D ( void )
{
return ::End3D ();
}
//------------------------------------------------------
BOOL CMyBitmap::ClearBuffer ( BOOL bZBuffer, BOOL bTarget, D3DCOLOR color )
{
return ::ClearBuffer ( bZBuffer, bTarget, color );
}
//------------------------------------------------------
BOOL CMyBitmap::Flip ( void )
{
return ::Flip ();
}
//------------------------------------------------------
void CMyBitmap::PrepareSprite ( void )
{
Sprite_Prepare ();
// mode
CMyBitmap::s_nShowMode =modeSprite;
}
//------------------------------------------------------
DWORD CMyBitmap::CalcRate ( void )
{
return ::CalcRate ();
}
//------------------------------------------------------
BOOL CMyBitmap::IsTransparent(CMyPos posPoint)
{
if(!m_pMask)
return true;
else
return m_pMask->IsTransparent(posPoint);
}
//------------------------------------------------------
void CMyBitmap::ScreenShot(const char* pszFileName)
{
char szFileName[256] = "";
if (!pszFileName)
{
_mkdir("ScreenShot");
sprintf(szFileName, "ScreenShot/%u.jpg", ::TimeGet());
}
else
strcpy(szFileName, pszFileName);
::CapScreen(szFileName);
}
//------------------------------------------------------
//------------------------------------------------------
// ----------- C3DTexture -----------
//------------------------------------------------------
C3DTexture::C3DTexture ()
{
m_pTexture =NULL;
}
C3DTexture::~C3DTexture ()
{
this->Destroy ();
}
//------------------------------------------------------
BOOL C3DTexture::Create(const char* pszFileName)
{
if (!pszFileName)
return false;
#ifdef _ANALYSIS_ON
g_dw3DTextureLoadAmount++;
DWORD dwTimeAnalysis = ::TimeGet();
#endif
int nReturn = ::Texture_Load(&m_pTexture, (char*)pszFileName, 3);
#ifdef _ANALYSIS_ON
DWORD dwTimePass = ::TimeGet() - dwTimeAnalysis;
g_dw3DTextureLoadTime += dwTimePass;
g_dw3DTextureLoadTimeFrame += dwTimePass;
if(g_dw3DTextureLoadTimeMax < dwTimePass)
g_dw3DTextureLoadTimeMax = dwTimePass;
#endif
return (nReturn != -1);
}
//------------------------------------------------------
void C3DTexture::Destroy(void)
{
if (m_pTexture)
::Texture_Unload(&m_pTexture);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -