From e38aa89418bde960d4132a269e6db27ae66a91de Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Mon, 29 Dec 2014 21:11:34 +0100 Subject: [PATCH 01/18] Overwrite keypress of Enter key --- examples/virtualKeyboard.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/examples/virtualKeyboard.js b/examples/virtualKeyboard.js index ce793c6ea0..aede5c69d5 100644 --- a/examples/virtualKeyboard.js +++ b/examples/virtualKeyboard.js @@ -26,6 +26,8 @@ const KBD_BACKGROUND = 4; const KEYBOARD_URL = HIFI_PUBLIC_BUCKET + "images/keyboard.svg"; const CURSOR_URL = HIFI_PUBLIC_BUCKET + "images/cursor.svg"; +const RETURN_CHARCODE = 0x01000004; +const ENTER_CHARCODE = 0x01000005; const SPACEBAR_CHARCODE = 32; const KEYBOARD_WIDTH = 1174.7; @@ -576,7 +578,10 @@ function Cursor() { function keyPressEvent(event) { if (event.key === SPACEBAR_CHARCODE) { keyboard.pressFocussedKey(); + } else if (event.key === ENTER_CHARCODE || event.key === RETURN_CHARCODE) { + print("Enter pressed"); } + } function keyReleaseEvent(event) { @@ -591,7 +596,11 @@ function scriptEnding() { Overlays.deleteOverlay(text); Overlays.deleteOverlay(textSizeMeasureOverlay); Controller.releaseKeyEvents({key: SPACEBAR_CHARCODE}); + Controller.releaseKeyEvents({key: RETURN_CHARCODE}); + Controller.releaseKeyEvents({key: ENTER_CHARCODE}); } +Controller.captureKeyEvents({key: RETURN_CHARCODE}); +Controller.captureKeyEvents({key: ENTER_CHARCODE}); Controller.captureKeyEvents({key: SPACEBAR_CHARCODE}); Controller.keyPressEvent.connect(keyPressEvent); Controller.keyReleaseEvent.connect(keyReleaseEvent); From d299f3f0c5e0bb3acf07e6218b6025a264b0ba66 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Mon, 29 Dec 2014 23:10:15 +0100 Subject: [PATCH 02/18] no 3d mode for now --- examples/virtualKeyboard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/virtualKeyboard.js b/examples/virtualKeyboard.js index a580bc7bcc..24b6cd39a1 100644 --- a/examples/virtualKeyboard.js +++ b/examples/virtualKeyboard.js @@ -18,7 +18,7 @@ Script.include("libraries/globals.js"); // experimental 3dmode -const THREE_D_MODE = true; +const THREE_D_MODE = false; const KBD_UPPERCASE_DEFAULT = 0; const KBD_LOWERCASE_DEFAULT = 1; From 4eec066d691f83baccc59ef1291c7cabb4663b6a Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Tue, 30 Dec 2014 19:51:53 +0100 Subject: [PATCH 03/18] split up virtualKeyboard script in a library and two script that will use it: virtualKeyboardLocation.js - Location through virtual keyboard virtualKeyboardTextEntityExample.js - Initial example for virtual keyboard --- examples/{ => libraries}/virtualKeyboard.js | 202 +++---------------- examples/virtualKeyboardLocation.js | 185 +++++++++++++++++ examples/virtualKeyboardTextEntityExample.js | 177 ++++++++++++++++ 3 files changed, 385 insertions(+), 179 deletions(-) rename examples/{ => libraries}/virtualKeyboard.js (75%) create mode 100644 examples/virtualKeyboardLocation.js create mode 100644 examples/virtualKeyboardTextEntityExample.js diff --git a/examples/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js similarity index 75% rename from examples/virtualKeyboard.js rename to examples/libraries/virtualKeyboard.js index 24b6cd39a1..ba9a30974e 100644 --- a/examples/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -9,8 +9,6 @@ // Usage: Enable VR-mode and go to First person mode, // look at the key that you would like to press, and press the spacebar on your "REAL" keyboard. // -// leased some code from newEditEntities.js for Text Entity example -// // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // @@ -18,26 +16,26 @@ Script.include("libraries/globals.js"); // experimental 3dmode -const THREE_D_MODE = false; +THREE_D_MODE = false; -const KBD_UPPERCASE_DEFAULT = 0; -const KBD_LOWERCASE_DEFAULT = 1; -const KBD_UPPERCASE_HOVER = 2; -const KBD_LOWERCASE_HOVER = 3; -const KBD_BACKGROUND = 4; +KBD_UPPERCASE_DEFAULT = 0; +KBD_LOWERCASE_DEFAULT = 1; +KBD_UPPERCASE_HOVER = 2; +KBD_LOWERCASE_HOVER = 3; +KBD_BACKGROUND = 4; -const KEYBOARD_URL = HIFI_PUBLIC_BUCKET + "images/keyboard.svg"; -const CURSOR_URL = HIFI_PUBLIC_BUCKET + "images/cursor.svg"; +KEYBOARD_URL = HIFI_PUBLIC_BUCKET + "images/keyboard.svg"; +CURSOR_URL = HIFI_PUBLIC_BUCKET + "images/cursor.svg"; -const RETURN_CHARCODE = 0x01000004; -const ENTER_CHARCODE = 0x01000005; -const SPACEBAR_CHARCODE = 32; +RETURN_CHARCODE = 0x01000004; +ENTER_CHARCODE = 0x01000005; +SPACEBAR_CHARCODE = 32; -const KEYBOARD_WIDTH = 1174.7; -const KEYBOARD_HEIGHT = 434.1; +KEYBOARD_WIDTH = 1174.7; +KEYBOARD_HEIGHT = 434.1; -const CURSOR_WIDTH = 33.9; -const CURSOR_HEIGHT = 33.9; +CURSOR_WIDTH = 33.9; +CURSOR_HEIGHT = 33.9; // VIEW_ANGLE can be adjusted to your likings, the smaller the faster movement. // Try setting it to 60 if it goes too fast for you. @@ -52,8 +50,8 @@ const BOUND_Y = 1; const BOUND_W = 2; const BOUND_H = 3; -const KEY_STATE_LOWER = 0; -const KEY_STATE_UPPER = 1; +KEY_STATE_LOWER = 0; +KEY_STATE_UPPER = 1; const TEXT_MARGIN_TOP = 0.15; const TEXT_MARGIN_LEFT = 0.15; @@ -62,131 +60,8 @@ const TEXT_MARGIN_BOTTOM = 0.17; var windowDimensions = Controller.getViewportDimensions(); var cursor = null; -var keyboard = new Keyboard(); -var textFontSize = 9; -var text = null; -var textText = ""; -var textSizeMeasureOverlay = Overlays.addOverlay("text3d", {visible: false}); -function appendChar(char) { - textText += char; - updateTextOverlay(); - Overlays.editOverlay(text, {text: textText}); -} - -function deleteChar() { - if (textText.length > 0) { - textText = textText.substring(0, textText.length - 1); - updateTextOverlay(); - } -} - -function updateTextOverlay() { - var textLines = textText.split("\n"); - var maxLineWidth = 0; - for (textLine in textLines) { - var lineWidth = Overlays.textSize(text, textLines[textLine]).width; - if (lineWidth > maxLineWidth) { - maxLineWidth = lineWidth; - } - } - var suggestedFontSize = (windowDimensions.x / maxLineWidth) * textFontSize * 0.90; - var maxFontSize = 190 / textLines.length; - textFontSize = (suggestedFontSize > maxFontSize) ? maxFontSize : suggestedFontSize; - var topMargin = (250 - (textFontSize * textLines.length)) / 4; - Overlays.editOverlay(text, {text: textText, font: {size: textFontSize}, topMargin: topMargin}); - var maxLineWidth = 0; - for (textLine in textLines) { - var lineWidth = Overlays.textSize(text, textLines[textLine]).width; - if (lineWidth > maxLineWidth) { - maxLineWidth = lineWidth; - } - } - Overlays.editOverlay(text, {leftMargin: (windowDimensions.x - maxLineWidth) / 2}); -} - -keyboard.onKeyPress = function(event) { - if (event.event == 'keypress') { - appendChar(event.char); - } else if (event.event == 'enter') { - appendChar("\n"); - } -}; - -keyboard.onKeyRelease = function(event) { - print("Key release event test"); - // you can cancel a key by releasing its focusing before releasing it - if (event.focus) { - if (event.event == 'delete') { - deleteChar(); - } else if (event.event == 'submit') { - print(textText); - - var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE)); - - var textLines = textText.split("\n"); - var maxLineWidth = 0; - for (textLine in textLines) { - var lineWidth = Overlays.textSize(textSizeMeasureOverlay, textLines[textLine]).width; - if (lineWidth > maxLineWidth) { - maxLineWidth = lineWidth; - } - } - var usernameLine = "--" + GlobalServices.myUsername; - var usernameWidth = Overlays.textSize(textSizeMeasureOverlay, usernameLine).width; - if (maxLineWidth < usernameWidth) { - maxLineWidth = usernameWidth; - } else { - var spaceableWidth = maxLineWidth - usernameWidth; - var spaceWidth = Overlays.textSize(textSizeMeasureOverlay, " ").width; - var numberOfSpaces = Math.floor(spaceableWidth / spaceWidth); - for (var i = 0; i < numberOfSpaces; i++) { - usernameLine = " " + usernameLine; - } - } - var dimension_x = maxLineWidth + TEXT_MARGIN_RIGHT + TEXT_MARGIN_LEFT; - if (position.x > 0 && position.y > 0 && position.z > 0) { - Entities.addEntity({ - type: "Text", - rotation: MyAvatar.orientation, - position: position, - dimensions: { x: dimension_x, y: (textLines.length + 1) * 0.14 + TEXT_MARGIN_TOP + TEXT_MARGIN_BOTTOM, z: DEFAULT_TEXT_DIMENSION_Z }, - backgroundColor: { red: 0, green: 0, blue: 0 }, - textColor: { red: 255, green: 255, blue: 255 }, - text: textText + "\n" + usernameLine - }); - } - textText = ""; - updateTextOverlay(); - } - } -}; - -keyboard.onFullyLoaded = function() { - print("Virtual-keyboard fully loaded."); - var dimensions = Controller.getViewportDimensions(); - text = Overlays.addOverlay("text", { - x: 0, - y: dimensions.y - keyboard.height() - 260, - width: dimensions.x, - height: 250, - backgroundColor: { red: 255, green: 255, blue: 255}, - color: { red: 0, green: 0, blue: 0}, - topMargin: 5, - leftMargin: 0, - font: {size: textFontSize}, - text: "", - alpha: 0.8 - }); - updateTextOverlay(); - // the cursor is being loaded after the keyboard, else it will be on the background of the keyboard - cursor = new Cursor(); - cursor.onUpdate = function(position) { - keyboard.setFocusPosition(position.x, position.y); - }; -}; - -function KeyboardKey(keyboard, keyProperties) { +KeyboardKey = (function(keyboard, keyProperties) { var tthis = this; this._focus = false; this._beingPressed = false; @@ -301,9 +176,9 @@ function KeyboardKey(keyboard, keyProperties) { } this.overlays.push(newOverlay); } -} +}); -function Keyboard() { +Keyboard = (function() { var tthis = this; this.focussed_key = -1; this.scale = windowDimensions.x / KEYBOARD_WIDTH; @@ -548,9 +423,9 @@ function Keyboard() { } }; this.keyboardTextureLoaded_timer = Script.setInterval(this.keyboardTextureLoaded, 250); -} +}); -function Cursor() { +Cursor = (function() { var tthis = this; this.x = windowDimensions.x / 2; this.y = windowDimensions.y / 2; @@ -604,35 +479,4 @@ function Cursor() { } }; Script.update.connect(this.update); -} - -function keyPressEvent(event) { - if (event.key === SPACEBAR_CHARCODE) { - keyboard.pressFocussedKey(); - } else if (event.key === ENTER_CHARCODE || event.key === RETURN_CHARCODE) { - print("Enter pressed"); - } - -} - -function keyReleaseEvent(event) { - if (event.key === SPACEBAR_CHARCODE) { - keyboard.releaseKeys(); - } -} - -function scriptEnding() { - keyboard.remove(); - cursor.remove(); - Overlays.deleteOverlay(text); - Overlays.deleteOverlay(textSizeMeasureOverlay); - Controller.releaseKeyEvents({key: SPACEBAR_CHARCODE}); - Controller.releaseKeyEvents({key: RETURN_CHARCODE}); - Controller.releaseKeyEvents({key: ENTER_CHARCODE}); -} -Controller.captureKeyEvents({key: RETURN_CHARCODE}); -Controller.captureKeyEvents({key: ENTER_CHARCODE}); -Controller.captureKeyEvents({key: SPACEBAR_CHARCODE}); -Controller.keyPressEvent.connect(keyPressEvent); -Controller.keyReleaseEvent.connect(keyReleaseEvent); -Script.scriptEnding.connect(scriptEnding); \ No newline at end of file +}); diff --git a/examples/virtualKeyboardLocation.js b/examples/virtualKeyboardLocation.js new file mode 100644 index 0000000000..a5688c4c34 --- /dev/null +++ b/examples/virtualKeyboardLocation.js @@ -0,0 +1,185 @@ +// +// virtualKeyboardTextEntityExample.js +// examples +// +// Created by Thijs Wenker on 11/18/14. +// Copyright 2014 High Fidelity, Inc. +// +// Control a virtual keyboard using your favorite HMD. +// Usage: Enable VR-mode and go to First person mode, +// look at the key that you would like to press, and press the spacebar on your "REAL" keyboard. +// +// Enter a location URL using your HMD. Press Enter to pop-up the virtual keyboard and location input. +// Press Space on the keyboard or the X button on your gamepad to press a key that you have selected. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +Script.include("libraries/virtualKeyboard.js"); + +const SPAWN_DISTANCE = 1; +const DEFAULT_TEXT_DIMENSION_Z = 0.02; + +const TEXT_MARGIN_TOP = 0.15; +const TEXT_MARGIN_LEFT = 0.15; +const TEXT_MARGIN_RIGHT = 0.17; +const TEXT_MARGIN_BOTTOM = 0.17; + +var windowDimensions = Controller.getViewportDimensions(); +var cursor = null; +var keyboard = new Keyboard(); +var textFontSize = 9; +var text = null; +var textText = ""; +var textSizeMeasureOverlay = Overlays.addOverlay("text3d", {visible: false}); + +function appendChar(char) { + textText += char; + updateTextOverlay(); + Overlays.editOverlay(text, {text: textText}); +} + +function deleteChar() { + if (textText.length > 0) { + textText = textText.substring(0, textText.length - 1); + updateTextOverlay(); + } +} + +function updateTextOverlay() { + var textLines = textText.split("\n"); + var maxLineWidth = 0; + for (textLine in textLines) { + var lineWidth = Overlays.textSize(text, textLines[textLine]).width; + if (lineWidth > maxLineWidth) { + maxLineWidth = lineWidth; + } + } + var suggestedFontSize = (windowDimensions.x / maxLineWidth) * textFontSize * 0.90; + var maxFontSize = 190 / textLines.length; + textFontSize = (suggestedFontSize > maxFontSize) ? maxFontSize : suggestedFontSize; + var topMargin = (250 - (textFontSize * textLines.length)) / 4; + Overlays.editOverlay(text, {text: textText, font: {size: textFontSize}, topMargin: topMargin}); + var maxLineWidth = 0; + for (textLine in textLines) { + var lineWidth = Overlays.textSize(text, textLines[textLine]).width; + if (lineWidth > maxLineWidth) { + maxLineWidth = lineWidth; + } + } + Overlays.editOverlay(text, {leftMargin: (windowDimensions.x - maxLineWidth) / 2}); +} + +keyboard.onKeyPress = function(event) { + if (event.event == 'keypress') { + appendChar(event.char); + } else if (event.event == 'enter') { + appendChar("\n"); + } +}; + +keyboard.onKeyRelease = function(event) { + print("Key release event test"); + // you can cancel a key by releasing its focusing before releasing it + if (event.focus) { + if (event.event == 'delete') { + deleteChar(); + } else if (event.event == 'submit') { + print(textText); + + var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE)); + + var textLines = textText.split("\n"); + var maxLineWidth = 0; + for (textLine in textLines) { + var lineWidth = Overlays.textSize(textSizeMeasureOverlay, textLines[textLine]).width; + if (lineWidth > maxLineWidth) { + maxLineWidth = lineWidth; + } + } + var usernameLine = "--" + GlobalServices.myUsername; + var usernameWidth = Overlays.textSize(textSizeMeasureOverlay, usernameLine).width; + if (maxLineWidth < usernameWidth) { + maxLineWidth = usernameWidth; + } else { + var spaceableWidth = maxLineWidth - usernameWidth; + var spaceWidth = Overlays.textSize(textSizeMeasureOverlay, " ").width; + var numberOfSpaces = Math.floor(spaceableWidth / spaceWidth); + for (var i = 0; i < numberOfSpaces; i++) { + usernameLine = " " + usernameLine; + } + } + var dimension_x = maxLineWidth + TEXT_MARGIN_RIGHT + TEXT_MARGIN_LEFT; + if (position.x > 0 && position.y > 0 && position.z > 0) { + Entities.addEntity({ + type: "Text", + rotation: MyAvatar.orientation, + position: position, + dimensions: { x: dimension_x, y: (textLines.length + 1) * 0.14 + TEXT_MARGIN_TOP + TEXT_MARGIN_BOTTOM, z: DEFAULT_TEXT_DIMENSION_Z }, + backgroundColor: { red: 0, green: 0, blue: 0 }, + textColor: { red: 255, green: 255, blue: 255 }, + text: textText + "\n" + usernameLine + }); + } + textText = ""; + updateTextOverlay(); + } + } +}; + +keyboard.onFullyLoaded = function() { + print("Virtual-keyboard fully loaded."); + var dimensions = Controller.getViewportDimensions(); + text = Overlays.addOverlay("text", { + x: 0, + y: dimensions.y - keyboard.height() - 260, + width: dimensions.x, + height: 250, + backgroundColor: { red: 255, green: 255, blue: 255}, + color: { red: 0, green: 0, blue: 0}, + topMargin: 5, + leftMargin: 0, + font: {size: textFontSize}, + text: "", + alpha: 0.8 + }); + updateTextOverlay(); + // the cursor is being loaded after the keyboard, else it will be on the background of the keyboard + cursor = new Cursor(); + cursor.onUpdate = function(position) { + keyboard.setFocusPosition(position.x, position.y); + }; +}; + +function keyPressEvent(event) { + if (event.key === SPACEBAR_CHARCODE) { + keyboard.pressFocussedKey(); + } else if (event.key === ENTER_CHARCODE || event.key === RETURN_CHARCODE) { + print("Enter pressed"); + } + +} + +function keyReleaseEvent(event) { + if (event.key === SPACEBAR_CHARCODE) { + keyboard.releaseKeys(); + } +} + +function scriptEnding() { + keyboard.remove(); + cursor.remove(); + Overlays.deleteOverlay(text); + Overlays.deleteOverlay(textSizeMeasureOverlay); + Controller.releaseKeyEvents({key: SPACEBAR_CHARCODE}); + Controller.releaseKeyEvents({key: RETURN_CHARCODE}); + Controller.releaseKeyEvents({key: ENTER_CHARCODE}); +} + +Controller.captureKeyEvents({key: RETURN_CHARCODE}); +Controller.captureKeyEvents({key: ENTER_CHARCODE}); +Controller.captureKeyEvents({key: SPACEBAR_CHARCODE}); +Controller.keyPressEvent.connect(keyPressEvent); +Controller.keyReleaseEvent.connect(keyReleaseEvent); +Script.scriptEnding.connect(scriptEnding); diff --git a/examples/virtualKeyboardTextEntityExample.js b/examples/virtualKeyboardTextEntityExample.js new file mode 100644 index 0000000000..830c50ab1e --- /dev/null +++ b/examples/virtualKeyboardTextEntityExample.js @@ -0,0 +1,177 @@ +// +// virtualKeyboardTextEntityExample.js +// examples +// +// Created by Thijs Wenker on 11/18/14. +// Copyright 2014 High Fidelity, Inc. +// +// Control a virtual keyboard using your favorite HMD. +// Usage: Enable VR-mode and go to First person mode, +// look at the key that you would like to press, and press the spacebar on your "REAL" keyboard. +// +// leased some code from newEditEntities.js for Text Entity example +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +Script.include("libraries/virtualKeyboard.js"); + +const SPAWN_DISTANCE = 1; +const DEFAULT_TEXT_DIMENSION_Z = 0.02; + +const TEXT_MARGIN_TOP = 0.15; +const TEXT_MARGIN_LEFT = 0.15; +const TEXT_MARGIN_RIGHT = 0.17; +const TEXT_MARGIN_BOTTOM = 0.17; + +var windowDimensions = Controller.getViewportDimensions(); +var cursor = null; +var keyboard = new Keyboard(); +var textFontSize = 9; +var text = null; +var textText = ""; +var textSizeMeasureOverlay = Overlays.addOverlay("text3d", {visible: false}); + +function appendChar(char) { + textText += char; + updateTextOverlay(); + Overlays.editOverlay(text, {text: textText}); +} + +function deleteChar() { + if (textText.length > 0) { + textText = textText.substring(0, textText.length - 1); + updateTextOverlay(); + } +} + +function updateTextOverlay() { + var textLines = textText.split("\n"); + var maxLineWidth = 0; + for (textLine in textLines) { + var lineWidth = Overlays.textSize(text, textLines[textLine]).width; + if (lineWidth > maxLineWidth) { + maxLineWidth = lineWidth; + } + } + var suggestedFontSize = (windowDimensions.x / maxLineWidth) * textFontSize * 0.90; + var maxFontSize = 190 / textLines.length; + textFontSize = (suggestedFontSize > maxFontSize) ? maxFontSize : suggestedFontSize; + var topMargin = (250 - (textFontSize * textLines.length)) / 4; + Overlays.editOverlay(text, {text: textText, font: {size: textFontSize}, topMargin: topMargin}); + var maxLineWidth = 0; + for (textLine in textLines) { + var lineWidth = Overlays.textSize(text, textLines[textLine]).width; + if (lineWidth > maxLineWidth) { + maxLineWidth = lineWidth; + } + } + Overlays.editOverlay(text, {leftMargin: (windowDimensions.x - maxLineWidth) / 2}); +} + +keyboard.onKeyPress = function(event) { + if (event.event == 'keypress') { + appendChar(event.char); + } else if (event.event == 'enter') { + appendChar("\n"); + } +}; + +keyboard.onKeyRelease = function(event) { + print("Key release event test"); + // you can cancel a key by releasing its focusing before releasing it + if (event.focus) { + if (event.event == 'delete') { + deleteChar(); + } else if (event.event == 'submit') { + print(textText); + + var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE)); + + var textLines = textText.split("\n"); + var maxLineWidth = 0; + for (textLine in textLines) { + var lineWidth = Overlays.textSize(textSizeMeasureOverlay, textLines[textLine]).width; + if (lineWidth > maxLineWidth) { + maxLineWidth = lineWidth; + } + } + var usernameLine = "--" + GlobalServices.myUsername; + var usernameWidth = Overlays.textSize(textSizeMeasureOverlay, usernameLine).width; + if (maxLineWidth < usernameWidth) { + maxLineWidth = usernameWidth; + } else { + var spaceableWidth = maxLineWidth - usernameWidth; + var spaceWidth = Overlays.textSize(textSizeMeasureOverlay, " ").width; + var numberOfSpaces = Math.floor(spaceableWidth / spaceWidth); + for (var i = 0; i < numberOfSpaces; i++) { + usernameLine = " " + usernameLine; + } + } + var dimension_x = maxLineWidth + TEXT_MARGIN_RIGHT + TEXT_MARGIN_LEFT; + if (position.x > 0 && position.y > 0 && position.z > 0) { + Entities.addEntity({ + type: "Text", + rotation: MyAvatar.orientation, + position: position, + dimensions: { x: dimension_x, y: (textLines.length + 1) * 0.14 + TEXT_MARGIN_TOP + TEXT_MARGIN_BOTTOM, z: DEFAULT_TEXT_DIMENSION_Z }, + backgroundColor: { red: 0, green: 0, blue: 0 }, + textColor: { red: 255, green: 255, blue: 255 }, + text: textText + "\n" + usernameLine + }); + } + textText = ""; + updateTextOverlay(); + } + } +}; + +keyboard.onFullyLoaded = function() { + print("Virtual-keyboard fully loaded."); + var dimensions = Controller.getViewportDimensions(); + text = Overlays.addOverlay("text", { + x: 0, + y: dimensions.y - keyboard.height() - 260, + width: dimensions.x, + height: 250, + backgroundColor: { red: 255, green: 255, blue: 255}, + color: { red: 0, green: 0, blue: 0}, + topMargin: 5, + leftMargin: 0, + font: {size: textFontSize}, + text: "", + alpha: 0.8 + }); + updateTextOverlay(); + // the cursor is being loaded after the keyboard, else it will be on the background of the keyboard + cursor = new Cursor(); + cursor.onUpdate = function(position) { + keyboard.setFocusPosition(position.x, position.y); + }; +}; + +function keyPressEvent(event) { + if (event.key === SPACEBAR_CHARCODE) { + keyboard.pressFocussedKey(); + } +} + +function keyReleaseEvent(event) { + if (event.key === SPACEBAR_CHARCODE) { + keyboard.releaseKeys(); + } +} + +function scriptEnding() { + keyboard.remove(); + cursor.remove(); + Overlays.deleteOverlay(text); + Overlays.deleteOverlay(textSizeMeasureOverlay); + Controller.releaseKeyEvents({key: SPACEBAR_CHARCODE}); +} + +Controller.captureKeyEvents({key: SPACEBAR_CHARCODE}); +Controller.keyPressEvent.connect(keyPressEvent); +Controller.keyReleaseEvent.connect(keyReleaseEvent); +Script.scriptEnding.connect(scriptEnding); From a8122e5a85e8927f93b12af9d82d38436a690d86 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Tue, 30 Dec 2014 23:30:48 +0100 Subject: [PATCH 04/18] virtualKeyboard.js - scale 50% virtualKeyboardLocation.js - toggle visibility with Enter/Return key virtualKeyboardTextEntityExample.js - attempt to fix character glyphs --- examples/libraries/virtualKeyboard.js | 112 ++++++++++++------- examples/virtualKeyboardLocation.js | 4 +- examples/virtualKeyboardTextEntityExample.js | 24 +--- 3 files changed, 78 insertions(+), 62 deletions(-) diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index ba9a30974e..9e5fd4accb 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -37,6 +37,8 @@ KEYBOARD_HEIGHT = 434.1; CURSOR_WIDTH = 33.9; CURSOR_HEIGHT = 33.9; +KEYBOARD_SCALE_MULTIPLIER = 0.50; + // VIEW_ANGLE can be adjusted to your likings, the smaller the faster movement. // Try setting it to 60 if it goes too fast for you. const VIEW_ANGLE = 40.0; @@ -127,6 +129,11 @@ KeyboardKey = (function(keyboard, keyProperties) { }); } }; + this.updateVisibility = function() { + for (var i = 0; i < tthis.bounds.length; i++) { + Overlays.editOverlay(tthis.overlays[i], {visible: tthis.keyboard.visible}); + } + }; this.rescale = function() { for (var i = 0; i < tthis.bounds.length; i++) { Overlays.editOverlay(tthis.overlays[i], { @@ -153,26 +160,26 @@ KeyboardKey = (function(keyboard, keyProperties) { for (var i = 0; i < this.bounds.length; i++) { var newOverlay = Overlays.cloneOverlay(this.keyboard.background); if (THREE_D_MODE) { - Overlays.editOverlay(newOverlay, { - position: { - x: MyAvatar.position.x,// + this.bounds[i][BOUND_X] * 0.01,// /*+ this.keyboard.getX()*/ + this.bounds[i][BOUND_X] * keyboard.scale, - y: MyAvatar.position.y,// - this.bounds[i][BOUND_Y] * 0.01,// /*+ this.keyboard.getY()*/ + this.bounds[i][BOUND_Y] * keyboard.scale, - z: MyAvatar.position.z - }, - width: this.bounds[i][BOUND_W] * keyboard.scale, - height: this.bounds[i][BOUND_H] * keyboard.scale, - subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]}, - alpha: 1 - }); + Overlays.editOverlay(newOverlay, { + position: { + x: MyAvatar.position.x,// + this.bounds[i][BOUND_X] * 0.01,// /*+ this.keyboard.getX()*/ + this.bounds[i][BOUND_X] * keyboard.scale, + y: MyAvatar.position.y,// - this.bounds[i][BOUND_Y] * 0.01,// /*+ this.keyboard.getY()*/ + this.bounds[i][BOUND_Y] * keyboard.scale, + z: MyAvatar.position.z + }, + width: this.bounds[i][BOUND_W] * keyboard.scale, + height: this.bounds[i][BOUND_H] * keyboard.scale, + subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]}, + alpha: 1 + }); } else { - Overlays.editOverlay(newOverlay, { - x: this.keyboard.getX() + this.bounds[i][BOUND_X] * keyboard.scale, - y: this.keyboard.getY() + this.bounds[i][BOUND_Y] * keyboard.scale, - width: this.bounds[i][BOUND_W] * keyboard.scale, - height: this.bounds[i][BOUND_H] * keyboard.scale, - subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]}, - alpha: 1 - }); + Overlays.editOverlay(newOverlay, { + x: this.keyboard.getX() + this.bounds[i][BOUND_X] * keyboard.scale, + y: this.keyboard.getY() + this.bounds[i][BOUND_Y] * keyboard.scale, + width: this.bounds[i][BOUND_W] * keyboard.scale, + height: this.bounds[i][BOUND_H] * keyboard.scale, + subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]}, + alpha: 1 + }); } this.overlays.push(newOverlay); } @@ -181,8 +188,9 @@ KeyboardKey = (function(keyboard, keyProperties) { Keyboard = (function() { var tthis = this; this.focussed_key = -1; - this.scale = windowDimensions.x / KEYBOARD_WIDTH; + this.scale = (windowDimensions.x / KEYBOARD_WIDTH) * KEYBOARD_SCALE_MULTIPLIER; this.shift = false; + this.visible = true; this.width = function() { return KEYBOARD_WIDTH * tthis.scale; }; @@ -196,30 +204,30 @@ Keyboard = (function() { return windowDimensions.y - this.height(); }; if (THREE_D_MODE) { - this.background = Overlays.addOverlay("billboard", { - scale: 1, - position: MyAvatar.position, - rotation: MyAvatar.rotation, - width: this.width(), - height: this.height(), - subImage: {width: KEYBOARD_WIDTH, height: KEYBOARD_HEIGHT, y: KEYBOARD_HEIGHT * KBD_BACKGROUND}, - isFacingAvatar: false, - url: KEYBOARD_URL, - alpha: 1 - }); + this.background = Overlays.addOverlay("billboard", { + scale: 1, + position: MyAvatar.position, + rotation: MyAvatar.rotation, + width: this.width(), + height: this.height(), + subImage: {width: KEYBOARD_WIDTH, height: KEYBOARD_HEIGHT, y: KEYBOARD_HEIGHT * KBD_BACKGROUND}, + isFacingAvatar: false, + url: KEYBOARD_URL, + alpha: 1 + }); } else { - this.background = Overlays.addOverlay("image", { - x: this.getX(), - y: this.getY(), - width: this.width(), - height: this.height(), - subImage: {width: KEYBOARD_WIDTH, height: KEYBOARD_HEIGHT, y: KEYBOARD_HEIGHT * KBD_BACKGROUND}, - imageURL: KEYBOARD_URL, - alpha: 1 - }); + this.background = Overlays.addOverlay("image", { + x: this.getX(), + y: this.getY(), + width: this.width(), + height: this.height(), + subImage: {width: KEYBOARD_WIDTH, height: KEYBOARD_HEIGHT, y: KEYBOARD_HEIGHT * KBD_BACKGROUND}, + imageURL: KEYBOARD_URL, + alpha: 1 + }); } this.rescale = function() { - this.scale = windowDimensions.x / KEYBOARD_WIDTH; + this.scale = (windowDimensions.x / KEYBOARD_WIDTH) * KEYBOARD_SCALE_MULTIPLIER; Overlays.editOverlay(tthis.background, { x: this.getX(), y: this.getY(), @@ -312,6 +320,28 @@ Keyboard = (function() { } }; + this.show = function() { + tthis.visible = true; + tthis.updateVisibility(); + }; + + this.hide = function() { + tthis.visible = false; + tthis.updateVisibility(); + }; + + this.toggle = function() { + tthis.visible = !tthis.visible; + tthis.updateVisibility(); + }; + + this.updateVisibility = function() { + Overlays.editOverlay(tthis.background, { visible: tthis.visible }); + for (var i = 0; i < this.keys.length; i++) { + this.keys[i].updateVisibility(); + } + }; + this.onKeyPress = null; this.onKeyRelease = null; this.onSubmit = null; diff --git a/examples/virtualKeyboardLocation.js b/examples/virtualKeyboardLocation.js index a5688c4c34..eae6c982b2 100644 --- a/examples/virtualKeyboardLocation.js +++ b/examples/virtualKeyboardLocation.js @@ -2,7 +2,7 @@ // virtualKeyboardTextEntityExample.js // examples // -// Created by Thijs Wenker on 11/18/14. +// Created by Thijs Wenker on 12/28/14. // Copyright 2014 High Fidelity, Inc. // // Control a virtual keyboard using your favorite HMD. @@ -156,7 +156,7 @@ function keyPressEvent(event) { if (event.key === SPACEBAR_CHARCODE) { keyboard.pressFocussedKey(); } else if (event.key === ENTER_CHARCODE || event.key === RETURN_CHARCODE) { - print("Enter pressed"); + keyboard.toggle(); } } diff --git a/examples/virtualKeyboardTextEntityExample.js b/examples/virtualKeyboardTextEntityExample.js index 830c50ab1e..2d46397831 100644 --- a/examples/virtualKeyboardTextEntityExample.js +++ b/examples/virtualKeyboardTextEntityExample.js @@ -2,7 +2,7 @@ // virtualKeyboardTextEntityExample.js // examples // -// Created by Thijs Wenker on 11/18/14. +// Created by Thijs Wenker on 12/28/14. // Copyright 2014 High Fidelity, Inc. // // Control a virtual keyboard using your favorite HMD. @@ -45,29 +45,15 @@ function deleteChar() { updateTextOverlay(); } } - + function updateTextOverlay() { var textLines = textText.split("\n"); - var maxLineWidth = 0; - for (textLine in textLines) { - var lineWidth = Overlays.textSize(text, textLines[textLine]).width; - if (lineWidth > maxLineWidth) { - maxLineWidth = lineWidth; - } - } - var suggestedFontSize = (windowDimensions.x / maxLineWidth) * textFontSize * 0.90; - var maxFontSize = 190 / textLines.length; + var suggestedFontSize = (windowDimensions.x / Overlays.textSize(text, textLines).width) * textFontSize * 0.90; + var maxFontSize = 170 / textLines.length; textFontSize = (suggestedFontSize > maxFontSize) ? maxFontSize : suggestedFontSize; var topMargin = (250 - (textFontSize * textLines.length)) / 4; Overlays.editOverlay(text, {text: textText, font: {size: textFontSize}, topMargin: topMargin}); - var maxLineWidth = 0; - for (textLine in textLines) { - var lineWidth = Overlays.textSize(text, textLines[textLine]).width; - if (lineWidth > maxLineWidth) { - maxLineWidth = lineWidth; - } - } - Overlays.editOverlay(text, {leftMargin: (windowDimensions.x - maxLineWidth) / 2}); + Overlays.editOverlay(text, {leftMargin: (windowDimensions.x - Overlays.textSize(text, textLines).width) / 2}); } keyboard.onKeyPress = function(event) { From 11d66ae83f81da354603f1f311092572a7d53688 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 31 Dec 2014 00:51:34 +0100 Subject: [PATCH 05/18] fixed text entity height --- examples/virtualKeyboardTextEntityExample.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/examples/virtualKeyboardTextEntityExample.js b/examples/virtualKeyboardTextEntityExample.js index 2d46397831..38beb08277 100644 --- a/examples/virtualKeyboardTextEntityExample.js +++ b/examples/virtualKeyboardTextEntityExample.js @@ -48,7 +48,7 @@ function deleteChar() { function updateTextOverlay() { var textLines = textText.split("\n"); - var suggestedFontSize = (windowDimensions.x / Overlays.textSize(text, textLines).width) * textFontSize * 0.90; + var suggestedFontSize = (windowDimensions.x / Overlays.textSize(text, textText).width) * textFontSize * 0.90; var maxFontSize = 170 / textLines.length; textFontSize = (suggestedFontSize > maxFontSize) ? maxFontSize : suggestedFontSize; var topMargin = (250 - (textFontSize * textLines.length)) / 4; @@ -76,13 +76,7 @@ keyboard.onKeyRelease = function(event) { var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE)); var textLines = textText.split("\n"); - var maxLineWidth = 0; - for (textLine in textLines) { - var lineWidth = Overlays.textSize(textSizeMeasureOverlay, textLines[textLine]).width; - if (lineWidth > maxLineWidth) { - maxLineWidth = lineWidth; - } - } + var maxLineWidth = Overlays.textSize(textSizeMeasureOverlay, textText).width; var usernameLine = "--" + GlobalServices.myUsername; var usernameWidth = Overlays.textSize(textSizeMeasureOverlay, usernameLine).width; if (maxLineWidth < usernameWidth) { @@ -104,7 +98,8 @@ keyboard.onKeyRelease = function(event) { dimensions: { x: dimension_x, y: (textLines.length + 1) * 0.14 + TEXT_MARGIN_TOP + TEXT_MARGIN_BOTTOM, z: DEFAULT_TEXT_DIMENSION_Z }, backgroundColor: { red: 0, green: 0, blue: 0 }, textColor: { red: 255, green: 255, blue: 255 }, - text: textText + "\n" + usernameLine + text: textText + "\n" + usernameLine, + lineHeight: 0.1 }); } textText = ""; From e856d302d38bee8d4ab9d421e78674842d757819 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 31 Dec 2014 01:37:51 +0100 Subject: [PATCH 06/18] - improved keyboard visibility setting - added posibility to teleport to location through hmd --- examples/libraries/virtualKeyboard.js | 19 ++++-- examples/virtualKeyboardLocation.js | 88 +++++---------------------- 2 files changed, 28 insertions(+), 79 deletions(-) diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index 9e5fd4accb..7e18ba1b5c 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -169,7 +169,8 @@ KeyboardKey = (function(keyboard, keyProperties) { width: this.bounds[i][BOUND_W] * keyboard.scale, height: this.bounds[i][BOUND_H] * keyboard.scale, subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]}, - alpha: 1 + alpha: 1, + visible: tthis.keyboard.visible }); } else { Overlays.editOverlay(newOverlay, { @@ -178,19 +179,20 @@ KeyboardKey = (function(keyboard, keyProperties) { width: this.bounds[i][BOUND_W] * keyboard.scale, height: this.bounds[i][BOUND_H] * keyboard.scale, subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]}, - alpha: 1 + alpha: 1, + visible: tthis.keyboard.visible }); } this.overlays.push(newOverlay); } }); -Keyboard = (function() { +Keyboard = (function(params) { var tthis = this; this.focussed_key = -1; this.scale = (windowDimensions.x / KEYBOARD_WIDTH) * KEYBOARD_SCALE_MULTIPLIER; this.shift = false; - this.visible = true; + this.visible = params.visible != undefined ? params.visible :true; this.width = function() { return KEYBOARD_WIDTH * tthis.scale; }; @@ -213,7 +215,8 @@ Keyboard = (function() { subImage: {width: KEYBOARD_WIDTH, height: KEYBOARD_HEIGHT, y: KEYBOARD_HEIGHT * KBD_BACKGROUND}, isFacingAvatar: false, url: KEYBOARD_URL, - alpha: 1 + alpha: 1, + visible: this.visible }); } else { this.background = Overlays.addOverlay("image", { @@ -223,7 +226,8 @@ Keyboard = (function() { height: this.height(), subImage: {width: KEYBOARD_WIDTH, height: KEYBOARD_HEIGHT, y: KEYBOARD_HEIGHT * KBD_BACKGROUND}, imageURL: KEYBOARD_URL, - alpha: 1 + alpha: 1, + visible: this.visible }); } this.rescale = function() { @@ -265,6 +269,9 @@ Keyboard = (function() { }; this.pressFocussedKey = function() { + if (!tthis.visible) { + return tthis; + } if (tthis.focussed_key != -1) { if (tthis.keys[tthis.focussed_key].event == 'shift') { tthis.toggleShift(); diff --git a/examples/virtualKeyboardLocation.js b/examples/virtualKeyboardLocation.js index eae6c982b2..2ff98c4c43 100644 --- a/examples/virtualKeyboardLocation.js +++ b/examples/virtualKeyboardLocation.js @@ -18,64 +18,40 @@ Script.include("libraries/virtualKeyboard.js"); -const SPAWN_DISTANCE = 1; -const DEFAULT_TEXT_DIMENSION_Z = 0.02; - -const TEXT_MARGIN_TOP = 0.15; -const TEXT_MARGIN_LEFT = 0.15; -const TEXT_MARGIN_RIGHT = 0.17; -const TEXT_MARGIN_BOTTOM = 0.17; - var windowDimensions = Controller.getViewportDimensions(); var cursor = null; -var keyboard = new Keyboard(); +var keyboard = new Keyboard({visible: false}); var textFontSize = 9; var text = null; -var textText = ""; -var textSizeMeasureOverlay = Overlays.addOverlay("text3d", {visible: false}); +var locationURL = ""; function appendChar(char) { - textText += char; + locationURL += char; updateTextOverlay(); - Overlays.editOverlay(text, {text: textText}); + Overlays.editOverlay(text, {text: locationURL}); } function deleteChar() { - if (textText.length > 0) { - textText = textText.substring(0, textText.length - 1); + if (locationURL.length > 0) { + locationURL = locationURL.substring(0, locationURL.length - 1); updateTextOverlay(); } } function updateTextOverlay() { - var textLines = textText.split("\n"); - var maxLineWidth = 0; - for (textLine in textLines) { - var lineWidth = Overlays.textSize(text, textLines[textLine]).width; - if (lineWidth > maxLineWidth) { - maxLineWidth = lineWidth; - } - } + var maxLineWidth = Overlays.textSize(text, locationURL).width; var suggestedFontSize = (windowDimensions.x / maxLineWidth) * textFontSize * 0.90; - var maxFontSize = 190 / textLines.length; + var maxFontSize = 140; textFontSize = (suggestedFontSize > maxFontSize) ? maxFontSize : suggestedFontSize; - var topMargin = (250 - (textFontSize * textLines.length)) / 4; - Overlays.editOverlay(text, {text: textText, font: {size: textFontSize}, topMargin: topMargin}); - var maxLineWidth = 0; - for (textLine in textLines) { - var lineWidth = Overlays.textSize(text, textLines[textLine]).width; - if (lineWidth > maxLineWidth) { - maxLineWidth = lineWidth; - } - } + var topMargin = (250 - textFontSize) / 4; + Overlays.editOverlay(text, {text: locationURL, font: {size: textFontSize}, topMargin: topMargin}); + maxLineWidth = Overlays.textSize(text, locationURL).width; Overlays.editOverlay(text, {leftMargin: (windowDimensions.x - maxLineWidth) / 2}); } keyboard.onKeyPress = function(event) { if (event.event == 'keypress') { appendChar(event.char); - } else if (event.event == 'enter') { - appendChar("\n"); } }; @@ -85,44 +61,10 @@ keyboard.onKeyRelease = function(event) { if (event.focus) { if (event.event == 'delete') { deleteChar(); - } else if (event.event == 'submit') { - print(textText); - - var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE)); - - var textLines = textText.split("\n"); - var maxLineWidth = 0; - for (textLine in textLines) { - var lineWidth = Overlays.textSize(textSizeMeasureOverlay, textLines[textLine]).width; - if (lineWidth > maxLineWidth) { - maxLineWidth = lineWidth; - } - } - var usernameLine = "--" + GlobalServices.myUsername; - var usernameWidth = Overlays.textSize(textSizeMeasureOverlay, usernameLine).width; - if (maxLineWidth < usernameWidth) { - maxLineWidth = usernameWidth; - } else { - var spaceableWidth = maxLineWidth - usernameWidth; - var spaceWidth = Overlays.textSize(textSizeMeasureOverlay, " ").width; - var numberOfSpaces = Math.floor(spaceableWidth / spaceWidth); - for (var i = 0; i < numberOfSpaces; i++) { - usernameLine = " " + usernameLine; - } - } - var dimension_x = maxLineWidth + TEXT_MARGIN_RIGHT + TEXT_MARGIN_LEFT; - if (position.x > 0 && position.y > 0 && position.z > 0) { - Entities.addEntity({ - type: "Text", - rotation: MyAvatar.orientation, - position: position, - dimensions: { x: dimension_x, y: (textLines.length + 1) * 0.14 + TEXT_MARGIN_TOP + TEXT_MARGIN_BOTTOM, z: DEFAULT_TEXT_DIMENSION_Z }, - backgroundColor: { red: 0, green: 0, blue: 0 }, - textColor: { red: 255, green: 255, blue: 255 }, - text: textText + "\n" + usernameLine - }); - } - textText = ""; + } else if (event.event == 'submit' || event.event == 'enter') { + print("going to hifi://" + locationURL); + location = "hifi://" + locationURL; + locationURL = ""; updateTextOverlay(); } } From 1365ecede309a2e774729aeba19a085dc2ca9b6e Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 31 Dec 2014 01:42:19 +0100 Subject: [PATCH 07/18] removed unused variables --- examples/libraries/virtualKeyboard.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index 7e18ba1b5c..98d8bdf561 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -44,9 +44,6 @@ KEYBOARD_SCALE_MULTIPLIER = 0.50; const VIEW_ANGLE = 40.0; const VIEW_ANGLE_BY_TWO = VIEW_ANGLE / 2; -const SPAWN_DISTANCE = 1; -const DEFAULT_TEXT_DIMENSION_Z = 0.02; - const BOUND_X = 0; const BOUND_Y = 1; const BOUND_W = 2; @@ -55,13 +52,7 @@ const BOUND_H = 3; KEY_STATE_LOWER = 0; KEY_STATE_UPPER = 1; -const TEXT_MARGIN_TOP = 0.15; -const TEXT_MARGIN_LEFT = 0.15; -const TEXT_MARGIN_RIGHT = 0.17; -const TEXT_MARGIN_BOTTOM = 0.17; - var windowDimensions = Controller.getViewportDimensions(); -var cursor = null; KeyboardKey = (function(keyboard, keyProperties) { var tthis = this; From a0e209276b81c42d51044b9f8bd5a9067075173c Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 31 Dec 2014 01:46:01 +0100 Subject: [PATCH 08/18] textbox visibility --- examples/virtualKeyboardLocation.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/virtualKeyboardLocation.js b/examples/virtualKeyboardLocation.js index 2ff98c4c43..c07877f2f1 100644 --- a/examples/virtualKeyboardLocation.js +++ b/examples/virtualKeyboardLocation.js @@ -84,7 +84,8 @@ keyboard.onFullyLoaded = function() { leftMargin: 0, font: {size: textFontSize}, text: "", - alpha: 0.8 + alpha: 0.8, + visible: keyboard.visible }); updateTextOverlay(); // the cursor is being loaded after the keyboard, else it will be on the background of the keyboard @@ -99,8 +100,8 @@ function keyPressEvent(event) { keyboard.pressFocussedKey(); } else if (event.key === ENTER_CHARCODE || event.key === RETURN_CHARCODE) { keyboard.toggle(); + Overlays.editOverlay(text, {visible: keyboard.visible}); } - } function keyReleaseEvent(event) { From 33a4f8030054cc3c63a0e6f6d8d954fdfadb022f Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 31 Dec 2014 01:49:01 +0100 Subject: [PATCH 09/18] hide keyboard after submit --- examples/virtualKeyboardLocation.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/virtualKeyboardLocation.js b/examples/virtualKeyboardLocation.js index c07877f2f1..839fa6e743 100644 --- a/examples/virtualKeyboardLocation.js +++ b/examples/virtualKeyboardLocation.js @@ -44,7 +44,7 @@ function updateTextOverlay() { var maxFontSize = 140; textFontSize = (suggestedFontSize > maxFontSize) ? maxFontSize : suggestedFontSize; var topMargin = (250 - textFontSize) / 4; - Overlays.editOverlay(text, {text: locationURL, font: {size: textFontSize}, topMargin: topMargin}); + Overlays.editOverlay(text, {text: locationURL, font: {size: textFontSize}, topMargin: topMargin, visible: keyboard.visible}); maxLineWidth = Overlays.textSize(text, locationURL).width; Overlays.editOverlay(text, {leftMargin: (windowDimensions.x - maxLineWidth) / 2}); } @@ -65,6 +65,7 @@ keyboard.onKeyRelease = function(event) { print("going to hifi://" + locationURL); location = "hifi://" + locationURL; locationURL = ""; + keyboard.hide(); updateTextOverlay(); } } From 398e88107cbe9a391f05f46564c4e1f6137d464e Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 31 Dec 2014 01:53:10 +0100 Subject: [PATCH 10/18] renamed virtualKeyboardLocation.js to goTo.js as discussed --- examples/{virtualKeyboardLocation.js => goTo.js} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename examples/{virtualKeyboardLocation.js => goTo.js} (99%) diff --git a/examples/virtualKeyboardLocation.js b/examples/goTo.js similarity index 99% rename from examples/virtualKeyboardLocation.js rename to examples/goTo.js index 839fa6e743..13114024ed 100644 --- a/examples/virtualKeyboardLocation.js +++ b/examples/goTo.js @@ -1,5 +1,5 @@ // -// virtualKeyboardTextEntityExample.js +// goTo.js // examples // // Created by Thijs Wenker on 12/28/14. From c73b496cacaafb995762a1d72fae50b3b3dcb62a Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 31 Dec 2014 02:25:55 +0100 Subject: [PATCH 11/18] press X button with gamepad --- examples/goTo.js | 15 +++++++++++++++ examples/libraries/virtualKeyboard.js | 3 +++ examples/virtualKeyboardTextEntityExample.js | 15 +++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/examples/goTo.js b/examples/goTo.js index 13114024ed..ef93bc9268 100644 --- a/examples/goTo.js +++ b/examples/goTo.js @@ -121,6 +121,21 @@ function scriptEnding() { Controller.releaseKeyEvents({key: ENTER_CHARCODE}); } +function reportButtonValue(button, newValue, oldValue) { + if (button == Joysticks.BUTTON_FACE_LEFT) { + if (newValue) { + keyboard.pressFocussedKey(); + } else { + keyboard.releaseKeys(); + } + } +} + +function addJoystick(gamepad) { + gamepad.buttonStateChanged.connect(reportButtonValue); +} + +Joysticks.joystickAdded.connect(addJoystick); Controller.captureKeyEvents({key: RETURN_CHARCODE}); Controller.captureKeyEvents({key: ENTER_CHARCODE}); Controller.captureKeyEvents({key: SPACEBAR_CHARCODE}); diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index 98d8bdf561..492b49a4aa 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -179,6 +179,9 @@ KeyboardKey = (function(keyboard, keyProperties) { }); Keyboard = (function(params) { + if (params === undefined) { + params = {}; + } var tthis = this; this.focussed_key = -1; this.scale = (windowDimensions.x / KEYBOARD_WIDTH) * KEYBOARD_SCALE_MULTIPLIER; diff --git a/examples/virtualKeyboardTextEntityExample.js b/examples/virtualKeyboardTextEntityExample.js index 38beb08277..a6960d209a 100644 --- a/examples/virtualKeyboardTextEntityExample.js +++ b/examples/virtualKeyboardTextEntityExample.js @@ -152,6 +152,21 @@ function scriptEnding() { Controller.releaseKeyEvents({key: SPACEBAR_CHARCODE}); } +function reportButtonValue(button, newValue, oldValue) { + if (button == Joysticks.BUTTON_FACE_LEFT) { + if (newValue) { + keyboard.pressFocussedKey(); + } else { + keyboard.releaseKeys(); + } + } +} + +function addJoystick(gamepad) { + gamepad.buttonStateChanged.connect(reportButtonValue); +} + +Joysticks.joystickAdded.connect(addJoystick); Controller.captureKeyEvents({key: SPACEBAR_CHARCODE}); Controller.keyPressEvent.connect(keyPressEvent); Controller.keyReleaseEvent.connect(keyReleaseEvent); From 19eec811731f5fd7c8e5ccacf8edeb29a4d0d0b0 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 7 Jan 2015 20:46:39 +0100 Subject: [PATCH 12/18] moved goTo.js and virtualKeyboardTextEntityExample.js to the right category folder --- examples/{ => controllers/oculus}/goTo.js | 0 .../{ => controllers/oculus}/virtualKeyboardTextEntityExample.js | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename examples/{ => controllers/oculus}/goTo.js (100%) rename examples/{ => controllers/oculus}/virtualKeyboardTextEntityExample.js (100%) diff --git a/examples/goTo.js b/examples/controllers/oculus/goTo.js similarity index 100% rename from examples/goTo.js rename to examples/controllers/oculus/goTo.js diff --git a/examples/virtualKeyboardTextEntityExample.js b/examples/controllers/oculus/virtualKeyboardTextEntityExample.js similarity index 100% rename from examples/virtualKeyboardTextEntityExample.js rename to examples/controllers/oculus/virtualKeyboardTextEntityExample.js From ff6cae738b5ba26d43b25cb58c54b8c5291fb783 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 7 Jan 2015 20:47:59 +0100 Subject: [PATCH 13/18] fixed library paths --- examples/controllers/oculus/goTo.js | 2 +- examples/controllers/oculus/virtualKeyboardTextEntityExample.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/controllers/oculus/goTo.js b/examples/controllers/oculus/goTo.js index ef93bc9268..50d44d0a28 100644 --- a/examples/controllers/oculus/goTo.js +++ b/examples/controllers/oculus/goTo.js @@ -16,7 +16,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/virtualKeyboard.js"); +Script.include("../../libraries/virtualKeyboard.js"); var windowDimensions = Controller.getViewportDimensions(); var cursor = null; diff --git a/examples/controllers/oculus/virtualKeyboardTextEntityExample.js b/examples/controllers/oculus/virtualKeyboardTextEntityExample.js index a6960d209a..9c5ba6dfe5 100644 --- a/examples/controllers/oculus/virtualKeyboardTextEntityExample.js +++ b/examples/controllers/oculus/virtualKeyboardTextEntityExample.js @@ -15,7 +15,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/virtualKeyboard.js"); +Script.include("../../libraries/virtualKeyboard.js"); const SPAWN_DISTANCE = 1; const DEFAULT_TEXT_DIMENSION_Z = 0.02; From 4fdcdf095c9af35f2f77e22340eb771dbe440860 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 7 Jan 2015 21:27:14 +0100 Subject: [PATCH 14/18] trying to fix url --- examples/libraries/virtualKeyboard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index 492b49a4aa..aab590e63f 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -13,7 +13,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/globals.js"); +Script.include("globals.js"); // experimental 3dmode THREE_D_MODE = false; From 6771252eab69c000631d82c48ff02a603eb0bb76 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 7 Jan 2015 21:34:34 +0100 Subject: [PATCH 15/18] seems like you need to offset the include from the script that uses it --- examples/libraries/virtualKeyboard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index aab590e63f..893ed929d6 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -13,7 +13,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("globals.js"); +Script.include("../../libraries/globals.js"); // experimental 3dmode THREE_D_MODE = false; From 527576eebad6a0ec63b1b2bd081afa72d32ae6c1 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 7 Jan 2015 21:38:31 +0100 Subject: [PATCH 16/18] or not... --- examples/libraries/virtualKeyboard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index 893ed929d6..aab590e63f 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -13,7 +13,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("../../libraries/globals.js"); +Script.include("globals.js"); // experimental 3dmode THREE_D_MODE = false; From 40b4a17ba803de674993a1777b27b93564776f35 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 7 Jan 2015 23:14:31 +0100 Subject: [PATCH 17/18] include globals.js from runnable scripts for now. --- examples/controllers/oculus/goTo.js | 1 + examples/controllers/oculus/virtualKeyboardTextEntityExample.js | 1 + examples/libraries/virtualKeyboard.js | 2 -- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/controllers/oculus/goTo.js b/examples/controllers/oculus/goTo.js index 50d44d0a28..3423716698 100644 --- a/examples/controllers/oculus/goTo.js +++ b/examples/controllers/oculus/goTo.js @@ -16,6 +16,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +Script.include("../../libraries/globals.js"); Script.include("../../libraries/virtualKeyboard.js"); var windowDimensions = Controller.getViewportDimensions(); diff --git a/examples/controllers/oculus/virtualKeyboardTextEntityExample.js b/examples/controllers/oculus/virtualKeyboardTextEntityExample.js index 9c5ba6dfe5..a5f5b2bf95 100644 --- a/examples/controllers/oculus/virtualKeyboardTextEntityExample.js +++ b/examples/controllers/oculus/virtualKeyboardTextEntityExample.js @@ -15,6 +15,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +Script.include("../../libraries/globals.js"); Script.include("../../libraries/virtualKeyboard.js"); const SPAWN_DISTANCE = 1; diff --git a/examples/libraries/virtualKeyboard.js b/examples/libraries/virtualKeyboard.js index aab590e63f..854ca58d1d 100644 --- a/examples/libraries/virtualKeyboard.js +++ b/examples/libraries/virtualKeyboard.js @@ -13,8 +13,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("globals.js"); - // experimental 3dmode THREE_D_MODE = false; From c791422fabf1ce844434242967b7e5ef3ab85eef Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Thu, 8 Jan 2015 02:22:08 +0100 Subject: [PATCH 18/18] make gamepads and A (select key) and B (delete character) button function --- examples/controllers/oculus/goTo.js | 9 ++++++++- .../oculus/virtualKeyboardTextEntityExample.js | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/examples/controllers/oculus/goTo.js b/examples/controllers/oculus/goTo.js index 3423716698..ba1ee1eb81 100644 --- a/examples/controllers/oculus/goTo.js +++ b/examples/controllers/oculus/goTo.js @@ -123,12 +123,14 @@ function scriptEnding() { } function reportButtonValue(button, newValue, oldValue) { - if (button == Joysticks.BUTTON_FACE_LEFT) { + if (button == Joysticks.BUTTON_FACE_BOTTOM) { if (newValue) { keyboard.pressFocussedKey(); } else { keyboard.releaseKeys(); } + } else if (button == Joysticks.BUTTON_FACE_RIGHT && newValue) { + deleteChar(); } } @@ -136,6 +138,11 @@ function addJoystick(gamepad) { gamepad.buttonStateChanged.connect(reportButtonValue); } +var allJoysticks = Joysticks.getAllJoysticks(); +for (var i = 0; i < allJoysticks.length; i++) { + addJoystick(allJoysticks[i]); +} + Joysticks.joystickAdded.connect(addJoystick); Controller.captureKeyEvents({key: RETURN_CHARCODE}); Controller.captureKeyEvents({key: ENTER_CHARCODE}); diff --git a/examples/controllers/oculus/virtualKeyboardTextEntityExample.js b/examples/controllers/oculus/virtualKeyboardTextEntityExample.js index a5f5b2bf95..794b659bcb 100644 --- a/examples/controllers/oculus/virtualKeyboardTextEntityExample.js +++ b/examples/controllers/oculus/virtualKeyboardTextEntityExample.js @@ -154,12 +154,14 @@ function scriptEnding() { } function reportButtonValue(button, newValue, oldValue) { - if (button == Joysticks.BUTTON_FACE_LEFT) { + if (button == Joysticks.BUTTON_FACE_BOTTOM) { if (newValue) { keyboard.pressFocussedKey(); } else { keyboard.releaseKeys(); } + } else if (button == Joysticks.BUTTON_FACE_RIGHT && newValue) { + deleteChar(); } } @@ -167,6 +169,11 @@ function addJoystick(gamepad) { gamepad.buttonStateChanged.connect(reportButtonValue); } +var allJoysticks = Joysticks.getAllJoysticks(); +for (var i = 0; i < allJoysticks.length; i++) { + addJoystick(allJoysticks[i]); +} + Joysticks.joystickAdded.connect(addJoystick); Controller.captureKeyEvents({key: SPACEBAR_CHARCODE}); Controller.keyPressEvent.connect(keyPressEvent);