nikobarli
Topic Author
Posts: 178
Joined: 26 Apr 2017, 06:23

Mouse position is reported wrong when mouse is captured and moved beyond the client area (left and top direction)

09 Jun 2017, 09:21

I attached mouse event handlers as follows (image is a framework element of type Image, 'this' is an MFC CWnd)
            image->MouseMove() += [=](BaseComponent* sender, const MouseEventArgs& args) {
                printf("MousePos %4.2f %4.2fn", args.position.x, args.position.y);
            };
            image->MouseLeftButtonDown() += [=](BaseComponent* sender, const MouseButtonEventArgs& args) {
                image->CaptureMouse();
                this->SetCapture();
            };
            image->MouseLeftButtonUp() += [=](BaseComponent* sender, const MouseButtonEventArgs& args) {
                image->ReleaseMouseCapture();
                ::ReleaseCapture();
            };
Then if I drag my mouse starting from inside the image, to the left, then go beyond the client area of the window, NoesisGUI calls the Mouse Move handler with wrong values. Below is the trace of the printf inside Mouse Move handler. You can observe that instead of giving negative value for the x coordinate beyond the client area on the left, NoesisGUI gives 65000+ values. Seems that it wraps around an unsigned short value internally.
MousePos 60.00 183.00
MousePos 58.00 183.00
MousePos 57.00 182.00
MousePos 53.00 182.00
MousePos 51.00 182.00
MousePos 48.00 181.00
MousePos 46.00 181.00
MousePos 44.00 180.00
MousePos 42.00 180.00
MousePos 40.00 180.00
MousePos 36.00 179.00
MousePos 35.00 178.00
MousePos 33.00 178.00
MousePos 30.00 178.00
MousePos 29.00 178.00
MousePos 26.00 178.00
MousePos 25.00 178.00
MousePos 19.00 176.00
MousePos 16.00 176.00
MousePos 13.00 175.00
MousePos 1.00 175.00
MousePos 65535.00 175.00
MousePos 65534.00 174.00
MousePos 65533.00 174.00
MousePos 65532.00 174.00
MousePos 65531.00 174.00
MousePos 65529.00 174.00
 
User avatar
sfernandez
Site Admin
Posts: 1915
Joined: 22 Dec 2011, 19:20

Re: Mouse position is reported wrong when mouse is captured and moved beyond the client area (left and top direction)

12 Jun 2017, 18:22

Hi,

Could you please create a ticket in our bugtracker and attach the project, because I did a similar test and the values I am getting are correct (negative values when mouse is moved beyond top-left corner of the window).

Thanks.
 
nikobarli
Topic Author
Posts: 178
Joined: 26 Apr 2017, 06:23

Re: Mouse position is reported wrong when mouse is captured and moved beyond the client area (left and top direction)

13 Jun 2017, 02:18

Ah, I found the source of the problem. Inside the integration layer, I copy pasted codes from the SDK's Tutorial05.cpp, and it was using macro LOWORD and HIWORD to extract x, y position inside mouse event handler.
        case WM_MOUSEMOVE:
            if (g_XamlView != 0)
            {
                g_XamlView->MouseMove(LOWORD(lParam), HIWORD(lParam));
            }
            break;
It should use GET_X_LPARAM/GET_Y_LPARAM macro instead (which return signed int).

So it is not a NoesisGUI bug, but you might want to fix the code inside your sample codes.
 
nikobarli
Topic Author
Posts: 178
Joined: 26 Apr 2017, 06:23

Re: Mouse position is reported wrong when mouse is captured and moved beyond the client area (left and top direction)

13 Jun 2017, 02:23

BTW, is there any good way to integrate NoesisGUI (C++ SDK, Windows Platform), so that I don't need to call CWnd::SetCapture and ::ReleaseCapture, in addition to NoesisGUI's CaptureMouse and ReleaseMouseCapture (please see the code snippet in the original post of this issue).

It is redundant, and developers easily forget to call CWnd::SetCapture and ::ReleaseCapture.
 
User avatar
sfernandez
Site Admin
Posts: 1915
Joined: 22 Dec 2011, 19:20

Re: Mouse position is reported wrong when mouse is captured and moved beyond the client area (left and top direction)

13 Jun 2017, 11:36

So it is not a NoesisGUI bug, but you might want to fix the code inside your sample codes.
Thanks for noticing this, we will fix it for the next release.
BTW, is there any good way to integrate NoesisGUI (C++ SDK, Windows Platform), so that I don't need to call CWnd::SetCapture and ::ReleaseCapture, in addition to NoesisGUI's CaptureMouse and ReleaseMouseCapture (please see the code snippet in the original post of this issue).

It is redundant, and developers easily forget to call CWnd::SetCapture and ::ReleaseCapture.
We cannot do any of this calls as we don't know anything about the windows created by the user.
Maybe if we develop a multi-platform application framework, in charge of starting the application and managing the operating system windows, we could automatically call these functions. But this is out of the scope of NoesisGUI, which is purely a UI middleware.
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: Mouse position is reported wrong when mouse is captured and moved beyond the client area (left and top direction)

