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

namespace Obligatorisk
{
    public partial class ObjectManager : Form
    {
        private Engine engine;

        public ObjectManager(Engine engine)
        {
            this.engine = engine;
            InitializeComponent();
        }

        private void ObjectList_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.ObjectBoundingBoxLength.Text = ((ModelComponent)this.ObjectList.SelectedItem).BoundingBox.Length.ToString();
            this.ObjectBoundingBoxWidth.Text = ((ModelComponent)this.ObjectList.SelectedItem).BoundingBox.Width.ToString();
            this.ObjectPositionZ.Text = ((ModelComponent)this.ObjectList.SelectedItem).Position.Z.ToString();
            this.ObjectPositionX.Text = ((ModelComponent)this.ObjectList.SelectedItem).Position.X.ToString();
            this.ObjectPositionY.Text = ((ModelComponent)this.ObjectList.SelectedItem).Position.Y.ToString();
            engine.Focus();
        }

        private void ObjectManager_Load(object sender, EventArgs e)
        {
            foreach (ModelComponent mc in engine.TheModel.ModelList)
            {
                this.ObjectList.Items.Add(mc);
            }
        }

        private void ObjectPositionZ_TextChanged(object sender, EventArgs e)
        {

        }

        private void ObjectPositionX_TextChanged(object sender, EventArgs e)
        {

        }

        private void ObjectPositionY_TextChanged(object sender, EventArgs e)
        {

        }

        private void ObjectBoundingBox_TextChanged(object sender, EventArgs e)
        {
           
            
        }

        private void ObjectBoundingBoxWidth_TextChanged(object sender, EventArgs e)
        {
            float result = 5;
            bool success = float.TryParse(this.ObjectBoundingBoxWidth.Text, out result);
            if (success)
            {
                ((ModelComponent)this.ObjectList.SelectedItem).SetNewBoundingMeshWidth(result);
            }
            else
            {
                ((ModelComponent)this.ObjectList.SelectedItem).SetNewBoundingMeshWidth(5f);
            }
        }

        private void ObjectBoundingBoxLength_TextChanged(object sender, EventArgs e)
        {
            float result = 5;
            bool success = float.TryParse(this.ObjectBoundingBoxLength.Text, out result);
            if (success)
            {
                ((ModelComponent)this.ObjectList.SelectedItem).SetNewBoundingMeshLength(result);
            }
            else
            {
                ((ModelComponent)this.ObjectList.SelectedItem).SetNewBoundingMeshLength(5f);
            }
        }
    }
}