I will soon report back with an updated repo which has full mouse support.
Good to hear.
FYI, I posted a PR that enables Mouse on any Wnd
control.
I will soon report back with an updated repo which has full mouse support.
Good to hear.
FYI, I posted a PR that enables Mouse on any Wnd
control.
Thank you very much, but I canāt find the PR. Can you please check it again?
Here it is: https://github.com/MonoGame/MonoGame/pull/6081
and hereās the MG setup: http://teamcity.monogame.net/repository/download/MonoGame_PackagingWindows/58823:id/MonoGameSetup.exe
You have to set Mouse.WindowHandle to your Control.Handle.
Ah, itās in the MonoGame repo - my bad
You made some nice commits. Someone in a forms environment could use the native MonoGame mouse state or the basic mouse events from the controls in that way. I like that the user could decide what he wants to use - depending on his needs or developing experience with WindowsForms or MonoGame.
First I will push the recent changes I did together with updated sample projects. After that I will come back to your changes and when I have time I will implement this. In the moment Iām very busy, so updates could take a while.
Thanks for your help @nkast!
In this update I show you multiple controls on one form and different mouse actions happening on those controls.
Please watch in fullscreen and 1080p:
I removed the old mouse button click detections and worked with the native windows forms control events instead. You can use all common mouse buttons now:
In the new sample project (you saw in the video) I created the abstract MapHost.cs class to show you how you could share a common code base on multiple MonoGame.Form controls, but still treat each controll differently. The controls in the view are both inheriting from the same MapHost, but they are getting initialized independently.
This keeps your main control classes clean and easy to manage, because only the non-abstract classes, which inheriting from a MonoGame.Forms control, are visible in the ToolBox from the designer (compare: Control_A vs Control_B)
For the next update I plan to bring back the native MonoGame mouse input using the updates from @nkast. This also has the advantage of faster click detections in relation to the WindowsForms event system.
You can then use both: WindowsForms Mouse Events and MonoGame Mouse Input.
Removed old Keyboard Util and Service classes
Added Mouse input support (now MonoGame native)
Added Keyboard input support (now MonoGame native)
Raised MonoGame.Framework to 3.7.0.1114 (DirectX)
The mouse handle is now attached when a new control is created, so you could simply use Mouse.GetState() of the MonoGame framework.
I implemented the nice Enable-Keyboard-Trick to enable the native Keyboard.GetState() method of the MonoGame framework.
At this point big thanks to @nkast for your nice input! (pun detected? )
It automatically enables itself when the control has focus and disables when it becomes unfocused.
I added the flag āAlwaysEnableKeyboardInputā so you can override the unfocused behavior (sometimes you may want to have either the keyboard for text input or game / editor related input and sometimes you may want to have game / editor input no matter where the mouse cursor currently is or rather which control has the focus).
Also thanks to everyone else here for your nice ideas so far!
Regarding extendend input capabillities of MonoGame.Forms I think we managed to get everything from the MonoGame framework working.
Thanks again
This is only good on windows right ?
Anyways if that is the case i found this it might be helpful.
http://www.pinvoke.net/default.aspx/user32.mouse_event
and this
https://docs.microsoft.com/en-us/dotnet/framework/ui-automation/ui-automation-and-screen-scaling.
And how does it work for Linux, Mac and Android and other platforms?
Currently only the windows platform is supported.
I want to add something to the screen scaling:
You should set AutoScaleMode to None on a Form containing a MonoGame.Forms control, otherwise the whole drawn content of the control would be misplaced due to the different viewport size.
If you still want to use DPI scaling, then you need to get the current DPI scale factor of the user and scale all control content by that factor. You can catch this factor in your Form class like this:
System.Drawing.SizeF CurrentDPIScaleFactor = AutoScaleFactor;
If you create a more complex editor environment you could split the DPI scaling of MonoGame.Forms controls and different controls, which containing text and other form controls, by using a DockPanel system and only turn the scaling off for a particular DockContent - containing a MonoGame.Forms control, and then dock it to a DockPanel.
I can reccomend this DockPanelSuit for this purpose. Iām using it in the Rogue Engine Editor and itās very nice and easy to work with, but for small editor projects it would be a bit overhelming.
You mean it is like GraphicsDeviceControl? But where is for OpenTK?
This is useful when working with NodeGraphEditors where the automatic invalidations would block the whole NodeGraph.
NuGet: https://www.nuget.org/packages/MonoGame.Forms/1.6.2
Progress Video
https://youtu.be/9PrY6TZn6bI
NodeGraphEditor Test
https://youtu.be/Mg_5vNfaygo
Fixed that on reinitializing a custom control of the type UpdateWindow, the GameLoop function was reatached multiple times to the Application.Idle event, which caused that the Update method in custom controls was also called multiple times accordingly.
Fixed that on reinitializing a custom control of the type UpdateWindow also reinitialized the StopWatch, which sets the elapsed time to 0 and so could possibly cause errors in the GameLoop.
Moved the bool AutomaticInvalidation to the GraphicsDeviceControl as it is used by all custom controls.
Added the protected event Action<SwapChainRenderTarget> to the GraphicsDeviceControl to reflect the changes on window resizing and giving the editor service classes the new SwapChainRenderTarget. This fixes a NullReferenceException when working with RenderTargets in custom controls.
Itās now possible to change the font color of the integrated display.
Do you know if the mousewheel events work properly?
I have the following set up:
protected void MapComponent_OnMouseWheelUpwards(MouseEventArgs e)
{
//do something
}
And I have this in Initialize()
OnMouseWheelUpwards += MapComponent_OnMouseWheelUpwards;
But nothing actually happens when I use the mouse wheel. I noticed similiar code in the MapHost source from the samples, but when running it, the mousewheel also does not do anything.
Yes, it still works for me.
Please check if the mouse cursor is inside the control of the MapHost when using the mouse wheel. The event wonāt be triggered if the mouse cursor is outside of the control.
You could check if the event triggers by placing a breakpoint in the OnMouseWheelUpwards event.
Iāve tried it with the mouse cursor inside the control, and it doesnāt trigger any breakpoints I put on the event. I tried getting a fresh copy of the sample project to make sure I hadnāt made any changes to it as well.
I can get around not using the mouse wheel, but I guess I just found it kinda weird since it looks like it should be working.
Just for clarification: does the OnMouseClick, OnMouseUp, OnMouseDown or OnMouseMove event working for you in the MapHost sample?
Correct. All of those do work, including clicking the mouse wheel button to re-center the map image. It just seems to be scrolling the mouse wheel that isnāt working.