mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
tabs to spaces
This commit is contained in:
parent
b4f18f15d7
commit
716fca6ae7
2 changed files with 248 additions and 250 deletions
|
@ -15,11 +15,11 @@ Script.include("libraries/toolBars.js");
|
|||
var recordingFile = "recording.rec";
|
||||
|
||||
function setPlayerOptions() {
|
||||
MyAvatar.setPlayFromCurrentLocation(true);
|
||||
MyAvatar.setPlayerUseDisplayName(false);
|
||||
MyAvatar.setPlayerUseAttachments(false);
|
||||
MyAvatar.setPlayerUseHeadModel(false);
|
||||
MyAvatar.setPlayerUseSkeletonModel(false);
|
||||
MyAvatar.setPlayFromCurrentLocation(true);
|
||||
MyAvatar.setPlayerUseDisplayName(false);
|
||||
MyAvatar.setPlayerUseAttachments(false);
|
||||
MyAvatar.setPlayerUseHeadModel(false);
|
||||
MyAvatar.setPlayerUseSkeletonModel(false);
|
||||
}
|
||||
|
||||
var windowDimensions = Controller.getViewportDimensions();
|
||||
|
@ -47,118 +47,118 @@ setupTimer();
|
|||
var watchStop = false;
|
||||
|
||||
function setupToolBar() {
|
||||
if (toolBar != null) {
|
||||
print("Multiple calls to Recorder.js:setupToolBar()");
|
||||
return;
|
||||
}
|
||||
if (toolBar != null) {
|
||||
print("Multiple calls to Recorder.js:setupToolBar()");
|
||||
return;
|
||||
}
|
||||
Tool.IMAGE_HEIGHT /= 2;
|
||||
Tool.IMAGE_WIDTH /= 2;
|
||||
|
||||
toolBar = new ToolBar(0, 0, ToolBar.HORIZONTAL);
|
||||
toolBar = new ToolBar(0, 0, ToolBar.HORIZONTAL);
|
||||
|
||||
toolBar.setBack(COLOR_TOOL_BAR, ALPHA_OFF);
|
||||
|
||||
recordIcon = toolBar.addTool({
|
||||
imageURL: TOOL_ICON_URL + "recording-record.svg",
|
||||
subImage: { x: 0, y: 0, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT },
|
||||
x: 0, y: 0,
|
||||
width: Tool.IMAGE_WIDTH,
|
||||
height: Tool.IMAGE_HEIGHT,
|
||||
alpha: MyAvatar.isPlaying() ? ALPHA_OFF : ALPHA_ON,
|
||||
visible: true
|
||||
}, true, !MyAvatar.isRecording());
|
||||
imageURL: TOOL_ICON_URL + "recording-record.svg",
|
||||
subImage: { x: 0, y: 0, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT },
|
||||
x: 0, y: 0,
|
||||
width: Tool.IMAGE_WIDTH,
|
||||
height: Tool.IMAGE_HEIGHT,
|
||||
alpha: MyAvatar.isPlaying() ? ALPHA_OFF : ALPHA_ON,
|
||||
visible: true
|
||||
}, true, !MyAvatar.isRecording());
|
||||
|
||||
var playLoopWidthFactor = 1.65;
|
||||
playIcon = toolBar.addTool({
|
||||
imageURL: TOOL_ICON_URL + "play-pause.svg",
|
||||
width: playLoopWidthFactor * Tool.IMAGE_WIDTH,
|
||||
height: Tool.IMAGE_HEIGHT,
|
||||
alpha: (MyAvatar.isRecording() || MyAvatar.playerLength() === 0) ? ALPHA_OFF : ALPHA_ON,
|
||||
visible: true
|
||||
}, false);
|
||||
imageURL: TOOL_ICON_URL + "play-pause.svg",
|
||||
width: playLoopWidthFactor * Tool.IMAGE_WIDTH,
|
||||
height: Tool.IMAGE_HEIGHT,
|
||||
alpha: (MyAvatar.isRecording() || MyAvatar.playerLength() === 0) ? ALPHA_OFF : ALPHA_ON,
|
||||
visible: true
|
||||
}, false);
|
||||
|
||||
playLoopIcon = toolBar.addTool({
|
||||
imageURL: TOOL_ICON_URL + "play-and-loop.svg",
|
||||
subImage: { x: 0, y: 0, width: playLoopWidthFactor * Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT },
|
||||
width: playLoopWidthFactor * Tool.IMAGE_WIDTH,
|
||||
height: Tool.IMAGE_HEIGHT,
|
||||
alpha: (MyAvatar.isRecording() || MyAvatar.playerLength() === 0) ? ALPHA_OFF : ALPHA_ON,
|
||||
visible: true
|
||||
}, false);
|
||||
imageURL: TOOL_ICON_URL + "play-and-loop.svg",
|
||||
subImage: { x: 0, y: 0, width: playLoopWidthFactor * Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT },
|
||||
width: playLoopWidthFactor * Tool.IMAGE_WIDTH,
|
||||
height: Tool.IMAGE_HEIGHT,
|
||||
alpha: (MyAvatar.isRecording() || MyAvatar.playerLength() === 0) ? ALPHA_OFF : ALPHA_ON,
|
||||
visible: true
|
||||
}, false);
|
||||
|
||||
timerOffset = toolBar.width;
|
||||
spacing = toolBar.addSpacing(0);
|
||||
|
||||
saveIcon = toolBar.addTool({
|
||||
imageURL: TOOL_ICON_URL + "recording-save.svg",
|
||||
width: Tool.IMAGE_WIDTH,
|
||||
height: Tool.IMAGE_HEIGHT,
|
||||
alpha: (MyAvatar.isRecording() || MyAvatar.isPlaying() || MyAvatar.playerLength() === 0) ? ALPHA_OFF : ALPHA_ON,
|
||||
visible: true
|
||||
}, false);
|
||||
imageURL: TOOL_ICON_URL + "recording-save.svg",
|
||||
width: Tool.IMAGE_WIDTH,
|
||||
height: Tool.IMAGE_HEIGHT,
|
||||
alpha: (MyAvatar.isRecording() || MyAvatar.isPlaying() || MyAvatar.playerLength() === 0) ? ALPHA_OFF : ALPHA_ON,
|
||||
visible: true
|
||||
}, false);
|
||||
|
||||
loadIcon = toolBar.addTool({
|
||||
imageURL: TOOL_ICON_URL + "recording-upload.svg",
|
||||
width: Tool.IMAGE_WIDTH,
|
||||
height: Tool.IMAGE_HEIGHT,
|
||||
alpha: (MyAvatar.isRecording() || MyAvatar.isPlaying()) ? ALPHA_OFF : ALPHA_ON,
|
||||
visible: true
|
||||
}, false);
|
||||
imageURL: TOOL_ICON_URL + "recording-upload.svg",
|
||||
width: Tool.IMAGE_WIDTH,
|
||||
height: Tool.IMAGE_HEIGHT,
|
||||
alpha: (MyAvatar.isRecording() || MyAvatar.isPlaying()) ? ALPHA_OFF : ALPHA_ON,
|
||||
visible: true
|
||||
}, false);
|
||||
}
|
||||
|
||||
function setupTimer() {
|
||||
timer = Overlays.addOverlay("text", {
|
||||
font: { size: 15 },
|
||||
text: (0.00).toFixed(3),
|
||||
backgroundColor: COLOR_OFF,
|
||||
x: 0, y: 0,
|
||||
width: 0,
|
||||
height: 0,
|
||||
alpha: 1.0,
|
||||
timer = Overlays.addOverlay("text", {
|
||||
font: { size: 15 },
|
||||
text: (0.00).toFixed(3),
|
||||
backgroundColor: COLOR_OFF,
|
||||
x: 0, y: 0,
|
||||
width: 0,
|
||||
height: 0,
|
||||
alpha: 1.0,
|
||||
backgroundAlpha: 1.0,
|
||||
visible: true
|
||||
});
|
||||
visible: true
|
||||
});
|
||||
|
||||
slider = { x: 0, y: 0,
|
||||
w: 200, h: 20,
|
||||
pos: 0.0, // 0.0 <= pos <= 1.0
|
||||
w: 200, h: 20,
|
||||
pos: 0.0, // 0.0 <= pos <= 1.0
|
||||
};
|
||||
slider.background = Overlays.addOverlay("text", {
|
||||
text: "",
|
||||
backgroundColor: { red: 128, green: 128, blue: 128 },
|
||||
x: slider.x, y: slider.y,
|
||||
width: slider.w,
|
||||
height: slider.h,
|
||||
alpha: 1.0,
|
||||
backgroundAlpha: 1.0,
|
||||
visible: true
|
||||
});
|
||||
text: "",
|
||||
backgroundColor: { red: 128, green: 128, blue: 128 },
|
||||
x: slider.x, y: slider.y,
|
||||
width: slider.w,
|
||||
height: slider.h,
|
||||
alpha: 1.0,
|
||||
backgroundAlpha: 1.0,
|
||||
visible: true
|
||||
});
|
||||
slider.foreground = Overlays.addOverlay("text", {
|
||||
text: "",
|
||||
backgroundColor: { red: 200, green: 200, blue: 200 },
|
||||
x: slider.x, y: slider.y,
|
||||
width: slider.pos * slider.w,
|
||||
height: slider.h,
|
||||
alpha: 1.0,
|
||||
backgroundAlpha: 1.0,
|
||||
visible: true
|
||||
});
|
||||
text: "",
|
||||
backgroundColor: { red: 200, green: 200, blue: 200 },
|
||||
x: slider.x, y: slider.y,
|
||||
width: slider.pos * slider.w,
|
||||
height: slider.h,
|
||||
alpha: 1.0,
|
||||
backgroundAlpha: 1.0,
|
||||
visible: true
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function updateTimer() {
|
||||
var text = "";
|
||||
if (MyAvatar.isRecording()) {
|
||||
text = formatTime(MyAvatar.recorderElapsed());
|
||||
var text = "";
|
||||
if (MyAvatar.isRecording()) {
|
||||
text = formatTime(MyAvatar.recorderElapsed());
|
||||
|
||||
} else {
|
||||
text = formatTime(MyAvatar.playerElapsed()) + " / " +
|
||||
formatTime(MyAvatar.playerLength());
|
||||
}
|
||||
} else {
|
||||
text = formatTime(MyAvatar.playerElapsed()) + " / " +
|
||||
formatTime(MyAvatar.playerLength());
|
||||
}
|
||||
|
||||
Overlays.editOverlay(timer, {
|
||||
text: text
|
||||
})
|
||||
Overlays.editOverlay(timer, {
|
||||
text: text
|
||||
})
|
||||
toolBar.changeSpacing(text.length * 8 + ((MyAvatar.isRecording()) ? 15 : 0), spacing);
|
||||
|
||||
if (MyAvatar.isRecording()) {
|
||||
|
@ -168,57 +168,56 @@ function updateTimer() {
|
|||
}
|
||||
|
||||
Overlays.editOverlay(slider.foreground, {
|
||||
width: slider.pos * slider.w
|
||||
});
|
||||
width: slider.pos * slider.w
|
||||
});
|
||||
}
|
||||
|
||||
function formatTime(time) {
|
||||
var MIN_PER_HOUR = 60;
|
||||
var SEC_PER_MIN = 60;
|
||||
var MSEC_PER_SEC = 1000;
|
||||
var MIN_PER_HOUR = 60;
|
||||
var SEC_PER_MIN = 60;
|
||||
var MSEC_PER_SEC = 1000;
|
||||
|
||||
var hours = Math.floor(time / (MSEC_PER_SEC * SEC_PER_MIN * MIN_PER_HOUR));
|
||||
time -= hours * (MSEC_PER_SEC * SEC_PER_MIN * MIN_PER_HOUR);
|
||||
var hours = Math.floor(time / (MSEC_PER_SEC * SEC_PER_MIN * MIN_PER_HOUR));
|
||||
time -= hours * (MSEC_PER_SEC * SEC_PER_MIN * MIN_PER_HOUR);
|
||||
|
||||
var minutes = Math.floor(time / (MSEC_PER_SEC * SEC_PER_MIN));
|
||||
time -= minutes * (MSEC_PER_SEC * SEC_PER_MIN);
|
||||
var minutes = Math.floor(time / (MSEC_PER_SEC * SEC_PER_MIN));
|
||||
time -= minutes * (MSEC_PER_SEC * SEC_PER_MIN);
|
||||
|
||||
var seconds = Math.floor(time / MSEC_PER_SEC);
|
||||
seconds = time / MSEC_PER_SEC;
|
||||
var seconds = Math.floor(time / MSEC_PER_SEC);
|
||||
seconds = time / MSEC_PER_SEC;
|
||||
|
||||
var text = "";
|
||||
text += (hours > 0) ? hours + ":" :
|
||||
"";
|
||||
text += (minutes > 0) ? ((minutes < 10 && text != "") ? "0" : "") + minutes + ":" :
|
||||
"";
|
||||
text += ((seconds < 10 && text != "") ? "0" : "") + seconds.toFixed(3);
|
||||
return text;
|
||||
var text = "";
|
||||
text += (hours > 0) ? hours + ":" :
|
||||
"";
|
||||
text += (minutes > 0) ? ((minutes < 10 && text != "") ? "0" : "") + minutes + ":" :
|
||||
"";
|
||||
text += ((seconds < 10 && text != "") ? "0" : "") + seconds.toFixed(3);
|
||||
return text;
|
||||
}
|
||||
|
||||
function moveUI() {
|
||||
var relative = { x: 70, y: 40 };
|
||||
toolBar.move(relative.x,
|
||||
windowDimensions.y - relative.y);
|
||||
Overlays.editOverlay(timer, {
|
||||
x: relative.x + timerOffset - ToolBar.SPACING,
|
||||
y: windowDimensions.y - relative.y - ToolBar.SPACING
|
||||
});
|
||||
var relative = { x: 70, y: 40 };
|
||||
toolBar.move(relative.x, windowDimensions.y - relative.y);
|
||||
Overlays.editOverlay(timer, {
|
||||
x: relative.x + timerOffset - ToolBar.SPACING,
|
||||
y: windowDimensions.y - relative.y - ToolBar.SPACING
|
||||
});
|
||||
|
||||
slider.x = relative.x - ToolBar.SPACING;
|
||||
slider.y = windowDimensions.y - relative.y - slider.h - ToolBar.SPACING;
|
||||
|
||||
Overlays.editOverlay(slider.background, {
|
||||
x: slider.x,
|
||||
y: slider.y,
|
||||
});
|
||||
x: slider.x,
|
||||
y: slider.y,
|
||||
});
|
||||
Overlays.editOverlay(slider.foreground, {
|
||||
x: slider.x,
|
||||
y: slider.y,
|
||||
});
|
||||
x: slider.x,
|
||||
y: slider.y,
|
||||
});
|
||||
}
|
||||
|
||||
function mousePressEvent(event) {
|
||||
clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });
|
||||
clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });
|
||||
|
||||
if (recordIcon === toolBar.clicked(clickedOverlay, false) && !MyAvatar.isPlaying()) {
|
||||
if (!MyAvatar.isRecording()) {
|
||||
|
@ -270,7 +269,7 @@ function mousePressEvent(event) {
|
|||
if (!MyAvatar.isRecording() && !MyAvatar.isPlaying() && MyAvatar.playerLength() != 0) {
|
||||
recordingFile = Window.save("Save recording to file", ".", "Recordings (*.hfr)");
|
||||
if (!(recordingFile === "null" || recordingFile === null || recordingFile === "")) {
|
||||
MyAvatar.saveRecording(recordingFile);
|
||||
MyAvatar.saveRecording(recordingFile);
|
||||
}
|
||||
}
|
||||
} else if (loadIcon === toolBar.clicked(clickedOverlay)) {
|
||||
|
@ -286,8 +285,8 @@ function mousePressEvent(event) {
|
|||
}
|
||||
}
|
||||
} else if (MyAvatar.playerLength() > 0 &&
|
||||
slider.x < event.x && event.x < slider.x + slider.w &&
|
||||
slider.y < event.y && event.y < slider.y + slider.h) {
|
||||
slider.x < event.x && event.x < slider.x + slider.w &&
|
||||
slider.y < event.y && event.y < slider.y + slider.h) {
|
||||
isSliding = true;
|
||||
slider.pos = (event.x - slider.x) / slider.w;
|
||||
MyAvatar.setPlayerTime(slider.pos * MyAvatar.playerLength());
|
||||
|
@ -311,14 +310,13 @@ function mouseReleaseEvent(event) {
|
|||
}
|
||||
|
||||
function update() {
|
||||
var newDimensions = Controller.getViewportDimensions();
|
||||
if (windowDimensions.x != newDimensions.x ||
|
||||
windowDimensions.y != newDimensions.y) {
|
||||
windowDimensions = newDimensions;
|
||||
moveUI();
|
||||
}
|
||||
var newDimensions = Controller.getViewportDimensions();
|
||||
if (windowDimensions.x != newDimensions.x || windowDimensions.y != newDimensions.y) {
|
||||
windowDimensions = newDimensions;
|
||||
moveUI();
|
||||
}
|
||||
|
||||
updateTimer();
|
||||
updateTimer();
|
||||
|
||||
if (watchStop && !MyAvatar.isPlaying()) {
|
||||
watchStop = false;
|
||||
|
@ -329,12 +327,12 @@ function update() {
|
|||
}
|
||||
|
||||
function scriptEnding() {
|
||||
if (MyAvatar.isRecording()) {
|
||||
MyAvatar.stopRecording();
|
||||
}
|
||||
if (MyAvatar.isPlaying()) {
|
||||
MyAvatar.stopPlaying();
|
||||
}
|
||||
if (MyAvatar.isRecording()) {
|
||||
MyAvatar.stopRecording();
|
||||
}
|
||||
if (MyAvatar.isPlaying()) {
|
||||
MyAvatar.stopPlaying();
|
||||
}
|
||||
toolBar.cleanup();
|
||||
Overlays.deleteOverlay(timer);
|
||||
Overlays.deleteOverlay(slider.background);
|
||||
|
|
|
@ -32,168 +32,168 @@ var clickedButton = false;
|
|||
var cursor = "|";
|
||||
// add more characters to the string if required
|
||||
var keyString = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
|
||||
~!@#$%^&*()_+`1234567890-={}|[]\\:\";'<>?,./"; //permitted characters
|
||||
~!@#$%^&*()_+`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,
|
||||
backgroundAlpha: backgroundAlpha,
|
||||
topMargin: topMargin,
|
||||
leftMargin: leftMargin,
|
||||
font: {size: fontSize},
|
||||
text: writing,
|
||||
visible: true
|
||||
});
|
||||
x: locationX,
|
||||
y: locationY,
|
||||
width: width,
|
||||
height: height,
|
||||
color: textColor,
|
||||
backgroundColor: backColor,
|
||||
alpha: backgroundAlpha,
|
||||
backgroundAlpha: 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
|
||||
});
|
||||
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,
|
||||
});
|
||||
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<keyString.length; i++){
|
||||
var nextChar = keyString.charAt(i);
|
||||
Controller.releaseKeyEvents({ text: nextChar});
|
||||
}
|
||||
Controller.releaseKeyEvents({"key": 0x5c}); // forward slash
|
||||
Controller.releaseKeyEvents({ text: "SHIFT"});
|
||||
Controller.releaseKeyEvents({ text: "BACKSPACE"});
|
||||
Controller.releaseKeyEvents({ text: "SPACE"});
|
||||
Controller.releaseKeyEvents({"key":16777220} ); //Enter
|
||||
Controller.releaseKeyEvents({"key":16777219} ); //Backspace
|
||||
Overlays.deleteOverlay(inputWindow);
|
||||
Overlays.deleteOverlay(button1);
|
||||
Overlays.deleteOverlay(button2);
|
||||
//Return control of keys to default on script ending
|
||||
for(var i=0; i<keyString.length; i++){
|
||||
var nextChar = keyString.charAt(i);
|
||||
Controller.releaseKeyEvents({ text: nextChar});
|
||||
}
|
||||
Controller.releaseKeyEvents({"key": 0x5c}); // forward slash
|
||||
Controller.releaseKeyEvents({ text: "SHIFT"});
|
||||
Controller.releaseKeyEvents({ text: "BACKSPACE"});
|
||||
Controller.releaseKeyEvents({ text: "SPACE"});
|
||||
Controller.releaseKeyEvents({"key":16777220} ); //Enter
|
||||
Controller.releaseKeyEvents({"key":16777219} ); //Backspace
|
||||
}
|
||||
Script.scriptEnding.connect(scriptEnding);
|
||||
|
||||
|
||||
function resetForm(){
|
||||
writing = ""; // Start with a blank string
|
||||
Overlays.editOverlay(button1, {color: readyColor} );
|
||||
Overlays.editOverlay(inputWindow, {backgroundColor: readyColor});
|
||||
clickedText = true;
|
||||
writing = ""; // Start with a blank string
|
||||
Overlays.editOverlay(button1, {color: readyColor} );
|
||||
Overlays.editOverlay(inputWindow, {backgroundColor: readyColor});
|
||||
clickedText = true;
|
||||
}
|
||||
|
||||
function submitForm(){
|
||||
print("form submitted");
|
||||
writingOutput = writing; // writingOutput is the data output
|
||||
writing = writing + ".\nYour data has been stored.\n\nClick here to reset form or \n\n\nClick red button to close,";
|
||||
Overlays.editOverlay(button1, { color: clickedColor} );
|
||||
Overlays.editOverlay(inputWindow, {backgroundColor: clickedColor});
|
||||
clickedText = false;
|
||||
clickedButton = true;
|
||||
print("form submitted");
|
||||
writingOutput = writing; // writingOutput is the data output
|
||||
writing = writing + ".\nYour data has been stored.\n\nClick here to reset form or \n\n\nClick red button to close,";
|
||||
Overlays.editOverlay(button1, { color: clickedColor} );
|
||||
Overlays.editOverlay(inputWindow, {backgroundColor: clickedColor});
|
||||
clickedText = false;
|
||||
clickedButton = true;
|
||||
}
|
||||
|
||||
// handle click detection
|
||||
function mousePressEvent(event) {
|
||||
|
||||
var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); //identify which overlay was clicked
|
||||
var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); //identify which overlay was clicked
|
||||
|
||||
if (clickedOverlay == inputWindow) { // if the user clicked on the text window, prepare the overlay
|
||||
if (clickedText == false){ // first time clicked?
|
||||
resetForm();
|
||||
}
|
||||
}
|
||||
if (clickedOverlay == inputWindow) { // if the user clicked on the text window, prepare the overlay
|
||||
if (clickedText == false){ // first time clicked?
|
||||
resetForm();
|
||||
}
|
||||
}
|
||||
|
||||
if (clickedOverlay == button1) { // if the user clicked on the green button
|
||||
if (clickedText == true){ // nothing happens unless the text window was clicked first
|
||||
submitForm();
|
||||
// clickedText == false;
|
||||
}
|
||||
else { // if the form has been submitted already
|
||||
resetForm();
|
||||
}
|
||||
}
|
||||
if (clickedOverlay == button1) { // if the user clicked on the green button
|
||||
if (clickedText == true){ // nothing happens unless the text window was clicked first
|
||||
submitForm();
|
||||
// clickedText == false;
|
||||
}
|
||||
else { // if the form has been submitted already
|
||||
resetForm();
|
||||
}
|
||||
}
|
||||
|
||||
if (clickedOverlay == button2) { // if the user clicked on the red button
|
||||
print ("script ending");
|
||||
Script.stop();
|
||||
}
|
||||
if (clickedOverlay == button2) { // if the user clicked on the red button
|
||||
print ("script ending");
|
||||
Script.stop();
|
||||
}
|
||||
}
|
||||
|
||||
//handle key press detection
|
||||
function keyPressEvent(key) {
|
||||
|
||||
if (clickedText == true){
|
||||
if (clickedText == true){
|
||||
|
||||
if (key.text == "SPACE") { //special conditions for space bar
|
||||
writing = writing + " ";
|
||||
key.text ="";
|
||||
}
|
||||
else if (key.text == "BACKSPACE") { // Backspace
|
||||
var myString = writing;
|
||||
writing = myString.substr(0, myString.length-1);
|
||||
key.text ="";
|
||||
}
|
||||
if (key.text == "SPACE") { //special conditions for space bar
|
||||
writing = writing + " ";
|
||||
key.text ="";
|
||||
}
|
||||
else if (key.text == "BACKSPACE") { // Backspace
|
||||
var myString = writing;
|
||||
writing = myString.substr(0, myString.length-1);
|
||||
key.text ="";
|
||||
}
|
||||
|
||||
if (key.text == "\r") { //special conditions for enter key
|
||||
writing = writing + "\n";
|
||||
key.text ="";
|
||||
}
|
||||
else if ( keyString.indexOf(key.text) == -1) { // prevent all other keys not in keyString
|
||||
key.text ="";
|
||||
}
|
||||
// build the string
|
||||
writing = writing + key.text;
|
||||
}
|
||||
if (key.text == "\r") { //special conditions for enter key
|
||||
writing = writing + "\n";
|
||||
key.text ="";
|
||||
}
|
||||
else if ( keyString.indexOf(key.text) == -1) { // prevent all other keys not in keyString
|
||||
key.text ="";
|
||||
}
|
||||
// build the string
|
||||
writing = writing + key.text;
|
||||
}
|
||||
}
|
||||
|
||||
var count = 0;
|
||||
function updateWriting(deltaTime){
|
||||
count++;
|
||||
// every half second or so, remove and replace the pipe to create a blinking cursor
|
||||
if (count % 30 == 0) {
|
||||
if (cursor == "|") {
|
||||
cursor="";
|
||||
} else {
|
||||
cursor = "|";
|
||||
}
|
||||
}
|
||||
// attempt at some overflow control of the text
|
||||
if ((writing.length % 53) == 0) {
|
||||
writing = writing + "\n";
|
||||
}
|
||||
// add blinking cursor to window during typing
|
||||
var addCursor = writing + cursor;
|
||||
if (clickedText == true){
|
||||
Overlays.editOverlay(inputWindow, { text: addCursor});
|
||||
}else{
|
||||
Overlays.editOverlay(inputWindow, { text: writing});
|
||||
}
|
||||
count++;
|
||||
// every half second or so, remove and replace the pipe to create a blinking cursor
|
||||
if (count % 30 == 0) {
|
||||
if (cursor == "|") {
|
||||
cursor="";
|
||||
} else {
|
||||
cursor = "|";
|
||||
}
|
||||
}
|
||||
// attempt at some overflow control of the text
|
||||
if ((writing.length % 53) == 0) {
|
||||
writing = writing + "\n";
|
||||
}
|
||||
// add blinking cursor to window during typing
|
||||
var addCursor = writing + cursor;
|
||||
if (clickedText == true){
|
||||
Overlays.editOverlay(inputWindow, { text: addCursor});
|
||||
}else{
|
||||
Overlays.editOverlay(inputWindow, { text: writing});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// test keystroke against keyString and capture permitted keys
|
||||
for (var i=0; i<keyString.length; i++){
|
||||
var nextChar = keyString.charAt(i);
|
||||
Controller.captureKeyEvents({ text: nextChar});
|
||||
var nextChar = keyString.charAt(i);
|
||||
Controller.captureKeyEvents({ text: nextChar});
|
||||
}
|
||||
// capture special keys
|
||||
Controller.captureKeyEvents({ "key": 0x5c}); //forward slash key
|
||||
|
|
Loading…
Reference in a new issue