picoe / Eto.OpenTK

Eto OpenGL viewport (C#)
MIT License
24 stars 41 forks source link

WPF with WindowsFormsHost #10

Closed j4m3z0r closed 7 years ago

j4m3z0r commented 7 years ago

Adds support for WPF by using the GLControl inside a WindowsFormsHost. Have also added LICENSE and AUTHORS files so as to explicitly grant a license to use these changes.

philstopford commented 7 years ago

The test application doesn't seem to draw populated viewports with this, from local testing. I've merged it, but haven't had time to understand why the corresponding 'TestEtoGl.WPF_WinformsHost' project isn't happy yet.

philstopford commented 7 years ago

My build and the related code are here : https://www.dropbox.com/s/xxy3qa2c0jihn6b/etoViewport-WPF_WIP.zip?dl=0 - as mentioned, I don't get the viewports drawing correctly. I'm curious whether this shows up on a different Windows system, but don't have one available.

j4m3z0r commented 7 years ago

Hey Phil,

I'm pretty busy today (it's my wedding anniversary), but I'll try to take a look at this tomorrow. I'll also send over my build so we can get that data point too.

Thanks for sticking with this. I really need this capability, so appreciate all the time you're spending on it. Not sure where you're located, but if you happen to be in the Bay Area ever, let me know and I'll gladly buy you a beer!

Cheers,

James.

On Sat, Jun 10, 2017 at 9:55 AM philstopford notifications@github.com wrote:

My build and the related code are here : https://www.dropbox.com/s/xxy3qa2c0jihn6b/etoViewport-WPF_WIP.zip?dl=0 - as mentioned, I don't get the viewports drawing correctly. I'm curious whether this shows up on a different Windows system, but don't have one available.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/philstopford/etoViewport/pull/10#issuecomment-307577169, or mute the thread https://github.com/notifications/unsubscribe-auth/ADahgwcdqdwBkVQ7brnRHDMzC1ZxWYDYks5sCsqRgaJpZM4NwoHE .

j4m3z0r commented 7 years ago

Hi Phil,

I just downloaded your zipfile and went and ran the .exe that was in the bin/Debug directory. There's some glitches where it will initialize such that the viewport initially contains a snapshot of what's underneath (my wallpaper in this instance), but I can click run and it renders as I'd expect. Here's a screenshot:

image

philstopford commented 7 years ago

Ideally, the viewport should scale to fill the divided region, reacting to the size when it is changed. To match the other implementations, it should also have hotkey and mouse handlers (wheel and drag). It wasn't clear to me how to wrangle these aspects On Sun, 11 Jun 2017 at 13:24, James Gregory notifications@github.com wrote:

Hi Phil,

I just downloaded your zipfile and went and ran the .exe that was in the bin/Debug directory. There's some glitches where it will initialize such that the viewport initially contains a snapshot of what's underneath (my wallpaper in this instance), but I can click run and it renders as I'd expect. Here's a screenshot:

[image: image] https://user-images.githubusercontent.com/3580291/27014206-f16ce982-4ea8-11e7-8fb9-f2230d4eec7a.png

— You are receiving this because you modified the open/close state.

Reply to this email directly, view it on GitHub https://github.com/philstopford/etoViewport/pull/10#issuecomment-307654390, or mute the thread https://github.com/notifications/unsubscribe-auth/AB5Fa6VxkeBWBHglt-dNp_uUcTHu38Y5ks5sDE0JgaJpZM4NwoHE .

j4m3z0r commented 7 years ago

Ok, so some progress here. Haven't tested inside your test app yet, but this gets me sensible scaling behavior in my app:

                case GLSurface.GLDrawEvent:
                    Control.glControl.Paint += (sender, e) =>
                    {
                        Control.glControl.MakeCurrent();
                        GL.Viewport(Control.glControl.ClientSize);
                        Callback.OnDraw(Widget, EventArgs.Empty);
                        Control.glControl.SwapBuffers();
                    };
                    break;

(in WPFWFGLSurfaceHandler.AttachEvent).

I'm not crazy about this solution, but I believe it will at least make WPF work the same as the other platforms. What do you think?

Haven't yet started looking at keyboard handlers, but this looks interesting:

https://github.com/mono/opentk/blob/master/Source/Examples/OpenTK/GLControl/GLControlGameLoop.cs

            glControl.KeyDown += new KeyEventHandler(glControl_KeyDown);

etc.

philstopford commented 7 years ago

That kind of works except the viewport goes black again when the divider is moved. I've tried also using this same code for OnSizeChanged, OnShown, but it doesn't force an update. Additionally, it seems like the viewports don't draw correctly at application startup. I'm hoping that there might be a common infrastructure tweak that would hit all of these small issues at once, but it's not yet clear to me what that is:

case GLSurface.ShownEvent: case GLSurface.SizeChangedEvent: case GLSurface.GLDrawEvent: Control.glControl.Paint += (sender, e) => { Control.glControl.MakeCurrent(); GL.Viewport(Control.glControl.ClientSize); Callback.OnDraw(Widget, EventArgs.Empty); Control.glControl.SwapBuffers(); }; break;

philstopford commented 7 years ago

Still at a loss for the keyboard / mouse event handlers. The advice from the gitter chat was :

Add a property to GLSurface, GLSurface.IHandler, and each of the GLSurfaceHandler implementations. GLSurface err.. the GLSurface property would be something like public TheSettingInstance Settings => Handler.Settings; Note that you are actually subscribing your Paint event potentially three times with that code. if someone uses the Shown event, SizeChanged event, and GLDraw event in GLSurface it'll call that code each time.

However, I am struggling.

j4m3z0r commented 7 years ago

Hey Phil,

I've been working on other parts of my app so I haven't had a chance to look at this. I expect I'll need this functionality pretty soon though, so I expect to take a look soon.

philstopford commented 7 years ago

No great rush from my side. I've been made to feel rather stupid sticking my toes into the WPF side of things - UI code isn't my favorite, it turns out - so I'm very grateful for your efforts here.

philstopford commented 7 years ago

By the way, I'll be in mountain view from Aug 21 to 25 :)

j4m3z0r commented 7 years ago

Awesome! If you've got time, I'd love to meet up. Couldn't see your email on your github profile, so send me an email and we'll set something up. I'm james@james.id.au

Cheers,

James.

On Thu, Aug 10, 2017 at 8:17 AM philstopford notifications@github.com wrote:

By the way, I'll be in mountain view from Aug 21 to 25 :)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/philstopford/etoViewport/pull/10#issuecomment-321582943, or mute the thread https://github.com/notifications/unsubscribe-auth/ADahgwfDzlctzdUmuzkKlp9bE_PhC86Eks5sWx8igaJpZM4NwoHE .

philstopford commented 6 years ago

I wondered if there might be a better approach, using the same hosting strategy. By hosting the WinForms etoViewport inside WPF, we'd have the handlers, etc. all set up in the right place and have accessibility to the methods we need. However, I'm not sure how to pass down from the WPF layer to the WinForms layer. This is with a mind to enable keyboard and mouse navigating with the OpenGL view. Any ideas? :)