Fix the longest bug in the launcher, where dragging something else over top or the window offscreen, caused garbage pixels to appear.

This commit is contained in:
UnknownShadow200 2018-07-12 03:34:05 +10:00
parent aff169862f
commit e683d70144
9 changed files with 46 additions and 164 deletions

View file

@ -59,7 +59,6 @@ namespace ClassicalSharp {
}
Stopwatch render_watch = new Stopwatch();
FrameEventArgs render_args = new FrameEventArgs();
public void Run() {
window.Visible = true;
window.Closed += OnClosed;

View file

@ -1,29 +1,27 @@
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
using System;
using System.Drawing;
using ClassicalSharp;
namespace Launcher.Drawing {
/// <summary> Per-platform class used to transfer a framebuffer directly to the native window. </summary>
public abstract class PlatformDrawer {
/// <summary> Data describing the native window. </summary>
internal OpenTK.Platform.IWindowInfo info;
/// <summary> Initialises the variables for this platform drawer. </summary>
public abstract void Init();
/// <summary> Creates a framebuffer bitmap of the given dimensions. </summary>
public virtual Bitmap CreateFrameBuffer(int width, int height) {
return Platform.CreateBmp(width, height);
}
/// <summary> Updates the variables when the native window changes dimensions. </summary>
public abstract void Resize();
/// <summary> Redraws a portion of the framebuffer to the window. </summary>
/// <remarks> r is only a hint, the entire framebuffer may still be
/// redrawn on some platforms. </remarks>
public abstract void Redraw(Bitmap framebuffer, Rectangle r);
}
}
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
using System;
using System.Drawing;
using ClassicalSharp;
namespace Launcher.Drawing {
/// <summary> Per-platform class used to transfer a framebuffer directly to the native window. </summary>
public abstract class PlatformDrawer {
internal OpenTK.IWindowInfo info;
/// <summary> Initialises the variables for this platform drawer. </summary>
public abstract void Init();
/// <summary> Creates a framebuffer bitmap of the given dimensions. </summary>
public virtual Bitmap CreateFrameBuffer(int width, int height) {
return Platform.CreateBmp(width, height);
}
/// <summary> Updates the variables when the native window changes dimensions. </summary>
public abstract void Resize();
/// <summary> Redraws a portion of the framebuffer to the window. </summary>
/// <remarks> r is only a hint, the entire framebuffer may still be
/// redrawn on some platforms. </remarks>
public abstract void Redraw(Bitmap framebuffer, Rectangle r);
}
}

View file

@ -74,8 +74,9 @@ namespace Launcher {
PlatformDrawer platformDrawer;
public void Init() {
Window.Resize += Resize;
Window.FocusedChanged += FocusedChanged;
Window.FocusedChanged += ForceRedraw;
Window.WindowStateChanged += Resize;
Window.Redraw += ForceRedraw;
Keyboard.KeyDown += KeyDown;
ClassicalSharp.Program.CleanupMainDirectory();
@ -115,15 +116,14 @@ namespace Launcher {
}
}
void FocusedChanged(object sender, EventArgs e) {
if (Program.ShowingErrorDialog) return;
RedrawBackground();
if (Screen != null) Screen.Resize();
}
void Resize(object sender, EventArgs e) {
platformDrawer.Resize();
RedrawBackground();
ForceRedraw(sender, e);
}
void ForceRedraw(object sender, EventArgs e) {
if (Program.ShowingErrorDialog) return;
RedrawBackground();
if (Screen != null) Screen.Resize();
fullRedraw = true;
}
@ -242,8 +242,9 @@ namespace Launcher {
public void Dispose() {
Window.Resize -= Resize;
Window.FocusedChanged -= FocusedChanged;
Window.FocusedChanged -= ForceRedraw;
Window.WindowStateChanged -= Resize;
Window.Redraw -= ForceRedraw;
Keyboard.KeyDown -= KeyDown;
List<FastBitmap> bitmaps = FetchFlagsTask.Bitmaps;

View file

@ -1,48 +0,0 @@
#region License
//
// The Open Toolkit Library License
//
// Copyright (c) 2006 - 2009 the Open Toolkit library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
#endregion
using System;
namespace OpenTK {
/// <summary> Defines the arguments for frame events.
/// A FrameEventArgs instance is only valid for the duration of the relevant event;
/// do not store references to FrameEventArgs outside this event. </summary>
public class FrameEventArgs : EventArgs {
double elapsed;
/// <summary> Gets a <see cref="System.Double"/> that indicates how many seconds of time elapsed since the previous event. </summary>
public double Time {
get { return elapsed; }
internal set {
if (value <= 0)
throw new ArgumentOutOfRangeException("value <= 0");
elapsed = value;
}
}
}
}

View file

@ -1,57 +0,0 @@
#region License
//
// The Open Toolkit Library License
//
// Copyright (c) 2006 - 2009 the Open Toolkit library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
#endregion
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Threading;
using OpenTK.Graphics;
using OpenTK.Input;
using OpenTK.Platform;
namespace OpenTK
{
public enum GameWindowFlags { Default = 0 };
public class GameWindow {
// TODO:
/// <summary> Gets or states the state of the NativeWindow. </summary>
/*public override WindowState WindowState {
get { return base.WindowState; }
set {
base.WindowState = value;
Debug.Print("Updating Context after setting WindowState to {0}", value);
if (Context != null)
Context.Update(WindowInfo);
}
}*/
}
}

View file

@ -31,7 +31,9 @@ using System.Drawing;
using OpenTK.Input;
using OpenTK.Platform;
namespace OpenTK {
namespace OpenTK {
/// <summary> Descibes an OS window. </summary>
public interface IWindowInfo : IDisposable { IntPtr WinHandle { get; } }
/// <summary> Defines the interface for a native window. </summary>
public abstract class INativeWindow : IDisposable {
@ -118,6 +120,11 @@ namespace OpenTK {
protected void RaiseResize() {
if (Resize != null) Resize(this, EventArgs.Empty);
}
public event EventHandler Redraw;
protected void RaiseRedraw() {
if (Redraw != null) Redraw(this, EventArgs.Empty);
}
/// <summary> Occurs when the window is about to close. </summary>
public event EventHandler Closing;

View file

@ -52,8 +52,6 @@
<Compile Include="BindingsBase.cs" />
<Compile Include="Debug.cs" />
<Compile Include="DisplayDevice.cs" />
<Compile Include="FrameEventArgs.cs" />
<Compile Include="GameWindow.cs" />
<Compile Include="Graphics\OpenGL\GL.cs" />
<Compile Include="INativeWindow.cs" />
<Compile Include="Interop.cs" />
@ -74,7 +72,6 @@
<Compile Include="Math\Vector4.cs" />
<Compile Include="Platform\Configuration.cs" />
<Compile Include="Platform\IPlatformFactory.cs" />
<Compile Include="Platform\IWindowInfo.cs" />
<Compile Include="Platform\MacOS\AglContext.cs" />
<Compile Include="Platform\MacOS\Application.cs" />
<Compile Include="Platform\MacOS\CarbonBindings\Agl.cs" />

View file

@ -1,16 +0,0 @@
#region --- License ---
/* Licensed under the MIT/X11 license.
* Copyright (c) 2006-2008 the OpenTK Team.
* This notice may not be removed from any source distribution.
* See license.txt for licensing detailed licensing details.
*/
#endregion
using System;
namespace OpenTK.Platform {
/// <summary> Descibes an OS window. </summary>
public interface IWindowInfo : IDisposable {
IntPtr WinHandle { get; }
}
}

View file

@ -95,6 +95,7 @@ namespace OpenTK.Platform.Windows
break;
case WindowMessage.ERASEBKGND:
RaiseRedraw();
return new IntPtr(1);
case WindowMessage.WINDOWPOSCHANGED: