UI Interaction Problem

Started by
6 comments, last by Sixten 18 years, 3 months ago
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 ????
Advertisement
Hi again!

May i ask you how you finnaly decided how to implement your UI?

I've look at your code, and i think you miss a ClientToScreen(LPPOINT) or the inverse ScreenToClient(LPPOINT) to convert the mouse coordinate to your ClientWnd...

Jonathan
Well i played around a little with giving the RGB value when i renderd the text box and i came out with a pritty nice result after calling about 3 DrawSpirit with diffrent sizes and colores on the Texture.. giving it a fake 3d look.. The outer edges are Light.. and then a secound line inside that is a little darker and then the actual text area is darker.. and that gave a pritty nice 3d effect.. it needs a little more work.. but it will do for now tho..

So all the user dose is give the filename for the Texture and the engine dose the rest :D
Hmm that didnt fix the problem.. it feels like one pixel for the mouse is more then one pixel on the form... i know the buttons rect is (10, 10, 100, 100) and when i click at the edge of the button the mouse gives me the x, y 90, 90...
PS. its just an exampel

So i dont really know what the problem is.. maybe its the rendering that dosent render the button at its full size ?? Or something like that .. Maybe it makes it smaller or something and its not the mouse that is giving the wrong x, y, and its the button that is the wrong size ???

I dont know..
Humm... are you using it in a Form? or fullscreen?

Because i know that sometime if you are not handling the form resize correctly (releasing, recreating the viewport) DX will strech the Backbuffer to fit the FrontBuffer...

Just Maybe..
Nice.. u where right. when i do it in fullscreen it works.. but how do i get it to work in Window mode.. The window i make is the same size as the backbuffer.. and so on.. why dosent it work in window mode ??????
Good :D

For what i know, i'm using SwapChains since i'm doing a WorldEditor (4 differents view of the same scene in 4 different CWnd). What i need to do, for my part, is simply release all my swapchain and recreate them (Resource are attached to the device, so i dont need to recreate them).

If your using the implicit device swapchain, the one created when you create the device, i think this mean you need to recreate it, like when handling a device reset. (I'm not sure, so maybe the opinion of someone else would be helpfull)

Maybe this link will be usefull for you: http://www.mvps.org/directx/articles/rendering_to_multiple_windows.htm

Also, maybe reading the the MSDN on Device Lost might be usefull: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/IDirect3DDevice9.asp

Good Luck,
Jonathan
Thx... i will take a look in to this :D
Thx for all the ideas and pointer :D

Cya later :D

This topic is closed to new replies.

Advertisement