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;
using VisiMath;
using VisimBox.Scene;
using VisimBox.Renderer;
using VisimBox;

namespace VisimBuilder.ObjectCreation
{
    public partial class CameraCreator : ObjectCreationBase
    {
        //todo tied camera positional, tied camera lookat

        public CameraCreator()
        {
            InitializeComponent();
            DisableScale = true;
            textBoxName.Text = "Camera";
        }

        public override void SetDefault()
        {
            base.SetDefault();
            textBoxName.Text = "Camera";
        }

        public override void CreateObject(object sender, EventArgs e)
        {
            ICamera finaltrans = null;

            float fov = (float)numericUpDown1.Value;
            fov = MathTools.DegToRad(fov);

            if (radioButton1.Checked)
                finaltrans = new FPSCamera(fov);
            else
                finaltrans = new StandardCamera(fov);

            finaltrans.Position = trans.Position;
            finaltrans.RPY = trans.RPY;

            #region Owner

            Node owner = null;

            if (checkBoxToRoot.Checked || (Boss.SelectedNode == null))
            {
                owner = VisimEngine.Instance.MainScene;
            }
            else
            {
                owner = Boss.SelectedNode;
            }

            #endregion


            CameraNode node = new CameraNode(finaltrans);

            owner.AddNode(node, textBoxName.Text);

            VisimBox.Console.WriteLine("New object " + node.XMLNodeName + " " + textBoxName.Text + "created.");

            Boss.UpdateSceneChange();
            Boss.SelectNode(node, false);
        }
    }

    public class CreateCameraItem : CreateNewItem
    {
        public CreateCameraItem(MainBuilderForm boss)
            : base(boss, "Camera", "Any of supported camera types")
        {
            RefreshBaseCreator();
        }

        protected override void RefreshBaseCreator()
        {
            BaseCreator = new CameraCreator();
            BaseCreator.Init(Boss);
        }
    }
}
