Mouse cursor for UI
Posted: Sat Jun 15, 2019 5:48 am
I'm trying to get the mouse coordinates so I can have a cursor in my UI. The only way to do this is via an EventHandler overriding UIProcess, from there I can get the mouse screen position from the UiEvent (InputEvent only gives the mouse delta which is not useful for mouse cursor control).
However, I also need to set IsUiProcessor = true for the EventHandler, and once I do this, ALL input (save for mouse movement, for some reason) is blocked. I can't even enter the menu or console
This is different from InputProcess where I can just return false and all inputs "go through".
So, the question is, how can I get the mouse cursor on screen and not block any input (save for the mouse movement, I guess)?
Or maybe this is not a good way to do it?
However, I also need to set IsUiProcessor = true for the EventHandler, and once I do this, ALL input (save for mouse movement, for some reason) is blocked. I can't even enter the menu or console
So, the question is, how can I get the mouse cursor on screen and not block any input (save for the mouse movement, I guess)?
Code: Select all
//registered in MapInfo/GameInfo
Class HG_InputHandlerUI : EventHandler
{
Vector2 cursorPos;
override void OnRegister()
{
self.IsUiProcessor = true;
//self.RequireMouse = true;//this shows the menu-style cursor, which I don't want. I'd rather draw the cursor in the StatusBar script and position it according to the cursorPos values.
}
override bool UiProcess(UiEvent e)
{
if(e.Type == UiEvent.Type_MouseMove)
{
cursorPos.x = clamp(e.MouseX, 0, Screen.GetWidth());
cursorPos.y = clamp(e.MouseY, 0, Screen.GetHeight());
}
return false;
}
}