Added custom tooltips for tool menu

This commit is contained in:
Jaex 2016-10-02 19:01:55 +03:00
parent 75cd1e5d20
commit e9f5ea2694
3 changed files with 47 additions and 28 deletions

View file

@ -545,6 +545,12 @@ private void Draw(Graphics g)
{
DrawCrosshair(g);
}
// Draw menu tooltips
if (IsAnnotationMode && ShapeManager.MenuTextAnimation.Update())
{
DrawTextAnimation(g, ShapeManager.MenuTextAnimation);
}
}
private void DrawObjects(Graphics g)
@ -639,23 +645,19 @@ private void DrawTips(Graphics g)
DrawInfoText(g, tipText, textRectangle, infoFont, padding);
}
private void DrawTopCenterTip(Graphics g, string text, double opacity = 1)
private void DrawTextAnimation(Graphics g, TextAnimation textAnimation)
{
Size textSize = g.MeasureString(text, infoFontMedium).ToSize();
int offset = 10;
Size textSize = g.MeasureString(textAnimation.Text, infoFontMedium).ToSize();
int padding = 3;
int rectWidth = textSize.Width + padding * 2;
int rectHeight = textSize.Height + padding * 2;
Rectangle screenBounds = CaptureHelpers.GetActiveScreenBounds0Based();
Rectangle textRectangle = new Rectangle(screenBounds.X + (screenBounds.Width / 2) - (rectWidth / 2), screenBounds.Y + offset, rectWidth, rectHeight);
Rectangle textRectangle = new Rectangle(textAnimation.Position.X, textAnimation.Position.Y, textSize.Width + padding * 2, textSize.Height + padding * 2);
using (Brush backgroundBrush = new SolidBrush(Color.FromArgb((int)(opacity * 75), Color.Black)))
using (Pen outerBorderPen = new Pen(Color.FromArgb((int)(opacity * 50), Color.White)))
using (Pen innerBorderPen = new Pen(Color.FromArgb((int)(opacity * 150), Color.Black)))
using (Brush textBrush = new SolidBrush(Color.FromArgb((int)(opacity * 255), Color.White)))
using (Brush textShadowBrush = new SolidBrush(Color.FromArgb((int)(opacity * 255), Color.Black)))
using (Brush backgroundBrush = new SolidBrush(Color.FromArgb((int)(textAnimation.Opacity * 175), Color.FromArgb(44, 135, 206))))
using (Pen outerBorderPen = new Pen(Color.FromArgb((int)(textAnimation.Opacity * 175), Color.White)))
using (Pen innerBorderPen = new Pen(Color.FromArgb((int)(textAnimation.Opacity * 175), Color.FromArgb(0, 81, 145))))
using (Brush textBrush = new SolidBrush(Color.FromArgb((int)(textAnimation.Opacity * 255), Color.White)))
using (Brush textShadowBrush = new SolidBrush(Color.FromArgb((int)(textAnimation.Opacity * 255), Color.Black)))
{
DrawInfoText(g, text, textRectangle, infoFontMedium, padding, backgroundBrush, outerBorderPen, innerBorderPen, textBrush, textShadowBrush);
DrawInfoText(g, textAnimation.Text, textRectangle, infoFontMedium, padding, backgroundBrush, outerBorderPen, innerBorderPen, textBrush, textShadowBrush);
}
}

View file

@ -26,6 +26,7 @@ You should have received a copy of the GNU General Public License
using ShareX.HelpersLib;
using System;
using System.Diagnostics;
using System.Drawing;
namespace ShareX.ScreenCaptureLib
{
@ -33,6 +34,8 @@ internal class TextAnimation
{
public string Text { get; private set; }
public Point Position { get; set; }
private double opacity;
public double Opacity
@ -50,21 +53,9 @@ private set
public TimeSpan Duration { get; private set; }
public TimeSpan FadeDuration { get; private set; }
public TimeSpan TotalDuration
{
get
{
return Duration + FadeDuration;
}
}
public TimeSpan TotalDuration => Duration + FadeDuration;
public bool Active
{
get
{
return timer.IsRunning && timer.Elapsed <= TotalDuration;
}
}
public bool Active => timer.IsRunning && timer.Elapsed <= TotalDuration;
private Stopwatch timer = new Stopwatch();
@ -81,7 +72,12 @@ public void Start(string text)
timer.Restart();
}
public void Update()
public void Stop()
{
timer.Stop();
}
public bool Update()
{
if (Active)
{
@ -91,7 +87,13 @@ public void Update()
{
timer.Stop();
}
else
{
return true;
}
}
return false;
}
}
}

View file

@ -34,6 +34,8 @@ namespace ShareX.ScreenCaptureLib
{
internal partial class ShapeManager
{
internal TextAnimation MenuTextAnimation = new TextAnimation(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(0.5));
private Form menuForm;
private ToolStripEx tsMain;
private ToolStripButton tsbUndoObject, tsbDeleteAll;
@ -632,6 +634,19 @@ private void CreateMenu()
menuForm.Location = rectActiveScreen.Location;
}
foreach (ToolStripButton tsb in tsMain.Items.OfType<ToolStripButton>())
{
tsb.MouseEnter += (sender, e) =>
{
Point pos = CaptureHelpers.ScreenToClient(menuForm.PointToScreen(tsb.Bounds.Location));
pos.Y += tsb.Height + 8;
MenuTextAnimation.Position = pos;
MenuTextAnimation.Start(tsb.ToolTipText);
};
tsb.MouseLeave += (sender, e) => MenuTextAnimation.Stop();
}
form.Activate();
UpdateMenu();