Canvas.js
Summary
No overview generated for 'Canvas.js'
draw2d.Canvas=function( canvasId)
{
if(canvasId)
this.construct(canvasId);
this.enableSmoothFigureHandling = false;
this.canvasLines = new draw2d.ArrayList();
}
draw2d.Canvas.prototype.type="Canvas";
draw2d.Canvas.prototype.construct=function( canvasId)
{
this.canvasId = canvasId;
this.html = document.getElementById(this.canvasId);
this.scrollArea = document.body.parentNode;
}
draw2d.Canvas.prototype.setViewPort= function( divId)
{
this.scrollArea = document.getElementById(divId);
}
draw2d.Canvas.prototype.addFigure= function( figure, xPos, yPos, avoidPaint)
{
if(this.enableSmoothFigureHandling==true)
{
if(figure.timer<=0)
figure.setAlpha(0.001);
var oFigure = figure;
var slowShow = function()
{
if(oFigure.alpha<1.0)
oFigure.setAlpha(Math.min(1.0,oFigure.alpha+0.05));
else
{
window.clearInterval(oFigure.timer);
oFigure.timer = -1;
}
};
if(oFigure.timer>0)
window.clearInterval(oFigure.timer);
oFigure.timer = window.setInterval(slowShow,30);
}
figure.setCanvas(this);
if(xPos && yPos)
figure.setPosition(xPos,yPos);
if(figure instanceof draw2d.Line)
{
this.canvasLines.add(figure);
this.html.appendChild(figure.getHTMLElement());
}
else
{
var obj = this.canvasLines.getFirstElement();
if(obj==null)
this.html.appendChild(figure.getHTMLElement());
else
this.html.insertBefore(figure.getHTMLElement(),obj.getHTMLElement());
}
if(!avoidPaint)
figure.paint();
}
draw2d.Canvas.prototype.removeFigure=function( figure)
{
if(this.enableSmoothFigureHandling==true)
{
var oThis = this;
var oFigure = figure;
var slowShow = function()
{
if(oFigure.alpha>0.0)
oFigure.setAlpha(Math.max(0.0,oFigure.alpha-0.05));
else
{
window.clearInterval(oFigure.timer);
oFigure.timer =-1;
oThis.html.removeChild(oFigure.html);
oFigure.setCanvas(null);
}
};
if(oFigure.timer>0)
window.clearInterval(oFigure.timer);
oFigure.timer = window.setInterval(slowShow,20);
}
else
{
this.html.removeChild(figure.html);
figure.setCanvas(null);
}
if(figure instanceof draw2d.Line)
this.canvasLines.remove(figure);
}
draw2d.Canvas.prototype.getEnableSmoothFigureHandling=function()
{
return this.enableSmoothFigureHandling;
}
draw2d.Canvas.prototype.setEnableSmoothFigureHandling=function( flag)
{
this.enableSmoothFigureHandling=flag;
}
draw2d.Canvas.prototype.getWidth=function()
{
return parseInt(this.html.style.width);
}
draw2d.Canvas.prototype.getHeight=function()
{
return parseInt(this.html.style.height);
}
draw2d.Canvas.prototype.setBackgroundImage=function( imageUrl, repeat)
{
if(imageUrl!=null)
{
if(repeat)
this.html.style.background="transparent url("+imageUrl+") ";
else
this.html.style.background="transparent url("+imageUrl+") no-repeat";
}
else
{
this.html.style.background="transparent";
}
}
draw2d.Canvas.prototype.getY=function()
{
return this.y;
}
draw2d.Canvas.prototype.getX=function()
{
return this.x;
}
draw2d.Canvas.prototype.getAbsoluteY=function()
{
var el = this.html;
var ot=el.offsetTop;
while((el=el.offsetParent) != null)
{
ot += el.offsetTop;
}
return ot;
}
draw2d.Canvas.prototype.getAbsoluteX=function()
{
var el = this.html;
var ol=el.offsetLeft;
while((el=el.offsetParent) != null)
{
ol += el.offsetLeft;
}
return ol;
}
draw2d.Canvas.prototype.getScrollLeft=function()
{
return this.scrollArea.scrollLeft;
}
draw2d.Canvas.prototype.getScrollTop=function()
{
return this.scrollArea.scrollTop;
}
Documentation generated by
JSDoc on Thu Feb 7 23:45:47 2008