Right now I build for both PC and PPC. Of course there is different behaviour with the stylus event handling functions.
On PC, it is possible to receive StylusMove events when the stylus (mouse) is not down. Am I correct in assuming that this is impossible on the PPC?
I like to keep track of whether the stylus is down or not. It just adjust a state variable in StylusDown and StylusUp.
However, on the PC build, it is possible to mouse down in the window, then move the mouse outside the window and release the mouse. So, the application does not receive a StylusUp event, and its state is incorrect.
How should I deal with this issue? Should I handle events for window exit and enter? Where should I be doing this in a GapiDraw application (that also runs in windowed mode on PC)?
On PC, it is possible to receive StylusMove events when the stylus (mouse) is not down. Am I correct in assuming that this is impossible on the PPC?
That's correct. There are no move events unless the stylus is down.
I like to keep track of whether the stylus is down or not. It just adjust a state variable in StylusDown and StylusUp.
That's exactly what I do since I occasionally need to know the state of the stylus outside of the stylus event handlers.
However, on the PC build, it is possible to mouse down in the window, then move the mouse outside the window and release the mouse. So, the application does not receive a StylusUp event, and its state is incorrect. How should I deal with this issue?
You
could simply check if there is another sytlus down event while your flag says the stylus is already in the down position. Since you should never have two down events in sequence, you can presume there was an up event that was missed.
True. But it still leaves problems.
On the PC build I have a fancy toolbar that works just like in Visual Studio 6. When you move the mouse over the buttons, they pop out with a rollover effect. This is without pressing the mouse button.
So, if I move outside the toolbar, they all go back to normal. But if I move off the toolbar outside the window, that button retains its rollover effect which is unaesthetic. Normally I would just handle this on window exit, but I'm unsure where to do that in GapiDraw.
I suppose a brutish hack would be to try to detect a mouse leaving the window. But you can always move the mouse really quickly and defeat that attempt.
When I move the mouse back in the window, not on the toolbar, the rollover effect disappears because I'm not on the toolbar.
But let's say instead of a toolbar rollover effect, I was instead dragging something. Normally I would stop draggin on mouse up, but in this case I have left the window without a mouse up event.
Now, I could let go of the mouse button and reenter the window at any place. My app still thinks it is dragging the object, but now there is a dire consequence. The object I was dragging will snap to whatever position I reentered the window, which is startling and not intended.
Are these little problems we just have to live with when using GapiDraw on the PC in windowed mode? I know they sound like insignificant details, but these little things always bother me. That's why I gave the Tower Mogul folks such a hard time on doing button actions on mouse down when they should be on mouse up. :-)
How about simply checking the stylus location to see if it is out of bounds of your window size?
When the mouse leaves the window you no longer receive mouse events at all.
mlepage: Is it really a big deal if the user presses the button and then moves out from the window? I think most users when they enter again noticed the issue and simply clicks away..
Why not use fullscreen mode on the PC by the way? That way you get HW acceleration and can use higher resolutions (given that the new Toshiba will have a 640x480 display
http://forums.pdabuzz.net/showthread.ph ... adid=48194 I think many games soon will support 640x480 on their desktop versions)...
Johan wrote:
Is it really a big deal if the user presses the button and then moves out from the window?
In the case of animated buttons, the button could be left in the incorrect state. In the case of Warlords, I base alot of operations on what state my GUI buttons are in (ie up, down, disabled, hidden).
Oh, I'm using windowed mode for a few reasons.
First of all, for developing and testing I run on the PC at 240x320, just like the PPC.
I don't make the screen bigger, because my game is fairly tailored to that resolution. At least, the levels and everything will be.
I'm not looking to have an actual PC version, that would run with a larger window (or fullscreen) and also have larger levels. Although there's no reason I couldn't do that, I just don't have plans for doing so for this game.
The one reason to run the PC version larger, is for editing levels. My game has a builtin editor which therefore runs on both the PC and PPC. On the PC it might be nicer to use a larger screen for editing. However, I would still want to see what it looks like with a smaller area, since that's where the game will mostly be played.
So I anticipate shipping a PPC game with a builtin level editor, and providing the PC version as a bonus. (Aren't I nice?) Since play is awkward with the mouse, the value of the PC version is predominantly in using the level editor, likely with a larger area.
Also, since the stylus resolution is limited to 2 pixels on the PPC, you can make slightly finer grained levels on the PC (in terms of where you place things). (I will be adding a way to deal with this on the PPC.)
I am leaning towards making it an option to run with a larger window, or full screen, on the PC. I might look at hijacking the window proc to handle window exit/enter events, but if I don't get around to it, people will have to just deal with the buttons being weird. :-)
Quick note:
Look a GetCapture(), SetCapture() and ReleaseCapture() in the win32 API. When you SetCapture() when you press a mouse button you wil get the mouse up event even if the mouse is outside your window. Off course call ReleaseCapture() when done.
Maurice
Indeed - mouse capture is your friend. I use it in my (hobby) game it and it works like a charm. That's the standard way of implementing things like toolbars and buttons that eat all of the events on mouse-down and don't give up until the mouse is released.
Make sure you catch the WM_CANCELMODE event, which is sent if something else steals capture. It's poorly documented and often overlooked.
Would this be something that should be added to GapiApplication? Does it affect performance in any way? If not on stationary PCs, does it on Pocket PCs?
Is it possible to release the stylus before it is out of the application on a PPC? I don't think so, since it is always fullscreen. On the desktop it can be usefull, but only in windowmode and I don't think it will downgrade performance.
Maurice
Here's what I'm using:
- Code:
//----------------------------------------------------------------------
HRESULT CMyApplication::StylusDown(POINT p)
//----------------------------------------------------------------------
{
g_fMouseDown = true;
g_lastPoint = p;
#ifndef _WIN32_WCE
::SetCapture( m_hwnd );
#endif
return SendEvent( GIID_MOUSE_DOWN, GIINPUTDATA( p ) );
}
//----------------------------------------------------------------------
HRESULT CMyApplication::StylusUp(POINT p)
//----------------------------------------------------------------------
{
g_fMouseDown = false;
#ifndef _WIN32_WCE
if( ::GetCapture() == m_hwnd )
::ReleaseCapture();
#endif
return SendEvent( GIID_MOUSE_UP, GIINPUTDATA( p ) );
}
(The SendEvent goes into my event delegation mechanism, you can ignore that.)
The only thing to watch out for is that on a windowed app you'll suddenly start getting negative mouse coordinates, or mouse coordinates beyond the window bounds. GapiApplication was already updated to use GET_X_LPARAM so apps will receive correct values (previously you got large positive values instead) , but they may still be unexpected by some apps.
Re: Perf - I doubt there is a noticeable impact, but I've never profiled and compared.
InexorableTash: Thanks! I'll add the code in the next GapiApplication 2.10... Um.. By the way.. Where do you capture the WM_CANCELMODE event?
Yes it would be great if this sort of thing can be added to GapiApplication.
Maybe I need to dust off my Richter and Petzhold books, to get back into this Win32 programming thing. :-)
Normally, I stay away from specifics like that, and use C APIs, toolkits like GapiDraw, etc.
I was wondering if anyone would notice that. :)
WM_CANCELMODE isn't necessary in this particular implementation since there's nothing in my code tracking whether or not the mouse is captured, or whether or not there's been a StylusUp event.
If you had a m_bMouseIsCaptured flag and wanted to keep it up to date then you'd want to catch that message in the window proc and update the state. If you tracking the stylus up/down state you'd also need to clear it on loss of capture.
BTW, to test that everything is working, do a mouse-down (which should capture the mouse) then Alt+Tab to another app. Your app should no longer have focus, and you should verify that your capture code is aware of this state change.
FYI, you can also watch for WM_CAPTURECHANGED which is sent when a window looses capture. In hindsight, that's probably the message I should have recommended. WM_CANCELMODE is sent in a few other places as well, so for minimal impact, use WM_CAPTURECHANGED