discrete cursor

Hi !!!
I need to write a cursor (default ?), which moves only on specified grid
(i.e discrete mouse move I guess).
How should I implement it ?
Is there are any examples around ?

Thanks.
mab11Asked:
Who is Participating?
 
migelConnect With a Mentor Commented:
hm
may by storing previous cursor position and calculating offset SUM will be help
for example:
OnMouseMove()
{
POINT pt
// POINT m_ptCurrPos = member of the class
// SIZE m_szOffset = current offset;

::GetCursorPos(&pt);
ScreenToClient(&pt);

m_szOffset.cx += pt.x - m_ptCurrPos.x;
m_szOffset.cy += pt.y - m_ptCurrPos.y;
m_ptCurrPos.y +=m_szOffset.cy;
m_ptCurrPos.x +=m_szOffset.cx;

if (abs(m_szOffset.cx) > xGridStep)
m_szOffset.cx = 0
if (abs(m_szOffset.cy) > yGridStep)
m_szOffset.cy = 0

// snap to grid:
m_ptCurrPos.x = (int)(xGridStep*floor((float)m_ptCurrPos.x/xGridStep+0.5));
m_ptCurrPos.y = (int)(yGridStep*floor((float)m_ptCurrPos.y/yGridStep+0.5));
SetCursorPos(m_ptCurrPos.x, m_ptCurrPos.y);
}
0
 
DeckmeisterCommented:
Hi,

I don't really understand what you
want to do.

The cursor's position on the screen
is discrete.
For instance, if you overload the
function OnMouseMove(), you will
see that there is a parameter of type
CPoint that is discrete.
0
 
migelCommented:
Hi!
you can handle OnMouseMove
catch cursor pos, align point to the desired position and call SetCursorPos
for example:
void CMyWnd::OnMouseMove(UINT uFlags, CPoint ptMouse)
{
POINT pt
::GetCursorPos(&pt);
ScreenToClient(&pt);
// snap to grid:
pt.x = (int)(xGridStep*floor((float)pt.x/xGridStep+0.5));
pt.y = (int)(yGridStep*floor((float)pt.y/yGridStep+0.5));
SetCursorPos(pt.x, pt.y);
}
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
migelCommented:
oops add
ClientToScreen(&pt);
before SetCursorPos...
0
 
mab11Author Commented:
I tried writing OnMouseMove, but I am getting very strange behaivior on the cursor part, it is dragging around a position and it's very hard to change it's postion.

Is there a way that I can leave default cursor alone and add one more which jumps on grid ?


0
 
DeckmeisterCommented:
Two cursors ???

Well, you can overload OnMouseMove()
for a specific control and leave it
as it is for the other controls
(including the main window).
0
 
mab11Author Commented:
I wrote overloading of mousemove with setcursorpos() , but somehow it's very difficult to move between neighbouring points, if I try to change position a little bit
it keepes dragging around current one, even though I made significant change with my hand.
Anybody knows why this is hapenning ?

Thanks
0
 
mab11Author Commented:
Precisly after I do SetCursorPos and check next mouse coordinates in WM_MOUSEMOVE - it stops being continious.
I think SetCursorPos influences it.
Anyway around this problem, i.e.
mouse coordinates in lParam being continiuos but Cursor positions not ?










0
 
mab11Author Commented:
Unfoirtunately it doesn't resolve mouse coordinates problem.
As soon as I introduce SetCursorPos,
what happenes is that mouse coordinates I am priniting are all at that cursor pos even though I am moving mouse.
In the description of SetCursorPos it doesn't say anything about mouse.
Any ideas ?

Thanks
0
All Courses

From novice to tech pro — start learning today.