refactoring: moved interfaces from GreenshotPlugin to GreenshotCore

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@704 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
JKlingen 2010-07-25 18:20:18 +00:00
parent 0dffa6054b
commit 01d843e8cf
46 changed files with 80 additions and 103 deletions

View file

@ -1,57 +0,0 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2010 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/
*
* 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
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Drawing;
namespace Greenshot.Drawing.Fields {
/// <summary>
/// Defines all FieldTypes + their default value.
/// (The additional value is why this is not an enum)
/// </summary>
[Serializable]
public enum FieldType {
ARROWHEADS,
BLUR_RADIUS,
BRIGHTNESS,
FILL_COLOR,
FONT_BOLD,
FONT_FAMILY,
FONT_ITALIC,
FONT_SIZE,
HIGHLIGHT_COLOR,
LINE_COLOR,
LINE_THICKNESS,
MAGNIFICATION_FACTOR,
PIXEL_SIZE,
PREVIEW_QUALITY,
SHADOW,
PREPARED_FILTER_OBFUSCATE,
PREPARED_FILTER_HIGHLIGHT,
FLAGS
}
[Flags]
public enum FieldFlag {
NONE = 0,
CONFIRMABLE = 1
}
}

View file

@ -41,16 +41,25 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Folder Include="Drawing" />
<Folder Include="Drawing\Fields" />
<Folder Include="Interfaces\Drawing" />
<Folder Include="Interfaces\Drawing\Fields" />
<Folder Include="Interfaces\Forms" />
<Folder Include="Interfaces\Capturing" />
<Folder Include="Interfaces\Plugin" />
<Folder Include="Lib" />
<Folder Include="Interfaces" />
<Folder Include="UnmanagedHelpers" />
<Compile Include="Drawing\Fields\FieldType.cs" />
<Compile Include="Drawing\Fields\IField.cs" />
<Compile Include="Drawing\Fields\IFieldHolder.cs" />
<Compile Include="Interfaces\Capturing\Capture.cs" />
<Compile Include="Interfaces\Drawing\IDrawableContainer.cs" />
<Compile Include="Interfaces\Drawing\Fields\IField.cs" />
<Compile Include="Interfaces\Drawing\Fields\IFieldHolder.cs" />
<Compile Include="Interfaces\Drawing\ISurface.cs" />
<Compile Include="Interfaces\Forms\IImageEditor.cs" />
<Compile Include="Interfaces\Plugin\PluginInterfaces.cs" />
<Compile Include="UnmanagedHelpers\GDI32.cs" />
<Compile Include="UnmanagedHelpers\User32.cs" />
<Compile Include="UnmanagedHelpers\Win32Errors.cs" />

View file

@ -0,0 +1,179 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2010 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/
*
* 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
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Greenshot.Plugin;
namespace Greenshot.Capturing {
/// <summary>
/// The capture mode for Greenshot
/// </summary>
public enum CaptureMode { None, Region, FullScreen, ActiveWindow, Window, LastRegion, Clipboard, File };
/// <summary>
/// The destinations for the capture, these will be set during capture and can be modified by plugins
/// </summary>
public enum CaptureDestination {File, FileWithDialog, Clipboard, Printer, Editor, EMail};
/// <summary>
/// Handler for the MakeCapture in ICaptureHost
/// </summary>
public delegate void CaptureHandler(object sender, CaptureTakenEventArgs e);
/// <summary>
/// The ICaptureHost is more or less the Interface that "Greenshot" itself implements (the MainForm)
/// over this Interface it is possible to register to the main ContextMenu or pass a Bitmap for processing
/// </summary>
public interface ICaptureHost {
/// <summary>
/// Process a bitmap like it was captured
/// </summary>
void HandleCapture(Bitmap bitmap);
/// <summary>
/// Make Capture with default destinations
/// </summary>
/// <param name="mode">CaptureMode</param>
/// <param name="captureMouseCursor">bool false if the mouse should not be captured, true if the configuration should be checked</param>
void MakeCapture(CaptureMode mode, bool captureMouseCursor);
/// <summary>
/// Make Capture with specified destinations
/// </summary>
/// <param name="mode">CaptureMode</param>
/// <param name="captureMouseCursor">bool false if the mouse should not be captured, true if the configuration should be checked</param>
/// <param name="captureDestinations">List<CaptureDestination> with destinations</param>
void MakeCapture(CaptureMode mode, bool captureMouseCursor, List<CaptureDestination> captureDestinations);
/// <summary>
/// Make Capture with specified Handler
/// </summary>
/// <param name="mode"></param>
/// <param name="captureMouseCursor">bool false if the mouse should not be captured, true if the configuration should be checked</param>
/// <param name="captureHandler">CaptureHandler delegate</param>
void MakeCapture(CaptureMode mode, bool captureMouseCursor, CaptureHandler captureHandler);
}
/// <summary>
/// Details for the capture, like the window title and date/time etc.
/// </summary>
public interface ICaptureDetails {
string Filename {
get;
set;
}
string Title {
get;
set;
}
DateTime DateTime {
get;
set;
}
List<CaptureDestination> CaptureDestinations {
get;
set;
}
void ClearDestinations();
void RemoveDestination(CaptureDestination captureDestination);
void AddDestination(CaptureDestination captureDestination);
CaptureHandler CaptureHandler {
get;
set;
}
CaptureMode CaptureMode {
get;
set;
}
}
/// <summary>
/// The interface to the Capture object, so Plugins can use it.
/// </summary>
public interface ICapture : IDisposable {
// The Capture Details
ICaptureDetails CaptureDetails {
get;
set;
}
// The captured Image
Image Image {
get;
set;
}
Rectangle ScreenBounds {
get;
set;
}
Icon Cursor {
get;
set;
}
// Boolean to specify if the cursor is available
bool CursorVisible {
get;
set;
}
Point CursorLocation {
get;
set;
}
Point Location {
get;
set;
}
/// <summary>
/// Crops the capture to the specified rectangle (with Bitmap coordinates!)
/// </summary>
/// <param name="cropRectangle">Rectangle with bitmap coordinates</param>
void Crop(Rectangle cropRectangle);
/// <summary>
/// Crops the capture to the specified rectangle (with screen coordinates!)
/// </summary>
/// <param name="cropRectangle">Rectangle with screen coordinates</param>
void CropWithScreenCoordinates(Rectangle cropRectangle);
/// <summary>
/// Apply a translate to the mouse location.
/// e.g. needed for crop
/// </summary>
/// <param name="x">x coordinates to move the mouse</param>
/// <param name="y">y coordinates to move the mouse</param>
void MoveMouseLocation(int x, int y);
}
}

