using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;

namespace VectorRace_LevelDesigner
{
    public class Field : UserControl
    {
        private int _Type = 0;

        public int Type
        {
            get { return _Type; }
            set { _Type = value; }
        }

        public Field()
        {
            Visible = true;
            AllowDrop = true;            
        }

        public Field(bool allowdrop)
        {
            Visible = true;
            AllowDrop = allowdrop;
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            FieldHandler.DrawType(e.Graphics, _Type);
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            DoDragDrop(_Type, DragDropEffects.Copy);
        }

        protected override void OnDragEnter(DragEventArgs drgevent)
        {
            if (drgevent.Data.GetDataPresent(typeof(int)))
            {
                drgevent.Effect = DragDropEffects.Copy;
            }
        }

        protected override void OnDragDrop(DragEventArgs drgevent)
        {
            _Type = (int)drgevent.Data.GetData(typeof(int));

            Invalidate();
        }
    }
}
