Вход Регистрация
Файл: Space race/libs/Editor_files/Diagram.js
Строк: 144
<?php
var pgli pgli || {};
pgli.diagram pgli.diagram || {};

pgli.diagram.Diagram gamecore.Base.extend('Diagram',
// static

},
// instance

    
domnull,
    
containernull,
    
width1024,
    
height768,

    
timernull,
    
redrawDelay1000/30,

    
stagenull,
    
layers: {
        
backgroundnull,
        
nodesnull,
        
linksnull
    
},
    
backgroundnull,
    
linksnull,

    
projectnull,

    
nodes: [],

    
/**
     * Bind a new renderer to given canvas
     * @param  HTMLElement domContainer [description]
     * @param  Integer width      [description]
     * @param  Integer height     [description]
     * @param  Integer autoRedraw If defined, sets redraw rate to given FPS
     */
    
init: function(domContainerautoRedraw)
    {
        var 
self this;

        
this.dom domContainer;
        
this.container = $('#'+domContainer);
        
this.width this.container.width();
        
this.height this.container.height();

        
this.stage = new Kinetic.Stage({
            
containerthis.dom,
            
widththis.width,
            
heightthis.height
        
});

        
this.layers.background = new Kinetic.Layer();
        
this.layers.nodes = new Kinetic.Layer();
        
this.layers.links = new Kinetic.Layer();

        
this.background = new Kinetic.Rect({
            
widththis.width,
            
heightthis.height,
            
fill"#272822"
        
});

        
this.layers.background.add(this.background);

        
this.links = new pgli.diagram.Links(this);
        
this.layers.links.add(this.links.shape);

        
this.stage.add(this.layers.background);
        
this.stage.add(this.layers.nodes);
        
this.stage.add(this.layers.links);

        
// Stage drag hack to trigger only on background drag
        
var self this;
        
this.background.on("mousedown", function(){
            
self.stage.setDraggable(true);
            
self.stage.on("dragmove", function(){
                
self.layers.background.setX(-this.getX());
                
self.layers.background.setY(-this.getY());
            });
            
self.stage.on("dragend", function(){
                
this.off("dragend");
                
this.off("dragmove");
                
this.setDraggable(false);
            });
        });

        if(
autoRedraw != undefined && autoRedraw != false && autoRedraw 0)
        {
            
this.redrawDelay 1000 autoRedraw;
            
this.timer = new bkcore.Timer();
            
this.timer.start();
            
this.autoRedraw(true);
        }
    },

    
addNode: function(node)
    {
        
this.nodes.push(node);
        
this.layers.nodes.add(node.shape);
        
this.layers.nodes.draw();
    },

    
getNode: function(nodeKey)
    {
        var 
0len this.nodes.length;
        while(
len)
        {
            if(
this.nodes[i].key == nodeKey)
                return 
this.nodes[i];
            
i++;
        }
        
console.warn("Error in Diagram: Unable to find node["+nodeKey+"]");
        return 
false;
    },

    
draw: function()
    {
        
this.layers.background.draw();
        
this.layers.nodes.draw();
        
this.layers.links.draw();
    },

    
autoRedraw: function(keep)
    {
        var 
self this;

        if(
this.timer.update() > this.redrawDelay)
        {
            
this.timer.start();
            
this.draw();
        }

        if(
keep)
            
requestAnimFrame(function(){
                
self.autoRedraw(true);
            });
    },

    
resize: function()
    {
        
this.width this.container.width();
        
this.height this.container.height();
        
this.stage.setSize(this.widththis.height);
        
this.background.setSize(this.widththis.height);
        
this.draw();
    }

});
?>
Онлайн: 1
Реклама