using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Machinations.FromFlash.machinations.model;

namespace Machinations.GUI
{
    /// <summary>
    /// Visualisation for converter node
    /// </summary>
    class ConverterView : NodeView<Converter>
    {
        public ConverterView(Converter node) : base(node)
        {
        }

        protected override void SetMainUiElementPosition(Point value)
        {
            m_uiElement.SetValue(Canvas.LeftProperty, value.X);
            m_uiElement.SetValue(Canvas.TopProperty, value.Y);
        }

        public override int Radius { get { return 30; } }

        public override void InitShape()
        {
            m_uiElement = new ConverterUiElement(Radius, m_model.Thickness, new SolidColorBrush(m_model.Color));
        }

        public override void ColorView(Brush brush)
        {
            ((ConverterUiElement)m_uiElement).Brush = brush;
            m_uiElement.InvalidateVisual();
        }
    }

    /// <summary>
    /// picture for converter
    /// </summary>
    public class ConverterUiElement : UIElement
    {
        private int m_radius = 30;
        private double m_thickness = 2;
        private Brush m_brush;

        public ConverterUiElement(int radius, double thickness, Brush brush = null)
        {
            m_radius = radius;
            m_thickness = thickness;
            m_brush = brush ?? Brushes.Black;
        }

        public Brush Brush
        {
            get { return m_brush; }
            set { m_brush = value; }
        }

        protected override void OnRender(DrawingContext drawingContext)
        {
            drawingContext.DrawLine(new Pen(m_brush, m_thickness),
                new Point(0.0, -m_radius / 2),
                new Point(0, m_radius / 2));
            drawingContext.DrawLine(new Pen(m_brush, m_thickness),
                new Point(-m_radius / 4, -m_radius / 2),
                new Point(-m_radius / 4, m_radius / 2));
            drawingContext.DrawLine(new Pen(m_brush, m_thickness),
                new Point(-m_radius / 4, -m_radius / 2),
                new Point(m_radius / 2, 0));
            drawingContext.DrawLine(new Pen(m_brush, m_thickness),
                new Point(-m_radius / 4, m_radius / 2),
                new Point(m_radius / 2, 0));

            //pro klikani
            drawingContext.DrawEllipse(Brushes.Transparent, new Pen(Brushes.Transparent, 0), new Point(0, 0), m_radius, m_radius);

            base.OnRender(drawingContext);
        }
    }
}
