ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  C++ zoom in with selection rectangle and mouse events
Posted by Ulrich Telle on Jul-20-2018 06:08
Hi Peter,

as you know I currently implement a chart viewer control for the wxWidgets framework. In principle, I have now all ChartDirector samples working properly. However, I'm struggling with a special case when a user drags with the mouse a selection rectangle to zoom in, but moves the mouse pointer outside of the plotarea of a chart resp outside of the chart control.

For comparison I got the MFC samples working. Here the user can drag the rectangle up to the edges of the dialog window, and can move the mouse pointer even beyond the window edges as long as the left mouse button is still pressed. And some sort of "zoom in" happens when the left mouse button is released (even outside the dialog window). Obviously, the chart viewer control can catch the mouse events, even if they happen outside the control.

In wxWidgets this is not possible. A control gets only mouse events when the mouse pointer moves within the control's area. One problem I experienced in my current implementation is that the selection rectangle stays visible when I drag the mouse pointer outside of the chart control. If I then release the mouse button outside the chart control, the chart control is not notified. Moving the mouse pointer back over the chart control, started to drag the selection rectangle even though the left mouse button wasn't down anymore. I was able to fix this by checking the state of the left mouse button in the chart viewer's mouse event handler.

However, I'm a bit undecided how I should implement the handling of this special case. One option would be to cancel the zoom in operation (and to remove the selection rectangle from screen) if a "mouse leaves chart" event occurs. Would that be a reasonable/acceptable implementation? If not, what approach would you recommend?

Kind regards,

Ulrich

  Re: C++ zoom in with selection rectangle and mouse events
Posted by Peter Kwan on Jul-20-2018 15:29
Hi Ulrich,

The behaviour you mentioned is called "mouse capture", that is, the object can "capture" the mouse and continue to receives mouse events until the object "releases" the mouse.

Every GUI framework handles mouse capture differently. In Qt, it is enabled by default and is the capture/release is controlled by mouse buttons. In MFC, mouse capture is not enabled, and we have to add extra code to capture/release the mouse. If you look at our MFC CChartViewer and search for "capture", you can see where do we capture the mouse and release the mouse.

I just search using google and there are also APIs in wxWidget to support mouse capture (eg. wxWindow::CaptureMouse and wxWindow::ReleaseMouse), so it should be possible to do similar things in wxWidget.

Regards
Peter Kwan

  Re: C++ zoom in with selection rectangle and mouse events
Posted by Ulrich Telle on Jul-20-2018 16:19
Hi Peter,

Peter Kwan wrote:
The behaviour you mentioned is called "mouse capture", that is, the object can "capture" the mouse and continue to receives mouse events until the object "releases" the mouse.

Thanks for the pointer. Although I used wxWidgets already for quite a long time, I haven't implemented any application yet that uses the mouse to select a certain region on screen.

Peter Kwan wrote:
Every GUI framework handles mouse capture differently. In Qt, it is enabled by default and is the capture/release is controlled by mouse buttons. In MFC, mouse capture is not enabled, and we have to add extra code to capture/release the mouse. If you look at our MFC CChartViewer and search for "capture", you can see where do we capture the mouse and release the mouse.

I haven't used QT myself, but I started my wxWidgets implementation from the QT chart viewer sources, because I thought it would be closer to what wxWidgets does. I will inspect the MFC code to see how mouse capture is handled there and will try to do it similarly in my wxWidgets implementation.

Peter Kwan wrote:
I just search using google and there are also APIs in wxWidget to support mouse capture (eg. wxWindow::CaptureMouse and wxWindow::ReleaseMouse), so it should be possible to do similar things in wxWidget.

Ouch ... I should have found this myself.

Thanks again. I really appreciate your continued excellent support.

Regards,

Ulrich