Mouse position is reported wrong when mouse is captured and moved beyond the client area (left and top direction)
I attached mouse event handlers as follows (image is a framework element of type Image, 'this' is an MFC CWnd)
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.
Code: Select all
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();
};
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
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Mouse position is reported wrong when mouse is captured and moved beyond the client area (left and top direction)
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.
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.
Re: Mouse position is reported wrong when mouse is captured and moved beyond the client area (left and top direction)
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.
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.
Code: Select all
case WM_MOUSEMOVE:
if (g_XamlView != 0)
{
g_XamlView->MouseMove(LOWORD(lParam), HIWORD(lParam));
}
break;
So it is not a NoesisGUI bug, but you might want to fix the code inside your sample codes.
Re: Mouse position is reported wrong when mouse is captured and moved beyond the client area (left and top direction)
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.
It is redundant, and developers easily forget to call CWnd::SetCapture and ::ReleaseCapture.
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Mouse position is reported wrong when mouse is captured and moved beyond the client area (left and top direction)
Thanks for noticing this, we will fix it for the next release.So it is not a NoesisGUI bug, but you might want to fix the code inside your sample codes.
We cannot do any of this calls as we don't know anything about the windows created by the user.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.
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.
Re: Mouse position is reported wrong when mouse is captured and moved beyond the client area (left and top direction)
Could you elaborate a bit more about why you need to capture and release the mouse?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).
Re: Mouse position is reported wrong when mouse is captured and moved beyond the client area (left and top direction)
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).Could you elaborate a bit more about why you need to capture and release the mouse?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).
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.
Re: Mouse position is reported wrong when mouse is captured and moved beyond the client area (left and top direction)
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?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.
Re: Mouse position is reported wrong when mouse is captured and moved beyond the client area (left and top direction)
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).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?
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.
Code: Select all
m_view->AttachMouseCaptureCallback([this]() {
// make the hosting CWnd (this) to capture the mouse
this->SetCapture();
});
m_view->AttachMouseReleaseCaptureCallback([this](){
// release the captured mouse
::ReleaseCapture();
});
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.
Code: Select all
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
};
Re: Mouse position is reported wrong when mouse is captured and moved beyond the client area (left and top direction)
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: Baidu [Spider] and 5 guests