diff --git a/HelpersLib/Forms/MonitorTestForm.Designer.cs b/HelpersLib/Forms/MonitorTestForm.Designer.cs index 282c9d090..0afdf9b2f 100644 --- a/HelpersLib/Forms/MonitorTestForm.Designer.cs +++ b/HelpersLib/Forms/MonitorTestForm.Designer.cs @@ -91,9 +91,9 @@ private void InitializeComponent() this.pSettings.Controls.Add(this.lblBlackWhiteValue); this.pSettings.Controls.Add(this.tbBlackWhite); this.pSettings.Controls.Add(this.rbBlackWhite); - this.pSettings.Location = new System.Drawing.Point(24, 24); + this.pSettings.Location = new System.Drawing.Point(100, 100); this.pSettings.Name = "pSettings"; - this.pSettings.Size = new System.Drawing.Size(320, 408); + this.pSettings.Size = new System.Drawing.Size(320, 396); this.pSettings.TabIndex = 0; // // lblTip @@ -366,7 +366,7 @@ private void InitializeComponent() this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.Gray; - this.ClientSize = new System.Drawing.Size(600, 500); + this.ClientSize = new System.Drawing.Size(700, 700); this.Controls.Add(this.pSettings); this.Cursor = System.Windows.Forms.Cursors.Default; this.DoubleBuffered = true; diff --git a/HelpersLib/Forms/MonitorTestForm.cs b/HelpersLib/Forms/MonitorTestForm.cs index 0bbd3557f..9e8a3a8e1 100644 --- a/HelpersLib/Forms/MonitorTestForm.cs +++ b/HelpersLib/Forms/MonitorTestForm.cs @@ -41,7 +41,7 @@ public MonitorTestForm() Size = screenBounds.Size; rbBlackWhite.Checked = true; - tbBlackWhite.Value = 100; + tbBlackWhite.Value = 128; tbRed.Value = 255; cbGradient.Items.AddRange(Enum.GetNames(typeof(LinearGradientMode))); cbGradient.SelectedIndex = 1; diff --git a/HelpersLib/Helpers/Helpers.cs b/HelpersLib/Helpers/Helpers.cs index d4cad73c8..fa5103b18 100644 --- a/HelpersLib/Helpers/Helpers.cs +++ b/HelpersLib/Helpers/Helpers.cs @@ -819,5 +819,13 @@ public static Size MeasureText(string text, Font font) return g.MeasureString(text, font).ToSize(); } } + + public static Size MeasureText(string text, Font font, int width) + { + using (Graphics g = Graphics.FromHwnd(IntPtr.Zero)) + { + return g.MeasureString(text, font, width).ToSize(); + } + } } } \ No newline at end of file diff --git a/HelpersLib/Helpers/ImageHelpers.cs b/HelpersLib/Helpers/ImageHelpers.cs index 6f2b0221e..cba64fffc 100644 --- a/HelpersLib/Helpers/ImageHelpers.cs +++ b/HelpersLib/Helpers/ImageHelpers.cs @@ -1091,7 +1091,7 @@ public static Image LoadImage(string filePath) { try { - if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath)) + if (!string.IsNullOrEmpty(filePath) && Helpers.IsImageFile(filePath) && File.Exists(filePath)) { return Image.FromStream(new MemoryStream(File.ReadAllBytes(filePath))); } diff --git a/ShareX/Forms/SettingsForm.Designer.cs b/ShareX/Forms/ApplicationSettingsForm.Designer.cs similarity index 99% rename from ShareX/Forms/SettingsForm.Designer.cs rename to ShareX/Forms/ApplicationSettingsForm.Designer.cs index d2fdbecb1..a0630e277 100644 --- a/ShareX/Forms/SettingsForm.Designer.cs +++ b/ShareX/Forms/ApplicationSettingsForm.Designer.cs @@ -1,6 +1,6 @@ namespace ShareX { - partial class SettingsForm + partial class ApplicationSettingsForm { /// /// Required designer variable. diff --git a/ShareX/Forms/SettingsForm.cs b/ShareX/Forms/ApplicationSettingsForm.cs similarity index 99% rename from ShareX/Forms/SettingsForm.cs rename to ShareX/Forms/ApplicationSettingsForm.cs index d12a27a07..8682f76d2 100644 --- a/ShareX/Forms/SettingsForm.cs +++ b/ShareX/Forms/ApplicationSettingsForm.cs @@ -35,13 +35,13 @@ namespace ShareX { - public partial class SettingsForm : Form + public partial class ApplicationSettingsForm : Form { private bool loaded; private const int MaxBufferSizePower = 14; private ContextMenuStrip cmsSaveImageSubFolderPattern; - public SettingsForm() + public ApplicationSettingsForm() { InitializeComponent(); LoadSettings(); diff --git a/ShareX/Forms/SettingsForm.resx b/ShareX/Forms/ApplicationSettingsForm.resx similarity index 100% rename from ShareX/Forms/SettingsForm.resx rename to ShareX/Forms/ApplicationSettingsForm.resx diff --git a/ShareX/Forms/MainForm.cs b/ShareX/Forms/MainForm.cs index 876cbf2bf..0d4828345 100644 --- a/ShareX/Forms/MainForm.cs +++ b/ShareX/Forms/MainForm.cs @@ -707,7 +707,7 @@ private void tsmiAutoCapture_Click(object sender, EventArgs e) private void tsbApplicationSettings_Click(object sender, EventArgs e) { - using (SettingsForm settingsForm = new SettingsForm()) + using (ApplicationSettingsForm settingsForm = new ApplicationSettingsForm()) { settingsForm.ShowDialog(); } diff --git a/ShareX/Forms/NotificationForm.cs b/ShareX/Forms/NotificationForm.cs index 47b76ac66..227d6a90d 100644 --- a/ShareX/Forms/NotificationForm.cs +++ b/ShareX/Forms/NotificationForm.cs @@ -50,18 +50,33 @@ public partial class NotificationForm : Form private bool closingAnimation = true; private int closingAnimationDuration = 2000; private int closingAnimationInterval = 50; + private Font textFont; + private int textPadding = 5; + private Size textRenderSize; - public NotificationForm(int duration, Size size, Image img, string url) + public NotificationForm(int duration, Size size, Image img, string text, string url) { InitializeComponent(); - img = ImageHelpers.ResizeImageLimit(img, size); - img = ImageHelpers.DrawCheckers(img); - ToastImage = img; + if (img != null) + { + img = ImageHelpers.ResizeImageLimit(img, size); + img = ImageHelpers.DrawCheckers(img); + size = new Size(img.Width + 2, img.Height + 2); + ToastImage = img; + } + else if (!string.IsNullOrEmpty(text)) + { + textFont = new Font("Arial", 10); + textRenderSize = Helpers.MeasureText(text, textFont, size.Width - textPadding * 2); + size = new Size(textRenderSize.Width + textPadding * 2, textRenderSize.Height + textPadding * 2 + 2); + ToastText = text; + } + ToastURL = url; SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); - Size = new Size(img.Width + 2, img.Height + 2); + Size = size; Location = new Point(Screen.PrimaryScreen.WorkingArea.Right - Width - windowOffset, Screen.PrimaryScreen.WorkingArea.Bottom - Height - windowOffset); tDuration.Interval = duration; @@ -111,41 +126,46 @@ protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; - g.DrawImage(ToastImage, 1, 1, ToastImage.Width, ToastImage.Height); + Rectangle rect = e.ClipRectangle; - if (!string.IsNullOrEmpty(ToastText)) + if (ToastImage != null) { - Rectangle textRect = new Rectangle(0, 0, e.ClipRectangle.Width, 40); - - using (SolidBrush brush = new SolidBrush(Color.FromArgb(150, 255, 255, 255))) + g.DrawImage(ToastImage, 1, 1, ToastImage.Width, ToastImage.Height); + } + else if (!string.IsNullOrEmpty(ToastText)) + { + using (LinearGradientBrush brush = new LinearGradientBrush(rect, Color.FromArgb(80, 80, 80), Color.FromArgb(50, 50, 50), LinearGradientMode.Vertical)) { - g.FillRectangle(brush, textRect); + g.FillRectangle(brush, rect); } - using (Font font = new Font("Arial", 10)) - { - g.DrawString(ToastText, font, Brushes.Black, textRect.RectangleOffset(-3)); - } + Rectangle textRect = new Rectangle(textPadding, textPadding, textRenderSize.Width + 2, textRenderSize.Height + 2); + g.DrawString(ToastText, textFont, Brushes.Black, textRect); + g.DrawString(ToastText, textFont, Brushes.White, textRect.LocationOffset(1)); } - g.DrawRectangleProper(Pens.Black, e.ClipRectangle); + g.DrawRectangleProper(Pens.Black, rect); } - public static void Show(int duration, Size size, string imagePath, string url) + public static void Show(int duration, Size size, string imagePath, string text, string url) { - if (duration > 0 && !size.IsEmpty && !string.IsNullOrEmpty(imagePath) && Helpers.IsImageFile(imagePath) && File.Exists(imagePath)) + if (duration > 0 && !size.IsEmpty) { Image img = ImageHelpers.LoadImage(imagePath); - NotificationForm form = new NotificationForm(duration, size, img, url); - NativeMethods.ShowWindow(form.Handle, (int)WindowShowStyle.ShowNoActivate); - NativeMethods.SetWindowPos(form.Handle, (IntPtr)SpecialWindowHandles.HWND_TOPMOST, 0, 0, 0, 0, - SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE); + + if (img != null || !string.IsNullOrEmpty(text)) + { + NotificationForm form = new NotificationForm(duration, size, img, text, url); + NativeMethods.ShowWindow(form.Handle, (int)WindowShowStyle.ShowNoActivate); + NativeMethods.SetWindowPos(form.Handle, (IntPtr)SpecialWindowHandles.HWND_TOPMOST, 0, 0, 0, 0, + SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE); + } } } - public static void Show(string imagePath, string url) + public static void Show(string imagePath, string text, string url) { - Show(4000, new Size(400, 300), imagePath, url); + Show(4000, new Size(400, 300), imagePath, text, url); } private void NotificationForm_MouseClick(object sender, MouseEventArgs e) @@ -166,9 +186,6 @@ private void NotificationForm_MouseEnter(object sender, EventArgs e) tOpacity.Stop(); Opacity = 1; - - ToastText = ToastURL; - Refresh(); } private void NotificationForm_MouseLeave(object sender, EventArgs e) @@ -200,6 +217,11 @@ protected override void Dispose(bool disposing) ToastImage.Dispose(); } + if (textFont != null) + { + textFont.Dispose(); + } + base.Dispose(disposing); } diff --git a/ShareX/ShareX.csproj b/ShareX/ShareX.csproj index badd331fb..df35af5e3 100644 --- a/ShareX/ShareX.csproj +++ b/ShareX/ShareX.csproj @@ -134,11 +134,11 @@ ScreenRegionForm.cs - + Form - - SettingsForm.cs + + ApplicationSettingsForm.cs Form @@ -235,8 +235,8 @@ ScreenRegionForm.cs - - SettingsForm.cs + + ApplicationSettingsForm.cs MainForm.cs diff --git a/ShareX/TaskManager.cs b/ShareX/TaskManager.cs index 79eff2cb4..d45137018 100644 --- a/ShareX/TaskManager.cs +++ b/ShareX/TaskManager.cs @@ -325,7 +325,7 @@ private static void task_UploadCompleted(UploadTask task) if (task.Info.TaskSettings.GeneralSettings.ShowToastWindowAfterTask) { NotificationForm.Show((int)(task.Info.TaskSettings.AdvancedSettings.ToastWindowDuration * 1000), - task.Info.TaskSettings.AdvancedSettings.ToastWindowSize, info.FilePath, result); + task.Info.TaskSettings.AdvancedSettings.ToastWindowSize, info.FilePath, "ShareX - Task completed\r\n" + balloonTipText, result); } } diff --git a/ShareX/UploadInfoParser.cs b/ShareX/UploadInfoParser.cs index 17ad93e68..6db03f0d8 100644 --- a/ShareX/UploadInfoParser.cs +++ b/ShareX/UploadInfoParser.cs @@ -47,7 +47,13 @@ public string Parse(TaskInfo info, string pattern) if (info.Result != null) { - string result = string.IsNullOrEmpty(info.Result.ToString()) ? info.FilePath : info.Result.ToString(); + string result = info.Result.ToString(); + + if (string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(info.FilePath)) + { + result = info.FilePath; + } + pattern = pattern.Replace("$result", result ?? ""); pattern = pattern.Replace("$url", info.Result.URL ?? ""); pattern = pattern.Replace("$shorturl", info.Result.ShortenedURL ?? "");