Translate box so its well placed
This commit is contained in:
parent
c0a2044118
commit
2a5ae4d985
|
@ -1,3 +1,7 @@
|
||||||
|
Math.clamp = Math.clamp || function(number, min, max) {
|
||||||
|
return Math.max(Math.min(number, max), min);
|
||||||
|
}
|
||||||
|
|
||||||
var Previewer = function(renderer) {
|
var Previewer = function(renderer) {
|
||||||
this.domElement = document.createElement('canvas');
|
this.domElement = document.createElement('canvas');
|
||||||
this.ctx = this.domElement.getContext('2d');
|
this.ctx = this.domElement.getContext('2d');
|
||||||
|
@ -14,11 +18,15 @@ Previewer.prototype.render = function(prev, container_width, container_height) {
|
||||||
if (!this.fixed) {
|
if (!this.fixed) {
|
||||||
left = Math.floor(prev.x - width/2);
|
left = Math.floor(prev.x - width/2);
|
||||||
bottom = Math.floor(this.renderer.domElement.height - prev.y + height/5);
|
bottom = Math.floor(this.renderer.domElement.height - prev.y + height/5);
|
||||||
|
|
||||||
|
// Translate box if too high
|
||||||
if (bottom + height > this.renderer.domElement.height) {
|
if (bottom + height > this.renderer.domElement.height) {
|
||||||
bottom -= 7 * height / 5;
|
bottom -= 7 * height / 5;
|
||||||
console.log(bottom);
|
|
||||||
}
|
}
|
||||||
console.log(bottom, this.renderer.domElement.height);
|
|
||||||
|
// Translate box if too on the side
|
||||||
|
left = Math.clamp(left, width / 5, this.renderer.domElement.width - 6 * width / 5);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
left = 0;
|
left = 0;
|
||||||
bottom = 0;
|
bottom = 0;
|
||||||
|
|
Loading…
Reference in New Issue