From c2f971f9e912bff674119fd2b6147a8bcb570461 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Mon, 18 May 2015 09:28:51 +0200 Subject: [PATCH] Added option to fix prev thing --- controllers/prototype/views/prototype.jade | 3 +++ static/js/prototype/ButtonManager.js | 9 ++++++++- static/js/prototype/Previewer.js | 22 ++++++++++++++-------- static/js/prototype/main.js | 2 +- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/controllers/prototype/views/prototype.jade b/controllers/prototype/views/prototype.jade index 2bbf4f0..5f22af7 100644 --- a/controllers/prototype/views/prototype.jade +++ b/controllers/prototype/views/prototype.jade @@ -114,6 +114,9 @@ block content input#showarrows(type="checkbox", style={'margin-right': '10px', 'margin-bottom': '10px'}, checked) label(for="showarrows" style={'margin-right':'10px'}) Show arrows + input#recommendation(type="checkbox", style={'margin-right': '10px', 'margin-bottom': '10px'}) + label(for="recommendation" style={'margin-right':'10px'}) Fixed prev + audio#music(controls, volume=0.5) source(src="/static/data/music/bobomb.ogg") source(src="/static/data/music/bobomb.mp3") diff --git a/static/js/prototype/ButtonManager.js b/static/js/prototype/ButtonManager.js index 2d8e32c..4521c2d 100644 --- a/static/js/prototype/ButtonManager.js +++ b/static/js/prototype/ButtonManager.js @@ -1,5 +1,6 @@ -var ButtonManager = function(cameras) { +var ButtonManager = function(cameras, previewer) { this.cameras = cameras; + this.previewer = previewer; this.showArrows = true; this.beenFullscreen = false; @@ -13,6 +14,8 @@ var ButtonManager = function(cameras) { this.collisionElement = document.getElementById('collisions'); this.showarrowsElement = document.getElementById('showarrows'); + this.recommendationElement = document.getElementById('recommendation'); + this.fullscreenElement.onclick = function() {fullscreen();}; (function(self) { @@ -31,6 +34,10 @@ var ButtonManager = function(cameras) { self.collisionElement.onchange = function() {self.cameras.mainCamera().collisions = self.collisionElement.checked;} self.showarrowsElement.onchange = function() {self.showArrows = self.showarrowsElement.checked;} self.resetElement.onclick = function() {self.cameras.mainCamera().reset();} + + self.recommendationElement.onchange = function() { + previewer.fixedRecommendation(self.recommendationElement.checked); + } })(this); } diff --git a/static/js/prototype/Previewer.js b/static/js/prototype/Previewer.js index 2d12477..760856f 100644 --- a/static/js/prototype/Previewer.js +++ b/static/js/prototype/Previewer.js @@ -2,20 +2,22 @@ var Previewer = function(renderer) { this.domElement = document.createElement('canvas'); this.ctx = this.domElement.getContext('2d'); this.renderer = renderer; + this.fixed = false; } Previewer.prototype.render = function(prev, container_width, container_height) { - var width = container_width / 5; - var height = container_height / 5; - var left = prev.x - width/2; - var bottom = renderer.domElement.height - prev.y + height/5; + var width, height, left, bottom; if (prev.go) { width = Math.floor(container_width / 5); height = Math.floor(container_height / 5); - left = Math.floor(prev.x - width/2); - bottom = Math.floor(renderer.domElement.height - prev.y + height/5); - + if (!this.fixed) { + left = Math.floor(prev.x - width/2); + bottom = Math.floor(this.renderer.domElement.height - prev.y + height/5); + } else { + left = 0; + bottom = 0; + } // Draw border var can_bottom = container_height - bottom - height ; @@ -40,7 +42,7 @@ Previewer.prototype.render = function(prev, container_width, container_height) { // Do render in previsualization prev.camera.look(); this.renderer.setScissor(left, bottom, width, height); - this.renderer.enableScissorTest (true); + this.renderer.enableScissorTest(true); this.renderer.setViewport(left, bottom, width, height); this.renderer.render(scene, prev.camera); @@ -54,3 +56,7 @@ Previewer.prototype.clear = function() { this.clearNeeded = false; } } + +Previewer.prototype.fixedRecommendation = function(bool) { + this.fixed = bool; +} diff --git a/static/js/prototype/main.js b/static/js/prototype/main.js index 92a217d..64fa38b 100644 --- a/static/js/prototype/main.js +++ b/static/js/prototype/main.js @@ -137,7 +137,7 @@ function initListeners() { document.addEventListener('keydown', function(event) { if (event.keyCode == 27) { stopFullscreen();} }, false); // HTML Bootstrap buttons - buttonManager = new ButtonManager(cameras); + buttonManager = new ButtonManager(cameras, previewer); // Camera selecter for hover and clicking recommendations cameraSelecter = new CameraSelecter(renderer, cameras, buttonManager);