View file

@ -45,4 +45,37 @@ namespace Greenshot.Drawing.Fields {
this.Field = field;
}
}
/// <summary>
/// All types of fields
/// </summary>
public enum FieldType {
ARROWHEADS,
BLUR_RADIUS,
BRIGHTNESS,
FILL_COLOR,
FONT_BOLD,
FONT_FAMILY,
FONT_ITALIC,
FONT_SIZE,
HIGHLIGHT_COLOR,
LINE_COLOR,
LINE_THICKNESS,
MAGNIFICATION_FACTOR,
PIXEL_SIZE,
PREVIEW_QUALITY,
SHADOW,
PREPARED_FILTER_OBFUSCATE,
PREPARED_FILTER_HIGHLIGHT,
FLAGS
}
/// <summary>
/// This enum provides values for FieldType.FLAGS
/// </summary>
[Flags]
public enum FieldFlag {
NONE = 0,
CONFIRMABLE = 1
}
}

View file

@ -0,0 +1,105 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2010 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/
*
* 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
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Forms;
namespace Greenshot.Drawing {
public enum RenderMode {EDIT, EXPORT};
public enum EditStatus {UNDRAWN, DRAWING, MOVING, RESIZING, IDLE};
public interface IDrawableContainer {
ISurface Parent {
get;
}
bool Selected {
get;
set;
}
int Left {
get;
set;
}
int Top {
get;
set;
}
int Width {
get;
set;
}
int Height {
get;
set;
}
Rectangle Bounds {
get;
}
void AlignToParent(HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment);
void Dispose();
}
public interface ITextContainer: IDrawableContainer {
string Text {
get;
set;
}
void FitToText();
}
public interface IBitmapContainer: IDrawableContainer {
Bitmap Bitmap {
get;
set;
}
void Load(string filename);
}
public interface ICursorContainer: IDrawableContainer {
Cursor Cursor {
get;
set;
}
void Load(string filename);
}
public interface IIconContainer: IDrawableContainer {
Icon Icon {
get;
set;
}
void Load(string filename);
}
public interface IMetafileContainer: IDrawableContainer {
Metafile Metafile {
get;
set;
}
void Load(string filename);
}
}

View file

