2015-07-01 16:31:43 +02:00
|
|
|
L3D.MousePointer = function(camera) {
|
2015-06-22 14:39:41 +02:00
|
|
|
|
2015-06-22 09:41:59 +02:00
|
|
|
this.domElement = document.createElement('canvas');
|
|
|
|
this.domElement.style.position = 'absolute';
|
|
|
|
this.domElement.style.cssFloat = 'top-left';
|
|
|
|
this.ctx = this.domElement.getContext('2d');
|
|
|
|
this.size = 10;
|
|
|
|
this.drawn = false;
|
|
|
|
camera.mousePointer = this;
|
2015-07-01 16:31:43 +02:00
|
|
|
this.style = L3D.MousePointer.NONE;
|
2015-07-01 10:14:15 +02:00
|
|
|
};
|
2015-06-22 14:39:41 +02:00
|
|
|
|
2015-07-01 16:31:43 +02:00
|
|
|
L3D.MousePointer.NONE = 0;
|
|
|
|
L3D.MousePointer.BLACK = 1;
|
|
|
|
L3D.MousePointer.RED = 2;
|
2015-06-22 14:39:41 +02:00
|
|
|
|
2015-07-01 16:31:43 +02:00
|
|
|
L3D.MousePointer.toColor = function(style) {
|
2015-06-22 14:39:41 +02:00
|
|
|
|
|
|
|
switch (style) {
|
|
|
|
|
2015-07-01 16:31:43 +02:00
|
|
|
case L3D.MousePointer.NONE:
|
2015-06-22 14:39:41 +02:00
|
|
|
return null;
|
2015-07-01 16:31:43 +02:00
|
|
|
case L3D.MousePointer.BLACK:
|
2015-06-22 14:39:41 +02:00
|
|
|
return '#000000';
|
2015-07-01 16:31:43 +02:00
|
|
|
case L3D.MousePointer.RED:
|
2015-06-22 14:39:41 +02:00
|
|
|
return '#ff0000';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-01 10:14:15 +02:00
|
|
|
};
|
2015-06-22 09:41:59 +02:00
|
|
|
|
2015-07-01 16:31:43 +02:00
|
|
|
L3D.MousePointer.prototype.render = function(style) {
|
2015-06-22 14:39:41 +02:00
|
|
|
|
|
|
|
if (this.style !== style) {
|
2015-06-22 09:41:59 +02:00
|
|
|
|
2015-07-01 16:31:43 +02:00
|
|
|
if (style === L3D.MousePointer.NONE) {
|
2015-06-22 09:41:59 +02:00
|
|
|
|
2015-06-22 14:39:41 +02:00
|
|
|
// Clear canvas
|
|
|
|
this.domElement.width = this.domElement.width;
|
2015-07-01 16:31:43 +02:00
|
|
|
this.style = L3D.MousePointer.NONE;
|
2015-06-22 09:41:59 +02:00
|
|
|
|
2015-06-22 14:39:41 +02:00
|
|
|
} else {
|
2015-06-22 09:41:59 +02:00
|
|
|
|
2015-06-22 14:39:41 +02:00
|
|
|
this.domElement.width = this.domElement.width;
|
|
|
|
|
|
|
|
var i = container_size.width() / 2;
|
|
|
|
var imin = i - this.size;
|
|
|
|
var imax = i + this.size;
|
|
|
|
|
|
|
|
var j = container_size.height() / 2;
|
|
|
|
var jmin = j - this.size;
|
|
|
|
var jmax = j + this.size;
|
|
|
|
|
|
|
|
this.ctx.beginPath();
|
|
|
|
this.ctx.moveTo(imin, j);
|
|
|
|
this.ctx.lineTo(imax, j);
|
|
|
|
this.ctx.moveTo(i, jmin);
|
|
|
|
this.ctx.lineTo(i, jmax);
|
|
|
|
this.ctx.closePath();
|
|
|
|
|
|
|
|
|
|
|
|
this.ctx.lineWidth = 5;
|
|
|
|
this.ctx.strokeStyle = '#ffffff';
|
|
|
|
this.ctx.stroke();
|
|
|
|
|
|
|
|
this.ctx.lineWidth = 2;
|
2015-07-01 16:31:43 +02:00
|
|
|
this.ctx.strokeStyle = L3D.MousePointer.toColor(style);
|
2015-06-22 14:39:41 +02:00
|
|
|
this.ctx.stroke();
|
|
|
|
|
|
|
|
this.style = style;
|
|
|
|
|
|
|
|
}
|
2015-06-22 09:41:59 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-01 10:14:15 +02:00
|
|
|
};
|
2015-06-22 09:41:59 +02:00
|
|
|
|
2015-07-01 16:31:43 +02:00
|
|
|
L3D.MousePointer.prototype.clear = function() {
|
2015-06-22 09:41:59 +02:00
|
|
|
|
2015-07-01 16:31:43 +02:00
|
|
|
this.render(L3D.MousePointer.NONE);
|
2015-06-22 09:41:59 +02:00
|
|
|
|
2015-07-01 10:14:15 +02:00
|
|
|
};
|