From 38d49854cbfa8254fbdf79de0274bdcac7609383 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 14 Jan 2015 01:06:44 +0100 Subject: [PATCH] hide cursor --- examples/controllers/oculus/goTo.js | 7 +++-- examples/libraries/virtualKeyboard.js | 38 +++++++++++++++++++-------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/examples/controllers/oculus/goTo.js b/examples/controllers/oculus/goTo.js index ba1ee1eb81..3966c28a5c 100644 --- a/examples/controllers/oculus/goTo.js +++ b/examples/controllers/oculus/goTo.js @@ -20,7 +20,7 @@ Script.include("../../libraries/globals.js"); Script.include("../../libraries/virtualKeyboard.js"); var windowDimensions = Controller.getViewportDimensions(); -var cursor = null; +var cursor = new Cursor({visible: false}); var keyboard = new Keyboard({visible: false}); var textFontSize = 9; var text = null; @@ -91,7 +91,7 @@ keyboard.onFullyLoaded = function() { }); updateTextOverlay(); // the cursor is being loaded after the keyboard, else it will be on the background of the keyboard - cursor = new Cursor(); + cursor.updateVisibility(keyboard.visible); cursor.onUpdate = function(position) { keyboard.setFocusPosition(position.x, position.y); }; @@ -102,6 +102,9 @@ function keyPressEvent(event) { keyboard.pressFocussedKey(); } else if (event.key === ENTER_CHARCODE || event.key === RETURN_CHARCODE) { keyboard.toggle(); + if (cursor !== undefined) { + cursor.updateVisibility(keyboard.visible); + } Overlays.editOverlay(text, {visible: keyboard.visible}); } } diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index 854ca58d1d..d93e569af5 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -184,7 +184,7 @@ Keyboard = (function(params) { this.focussed_key = -1; this.scale = (windowDimensions.x / KEYBOARD_WIDTH) * KEYBOARD_SCALE_MULTIPLIER; this.shift = false; - this.visible = params.visible != undefined ? params.visible :true; + this.visible = params.visible != undefined ? params.visible : true; this.width = function() { return KEYBOARD_WIDTH * tthis.scale; }; @@ -320,21 +320,19 @@ Keyboard = (function(params) { }; this.show = function() { - tthis.visible = true; - tthis.updateVisibility(); + tthis.updateVisibility(true); }; this.hide = function() { - tthis.visible = false; - tthis.updateVisibility(); + tthis.updateVisibility(false); }; this.toggle = function() { - tthis.visible = !tthis.visible; - tthis.updateVisibility(); + tthis.updateVisibility(!tthis.visible); }; - - this.updateVisibility = function() { + + this.updateVisibility = function(visible) { + tthis.visible = visible; Overlays.editOverlay(tthis.background, { visible: tthis.visible }); for (var i = 0; i < this.keys.length; i++) { this.keys[i].updateVisibility(); @@ -454,8 +452,12 @@ Keyboard = (function(params) { this.keyboardTextureLoaded_timer = Script.setInterval(this.keyboardTextureLoaded, 250); }); -Cursor = (function() { +Cursor = (function(params) { + if (params === undefined) { + params = {}; + } var tthis = this; + this.visible = params.visible != undefined ? params.visible : true; this.x = windowDimensions.x / 2; this.y = windowDimensions.y / 2; this.overlay = Overlays.addOverlay("image", { @@ -464,7 +466,8 @@ Cursor = (function() { width: CURSOR_WIDTH, height: CURSOR_HEIGHT, imageURL: CURSOR_URL, - alpha: 1 + alpha: 1, + visible: this.visible }); this.remove = function() { Overlays.deleteOverlay(this.overlay); @@ -478,6 +481,19 @@ Cursor = (function() { this.getY = function() { return tthis.y; }; + this.show = function() { + tthis.updateVisibility(true); + }; + this.hide = function() { + tthis.updateVisibility(false); + }; + this.toggle = function() { + tthis.updateVisibility(!tthis.visible); + }; + this.updateVisibility = function(visible) { + tthis.visible = visible; + Overlays.editOverlay(this.overlay, { visible: tthis.visible }); + }; this.onUpdate = null; this.update = function() { var newWindowDimensions = Controller.getViewportDimensions();