annotate tests/test_font.nim @ 811:cc59b7650075

did: improve error output, allow import of meshes without materials
author Sam <sam@basx.dev>
date Tue, 19 Sep 2023 21:27:25 +0700
parents 7a13941ba204
children f054b8bacab8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
733
07c755e65a4a add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents: 726
diff changeset
1 import std/unicode
07c755e65a4a add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents: 726
diff changeset
2
726
443791a202c8 add: font-test
Sam <sam@basx.dev>
parents:
diff changeset
3 import semicongine
443791a202c8 add: font-test
Sam <sam@basx.dev>
parents:
diff changeset
4
443791a202c8 add: font-test
Sam <sam@basx.dev>
parents:
diff changeset
5 proc main() =
733
07c755e65a4a add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents: 726
diff changeset
6 var font = loadFont("DejaVuSans.ttf", color=newVec4f(1, 0.5, 0.5, 1), resolution=20)
791
43432dad4797 did: remove some stuff from the heap, maybe nicer?
Sam <sam@basx.dev>
parents: 777
diff changeset
7
802
a9c67e1ecb8d did: small font improvments
Sam <sam@basx.dev>
parents: 792
diff changeset
8 var textbox = initTextbox(32, font, "")
792
d65b62812d34 did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 791
diff changeset
9 var scene = Scene(name: "main")
d65b62812d34 did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 791
diff changeset
10 scene.add textbox
d65b62812d34 did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 791
diff changeset
11 textbox.mesh.transform = scale(0.01, 0.01)
733
07c755e65a4a add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents: 726
diff changeset
12 var engine = initEngine("Test fonts")
805
7a13941ba204 fix: all tests
Sam <sam@basx.dev>
parents: 802
diff changeset
13 engine.initRenderer([])
791
43432dad4797 did: remove some stuff from the heap, maybe nicer?
Sam <sam@basx.dev>
parents: 777
diff changeset
14 engine.addScene(scene)
733
07c755e65a4a add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents: 726
diff changeset
15
726
443791a202c8 add: font-test
Sam <sam@basx.dev>
parents:
diff changeset
16 while engine.updateInputs() == Running and not engine.keyIsDown(Escape):
733
07c755e65a4a add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents: 726
diff changeset
17 if engine.windowWasResized():
07c755e65a4a add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents: 726
diff changeset
18 var winSize = engine.getWindow().size
792
d65b62812d34 did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 791
diff changeset
19 textbox.mesh.transform = scale(0.01 * (winSize[1] / winSize[0]), 0.01)
733
07c755e65a4a add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents: 726
diff changeset
20 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]:
07c755e65a4a add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents: 726
diff changeset
21 if engine.keyWasPressed(c):
07c755e65a4a add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents: 726
diff changeset
22 if engine.keyIsDown(ShiftL) or engine.keyIsDown(ShiftR):
07c755e65a4a add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents: 726
diff changeset
23 textbox.text = textbox.text & ($c).toRunes
07c755e65a4a add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents: 726
diff changeset
24 else:
07c755e65a4a add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents: 726
diff changeset
25 textbox.text = textbox.text & ($c).toRunes[0].toLower()
07c755e65a4a add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents: 726
diff changeset
26 if engine.keyWasPressed(Space):
07c755e65a4a add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents: 726
diff changeset
27 textbox.text = textbox.text & " ".toRunes[0]
07c755e65a4a add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents: 726
diff changeset
28 if engine.keyWasPressed(Backspace) and textbox.text.len > 0:
07c755e65a4a add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents: 726
diff changeset
29 textbox.text = textbox.text[0 ..< ^1]
726
443791a202c8 add: font-test
Sam <sam@basx.dev>
parents:
diff changeset
30 engine.renderScene(scene)
443791a202c8 add: font-test
Sam <sam@basx.dev>
parents:
diff changeset
31 engine.destroy()
443791a202c8 add: font-test
Sam <sam@basx.dev>
parents:
diff changeset
32
443791a202c8 add: font-test
Sam <sam@basx.dev>
parents:
diff changeset
33
443791a202c8 add: font-test
Sam <sam@basx.dev>
parents:
diff changeset
34 when isMainModule:
443791a202c8 add: font-test
Sam <sam@basx.dev>
parents:
diff changeset
35 main()