Updated the about form to have an animation, which is not yet finished.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2368 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-12-07 20:40:17 +00:00
commit 9803c91122
4 changed files with 263 additions and 97 deletions

View file

@ -1,27 +1,32 @@
/* /*
* Greenshot - a free and open source screenshot tool * Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom * Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
* *
* For more information see: http://getgreenshot.org/ * For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/ * The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or * the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
using System; using System;
using System.Reflection; using System.Reflection;
using System.Windows.Forms; using System.Windows.Forms;
using System.IO; using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using Greenshot.Helpers; using Greenshot.Helpers;
using Greenshot.Configuration; using Greenshot.Configuration;
@ -29,81 +34,177 @@ 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));
public AboutForm() { private Bitmap gBitmap = new Bitmap(90, 90, PixelFormat.Format32bppRgb);
// private ColorAnimator backgroundColor;
// The InitializeComponent() call is required for Windows Forms designer support. private List<RectangleAnimator> pixels = new List<RectangleAnimator>();
// private IntAnimator angleAnimator;
InitializeComponent();
// Not needed for a Tool Window: private const int w = 13;
//this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon(); private const int p1 = 7;
this.pictureBox1.Image = GreenshotPlugin.Core.GreenshotResources.getGreenshotImage(); private const int p2 = p1+w;
Version v = Assembly.GetExecutingAssembly().GetName().Version; private const int p3 = p2+w;
// Format is like this: AssemblyVersion("Major.Minor.Build.Revision")] private const int p4 = p3+w;
lblTitle.Text = "Greenshot " + v.Major + "." + v.Minor + "." + v.Build + " Build " + v.Revision + (IniConfig.IsPortable?" Portable":"") + (" (" + OSInfo.Bits +" bit)"); private const int p5 = p4+w;
} private const int p6 = p5+w;
private const int p7 = p6+w;
private List<Point> gSpots = new List<Point>() {
// Top row
new Point(p2, p1),
new Point(p3, p1),
new Point(p4, p1),
new Point(p5, p1),
new Point(p6, p1),
/// <summary> // Second row
/// This is called when a link is clicked new Point(p1, p2),
/// </summary> new Point(p2, p2),
/// <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));
}
}
}
/// <summary> // Third row
/// CmdKey handler new Point(p1, p3),
/// </summary> new Point(p2, p3),
/// <param name="msg"></param>
/// <param name="keyData"></param> // Fourth row
/// <returns></returns> new Point(p1, p4),
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { new Point(p2, p4),
try { new Point(p5, p4),
switch (keyData) { new Point(p6, p4),
case Keys.Escape: new Point(p7, p4),
DialogResult = DialogResult.Cancel;
break; // Fifth row
case Keys.E: new Point(p1, p5),
MessageBox.Show(EnvironmentInfo.EnvironmentToString(true)); new Point(p2, p5),
break; new Point(p6, p5),
case Keys.L: new Point(p7, p5),
try {
if (File.Exists( MainForm.LogFileLocation)) { // Sixth row
System.Diagnostics.Process.Start("\"" + MainForm.LogFileLocation + "\""); new Point(p1, p6),
} else { new Point(p2, p6),
MessageBox.Show("Greenshot can't find the logfile, it should have been here: " + MainForm.LogFileLocation); new Point(p3, p6),
} new Point(p4, p6),
} catch (Exception) { new Point(p5, p6),
MessageBox.Show("Couldn't open the greenshot.log, it's located here: " + MainForm.LogFileLocation, "Error opening greeenshot.log", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); new Point(p6, p6)
} };
break;
case Keys.I: public AboutForm() {
try { EnableAnimation = true;
System.Diagnostics.Process.Start("\"" + IniFile.IniConfig.ConfigLocation + "\""); //
} catch (Exception) { // The InitializeComponent() call is required for Windows Forms designer support.
MessageBox.Show("Couldn't open the greenshot.ini, it's located here: " + IniFile.IniConfig.ConfigLocation, "Error opening greeenshot.ini", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); //
} InitializeComponent();
break; DoubleBuffered = !OptimizeForTerminalServer;
default:
return base.ProcessCmdKey(ref msg, keyData); // Not needed for a Tool Window, but still for the task manager it's important
} this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon();
} catch (Exception ex) {
LOG.Error(string.Format("Error handling key '{0}'", keyData), ex); // Use the self drawn image
} this.pictureBox1.Image = gBitmap;
return true; Version v = Assembly.GetExecutingAssembly().GetName().Version;
}
} // Format is like this: AssemblyVersion("Major.Minor.Build.Revision")]
} lblTitle.Text = "Greenshot " + v.Major + "." + v.Minor + "." + v.Build + " Build " + v.Revision + (IniConfig.IsPortable?" Portable":"") + (" (" + OSInfo.Bits +" bit)");
//Random rand = new Random();
// Number of frames the "fade-in" takes
int frames = CalculateFrames(3000);
// Create pixels
foreach (Point gSpot in gSpots) {
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);
}
// color animation
backgroundColor = new ColorAnimator(this.BackColor, Color.FromArgb(61, 61, 61), 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() {
using (Graphics graphics = Graphics.FromImage(gBitmap)) {
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.Clear(backgroundColor.Next());
graphics.TranslateTransform(2, -2);
graphics.RotateTransform(angleAnimator.Next());
using (SolidBrush brush = new SolidBrush(Color.FromArgb(138, 255, 0))) {
foreach (RectangleAnimator pixel in pixels) {
graphics.FillEllipse(brush, pixel.Current);
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;
}
}
}

View file

@ -180,7 +180,6 @@
<DependentUpon>MovableShowColorForm.cs</DependentUpon> <DependentUpon>MovableShowColorForm.cs</DependentUpon>
</Compile> </Compile>
<None Include="App.config" /> <None Include="App.config" />
<Compile Include="Helpers\AnimationHelper.cs" />
<Compile Include="Helpers\AviHelper.cs" /> <Compile Include="Helpers\AviHelper.cs" />
<Compile Include="Helpers\CaptureHelper.cs" /> <Compile Include="Helpers\CaptureHelper.cs" />
<Compile Include="Helpers\Colors.cs" /> <Compile Include="Helpers\Colors.cs" />

View file

@ -23,7 +23,7 @@ using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Collections.Generic; using System.Collections.Generic;
namespace Greenshot.Helpers { namespace GreenshotPlugin.Core {
/// <summary> /// <summary>
/// Helper interface for passing base type /// Helper interface for passing base type
@ -332,6 +332,71 @@ namespace Greenshot.Helpers {
} }
} }
/// <summary>
/// Implementation of the ColorAnimator
/// </summary>
public class ColorAnimator : AnimatorBase<Color> {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ColorAnimator));
public ColorAnimator(Color first, Color last, int frames)
: base(first, last, frames, EasingType.Linear, EasingMode.EaseIn) {
}
public ColorAnimator(Color first, Color last, int frames, EasingType easingType)
: base(first, last, frames, easingType, EasingMode.EaseIn) {
}
public ColorAnimator(Color first, Color last, int frames, EasingType easingType, EasingMode easingMode)
: base(first, last, frames, easingType, easingMode) {
}
/// <summary>
/// Calculate the next frame values
/// </summary>
/// <returns>Color</returns>
public override Color Next() {
if (NextFrame) {
double easingValue = EasingValue;
double da = last.A - first.A;
double dr = last.R - first.R;
double dg = last.G - first.G;
double db = last.B - first.B;
int a = first.A + (int)(easingValue * da);
int r = first.R + (int)(easingValue * dr);
int g = first.G + (int)(easingValue * dg);
int b = first.B + (int)(easingValue * db);
current = Color.FromArgb(a,r,g,b);
}
return current;
}
}
/// <summary>
/// Implementation of the IntAnimator
/// </summary>
public class IntAnimator : AnimatorBase<int> {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(IntAnimator));
public IntAnimator(int first, int last, int frames)
: base(first, last, frames, EasingType.Linear, EasingMode.EaseIn) {
}
public IntAnimator(int first, int last, int frames, EasingType easingType)
: base(first, last, frames, easingType, EasingMode.EaseIn) {
}
public IntAnimator(int first, int last, int frames, EasingType easingType, EasingMode easingMode)
: base(first, last, frames, easingType, easingMode) {
}
/// <summary>
/// Calculate the next frame values
/// </summary>
/// <returns>int</returns>
public override int Next() {
if (NextFrame) {
double easingValue = EasingValue;
double delta = last - first;
current = first + (int)(easingValue * delta);
}
return current;
}
}
/// <summary> /// <summary>
/// Easing logic, to make the animations more "fluent" /// Easing logic, to make the animations more "fluent"
/// </summary> /// </summary>

View file

@ -140,6 +140,7 @@
<Compile Include="Core\AbstractDestination.cs" /> <Compile Include="Core\AbstractDestination.cs" />
<Compile Include="Core\AbstractProcessor.cs" /> <Compile Include="Core\AbstractProcessor.cs" />
<Compile Include="Core\AccessibleHelper.cs" /> <Compile Include="Core\AccessibleHelper.cs" />
<Compile Include="Core\AnimationHelpers.cs" />
<Compile Include="Core\BinaryStructHelper.cs" /> <Compile Include="Core\BinaryStructHelper.cs" />
<Compile Include="Core\BitmapBuffer.cs" /> <Compile Include="Core\BitmapBuffer.cs" />
<Compile Include="Core\Cache.cs" /> <Compile Include="Core\Cache.cs" />