This project is read-only.

Nuclex in Winform

Oct 13, 2011 at 11:47 PM

How do I include Nuclex UI controls in an application that runs inside a winform ModelViewerControl?  I have a usable GraphicsDevice that the control hands me, but I don't know how to get it to the Nuclex framework.

Or is there a better way to do this?

Thanks,

-Jim

Oct 14, 2011 at 7:30 AM

Check the constructor of the GuiManager class: it requires an IGraphicsDeviceService and an IInputService.

The former should be implemented through the ModelViewerControl. If it isn't, you can use the GraphicsDeviceServiceHelper.MakeDummyGraphicsDeviceService() method from Nuclex.Graphics to create an IGraphicsDeviceService that wraps your GraphicsDevice.

The latter is provided by the InputManager in Nuclex.Input. You could use Nuclex.Input (if this is a windowed game) or pass null to the GuiManager and set a custom IInputCapturer that you implement based on the mouse + keyboard events of the ModelViewerControl.

Oct 14, 2011 at 10:32 PM

Thanks Cygon,  I'll give this a try.

Oct 14, 2011 at 11:23 PM
Edited Oct 14, 2011 at 11:50 PM

This works, but I don't get any events because I setup the Input manager as:

this.input = new InputManager(Services, Window.Handle);

How do you recommend setting up the input manager in this situation?

-Jim

Oct 15, 2011 at 9:42 AM

There should be no problems using the InputManager as long it has access to the handle of the game's main window.

You may be forgetting to call this.input.Update() - the InputManager does not deliver events or change the reported state of the input devices until its Update() method is called.

If it doesn't work after that, then that's a bug. You can also just feed input to the GuiManager yourself by implementing the IInputCapturer interface as I described above.

Oct 17, 2011 at 10:32 PM

Thank you for being so helpful, I really appreciate it.

Can you sketch out how I'd build a custom IInputCapturer? Event's work fine when I pass in the main window handle, but if a click occurs in the ModelViewerControl, its 24 pix off because the main window origin is above the origin of the ModelViewerControl (the menu bar takes up this space).  If I pass in the window handle to the ModelViewerControl, no events register.  So I guess I need to build an IIputCapturer and feed it the events I get from the ModelViewerControl Does this sound right?

Oct 17, 2011 at 10:52 PM

Yep, that sounds about right :)

Building an InputCapturer is easy: Just implement the IInputCapturer interface somewhere (for example, in your ModelViewerControl). It has just one member, a property through which it can be assigned an IInputReceiver. All it has to do is store the reference to that input receiver and feed any events into it.

For example:

class ModelViewerControl : Control, IInputCapturer {

  public IInputReceiver InputReceiver { get; set; }

  protected override void OnMouseMove(MouseEventArgs e) {
    if(InputReceiver != null) {
      InputReceiver.InjectMouseMove(e.X, e.Y);
    }
  }

  protected override void OnMouseDown(MouseEventArgs e) {
    if(InputReceiver != null) {
      InputReceiver.InjectMouseMove(e.X, e.Y);
      InputReceiver.InjectMousePress(e.Button);
    }
  }

  protected override void OnMouseUp(MouseEventArgs e) {
    if(InputReceiver != null) {
      InputReceiver.InjectMouseMove(e.X, e.Y);
      InputReceiver.InjectMouseRelease(e.Button);
    }
  }

}

That probably won't compile as it is because I'm using a different mouse buttons enumeration and floating point coordinates, but I think you get the idea :)

Then, just pass null as the IInputService to the GuiManager constructor and assign your ModelViewerControl to the GuiManager.InputCapturer property as soon as possible.

You don't have to necessarily forward all events to the GUI, so you can go step by step and first see if the mouse works this way and then do the rest.

Oct 28, 2011 at 11:58 PM

One more question, where do I get a valid InputManager?  I need to call it to update.

-Jim