2017-10-09 10:18:59 +02:00
|
|
|
/**
|
|
|
|
* Canvas Superset - The apiCanvas properties get moved into the Canvas object itself, and then the instance is created
|
|
|
|
* @param graphics GameLib.D3.Graphics
|
|
|
|
* @param apiCanvas GameLib.D3.API.Canvas
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
GameLib.D3.Canvas = function(
|
|
|
|
graphics,
|
|
|
|
apiCanvas
|
|
|
|
) {
|
|
|
|
this.graphics = graphics;
|
|
|
|
this.graphics.isNotThreeThrow();
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(apiCanvas)) {
|
|
|
|
apiCanvas = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (apiCanvas instanceof GameLib.D3.Canvas) {
|
|
|
|
return apiCanvas;
|
|
|
|
}
|
|
|
|
|
|
|
|
GameLib.D3.API.Canvas.call(
|
|
|
|
this,
|
|
|
|
apiCanvas.id,
|
|
|
|
apiCanvas.name,
|
|
|
|
apiCanvas.width,
|
|
|
|
apiCanvas.height,
|
|
|
|
apiCanvas.parentEntity
|
|
|
|
);
|
|
|
|
|
|
|
|
GameLib.Component.call(
|
|
|
|
this,
|
|
|
|
GameLib.Component.COMPONENT_CANVAS
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.D3.Canvas.prototype = Object.create(GameLib.D3.API.Canvas.prototype);
|
|
|
|
GameLib.D3.Canvas.prototype.constructor = GameLib.D3.Canvas;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a light instance
|
|
|
|
* @returns {*}
|
|
|
|
*/
|
|
|
|
GameLib.D3.Canvas.prototype.createInstance = function() {
|
|
|
|
|
2017-10-23 14:52:35 +02:00
|
|
|
this.instance = document.createElement('canvas');
|
2017-10-09 10:18:59 +02:00
|
|
|
|
2017-10-23 14:52:35 +02:00
|
|
|
this.instance.width = this.width;
|
|
|
|
this.instance.height = this.height;
|
2017-10-09 10:18:59 +02:00
|
|
|
|
2017-10-23 14:52:35 +02:00
|
|
|
GameLib.Component.prototype.createInstance.call(this);
|
2017-10-09 10:18:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the instance with the current state
|
|
|
|
*/
|
|
|
|
GameLib.D3.Canvas.prototype.updateInstance = function() {
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
|
2017-10-23 14:52:35 +02:00
|
|
|
this.createInstance();
|
2017-10-09 10:18:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.instance.width = this.width;
|
|
|
|
this.instance.height = this.height;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a GameLib.D3.Canvas to a GameLib.D3.API.Canvas
|
|
|
|
* @returns {GameLib.D3.API.Canvas}
|
|
|
|
*/
|
|
|
|
GameLib.D3.Canvas.prototype.toApiObject = function() {
|
|
|
|
return new GameLib.D3.API.Canvas(
|
|
|
|
this.id,
|
|
|
|
this.name,
|
|
|
|
this.width,
|
|
|
|
this.height,
|
|
|
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a new GameLib.D3.Canvas from a GameLib.D3.API.Canvas
|
|
|
|
* @param graphics GameLib.D3.Graphics
|
|
|
|
* @param objectCanvas GameLib.D3.API.Canvas
|
|
|
|
* @returns {GameLib.D3.Canvas}
|
|
|
|
*/
|
|
|
|
GameLib.D3.Canvas.FromObject = function(graphics, objectCanvas) {
|
|
|
|
|
|
|
|
return new GameLib.D3.Canvas(
|
|
|
|
graphics,
|
|
|
|
GameLib.D3.API.Canvas.FromObject(objectCanvas)
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|