Re: ClipCursor trouble after window is resized
- From: "Steve Russell" <srussell@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 19 Nov 2006 10:21:00 -0500
Here is fuller version of my code. I very much appreciate assistance!
// a class gets the client coordinates of a sprite rectangle
// and then passes its centerpoint to SetMoveToward
// as the destination for the cursor demo
m_pCurrentSprite = pSourceSprite;
CRect rect;
pSourceSprite->GetRect(&rect);
m_pView->SetMoveCursorToward(rect.CenterPoint() );
// set up to move cursor toward a point
void CTestView::SetMoveCursorToward(CPoint point)
{
m_ptMoveCursorToward.x = point.x;
m_ptMoveCursorToward.y = point.y;
// ::GetCursorPos(&m_ptMoveCursorFrom);
// ClientToScreen(&m_ptMoveCursorFrom);
// SetCursorPos(m_ptMoveCursorFrom.x,m_ptMoveCursorFrom.y);
m_bCursorCouldBeMovingToward = true;
m_nMoveCursorTowardCounter = 0;
SetTimer(Timer_MoveCursorToward,0,NULL);
}
// move cursor toward a point
void CTestView::MoveCursorToward()
{
CPoint point;
::GetCursorPos(&point);
m_nMoveCursorTowardCounter++;
m_nMoveCursorTowardDivisor = 40;
int nDivisor = m_nMoveCursorTowardDivisor;
CPoint ptMoveTo;
int nTotalDistanceX = abs( m_ptMoveCursorToward.x - m_ptMoveCursorFrom.x);
int nTotalDistanceY = abs( m_ptMoveCursorToward.y - m_ptMoveCursorFrom.y);
float fLegX = (float)nTotalDistanceX / nDivisor;
// get the integer portion of leg
int nLegXInteger = fLegX;
// get the decimal portion of leg
float fLegXRemainder = fLegX - nLegXInteger;
// now get the cumulative integer and decimal distance
// according to the number of moves thus far
int nCumulativeMoveDistanceX = (nLegXInteger + fLegXRemainder) *
m_nMoveCursorTowardCounter;
if(point.x < m_ptMoveCursorToward.x)
if(m_ptMoveCursorFrom.x + nCumulativeMoveDistanceX <
m_ptMoveCursorToward.x)
ptMoveTo.x = m_ptMoveCursorFrom.x + nCumulativeMoveDistanceX;
else
ptMoveTo.x = m_ptMoveCursorToward.x;
else
if(m_ptMoveCursorFrom.x - nCumulativeMoveDistanceX >
m_ptMoveCursorToward.x)
ptMoveTo.x = m_ptMoveCursorFrom.x - nCumulativeMoveDistanceX;
else
ptMoveTo.x = m_ptMoveCursorToward.x;
float fLegY = (float)nTotalDistanceY / nDivisor;
// get the integer portion of leg
int nLegYInteger = fLegY;
// get the decimal portion of leg
float fLegYRemainder = fLegY - nLegYInteger;
// now get the cumulative integer and decimal distance
// according to the number of moves thus far
int nCumulativeMoveDistanceY = (nLegYInteger + fLegYRemainder) *
m_nMoveCursorTowardCounter;
if(point.y < m_ptMoveCursorToward.y)
if(m_ptMoveCursorFrom.y + nCumulativeMoveDistanceY <
m_ptMoveCursorToward.y)
ptMoveTo.y = m_ptMoveCursorFrom.y + nCumulativeMoveDistanceY;
else
ptMoveTo.y = m_ptMoveCursorToward.y;
else
if(m_ptMoveCursorFrom.y - nCumulativeMoveDistanceY >
m_ptMoveCursorToward.y)
ptMoveTo.y = m_ptMoveCursorFrom.y - nCumulativeMoveDistanceY;
else
ptMoveTo.y = m_ptMoveCursorToward.y;
::SetCursorPos(ptMoveTo.x, ptMoveTo.y);
CRect rectCursor(ptMoveTo.x, ptMoveTo.y, ptMoveTo.x + 1, ptMoveTo.y + 1);
ClipCursorTo(&rectCursor);
////////////////////////////////////
// if cursor has arrived, kill timer
////////////////////////////////////
if(point.x == m_ptMoveCursorToward.x && point.y == m_ptMoveCursorToward.y)
{
KillTimer(Timer_MoveCursorToward);
m_bCursorHasDemoed = true;
}
}
----------------------
"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:a5nvl2l09pq5tn3cbnkk26epki51l7hgjj@xxxxxxxxxx
Not enough information here. Is CPoint in screen or client coordinates?
On Sat, 18 Nov 2006 19:54:06 -0500, "Steve Russell"
<srussell@xxxxxxxxxxxxxxxxxxxxxx>
wrote:
Thanks, Joe. Here is where I think the trouble first shows up. I have****
spent all day trying to understand and solve it, including various uses of
ScreenToClient etc that I have read in various literature, particularly
after your comments.
void CTestView::SetMoveCursorToward(CPoint point)
{
m_ptMoveCursorToward.x = point.x;
m_ptMoveCursorToward.y = point.y;
What's wrong with writing
m_ptMoveCursorToward = point;
?
I don't see the role this plays. A spec of expected behavior would help.
How is 'point'
computed, and what relationship does it have to the current cursor
position? And since I
don't actually see a SetClipCursor call anywhere here, it is hard to guess
what is
intended.
****
*****
::GetCursorPos(&m_ptMoveCursorFrom);
m_bCursorCouldBeMovingToward = true;
m_nMoveCursorTowardCounter = 0;
SetTimer(Timer_MoveCursorToward,0,NULL);
Since the role of these variables is not defined, and the role of the
timer is not
specified, and the timer handler code is not shownt is hard to guess what
any of this code
is attempting to do.
****
}Joseph M. Newcomer [MVP]
--------
"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:id3vl2pjg1eeed3o670fvk20il8ma03u05@xxxxxxxxxx
Show the code. Note that you must use screen coordinates, which means
you
must recompute
the cursor position any time the window is moved or resized.
joe
On Sat, 18 Nov 2006 17:03:47 -0500, "Steve Russell"
<srussell@xxxxxxxxxxxxxxxxxxxxxx>
wrote:
I should add that in the resized window, when I run a test withJoseph M. Newcomer [MVP]
GetCursorPos
and then create a small color filled rectangle centered on those
coordinates, the rectangle is accurate, but my cursor is in a different
position. The smaller the window, the greater the divergence.
-------------
"Steve Russell" <srussell@xxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:%23%231Ujo1CHHA.4928@xxxxxxxxxxxxxxxxxxxxxxx
I am unable to use ClipCursor accurately when I resize my window.
Maximized is the only state in which I get perfect results. Is there
something I should know about the relationship between ClipCursor and
resizing a window?
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- Re: ClipCursor trouble after window is resized
- From: Steve Russell
- Re: ClipCursor trouble after window is resized
- References:
- ClipCursor trouble
- From: Steve Russell
- Re: ClipCursor trouble
- From: Steve Russell
- Re: ClipCursor trouble
- From: Joseph M . Newcomer
- Re: ClipCursor trouble
- From: Steve Russell
- Re: ClipCursor trouble
- From: Joseph M . Newcomer
- ClipCursor trouble
- Prev by Date: Re: Convert CString To char[]
- Next by Date: Re: Drawing on DC
- Previous by thread: Re: ClipCursor trouble
- Next by thread: Re: ClipCursor trouble after window is resized
- Index(es):
Relevant Pages
|