mirror of
https://github.com/LorenzCK/OnTopReplica.git
synced 2024-05-10 07:22:29 +12:00
Issue #37: added width/height only command line parameters.
This commit is contained in:
parent
704456e2f6
commit
478adfab19
|
@ -150,7 +150,7 @@ namespace OnTopReplica {
|
|||
//Ensure that the ClientSize of the form is always respected
|
||||
//(not ensured by the WM_SIZING message alone because of rounding errors and the chrome space)
|
||||
if (KeepAspectRatio) {
|
||||
var newHeight = (int)Math.Round(((ClientSize.Width - ExtraPadding.Horizontal) / AspectRatio) + ExtraPadding.Vertical);
|
||||
var newHeight = ComputeHeightFromWidth(ClientSize.Width);
|
||||
ClientSize = new Size(ClientSize.Width, newHeight);
|
||||
}
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ namespace OnTopReplica {
|
|||
|
||||
#endregion
|
||||
|
||||
#region ClientSize/Size conversion helpers
|
||||
#region Conversion helpers
|
||||
|
||||
/// <summary>
|
||||
/// Converts a client size measurement to a window size measurement.
|
||||
|
@ -227,6 +227,20 @@ namespace OnTopReplica {
|
|||
return new Size(size.Width - difference.Width, size.Height - difference.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes height from width value, according to aspect ratio of window.
|
||||
/// </summary>
|
||||
public int ComputeHeightFromWidth(int width) {
|
||||
return (int)Math.Round(((width - ExtraPadding.Horizontal) / AspectRatio) + ExtraPadding.Vertical);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes width from height value, according to aspect ratio of window.
|
||||
/// </summary>
|
||||
public int ComputeWidthFromHeight(int height) {
|
||||
return (int)Math.Round(((height - ExtraPadding.Vertical) * AspectRatio) + ExtraPadding.Horizontal);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -83,9 +83,19 @@ namespace OnTopReplica.StartupOptions {
|
|||
.Add("v|visible", "If set, only clones windows that are visible.", s => {
|
||||
options.MustBeVisible = true;
|
||||
})
|
||||
.Add<Size>("size=", "Target {WIDTH,HEIGHT} of the cloned thumbnail.", s => {
|
||||
.Add<Size>("size=", "Target {WIDTH,HEIGHT} of the cloned thumbnail, or", s => {
|
||||
options.StartSize = s;
|
||||
})
|
||||
.Add<int>("width=", "Target WIDTH of cloned thumbnail, or", i => {
|
||||
if (options.StartSize.HasValue || options.StartHeight.HasValue)
|
||||
return;
|
||||
options.StartWidth = i;
|
||||
})
|
||||
.Add<int>("height=", "Target HEIGHT of cloned thumbnail.", i => {
|
||||
if (options.StartSize.HasValue || options.StartWidth.HasValue)
|
||||
return;
|
||||
options.StartHeight = i;
|
||||
})
|
||||
.Add<Size>("position=", "Target {X,Y} of the OnTopReplica window.", s => {
|
||||
options.StartLocation = new Point(s.Width, s.Height);
|
||||
options.StartPositionLock = null;
|
||||
|
|
|
@ -29,6 +29,10 @@ namespace OnTopReplica.StartupOptions {
|
|||
|
||||
public Size? StartSize { get; set; }
|
||||
|
||||
public int? StartWidth { get; set; }
|
||||
|
||||
public int? StartHeight { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Window cloning
|
||||
|
@ -124,6 +128,21 @@ namespace OnTopReplica.StartupOptions {
|
|||
form.PositionLock = StartPositionLock.Value;
|
||||
}
|
||||
|
||||
//Clone any found handle (this applies thumbnail and aspect ratio)
|
||||
if (handle != null) {
|
||||
form.SetThumbnail(handle, Region);
|
||||
}
|
||||
|
||||
//Adaptive size handling
|
||||
if (!StartSize.HasValue && (StartWidth.HasValue || StartHeight.HasValue)) {
|
||||
if (StartWidth.HasValue) {
|
||||
StartSize = new Size(StartWidth.Value, form.ComputeHeightFromWidth(StartWidth.Value));
|
||||
}
|
||||
else {
|
||||
StartSize = new Size(form.ComputeWidthFromHeight(StartHeight.Value), StartHeight.Value);
|
||||
}
|
||||
}
|
||||
|
||||
//Size and location start values
|
||||
if (StartLocation.HasValue && StartSize.HasValue) {
|
||||
form.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
|
||||
|
@ -139,11 +158,6 @@ namespace OnTopReplica.StartupOptions {
|
|||
form.ClientSize = StartSize.Value;
|
||||
}
|
||||
|
||||
//Clone any found handle
|
||||
if (handle != null) {
|
||||
form.SetThumbnail(handle, Region);
|
||||
}
|
||||
|
||||
//Other features
|
||||
if (EnableClickForwarding) {
|
||||
form.ClickForwardingEnabled = true;
|
||||
|
|
Loading…
Reference in a new issue