From 48681af90069102d956246f719f667826c5bc6a2 Mon Sep 17 00:00:00 2001 From: Jaex Date: Tue, 24 Oct 2017 02:24:50 +0300 Subject: [PATCH] Automatically move toolbar to snap top of annotate window --- .../Forms/RegionCaptureForm.cs | 16 ++++++++++--- .../Shapes/ShapeManagerMenu.cs | 23 ++++++++++++------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/ShareX.ScreenCaptureLib/Forms/RegionCaptureForm.cs b/ShareX.ScreenCaptureLib/Forms/RegionCaptureForm.cs index 0f1d5175f..abeefc788 100644 --- a/ShareX.ScreenCaptureLib/Forms/RegionCaptureForm.cs +++ b/ShareX.ScreenCaptureLib/Forms/RegionCaptureForm.cs @@ -254,9 +254,12 @@ internal void InitBackground(Image img) } } - private void CenterCanvas() + private void CenterCanvas(bool updateCoordinates = true) { - UpdateCoordinates(); + if (updateCoordinates) + { + UpdateCoordinates(); + } Rectangle rect = ScreenRectangle0Based; @@ -291,15 +294,22 @@ private void RegionCaptureForm_Shown(object sender, EventArgs e) private void RegionCaptureForm_Resize(object sender, EventArgs e) { + UpdateCoordinates(); + if (WindowState != lastWindowState) { lastWindowState = WindowState; if (WindowState == FormWindowState.Normal || WindowState == FormWindowState.Maximized) { - CenterCanvas(); + CenterCanvas(false); } } + + if (IsAnnotationMode && ShapeManager != null && ShapeManager.ToolbarCreated) + { + ShapeManager.UpdateMenuPosition(); + } } internal void RegionCaptureForm_KeyDown(object sender, KeyEventArgs e) diff --git a/ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs b/ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs index 93cd7ec0d..b5e0260b4 100644 --- a/ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs +++ b/ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs @@ -35,6 +35,7 @@ namespace ShareX.ScreenCaptureLib { internal partial class ShapeManager { + public bool ToolbarCreated { get; private set; } public bool IsMenuCollapsed { get; private set; } internal TextAnimation MenuTextAnimation = new TextAnimation() @@ -53,7 +54,7 @@ internal partial class ShapeManager private ToolStripLabel tslDragLeft; private ToolStripLabeledComboBox tscbCursorTypes; - private void CreateToolbar() + internal void CreateToolbar() { menuForm = new Form() { @@ -66,8 +67,7 @@ private void CreateToolbar() Location = new Point(200, 200), ShowInTaskbar = false, StartPosition = FormStartPosition.Manual, - Text = "ShareX - Region capture menu", - TopMost = true + Text = "ShareX - Region capture menu" }; menuForm.Shown += MenuForm_Shown; @@ -857,6 +857,8 @@ private void CreateToolbar() ConfigureMenuState(); form.Activate(); + + ToolbarCreated = true; } private void MenuForm_Shown(object sender, EventArgs e) @@ -930,7 +932,12 @@ private void ConfigureMenuState() SetMenuCollapsed(Config.MenuCollapsed); } - Rectangle rectScreen = CaptureHelpers.GetScreenBounds(); + UpdateMenuPosition(); + } + + internal void UpdateMenuPosition() + { + Rectangle rectScreen = form.RectangleToScreen(form.ScreenRectangle0Based); if (Config.RememberMenuState && rectScreen.Contains(Config.MenuPosition)) { @@ -938,15 +945,15 @@ private void ConfigureMenuState() } else { - Rectangle rectActiveScreen = CaptureHelpers.GetActiveScreenBounds(); + //Rectangle rectActiveScreen = CaptureHelpers.GetActiveScreenBounds(); - if (tsMain.Width < rectActiveScreen.Width) + if (tsMain.Width < rectScreen.Width) { - menuForm.Location = new Point(rectActiveScreen.X + rectActiveScreen.Width / 2 - tsMain.Width / 2, rectActiveScreen.Y + 20); + menuForm.Location = new Point(rectScreen.X + rectScreen.Width / 2 - tsMain.Width / 2, rectScreen.Y); } else { - menuForm.Location = rectActiveScreen.Location; + menuForm.Location = rectScreen.Location; } } }