mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-08-05 05:51:01 +00:00
Add initial d&d support for GameWindow. Add SDL2 d&d support
This commit is contained in:
parent
1e73f38ecd
commit
e792bd80fe
|
@ -285,6 +285,7 @@ namespace OpenTK
|
||||||
//event EventHandler<MouseEventArgs> MouseClick;
|
//event EventHandler<MouseEventArgs> MouseClick;
|
||||||
//event EventHandler<MouseEventArgs> MouseDoubleClick;
|
//event EventHandler<MouseEventArgs> MouseDoubleClick;
|
||||||
|
|
||||||
|
event EventHandler<OpenTK.Input.DropEventArgs> Drop;
|
||||||
//event EventHandler<DragEventArgs> DragDrop;
|
//event EventHandler<DragEventArgs> DragDrop;
|
||||||
//event EventHandler<DragEventArgs> DragEnter;
|
//event EventHandler<DragEventArgs> DragEnter;
|
||||||
//event EventHandler<DragEventArgs> DragOver;
|
//event EventHandler<DragEventArgs> DragOver;
|
||||||
|
|
51
src/OpenTK/Input/DropEventArgs.cs
Normal file
51
src/OpenTK/Input/DropEventArgs.cs
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
#region License
|
||||||
|
//
|
||||||
|
// ConfigurationType.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;
|
||||||
|
|
||||||
|
namespace OpenTK.Input
|
||||||
|
{
|
||||||
|
public class DropEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
string drop_string;
|
||||||
|
public DropEventArgs () { }
|
||||||
|
|
||||||
|
public string DropString
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return drop_string;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
drop_string = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -709,6 +709,11 @@ namespace OpenTK
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler<MouseWheelEventArgs> MouseWheel = delegate { };
|
public event EventHandler<MouseWheelEventArgs> MouseWheel = delegate { };
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs whenever a file dropped in window;
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler<DropEventArgs> Drop = delegate { };
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -981,6 +986,11 @@ namespace OpenTK
|
||||||
MouseWheel(this, e);
|
MouseWheel(this, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual void OnDrop(DropEventArgs e)
|
||||||
|
{
|
||||||
|
Drop(this, e);
|
||||||
|
}
|
||||||
|
|
||||||
#region OnResize
|
#region OnResize
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1142,6 +1152,8 @@ namespace OpenTK
|
||||||
private void OnMouseMoveInternal(object sender, MouseMoveEventArgs e) { OnMouseMove(e); }
|
private void OnMouseMoveInternal(object sender, MouseMoveEventArgs e) { OnMouseMove(e); }
|
||||||
private void OnMouseWheelInternal(object sender, MouseWheelEventArgs e) { OnMouseWheel(e); }
|
private void OnMouseWheelInternal(object sender, MouseWheelEventArgs e) { OnMouseWheel(e); }
|
||||||
|
|
||||||
|
private void OnDropInternal(object sender, DropEventArgs e) { OnDrop(e); }
|
||||||
|
|
||||||
#region OnMoveInternal
|
#region OnMoveInternal
|
||||||
|
|
||||||
private void OnMoveInternal(object sender, EventArgs e) { OnMove(e); }
|
private void OnMoveInternal(object sender, EventArgs e) { OnMove(e); }
|
||||||
|
@ -1214,6 +1226,7 @@ namespace OpenTK
|
||||||
implementation.VisibleChanged += OnVisibleChangedInternal;
|
implementation.VisibleChanged += OnVisibleChangedInternal;
|
||||||
implementation.WindowBorderChanged += OnWindowBorderChangedInternal;
|
implementation.WindowBorderChanged += OnWindowBorderChangedInternal;
|
||||||
implementation.WindowStateChanged += OnWindowStateChangedInternal;
|
implementation.WindowStateChanged += OnWindowStateChangedInternal;
|
||||||
|
implementation.Drop += OnDropInternal;
|
||||||
events = true;
|
events = true;
|
||||||
}
|
}
|
||||||
else if (events)
|
else if (events)
|
||||||
|
@ -1238,6 +1251,7 @@ namespace OpenTK
|
||||||
implementation.VisibleChanged -= OnVisibleChangedInternal;
|
implementation.VisibleChanged -= OnVisibleChangedInternal;
|
||||||
implementation.WindowBorderChanged -= OnWindowBorderChangedInternal;
|
implementation.WindowBorderChanged -= OnWindowBorderChangedInternal;
|
||||||
implementation.WindowStateChanged -= OnWindowStateChangedInternal;
|
implementation.WindowStateChanged -= OnWindowStateChangedInternal;
|
||||||
|
implementation.Drop -= OnDropInternal;
|
||||||
events = false;
|
events = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -795,6 +795,7 @@
|
||||||
<Compile Include="Platform\Linux\Bindings\Evdev.cs" />
|
<Compile Include="Platform\Linux\Bindings\Evdev.cs" />
|
||||||
<Compile Include="Platform\Linux\DefaultCursor.cs" />
|
<Compile Include="Platform\Linux\DefaultCursor.cs" />
|
||||||
<Compile Include="Platform\Linux\Bindings\Kms.cs" />
|
<Compile Include="Platform\Linux\Bindings\Kms.cs" />
|
||||||
|
<Compile Include="Input\DropEventArgs.cs" />
|
||||||
<None Include="OpenTK.csproj.paket.template" />
|
<None Include="OpenTK.csproj.paket.template" />
|
||||||
<None Include="paket.references" />
|
<None Include="paket.references" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -53,6 +53,8 @@ namespace OpenTK.Platform
|
||||||
readonly KeyboardKeyEventArgs KeyUpArgs = new KeyboardKeyEventArgs();
|
readonly KeyboardKeyEventArgs KeyUpArgs = new KeyboardKeyEventArgs();
|
||||||
readonly KeyPressEventArgs KeyPressArgs = new KeyPressEventArgs((char)0);
|
readonly KeyPressEventArgs KeyPressArgs = new KeyPressEventArgs((char)0);
|
||||||
|
|
||||||
|
readonly DropEventArgs DropArgs = new DropEventArgs();
|
||||||
|
|
||||||
// In order to simplify mouse event implementation,
|
// In order to simplify mouse event implementation,
|
||||||
// we can store the current mouse state here.
|
// we can store the current mouse state here.
|
||||||
protected MouseState MouseState = new MouseState();
|
protected MouseState MouseState = new MouseState();
|
||||||
|
@ -156,6 +158,13 @@ namespace OpenTK.Platform
|
||||||
KeyUp(this, e);
|
KeyUp(this, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void OnDrop(string s)
|
||||||
|
{
|
||||||
|
var e = DropArgs;
|
||||||
|
DropArgs.DropString = s;
|
||||||
|
Drop(this, e);
|
||||||
|
}
|
||||||
|
|
||||||
/// \internal
|
/// \internal
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Call this method to simulate KeyDown/KeyUp events
|
/// Call this method to simulate KeyDown/KeyUp events
|
||||||
|
@ -318,6 +327,7 @@ namespace OpenTK.Platform
|
||||||
public event EventHandler<MouseButtonEventArgs> MouseUp = delegate { };
|
public event EventHandler<MouseButtonEventArgs> MouseUp = delegate { };
|
||||||
public event EventHandler<MouseMoveEventArgs> MouseMove = delegate { };
|
public event EventHandler<MouseMoveEventArgs> MouseMove = delegate { };
|
||||||
public event EventHandler<MouseWheelEventArgs> MouseWheel = delegate { };
|
public event EventHandler<MouseWheelEventArgs> MouseWheel = delegate { };
|
||||||
|
public event EventHandler<DropEventArgs> Drop = delegate { };
|
||||||
|
|
||||||
public abstract void Close();
|
public abstract void Close();
|
||||||
|
|
||||||
|
|
|
@ -1442,6 +1442,8 @@ namespace OpenTK.Platform.SDL2
|
||||||
public ControllerButtonEvent ControllerButton;
|
public ControllerButtonEvent ControllerButton;
|
||||||
[FieldOffset(0)]
|
[FieldOffset(0)]
|
||||||
public ControllerDeviceEvent ControllerDevice;
|
public ControllerDeviceEvent ControllerDevice;
|
||||||
|
[FieldOffset(0)]
|
||||||
|
public DropEvent Drop;
|
||||||
#if false
|
#if false
|
||||||
[FieldOffset(0)]
|
[FieldOffset(0)]
|
||||||
public QuitEvent quit;
|
public QuitEvent quit;
|
||||||
|
@ -1755,6 +1757,14 @@ namespace OpenTK.Platform.SDL2
|
||||||
public Int32 Data2;
|
public Int32 Data2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct DropEvent
|
||||||
|
{
|
||||||
|
public UInt32 Type;
|
||||||
|
public UInt32 Timestamp;
|
||||||
|
public IntPtr File;
|
||||||
|
public UInt32 WindowID;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -197,6 +197,14 @@ namespace OpenTK.Platform.SDL2
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case EventType.DROPFILE:
|
||||||
|
if (windows.TryGetValue(ev.Drop.WindowID, out window))
|
||||||
|
{
|
||||||
|
ProcessDropEvent(window, ev.Drop);
|
||||||
|
processed = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case EventType.QUIT:
|
case EventType.QUIT:
|
||||||
Debug.WriteLine("Sdl2 application quit");
|
Debug.WriteLine("Sdl2 application quit");
|
||||||
break;
|
break;
|
||||||
|
@ -293,6 +301,20 @@ namespace OpenTK.Platform.SDL2
|
||||||
window.OnMouseWheel(ev.X, ev.Y);
|
window.OnMouseWheel(ev.X, ev.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static unsafe void ProcessDropEvent(Sdl2NativeWindow window, DropEvent ev)
|
||||||
|
{
|
||||||
|
byte* str = (byte*)ev.File;
|
||||||
|
|
||||||
|
int length = 0;
|
||||||
|
for (; str[length] != 0; length++)
|
||||||
|
;
|
||||||
|
|
||||||
|
byte [] byteArray = new byte[length];
|
||||||
|
Marshal.Copy(ev.File, byteArray, 0, length);
|
||||||
|
string dropString = System.Text.Encoding.UTF8.GetString (byteArray);
|
||||||
|
window.OnDrop(dropString);
|
||||||
|
}
|
||||||
|
|
||||||
static void ProcessWindowEvent(Sdl2NativeWindow window, WindowEvent e)
|
static void ProcessWindowEvent(Sdl2NativeWindow window, WindowEvent e)
|
||||||
{
|
{
|
||||||
switch (e.Event)
|
switch (e.Event)
|
||||||
|
|
Loading…
Reference in a new issue