mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
Notification placement setting
This commit is contained in:
parent
a8c0f6e6f1
commit
c734f5c208
3 changed files with 13 additions and 12 deletions
|
@ -781,14 +781,14 @@ public static string HtmlEncode(string text)
|
|||
return result.ToString();
|
||||
}
|
||||
|
||||
public static Point GetPosition(ContentAlignment alignment, Point offset, Size sourceImage, Size img)
|
||||
public static Point GetPosition(ContentAlignment placement, Point offset, Size backgroundSize, Size objectSize)
|
||||
{
|
||||
int midX = sourceImage.Width / 2 - img.Width / 2;
|
||||
int midY = sourceImage.Height / 2 - img.Height / 2;
|
||||
int right = sourceImage.Width - img.Width;
|
||||
int bottom = sourceImage.Height - img.Height;
|
||||
int midX = backgroundSize.Width / 2 - objectSize.Width / 2;
|
||||
int midY = backgroundSize.Height / 2 - objectSize.Height / 2;
|
||||
int right = backgroundSize.Width - objectSize.Width;
|
||||
int bottom = backgroundSize.Height - objectSize.Height;
|
||||
|
||||
switch (alignment)
|
||||
switch (placement)
|
||||
{
|
||||
default:
|
||||
case ContentAlignment.TopLeft:
|
||||
|
|
|
@ -54,7 +54,7 @@ public partial class NotificationForm : Form
|
|||
private int textPadding = 5;
|
||||
private Size textRenderSize;
|
||||
|
||||
public NotificationForm(int duration, Size size, Image img, string text, string url)
|
||||
public NotificationForm(int duration, ContentAlignment placement, Size size, Image img, string text, string url)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
|
@ -77,7 +77,8 @@ public NotificationForm(int duration, Size size, Image img, string text, string
|
|||
|
||||
SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
|
||||
Size = size;
|
||||
Location = new Point(Screen.PrimaryScreen.WorkingArea.Right - Width - windowOffset, Screen.PrimaryScreen.WorkingArea.Bottom - Height - windowOffset);
|
||||
Point position = Helpers.GetPosition(placement, new Point(windowOffset, windowOffset), Screen.PrimaryScreen.WorkingArea.Size, Size);
|
||||
Location = new Point(Screen.PrimaryScreen.WorkingArea.X + position.X, Screen.PrimaryScreen.WorkingArea.Y + position.Y);
|
||||
|
||||
tDuration.Interval = duration;
|
||||
tDuration.Start();
|
||||
|
@ -147,7 +148,7 @@ protected override void OnPaint(PaintEventArgs e)
|
|||
g.DrawRectangleProper(Pens.Black, rect);
|
||||
}
|
||||
|
||||
public static void Show(int duration, Size size, string imagePath, string text, string url)
|
||||
public static void Show(int duration, ContentAlignment placement, Size size, string imagePath, string text, string url)
|
||||
{
|
||||
if (duration > 0 && !size.IsEmpty)
|
||||
{
|
||||
|
@ -155,7 +156,7 @@ public static void Show(int duration, Size size, string imagePath, string text,
|
|||
|
||||
if (img != null || !string.IsNullOrEmpty(text))
|
||||
{
|
||||
NotificationForm form = new NotificationForm(duration, size, img, text, url);
|
||||
NotificationForm form = new NotificationForm(duration, placement, 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);
|
||||
|
@ -165,7 +166,7 @@ public static void Show(int duration, Size size, string imagePath, string text,
|
|||
|
||||
public static void Show(string imagePath, string text, string url)
|
||||
{
|
||||
Show(4000, new Size(400, 300), imagePath, text, url);
|
||||
Show(4000, ContentAlignment.BottomRight, new Size(400, 300), imagePath, text, url);
|
||||
}
|
||||
|
||||
private void NotificationForm_MouseClick(object sender, MouseEventArgs e)
|
||||
|
|
|
@ -168,7 +168,7 @@ public static void ShowResultNotifications(string notificationText, TaskSettings
|
|||
}
|
||||
break;
|
||||
case PopUpNotificationType.ToastNotification:
|
||||
NotificationForm.Show((int)(taskSettings.AdvancedSettings.ToastWindowDuration * 1000),
|
||||
NotificationForm.Show((int)(taskSettings.AdvancedSettings.ToastWindowDuration * 1000), taskSettings.AdvancedSettings.ToastWindowPlacement,
|
||||
taskSettings.AdvancedSettings.ToastWindowSize, filePath, "ShareX - Task completed\r\n" + notificationText, notificationText);
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue