Skip to content

Commit

Permalink
Wpf/WinForms: Fix initial draw of viewport in some cases.
Browse files Browse the repository at this point in the history
- Only subscribe to Paint to update the view (like before)
- Don't override Eto's Control.Shown or SizeChanged event registration, it caused the view to be redrawn many multiple times (and broke those events).
- Update the context during OnPaint() instead of calling OnResize to do the same as it has unintended side effects e.g. causes the view not to show initially.
- Set the background of the WPF control to ControlBrush so it doesn't show unpainted areas when resizing.
  • Loading branch information
cwensley committed Aug 8, 2019
1 parent 1944fef commit 43c5f5a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
7 changes: 4 additions & 3 deletions Eto.OpenTK.WinForms/WinGLUserControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,12 @@ protected override void OnHandleDestroyed(EventArgs e)
protected override void OnPaint(PaintEventArgs e)
{
EnsureValidHandle();
if (context != null)
{
context.Update(windowInfo);
}

base.OnPaint(e);

// prompt view to update when it is repainted
OnResize(EventArgs.Empty);
}

/// <summary>
Expand Down
32 changes: 8 additions & 24 deletions Eto.OpenTK.Wpf/WpfWinGLSurfaceHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class WpfWinGLSurfaceHandler : WindowsFormsHostHandler<WinGLUserControl,
public void CreateWithParams(GraphicsMode mode, int major, int minor, GraphicsContextFlags flags)
{
WinFormsControl = new WinGLUserControl(mode, major, minor, flags);
Control.Focusable = true;
Control.Background = System.Windows.SystemColors.ControlBrush;
}

protected override void Initialize()
Expand All @@ -25,29 +27,15 @@ protected override void Initialize()
HandleEvent(GLSurface.GLDrawEvent);
}

public bool IsInitialized
{
get { return Control.IsInitialized; }
}
public bool IsInitialized => WinFormsControl.IsInitialized;

public void MakeCurrent()
{
WinFormsControl.MakeCurrent();
}
public void MakeCurrent() => WinFormsControl.MakeCurrent();

public void SwapBuffers()
{
WinFormsControl.SwapBuffers();
}

public void updateViewHandler(object sender, EventArgs e)
{
updateView();
}
public void SwapBuffers() => WinFormsControl.SwapBuffers();

public void updateView()
public void UpdateView()
{
if (!Control.IsInitialized)
if (!WinFormsControl.IsInitialized)
return;

MakeCurrent();
Expand All @@ -68,12 +56,8 @@ public override void AttachEvent(string id)
WinFormsControl.ShuttingDown += (sender, e) => Callback.OnShuttingDown(Widget, e);
break;

case GLSurface.ShownEvent:
case GLSurface.SizeChangedEvent:
case GLSurface.GLDrawEvent:
WinFormsControl.SizeChanged += updateViewHandler;
WinFormsControl.Paint += updateViewHandler;
//Control.Resize += (sender, e) => Callback.OnDraw(Widget, EventArgs.Empty);
WinFormsControl.Paint += (sender, e) => UpdateView();
break;

default:
Expand Down

0 comments on commit 43c5f5a

Please sign in to comment.