@ -0,0 +1,101 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2010 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/
*
* 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
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
namespace Greenshot.Drawing {
/// <summary>
/// Alignment Enums for positioning
/// </summary>
//public enum HorizontalAlignment {LEFT, CENTER, RIGHT};
public enum VerticalAlignment {TOP, CENTER, BOTTOM};
/// <summary>
/// The interface to the Surface object, so Plugins can use it.
/// </summary>
public interface ISurface {
/// <summary>
/// Get/Set the original image from the Surface, use this if you need the captured image without anything on it!
/// </summary>
Image OriginalImage {
get;
}
/// <summary>
/// Get/Set the image to the Surface
/// get will give the image as is currently visible
/// set will overwrite both the visible image as the underlying image
///
/// important notice:
/// The setter will clone the passed bitmap and dispose it when the Surface is disposed
/// This means that the supplied image needs to be disposed by the calling code (if needed!)
/// </summary>
Image Image {
get;
set;
}
/// <summary>
/// Get the current Image from the Editor for Exporting (save/upload etc)
/// Don't forget to call image.Dispose() when finished!!!
/// </summary>
/// <returns>Bitmap</returns>
Image GetImageForExport();
/// <summary>
/// Add a TextContainer, at the given location, to the Surface.
/// The TextContainer will be "re"sized to the text size.
/// </summary>
/// <param name="text">String to show</param>
/// <param name="horizontalAlignment">Left, Center, Right</param>
/// <param name="verticalAlignment">TOP, CENTER, BOTTOM</param>
/// <param name="family">FontFamily</param>
/// <param name="size">Font Size in float</param>
/// <param name="italic">bool true if italic</param>
/// <param name="bold">bool true if bold</param>
/// <param name="shadow">bool true if shadow</param>
/// <param name="borderSize">size of border (0 for none)</param>
/// <param name="color">Color of string</param>
/// <param name="fillColor">Color of background (e.g. Color.Transparent)</param>
ITextContainer AddTextContainer(string text, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, FontFamily family, float size, bool italic, bool bold, bool shadow, int borderSize, Color color, Color fillColor);
IBitmapContainer AddBitmapContainer(Bitmap bitmap, int x, int y);
ICursorContainer AddCursorContainer(Cursor cursor, int x, int y);
IIconContainer AddIconContainer(Icon icon, int x, int y);
IMetafileContainer AddMetafileContainer(Metafile metafile, int x, int y);
IBitmapContainer AddBitmapContainer(string filename, int x, int y);
ICursorContainer AddCursorContainer(string filename, int x, int y);
IIconContainer AddIconContainer(string filename, int x, int y);
IMetafileContainer AddMetafileContainer(string filename, int x, int y);
bool HasSelectedElements();
void RemoveSelectedElements();
void CutSelectedElements();
void CopySelectedElements();
void PasteElementFromClipboard();
void DuplicateSelectedElements();
void DeselectElement(IDrawableContainer container);
void DeselectAllElements();
void SelectElement(IDrawableContainer container);
}
}

View file

@ -0,0 +1,74 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2010 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/
*
* 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
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Greenshot.Capturing;
using Greenshot.Drawing;
namespace Greenshot.Forms {
/// <summary>
/// The IImageEditor is the Interface that the Greenshot ImageEditor has to implement
/// </summary>
public interface IImageEditor {
/// <summary>
/// Return the IWin32Window, this way Plugins have access to the HWND handles wich can be used with Win32 API calls.
/// </summary>
IWin32Window WindowHandle {
get;
}
/// <summary>
/// Get the current Image from the Editor for Exporting (save/upload etc)
/// This is actually a wrapper which calls Surface.GetImageForExport().
/// Don't forget to call image.Dispose() when finished!!!
/// </summary>
/// <returns>Bitmap</returns>
Image GetImageForExport();
/// <summary>
/// Will save the current Image in the supplied format to the given stream
/// </summary>
/// <param name="stream">The stream the image is stored on</param>
/// <param name="extension">The image type (extension), e.g. "png", "jpg", "bmp"</param>
/// <param name="quality">Only needed for "jpg"</param>
void SaveToStream(Stream stream, string extension, int quality);
/// <summary>
/// Get the ToolStripMenuItem where plugins can place their Menu entrys
/// </summary>
/// <returns>ToolStripMenuItem</returns>
ToolStripMenuItem GetPluginMenuItem();
/// <summary>
/// Make the ICaptureDetails from the current Surface in the EditorForm available.
/// </summary>
ICaptureDetails CaptureDetails {
get;
}
ISurface Surface {
get;
}
}
}

View file

