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
231
232
233
234
235
236
237
238
239
240
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Tango.Editors;
using Tango.Shared;
namespace Tango.Editors
{
/// <summary>
/// <para><img class="classImage" src="../Media/CanvasItemEditor.png" /></para>
/// Represents a <see cref="FrameworkElement"/> editor with position, size and angle control.
/// </summary>
/// <example>
/// <para class="example-title">
/// <img class="exampleIcon" src="../Icons/CodeExample.png" />
/// <i>
/// The following example demonstrates a basic scenario of using <see cref="N:WpfVideoTools.Tiles"/> and <see cref="N:Tango.Editors"/> by creating a simple video projection application with the following features:
/// </i>
/// <list type="bullet">
/// <item>Use the mouse to draw any type of tile of the editor surface.</item>
/// <item>Apply any input shape on any tile.</item>
/// <item>Load any video and display it on any of the selected tile.</item>
/// <item>Built in support for undo, redo, cut, copy and paste, delete and select operations.</item>
/// <item>Built in support for saving/loading the editor state to memory or file.</item>
/// <item>Built in support for tile and editor properties adjustment using the <see cref="ParameterizedEditor"/>.</item>
/// </list>
/// </para>
/// <para><markup><video class="exampleVideo" autoplay="autoplay" loop="loop" controls="controls" src="../Media/EditorsExample.mp4"></video></markup></para>
/// <code lang="XAML" source="../FullAPIExamples/Examples/Editors/EditorsExample.xaml" title="Elements editor example." />
/// <i>Code-Behind.</i>
/// <code lang="C#" source="../FullAPIExamples/Examples/Editors/EditorsExample.xaml.cs" title="Elements editor example." />
/// </example>
/// <seealso cref="Tango.Editors.ElementEditor" />
[ContentProperty("InnerContent")]
public partial class CanvasItemEditor : ElementEditor
{
/// <summary>
/// Initializes a new instance of the <see cref="CanvasItemEditor"/> class.
/// </summary>
public CanvasItemEditor()
: base()
{
InitializeComponent();
AdaptToCanasItemType();
}
/// <summary>
/// Initializes a new instance of the <see cref="CanvasItemEditor"/> class.
/// </summary>
/// <param name="canvasItem">The canvas item.</param>
public CanvasItemEditor(CanvasItem canvasItem)
: this()
{
CanvasItem = canvasItem;
Left = canvasItem.Left;
Top = canvasItem.Top;
Width = canvasItem.Width;
Height = canvasItem.Height;
Angle = canvasItem.Angle;
AdaptToCanasItemType();
}
/// <summary>
/// Initializes a new instance of the <see cref="CanvasItemEditor"/> class.
/// </summary>
/// <param name="canvasItem">The canvas item.</param>
/// <param name="bounds">The bounds.</param>
public CanvasItemEditor(CanvasItem canvasItem, Rect bounds)
: this(canvasItem)
{
Left = bounds.Left;
Top = bounds.Top;
Width = bounds.Width;
Height = bounds.Height;
AdaptToCanasItemType();
}
private void AdaptToCanasItemType()
{
if (CanvasItem != null && CanvasItem.CustomContent != null)
{
normalGrid.Visibility = Visibility.Hidden;
customContent.Content = CanvasItem.CustomContent;
ZIndex = CanvasItem.ZIndex;
}
}
public CanvasItem CanvasItem
{
get { return (CanvasItem)GetValue(CanvasItemProperty); }
set { SetValue(CanvasItemProperty, value); }
}
public static readonly DependencyProperty CanvasItemProperty =
DependencyProperty.Register("CanvasItem", typeof(CanvasItem), typeof(CanvasItemEditor), new PropertyMetadata(null, (d, e) => (d as CanvasItemEditor).AdaptToCanasItemType()));
/// <summary>
/// Clones this instance.
/// </summary>
/// <returns></returns>
public override IElementEditor Clone()
{
try
{
CanvasItemEditor cloned = new CanvasItemEditor();
cloned.CanvasItem = CanvasItem.Clone();
cloned.ElementDetached = ElementDetached;
cloned.Top = Top;
cloned.Left = Left;
cloned.Width = Width;
cloned.Height = Height;
cloned.Angle = Angle;
cloned.Background = Background;
cloned.Foreground = Foreground;
cloned.CornersBrush = CornersBrush;
return cloned;
}
catch (Exception ex)
{
throw new InvalidOperationException("Could not clone this editor. You may have to create a custom editor and implement a custom Clone method.", ex);
}
}
/// <summary>
/// Gets the hosted element.
/// </summary>
[ParameterIgnore]
public override Object HostedElement
{
get { return CanvasItem; }
}
/// <summary>
/// Gets a configuration object representing the configurable properties. This configuration can be serialized to a stream or file, and later be loaded and applied to the configurable object.
/// </summary>
/// <returns></returns>
public override IConfiguration GetConfiguration()
{
//CanvasItemEditorConfiguration config = new CanvasItemEditorConfiguration(base.GetConfiguration() as ElementEditorConfiguration);
//try
//{
// config.ElementXaml = FrameworkElementCloner.Serialize(Element);
//}
//catch
//{
// Debug.WriteLine("Could not serialize framework element with ID " + ID);
//}
return null;
}
/// <summary>
/// Invoked when the attached editor has changed.
/// </summary>
protected override void OnAttachedEditorChanged()
{
base.OnAttachedEditorChanged();
}
/// <summary>
/// Applies the specified configuration with an optional animation if supported by the configurable type.
/// </summary>
/// <param name="configuration">The configuration.</param>
/// <param name="animation">The animation.</param>
public override void SetConfiguration(IConfiguration configuration, ConfigurationAnimation animation)
{
//if (!(configuration is CanvasItemEditorConfiguration))
//{
// throw new InvalidConfigurationException();
//}
//var config = configuration as CanvasItemEditorConfiguration;
//try
//{
// Element = FrameworkElementCloner.Deserialize(config.ElementXaml);
//}
//catch
//{
// Debug.WriteLine("Could not deserialize framework element with ID " + ID);
//}
base.SetConfiguration(configuration, animation);
}
/// <summary>
/// Called when the editor detached property has changed.
/// </summary>
protected override void OnElementDetachedChanged()
{
base.OnElementDetachedChanged();
}
protected override void OnAfterBoundsChange()
{
base.OnAfterBoundsChange();
CanvasItem.Angle = Angle;
CanvasItem.Width = Width;
CanvasItem.Height = Height;
CanvasItem.Top = Top;
CanvasItem.Left = Left;
}
public override int ZIndex
{
get
{
return Canvas.GetZIndex(this as UIElement);
}
set
{
_zIndex = value;
Canvas.SetZIndex(this as UIElement, value);
if (CanvasItem != null)
{
CanvasItem.ZIndex = value;
}
RaisePropertyChanged(nameof(ZIndex));
}
}
}
}
|