Mouse cursor for UI

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Cherno
Posts: 1337
Joined: Tue Dec 06, 2016 11:25 am

Mouse cursor for UI

Post 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?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Mouse cursor for UI

Post 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.
User avatar
Cherno
Posts: 1337
Joined: Tue Dec 06, 2016 11:25 am

Re: Mouse cursor for UI

Post by Cherno »

Ok, thank you for the clarification. Is there any way to have a mouse cursor for an in-game HUD?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Mouse cursor for UI

Post 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.
User avatar
Cherno
Posts: 1337
Joined: Tue Dec 06, 2016 11:25 am

Re: Mouse cursor for UI

Post 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?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Mouse cursor for UI

Post by Graf Zahl »

No, because the movement code has acquired the mouse in there.
Post Reply

Return to “Scripting”