﻿//Enumerado de capas de sistema del visor web
function WVNavigate(valor) 
{
    this.value = valor;
}
WVNavigate.prototype.toString = function () 
{
    return this.value;
};
WVNavigate.NONE  = new WVNavigate(0);
WVNavigate.NORTH = new WVNavigate(1);
WVNavigate.SOUTH = new WVNavigate(2);
WVNavigate.EAST  = new WVNavigate(4);
WVNavigate.WEST  = new WVNavigate(8);

//Comportamiento para navegación contínua en cualquier dirección
function WVNavigator()
{
    var oThis=this;
    var viewer = null;
    var behaviorType = WVBehaviorType.NAVIGATOR;
    var direction = WVNavigate.NONE;
    var enabled  = true; //indica si este comportamiento está operativo para afectar al visor
    
    var speedStep=10; //límite máximo de pixels trasladados a cada frame
    var currentSpeed=0;
    var vOffset;//=new Vector2D(); //vector de scrolling
    
    this.getEnabled=function()
    {
        return enabled;
    }
    
    this.setEnabled=function(enable)
    {
        enabled = true;//enable;
    }
    
    //retorna si el comportamiento debe estar siempre activo
    this.alwaysKeepEnabled=function()
    {
        return enabled;
    }
    
    this.init=function (visor)
    {
        viewer = visor;
        vOffset=new Vector2D();
    }
    
    this.getBehaviorType=function()
    {
        return behaviorType;
    }
    
    this.setSpeedStep = function(speed)
    {
        speedStep=speed;
    }
    
    this.setDirection = function(dir)
    {
        direction = dir;
    }
    
    this.onUpdate = function ()
    {
        if (viewer.getAllowPanning())
        {
            if (direction != WVNavigate.NONE.value)
            {
                if (direction & WVNavigate.NORTH.value)
                    vOffset.y = speedStep;
                
                if (direction & WVNavigate.SOUTH.value)
                    vOffset.y = -speedStep;
                
                if (direction & WVNavigate.EAST.value)
                    vOffset.x = -speedStep;
                
                if (direction & WVNavigate.WEST.value)
                    vOffset.x = speedStep;
                
                if (vOffset.x!=0 || vOffset.y!=0)
                {
                    viewer.addOffset(vOffset);
                    vOffset.x = 0;
                    vOffset.y = 0;
                }
            }
        }
    }
    
    this.finalize=function()
    {
        direction = WVNavigate.NONE.value;
    }
}



