marc.mitchell_ Posted August 7, 2018 Share Posted August 7, 2018 Hi, I’m looking to control when the cursor graphic is displayed on screen so I can toggle between showing mouse cursor for UI interaction and hiding the mouse cursor for controlling the player camera via custom controls. Currently I and using the define MOUSE_USER and have the two functions below in an input manger class to enable mouse control which should hide the mouse cursor but still allow getting mouse delta x and y values for custom control handling while the cursor is hidden and disable mouse which should show the cursor disabling my custom input and allow the user to interact with UI: public void EnableMouse() { if(!MouseEnabled) { App.get().setMouseGrab(1); App.get().setMouseShow(0); //controls.grab(); //ControlsApp.get().setMouseEnabled(0); MouseEnabled = true; } } public void DisableMouse() { if (MouseEnabled) { App.get().setMouseGrab(0); App.get().setMouseShow(1); //ControlsApp.get().setMouseEnabled(1); //controls.release(); MouseEnabled = false; } } Currently when I call App.get.setMouseShow(0) the default windows cursor is hidden but replaced by the cursor graphic below: How can I achieve the desired results? Mouse Enable should: · Hide all cursor graphics · Allow a method of retrieving either mouse delta x and y or mouse position x and y within the my custom input manager class · Disable interaction with Unigine UI Mouse Disable should: · Show default windows cursor allowing interaction with Uninge UI Link to comment
fox Posted August 10, 2018 Share Posted August 10, 2018 Hi Marc, Try this code (to be inserted into AppWorldLogic.cs file of your project), it works without using MOUSE_USER and MOUSE_SOFT defines, maybe it'll meet your requirements, hope I got them right: class AppWorldLogic : WorldLogic { // auxiliary variables App app; ControlsApp controls_app; Controls controls; Gui gui; // widgets WidgetLabel label; WidgetButton button; /* ... */ // Method toggling the mouse cursor's state public void ToggleMouseCursor() { // getting current mouse state int enabled = controls_app.isMouseEnabled(); // changing necessary parameters app.setMouseGrab(1 - enabled); gui.setMouseEnabled(enabled); controls_app.setMouseEnabled(1 - enabled); } public override int init() { // initializing auxiliary variables app = App.get(); controls_app = ControlsApp.get(); controls = Game.get().getPlayer().getControls(); gui = Gui.get(); // preparing UI label = new WidgetLabel(gui); button = new WidgetButton(gui, "BUTTON"); button.setPosition(10, 40); gui.addChild(label, Gui.ALIGN_OVERLAP | Gui.ALIGN_TOP | Gui.ALIGN_LEFT); gui.addChild(button, Gui.ALIGN_OVERLAP | Gui.ALIGN_TOP | Gui.ALIGN_LEFT); return 1; } public override int update() { // checking for STATE_USE and toggling mouse cursor state if (controls.clearState(Controls.STATE_USE) == 1) ToggleMouseCursor(); // updating cursor position info label.setText(String.Format("\n MOUSE COORDS: ({0}, {1})", app.getMouseX(), app.getMouseY())); return 1; } /* ... */ } Just create an empty C# project, declare AppWorldLogic class members, add toggling function and modify init() and update() methods as shown above. Hope this solves your issue! Thanks! Link to comment
Recommended Posts