sgonchar
Topic Author
Posts: 48
Joined: 15 Mar 2021, 22:11

All mouse interaction is offset

18 May 2021, 00:27

Hello,

All of our interactive objects are offset by a few pixels like so:
Image

Not just buttons, also input fields etc.
Inspector highlight doesn't seem to show why, when mouse is right on top few pixels of the button the entire panel is selected as if cursor is way off the button.

I'd like to ask for some pointers on how to debug something like this?
I'm going through our button styles and such to see if offsets make a difference, but I don't see how we could make visual boundary disjointed from interaction boundary.
Maybe animations can do this?

edit: is there an easy way to attach a marker to where Noesis thinks current mouse is? Maybe mouse being sent to Noesis is disjointed from actual mouse position?
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: All mouse interaction is offset

18 May 2021, 11:54

If all the UI elements are affected by this offset I would say it is a problem with the integration layer (mouse coordinates injected into the IView are not correct). Styles or animations won't be the cause for this.

You can draw a cross hair in your main window that is moved with the mouse to detect that:
<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Canvas Background="Transparent">
    <Path x:Name="MouseCursor" Data="M0,10L20,10M10,0L10,20" Stroke="Yellow" Stretch="None" Margin="-10,-10,10,10"/>
  </Canvas>
</Grid>
To update the cross hair position you can hook to PreviewMouseMove in your root element:
MainWindow::MainWindow()
{
  PreviewMouseMove() += [this](BaseComponent*, const MouseEventArgs& e)
  {
    UIElement* mouseCursor = FindName<UIElement>("MouseCursor");
    Canvas::SetLeft(mouseCursor, e.position.x);
    Canvas::SetTop(mouseCursor, e.position.y);
  };
}
Could you try that and let us know what you find?
 
sgonchar
Topic Author
Posts: 48
Joined: 15 Mar 2021, 22:11

Re: All mouse interaction is offset

18 May 2021, 18:12

Hi!
Thank you for the debugging info, super helpful!

Here's what I found so far:
- (green) all capture areas are offset by same relative amount from top middle-ish (red) of the screen.
- (yellow +) the raw noesis mouse pointer and actual interaction area don't match. Also very easily spoofed by resizing the window, where
- (purple) Interaction area is in-between raw mouse and windows mouse pointer (maybe 40-60% split?) . green vs yellow not quite to scale, purple shows better.

I'll keep poking around raw mouse updates ..

Image

- windows pointer to noesis raw mouse difference can exaggerated by resizing the window, however green capture area changes only a little.

Image
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: All mouse interaction is offset

18 May 2021, 18:38

Some questions...

Are you on Noesis 3.0, right?
Are you using our application framework for the windowing system or your own?
Have you set a scale in Windows 10 Display settings?
Are you setting any projection matrix (SetProjectionMatrix) in the IView?

One thing that comes to my mind is that you are possibly calling IView::SetSize with incorrect client rect when your system window is resized, could you please check that?
 
sgonchar
Topic Author
Posts: 48
Joined: 15 Mar 2021, 22:11

Re: All mouse interaction is offset

18 May 2021, 21:03

Hello,
1) We're on Noesis 3.1.0-9989
2) Yes, we're using application framework.
3) No scale in windows 10.
4) No instance of SetProjectionMatrix use.
5) Ae are using SetSize like this:
       display->SizeChanged() += [view, ctx](NoesisApp::Display*, uint32_t width, uint32_t height) {
            view->SetSize(width, height);  // debugger values: 1920x1029 , but actual window size: 1906x1022 
            ctx->Resize();
        };
SetSize can be called in several other spots that but currently only the above case gets triggered.
Get trigged as window appears. Maybe we're missing a SetSize / AdjustWindowSize earlier in init?
 
sgonchar
Topic Author
Posts: 48
Joined: 15 Mar 2021, 22:11

Re: All mouse interaction is offset

18 May 2021, 22:26

Ha!
Thank you, your samples have the correct code to fix our mouse cursor bounding box issue!
    display->SizeChanged() += [view, ctx](NoesisApp::Display* display, uint32_t, uint32_t)
    {
        view->SetSize(display->GetClientWidth(), display->GetClientHeight());
        ctx->Resize();
    };
FYI though, the crosshair still acts weird and doesn't quite follow the mouse pointer.

Edit: I'd also like to ask if you have idea why function params would produce different results from display-GetClient.. ? Does display do something specials / scaling / window with border vs borderless calculations?
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: All mouse interaction is offset

19 May 2021, 14:21

Glad it finally works.
FYI though, the crosshair still acts weird and doesn't quite follow the mouse pointer.
This can happen if the Canvas where the crosshair is placed doesn't fill the entire window. Could that be the case? To make sure you use the correct coordinates you can transform them to the canvas local space:
MainWindow::MainWindow()
{
  PreviewMouseMove() += [this](BaseComponent*, const MouseEventArgs& e)
  {
    Canvas* mouseCanvas = FindName<Canvas>("MouseCanvas");
    UIElement* mouseCursor = FindName<UIElement>("MouseCursor");
    Point p = mouseCanvas->PointFromScreen(e.position);
    Canvas::SetLeft(mouseCursor, p.x);
    Canvas::SetTop(mouseCursor, p.y);
  };
}
I'd also like to ask if you have idea why function params would produce different results from display-GetClient.. ? Does display do something specials / scaling / window with border vs borderless calculations?
The width and height reported by Display's SizeChanged event include window's title bar and borders, but the View requires the client area of the window only, the size of the render surface. That is why you should call view->SetSize(display->GetClientWidth(), display->GetClientHeight()).

Who is online

Users browsing this forum: Google [Bot] and 69 guests