mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-07 15:35:47 +12:00
Added Title support to notification form
This commit is contained in:
parent
a031f774e2
commit
567c565bf4
|
@ -36,14 +36,18 @@ public class NotificationFormConfig : IDisposable
|
||||||
public int Duration { get; set; }
|
public int Duration { get; set; }
|
||||||
public int FadeDuration { get; set; }
|
public int FadeDuration { get; set; }
|
||||||
public ContentAlignment Placement { get; set; }
|
public ContentAlignment Placement { get; set; }
|
||||||
public int Offset { get; set; } = 3;
|
public int Offset { get; set; } = 5;
|
||||||
public Size Size { get; set; }
|
public Size Size { get; set; }
|
||||||
public bool IsValid => (Duration > 0 || FadeDuration > 0) && Size.Width > 0 && Size.Height > 0;
|
public bool IsValid => (Duration > 0 || FadeDuration > 0) && Size.Width > 0 && Size.Height > 0;
|
||||||
public int TextPadding { get; set; } = 8;
|
public int TextPadding { get; set; } = 10;
|
||||||
public Font TextFont { get; set; } = new Font("Arial", 10);
|
public Font TextFont { get; set; } = new Font("Arial", 11);
|
||||||
|
public Color TextColor { get; set; } = Color.FromArgb(210, 210, 210);
|
||||||
|
public Font TitleFont { get; set; } = new Font("Arial", 11, FontStyle.Bold);
|
||||||
|
public Color TitleColor { get; set; } = Color.FromArgb(255, 255, 255);
|
||||||
|
|
||||||
public Bitmap Image { get; set; }
|
public Bitmap Image { get; set; }
|
||||||
public string Text { get; set; }
|
public string Text { get; set; }
|
||||||
|
public string Title { get; set; }
|
||||||
public string FilePath { get; set; }
|
public string FilePath { get; set; }
|
||||||
public string URL { get; set; }
|
public string URL { get; set; }
|
||||||
public ToastClickAction LeftClickAction { get; set; }
|
public ToastClickAction LeftClickAction { get; set; }
|
||||||
|
@ -57,6 +61,11 @@ public void Dispose()
|
||||||
TextFont.Dispose();
|
TextFont.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (TitleFont != null)
|
||||||
|
{
|
||||||
|
TitleFont.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
if (Image != null)
|
if (Image != null)
|
||||||
{
|
{
|
||||||
Image.Dispose();
|
Image.Dispose();
|
||||||
|
@ -73,7 +82,10 @@ public class NotificationForm : Form
|
||||||
private int fadeInterval = 50;
|
private int fadeInterval = 50;
|
||||||
private float opacityDecrement;
|
private float opacityDecrement;
|
||||||
private int urlPadding = 3;
|
private int urlPadding = 3;
|
||||||
|
private int titleSpace = 3;
|
||||||
|
private Size titleRenderSize;
|
||||||
private Size textRenderSize;
|
private Size textRenderSize;
|
||||||
|
private Size totalRenderSize;
|
||||||
|
|
||||||
protected override CreateParams CreateParams
|
protected override CreateParams CreateParams
|
||||||
{
|
{
|
||||||
|
@ -103,8 +115,18 @@ private NotificationForm(NotificationFormConfig config)
|
||||||
}
|
}
|
||||||
else if (!string.IsNullOrEmpty(Config.Text))
|
else if (!string.IsNullOrEmpty(Config.Text))
|
||||||
{
|
{
|
||||||
textRenderSize = TextRenderer.MeasureText(Config.Text, Config.TextFont, Config.Size.Offset(-Config.TextPadding * 2), TextFormatFlags.Left | TextFormatFlags.EndEllipsis);
|
textRenderSize = TextRenderer.MeasureText(Config.Text, Config.TextFont, Config.Size.Offset(-Config.TextPadding * 2),
|
||||||
Config.Size = new Size(textRenderSize.Width + (Config.TextPadding * 2), textRenderSize.Height + (Config.TextPadding * 2) + 2);
|
TextFormatFlags.Left | TextFormatFlags.EndEllipsis);
|
||||||
|
totalRenderSize = textRenderSize;
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(Config.Title))
|
||||||
|
{
|
||||||
|
titleRenderSize = TextRenderer.MeasureText(Config.Title, Config.TitleFont, Config.Size.Offset(-Config.TextPadding * 2),
|
||||||
|
TextFormatFlags.Left | TextFormatFlags.EndEllipsis);
|
||||||
|
totalRenderSize = new Size(Math.Max(textRenderSize.Width, titleRenderSize.Width), titleRenderSize.Height + titleSpace + textRenderSize.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
Config.Size = new Size(totalRenderSize.Width + (Config.TextPadding * 2), totalRenderSize.Height + (Config.TextPadding * 2) + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
Point position = Helpers.GetPosition(Config.Placement, Config.Offset, Screen.PrimaryScreen.WorkingArea.Size, Config.Size);
|
Point position = Helpers.GetPosition(Config.Placement, Config.Offset, Screen.PrimaryScreen.WorkingArea.Size, Config.Size);
|
||||||
|
@ -211,9 +233,20 @@ protected override void OnPaint(PaintEventArgs e)
|
||||||
g.FillRectangle(brush, rect);
|
g.FillRectangle(brush, rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle textRect = new Rectangle(Config.TextPadding, Config.TextPadding, textRenderSize.Width + 2, textRenderSize.Height + 2);
|
Rectangle textRect;
|
||||||
TextRenderer.DrawText(g, Config.Text, Config.TextFont, textRect, Color.Black, TextFormatFlags.Left | TextFormatFlags.EndEllipsis);
|
|
||||||
TextRenderer.DrawText(g, Config.Text, Config.TextFont, textRect.LocationOffset(1), Color.White, TextFormatFlags.Left | TextFormatFlags.EndEllipsis);
|
if (!string.IsNullOrEmpty(Config.Title))
|
||||||
|
{
|
||||||
|
Rectangle titleRect = new Rectangle(Config.TextPadding, Config.TextPadding, titleRenderSize.Width + 2, titleRenderSize.Height + 2);
|
||||||
|
TextRenderer.DrawText(g, Config.Title, Config.TitleFont, titleRect, Color.White, TextFormatFlags.Left | TextFormatFlags.EndEllipsis);
|
||||||
|
textRect = new Rectangle(Config.TextPadding, Config.TextPadding + titleRect.Height + titleSpace, textRenderSize.Width + 2, textRenderSize.Height + 2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
textRect = new Rectangle(Config.TextPadding, Config.TextPadding, textRenderSize.Width + 2, textRenderSize.Height + 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
TextRenderer.DrawText(g, Config.Text, Config.TextFont, textRect, Color.FromArgb(240, 240, 240), TextFormatFlags.Left | TextFormatFlags.EndEllipsis);
|
||||||
}
|
}
|
||||||
|
|
||||||
Color borderColor = ShareXResources.UseCustomTheme ? ShareXResources.Theme.BorderColor : SystemColors.ControlText;
|
Color borderColor = ShareXResources.UseCustomTheme ? ShareXResources.Theme.BorderColor : SystemColors.ControlText;
|
||||||
|
|
|
@ -816,15 +816,17 @@ public static void OpenScreenColorPicker(TaskSettings taskSettings = null)
|
||||||
|
|
||||||
if (!taskSettings.AdvancedSettings.DisableNotifications)
|
if (!taskSettings.AdvancedSettings.DisableNotifications)
|
||||||
{
|
{
|
||||||
|
// TODO: Translate
|
||||||
|
string tipTitle = "ShareX - " + "Screen color picker";
|
||||||
string tipText = string.Format(Resources.TaskHelpers_OpenQuickScreenColorPicker_Copied_to_clipboard___0_, text);
|
string tipText = string.Format(Resources.TaskHelpers_OpenQuickScreenColorPicker_Copied_to_clipboard___0_, text);
|
||||||
|
|
||||||
switch (taskSettings.GeneralSettings.PopUpNotification)
|
switch (taskSettings.GeneralSettings.PopUpNotification)
|
||||||
{
|
{
|
||||||
case PopUpNotificationType.BalloonTip:
|
case PopUpNotificationType.BalloonTip:
|
||||||
ShowBalloonTip(tipText, ToolTipIcon.Info, 3000);
|
ShowBalloonTip(tipText, ToolTipIcon.Info, 3000, tipTitle);
|
||||||
break;
|
break;
|
||||||
case PopUpNotificationType.ToastNotification:
|
case PopUpNotificationType.ToastNotification:
|
||||||
ShowNotificationTip(tipText);
|
ShowNotificationTip(tipText, tipTitle);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1869,7 +1871,7 @@ public static void ShowBalloonTip(string text, ToolTipIcon icon, int timeout, st
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ShowNotificationTip(string text)
|
public static void ShowNotificationTip(string text, string title = "ShareX")
|
||||||
{
|
{
|
||||||
NotificationFormConfig toastConfig = new NotificationFormConfig()
|
NotificationFormConfig toastConfig = new NotificationFormConfig()
|
||||||
{
|
{
|
||||||
|
@ -1877,7 +1879,8 @@ public static void ShowNotificationTip(string text)
|
||||||
FadeDuration = (int)(Program.DefaultTaskSettings.AdvancedSettings.ToastWindowFadeDuration * 1000),
|
FadeDuration = (int)(Program.DefaultTaskSettings.AdvancedSettings.ToastWindowFadeDuration * 1000),
|
||||||
Placement = Program.DefaultTaskSettings.AdvancedSettings.ToastWindowPlacement,
|
Placement = Program.DefaultTaskSettings.AdvancedSettings.ToastWindowPlacement,
|
||||||
Size = Program.DefaultTaskSettings.AdvancedSettings.ToastWindowSize,
|
Size = Program.DefaultTaskSettings.AdvancedSettings.ToastWindowSize,
|
||||||
Text = text
|
Text = text,
|
||||||
|
Title = title
|
||||||
};
|
};
|
||||||
|
|
||||||
NotificationForm.Show(toastConfig);
|
NotificationForm.Show(toastConfig);
|
||||||
|
|
Loading…
Reference in a new issue