Re: Mouse position

Jason Morales <[email protected]> Tue, 18 Oct 2005 05:12:00 -0700
Newsgroups gmane.games.devel.windows
Message-ID <[email protected]>
Check out GetClientRect() and AdjustWindowRect as well, those should 
give you all the info you need.

Here is how we get the mouse position in our game:

CRecti CSystem::GetWindowArea()
{
RECT full, client;
int clientw, clienth;
int style;

if (Vid.IsFullScreen())
style = WS_POPUP | WS_MAXIMIZE;
else
style = WS_CAPTION | WS_MINIMIZEBOX | WS_VISIBLE;

GetClientRect((HWND)m_WindowHandle, &client);
clientw = client.right;
clienth = client.bottom;
AdjustWindowRect(&client, style, false);
GetWindowRect((HWND)m_WindowHandle, &full);

return CRecti(full.left - client.left,
full.top - client.top,
full.left - client.left + clientw,
full.top - client.top + clienth);
}


CVec2i CSystem::GetMousePos()
{
CRecti winrec = GetWindowArea();
POINT p;
::GetCursorPos(&p);
return CVec2i(p.x - winrec.left, p.y - winrec.top);
}


Diogo de Andrade wrote:

> Hey all…
>
> I’m having a small problem getting the coordinate of the mouse in the 
> window… My current system gets the coordinate like this:
>
> POINT pt;
>
> GetCursorPos(&pt);
>
> Then I want to transform this coordinate (in absolute screen 
> coordinates, as I see it) to my engine's coordinates (which has 
> logical coordinates, to account for different resolutions, bitmap 
> scaling, etc)...
>
> I get the window rectangle (also in screen coordinates):
>
> RECT rect;
>
> GetWindowRect(m_window,&rect);
>
> Finally, I do the conversion itself
>
> float sx=rect.right-rect.left;
>
> float sy=rect.bottom-rect.top;
>
> float relative_x=virtual_res_x*(pt.x-rect.left)/sx;
>
> float relative_y=virtual_res_y*(pt.y-rect.top)/sy;
>
> This works almost perfectly, except when I approach the cursor from 
> the top of the window... The window has the standard bar (created with 
> WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | 
> WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE | WS_POPUPWINDOW), and 
> apparently GetWindowRect gets the whole window, including the top bar, 
> instead of getting only the "drawable" part of it... I imagine the 
> problem is that m_window above is a parent window with 2 children (the 
> system bar, and the drawable part), but I can't find how to get just 
> the drawable rectangle to do the conversion... This works fine if I 
> create the window without border of title/system bar... So, my 
> question is: how do I get the drawable part of the window's rectangle?
>
> Thanks in advance!
>
> Diogo de Andrade
>
> Creative & Technical Director
>
> Spellcaster Studios
>
> [email protected]
>
> www.spellcasterstudios.com
>



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Gamedevlists-windows mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_idU5