PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Stylus Move always when Stylus Down?

Is it true that on a PocketPC the StylusMove will always be called (from within CGapiApplication::WindowProc) when the StylusDown is called? :?:

In my app I have placed TraceLog messages in both methods and also in the StylusUp, and I see all three methods being called one after the other, with exactly the same POINT values.

And:
* on my PocketPC the order is: StylusDown, StylusMove, StylusUp
* on my WinXP PC the order is: StylusDown, StylusUp, StylusMove

:idea: On my XP machine this probably is because after the mouse-click (=StylusDown and StylusUp) I move the mouse away from the point where I clicked, so the first StylusMove probably will be from this moving-away mouse-move.

Note: I am using GD 2.05.
Does it really matter in what order they are called? Toggle a flag on stylusdown/up and then catch move if stylus is down. Of course you miss the first move event, but you can use a "previous coord" variable for that and set it on stylus down.
Johan, that's exactly what I am doing.

But that's where/why my problem arise:
Because of the different order in which the stylus events are fired, on my stationary PC I do NOT get a StylusMove: because the StylusUp comes before the StylusMove, the stylus-down-flag has already be reset.

But on my ipaq (2210) the StylusMove directly follows the StylusDown, so the flag is still set and I receive/process a StylusMove (which I do not want if it is only a tap on the screen on one location).

The solution will probably be that I continuously register the coords in the StylusDown and StylusMove and check in the StylusMove if the new coords are really different from the registered ones. Only then I will consider this as a real StylusMove.

But what I don't understand is why a StylusMove is generated in the first place when I just tap on my PPC screen???
What desktop machine are you seeing this problem on? In two years of developing with GapiDraw on a daily basis I've never had an issue with StylusMove being called in the incorrect order. As Johan suggested, the standard method of dealing with the Stylus methods is to set a flag on StylusDown and reset it on StylusUp - any movement would then be recognized in StylusMove.

Can you post a small test app that exhibits this problem? I'd be more than happy to take a look at it.
Centaur: If you use StylusMove for simple "clicks", then I can see the issue you are mentioning. But for clicks you could simply use StylusUp and check the last known coordinate.

The issue you mention is not really an issue - you are simply doing things the wrong way..
Thanx ppcStudios for your kind offer to take a look at my problem.

I'm running WinXP Pro SP1, and develop with Visual Studio.Net 2003 for the PC and with embedded Visual C++ for the PocketPC.

I have just taken the sample app "Minimal" from the GD 2.05 package, added STLogFile.h v3.75 by Nicholas Tsipanov for the Log trace messages, and build a ppc2002 release version for the pocketpc and a release version for the PC.

Code:
HRESULT CMyApplication::StylusDown(POINT p)
{
STLOG_WRITE(_T("Stylus DOWN CMy_Application - x=%i y=%i"), p.x, p.y);
return S_OK;
}

HRESULT CMyApplication::StylusUp(POINT p)
{
STLOG_WRITE(_T("Stylus UP CMy_Application - x=%i y=%i"), p.x, p.y);
return S_OK;
}

HRESULT CMyApplication::StylusMove(POINT p)
{
STLOG_WRITE(_T("Stylus MOVE CMy_Application - x=%i y=%i"), p.x, p.y);
return S_OK;
}


Test result on PC (note: the moves come from real mouse moves):

Code:
22:17:19(10786960258),thr 0x00000844 : Log is started on 11.05.2004, at 22:17:19:328, executable:
g:\pocketpc\gapidraw205\samples\minimal\vsnet\minimalsample\release\MinimalSample.exe (ProcID: 0x000007bc),
compile time : May 11 2004 22:15:00
22:17:19(10786960479),thr 0x00000844 : Stylus MOVE CMy_Application - x=81 y=92
22:17:19(10787444061),thr 0x00000844 : Stylus MOVE CMy_Application - x=81 y=92
22:17:20(10791365057),thr 0x00000844 : Stylus DOWN CMy_Application - x=81 y=92
22:17:20(10792197426),thr 0x00000844 : Stylus UP CMy_Application - x=81 y=92
22:17:21(10796280434),thr 0x00000844 : Stylus MOVE CMy_Application - x=82 y=93


Testresult on my Ipaq 2210: notice the same coords for each down/move/up trio !
Code:
22:05:05(102324542980),thr 0x92E20C26 : Log is started on 11.05.2004, at 22:05:05:000, executable:
\Program Files\MinimalSample\Minimal.exe (ProcID: 0x92efe44a),
compile time : May 11 2004 22:03:19
22:05:05(102324543494),thr 0x92E20C26 : Stylus DOWN CMy_Application - x=119 y=198
22:05:05(102324572533),thr 0x92E20C26 : Stylus MOVE CMy_Application - x=119 y=198
22:05:05(102324573439),thr 0x92E20C26 : Stylus UP CMy_Application - x=119 y=198
22:05:06(102325873827),thr 0x92E20C26 : Stylus DOWN CMy_Application - x=123 y=109
22:05:06(102325939550),thr 0x92E20C26 : Stylus MOVE CMy_Application - x=123 y=109
22:05:06(102325940476),thr 0x92E20C26 : Stylus UP CMy_Application - x=123 y=109


