Skip to content

Commit

Permalink
Merge #319, This is the October 2020 update
Browse files Browse the repository at this point in the history
  • Loading branch information
Perksey authored Oct 2, 2020
2 parents 1b304fc + 4ae5a30 commit d3ad8ba
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 7 deletions.
12 changes: 6 additions & 6 deletions build/props/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<LangVersion>8.0</LangVersion>
<PackageReleaseNotes>
Silk.NET September 2020 Update
Silk.NET October 2020 Update

- Add a byte* overload to Glfw.GetError
- Make GlfwProvider throw if Glfw.Init fails
- Update to latest specifications
- Miscellaneous bug fixes and improvements
- Add a BorderSize property and GetFullSize extension method to IWindow for working with window borders.
- Add a Center extension method which will center the window to a monitor.
- Update to latest specifications.
- Miscellaneous bug fixes and improvements.
</PackageReleaseNotes>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageOutputPath>$(MSBuildThisFileDirectory)/../output_packages</PackageOutputPath>
<RepositoryUrl>https://github.com/Ultz/Silk.NET</RepositoryUrl>
<RepositoryType>Git</RepositoryType>
<VersionPrefix>1.6.0</VersionPrefix>
<VersionPrefix>1.7.0</VersionPrefix>
<VersionSuffix Condition="'$(VersionSuffix)' == ''"></VersionSuffix>
<Description>
Silk.NET is a high-speed, advanced library, providing bindings to popular low-level APIs such as OpenGL, OpenCL, OpenAL, GLFW, and Vulkan.
Expand Down
5 changes: 5 additions & 0 deletions src/Lab/MonitorPlayground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ static void Main(string[] args)
}
}
if (input.Keyboards[0].IsKeyPressed(Key.Space))
{
window.Center();
}
if (input.Keyboards[0].IsKeyPressed(Key.Escape))
{
window.Close();
Expand Down
11 changes: 11 additions & 0 deletions src/Windowing/Silk.NET.Windowing.Common/Interfaces/IWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ public interface IWindow : IWindowProperties, IWindowHost, IView
/// </summary>
new bool IsClosing { get; set; }

/// <summary>
/// Gets the distances in screen coordinates from the edges of the content area to the corresponding edges of
/// the full window.
/// </summary>
/// <remarks>
/// Because these are distances and not coordinates, they are always zero or positive.
/// </remarks>
/// <seealso cref="WindowExtensions.GetFullSize"/>
// This is in IWindow because it can't be configured.
Rectangle BorderSize { get; }

/// <summary>
/// Raised when the window is moved.
/// </summary>
Expand Down
29 changes: 29 additions & 0 deletions src/Windowing/Silk.NET.Windowing.Common/WindowExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// of the MIT license. See the LICENSE file for details.

using System;
using System.Drawing;
using Silk.NET.Windowing.Common.Structs;

namespace Silk.NET.Windowing.Common
Expand Down Expand Up @@ -61,6 +62,34 @@ public static void Run(this IView view)
view.Reset();
}

/// <summary>
/// Gets the full size of the given window including its borders.
/// </summary>
/// <param name="window">The window to get size information from.</param>
/// <returns>The full size of the window (including both content area and borders)</returns>
public static Size GetFullSize(this IWindow window) => Size.Add(window.Size, window.BorderSize.Size);

/// <summary>
/// Centers this window to the given monitor or, if null, the current monitor the window's on.
/// </summary>
/// <param name="window">The window to center.</param>
/// <param name="monitor">The specific monitor to center the window to, if any.</param>
public static void Center(this IWindow window, IMonitor? monitor = null)
{
monitor ??= window.Monitor;
var monitorBounds = monitor.Bounds;
var windowFullSize = window.GetFullSize();
window.Position = Point.Add
(
monitorBounds.Location,
new Size
(
monitorBounds.Size.Width / 2 - windowFullSize.Width / 2,
monitorBounds.Size.Height / 2 - windowFullSize.Height / 2
)
);
}

/// <summary>
/// Sets the window icon to default on the given window.
/// </summary>
Expand Down
12 changes: 11 additions & 1 deletion src/Windowing/Silk.NET.Windowing.Desktop/GlfwWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,23 @@ public GlfwWindow(WindowOptions options, GlfwWindow parent, GlfwMonitor monitor)
/// <inheritdoc />
public int RunningSlowTolerance { get; set; }

/// <inheritdoc />
/// <inheritdoc cref="IWindow" />
public unsafe bool IsClosing
{
get => _glfw.WindowShouldClose(_windowPtr);
set => _glfw.SetWindowShouldClose(_windowPtr, value);
}

/// <inheritdoc />
public unsafe Rectangle BorderSize
{
get
{
_glfw.GetWindowFrameSize(_windowPtr, out var l, out var t, out var r, out var b);
return Rectangle.FromLTRB(l, t, r, b);
}
}

/// <inheritdoc />
public bool IsRunningSlowly => _isRunningSlowlyTries > RunningSlowTolerance;

Expand Down

0 comments on commit d3ad8ba

Please sign in to comment.