﻿if (!window.ArtsAndArchitecture)
    window.ArtsAndArchitecture = {};
    
ArtsAndArchitecture.PanTool = function(control, target, x, y)
{
    this.control = control;
    this.target = target;
    
    // replace with button
    this._panToolImage = this.target.findName("PanToolImage");
    this._panToolUp = this.target.findName("PanToolUp");
    this._panToolDown = this.target.findName("PanToolDown");
    this._panToolLeft =  this.target.findName("PanToolLeft");
    this._panToolRight = this.target.findName("PanToolRight");
    
    this._panToolUp.addEventListener("MouseEnter", Silverlight.createDelegate(this, this.handleMouseEnter_PanToolUp));
    this._panToolUp.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.handleMouseLeave_PanToolUp));
    this._panToolUp.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleMouseLeftButtonDown_PanToolUp));
    this._panToolUp.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseLeftButtonUp_PanToolUp));
    
    this._panToolDown.addEventListener("MouseEnter", Silverlight.createDelegate(this, this.handleMouseEnter_PanToolDown));
    this._panToolDown.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.handleMouseLeave_PanToolDown));
    this._panToolDown.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleMouseLeftButtonDown_PanToolDown));    
    this._panToolDown.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseLeftButtonUp_PanToolDown));
    
    this._panToolLeft.addEventListener("MouseEnter", Silverlight.createDelegate(this, this.handleMouseEnter_PanToolLeft));
    this._panToolLeft.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.handleMouseLeave_PanToolLeft));
    this._panToolLeft.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleMouseLeftButtonDown_PanToolLeft));
    this._panToolLeft.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseLeftButtonUp_PanToolLeft));
    
    this._panToolRight.addEventListener("MouseEnter", Silverlight.createDelegate(this, this.handleMouseEnter_PanToolRight));
    this._panToolRight.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.handleMouseLeave_PanToolRight));
    this._panToolRight.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleMouseLeftButtonDown_PanToolRight));    
    this._panToolRight.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseLeftButtonUp_PanToolRight));
        
    this.target["Canvas.Top"] = y;
    this.target["Canvas.Left"] = x;
}

ArtsAndArchitecture.PanTool.prototype = 
{
    handleMouseEnter_PanToolUp: function (sender, args)
    {
        this._panToolImage.Source = "Content/pan_tool/controller_2d_top_d.png";
    },
    
    handleMouseLeave_PanToolUp: function (sender, args)
    {
        this._panToolImage.Source = "Content/pan_tool/controller_2d_u.png";
        AAMainView.stopPanning();
    },
    
    handleMouseLeftButtonDown_PanToolUp: function (sender, args)
    {
        AAMainView.startPanningUp();
    },
    
    handleMouseLeftButtonUp_PanToolUp: function (sender, args)
    {
        AAMainView.stopPanning();
    },    

//

    handleMouseEnter_PanToolDown: function (sender, args)
    {
        this._panToolImage.Source = "Content/pan_tool/controller_2d_bottom_d.png";
    },
    
    handleMouseLeave_PanToolDown: function (sender, args)
    {
        this._panToolImage.Source = "Content/pan_tool/controller_2d_u.png";
        AAMainView.stopPanning();
    },
    
    handleMouseLeftButtonDown_PanToolDown: function (sender, args)
    {
        AAMainView.startPanningDown();
    },
    
    handleMouseLeftButtonUp_PanToolDown: function (sender, args)
    {
        AAMainView.stopPanning();
    },   
    
//

    handleMouseEnter_PanToolLeft: function (sender, args)
    {
        this._panToolImage.Source = "Content/pan_tool/controller_2d_left_d.png";
    },
    
    handleMouseLeave_PanToolLeft: function (sender, args)
    {
        this._panToolImage.Source = "Content/pan_tool/controller_2d_u.png";
        AAMainView.stopPanning();
    },
    
    handleMouseLeftButtonDown_PanToolLeft: function (sender, args)
    {
        AAMainView.startPanningLeft();
    },
    
    handleMouseLeftButtonUp_PanToolLeft: function (sender, args)
    {
        AAMainView.stopPanning();
    },       
    
//
    
    handleMouseEnter_PanToolRight: function (sender, args)
    {
        this._panToolImage.Source = "Content/pan_tool/controller_2d_right_d.png";
    },
    
    handleMouseLeave_PanToolRight: function (sender, args)
    {
        this._panToolImage.Source = "Content/pan_tool/controller_2d_u.png";
        AAMainView.stopPanning();
    },
    
    handleMouseLeftButtonDown_PanToolRight: function (sender, args)
    {
        AAMainView.startPanningRight();
    },
    
    handleMouseLeftButtonUp_PanToolRight: function (sender, args)
    {
        AAMainView.stopPanning();
    }     
}