mirror of
https://github.com/LorenzCK/OnTopReplica.git
synced 2024-06-03 11:04:32 +12:00
Bug fix to recent changes: region selection works and aspect ratio is maintained correctly.
This commit is contained in:
parent
95d4a9bd1d
commit
5c47783de1
|
@ -43,15 +43,30 @@ namespace OnTopReplica {
|
|||
}
|
||||
}
|
||||
|
||||
Padding _extraPadding;
|
||||
public Padding ExtraPadding {
|
||||
get {
|
||||
return _extraPadding;
|
||||
}
|
||||
set {
|
||||
_extraPadding = value;
|
||||
|
||||
if(KeepAspectRatio)
|
||||
RefreshAspectRatio();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Forces the form to update its height based on the current aspect ratio setting.
|
||||
/// </summary>
|
||||
public void RefreshAspectRatio() {
|
||||
ClientSize = new Size(ClientSize.Width, (int)(ClientSize.Width / AspectRatio));
|
||||
Console.WriteLine("Refreshing, size " + ClientSize.ToString() + " padding " + ExtraPadding.ToString());
|
||||
ClientSize = new Size(ClientSize.Width,
|
||||
(int)((ClientSize.Width - ExtraPadding.Horizontal) / AspectRatio) + ExtraPadding.Vertical);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the aspect ratio of the form and refreshes it.
|
||||
/// Updates the aspect ratio of the form and forces a refresh.
|
||||
/// </summary>
|
||||
public void SetAspectRatio(Size aspectRatioSource) {
|
||||
_keepAspectRatio = true; //set without updating
|
||||
|
@ -70,7 +85,7 @@ namespace OnTopReplica {
|
|||
|
||||
if (res == NativeMethods.WMSZ_LEFT || res == NativeMethods.WMSZ_RIGHT) {
|
||||
//Left or right resize -> adjust height (bottom)
|
||||
int targetHeight = (int)Math.Ceiling(this.Width / AspectRatio);
|
||||
int targetHeight = (int)Math.Ceiling((Width - ExtraPadding.Horizontal) / AspectRatio) + ExtraPadding.Vertical;
|
||||
int originalHeight = rc.Bottom - rc.Top;
|
||||
int diffHeight = originalHeight - targetHeight;
|
||||
|
||||
|
@ -79,28 +94,20 @@ namespace OnTopReplica {
|
|||
}
|
||||
else if (res == NativeMethods.WMSZ_TOP || res == NativeMethods.WMSZ_BOTTOM) {
|
||||
//Up or down resize -> adjust width (right)
|
||||
int targetWidth = (int)Math.Ceiling(this.Height * AspectRatio);
|
||||
int targetWidth = (int)Math.Ceiling((Height - ExtraPadding.Vertical) * AspectRatio) + ExtraPadding.Horizontal;
|
||||
int originalWidth = rc.Right - rc.Left;
|
||||
int diffWidth = originalWidth - targetWidth;
|
||||
|
||||
rc.Left += (diffWidth / 2);
|
||||
rc.Right = rc.Left + targetWidth;
|
||||
}
|
||||
else if (res == NativeMethods.WMSZ_RIGHT + NativeMethods.WMSZ_BOTTOM) {
|
||||
//Lower-right corner resize -> adjust height (could have been width)
|
||||
rc.Bottom = rc.Top + (int)Math.Ceiling(this.Width / AspectRatio);
|
||||
else if (res == NativeMethods.WMSZ_RIGHT + NativeMethods.WMSZ_BOTTOM || res == NativeMethods.WMSZ_LEFT + NativeMethods.WMSZ_BOTTOM) {
|
||||
//Lower-right/left corner resize -> adjust height (could have been width)
|
||||
rc.Bottom = rc.Top + (int)Math.Ceiling((Width - ExtraPadding.Horizontal) / AspectRatio) + ExtraPadding.Vertical;
|
||||
}
|
||||
else if (res == NativeMethods.WMSZ_LEFT + NativeMethods.WMSZ_BOTTOM) {
|
||||
//Lower-left corner resize -> adjust height (could have been width)
|
||||
rc.Bottom = rc.Top + (int)Math.Ceiling(this.Width / AspectRatio);
|
||||
}
|
||||
else if (res == NativeMethods.WMSZ_LEFT + NativeMethods.WMSZ_TOP) {
|
||||
//Upper-left corner -> adjust width (could have been height)
|
||||
rc.Left = rc.Right - (int)Math.Ceiling(this.Height * AspectRatio);
|
||||
}
|
||||
else if (res == NativeMethods.WMSZ_RIGHT + NativeMethods.WMSZ_TOP) {
|
||||
//Upper-right corner -> adjust width (could have been height)
|
||||
rc.Right = rc.Left + (int)Math.Ceiling(this.Height * AspectRatio);
|
||||
else if (res == NativeMethods.WMSZ_LEFT + NativeMethods.WMSZ_TOP || res == NativeMethods.WMSZ_RIGHT + NativeMethods.WMSZ_TOP) {
|
||||
//Upper-left/right corner -> adjust width (could have been height)
|
||||
rc.Top = rc.Bottom - (int)Math.Ceiling((Width - ExtraPadding.Horizontal) / AspectRatio) + ExtraPadding.Vertical;
|
||||
}
|
||||
|
||||
Marshal.StructureToPtr(rc, m.LParam, true);
|
||||
|
|
2
OnTopReplica/MainForm.Designer.cs
generated
2
OnTopReplica/MainForm.Designer.cs
generated
|
@ -466,7 +466,7 @@
|
|||
this.ControlBox = false;
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.MinimumSize = new System.Drawing.Size(39, 40);
|
||||
this.MinimumSize = new System.Drawing.Size(200, 205);
|
||||
this.Name = "MainForm";
|
||||
this.ShowInTaskbar = false;
|
||||
this.TopMost = true;
|
||||
|
|
|
@ -40,6 +40,8 @@ namespace OnTopReplica
|
|||
public MainForm() {
|
||||
InitializeComponent();
|
||||
|
||||
KeepAspectRatio = false;
|
||||
|
||||
//Thumbnail panel
|
||||
_thumbnailPanel = new ThumbnailPanel(Settings.Default.UseGlass);
|
||||
_thumbnailPanel.RegionDrawn += new ThumbnailPanel.RegionDrawnHandler(Thumbnail_RegionDrawn);
|
||||
|
@ -85,6 +87,7 @@ namespace OnTopReplica
|
|||
|
||||
void RegionBox_RegionChanged(object sender, Rectangle region) {
|
||||
_thumbnailPanel.ShownRegion = region;
|
||||
SetAspectRatio(region.Size);
|
||||
}
|
||||
|
||||
void RegionBox_RequestRegionReset(object sender, EventArgs e) {
|
||||
|
@ -120,65 +123,55 @@ namespace OnTopReplica
|
|||
return _regionBoxShowing;
|
||||
}
|
||||
set {
|
||||
if (_regionBoxShowing != value) {
|
||||
_regionBoxShowing = value;
|
||||
if (_regionBoxShowing != value) {
|
||||
//Show box
|
||||
_regionBoxShowing = value;
|
||||
_regionBox.Visible = value;
|
||||
_regionBox.Enabled = value;
|
||||
|
||||
//Show box
|
||||
_regionBox.Visible = value;
|
||||
_regionBox.Enabled = value;
|
||||
//Disable dragging
|
||||
HandleMouseMove = !value;
|
||||
|
||||
//Disable dragging
|
||||
HandleMouseMove = !value;
|
||||
//Enable region drawing on thumbnail
|
||||
_thumbnailPanel.DrawMouseRegions = value;
|
||||
|
||||
//Enable region drawing on thumbnail
|
||||
_thumbnailPanel.DrawMouseRegions = value;
|
||||
//Pad form and resize it
|
||||
ClientSize = new Size {
|
||||
Width = ClientSize.Width + ((value) ? _regionBox.Width : -_regionBox.Width),
|
||||
Height = Math.Max(ClientSize.Height, _regionBox.ClientSize.Height)
|
||||
};
|
||||
ExtraPadding = (value) ? new Padding(0, 0, _regionBox.Width, 0) : new Padding(0);
|
||||
|
||||
//Resize and move to fit region panel
|
||||
ClientSize = new Size {
|
||||
Width = ClientSize.Width + ((value) ? _regionBox.Width : -_regionBox.Width),
|
||||
Height = Math.Max(ClientSize.Height, _regionBox.ClientSize.Height)
|
||||
};
|
||||
_thumbnailPanel.Size = new Size {
|
||||
Width = (value) ? (ClientSize.Width - _regionBox.Width) : ClientSize.Width,
|
||||
Height = ClientSize.Height
|
||||
};
|
||||
_regionBox.Location = new Point {
|
||||
X = (value) ? (ClientSize.Width - _regionBox.Width) : ClientSize.Width,
|
||||
Y = 0
|
||||
};
|
||||
//Resize and move panels
|
||||
_thumbnailPanel.Size = new Size {
|
||||
Width = (value) ? (ClientSize.Width - _regionBox.Width) : ClientSize.Width,
|
||||
Height = ClientSize.Height
|
||||
};
|
||||
_regionBox.Location = new Point {
|
||||
X = (value) ? (ClientSize.Width - _regionBox.Width) : ClientSize.Width,
|
||||
Y = 0
|
||||
};
|
||||
|
||||
//Disable aspect ratio keeping
|
||||
KeepAspectRatio = !value;
|
||||
//Check form boundaries and move form if necessary
|
||||
if (value) {
|
||||
var screenCurr = Screen.FromControl(this);
|
||||
int pRight = Location.X + Size.Width + cWindowBoundary;
|
||||
if (pRight >= screenCurr.Bounds.Width) {
|
||||
_regionBoxPrevFormLocation = Location;
|
||||
_regionBoxDidMoveForm = true;
|
||||
|
||||
//Set new glass margins
|
||||
this.GlassMargins = (value) ?
|
||||
new Margins(ClientSize.Width - _regionBox.Width, 0, 0, 0) :
|
||||
new Margins(-1);
|
||||
|
||||
//Check form boundaries and move form if necessary
|
||||
if (value) {
|
||||
var screenCurr = Screen.FromControl(this);
|
||||
int pRight = Location.X + Size.Width + cWindowBoundary;
|
||||
if (pRight >= screenCurr.Bounds.Width) {
|
||||
_regionBoxPrevFormLocation = Location;
|
||||
_regionBoxDidMoveForm = true;
|
||||
|
||||
Location = new Point(screenCurr.WorkingArea.Width - Size.Width - cWindowBoundary, Location.Y);
|
||||
}
|
||||
else
|
||||
_regionBoxDidMoveForm = false;
|
||||
}
|
||||
else {
|
||||
if (_regionBoxDidMoveForm) {
|
||||
Location = _regionBoxPrevFormLocation;
|
||||
_regionBoxDidMoveForm = false;
|
||||
}
|
||||
|
||||
//Resize automatically on region box closing
|
||||
/*if (Settings.Default.AutoFitOnResize)
|
||||
FitToThumbnail();*/
|
||||
}
|
||||
}
|
||||
Location = new Point(screenCurr.WorkingArea.Width - Size.Width - cWindowBoundary, Location.Y);
|
||||
}
|
||||
else
|
||||
_regionBoxDidMoveForm = false;
|
||||
}
|
||||
else {
|
||||
if (_regionBoxDidMoveForm) {
|
||||
Location = _regionBoxPrevFormLocation;
|
||||
_regionBoxDidMoveForm = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -210,9 +203,16 @@ namespace OnTopReplica
|
|||
base.OnResizeBegin(e);
|
||||
|
||||
//Update aspect ratio if needed
|
||||
if (_thumbnailPanel.IsShowingThumbnail) {
|
||||
/*if (_thumbnailPanel.IsShowingThumbnail) {
|
||||
SetAspectRatio(_thumbnailPanel.ThumbnailOriginalSize);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
protected override void OnResize(EventArgs e) {
|
||||
base.OnResize(e);
|
||||
this.GlassMargins = (_regionBoxShowing) ?
|
||||
new Margins(ClientSize.Width - _regionBox.Width, 0, 0, 0) :
|
||||
new Margins(-1);
|
||||
}
|
||||
|
||||
protected override void OnShown(EventArgs e) {
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
|
||||
<WebPage>publish.htm</WebPage>
|
||||
<OpenBrowserOnPublish>false</OpenBrowserOnPublish>
|
||||
<ApplicationRevision>2</ApplicationRevision>
|
||||
<ApplicationRevision>3</ApplicationRevision>
|
||||
<ApplicationVersion>2.9.1.%2a</ApplicationVersion>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<PublishWizardCompleted>true</PublishWizardCompleted>
|
||||
|
|
|
@ -204,13 +204,14 @@ namespace OnTopReplica {
|
|||
if (_thumbnail != null && !_thumbnail.IsInvalid){
|
||||
try {
|
||||
Size sourceSize = (_regionEnabled) ? _regionCurrent.Size : _thumbnail.SourceSize;
|
||||
thumbnailSize = new Size(Size.Width, Size.Height * 2); //ComputeIdealSize(sourceSize, Size);
|
||||
thumbnailSize = ComputeIdealSize(sourceSize, Size);
|
||||
padHeight = (Size.Height - thumbnailSize.Height) / 2;
|
||||
|
||||
/*padWidth = (Size.Width - thumbnailSize.Width) / 2;
|
||||
padHeight = (Size.Height - thumbnailSize.Height) / 2;
|
||||
|
||||
Rectangle target = new Rectangle(padWidth, padHeight, thumbnailSize.Width, thumbnailSize.Height);*/
|
||||
var target = new Rectangle(0, 0, thumbnailSize.Width, thumbnailSize.Height);
|
||||
var target = new Rectangle(0, padHeight, thumbnailSize.Width, thumbnailSize.Height);
|
||||
Rectangle source = (_regionEnabled) ? _regionCurrent : new Rectangle(Point.Empty, _thumbnail.SourceSize);
|
||||
|
||||
//Console.WriteLine("Source " + sourceSize.ToString() + ", Target " + Size.ToString() + ", Fit " + thumbnailSize.ToString() + ", Padding " + padWidth + "," + padHeight);
|
||||
|
@ -235,10 +236,10 @@ namespace OnTopReplica {
|
|||
double clientRatio = (double)clientSize.Width / (double)clientSize.Height;
|
||||
|
||||
Size ret;
|
||||
if(sourceRatio >= clientRatio)
|
||||
//if(sourceRatio >= clientRatio)
|
||||
ret = new Size(clientSize.Width, (int)((double)clientSize.Width / sourceRatio));
|
||||
else
|
||||
ret = new Size((int)((double)clientSize.Height * sourceRatio), clientSize.Height);
|
||||
/*else
|
||||
ret = new Size((int)((double)clientSize.Height * sourceRatio), clientSize.Height);*/
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue