Re: [GD-Windows] Mouse position
Brought to you by:
vexxed72
From: Jason M. <ja...@s2...> - 2005-10-18 12:06:20
|
Check out GetClientRect() and AdjustWindowRect as well, those should=20 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 =3D WS_POPUP | WS_MAXIMIZE; else style =3D WS_CAPTION | WS_MINIMIZEBOX | WS_VISIBLE; GetClientRect((HWND)m_WindowHandle, &client); clientw =3D client.right; clienth =3D 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 =3D GetWindowArea(); POINT p; ::GetCursorPos(&p); return CVec2i(p.x - winrec.left, p.y - winrec.top); } Diogo de Andrade wrote: > Hey all=85 > > I=92m having a small problem getting the coordinate of the mouse in the= =20 > window=85 My current system gets the coordinate like this: > > POINT pt; > > GetCursorPos(&pt); > > Then I want to transform this coordinate (in absolute screen=20 > coordinates, as I see it) to my engine's coordinates (which has=20 > logical coordinates, to account for different resolutions, bitmap=20 > 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=3Drect.right-rect.left; > > float sy=3Drect.bottom-rect.top; > > float relative_x=3Dvirtual_res_x*(pt.x-rect.left)/sx; > > float relative_y=3Dvirtual_res_y*(pt.y-rect.top)/sy; > > This works almost perfectly, except when I approach the cursor from=20 > the top of the window... The window has the standard bar (created with=20 > WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME |=20 > WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE | WS_POPUPWINDOW), and=20 > apparently GetWindowRect gets the whole window, including the top bar,=20 > instead of getting only the "drawable" part of it... I imagine the=20 > problem is that m_window above is a parent window with 2 children (the=20 > system bar, and the drawable part), but I can't find how to get just=20 > the drawable rectangle to do the conversion... This works fine if I=20 > create the window without border of title/system bar... So, my=20 > 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 > > dio...@sp... > > www.spellcasterstudios.com > |