13 Jun 2017, 11:44

BTW, is there any good way to integrate NoesisGUI (C++ SDK, Windows Platform), so that I don't need to call CWnd::SetCapture and ::ReleaseCapture, in addition to NoesisGUI's CaptureMouse and ReleaseMouseCapture (please see the code snippet in the original post of this issue).
Could you elaborate a bit more about why you need to capture and release the mouse?
 
nikobarli
Topic Author
Posts: 178
Joined: 26 Apr 2017, 06:23

Re: Mouse position is reported wrong when mouse is captured and moved beyond the client area (left and top direction)

14 Jun 2017, 03:19

BTW, is there any good way to integrate NoesisGUI (C++ SDK, Windows Platform), so that I don't need to call CWnd::SetCapture and ::ReleaseCapture, in addition to NoesisGUI's CaptureMouse and ReleaseMouseCapture (please see the code snippet in the original post of this issue).
Could you elaborate a bit more about why you need to capture and release the mouse?
Because if I don't call CWnd::SetCapture and ::ReleaseCapture (in addition to NoesisGUI's CaptureMouse and ReleaseMouseCapture), I cannot track the mouse movement beyond the view (i.e. MouseMove event is not sent when the pointer goes out of the view. UIElement::CaptureMouse "captures" the mouse movement beyond the element only when the pointer is above the view).

The capability to capture the mouse beyond the current view is very common in our application. Google's map is also another example where during the dragging, the application captures the mouse beyond the browser windows.

In my opinion, you can provide an integration API so that I can set a SetCapture/ReleaseCapture callback to an IView. Thus NoesisGUI can call the callback when it is set, and it is up to user to implement it (in my case, it will forwarded to the host windows CWnd::SetCapture and ::ReleaseCapture.
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: Mouse position is reported wrong when mouse is captured and moved beyond the client area (left and top direction)

14 Jun 2017, 13:32

In my opinion, you can provide an integration API so that I can set a SetCapture/ReleaseCapture callback to an IView. Thus NoesisGUI can call the callback when it is set, and it is up to user to implement it (in my case, it will forwarded to the host windows CWnd::SetCapture and ::ReleaseCapture.
Not sure to understand this. When should we call those callbacks? At left mouse button down for example? I don't see any difference between you sending us a LeftMouseDown and doing a capture yourserlf or you sending us a LeftMouseDown, we calling your callback and you doing the capture there. Is this what you mean?
 
nikobarli
Topic Author
Posts: 178
Joined: 26 Apr 2017, 06:23

Re: Mouse position is reported wrong when mouse is captured and moved beyond the client area (left and top direction)

15 Jun 2017, 02:05

Not sure to understand this. When should we call those callbacks? At left mouse button down for example? I don't see any difference between you sending us a LeftMouseDown and doing a capture yourserlf or you sending us a LeftMouseDown, we calling your callback and you doing the capture there. Is this what you mean?
The idea is to allow UI developers to program in terms of NoesisGUI API, without worrying the interaction with the hosting GUI environment (in our case it is MFC).

Here some pseudocode to illustrate my thinking:

Inside integration layer code, I registered my callback to the NoesisGUI view during initialization. This integration code is not visible to the UI developer.
m_view->AttachMouseCaptureCallback([this]() {
    // make the hosting CWnd (this) to capture the mouse
    this->SetCapture();
});
m_view->AttachMouseReleaseCaptureCallback([this](){
    // release the captured mouse
    ::ReleaseCapture();
});
NoesisGUI's View should call the callback when any of its UIElement's CaptureMouse or ReleaseMouseCapture is called.

Then the UI developer can purely program in terms of NoesisGUI API. He will call UIElement::CaptureMouse and UIElement::ReleaseCaptureMouse when needed, and NoesisGUI will automatically call the callbacks registered by the integration layer. The UI developer doesn't need to be aware that its UI is hosted by MFC CWnd and he doesn't need to worry about controlling the host environment.
            image->MouseMove() += [=](BaseComponent* sender, const MouseEventArgs& args) {
                printf("MousePos %4.2f %4.2fn", args.position.x, args.position.y);
            };
            image->MouseLeftButtonDown() += [=](BaseComponent* sender, const MouseButtonEventArgs& args) {
                image->CaptureMouse(); // Noesis GUI internally calls integration layer's mouse capture callback
            };
            image->MouseLeftButtonUp() += [=](BaseComponent* sender, const MouseButtonEventArgs& args) {
                image->ReleaseMouseCapture(); // Noesis GUI internally calls integration layer's mouse release capture callback
            };
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: Mouse position is reported wrong when mouse is captured and moved beyond the client area (left and top direction)

15 Jun 2017, 13:12

I see the point now. Thanks for the clarification. The only minor inconvenience is that our internal controls handle mouse capturing opaquely to the operating system (because for the operating system our view is just a single window). But I don't see big problems in also calling the operating mouse capture mechanism whenever our internal controls need it. I think I like the idea.

Who is online

Users browsing this forum: Bing [Bot] and 1 guest