﻿using UnityEngine;
using System.Collections;
using Noesis;

namespace FiveGui
{
    [Noesis.Extended]
    [Noesis.UserControlSource("Assets/Test/Test.xaml")]
    public class UIImageViewer : Noesis.UserControl
    {
        public static DependencyProperty FrameProperty = DependencyProperty.Register(
            "Frame", typeof(Noesis.Rect), typeof(UIImageViewer), new PropertyMetadata(null));

        public Noesis.Rect Frame
        {
            get { return GetValue<Noesis.Rect>(FrameProperty); }
            set { SetValue<Noesis.Rect>(FrameProperty, value); }
        }

        private Storyboard _nextFrame;

        public void OnPostInit()
        {
            SetDataContext(this);
            
            _nextFrame = FindStringResource<Storyboard>("NextFrame");
            Frame = new Noesis.Rect(0, 0, 640, 480);
        }

        public void AnimateToView(Noesis.Rect rect)
        {
            Frame = rect;
            _nextFrame.Begin(this);
        }
    }
}

public class Test : MonoBehaviour
{
    FiveGui.UIImageViewer _root;

	// Use this for initialization
	void Start()
    {
        _root = GetComponent<NoesisGUIPanel>().GetRoot<FiveGui.UIImageViewer>();
	}
	
	// Update is called once per frame
	void Update()
    {
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            _root.AnimateToView(new Noesis.Rect(0,0,64,80));
        }
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            _root.AnimateToView(new Noesis.Rect(0,0,1280,960));
        }
	}
}
