Skip to content

Commit

Permalink
Fixing samples to use the Class Instance style rather than statics
Browse files Browse the repository at this point in the history
  • Loading branch information
avivbeeri committed Apr 22, 2021
1 parent c66431d commit a1f112c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 50 deletions.
92 changes: 48 additions & 44 deletions examples/textInput/main.wren
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,60 @@ import "dome" for Window
var X = 10
var Y = 28

class Game {
static init() {
__text = ""
Keyboard.handleText = true
Keyboard.textRegion(X, Y, 8, 8)
}
class Main {
construct new() {}

static update() {
var change = false
if (Keyboard.text.count > 0) {
__text = __text + Keyboard.text
change = true
}
init() {
__text = ""
Keyboard.handleText = true
Keyboard.textRegion(X, Y, 8, 8)
}

if (!Keyboard.compositionText && 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
}
if (change) {
Keyboard.textRegion(__text.count * 8, Y, 8, 8)
}
update() {
var change = false
if (Keyboard.text.count > 0) {
__text = __text + Keyboard.text
change = true
}

if ((Keyboard["left ctrl"].down || Keyboard["right ctrl"].down) && Keyboard["c"].justPressed) {
Clipboard.content = __text
}
if ((Keyboard["left ctrl"].down || Keyboard["right ctrl"].down) && Keyboard["v"].justPressed) {
__text = __text + Clipboard.content
if (!Keyboard.compositionText && 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
}
if (change) {
Keyboard.textRegion(__text.count * 8, Y, 8, 8)
}

if ((Keyboard["left ctrl"].down || Keyboard["right ctrl"].down) && Keyboard["c"].justPressed) {
Clipboard.content = __text
}
if ((Keyboard["left ctrl"].down || Keyboard["right ctrl"].down) && Keyboard["v"].justPressed) {
__text = __text + Clipboard.content
}
}

static draw(dt) {
Canvas.cls()
Canvas.rect(X, Y, 8, 8, Color.red)
Canvas.print("Enter Text:", 10, 10, Color.white)
Canvas.print(__text, 10, 20, Color.white)
if (Keyboard.compositionText) {
var left = 10 + 8 * __text.count
Canvas.print(Keyboard.compositionText, left, 20, Color.red)
var range = Keyboard.compositionRange
var length = range.max - range.min
if (length > 0) {
Canvas.line(left + 8 * range.min, 30, left + 8 * (range.min + length), 30, Color.red)
} else {
Canvas.line(left, 30, left + 8 * (Keyboard.compositionText.count), 30, Color.red)
}
draw(dt) {
Canvas.cls()
Canvas.rect(X, Y, 8, 8, Color.red)
Canvas.print("Enter Text:", 10, 10, Color.white)
Canvas.print(__text, 10, 20, Color.white)
if (Keyboard.compositionText) {
var left = 10 + 8 * __text.count
Canvas.print(Keyboard.compositionText, left, 20, Color.red)
var range = Keyboard.compositionRange
var length = range.max - range.min
if (length > 0) {
Canvas.line(left + 8 * range.min, 30, left + 8 * (range.min + length), 30, Color.red)
} else {
Canvas.line(left, 30, left + 8 * (Keyboard.compositionText.count), 30, Color.red)
}
}
}
}

var Game = Main.new()
15 changes: 9 additions & 6 deletions main.wren
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import "graphics" for Canvas, Color
class Game {
static init() {}
static update() {}
static draw(dt) {
Canvas.print("DOME Installed Successfully.", 10, 10, Color.white)
}
class Main {
construct new() {}
init() {}
update() {}
draw(dt) {
Canvas.print("DOME Installed Successfully.", 10, 10, Color.white)
}
}

var Game = Main.new()

0 comments on commit a1f112c

Please sign in to comment.