-
Notifications
You must be signed in to change notification settings - Fork 10
/
Effect.cs
90 lines (74 loc) · 4.15 KB
/
Effect.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
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Xml.Linq;
using RT.Util.Lingo;
using RT.Util.Serialization;
using WpfCrutches;
namespace TankIconMaker
{
abstract class EffectBase : IHasTreeViewItem, IHasTypeNameDescription, IClassifyXmlObjectProcessor, INotifyPropertyChanged
{
/// <summary>Describes what this effect type does as concisely as possible.</summary>
[Browsable(false)]
public abstract string TypeName { get; }
/// <summary>Describes what this effect type does in more detail.</summary>
[Browsable(false)]
public abstract string TypeDescription { get; }
/// <summary>Specifies the version of this layer’s settings - incremented on changing layer settings backwards-incompatibly.</summary>
[Browsable(false)]
public abstract int Version { get; }
[Browsable(false)]
public string Name { get { return _Name; } set { _Name = value; NotifyPropertyChanged("Name"); NotifyPropertyChanged("NameVisibility"); } }
private string _Name;
[Browsable(false)]
public Visibility NameVisibility { get { return string.IsNullOrEmpty(Name) ? Visibility.Collapsed : Visibility.Visible; } }
/// <summary>Keeps track of the layer that this effect belongs to. This value is kept up-to-date automatically.</summary>
[Browsable(false), ClassifyIgnore]
public LayerBase Layer;
public bool Visible { get { return _Visible; } set { _Visible = value; NotifyPropertyChanged("Visible"); } }
private bool _Visible;
public static MemberTr VisibleTr(Translation tr) { return new MemberTr(tr.Category.General, tr.LayerAndEffect.EffectVisible); }
public ValueSelector<BoolWithPassthrough> VisibleFor { get; set; }
public static MemberTr VisibleForTr(Translation tr) { return new MemberTr(tr.Category.General, tr.LayerAndEffect.EffectVisibleFor); }
public EffectBase()
{
Visible = true;
VisibleFor = new ValueSelector<BoolWithPassthrough>(BoolWithPassthrough.Yes);
}
/// <summary>
/// Applies the effect to the specified layer. Returns the resulting image. The caller must make sure that the layer
/// is writable, because all Apply methods expect to be able to modify the layer if necessary and return it, instead of
/// creating a new instance.
/// </summary>
public abstract BitmapBase Apply(RenderTask renderTask, BitmapBase layer);
/// <summary>
/// Stores the <see cref="Version"/> of the maker as it was at the time of saving settings to XML. This may
/// then be used to apply transformations to the XML produced by old versions of a layer.
/// </summary>
public int SavedByVersion;
void IClassifyObjectProcessor<XElement>.BeforeSerialize() { BeforeSerialize(); }
protected virtual void BeforeSerialize()
{
SavedByVersion = Version;
}
void IClassifyObjectProcessor<XElement>.AfterSerialize(XElement xml) { AfterSerialize(xml); }
protected virtual void AfterSerialize(XElement xml) { }
void IClassifyObjectProcessor<XElement>.BeforeDeserialize(XElement xml) { BeforeDeserialize(xml); }
protected virtual void BeforeDeserialize(XElement xml) { }
void IClassifyObjectProcessor<XElement>.AfterDeserialize(XElement xml) { AfterDeserialize(xml); }
protected virtual void AfterDeserialize(XElement xml) { }
[ClassifyIgnore, Browsable(false)]
public TreeViewItem TreeViewItem { get; set; }
protected void NotifyPropertyChanged(string name) { PropertyChanged(this, new PropertyChangedEventArgs(name)); }
public event PropertyChangedEventHandler PropertyChanged = (_, __) => { };
public virtual EffectBase Clone()
{
var result = MemberwiseClone() as EffectBase;
result.Layer = null;
result.PropertyChanged = (_, __) => { };
result.VisibleFor = VisibleFor.Clone();
return result;
}
}
}