Trouble with mouse events on my wxpanel Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
MrPoletski
Earned a small fee
Earned a small fee
Posts: 14
Joined: Sun Mar 16, 2014 6:30 am

Trouble with mouse events on my wxpanel

Post by MrPoletski »

So I'm building a GUI, for my program CG Studio. (card game studio)

I am using a wxpanel as my main drawing area where I am placing objects, (these objects have become quite complex)

The objects all together, along with a background constitute a template for which multiple cards will be produced, i.e. 'character template' with a space for various stats, flavour text and stuff, each of which is one of my objects class that accept parameters. The editor just shows default values, but when you create a card instance you modify the parameters and hey presto a unique card. That's the context we're in.

Anyway, the issue I have is I'm using the mouse events to manipulate these objects on the page. Focusing just on the left mouse button (though the issue also exists with the right) When I click the left mouse I run through this soutine that detects what I have clicked on and based on that, what the mouse cursor shuld be doing. Perhaps I had already clicked the add new object button, so don't do any tests, place the new object at the mouse location, or, did I click on the currently selected objects dragbox, the currently selected object(s) area, or a new object. Lets say I click on the selected object, when I do that I set the 'dragging' flag to true and then the mouse move event will update that objects position and redraw the editor screen as I move the mouse around dragging said object. When the mouse button up event is called, I stop dragging and commit to the objects change in position.

So, click an object, holding the mosue down, move the mouse, the objects move, let go of the mouse object 'dropped' again. This works.

However, if I thrash the mouse about a lot while dragging the object, making sure the mouse move event is called many times, when I release the mouse button nothing happens and the object remains tied to my mouse pointer - exactly as if the mouse button up event has not been called.


So what's going on here, I was under the impression that events would be queued and that even if the mouse move event is still running (which has become quite significant in it's workload, especially if it's drawing a large number of objects) that the mouse up event would still execute, just perhaps a few ms later while it waits for the last mousemove event to complete.

As it stands, the only way I can think of dealing with this is detecting in the mouse move event that the mouse button is still down and if it isn't then running the mouse up function manually, gating it to avoid running it twice (I already do this for the mouse leaving the window area). I can't help but think there is some flag I need to set somewhere that'd fix all this though - or, that I'm doing something else fundamentally wrong.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Trouble with mouse events on my wxpanel

Post by PB »

You need to debug the application, starting with whether you actually do receive the mouse up event and if so, what happens during handling it.

I assume you use wxWindow's {Capture/Release}Mouse(), HasCapture() etc. Do you properly handle EVT_MOUSE_CAPTURE_LOST?

If just moving a mouse cursor a lot is an issue, it should be easy to reproduce in a minimal sample.
MrPoletski
Earned a small fee
Earned a small fee
Posts: 14
Joined: Sun Mar 16, 2014 6:30 am

Re: Trouble with mouse events on my wxpanel

Post by MrPoletski »

I assume you use wxWindow's {Capture/Release}Mouse(), HasCapture() etc. Do you properly handle EVT_MOUSE_CAPTURE_LOST?
Built using wxsmith, I have never heard of those functions.

I shall look into these, already found them in the documentation just now. I don't have the capture lost event in the events tab of my wxpanel so I guess I'll have to bind it manually and see if that's being called. If it is, I suppose I can have it run the same function I ran as I do when the mouse leaves the window.

The pain is it's difficult to reproduce on demand, but it never, ever fails to register the mouse button being releasead if I am not moving the mouse when I release it. (at least it hasn't yet)

As for debugging, I currently have a textctrl in the bottom of the app that spits out a ton of garb exactly for debugging purposes, so I can see when I am redrawing, data from the object selection tests etc. Yeah adding log entries for entering all those functions.

As for a real debugger, I've found the code blocks debugger useful at times, but given the nature of this, I can't see it being useful here (it's not a great debugger tbh and I'm not that proficient in using it)

Thanks for your help, you've given me valuable clues to investigate.
MrPoletski
Earned a small fee
Earned a small fee
Posts: 14
Joined: Sun Mar 16, 2014 6:30 am

Re: Trouble with mouse events on my wxpanel

Post by MrPoletski »

Well,

Mystery 1 has turned into mystery 2.

Your advice has lead me to deduce (via log spitting) that the reason that mouse left up event was not being called was actually that mouse left up was leaving early due to my 'mouse up called early' flag being set. So upon removing that gate, I have been unable to reproduce my bug :-D

But it begs the question, the only place I set that flag true is in the mouse leave window event and yes, it's properly initialised to false, and no, I haven't called that event when the bug occurs. So how is that being set to true?!??

Maybe superflouous though, I just added that gate because I assumed I'd need it but the more I think about it the more I think I actually don't.

I question if I need that gate at all because I check for every condition I might be in (dragging, resizing etc) and if they all fail, I do nothing. I was worried I'd end up double tapping the mouse left up event if my leave the area event calls the mouse left up function. I will, but the thing to do I suppose is to make sure I can double call mouse left up and not break anything.

Thanks again for your help, you answered me in the best way, got me to look through my own code again with a freshly rubbed pair of eyes =D>
Post Reply