This repository was archived by the owner on Jul 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBrushFilterEffect.cs
230 lines (213 loc) · 7.52 KB
/
BrushFilterEffect.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
using PaintDotNet;
using PaintDotNet.Effects;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Reflection;
using BrushFilter.Properties;
namespace BrushFilter
{
/// <summary>
/// Contains assembly information, accessible through variables.
/// </summary>
public class PluginSupportInfo : IPluginSupportInfo
{
#region Properties
/// <summary>
/// Gets the author.
/// </summary>
public string Author
{
get
{
return ((AssemblyCompanyAttribute)base.GetType().Assembly
.GetCustomAttributes(typeof(AssemblyCompanyAttribute), false)[0]).Company;
}
}
/// <summary>
/// Gets the copyright information.
/// </summary>
public string Copyright
{
get
{
return ((AssemblyCopyrightAttribute)base.GetType().Assembly
.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false)[0]).Copyright;
}
}
/// <summary>
/// Gets the name of the product.
/// </summary>
public string DisplayName
{
get
{
return ((AssemblyProductAttribute)base.GetType().Assembly
.GetCustomAttributes(typeof(AssemblyProductAttribute), false)[0]).Product;
}
}
/// <summary>
/// Gets the version number.
/// </summary>
public Version Version
{
get
{
return base.GetType().Assembly.GetName().Version;
}
}
/// <summary>
/// Gets the URL where the plugin is released to the public.
/// </summary>
public Uri WebsiteUri
{
get
{
return new Uri("http://forums.getpaint.net/index.php?/forum/7-plugins-publishing-only/");
}
}
#endregion
}
/// <summary>
/// Controls the effect. In short, a GUI is instantiated by
/// CreateConfigDialog and when the dialog signals OK, Render is called,
/// passing OnSetRenderInfo to it. The dialog stores its result in an
/// intermediate class called RenderSettings, which is then accessed to
/// draw the final result in Render.
/// </summary>
[PluginSupportInfo(typeof(PluginSupportInfo), DisplayName = "Brush Filter")]
public class BrushFilterEffectPlugin : Effect
{
#region Properties
/// <summary>
/// The icon of the plugin to be displayed next to its menu entry.
/// </summary>
public static Bitmap StaticImage
{
get
{
return Resources.IconPng;
}
}
/// <summary>
/// The name of the plugin as it appears in Paint.NET.
/// </summary>
public static string StaticName
{
get
{
return Globalization.GlobalStrings.Title;
}
}
/// <summary>
/// The name of the menu category the plugin appears under.
/// </summary>
public static string StaticSubMenuName
{
get
{
return "Tools";
}
}
#endregion
#region Constructors
/// <summary>
/// Constructor.
/// </summary>
public BrushFilterEffectPlugin()
: base(
StaticName,
StaticImage,
StaticSubMenuName,
EffectFlags.Configurable)
{
}
#endregion
#region Methods
/// <summary>
/// Tells Paint.NET which form to instantiate as the plugin's GUI.
/// Called remotely by Paint.NET.
/// </summary>
public override EffectConfigDialog CreateConfigDialog()
{
//Copies necessary user variables for dialog access.
UserSettings.UserPrimaryColor = EnvironmentParameters.PrimaryColor;
UserSettings.UserSecondaryColor = EnvironmentParameters.SecondaryColor;
UserSettings.UserBrushWidth = EnvironmentParameters.BrushWidth;
//Static variables are remembered between plugin calls, so clear them.
RenderSettings.Clear();
//Creates and returns a new dialog.
return new WinBrushFilter();
}
/// <summary>
/// Gets the render information.
/// </summary>
/// <param name="parameters">
/// Saved settings used to restore the GUI to the same settings it was
/// saved with last time the effect was applied.
/// </param>
/// <param name="dstArgs">The destination canvas.</param>
/// <param name="srcArgs">The source canvas.</param>
protected override void OnSetRenderInfo(
EffectConfigToken parameters,
RenderArgs dstArgs,
RenderArgs srcArgs)
{
//Copies the render information to the base Effect class.
base.OnSetRenderInfo(parameters, dstArgs, srcArgs);
}
/// <summary>
/// Renders the effect over rectangular regions automatically
/// determined and handled by Paint.NET for multithreading support.
/// </summary>
/// <param name="parameters">
/// Saved settings used to restore the GUI to the same settings it was
/// saved with last time the effect was applied.
/// </param>
/// <param name="dstArgs">The destination canvas.</param>
/// <param name="srcArgs">The source canvas.</param>
/// <param name="rois">
/// A list of rectangular regions to split this effect into so it can
/// be optimized by worker threads. Determined and managed by
/// Paint.NET.
/// </param>
/// <param name="startIndex">
/// The rectangle to begin rendering with. Used in Paint.NET's effect
/// multithreading process.
/// </param>
/// <param name="length">
/// The number of rectangles to render at once. Used in Paint.NET's
/// effect multithreading process.
/// </param>
public override void Render(
EffectConfigToken parameters,
RenderArgs dstArgs,
RenderArgs srcArgs,
Rectangle[] rois,
int startIndex,
int length)
{
//Renders the effect if the dialog is closed and accepted.
if (!RenderSettings.EffectApplied &&
RenderSettings.DoApplyEffect && !IsCancelRequested)
{
//The effect should only render once.
RenderSettings.EffectApplied = true;
using (Graphics g = new RenderArgs(dstArgs.Surface).Graphics)
{
//Copies the drawn image, clipping it to the selection.
g.CompositingMode = CompositingMode.SourceCopy;
Region region = new Region(EnvironmentParameters
.GetSelection(srcArgs.Bounds).GetRegionData());
g.SetClip(region, CombineMode.Replace);
g.DrawImage(RenderSettings.BmpToRender, 0, 0,
RenderSettings.BmpToRender.Width,
RenderSettings.BmpToRender.Height);
//TODO: This copies perfectly, but can't handle clipping to a region.
//Utils.CopyBitmapPure(RenderSettings.BmpToRender, dstArgs.Bitmap);
}
}
}
#endregion
}
}