diff --git a/HelpersLib/Extensions/Extensions.cs b/HelpersLib/Extensions/Extensions.cs index d9e795bc5..bb9121a84 100644 --- a/HelpersLib/Extensions/Extensions.cs +++ b/HelpersLib/Extensions/Extensions.cs @@ -191,6 +191,26 @@ public static bool IsValid(this Rectangle rect) return rect.Width > 0 && rect.Height > 0; } + public static Size Offset(this Size size, int offset) + { + return new Size(size.Width + offset, size.Height + offset); + } + + public static Rectangle RectangleOffset(this Rectangle rect, int offset) + { + return new Rectangle(rect.X - offset, rect.Y - offset, rect.Width + offset * 2, rect.Height + offset * 2); + } + + public static Rectangle LocationOffset(this Rectangle rect, int offset) + { + return new Rectangle(rect.X + offset, rect.Y + offset, rect.Width, rect.Height); + } + + public static Rectangle LocationOffset(this Rectangle rect, int x, int y) + { + return new Rectangle(rect.X + x, rect.Y + y, rect.Width, rect.Height); + } + public static Rectangle SizeOffset(this Rectangle rect, int offset) { return rect.SizeOffset(offset, offset); diff --git a/HelpersLib/Helpers/ImageHelpers.cs b/HelpersLib/Helpers/ImageHelpers.cs index 1cf3ca383..28a9239e8 100644 --- a/HelpersLib/Helpers/ImageHelpers.cs +++ b/HelpersLib/Helpers/ImageHelpers.cs @@ -69,31 +69,26 @@ namespace HelpersLib { public static class ImageHelpers { - public static Image ResizeImage(Image img, int width, int height) - { - return ResizeImage(img, 0, 0, width, height); - } - public static Image ResizeImage(Image img, Size size) { - return ResizeImage(img, 0, 0, size.Width, size.Height); + return ResizeImage(img, size.Width, size.Height); } - public static Image ResizeImage(Image img, int x, int y, int width, int height) + public static Image ResizeImage(Image img, int width, int height) { if (width < 1 || height < 1 || (img.Width == width && img.Height == height)) { return img; } - Bitmap bmp = new Bitmap(x + width, y + height, img.PixelFormat); + Bitmap bmp = new Bitmap(width, height, img.PixelFormat); bmp.SetResolution(img.HorizontalResolution, img.VerticalResolution); using (Graphics g = Graphics.FromImage(bmp)) using (img) { g.SetHighQuality(); - g.DrawImage(img, x, y, width, height); + g.DrawImage(img, 0, 0, width, height); } return bmp; @@ -111,17 +106,17 @@ public static Image ResizeImageByPercentage(Image img, float percentageWidth, fl return ResizeImage(img, width, height); } + public static Image ResizeImage(Image img, Size size, bool allowEnlarge, bool centerImage) + { + return ResizeImage(img, size.Width, size.Height, allowEnlarge, centerImage); + } + public static Image ResizeImage(Image img, int width, int height, bool allowEnlarge, bool centerImage) { - return ResizeImage(img, 0, 0, width, height, allowEnlarge, centerImage); + return ResizeImage(img, width, height, allowEnlarge, centerImage, Color.Transparent); } - public static Image ResizeImage(Image img, Rectangle rect, bool allowEnlarge, bool centerImage) - { - return ResizeImage(img, rect.X, rect.Y, rect.Width, rect.Height, allowEnlarge, centerImage); - } - - public static Image ResizeImage(Image img, int x, int y, int width, int height, bool allowEnlarge, bool centerImage) + public static Image ResizeImage(Image img, int width, int height, bool allowEnlarge, bool centerImage, Color backColor) { double ratio; int newWidth, newHeight; @@ -141,8 +136,8 @@ public static Image ResizeImage(Image img, int x, int y, int width, int height, newHeight = (int)(img.Height * ratio); } - int newX = x; - int newY = y; + int newX = 0; + int newY = 0; if (centerImage) { @@ -150,7 +145,18 @@ public static Image ResizeImage(Image img, int x, int y, int width, int height, newY += (int)((height - (img.Height * ratio)) / 2); } - return ResizeImage(img, newX, newY, newWidth, newHeight); + Bitmap bmp = new Bitmap(width, height, img.PixelFormat); + bmp.SetResolution(img.HorizontalResolution, img.VerticalResolution); + + using (Graphics g = Graphics.FromImage(bmp)) + using (img) + { + g.Clear(backColor); + g.SetHighQuality(); + g.DrawImage(img, newX, newY, newWidth, newHeight); + } + + return bmp; } public static Image CropImage(Image img, Rectangle rect) diff --git a/HelpersLib/Native/NativeEnums.cs b/HelpersLib/Native/NativeEnums.cs index 49539d84d..6936efa88 100644 --- a/HelpersLib/Native/NativeEnums.cs +++ b/HelpersLib/Native/NativeEnums.cs @@ -27,6 +27,20 @@ You should have received a copy of the GNU General Public License namespace HelpersLib { + [Flags] + public enum AnimateWindowFlags + { + AW_HOR_POSITIVE = 0x00000001, + AW_HOR_NEGATIVE = 0x00000002, + AW_VER_POSITIVE = 0x00000004, + AW_VER_NEGATIVE = 0x00000008, + AW_CENTER = 0x00000010, + AW_HIDE = 0x00010000, + AW_ACTIVATE = 0x00020000, + AW_SLIDE = 0x00040000, + AW_BLEND = 0x00080000 + } + public enum HRESULT : long { S_FALSE = 1, diff --git a/HelpersLib/Native/NativeMethods.cs b/HelpersLib/Native/NativeMethods.cs index 9fd50052a..688cc6d5f 100644 --- a/HelpersLib/Native/NativeMethods.cs +++ b/HelpersLib/Native/NativeMethods.cs @@ -69,6 +69,9 @@ public static partial class NativeMethods #region user32.dll + [DllImport("user32")] + public static extern bool AnimateWindow(IntPtr hwnd, int time, AnimateWindowFlags flags); + [DllImport("user32.dll")] public static extern bool BringWindowToTop(IntPtr hWnd); diff --git a/ScreenCaptureLib/Screenshot_Transparent.cs b/ScreenCaptureLib/Screenshot_Transparent.cs index 8497890db..15511fe24 100644 --- a/ScreenCaptureLib/Screenshot_Transparent.cs +++ b/ScreenCaptureLib/Screenshot_Transparent.cs @@ -74,10 +74,14 @@ public static Image CaptureWindowTransparent(IntPtr handle) form.BackColor = Color.White; form.FormBorderStyle = FormBorderStyle.None; form.ShowInTaskbar = false; + form.StartPosition = FormStartPosition.Manual; + form.Location = new Point(rect.X, rect.Y); + form.Size = new Size(rect.Width, rect.Height); - NativeMethods.ShowWindow(form.Handle, (int)WindowShowStyle.ShowNormalNoActivate); + NativeMethods.ShowWindow(form.Handle, (int)WindowShowStyle.ShowNoActivate); - if (!NativeMethods.SetWindowPos(form.Handle, handle, rect.X, rect.Y, rect.Width, rect.Height, SetWindowPosFlags.SWP_NOACTIVATE)) + if (!NativeMethods.SetWindowPos(form.Handle, handle, 0, 0, 0, 0, + SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE)) { form.Close(); DebugHelper.WriteLine("Transparent capture failed. Reason: SetWindowPos fail."); diff --git a/ShareX/Forms/MainForm.cs b/ShareX/Forms/MainForm.cs index cdce50cfe..29fd5a228 100644 --- a/ShareX/Forms/MainForm.cs +++ b/ShareX/Forms/MainForm.cs @@ -70,6 +70,7 @@ private void MainForm_HandleCreated(object sender, EventArgs e) private void AfterShownJobs() { this.ShowActivate(); + ToastForm.ShowAsync("test", ShareXResources.Logo); } private void InitControls() diff --git a/ShareX/Forms/MainForm_Capture.cs b/ShareX/Forms/MainForm_Capture.cs index 3d5374428..a9762af6e 100644 --- a/ShareX/Forms/MainForm_Capture.cs +++ b/ShareX/Forms/MainForm_Capture.cs @@ -208,11 +208,6 @@ private void DoCaptureWork(ScreenCaptureDelegate capture, CaptureType captureTyp Screenshot.AutoHideTaskbar = taskSettings.CaptureSettings.CaptureAutoHideTaskbar; img = capture(); - - if (img != null && taskSettings.GeneralSettings.PlaySoundAfterCapture) - { - Helpers.PlaySoundAsync(Resources.CameraSound); - } } catch (Exception ex) { @@ -233,6 +228,11 @@ private void AfterCapture(Image img, CaptureType captureType, TaskSettings taskS { if (img != null) { + if (taskSettings.GeneralSettings.PlaySoundAfterCapture) + { + Helpers.PlaySoundAsync(Resources.CameraSound); + } + if (taskSettings.ImageSettings.ImageEffectOnlyRegionCapture && !IsRegionCapture(captureType)) { taskSettings.AfterCaptureJob = taskSettings.AfterCaptureJob.Remove(AfterCaptureTasks.AddImageEffects); diff --git a/ShareX/Forms/TaskSettingsForm.Designer.cs b/ShareX/Forms/TaskSettingsForm.Designer.cs index 3f3bc3217..b9f7c1aab 100644 --- a/ShareX/Forms/TaskSettingsForm.Designer.cs +++ b/ShareX/Forms/TaskSettingsForm.Designer.cs @@ -469,7 +469,7 @@ private void InitializeComponent() // chkShowAfterUploadForm // this.chkShowAfterUploadForm.AutoSize = true; - this.chkShowAfterUploadForm.Location = new System.Drawing.Point(8, 80); + this.chkShowAfterUploadForm.Location = new System.Drawing.Point(8, 104); this.chkShowAfterUploadForm.Name = "chkShowAfterUploadForm"; this.chkShowAfterUploadForm.Size = new System.Drawing.Size(271, 17); this.chkShowAfterUploadForm.TabIndex = 18; @@ -491,7 +491,7 @@ private void InitializeComponent() // cbTrayBalloonTipAfterUpload // this.cbTrayBalloonTipAfterUpload.AutoSize = true; - this.cbTrayBalloonTipAfterUpload.Location = new System.Drawing.Point(8, 104); + this.cbTrayBalloonTipAfterUpload.Location = new System.Drawing.Point(8, 80); this.cbTrayBalloonTipAfterUpload.Name = "cbTrayBalloonTipAfterUpload"; this.cbTrayBalloonTipAfterUpload.Size = new System.Drawing.Size(233, 17); this.cbTrayBalloonTipAfterUpload.TabIndex = 16; diff --git a/ShareX/Forms/ToastForm.Designer.cs b/ShareX/Forms/ToastForm.Designer.cs new file mode 100644 index 000000000..ac3714041 --- /dev/null +++ b/ShareX/Forms/ToastForm.Designer.cs @@ -0,0 +1,58 @@ +namespace ShareX +{ + partial class ToastForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.tDuration = new System.Windows.Forms.Timer(this.components); + this.SuspendLayout(); + // + // tDuration + // + this.tDuration.Tick += new System.EventHandler(this.tDuration_Tick); + // + // ToastForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(300, 150); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.Name = "ToastForm"; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; + this.Text = "ToastForm"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Timer tDuration; + + } +} \ No newline at end of file diff --git a/ShareX/Forms/ToastForm.cs b/ShareX/Forms/ToastForm.cs new file mode 100644 index 000000000..007ee88b4 --- /dev/null +++ b/ShareX/Forms/ToastForm.cs @@ -0,0 +1,87 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (C) 2008-2013 ShareX Developers + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using HelpersLib; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading; +using System.Windows.Forms; + +namespace ShareX +{ + public partial class ToastForm : Form + { + public string ToastText { get; private set; } + public Image ToastImage { get; private set; } + + public ToastForm(int duration, string text, Image image) + { + InitializeComponent(); + ToastText = text; + image = ImageHelpers.ResizeImage(image, ClientRectangle.Size.Offset(-2), true, true); + image = ImageHelpers.DrawCheckers(image); + ToastImage = image; + SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); + Location = new Point(Screen.PrimaryScreen.WorkingArea.Right - Width, Screen.PrimaryScreen.WorkingArea.Bottom - Height); + NativeMethods.AnimateWindow(Handle, 1000, AnimateWindowFlags.AW_BLEND); + tDuration.Interval = duration; + tDuration.Start(); + } + + private void tDuration_Tick(object sender, EventArgs e) + { + tDuration.Stop(); + NativeMethods.AnimateWindow(Handle, 1000, AnimateWindowFlags.AW_HIDE | AnimateWindowFlags.AW_BLEND); + Close(); + } + + protected override void OnPaint(PaintEventArgs e) + { + Graphics g = e.Graphics; + g.DrawImage(ToastImage, 1, 1, ToastImage.Width, ToastImage.Height); + g.DrawRectangleProper(Pens.Black, e.ClipRectangle); + } + + public static void ShowAsync(string text, Image image) + { + Image cloneImage = (Image)image.Clone(); + + Thread thread = new Thread(() => + { + using (ToastForm toastForm = new ToastForm(5000, text, cloneImage)) + { + toastForm.ShowDialog(); + } + }); + + thread.Start(); + } + } +} \ No newline at end of file diff --git a/ShareX/Forms/ToastForm.resx b/ShareX/Forms/ToastForm.resx new file mode 100644 index 000000000..83dccaf90 --- /dev/null +++ b/ShareX/Forms/ToastForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/ShareX/ShareX.csproj b/ShareX/ShareX.csproj index 0f744b2d2..bd5a9d749 100644 --- a/ShareX/ShareX.csproj +++ b/ShareX/ShareX.csproj @@ -140,6 +140,12 @@ SettingsForm.cs + + Form + + + ToastForm.cs + Form @@ -238,6 +244,9 @@ MainForm.cs + + ToastForm.cs + UploadTestForm.cs diff --git a/ShareX/TaskManager.cs b/ShareX/TaskManager.cs index c148bb19d..95a6e89c3 100644 --- a/ShareX/TaskManager.cs +++ b/ShareX/TaskManager.cs @@ -302,14 +302,13 @@ private static void task_UploadCompleted(UploadTask task) if (!info.TaskSettings.AdvancedSettings.DisableNotifications) { - string balloonTipText = result; - - if (info.TaskSettings.GeneralSettings.ShowAfterUploadForm) + if (task.Info.TaskSettings.GeneralSettings.PlaySoundAfterUpload) { - AfterUploadForm dlg = new AfterUploadForm(info); - NativeMethods.ShowWindow(dlg.Handle, (int)WindowShowStyle.ShowNoActivate); + SystemSounds.Exclamation.Play(); } + string balloonTipText = result; + if (!string.IsNullOrEmpty(info.TaskSettings.AdvancedSettings.BalloonTipContentFormat)) { balloonTipText = new UploadInfoParser().Parse(info, info.TaskSettings.AdvancedSettings.BalloonTipContentFormat); @@ -321,9 +320,10 @@ private static void task_UploadCompleted(UploadTask task) Program.MainForm.niTray.ShowBalloonTip(5000, "ShareX - Task completed", balloonTipText, ToolTipIcon.Info); } - if (task.Info.TaskSettings.GeneralSettings.PlaySoundAfterUpload) + if (info.TaskSettings.GeneralSettings.ShowAfterUploadForm) { - SystemSounds.Exclamation.Play(); + AfterUploadForm dlg = new AfterUploadForm(info); + NativeMethods.ShowWindow(dlg.Handle, (int)WindowShowStyle.ShowNoActivate); } } }