Skip to content

Commit

Permalink
added more overloaded constructors to support variable initial window…
Browse files Browse the repository at this point in the history
… size
  • Loading branch information
zaafar committed May 2, 2024
1 parent f5fd6bf commit 8af37d3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
63 changes: 59 additions & 4 deletions ClickableTransparentOverlay/Overlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public abstract class Overlay : IDisposable
{
private readonly string title;
private readonly Format format;
private readonly int initialWindowWidth;
private readonly int initialWindowHeight;

private WNDCLASSEX wndClass;
private Win32Window window;
Expand Down Expand Up @@ -88,8 +90,61 @@ public Overlay(bool DPIAware) : this("Overlay", DPIAware)
/// <param name="DPIAware">
/// should the overlay scale with windows scale value or not.
/// </param>
public Overlay(string windowTitle, bool DPIAware)
public Overlay(string windowTitle, bool DPIAware) : this(windowTitle, DPIAware, 800, 600)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="Overlay"/> class.
/// </summary>
/// <param name="windowWidth">
/// width to use when creating the clickable transparent overlay window
/// </param>
/// <param name="windowHeight">
/// height to use when creating the clickable transparent overlay window
/// </param>
public Overlay(int windowWidth, int windowHeight) : this("Overlay", windowWidth, windowHeight)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="Overlay"/> class.
/// </summary>
/// <param name="windowTitle">
/// Title of the window created by the overlay
/// </param>
/// <param name="windowWidth">
/// width to use when creating the clickable transparent overlay window
/// </param>
/// <param name="windowHeight">
/// height to use when creating the clickable transparent overlay window
/// </param>
public Overlay(string windowTitle, int windowWidth, int windowHeight) : this(windowTitle, false, windowWidth, windowHeight)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="Overlay"/> class.
/// </summary>
/// <param name="windowTitle">
/// Title of the window created by the overlay
/// </param>
/// <param name="DPIAware">
/// should the overlay scale with windows scale value or not.
/// </param>
/// <param name="vsync">
/// vsync is enabled if true otherwise disabled.
/// </param>
/// <param name="windowWidth">
/// width to use when creating the clickable transparent overlay window
/// </param>
/// <param name="windowHeight">
/// height to use when creating the clickable transparent overlay window
/// </param>
public Overlay(string windowTitle, bool DPIAware, int windowWidth, int windowHeight)
{
this.initialWindowWidth = windowWidth;
this.initialWindowHeight = windowHeight;
this.VSync = true;
this._disposedValue = false;
this.overlayIsReady = false;
Expand Down Expand Up @@ -536,14 +591,14 @@ private async Task InitializeResources()

this.window = new Win32Window(
wndClass.ClassName,
800,
600,
this.initialWindowWidth,
this.initialWindowHeight,
0,
0,
this.title,
WindowStyles.WS_POPUP,
WindowExStyles.WS_EX_ACCEPTFILES | WindowExStyles.WS_EX_TOPMOST);
this.renderer = new ImGuiRenderer(device, deviceContext, 800, 600);
this.renderer = new ImGuiRenderer(device, deviceContext, this.initialWindowWidth, this.initialWindowHeight);
this.inputhandler = new ImGuiInputHandler(this.window.Handle);
this.overlayIsReady = true;
await this.PostInitialized();
Expand Down
5 changes: 5 additions & 0 deletions Examples/SimpleExample/SampleOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

internal class SampleOverlay : Overlay
{
public SampleOverlay()
: base(3840, 2160)
{
}

private bool wantKeepDemoWindow = true;
protected override Task PostInitialized()
{
Expand Down

0 comments on commit 8af37d3

Please sign in to comment.