Hiya..
I am designing my UI with DX Draw Spirit.. All work well it renders the buttons at the right places and the textures are there and everything..
But when i try the mouse interacation i found a problem..
Everything works fine if the buttons and text boxes are positiones at the top of the screen but when i move them down more.. the x, y dosent seem to fit with the x, y i get from the mouse..
When i try to click my button i have to move the mouse in to the middel of the button for it to work and it works then the height of the button downwards from the middel (The click area goes down past the buttons edge at the bottom) and the more i move the control down the futher down i have to move the mouse past the begining of the control
Here u can see the code i use to render the button "Verry sloppy code in development"
void DXButton::Render()
{
int nOffsetX = 0;
int nOffsetY = 0;
D3DSURFACE_DESC Desc;
D3DXMATRIXA16 matTransform;
RECT rcScreen = m_rcBoundingBox; // The button RECT placement
RECT rcTexture;
DXUT_CONTROL_STATE iState = DXUT_STATE_NORMAL;
if( m_bVisible == false )
{
iState = DXUT_STATE_HIDDEN;
}
else if( m_bEnabled == false )
{
iState = DXUT_STATE_DISABLED;
}
else if( Clicked )
{
iState = DXUT_STATE_PRESSED;
nOffsetX = 1;
nOffsetY = 2;
}
float fBlendRate = ( iState == DXUT_STATE_PRESSED ) ? 0.0f : 0.8f;
OffsetRect( &rcScreen, nOffsetX, nOffsetY );
this->Tex->GetLevelDesc(0, &Desc);
SetRect( &rcTexture, 0, 0, Desc.Width, Desc.Height);
POINT pt;
m_Frame->GetLocation(pt);
OffsetRect( &rcScreen, pt.x, pt.y ); // The frame that the control is positioned in x, and y
float fScaleX = (float) RectWidth( rcScreen ) / RectWidth( rcTexture );
float fScaleY = (float) RectHeight( rcScreen ) / RectHeight( rcTexture );
D3DXMatrixScaling( &matTransform, fScaleX, fScaleY, 1.0f );
m_Frame->FrameSprite->SetTransform( &matTransform );
D3DXVECTOR3 vPos( (float)rcScreen.left, (float)rcScreen.top, 0.01f );
vPos.x /= fScaleX;
vPos.y /= fScaleY;
TextureColor.Blend( iState, 1, fBlendRate );
FTextureColor.Blend( iState, 1, fBlendRate );
m_Frame->FrameSprite->Draw( this->Tex, &rcTexture, NULL, &vPos, TextureColor.Current );
m_Frame->FrameSprite->Draw( this->Tex, &rcTexture, NULL, &vPos, FTextureColor.Current );
D3DXMatrixIdentity( &matTransform );
m_Frame->FrameSprite->SetTransform( &matTransform );
DXFont->DrawText( m_Frame->FrameSprite, Text, -1, &rcScreen, DT_CENTER|DT_VCENTER, FontColor );
}
AS u can see i have copied alot of code from the SDK.. But it dosent seem to work anyways ???
The checking if the mouse is over the control code
bool Frame::MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch( uMsg )
{
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
{
POINT mousePoint = { short(LOWORD(lParam)) - m_x, short(HIWORD(lParam)) - m_y };
DXControl* pControl = GetControlAtPoint(mousePoint);
if(!pControl == NULL && pControl->GetEnabled() == true && pControl->GetVisible() == true)
{
if(!GetFocusControl() == NULL && GetFocusControl() != pControl)
{
DXControl* mControl = GetFocusControl();
mControl->SetFocus(false);
pControl->SetFocus(true);
SetFocusControl(pControl);
}
else
{
pControl->SetFocus(true);
SetFocusControl(pControl);
}
pControl->HandleMouse(uMsg, mousePoint, wParam, lParam);
return true;
}
}
case WM_CHAR:
DXControl* mControl = GetFocusControl();
if(mControl != NULL)
mControl->HandleKeyboard(uMsg, wParam, lParam );
}
return false;
}
If u need anything else i wil post it..
Anyone got anyidees what i am doing wrong ????