fixes for the virtualKeyboardTextEntityExample

This commit is contained in:
Thijs Wenker 2015-02-11 22:57:59 +01:00
parent 525fe7881e
commit 2c52c9c3c0

View file

@ -27,7 +27,7 @@ const TEXT_MARGIN_RIGHT = 0.17;
const TEXT_MARGIN_BOTTOM = 0.17; const TEXT_MARGIN_BOTTOM = 0.17;
var windowDimensions = Controller.getViewportDimensions(); var windowDimensions = Controller.getViewportDimensions();
var cursor = null; var cursor = new Cursor();
var keyboard = new Keyboard(); var keyboard = new Keyboard();
var textFontSize = 9; var textFontSize = 9;
var text = null; var text = null;
@ -70,7 +70,7 @@ keyboard.onKeyRelease = function(event) {
// you can cancel a key by releasing its focusing before releasing it // you can cancel a key by releasing its focusing before releasing it
if (event.focus) { if (event.focus) {
if (event.event == 'delete') { if (event.event == 'delete') {
deleteChar(); deleteChar();
} else if (event.event == 'submit') { } else if (event.event == 'submit') {
print(textText); print(textText);
@ -83,12 +83,14 @@ keyboard.onKeyRelease = function(event) {
if (maxLineWidth < usernameWidth) { if (maxLineWidth < usernameWidth) {
maxLineWidth = usernameWidth; maxLineWidth = usernameWidth;
} else { } else {
var spaceableWidth = maxLineWidth - usernameWidth; var spaceableWidth = maxLineWidth - usernameWidth;
var spaceWidth = Overlays.textSize(textSizeMeasureOverlay, " ").width; //TODO: WORKAROUND WARNING BELOW Fix this when spaces are not trimmed out of the textsize calculation anymore
var numberOfSpaces = Math.floor(spaceableWidth / spaceWidth); var spaceWidth = Overlays.textSize(textSizeMeasureOverlay, "| |").width
for (var i = 0; i < numberOfSpaces; i++) { - Overlays.textSize(textSizeMeasureOverlay, "||").width;
usernameLine = " " + usernameLine; 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; var dimension_x = maxLineWidth + TEXT_MARGIN_RIGHT + TEXT_MARGIN_LEFT;
if (position.x > 0 && position.y > 0 && position.z > 0) { if (position.x > 0 && position.y > 0 && position.z > 0) {
@ -100,7 +102,7 @@ keyboard.onKeyRelease = function(event) {
backgroundColor: { red: 0, green: 0, blue: 0 }, backgroundColor: { red: 0, green: 0, blue: 0 },
textColor: { red: 255, green: 255, blue: 255 }, textColor: { red: 255, green: 255, blue: 255 },
text: textText + "\n" + usernameLine, text: textText + "\n" + usernameLine,
lineHeight: 0.1 lineHeight: 0.1
}); });
} }
textText = ""; textText = "";
@ -127,7 +129,7 @@ keyboard.onFullyLoaded = function() {
}); });
updateTextOverlay(); updateTextOverlay();
// the cursor is being loaded after the keyboard, else it will be on the background of the keyboard // the cursor is being loaded after the keyboard, else it will be on the background of the keyboard
cursor = new Cursor(); cursor.initialize();
cursor.onUpdate = function(position) { cursor.onUpdate = function(position) {
keyboard.setFocusPosition(position.x, position.y); keyboard.setFocusPosition(position.x, position.y);
}; };