Changed the animation to something less... irritating and made it skip when OptimizeForRemoteDesktop is true.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2370 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-12-10 11:53:57 +00:00
commit 88b869499a

View file

@ -34,34 +34,41 @@ using GreenshotPlugin.Core;
using Greenshot.IniFile; using Greenshot.IniFile;
namespace Greenshot { namespace Greenshot {
/// <summary> /// <summary>
/// The about form /// The about form
/// </summary> /// </summary>
public partial class AboutForm : BaseForm { public partial class AboutForm : BaseForm {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(AboutForm)); private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(AboutForm));
private Bitmap gBitmap = new Bitmap(90, 90, PixelFormat.Format32bppRgb); private Bitmap gBitmap = new Bitmap(90, 90, PixelFormat.Format32bppRgb);
private ColorAnimator backgroundColor; private ColorAnimator backgroundAnimation;
private List<RectangleAnimator> pixels = new List<RectangleAnimator>(); private List<RectangleAnimator> pixels = new List<RectangleAnimator>();
private List<Color> colorFlow = new List<Color>(); private List<Color> colorFlow = new List<Color>();
private List<Color> pixelColors = new List<Color>(); private List<Color> pixelColors = new List<Color>();
private IntAnimator angleAnimator; //private IntAnimator angleAnimator;
private Random rand = new Random(); private Random rand = new Random();
private Color backColor = Color.FromArgb(61, 61, 61); private readonly Color backColor = Color.FromArgb(61, 61, 61);
private Color pixelColor = Color.FromArgb(138, 255, 0); private readonly Color pixelColor = Color.FromArgb(138, 255, 0);
private int waitFrames = 0;
private int colorIndex = 0; // Variables used for the color-cycle
private int scrollCount = 0; private int waitFrames = 0;
private int colorIndex = 0;
private const int w = 13; private int scrollCount = 0;
private const int p1 = 7; private bool hasAnimationsLeft;
private const int p2 = p1+w;
private const int p3 = p2+w; // Variables are used to define the location of the dots
private const int p4 = p3+w; private const int w = 13;
private const int p5 = p4+w; private const int p1 = 7;
private const int p6 = p5+w; private const int p2 = p1 + w;
private const int p7 = p6+w; private const int p3 = p2 + w;
private const int p4 = p3 + w;
private List<Point> gSpots = new List<Point>() { private const int p5 = p4 + w;
private const int p6 = p5 + w;
private const int p7 = p6 + w;
/// <summary>
/// The location of every dot in the "G"
/// </summary>
private List<Point> gSpots = new List<Point>() {
// Top row // Top row
new Point(p2, p1), // 0 new Point(p2, p1), // 0
new Point(p3, p1), // 1 new Point(p3, p1), // 1
@ -98,168 +105,211 @@ namespace Greenshot {
new Point(p5, p6), // 22 new Point(p5, p6), // 22
new Point(p6, p6) // 23 new Point(p6, p6) // 23
}; };
// 0 1 2 3 4
// 5 6
// 7 8
// 9 10 11 12 13
// 14 15 16 17
// 18 19 20 21 22 23
List<int> flowOrder = new List<int>() {
4, 3, 2, 1, 0, 5, 6, 7, 8, 9, 10, 14, 15, 18, 19, 20, 21, 22, 23, 16, 17, 13, 12, 11
};
public AboutForm() { // 0 1 2 3 4
EnableAnimation = true; // 5 6
// // 7 8
// The InitializeComponent() call is required for Windows Forms designer support. // 9 10 11 12 13
// // 14 15 16 17
InitializeComponent(); // 18 19 20 21 22 23
DoubleBuffered = !OptimizeForTerminalServer;
// Not needed for a Tool Window, but still for the task manager it's important // The order in which we draw the dots & flow the collors.
this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon(); List<int> flowOrder = new List<int>() { 4, 3, 2, 1, 0, 5, 6, 7, 8, 9, 10, 14, 15, 18, 19, 20, 21, 22, 23, 16, 17, 13, 12, 11 };
// Use the self drawn image /// <summary>
this.pictureBox1.Image = gBitmap; /// Constructor
Version v = Assembly.GetExecutingAssembly().GetName().Version; /// </summary>
public AboutForm() {
EnableAnimation = true;
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
DoubleBuffered = !OptimizeForTerminalServer;
// Format is like this: AssemblyVersion("Major.Minor.Build.Revision")] // Not needed for a Tool Window, but still for the task manager it's important
lblTitle.Text = "Greenshot " + v.Major + "." + v.Minor + "." + v.Build + " Build " + v.Revision + (IniConfig.IsPortable?" Portable":"") + (" (" + OSInfo.Bits +" bit)"); this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon();
//Random rand = new Random(); // Use the self drawn image
this.pictureBox1.Image = gBitmap;
// Number of frames the "fade-in" takes Version v = Assembly.GetExecutingAssembly().GetName().Version;
int frames = CalculateFrames(3000);
waitFrames = CalculateFrames(5000);
// Create pixels // Format is like this: AssemblyVersion("Major.Minor.Build.Revision")]
foreach (Point gSpot in gSpots) { lblTitle.Text = "Greenshot " + v.Major + "." + v.Minor + "." + v.Build + " Build " + v.Revision + (IniConfig.IsPortable ? " Portable" : "") + (" (" + OSInfo.Bits + " bit)");
RectangleAnimator pixelAnimation = new RectangleAnimator(new Rectangle(p4, p3, 0, 0), new Rectangle(gSpot.X, gSpot.Y, w-2, w-2), frames, EasingType.Sine, EasingMode.EaseIn);
pixels.Add(pixelAnimation);
pixelColors.Add(pixelColor);
}
// Pixel Color animation
ColorAnimator pixelColorAnimator = new ColorAnimator(pixelColor, Color.FromArgb(255, 255, 255), 6, EasingType.Quadratic, EasingMode.EaseIn);
pixelColorAnimator.QueueDestinationLeg(pixelColor, 6, EasingType.Quadratic, EasingMode.EaseOut);
do {
colorFlow.Add(pixelColorAnimator.Current);
pixelColorAnimator.Next();
} while (pixelColorAnimator.hasNext);
// color animation //Random rand = new Random();
backgroundColor = new ColorAnimator(this.BackColor, backColor, frames, EasingType.Linear, EasingMode.EaseIn);
// Angle animation
angleAnimator = new IntAnimator(-30, 20, frames, EasingType.Sine, EasingMode.EaseIn);
}
/// <summary>
/// This is called when a link is clicked
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void LinkLabelClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) {
LinkLabel linkLabel = sender as LinkLabel;
if (linkLabel != null) {
try {
linkLabel.LinkVisited = true;
System.Diagnostics.Process.Start(linkLabel.Text);
} catch (Exception) {
MessageBox.Show(Language.GetFormattedString(LangKey.error_openlink, linkLabel.Text), Language.GetString(LangKey.error));
}
}
}
protected override void Animate() {
// Color cycle
if (waitFrames != 0) {
waitFrames--;
} else if (scrollCount < (pixelColors.Count + colorFlow.Count)) {
// Scroll colors, the scrollCount is the amount of pixels + the amount of colors to cycle.
for (int index = pixelColors.Count - 1; index > 0; index--) {
pixelColors[flowOrder[index]] = pixelColors[flowOrder[index-1]];
}
// Keep adding from the colors to cycle until there is nothing left
if (colorIndex < colorFlow.Count) {
pixelColors[flowOrder[0]] = colorFlow[colorIndex++];
}
scrollCount++;
} else {
// Reset values, wait X time for the next one
waitFrames = CalculateFrames(rand.Next(40000));
colorIndex = 0;
scrollCount = 0;
}
// Draw the "G" // Number of frames the "fade-in" takes
using (Graphics graphics = Graphics.FromImage(gBitmap)) { int frames = CalculateFrames(1400);
graphics.SmoothingMode = SmoothingMode.HighQuality; // The number of frames the color-cycle waits before it starts
graphics.InterpolationMode = InterpolationMode.HighQualityBilinear; waitFrames = CalculateFrames(5000);
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.Clear(backgroundColor.Next()); // Every pixel is created after pixelWaitFrames frames, which is increased in the loop.
int pixelWaitFrames = CalculateFrames(100);
graphics.TranslateTransform(2, -2); // Create pixels
graphics.RotateTransform(angleAnimator.Next()); for (int index = 0; index < gSpots.Count; index++) {
// Read the pixels in the order of the flow
Point gSpot = gSpots[flowOrder[index]];
// Create the animation, first we do nothing (on the final destination)
RectangleAnimator pixelAnimation;
using (SolidBrush brush = new SolidBrush(pixelColor)) { // If the optimize for Terminal Server is set we make the animation without much ado
int index = 0; if (OptimizeForTerminalServer) {
// Pixels of the G // No animation
foreach (RectangleAnimator pixel in pixels) { pixelAnimation = new RectangleAnimator(new Rectangle(gSpot.X, gSpot.Y, w - 2, w - 2), new Rectangle(gSpot.X, gSpot.Y, w - 2, w - 2), 1, EasingType.Cubic, EasingMode.EaseIn);
brush.Color = pixelColors[index++]; } else {
graphics.FillEllipse(brush, pixel.Current); // Create the animation, first we do nothing (on the final destination)
pixel.Next(); pixelAnimation = new RectangleAnimator(new Rectangle(gSpot.X, gSpot.Y, 0, 0), new Rectangle(gSpot.X, gSpot.Y, 0, 0), pixelWaitFrames, EasingType.Cubic, EasingMode.EaseIn);
} // And than we size to the wanted size.
} pixelAnimation.QueueDestinationLeg(new Rectangle(gSpot.X, gSpot.Y, w - 2, w - 2), frames);
} }
pictureBox1.Invalidate(); // Increase the wait frames
} pixelWaitFrames += CalculateFrames(100);
// Add to the list of to be animated pixels
/// <summary> pixels.Add(pixelAnimation);
/// CmdKey handler // Add a color to the list for this pixel.
/// </summary> pixelColors.Add(pixelColor);
/// <param name="msg"></param> }
/// <param name="keyData"></param> // Make sure the frame "loop" knows we have to animate
/// <returns></returns> hasAnimationsLeft = true;
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
try { // Pixel Color cycle colors, here we use a pre-animated loop which stores the values.
switch (keyData) { ColorAnimator pixelColorAnimator = new ColorAnimator(pixelColor, Color.FromArgb(255, 255, 255), 6, EasingType.Quadratic, EasingMode.EaseIn);
case Keys.Escape: pixelColorAnimator.QueueDestinationLeg(pixelColor, 6, EasingType.Quadratic, EasingMode.EaseOut);
DialogResult = DialogResult.Cancel; do {
break; colorFlow.Add(pixelColorAnimator.Current);
case Keys.E: pixelColorAnimator.Next();
MessageBox.Show(EnvironmentInfo.EnvironmentToString(true)); } while (pixelColorAnimator.hasNext);
break;
case Keys.L: // color animation for the background
try { backgroundAnimation = new ColorAnimator(this.BackColor, backColor, frames, EasingType.Linear, EasingMode.EaseIn);
if (File.Exists( MainForm.LogFileLocation)) { // Angle animation
System.Diagnostics.Process.Start("\"" + MainForm.LogFileLocation + "\""); // angleAnimator = new IntAnimator(-30, 20, frames, EasingType.Sine, EasingMode.EaseIn);
} else { }
MessageBox.Show("Greenshot can't find the logfile, it should have been here: " + MainForm.LogFileLocation);
} /// <summary>
} catch (Exception) { /// This is called when a link is clicked
MessageBox.Show("Couldn't open the greenshot.log, it's located here: " + MainForm.LogFileLocation, "Error opening greeenshot.log", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); /// </summary>
} /// <param name="sender"></param>
break; /// <param name="e"></param>
case Keys.I: void LinkLabelClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) {
try { LinkLabel linkLabel = sender as LinkLabel;
System.Diagnostics.Process.Start("\"" + IniFile.IniConfig.ConfigLocation + "\""); if (linkLabel != null) {
} catch (Exception) { try {
MessageBox.Show("Couldn't open the greenshot.ini, it's located here: " + IniFile.IniConfig.ConfigLocation, "Error opening greeenshot.ini", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); linkLabel.LinkVisited = true;
} System.Diagnostics.Process.Start(linkLabel.Text);
break; } catch (Exception) {
default: MessageBox.Show(Language.GetFormattedString(LangKey.error_openlink, linkLabel.Text), Language.GetString(LangKey.error));
return base.ProcessCmdKey(ref msg, keyData); }
} }
} catch (Exception ex) { }
LOG.Error(string.Format("Error handling key '{0}'", keyData), ex);
} /// <summary>
return true; /// Called from the AnimatingForm, for every frame
} /// </summary>
} protected override void Animate() {
if (!OptimizeForTerminalServer) {
// Color cycle
if (waitFrames != 0) {
waitFrames--;
// Check if there is something else to do, if not we return so we don't occupy the CPU
if (!hasAnimationsLeft) {
return;
}
} else if (scrollCount < (pixelColors.Count + colorFlow.Count)) {
// Scroll colors, the scrollCount is the amount of pixels + the amount of colors to cycle.
for (int index = pixelColors.Count - 1; index > 0; index--) {
pixelColors[index] = pixelColors[index - 1];
}
// Keep adding from the colors to cycle until there is nothing left
if (colorIndex < colorFlow.Count) {
pixelColors[0] = colorFlow[colorIndex++];
}
scrollCount++;
} else {
// Reset values, wait X time for the next one
waitFrames = CalculateFrames(3000 + rand.Next(35000));
colorIndex = 0;
scrollCount = 0;
// Check if there is something else to do, if not we return so we don't occupy the CPU
if (!hasAnimationsLeft) {
return;
}
}
} else if (!hasAnimationsLeft) {
return;
}
// Draw the "G"
using (Graphics graphics = Graphics.FromImage(gBitmap)) {
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.Clear(backgroundAnimation.Next());
graphics.TranslateTransform(2, -2);
//graphics.RotateTransform(angleAnimator.Next());
graphics.RotateTransform(20);
using (SolidBrush brush = new SolidBrush(pixelColor)) {
int index = 0;
// We asume there is nothing to animate in the next Animate loop
hasAnimationsLeft = false;
// Pixels of the G
foreach (RectangleAnimator pixel in pixels) {
brush.Color = pixelColors[index++];
graphics.FillEllipse(brush, pixel.Current);
// If a pixel still has frames left, the hasAnimationsLeft will be true
hasAnimationsLeft = hasAnimationsLeft | pixel.hasNext;
pixel.Next();
}
}
}
pictureBox1.Invalidate();
}
/// <summary>
/// CmdKey handler
/// </summary>
/// <param name="msg"></param>
/// <param name="keyData"></param>
/// <returns></returns>
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
try {
switch (keyData) {
case Keys.Escape:
DialogResult = DialogResult.Cancel;
break;
case Keys.E:
MessageBox.Show(EnvironmentInfo.EnvironmentToString(true));
break;
case Keys.L:
try {
if (File.Exists(MainForm.LogFileLocation)) {
System.Diagnostics.Process.Start("\"" + MainForm.LogFileLocation + "\"");
} else {
MessageBox.Show("Greenshot can't find the logfile, it should have been here: " + MainForm.LogFileLocation);
}
} catch (Exception) {
MessageBox.Show("Couldn't open the greenshot.log, it's located here: " + MainForm.LogFileLocation, "Error opening greeenshot.log", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
break;
case Keys.I:
try {
System.Diagnostics.Process.Start("\"" + IniFile.IniConfig.ConfigLocation + "\"");
} catch (Exception) {
MessageBox.Show("Couldn't open the greenshot.ini, it's located here: " + IniFile.IniConfig.ConfigLocation, "Error opening greeenshot.ini", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
break;
default:
return base.ProcessCmdKey(ref msg, keyData);
}
} catch (Exception ex) {
LOG.Error(string.Format("Error handling key '{0}'", keyData), ex);
}
return true;
}
}
} }