If you want I can sent you the complete projects...
Johan, I am not using and do not want to use StylusMove for simple clicks!

But I feed the Stylus events from the Application class into my sprite-engine and window controls (eg. to show a pressed button as long as the stylus is down), and these unexpected StylusMove event now interfere in my processing.
And I am noticing this only now I am really testing on my PocketPC.

I agree that I probably am overlooking something, but I still do not understand why the StylusMove event is fired when tapping the screen with the stylus... :oops:
Note that on a stationary PC, you will get StylusMove messages whether you click or not. In other words, just moving the mouse around the app's window will result in StylusMove messages. Maybe this is the source of your confusion, at least as far as a stationary PC goes.

I know this because I just took the minimal sample and put MessageBox's in StylusMove, StylusDown and StylusUp. Sure enough, just moving the mouse over the window results in a boatlod of StylusMove's, but no StylusDown or StylusUp's, as you would expect, until I click.
Centaur, please do email me your project (or just attach it to a message here if you like and I'll snag it). If this is all you have in your Stylus methods, I have a sneaking suspicion that it may be a buffering problem with STLog (ie the actual messages aren't being logged in the correct order). My guess is that it isn't flushing the buffers as you might expect. I do use STLog quite a bit in debugging odd ppc issues, but seldom use it on the desktop because the debugger is so much more reliable there.

Now, I do develop with VS6 not .NET, so I can't comment on any issues that may exist there. I can only presume that .NET compiles correctly. Do you have any optimizations turned on? If so, definately turn them off and try this again.

As I said, I use the Stylus methods in all of my projects and have no timing issues whatsoever. I develop under XP, Win2K and all flavors of the ppc OS.
InexorableTash · 12 May 2004, 06:40 UTC
As a simple fix, just call StylusMove from StylusUp and StylusDown before or after processing the message yourself, depending on what order you're dependent on. Keep your logic for tracking state in one place, and just make sure that place gets visited no matter what the actual event is.

Your code will need to be resilient against (seemingly) spurrious StylusMove events anyway, as Windows will send WM_MOUSEMOVE when you might least expect it (e.g. capture is set, a window is shown/hidden, etc).
ppcStudios: Unfortunately I am at work now, so I can't send or attach my project yet. I will do this tonight.
But the timing/flushing of buffers seems fine to me: just take a look at the timing info at the start of each line: they seem to be in the right order.

Thanx for the suggested solutions, I will implement these to get things working right again. I obvious have to change some things to get these events working the way I expect them (on all platforms).

Note that my main question remains why on the PocketPC the extra, not expected StylusMove event occurs when only tapping the screen.
But maybe it is what InexorableTash mentioned: Windows just throws all kinds of messages at you which and when you just don't expect it... :(
What concerns me is that Centaur's original complaint was that StylusUp is occurring prior to the StylusMove events on the desktop. While I've never seen this problem, if it is truly happening we need to understand why and what can be done to correct it.

Just incase there may be some misunderstanding, here's some simple pseudocode for handling a graphical button press:

Code:

bool down = false
StylusDown(POINT p)
if p inside button rect
down = true

StylusUp(POINT p)
if p inside button rect
down = false

StylusMove(POINT p)
if p !inside button rect AND down == true
down = false


Basically, if you're within the button rectangle on a StylusDown event, you set a flag stating the button has been depressed. If you're within the button rectangle on a StylusUp event, you reset the same flag stating the button has been released. If you get a StylusMove event and the button flag is set to true AND you're not within the button rectangle any longer, you reset the flag to false.

I use this same style for every button and have never found it not to work.
Oh! I just realized something! Never ever, ever, ever try to write to the file system (or draw, or do anything that takes a lot of computing time) within the Stylus event handlers. These have to return extremely fast or you will begin seeing odd occurances like Centaur is now finding. On the ppc, the file system is pretty fast - on the desktop it is extremely slow.

Centaur, try this: set flags in each of the Stylus event handlers and monitor them in the ProcessNextFrame method. Log the state of the flags there instead of within the Stylus methods.
OK, I tried the following:
Centaur, try this: set flags in each of the Stylus event handlers and monitor them in the ProcessNextFrame method. Log the state of the flags there instead of within the Stylus methods.


This gave the same results as in my earlier post. So I can confidently say:

On my 2210, when tapping the screen once in one location, I receive a StylusDown, StylusMove and StylusUp (in that order), and all these three events have the same POINT p.x and p.y values.

Probably not shocking to anybody but me, but nonetheless something to be aware of... :roll:
(especially because this behaviour is different on a stationay PC, so debugging on the PC does not garantee a good working PocketPC version!!!)

Thanx for all your reactions!
Centaur wrote:On my 2210, when tapping the screen once in one location, I receive a StylusDown, StylusMove and StylusUp (in that order), and all these three events have the same POINT p.x and p.y values.

Probably not shocking to anybody but me, but nonetheless something to be aware of... :roll:
(especially because this behaviour is different on a stationay PC, so debugging on the PC does not garantee a good working PocketPC version!!!)


Yes, this is exactly what I would have expected to see - both on the ppc and the desktop. You're absolutely correct - just because it functions on one platform, don't presume it will function on another. =)