[OpenTK] Added NativeWindowBase

This acts as a common base class to INativeWindow implementations and
can be used to reduce code duplication.
This commit is contained in:
thefiddler 2014-04-27 09:20:33 +02:00
parent 495ded54d8
commit 5ba1bf89f1
2 changed files with 203 additions and 0 deletions

View file

@ -797,6 +797,7 @@
<Compile Include="Platform\MacOS\Carbon\Cgl.cs" />
<Compile Include="WindowIcon.cs" />
<Compile Include="Platform\MacOS\Cocoa\NSBitmapFormat.cs" />
<Compile Include="Platform\NativeWindowBase.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>

View file

@ -0,0 +1,202 @@
#region License
//
// NativeWindowBase.cs
//
// Author:
// Stefanos A. <stapostol@gmail.com>
//
// Copyright (c) 2006-2014 Stefanos Apostolopoulos
//
// 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.Diagnostics;
using System.Drawing;
using OpenTK.Input;
namespace OpenTK.Platform
{
abstract class NativeWindowBase : INativeWindow
{
readonly LegacyInputDriver LegacyInputDriver =
new LegacyInputDriver();
public event EventHandler<EventArgs> Move = delegate { };
public event EventHandler<EventArgs> Resize = delegate { };
public event EventHandler<System.ComponentModel.CancelEventArgs> Closing = delegate { };
public event EventHandler<EventArgs> Closed = delegate { };
public event EventHandler<EventArgs> Disposed = delegate { };
public event EventHandler<EventArgs> IconChanged = delegate { };
public event EventHandler<EventArgs> TitleChanged = delegate { };
public event EventHandler<EventArgs> VisibleChanged = delegate { };
public event EventHandler<EventArgs> FocusedChanged = delegate { };
public event EventHandler<EventArgs> WindowBorderChanged = delegate { };
public event EventHandler<EventArgs> WindowStateChanged = delegate { };
public event EventHandler<KeyboardKeyEventArgs> KeyDown = delegate { };
public event EventHandler<KeyPressEventArgs> KeyPress = delegate { };
public event EventHandler<KeyboardKeyEventArgs> KeyUp = delegate { };
public event EventHandler<EventArgs> MouseLeave = delegate { };
public event EventHandler<EventArgs> MouseEnter = delegate { };
public abstract void Close();
public abstract void ProcessEvents();
public abstract Point PointToClient(Point point);
public abstract Point PointToScreen(Point point);
public abstract Icon Icon { get; set; }
public abstract string Title { get; set; }
public abstract bool Focused { get; }
public abstract bool Visible { get; set; }
public abstract bool Exists { get; set; }
public abstract IWindowInfo WindowInfo { get; }
public abstract WindowState WindowState { get; set; }
public abstract WindowBorder WindowBorder { get; set; }
public abstract Rectangle Bounds { get; set; }
public virtual Point Location
{
get
{
return Bounds.Location;
}
set
{
Bounds = new Rectangle(value, Bounds.Size);
}
}
public Size Size
{
get
{
return Bounds.Size;
}
set
{
Bounds = new Rectangle(Bounds.Location, value);
}
}
public int X
{
get
{
return Bounds.X;
}
set
{
Rectangle old = Bounds;
Bounds = new Rectangle(value, old.Y, old.Width, old.Height);
}
}
public int Y
{
get
{
return Bounds.Y;
}
set
{
Rectangle old = Bounds;
Bounds = new Rectangle(old.X, value, old.Width, old.Height);
}
}
public int Width
{
get
{
return ClientSize.Width;
}
set
{
Rectangle old = ClientRectangle;
ClientRectangle = new Rectangle(old.X, old.Y, value, old.Height);
}
}
public int Height
{
get
{
return ClientSize.Height;
}
set
{
Rectangle old = ClientRectangle;
Bounds = new Rectangle(old.X, old.Y, old.Width, value);
}
}
public Rectangle ClientRectangle
{
get
{
return new Rectangle(Point.Empty, ClientSize);
}
set
{
ClientSize = value.Size;
}
}
public abstract Size ClientSize { get; set; }
public virtual IInputDriver InputDriver
{
get
{
return LegacyInputDriver;
}
}
public abstract bool CursorVisible { get; set; }
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize();
}
protected abstract void Dispose(bool disposing);
[Conditional("DEBUG")]
~NativeWindowBase()
{
Debug.Print("NativeWindowBase leaked, did you forget to call Dispose()?");
Dispose(false);
}
}
}