comparison tests/test_font.nim @ 877:773af36148bd

did: changes
author Sam <sam@basx.dev>
date Sat, 27 Jan 2024 21:08:31 +0700
parents 164b41a2d5a6
children b032768df631
comparison
equal deleted inserted replaced
876:164b41a2d5a6 877:773af36148bd
8 engine.initRenderer([]) 8 engine.initRenderer([])
9 9
10 # build scene 10 # build scene
11 var scene = Scene(name: "main") 11 var scene = Scene(name: "main")
12 # var font = loadFont("DejaVuSans.ttf", lineHeightPixels=90'f32, charset="abcdefghijklmnopqrstuvwxyz ".toRunes) 12 # var font = loadFont("DejaVuSans.ttf", lineHeightPixels=90'f32, charset="abcdefghijklmnopqrstuvwxyz ".toRunes)
13 var font = loadFont("DejaVuSans.ttf", lineHeightPixels=180'f32) 13 var font = loadFont("DejaVuSans.ttf", lineHeightPixels = 250'f32)
14 var textbox = initText(32, font, "", color=newVec4f(1, 0, 0, 1)) 14 var textbox = initText(32, font, "_", color = newVec4f(1, 0, 0, 1))
15 let fontscale = 0.002 15 let fontscale = 0.001
16 scene.add textbox 16 scene.add textbox
17 textbox.mesh.transform = scale(fontscale, fontscale) 17 textbox.mesh.transform = scale(fontscale, fontscale)
18 engine.loadScene(scene) 18 engine.loadScene(scene)
19 19
20 let cursor = Rune('_')
20 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): 21 while engine.updateInputs() == Running and not engine.keyIsDown(Escape):
21 if engine.windowWasResized(): 22 if engine.windowWasResized():
22 var winSize = engine.getWindow().size 23 var winSize = engine.getWindow().size
23 textbox.mesh.transform = scale(fontscale * (winSize[1] / winSize[0]), fontscale) 24 textbox.mesh.transform = scale(fontscale * (winSize[1] / winSize[0]), fontscale)
24 for c in [Key.A, Key.B, Key.C, Key.D, Key.E, Key.F, Key.G, Key.H, Key.I, Key.J, Key.K, Key.L, Key.M, Key.N, Key.O, Key.P, Key.Q, Key.R, Key.S, Key.T, Key.U, Key.V, Key.W, Key.X, Key.Y, Key.Z]: 25 for c in [Key.A, Key.B, Key.C, Key.D, Key.E, Key.F, Key.G, Key.H, Key.I,
26 Key.J, Key.K, Key.L, Key.M, Key.N, Key.O, Key.P, Key.Q, Key.R, Key.S,
27 Key.T, Key.U, Key.V, Key.W, Key.X, Key.Y, Key.Z]:
25 if engine.keyWasPressed(c): 28 if engine.keyWasPressed(c):
26 if engine.keyIsDown(ShiftL) or engine.keyIsDown(ShiftR): 29 if engine.keyIsDown(ShiftL) or engine.keyIsDown(ShiftR):
27 textbox.text = textbox.text & ($c).toRunes 30 textbox.text = textbox.text[0 ..< ^1] & ($c).toRunes & cursor
28 else: 31 else:
29 textbox.text = textbox.text & ($c).toRunes[0].toLower() 32 textbox.text = textbox.text[0 ..< ^1] & ($c).toRunes[0].toLower() & cursor
30 if engine.keyWasPressed(Enter): 33 if engine.keyWasPressed(Enter):
31 textbox.text = textbox.text & Rune('\n') 34 textbox.text = textbox.text[0 ..< ^1] & Rune('\n') & cursor
32 if engine.keyWasPressed(Space): 35 if engine.keyWasPressed(Space):
33 textbox.text = textbox.text & Rune(' ') 36 textbox.text = textbox.text[0 ..< ^1] & Rune(' ') & cursor
34 if engine.keyWasPressed(Backspace) and textbox.text.len > 0: 37 if engine.keyWasPressed(Backspace) and textbox.text.len > 1:
35 textbox.text = textbox.text[0 ..< ^1] 38 textbox.text = textbox.text[0 ..< ^2] & cursor
36 engine.renderScene(scene) 39 engine.renderScene(scene)
37 engine.destroy() 40 engine.destroy()
38 41
39 42
40 when isMainModule: 43 when isMainModule: