Displaying the mouse cursor in Noesis
Hi.
I wanted to ask for some tips regarding cursor rendering. I couldn't really find that much information on it, so here's a couple questions:
1. Does Noesis have any built in cursor rendering functionality? I'm assuming that no - if we want to use cursors via .cur files we have to do that on our end and all Noesis does is send events via NoesisGUI.SetCursorCallback? And if we want to handle the cursor via Noesis we should treat it like any other control that we move via mouse events (see point 2)?
2. We are currently using a UserControl to display the cursor, settings it's position according to PreviewMouseMove and setting clicked/unclicked according to PreviewMouseLeftButtonDown/Up. The cursor is the bottom-most element in our visual tree.
ie.
Now this works properly for almost all cases - cursor is always rendered above everything else (since everything else is within MainMenuControl. The only problem so far is with popups. When we use Noesis' <Popup> control it is rendered above everything else, including the cursor. We tried some experimentation with ZIndex etc., but it doesn't seem to work (since the Popup doesn't have the same parent panel as Cursor).
Is there any solution to this problem, such as forcing the CursorControl to always render at the top (even above the Popups)? For now we just ignore the <Popup> control and use our own control which imitates the functionality, but we'd like to use the actual <Popup> to reduce the chance of problems appearing down the line. Another option would be to put a second CursorControl inside the popup, hide the first one and use the second one. But that seems really hacky to have to do for all popups. I'm looking for any tips as to what is the recommended way for handling the mouse cursor.
I wanted to ask for some tips regarding cursor rendering. I couldn't really find that much information on it, so here's a couple questions:
1. Does Noesis have any built in cursor rendering functionality? I'm assuming that no - if we want to use cursors via .cur files we have to do that on our end and all Noesis does is send events via NoesisGUI.SetCursorCallback? And if we want to handle the cursor via Noesis we should treat it like any other control that we move via mouse events (see point 2)?
2. We are currently using a UserControl to display the cursor, settings it's position according to PreviewMouseMove and setting clicked/unclicked according to PreviewMouseLeftButtonDown/Up. The cursor is the bottom-most element in our visual tree.
ie.
Code: Select all
<Window (...)>
<Canvas >
<Viewbox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="{Binding ActualHeight, ElementName=window}" Width="{Binding ActualWidth, ElementName=window}">
<local:MainMenuControl ></local:MainMenuControl>
</Viewbox>
<common:CursorControl/>
</Canvas>
</Window>
Is there any solution to this problem, such as forcing the CursorControl to always render at the top (even above the Popups)? For now we just ignore the <Popup> control and use our own control which imitates the functionality, but we'd like to use the actual <Popup> to reduce the chance of problems appearing down the line. Another option would be to put a second CursorControl inside the popup, hide the first one and use the second one. But that seems really hacky to have to do for all popups. I'm looking for any tips as to what is the recommended way for handling the mouse cursor.
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Displaying the mouse cursor in Noesis
1. Yes, the cursor rendering is part of the operating system, so it should be handled outside Noesis. As you mentioned we provide the SetCursorCallback to indicate which cursor should be activated. You will receive in the callback a cursor object that provides information about the type (Arrow, Hand, Cross, ..., Custom), and a filename in case it is a custom cursor.
2. Rendering the cursor using the UI is not recommended because it will be tied to the framerate of the game and that would feel weird many times, specially with high-dpi mouse devices.
Anyway, in case you still want to render the cursor as a UI element on top of everything else, there is no easy way to achieve it. Popups are added as new layers to the root of the View, so one option could be to add the cursor each frame as a new layer, it is very hacky but it'll work:
2. Rendering the cursor using the UI is not recommended because it will be tied to the framerate of the game and that would feel weird many times, specially with high-dpi mouse devices.
Anyway, in case you still want to render the cursor as a UI element on top of everything else, there is no easy way to achieve it. Popups are added as new layers to the root of the View, so one option could be to add the cursor each frame as a new layer, it is very hacky but it'll work:
Code: Select all
void ShowCursor(Noesis.View view, Noesis.Visual cursor)
{
Noesis.Visual root = (Noesis.Visual)Noesis.VisualTreeHelper.GetRoot(view.Content);
root.RemoveLayer(cursor);
root.AddLayer(cursor);
}Re: Displaying the mouse cursor in Noesis
Or use a different View only for the cursor. Hacky, but it will work.
But as said above, we recommend leaving the rendering of the cursor to the operating system.
But as said above, we recommend leaving the rendering of the cursor to the operating system.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 7 guests