3d-interface/js/l3d/src/canvases/MousePointer.js

83 lines
1.8 KiB
JavaScript
Raw Normal View History

2015-06-22 09:41:59 +02:00
var MousePointer = function(camera) {
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;
this.style = MousePointer.NONE;
};
MousePointer.NONE = 0;
MousePointer.BLACK = 1;
MousePointer.RED = 2;
MousePointer.toColor = function(style) {
switch (style) {
case MousePointer.NONE:
return null;
case MousePointer.BLACK:
return '#000000';
case MousePointer.RED:
return '#ff0000';
}
};
2015-06-22 09:41:59 +02:00
MousePointer.prototype.render = function(style) {
if (this.style !== style) {
2015-06-22 09:41:59 +02:00
if (style === MousePointer.NONE) {
2015-06-22 09:41:59 +02:00
// Clear canvas
this.domElement.width = this.domElement.width;
this.style = MousePointer.NONE;
2015-06-22 09:41:59 +02:00
} else {
2015-06-22 09:41:59 +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;
this.ctx.strokeStyle = MousePointer.toColor(style);
this.ctx.stroke();
this.style = style;
}
2015-06-22 09:41:59 +02:00
}
};
2015-06-22 09:41:59 +02:00
MousePointer.prototype.clear = function() {
this.render(MousePointer.NONE);
2015-06-22 09:41:59 +02:00
};