bool cTexture::draw ( long p_destX, long p_destY, long p_srcX /*= 0*/, long p_srcY /*= 0*/, long p_width /*= 0*/, long p_height /*= 0*/, D3DCOLOR p_color /*= 0xffffffff*/, D3DXVECTOR2 *p_pRotationCenter /*= NULL*/, float p_angle /*= 0.0f*/, float p_XScale /*= 1.0f*/, float p_YScale /*= 1.0f*/ ) { RECT rect; ID3DXSprite *pSprite; if(m_pTexture == NULL) return FALSE; if(m_pGraphics == NULL) return FALSE; if((pSprite = m_pGraphics->getSprite()) == NULL) return FALSE; if(!p_width) p_width = m_width; if(!p_height) p_height = m_height; rect.left = p_srcX; rect.top = p_srcY; rect.right = rect.left + p_width; rect.bottom = rect.top + p_height; //D3DXVECTOR3 Center = D3DXVECTOR3(10, 10, 1); // 材质的矩形区域的中心点 D3DXVECTOR3 Position = D3DXVECTOR3((float)p_destX, (float)p_destY, 0); // 画的位置 pSprite->Begin(D3DXSPRITE_ALPHABLEND); D3DXVECTOR2 Scaling(p_XScale, p_YScale); // 縮放比例 /*D3DXVECTOR2 RotationCenter( p_destX + p_width / 2, p_destY + p_height / 2 );*/ D3DXMATRIX Matrix; // 坐标转换矩阵 D3DXVECTOR2 d3dx_vector2((float)p_destX, (float)p_destY); D3DXMatrixTransformation2D(&Matrix, &d3dx_vector2, 0.0, &Scaling, p_pRotationCenter, p_angle, 0 ); pSprite->SetTransform(&Matrix); pSprite->Draw( m_pTexture, &rect, NULL, &Position, p_color); pSprite->End(); return true; }
void nekoGUISelectionButtons::Draw() { if(mButtons.empty()) return; nekoVideoDriver *videoDrv = GetNekoNovel()->GetVideoDriver(); ID3DXSprite *sprite = videoDrv->GetSprite(); uint32 color = GetNekoNovel()->GetCurrentGame()->GetEnvironment().mSelectionColor; list<nekoOneButton *>::iterator iter = mButtons.begin(); int32 a; int32 i = 0; D3DXMATRIX matIdentity; D3DXMatrixIdentity(&matIdentity); matIdentity *= videoDrv->GetBaseMatrix(); for(;iter != mButtons.end();++iter, ++i) { if(mSelectedIndex == i) a = mButtonState; else a = 0; if(!(*iter)->mImage[a]) continue; videoDrv->DrawImage((*iter)->mImage[a], (*iter)->rect.left, (*iter)->rect.top, -1, -1, 0xffffffff, 0, 0, -1, -1, 0, 1, 1, 0.46f); sprite->SetTransform(&matIdentity); nekoPoint center = (*iter)->rect.GetCenter(); RECT rect = {center.x - (*iter)->mTextSize.x / 2, center.y - (*iter)->mTextSize.y / 2, 0, 0}; (*iter)->mFont->DrawText(sprite, (*iter)->mCaption.c_str(), -1, &rect, DT_NOCLIP, color); } }