@ -0,0 +1,226 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2010 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/
*
* 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
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Greenshot.Capturing;
using Greenshot.Drawing;
using Greenshot.Forms;
namespace Greenshot.Plugin {
[Serializable]
[AttributeUsageAttribute(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)]
sealed public class PluginAttribute : Attribute {
public string Name {
get;
set;
}
public string Version {
get;
set;
}
public string EntryType {
get;
private set;
}
public bool Configurable {
get;
private set;
}
public string DllFile {
get;
set;
}
public PluginAttribute(string entryType, bool configurable) {
this.EntryType = entryType;
this.Configurable = configurable;
}
}
#region EventArgs
[Serializable]
public class ImageEditorOpenEventArgs : EventArgs {
private readonly IImageEditor imageEditor;
public IImageEditor ImageEditor {
get { return imageEditor;}
}
public ImageEditorOpenEventArgs(IImageEditor imageEditor) {
this.imageEditor = imageEditor;
}
}
[Serializable]
public class CaptureTakenEventArgs : EventArgs {
private readonly ICapture capture;
public ICapture Capture {
get { return capture;}
}
public CaptureTakenEventArgs(ICapture capture) {
this.capture = capture;
}
}
[Serializable]
public class SurfaceFromCaptureEventArgs : EventArgs {
private readonly ICapture capture;
public ICapture Capture {
get { return capture;}
}
private readonly ISurface surface;
public ISurface Surface {
get { return surface;}
}
public SurfaceFromCaptureEventArgs(ICapture capture, ISurface surface) {
this.capture = capture;
this.surface = surface;
}
}
[Serializable]
public class ImageOutputEventArgs : EventArgs {
private readonly string fullPath;
public string FullPath {
get { return fullPath;}
}
private readonly Image image;
public Image Image {
get { return image;}
}
private readonly ICaptureDetails captureDetails;
public ICaptureDetails CaptureDetails {
get { return captureDetails;}
}
public ImageOutputEventArgs(string fullPath, Image image, ICaptureDetails captureDetails) {
this.image = image;
this.fullPath = fullPath;
this.captureDetails = captureDetails;
}
}
#endregion
// Delegates for hooking up events.
public delegate void OnImageEditorOpenHandler(object sender, ImageEditorOpenEventArgs e);
public delegate void OnCaptureTakenHandler(object sender, CaptureTakenEventArgs e);
public delegate void OnSurfaceFromCaptureHandler(object sender, SurfaceFromCaptureEventArgs e);
public delegate void OnImageOutputHandler(object sender, ImageOutputEventArgs e);
public delegate void HotKeyHandler();
/// <summary>
/// This interface is the GreenshotPluginHost, that which "Hosts" the plugin.
/// For Greenshot this is implmented in the PluginHelper
/// </summary>
public interface IGreenshotPluginHost {
/// The Plugin can register to be called after every a newly opened ImageEditor
/// and will be passed the IImageEditor interface so it can register itself e.g. in the Menu
event OnImageEditorOpenHandler OnImageEditorOpen;
/// The Plugin can register to be called after every take Capture
/// and will be passed the ICapture interface so it can do something with it
event OnCaptureTakenHandler OnCaptureTaken;
/// The Plugin can register to be called after a Surface is created from a Capture
/// and will be passed the ICapture and ISurface interfaces so it can do something with it
event OnSurfaceFromCaptureHandler OnSurfaceFromCapture;
/// The Plugin can register to be called when an image is written to a file
/// and will be passed the full path to the file
event OnImageOutputHandler OnImageOutput;
/// <summary>
/// Return the location of the configuration, if any
/// </summary>
string ConfigurationPath {
get;
}
ContextMenuStrip MainMenu {
get;
}
/// <summary>
/// Saves the image to the supplied stream using the specified extension as the format
/// </summary>
/// <param name="image">The Image to save</param>
/// <param name="stream">The Stream to save to</param>
/// <param name="format">The format to save with (png, jpg etc)</param>
/// <param name="quality">Jpeg quality</param>
void SaveToStream(Image image, Stream stream, string format, int quality);
/// <summary>
/// Return a filename for the current image format (png,jpg etc) with the default file pattern
/// that is specified in the configuration
/// </summary>
/// <param name="format">A string with the format</param>
/// <returns>The filename which should be used to save the image</returns>
string GetFilename(string format, ICaptureDetails captureDetails);
/// <summary>
/// Create a Thumbnail
/// </summary>
/// <param name="image">Image of which we need a Thumbnail</param>
/// <returns>Image with Thumbnail</returns>
Image GetThumbnail(Image image, int width, int height);
/// <summary>
/// List of available plugins with their PluginAttributes
/// This can be usefull for a plugin manager plugin...
/// </summary>
Dictionary<PluginAttribute, IGreenshotPlugin> Plugins {
get;
}
/// <summary>
/// Register Hotkey handler!
/// </summary>
/// <param name="modifierKeyCode"></param>
/// <param name="virtualKeyCode"></param>
/// <param name="handler"></param>
/// <returns>bool true if all went okay</returns>
bool RegisterHotKey(int modifierKeyCode, int virtualKeyCode, HotKeyHandler handler);
}
public interface IGreenshotPlugin {
/// <summary>
/// Is called after the plugin is instanciated, the Plugin should keep a copy of the host and pluginAttribute.
/// </summary>
/// <param name="host">The IPluginHost that will be hosting the plugin</param>
/// <param name="pluginAttribute">The PluginAttribute for the actual plugin</param>
void Initialize(IGreenshotPluginHost host, ICaptureHost captureHost, PluginAttribute pluginAttribute);
/// <summary>
/// Unload of the plugin
/// </summary>
void Shutdown();
/// <summary>
/// Open the Configuration Form, will/should not be called before handshaking is done
/// </summary>
void Configure();
}
}