nanogui: I don't understand GdMoveCursor()
Subject:
I don't understand GdMoveCursor()
From:
Wayne ####@####.####
Date:
18 Jan 2008 19:48:40 -0000
Message-Id: <47910276.4000909@zk.com>
I am working on an application that emulates mouse support by moving
moving the mouse when cursor keys are pressed. Currently the application
is running on top of the MWin library. I am having a problem with the
cursor movement. If I move the cursor during the WM_KEY_DOWN callback
everything _seems_ to work fine. If I move the cursor in the WM_KEY_UP
message the cursor position does not get updated until another key is
pressed. I have been trying to chase this down. What I think happens:
* MwMoveCursor() updates the MWin variables cursorx and cursory with the
new cursor position and calls GdMoveCursor().
* GdMoveCursor() updates the current min and max for the cursor (this
confuses me) then erases the cursor and redraws it.
Since the cursor position vars are not updated in GdMoveCursor the
cursor gets draw in the exactly the same location.
* The next key event (either up or down or maybe only up) triggers some
chain of events that I have not been able to figure out ends up calling
GdMoveMouse(), I think, and at that point the mouse cursors position
actually gets updated.
I am currently looking at GdMoveCursor() and it doesn't look right to me:
void
GdMoveCursor(MWCOORD newx, MWCOORD newy)
{
MWCOORD shiftx;
MWCOORD shifty;
shiftx = newx - curminx;
shifty = newy - curminy;
if(shiftx == 0 && shifty == 0)
return;
curminx += shiftx;
curmaxx += shiftx;
curminy += shifty;
curmaxy += shifty;
/* Restore the screen under the mouse pointer*/
GdHideCursor(&scrdev);
/* Draw the new pointer*/
GdShowCursor(&scrdev);
}
Why does this function change the current x/y min and max? Shouldn't it
instead compare the new x/y with their respective mins and maxes and
either clip or reject a value outside the range? Also, shouldn't it
update the cursor global cursor position after it has erased the current
cursor -- GdHideCursor() -- and before redrawing it -- GdShowCursor(). I
tried calling GdMoveMouse() in MwMoveMouse() instead of GdMoveCursor and
that does not work. I don't remember exactly what happens. However, I
have found that if I add a call to GeMoveMouse() in GdMoveCursor() all
appears to work correctly.
Initially I had placed the call before GdHideCursor() but as I was
writing this mail I decided that I think it should go between the
GdHideCursor() and GdShowCursor() calls.
Is this correct or I not understand something?
Thanks,
Wayne J.