Page 1 of 1

Mouse cursor for UI

Posted: Sat Jun 15, 2019 5:48 am
by Cherno
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 :roll: 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)?

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;
	}
	
	
}
Or maybe this is not a good way to do it?

Re: Mouse cursor for UI

Posted: Mon Jun 17, 2019 12:22 am
by Graf Zahl
Mouse handling has been set up so that if mouse input is possible, the system's mouse cursor is displayed. So what you try here will inevitably cause problems, because in order to hide the cursor you will disable its function.

Re: Mouse cursor for UI

Posted: Mon Jun 17, 2019 6:04 am
by Cherno
Ok, thank you for the clarification. Is there any way to have a mouse cursor for an in-game HUD?

Re: Mouse cursor for UI

Posted: Mon Jun 17, 2019 6:25 am
by Graf Zahl
No. In-game the mouse is needed for movement and its buttons are used as bindable keys. You need to be in some form of UI mode, like a menu to have the mouse active as a pointing device.

Re: Mouse cursor for UI

Posted: Mon Jun 17, 2019 6:59 am
by Cherno
Yes, the movement and mouse button input could be blocked though... But there is no way to get cursor input while the game keeps running, right?

Re: Mouse cursor for UI

Posted: Mon Jun 17, 2019 8:00 am
by Graf Zahl
No, because the movement code has acquired the mouse in there.