From 1d335c1218f085f9934458fe6e11335fce03b962 Mon Sep 17 00:00:00 2001 From: Adrianl3d Date: Wed, 29 Oct 2014 23:39:44 +1000 Subject: [PATCH] Added textInputOverlayExample.js Displays a text overlay and captures keystrokes which appear on the overlay. Demonstrates keystroke events, mouse click events, clickable text overlay and image overlay buttons --- examples/textInputOverlayExample.js | 206 ++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 examples/textInputOverlayExample.js diff --git a/examples/textInputOverlayExample.js b/examples/textInputOverlayExample.js new file mode 100644 index 0000000000..7f470b16f7 --- /dev/null +++ b/examples/textInputOverlayExample.js @@ -0,0 +1,206 @@ +// +// textInputOverlayExample.js + +// Captures keystrokes and generates a string which is displayed as a text Overlay +// demonstrates keystroke events, mouse click events and overlay buttons. +// Created by Adrian McCarlie 7 October 2014 +// +// Copyright 2014 High Fidelity, Inc. +// +// +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +var locationX = 500; // on screen location X +var locationY = 175; // on screen location Y +var width = 600; //width of input window +var height = 100; // height of input window +var topMargin = 20; +var leftMargin = 10; +var textColor = { red: 228, green: 228, blue: 228}; // text color +var backColor = { red: 170, green: 200, blue: 255}; // default background color +var readyColor = { red: 2, green: 255, blue: 2}; // green background and button +var clickedColor = { red: 255, green: 220, blue: 20}; //amber background and button +var backgroundAlpha = 0.6; +var fontSize = 12; +var writing ="Click here and type input, then click green button to submit.\n \n \n \n \n \n \n \n Click red button to close,"; +var buttonLocationX = locationX - 50; // buttons locked relative to input window +var clickedText = false; +var clickedButton = false; +var cursor = "|"; +// add more characters to the string if required +var keyString = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ + ~!@#$%^&*()_+`1234567890-={}|[]\\:\";'<>?,./"; //permitted characters + + +// This will create a text overlay that displays what you type +var inputWindow = Overlays.addOverlay("text", { + x: locationX, + y: locationY, + width: width, + height: height, + color: textColor, + backgroundColor: backColor, + alpha: backgroundAlpha, + topMargin: topMargin, + leftMargin: leftMargin, + font: {size: fontSize}, + text: writing, + visible: true + }); +// This will create an image overlay of a button. +var button1 = Overlays.addOverlay("image", { // green button + x: buttonLocationX, + y: locationY + 10, + width: 40, + height: 35, + subImage: { x: 0, y: 0, width: 39, height: 35 }, + imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/thumb.png", + color: readyColor, + visible: true + }); +// This will create an image overlay of another button. +var button2 = Overlays.addOverlay("image", { // red button + x: buttonLocationX, + y: locationY + 60, + width: 40, + height: 35, + subImage: { x: 0, y: 0, width: 39, height: 35 }, + imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/thumb.png", + color: { red: 250, green: 2, blue: 2}, + visible: true, + }); +// When our script shuts down, we should clean up all of our overlays +function scriptEnding() { + Overlays.deleteOverlay(inputWindow); + Overlays.deleteOverlay(button1); + Overlays.deleteOverlay(button2); + //Return control of keys to default on script ending + for(var i=0; i