using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace VisimBuilder.ObjectCreation
{
    public partial class GridControl : UserControl
    {
        protected Gizmos.EditingGrid Grid;
        protected MainBuilderForm Boss;

        public GridControl()
        {
            InitializeComponent();
        }

        public void Init(MainBuilderForm boss, Gizmos.EditingGrid grid)
        {
            Boss = boss;
            Grid = grid;
            SetFromGrid();

            colorEditing1.ColorChanged += new ColorEditing.ColorChangedCallback(colorEditing1_ColorChanged);
            vectorEditing1.VectorChanged += new VectorEditing.VectorChangedCallback(vectorEditing1_VectorChanged);
            vectorEditing2.VectorChanged += new VectorEditing.VectorChangedCallback(vectorEditing2_VectorChanged);
        }

        void vectorEditing2_VectorChanged(VectorEditing sender, VisiMath.Vector3 newvalue)
        {
            Grid.GridExtentsMaximum = newvalue;
            sender.EditedVector = Grid.GridExtentsMaximum;
        }

        void vectorEditing1_VectorChanged(VectorEditing sender, VisiMath.Vector3 newvalue)
        {
            Grid.GridExtentsMinimum = newvalue;
            sender.EditedVector = Grid.GridExtentsMinimum;
        }

        void colorEditing1_ColorChanged(ColorEditing sender, VisiMath.ColorByte newcolor)
        {
            Grid.GridColor = newcolor;
        }

        public void SetFromGrid()
        {
            colorEditing1.EditedColor = Grid.GridColor;
            vectorEditing1.EditedVector = Grid.GridExtentsMinimum;
            vectorEditing2.EditedVector = Grid.GridExtentsMaximum;
            numericUpDown1.Value = (decimal)Grid.GridSize;
            checkBoxHidden.Checked = Grid.Hidden;
            checkBoxAlwaysOnTop.Checked = Grid.AlwaysOnTop;
            //checkBoxMarkCursor.Checked = Grid.MarkCursorLocation;
            checkBoxMoveWithCam.Checked = Grid.MoveWithCamera;
            checkBoxMoveWithSelect.Checked = Grid.MoveWithSelectedObject;
        }

        private void GridSizeChanged(object sender, EventArgs e)
        {
            float val = (float)numericUpDown1.Value;

            VisiMath.MathTools.Clamp(ref val, 0.0001f, 100);

            Grid.GridSize = val;
        }

        private void HiddenCheck(object sender, EventArgs e)
        {
            Grid.Hidden = checkBoxHidden.Checked;
        }

        private void OnTopCheck(object sender, EventArgs e)
        {
            Grid.AlwaysOnTop = checkBoxAlwaysOnTop.Checked;
        }

        private void MoveWithCamCheck(object sender, EventArgs e)
        {
            Grid.MoveWithCamera = checkBoxMoveWithCam.Checked;
            checkBoxMoveWithSelect.Checked = Grid.MoveWithSelectedObject;
        }

        private void MoveWithSelectedCheck(object sender, EventArgs e)
        {
            Grid.MoveWithSelectedObject = checkBoxMoveWithSelect.Checked;
            checkBoxMoveWithCam.Checked = Grid.MoveWithCamera;
        }

        private void MarkCursorCheck(object sender, EventArgs e)
        {
            //Grid.MarkCursorLocation = checkBoxMarkCursor.Checked;
        }
    }
}
