Panel.cpp
资源名称:3DRPG.rar [点击查看]
上传用户:cjwanglu
上传日期:2013-07-10
资源大小:4744k
文件大小:8k
源码类别:
游戏
开发平台:
Visual C++
- #include "stdafx.h"
- #include "Panel.h"
- #include "Game.h"
- CPanel::CPanel(LPDIRECT3DDEVICE9 d3dd,int nWidth,int nHeight,int nScreenWidth,int nScreenHeight)
- {
- m_pD3DDevice=d3dd;
- m_pBuffer=NULL;
- m_pTexture=NULL;
- m_nWidth=nWidth;
- m_nHeight=nHeight;
- m_nScreenWidth=nScreenWidth;
- m_nScreenHeight=nScreenHeight;
- m_Rect.left=0.0f;
- m_Rect.top=0.0f;
- NIcon=3;
- IconVer=NIcon*4;
- TxOfIcon=NIcon*2;
- NumOfPos=new POSS[NIcon];
- RECT rect0;rect0.left=250; rect0.top=350; rect0.right=300; rect0.bottom=100;//退出面板
- RECT rect1={rect0.left+10,rect0.top-60,63,26,};//“是”按钮
- RECT rect2={rect0.left+227,rect0.top-60,63,26,};//“否”按钮
- //RECT rect1;rect1.left=0; rect1.top=0; rect1.right=63; rect1.bottom=26;
- RECT rect3={0.0f,100.0f,800.0f,100.0f};
- RolePanel=Calculate(rect3);
- NumOfPos[0]=Calculate(rect0);
- NumOfPos[1]=Calculate(rect1);
- NumOfPos[2]=Calculate(rect2);
- m_ArrayOfTx=new LPDIRECT3DTEXTURE9[TxOfIcon];
- Result=new bool[NIcon];
- ButtonPress=new bool[NIcon];//false表示没被按下,true表示已按下
- CallPress=new bool[NIcon];//false表示按钮没被调用,true表示被调用
- for(int i=0;i<NIcon;i++)
- {
- ButtonPress[i]=false;
- CallPress[i]=false;
- Result[i]=false;
- }
- SetVertexBuffer();
- UpdateVertex();
- SetTexture();
- }
- CPanel::~CPanel()
- {
- m_pBuffer->Release();
- m_pTexture->Release();
- m_pTexture_1->Release();
- m_pIconBuffer->Release();
- for(int i=0;i<TxOfIcon;i++)
- {
- m_ArrayOfTx[i]->Release();
- }
- DeleteObject(m_ArrayOfTx);
- }
- void CPanel::SetVertexBuffer()
- {
- m_pD3DDevice->CreateVertexBuffer(8*sizeof(VERTEX),0,PANEL_D3DFVF_VERTEXBUFFER,D3DPOOL_DEFAULT,&m_pBuffer,NULL);
- m_pD3DDevice->CreateVertexBuffer(IconVer*sizeof(VERTEX),0,PANEL_D3DFVF_VERTEXBUFFER,D3DPOOL_DEFAULT,&m_pIconBuffer,NULL);
- }
- void CPanel::UpdateVertex()
- {
- VERTEX * pVertex;
- m_pBuffer->Lock(0,8*sizeof(VERTEX),(void **)&pVertex,0);
- pVertex[0].x=300;
- pVertex[0].y=580;
- pVertex[0].z=0.0f;
- pVertex[1].x=500;
- pVertex[1].y=580;
- pVertex[1].z=0.0f;
- pVertex[2].x=300;
- pVertex[2].y=520;
- pVertex[2].z=0.0f;
- pVertex[3].x=500;
- pVertex[3].y=520;
- pVertex[3].z=0.0f;
- pVertex[4].x=RolePanel.ltx;
- pVertex[4].y=RolePanel.lty;
- pVertex[4].z=0.0f;
- pVertex[5].x=RolePanel.rtx;
- pVertex[5].y=RolePanel.rty;
- pVertex[5].z=0.0f;
- pVertex[6].x=RolePanel.lbx;
- pVertex[6].y=RolePanel.lby;
- pVertex[6].z=0.0f;
- pVertex[7].x=RolePanel.rbx;
- pVertex[7].y=RolePanel.lby;
- pVertex[7].z=0.0f;
- pVertex[0].tu=0.0f;
- pVertex[0].tv=0.0f;
- pVertex[1].tu=1.0f;
- pVertex[1].tv=0.0f;
- pVertex[2].tu=0.0f;
- pVertex[2].tv=1.0f;
- pVertex[3].tu=1.0f;
- pVertex[3].tv=1.0f;
- pVertex[4].tu=0.0f;
- pVertex[4].tv=0.0f;
- pVertex[5].tu=1.0f;
- pVertex[5].tv=0.0f;
- pVertex[6].tu=0.0f;
- pVertex[6].tv=1.0f;
- pVertex[7].tu=1.0f;
- pVertex[7].tv=1.0f;
- m_pBuffer->Unlock();
- pVertex=NULL;
- m_pIconBuffer->Lock(0,IconVer*sizeof(VERTEX),(void **)&pVertex,0);
- int k=0;
- for(int i=0;i<NIcon;i++)
- {
- pVertex[k].x=NumOfPos[i].ltx;
- pVertex[k].y=NumOfPos[i].lty;
- pVertex[k].z=0;
- pVertex[k+1].x=NumOfPos[i].rtx;
- pVertex[k+1].y=NumOfPos[i].rty;
- pVertex[k+1].z=0.0f;
- pVertex[k+2].x=NumOfPos[i].lbx;
- pVertex[k+2].y=NumOfPos[i].lby;
- pVertex[k+2].z=0.0f;
- pVertex[k+3].x=NumOfPos[i].rbx;
- pVertex[k+3].y=NumOfPos[i].rby;
- pVertex[k+3].z=0.0f;
- pVertex[k+0].tu=0.0f;
- pVertex[k+0].tv=0.0f;
- pVertex[k+0].tu1=0.0f;
- pVertex[k+0].tv1=0.0f;
- pVertex[k+1].tu=1.0f;
- pVertex[k+1].tv=0.0f;
- pVertex[k+1].tu1=1.0f;
- pVertex[k+1].tv1=0.0f;
- pVertex[k+2].tu=0.0f;
- pVertex[k+2].tv=1.0f;
- pVertex[k+2].tu1=0.0f;
- pVertex[k+2].tv1=1.0f;
- pVertex[k+3].tu=1.0f;
- pVertex[k+3].tv=1.0f;
- pVertex[k+3].tu1=1.0f;
- pVertex[k+3].tv1=1.0f;
- k+=4;
- }
- m_pIconBuffer->Unlock();
- }
- HRESULT CPanel::SetTexture()
- {
- if(FAILED(D3DXCreateTextureFromFileEx(m_pD3DDevice, "./res/bar_2.tga", 0, 0, 0, 0,
- D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT,
- D3DX_DEFAULT, D3DCOLOR_XRGB(0,0,0), NULL, NULL, &m_pTexture)))
- {
- E_FAIL;
- }
- D3DXCreateTextureFromFileEx(m_pD3DDevice, "./res/bar_1.tga", 0, 0, 0, 0,
- D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT,
- D3DX_DEFAULT, D3DCOLOR_XRGB(0,0,0), NULL, NULL, &m_pTexture_1);
- D3DXCreateTextureFromFileEx(m_pD3DDevice, "./res/exit.jpg", 0, 0, 0, 0,
- D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT,
- D3DX_DEFAULT, D3DCOLOR_XRGB(0,0,0), NULL, NULL, &m_ArrayOfTx[0]);//退出面板
- D3DXCreateTextureFromFileEx(m_pD3DDevice, "./res/exit.jpg", 0, 0, 0, 0,
- D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT,
- D3DX_DEFAULT, D3DCOLOR_XRGB(0,0,0), NULL, NULL, &m_ArrayOfTx[1]);//退出面板
- D3DXCreateTextureFromFileEx(m_pD3DDevice, "./res/exit_buttonY_up.jpg", 0, 0, 0, 0,
- D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT,
- D3DX_DEFAULT, D3DCOLOR_XRGB(0,0,0), NULL, NULL, &m_ArrayOfTx[2]);//退出面板,是按钮弹起
- D3DXCreateTextureFromFileEx(m_pD3DDevice, "./res/exit_buttonY_down.jpg", 0, 0, 0, 0,
- D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT,
- D3DX_DEFAULT, D3DCOLOR_XRGB(0,0,0), NULL, NULL, &m_ArrayOfTx[3]);//退出面板,是按钮按下
- D3DXCreateTextureFromFileEx(m_pD3DDevice, "./res/exit_buttonN_up.jpg", 0, 0, 0, 0,
- D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT,
- D3DX_DEFAULT, D3DCOLOR_XRGB(0,0,0), NULL, NULL, &m_ArrayOfTx[4]);//退出面板,否按钮弹起
- D3DXCreateTextureFromFileEx(m_pD3DDevice, "./res/exit_buttonN_down.jpg", 0, 0, 0, 0,
- D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT,
- D3DX_DEFAULT, D3DCOLOR_XRGB(0,0,0), NULL, NULL, &m_ArrayOfTx[5]);//退出面板,否按钮按下
- return S_OK;
- }
- void CPanel::Translate(int x,int y)
- {
- D3DXMATRIX matMove;
- D3DXMatrixTranslation(&matMove, (float)x, -(float)y, 0.0f);
- m_pD3DDevice->SetTransform(D3DTS_WORLD, &matMove);
- }
- void CPanel::RenderPanel()
- {
- m_pD3DDevice->SetStreamSource(0,m_pIconBuffer,0,sizeof(VERTEX));
- m_pD3DDevice->SetFVF(PANEL_D3DFVF_VERTEXBUFFER);
- int k=0;int j=0;
- for(int i=0; i<NIcon;i++)
- {
- if(CallPress[i]==true)
- {
- if(ButtonPress[i]==false)
- {
- m_pD3DDevice->SetTexture(0,m_ArrayOfTx[k]);
- //m_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
- m_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1,D3DTA_TEXTURE);
- //m_pD3DDevice->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_DISABLE);
- m_pD3DDevice->SetTexture(1,m_ArrayOfTx[k+1]);//m_ArrayOfTx[k+1]
- //m_pD3DDevice->SetTextureStageState(1,D3DTSS_COLOROP,D3DTOP_SELECTARG1);
- m_pD3DDevice->SetTextureStageState(1, D3DTSS_COLORARG1,D3DTA_CURRENT);
- //m_pD3DDevice->SetTextureStageState(1,D3DTSS_ALPHAOP,D3DTOP_DISABLE);
- }
- else
- {
- m_pD3DDevice->SetTexture(0,m_ArrayOfTx[k+1]);//m_ArrayOfTx[k+1]
- //m_pD3DDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_SELECTARG1);
- m_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1,D3DTA_TEXTURE);
- //m_pD3DDevice->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_DISABLE);
- m_pD3DDevice->SetTexture(1,m_ArrayOfTx[k]);
- //m_pD3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
- m_pD3DDevice->SetTextureStageState(1, D3DTSS_COLORARG1,D3DTA_CURRENT);
- //m_pD3DDevice->SetTextureStageState(1,D3DTSS_ALPHAOP,D3DTOP_DISABLE);
- }
- m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,j,2);
- }
- k+=2;
- j+=4;
- }
- m_pD3DDevice->SetStreamSource(0,m_pBuffer,0,sizeof(VERTEX));
- m_pD3DDevice->SetFVF(PANEL_D3DFVF_VERTEXBUFFER);
- m_pD3DDevice->SetTexture(0,m_pTexture_1);
- m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,4,2);
- }
- POSS CPanel::Calculate(RECT rect)
- {
- POSS a;
- a.ltx=rect.left; a.lty=rect.top; a.rtx=rect.left+rect.right; a.rty=rect.top;
- a.lbx=rect.left; a.lby=rect.top-rect.bottom; a.rbx=rect.left+rect.right; a.rby=rect.top-rect.bottom;
- return a;
- }
- void CPanel::Render()
- {
- m_pD3DDevice->SetStreamSource(0,m_pBuffer,0,sizeof(VERTEX));
- m_pD3DDevice->SetFVF(PANEL_D3DFVF_VERTEXBUFFER);
- m_pD3DDevice->SetTexture(0,m_pTexture);
- //m_pD3DDevice->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_MODULATE);
- m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
- }