Moving back to trunk!

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1602 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-01-24 19:24:36 +00:00
parent ad265b2c54
commit 8d458998a1
332 changed files with 17647 additions and 9466 deletions

View file

@ -1,6 +1,6 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2010 Thomas Braun, Jens Klingen, Robin Krom
* Copyright (C) 2007-2011 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
@ -27,6 +27,8 @@ using System.Text;
using System.Windows.Forms;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
using IniFile;
namespace PluginExample {
/// <summary>
@ -34,37 +36,38 @@ namespace PluginExample {
/// </summary>
public class PluginExample : IGreenshotPlugin {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(PluginExample));
private IGreenshotPluginHost host;
private ICaptureHost captureHost = null;
private IGreenshotHost host;
private PluginAttribute myAttributes;
private bool testAnnotations = false;
public PluginExample() {
}
public IEnumerable<IDestination> Destinations() {
yield return new SimpleOutputDestination(host);
}
public IEnumerable<IProcessor> Processors() {
yield return new AnnotateProcessor(host);
yield return new GreyscaleProcessor(host);
}
/// <summary>
/// Implementation of the IGreenshotPlugin.Initialize
/// </summary>
/// <param name="host">Use the IGreenshotPluginHost interface to register events</param>
/// <param name="pluginHost">Use the IGreenshotPluginHost interface to register events</param>
/// <param name="captureHost">Use the ICaptureHost interface to register in the MainContextMenu</param>
/// <param name="pluginAttribute">My own attributes</param>
public virtual void Initialize(IGreenshotPluginHost pluginHost, ICaptureHost captureHost, PluginAttribute myAttributes) {
/// <returns>true if plugin is initialized, false if not (doesn't show)</returns>
public virtual bool Initialize(IGreenshotHost pluginHost, PluginAttribute myAttributes) {
LOG.Debug("Initialize called of " + myAttributes.Name);
this.host = (IGreenshotPluginHost)pluginHost;
this.captureHost = captureHost;
this.host = pluginHost;
this.myAttributes = myAttributes;
this.host.OnImageEditorOpen += new OnImageEditorOpenHandler(ImageEditorOpened);
this.host.OnSurfaceFromCapture += new OnSurfaceFromCaptureHandler(SurfaceFromCapture);
this.host.OnImageOutput += new OnImageOutputHandler(ImageOutput);
return true;
}
public virtual void Shutdown() {
LOG.Debug("Shutdown of " + myAttributes.Name);
this.host.OnImageEditorOpen -= new OnImageEditorOpenHandler(ImageEditorOpened);
this.host.OnSurfaceFromCapture -= new OnSurfaceFromCaptureHandler(SurfaceFromCapture);
this.host.OnImageOutput -= new OnImageOutputHandler(ImageOutput);
}
/// <summary>
@ -72,123 +75,8 @@ namespace PluginExample {
/// </summary>
public virtual void Configure() {
LOG.Debug("Configure called");
SettingsForm settingsForm = new SettingsForm(testAnnotations);
DialogResult result = settingsForm.ShowDialog();
if (result == DialogResult.OK) {
testAnnotations = settingsForm.TestAnnotations;
}
settingsForm.Dispose();
}
/// <summary>
/// Implementation of the OnImageEditorOpen event
/// Using the ImageEditor interface to register in the plugin menu
/// </summary>
private void ImageEditorOpened(object sender, ImageEditorOpenEventArgs eventArgs) {
LOG.Debug("ImageEditorOpened called");
ToolStripMenuItem toolStripMenuItem = eventArgs.ImageEditor.GetPluginMenuItem();
ToolStripMenuItem saveItem = new ToolStripMenuItem();
saveItem.Text = "Save with Plugin";
saveItem.Tag = eventArgs.ImageEditor;
saveItem.Click += new System.EventHandler(EditMenuClick);
toolStripMenuItem.DropDownItems.Add(saveItem);
ToolStripMenuItem grayscaleItem = new ToolStripMenuItem();
grayscaleItem.Text = "Turn bitmap into gray-scales";
grayscaleItem.Tag = eventArgs.ImageEditor;
grayscaleItem.Click += new System.EventHandler(GrayScaleMenuClick);
toolStripMenuItem.DropDownItems.Add(grayscaleItem);
}
private void MainMenuClick(object sender, EventArgs e) {
LOG.Debug("Sympathy for the Devil!");
Bitmap bitmap = new Bitmap(100, 100, PixelFormat.Format16bppRgb555);
captureHost.HandleCapture(bitmap);
bitmap.Dispose();
}
/// <summary>
/// This will be called when the menu item in the Editor is clicked
/// Just an example...
/// </summary>
private void EditMenuClick(object sender, EventArgs e) {
ToolStripMenuItem item = (ToolStripMenuItem)sender;
IImageEditor imageEditor = (IImageEditor)item.Tag;
string file = host.GetFilename("png", null);
string filePath = Path.Combine(host.ConfigurationPath,file);
using (FileStream stream = new FileStream(filePath, FileMode.Create)) {
imageEditor.SaveToStream(stream, "PNG", 100);
}
LOG.Debug("Saved test file to: " + filePath);
}
/// <summary>
/// This will be called when the menu item in the Editor is clicked
/// Just an example...
/// </summary>
private void GrayScaleMenuClick(object sender, EventArgs e) {
ToolStripMenuItem item = (ToolStripMenuItem)sender;
IImageEditor imageEditor = (IImageEditor)item.Tag;
ISurface surface = imageEditor.Surface;
// copy & do something with the image
Image image = (Image)surface.OriginalImage.Clone();
using (BitmapBuffer bbb = new BitmapBuffer(image as Bitmap)) {
// Image is copied, dispose it!
image.Dispose();
bbb.Lock();
for(int y=0;y<bbb.Height; y++) {
for(int x=0;x<bbb.Width; x++) {
Color color = bbb.GetColorAt(x, y);
int luma = (int)((0.3*color.R) + (0.59*color.G) + (0.11*color.B));
color = Color.FromArgb(luma, luma, luma);
bbb.SetColorAt(x, y, color);
}
}
surface.Image = bbb.Bitmap;
}
}
/// <summary>
/// Handling of the OnImageOutputHandler event from the IGreenshotPlugin
/// </summary>
/// <param name="ImageOutputEventArgs">Has the FullPath to the image</param>
private void ImageOutput(object sender, ImageOutputEventArgs eventArgs) {
LOG.Debug("ImageOutput called with full path: " + eventArgs.FullPath);
}
/// <summary>
/// Handling of the OnSurfaceFromCapture event from the IGreenshotPlugin
/// </summary>
/// <param name="SurfaceFromCaptureEventArgs">Has the ICapture and ISurface</param>
public void SurfaceFromCapture(object sender, SurfaceFromCaptureEventArgs eventArgs) {
LOG.Debug("SurfaceFromCapture called");
if (!testAnnotations) {
return;
}
ISurface surface = eventArgs.Surface;
surface.SelectElement(surface.AddCursorContainer(Cursors.Hand, 100, 100));
// Do something with the screenshot
string title = eventArgs.Capture.CaptureDetails.Title;
if (title != null) {
LOG.Debug("Added title to surface: " + title);
surface.SelectElement(surface.AddTextContainer(title, HorizontalAlignment.Center, VerticalAlignment.CENTER,
FontFamily.GenericSansSerif, 12f, false, false, false, 2, Color.Red, Color.White));
surface.SelectElement(surface.AddTextContainer(Environment.UserName, HorizontalAlignment.Right, VerticalAlignment.TOP,
FontFamily.GenericSansSerif, 12f, false, false, false, 2, Color.Red, Color.White));
surface.SelectElement(surface.AddTextContainer(Environment.MachineName, HorizontalAlignment.Right, VerticalAlignment.BOTTOM,
FontFamily.GenericSansSerif, 12f, false, false, false, 2, Color.Red, Color.White));
surface.SelectElement(surface.AddTextContainer(eventArgs.Capture.CaptureDetails.DateTime.ToLongDateString(), HorizontalAlignment.Left, VerticalAlignment.BOTTOM,
FontFamily.GenericSansSerif, 12f, false, false, false, 2, Color.Red, Color.White));
} else {
LOG.Debug("No title available, doing nothing.");
}
SettingsForm settingsForm = new SettingsForm();
settingsForm.ShowDialog();
}
}
}