mirror of
https://github.com/UnickSoft/graphonline.git
synced 2026-04-11 18:26:17 +00:00
Change script location.
Split js code. Added cache and changed loading mechanism for js sources.
This commit is contained in:
89
script/features/draw_graph/model/BaseBackgroundDrawer.js
Normal file
89
script/features/draw_graph/model/BaseBackgroundDrawer.js
Normal file
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Graph drawer.
|
||||
*/
|
||||
|
||||
|
||||
function CommonBackgroundStyle()
|
||||
{
|
||||
this.commonColor = '#ffffff';
|
||||
this.commonOpacity = 1.0;
|
||||
this.image = null;
|
||||
}
|
||||
|
||||
CommonBackgroundStyle.prototype.Clear = function ()
|
||||
{
|
||||
delete this.commonColor;
|
||||
delete this.commonOpacity;
|
||||
delete this.image;
|
||||
}
|
||||
|
||||
CommonBackgroundStyle.prototype.ShouldLoad = function (field)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
CommonBackgroundStyle.prototype.saveToJson = function (field)
|
||||
{
|
||||
return JSON.stringify({commonColor: this.commonColor, commonOpacity: this.commonOpacity, image: this.image != null ? this.image.src : null});
|
||||
}
|
||||
|
||||
CommonBackgroundStyle.prototype.loadFromJson = function (json, callbackOnLoaded)
|
||||
{
|
||||
this.commonColor = json["commonColor"];
|
||||
this.commonOpacity = json["commonOpacity"];
|
||||
this.image = null;
|
||||
if (typeof json["image"] === 'string') {
|
||||
this.image = new Image();
|
||||
this.image.onload = function() {
|
||||
callbackOnLoaded();
|
||||
}
|
||||
this.image.src = json["image"];
|
||||
}
|
||||
}
|
||||
|
||||
PrintBackgroundStyle.prototype = Object.create(CommonBackgroundStyle.prototype);
|
||||
|
||||
function PrintBackgroundStyle()
|
||||
{
|
||||
CommonBackgroundStyle.apply(this, arguments);
|
||||
|
||||
this.commonColor = '#ffffff';
|
||||
this.commonOpacity = 1.0;
|
||||
this.image = null;
|
||||
}
|
||||
|
||||
function BaseBackgroundDrawer(context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
BaseBackgroundDrawer.prototype.Draw = function(style, width, height, position, scale)
|
||||
{
|
||||
var context = this.context;
|
||||
|
||||
var rect = new Rect(position, position.add(new Point(width / scale, height / scale)));
|
||||
|
||||
context.clearRect(-rect.minPoint.x, -rect.minPoint.y, rect.size().x + 1, rect.size().y + 1);
|
||||
|
||||
var oldOpacity = context.globalAlpha;
|
||||
if (style.commonOpacity > 0.0)
|
||||
{
|
||||
context.globalAlpha = style.commonOpacity;
|
||||
context.fillStyle = style.commonColor;
|
||||
context.fillRect(-rect.minPoint.x, -rect.minPoint.y, rect.size().x + 1, rect.size().y + 1);
|
||||
this.DrawImage(style, width, height, position, scale);
|
||||
}
|
||||
context.globalAlpha = oldOpacity;
|
||||
}
|
||||
|
||||
BaseBackgroundDrawer.prototype.DrawImage = function(style, width, height, position, scale)
|
||||
{
|
||||
if (style.image == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var context = this.context;
|
||||
|
||||
context.clearRect(0, 0, style.image.width, style.image.height);
|
||||
context.drawImage(style.image, 0, 0)
|
||||
}
|
||||
Reference in New Issue
Block a user