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 { /// /// /// Represents a editor with position, size and angle control. /// /// /// /// /// /// The following example demonstrates a basic scenario of using and by creating a simple video projection application with the following features: /// /// /// Use the mouse to draw any type of tile of the editor surface. /// Apply any input shape on any tile. /// Load any video and display it on any of the selected tile. /// Built in support for undo, redo, cut, copy and paste, delete and select operations. /// Built in support for saving/loading the editor state to memory or file. /// Built in support for tile and editor properties adjustment using the . /// /// /// /// /// Code-Behind. /// /// /// [ContentProperty("InnerContent")] public partial class CanvasItemEditor : ElementEditor { /// /// Initializes a new instance of the class. /// public CanvasItemEditor() : base() { InitializeComponent(); AdaptToCanasItemType(); } /// /// Initializes a new instance of the class. /// /// The canvas item. public CanvasItemEditor(CanvasItem canvasItem) : this() { CanvasItem = canvasItem; Left = canvasItem.Left; Top = canvasItem.Top; Width = canvasItem.Width; Height = canvasItem.Height; Angle = canvasItem.Angle; AdaptToCanasItemType(); } /// /// Initializes a new instance of the class. /// /// The canvas item. /// The bounds. 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())); /// /// Clones this instance. /// /// 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); } } /// /// Gets the hosted element. /// [ParameterIgnore] public override Object HostedElement { get { return CanvasItem; } } /// /// 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. /// /// 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; } /// /// Invoked when the attached editor has changed. /// protected override void OnAttachedEditorChanged() { base.OnAttachedEditorChanged(); } /// /// Applies the specified configuration with an optional animation if supported by the configurable type. /// /// The configuration. /// The animation. 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); } /// /// Called when the editor detached property has changed. /// 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)); } } } }