Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
68
Task/User-input-Graphical/Wren/user-input-graphical.wren
Normal file
68
Task/User-input-Graphical/Wren/user-input-graphical.wren
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
import "graphics" for Canvas, Color
|
||||
import "input" for Keyboard, Clipboard
|
||||
import "dome" for Window, Process
|
||||
|
||||
var X = 10
|
||||
var Y = 28
|
||||
|
||||
class Main {
|
||||
construct new() {}
|
||||
|
||||
init() {
|
||||
_text = ""
|
||||
_enterNum = false
|
||||
Keyboard.handleText = true
|
||||
Keyboard.textRegion(X, Y, 8, 8)
|
||||
}
|
||||
|
||||
update() {
|
||||
var change = false
|
||||
if (Keyboard.text.count > 0) {
|
||||
_text = _text + Keyboard.text
|
||||
change = true
|
||||
}
|
||||
|
||||
// enable backspace key to delete last character entered
|
||||
if (Keyboard["backspace"].justPressed && _text.count > 0) {
|
||||
var codePoints = _text.codePoints
|
||||
codePoints = codePoints.take(codePoints.count - 1)
|
||||
_text = ""
|
||||
for (point in codePoints) {
|
||||
_text = _text + String.fromCodePoint(point)
|
||||
}
|
||||
change = true
|
||||
}
|
||||
|
||||
// enable return key to terminate input
|
||||
if (Keyboard["return"].justPressed) {
|
||||
System.print("'%(_text)' was entered.")
|
||||
if (!_enterNum) {
|
||||
_text = ""
|
||||
_enterNum = true
|
||||
change = true
|
||||
} else if (_text == "75000") {
|
||||
Process.exit()
|
||||
} else {
|
||||
_text = ""
|
||||
change = true
|
||||
}
|
||||
}
|
||||
|
||||
if (change) {
|
||||
Keyboard.textRegion(X.min(_text.count * 8), Y, 8, 8)
|
||||
}
|
||||
}
|
||||
|
||||
draw(dt) {
|
||||
Canvas.cls()
|
||||
Canvas.rect(X, Y, 8, 8, Color.red)
|
||||
if (!_enterNum) {
|
||||
Canvas.print("Enter Text and press return:", 10, 10, Color.white)
|
||||
} else {
|
||||
Canvas.print("Enter 75000 and press return:", 10, 10, Color.white)
|
||||
}
|
||||
Canvas.print(_text, 10, 20, Color.white)
|
||||
}
|
||||
}
|
||||
|
||||
var Game = Main.new()
|
||||
Loading…
Add table
Add a link
Reference in a new issue