Skip to content

Commit

Permalink
testing window move/resize improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
zaafar committed Dec 6, 2023
1 parent 30847b1 commit a927e4b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
24 changes: 14 additions & 10 deletions ClickableTransparentOverlay/Overlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ public Point Position
{
if (this.window.Dimensions.Location != value)
{
User32.MoveWindow(this.window.Handle, value.X, value.Y, this.window.Dimensions.Width, this.window.Dimensions.Height, true);
this.window.Dimensions.Location = value;
User32.MoveWindow(this.window.Handle, value.X, value.Y, this.window.Dimensions.Width, this.window.Dimensions.Height, true);
}
}
}
Expand All @@ -287,8 +287,8 @@ public Size Size
{
if (this.window.Dimensions.Size != value)
{
User32.MoveWindow(this.window.Handle, this.window.Dimensions.X, this.window.Dimensions.Y, value.Width, value.Height, true);
this.window.Dimensions.Size = value;
User32.MoveWindow(this.window.Handle, this.window.Dimensions.X, this.window.Dimensions.Y, value.Width, value.Height, true);
}
}
}
Expand Down Expand Up @@ -467,15 +467,15 @@ private void ReplaceFontIfRequired()
}
}

private void OnResize()
private void OnResize(int width, int height)
{
if (renderView == null)//first show
{
using var dxgiFactory = device.QueryInterface<IDXGIDevice>().GetParent<IDXGIAdapter>().GetParent<IDXGIFactory>();
var swapchainDesc = new SwapChainDescription()
{
BufferCount = 1,
BufferDescription = new ModeDescription(this.window.Dimensions.Width, this.window.Dimensions.Height, this.format),
BufferDescription = new ModeDescription(width, height, this.format),
Windowed = true,
OutputWindow = this.window.Handle,
SampleDescription = new SampleDescription(1, 0),
Expand All @@ -494,13 +494,13 @@ private void OnResize()
this.renderView.Dispose();
this.backBuffer.Dispose();

this.swapChain.ResizeBuffers(1, this.window.Dimensions.Width, this.window.Dimensions.Height, this.format, SwapChainFlags.None);
this.swapChain.ResizeBuffers(1, width, height, this.format, SwapChainFlags.None);

backBuffer = this.swapChain.GetBuffer<ID3D11Texture2D1>(0);
renderView = this.device.CreateRenderTargetView(backBuffer);
}

this.renderer.Resize(this.window.Dimensions.Width, this.window.Dimensions.Height);
this.renderer.Resize(width, height);
}

private async Task InitializeResources()
Expand Down Expand Up @@ -547,23 +547,27 @@ private async Task InitializeResources()
this.inputhandler = new ImGuiInputHandler(this.window.Handle);
this.overlayIsReady = true;
await this.PostInitialized();
User32.ShowWindow(this.window.Handle, ShowWindowCommand.ShowMaximized);
User32.ShowWindow(this.window.Handle, ShowWindowCommand.Show);
Utils.InitTransparency(this.window.Handle);
}

private bool ProcessMessage(WindowMessage msg, UIntPtr wParam, IntPtr lParam)
{
switch (msg)
{
case WindowMessage.ShowWindow:
this.OnResize(this.window.Dimensions.Width, this.window.Dimensions.Height);
break;
// case WindowMessage.WindowPositionChanged:
// this.OnResize(this.window.Dimensions.Width, this.window.Dimensions.Height);
// break;
case WindowMessage.Size:
switch ((SizeMessage)wParam)
{
case SizeMessage.SIZE_RESTORED:
case SizeMessage.SIZE_MAXIMIZED:
var lp = (int)lParam;
this.window.Dimensions.Width = Utils.Loword(lp);
this.window.Dimensions.Height = Utils.Hiword(lp);
this.OnResize();
this.OnResize(Utils.Loword(lp), Utils.Hiword(lp));
break;
default:
break;
Expand Down
2 changes: 1 addition & 1 deletion Examples/MultiThreadedOverlay/MultiThreadedOverlay.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<PublishAot>true</PublishAot>
</PropertyGroup>
Expand Down

0 comments on commit a927e4b

Please sign in to comment.