-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial SDL2 window implementation (#3013)
Initial SDL2 window implementation Co-authored-by: Dean Herbert <pe@ppy.sh>
- Loading branch information
Showing
25 changed files
with
1,677 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using TKVector2 = osuTK.Vector2; | ||
using SNVector2 = System.Numerics.Vector2; | ||
using SDPoint = System.Drawing.Point; | ||
using VPoint = Veldrid.Point; | ||
using SDSize = System.Drawing.Size; | ||
using VWindowState = Veldrid.WindowState; | ||
using TKWindowState = osuTK.WindowState; | ||
|
||
namespace osu.Framework.Extensions | ||
{ | ||
/// <summary> | ||
/// Temporary extension functions for bridging between osuTK, Veldrid, and System.Numerics | ||
/// </summary> | ||
public static class BridgingExtensions | ||
{ | ||
public static TKVector2 ToOsuTK(this SNVector2 vec) => | ||
new TKVector2(vec.X, vec.Y); | ||
|
||
public static SNVector2 ToSystemNumerics(this TKVector2 vec) => | ||
new SNVector2(vec.X, vec.Y); | ||
|
||
public static SNVector2 ToSystemNumerics(this SDSize size) => | ||
new SNVector2(size.Width, size.Height); | ||
|
||
public static SNVector2 ToSystemNumerics(this SDPoint point) => | ||
new SNVector2(point.X, point.Y); | ||
|
||
public static SDSize ToSystemDrawingSize(this SNVector2 vec) => | ||
new SDSize((int)vec.X, (int)vec.Y); | ||
|
||
public static SDPoint ToSystemDrawingPoint(this SNVector2 vec) => | ||
new SDPoint((int)vec.X, (int)vec.Y); | ||
|
||
public static VPoint ToVeldridPoint(this SNVector2 vec) => | ||
new VPoint((int)vec.X, (int)vec.Y); | ||
|
||
public static SNVector2 ToSystemNumerics(this VPoint point) => | ||
new SNVector2(point.X, point.Y); | ||
|
||
public static TKWindowState ToOsuTK(this VWindowState state) | ||
{ | ||
switch (state) | ||
{ | ||
case VWindowState.Normal: | ||
return TKWindowState.Normal; | ||
|
||
case VWindowState.FullScreen: | ||
return TKWindowState.Fullscreen; | ||
|
||
case VWindowState.Maximized: | ||
return TKWindowState.Maximized; | ||
|
||
case VWindowState.Minimized: | ||
return TKWindowState.Minimized; | ||
|
||
case VWindowState.BorderlessFullScreen: | ||
// WARNING: not supported by osuTK.WindowState | ||
return TKWindowState.Fullscreen; | ||
|
||
case VWindowState.Hidden: | ||
// WARNING: not supported by osuTK.WindowState | ||
return TKWindowState.Normal; | ||
} | ||
|
||
return TKWindowState.Normal; | ||
} | ||
|
||
public static VWindowState ToVeldrid(this TKWindowState state) | ||
{ | ||
switch (state) | ||
{ | ||
case TKWindowState.Normal: | ||
return VWindowState.Normal; | ||
|
||
case TKWindowState.Minimized: | ||
return VWindowState.Minimized; | ||
|
||
case TKWindowState.Maximized: | ||
return VWindowState.Maximized; | ||
|
||
case TKWindowState.Fullscreen: | ||
return VWindowState.FullScreen; | ||
} | ||
|
||
// WARNING: some cases not supported by osuTK.WindowState | ||
return VWindowState.Normal; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using osu.Framework.Input.StateChanges; | ||
using osu.Framework.Platform; | ||
using osu.Framework.Statistics; | ||
using TKKey = osuTK.Input.Key; | ||
|
||
namespace osu.Framework.Input.Handlers.Keyboard | ||
{ | ||
public class KeyboardHandler : InputHandler | ||
{ | ||
public override bool IsActive => true; | ||
|
||
public override int Priority => 0; | ||
|
||
public override bool Initialize(GameHost host) | ||
{ | ||
if (!(host.Window is SDLWindow window)) | ||
return false; | ||
|
||
Enabled.BindValueChanged(e => | ||
{ | ||
if (e.NewValue) | ||
{ | ||
window.KeyDown += handleKeyboardEvent; | ||
window.KeyUp += handleKeyboardEvent; | ||
} | ||
else | ||
{ | ||
window.KeyDown -= handleKeyboardEvent; | ||
window.KeyUp -= handleKeyboardEvent; | ||
} | ||
}, true); | ||
|
||
return true; | ||
} | ||
|
||
private void handleKeyboardEvent(KeyboardKeyInput keyEvent) | ||
{ | ||
PendingInputs.Enqueue(keyEvent); | ||
FrameStatistics.Increment(StatisticsCounterType.KeyEvents); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using osu.Framework.Platform; | ||
|
||
namespace osu.Framework.Input.Handlers.Mouse | ||
{ | ||
public class MouseHandler : InputHandler | ||
{ | ||
private Window window; | ||
|
||
public override bool Initialize(GameHost host) | ||
{ | ||
window = host.Window as Window; | ||
|
||
if (window == null) | ||
return false; | ||
|
||
Enabled.BindValueChanged(e => | ||
{ | ||
if (e.NewValue) | ||
{ | ||
window.MouseMove += PendingInputs.Enqueue; | ||
window.MouseDown += PendingInputs.Enqueue; | ||
window.MouseUp += PendingInputs.Enqueue; | ||
window.MouseWheel += PendingInputs.Enqueue; | ||
} | ||
else | ||
{ | ||
window.MouseMove -= PendingInputs.Enqueue; | ||
window.MouseDown -= PendingInputs.Enqueue; | ||
window.MouseUp -= PendingInputs.Enqueue; | ||
window.MouseWheel -= PendingInputs.Enqueue; | ||
} | ||
}, true); | ||
|
||
return true; | ||
} | ||
|
||
public override bool IsActive => true; | ||
|
||
public override int Priority => 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.