Mercurial > games > semicongine
annotate tests/test_font.nim @ 378:c7468c8350c3
del: default material makes no sense, fix: gltf import orientation
author | Sam <sam@basx.dev> |
---|---|
date | Sun, 26 Nov 2023 23:09:19 +0700 |
parents | f054b8bacab8 |
children | e50c57423567 |
rev | line source |
---|---|
272
bfcb41211c5b
add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents:
265
diff
changeset
|
1 import std/unicode |
bfcb41211c5b
add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents:
265
diff
changeset
|
2 |
265 | 3 import semicongine |
4 | |
5 proc main() = | |
371
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
344
diff
changeset
|
6 # setup engine |
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
344
diff
changeset
|
7 var engine = initEngine("Test fonts") |
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
344
diff
changeset
|
8 engine.initRenderer([]) |
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
344
diff
changeset
|
9 |
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
344
diff
changeset
|
10 # build scene |
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
344
diff
changeset
|
11 var scene = Scene(name: "main") |
272
bfcb41211c5b
add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents:
265
diff
changeset
|
12 var font = loadFont("DejaVuSans.ttf", color=newVec4f(1, 0.5, 0.5, 1), resolution=20) |
341 | 13 var textbox = initTextbox(32, font, "") |
331
05fb85ba97dd
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:
330
diff
changeset
|
14 scene.add textbox |
05fb85ba97dd
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:
330
diff
changeset
|
15 textbox.mesh.transform = scale(0.01, 0.01) |
371
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
344
diff
changeset
|
16 engine.loadScene(scene) |
272
bfcb41211c5b
add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents:
265
diff
changeset
|
17 |
265 | 18 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): |
272
bfcb41211c5b
add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents:
265
diff
changeset
|
19 if engine.windowWasResized(): |
bfcb41211c5b
add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents:
265
diff
changeset
|
20 var winSize = engine.getWindow().size |
331
05fb85ba97dd
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:
330
diff
changeset
|
21 textbox.mesh.transform = scale(0.01 * (winSize[1] / winSize[0]), 0.01) |
272
bfcb41211c5b
add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents:
265
diff
changeset
|
22 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]: |
bfcb41211c5b
add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents:
265
diff
changeset
|
23 if engine.keyWasPressed(c): |
bfcb41211c5b
add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents:
265
diff
changeset
|
24 if engine.keyIsDown(ShiftL) or engine.keyIsDown(ShiftR): |
bfcb41211c5b
add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents:
265
diff
changeset
|
25 textbox.text = textbox.text & ($c).toRunes |
bfcb41211c5b
add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents:
265
diff
changeset
|
26 else: |
bfcb41211c5b
add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents:
265
diff
changeset
|
27 textbox.text = textbox.text & ($c).toRunes[0].toLower() |
bfcb41211c5b
add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents:
265
diff
changeset
|
28 if engine.keyWasPressed(Space): |
bfcb41211c5b
add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents:
265
diff
changeset
|
29 textbox.text = textbox.text & " ".toRunes[0] |
bfcb41211c5b
add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents:
265
diff
changeset
|
30 if engine.keyWasPressed(Backspace) and textbox.text.len > 0: |
bfcb41211c5b
add: final font-rendering, API changes fixed
Sam <sam@basx.dev>
parents:
265
diff
changeset
|
31 textbox.text = textbox.text[0 ..< ^1] |
265 | 32 engine.renderScene(scene) |
33 engine.destroy() | |
34 | |
35 | |
36 when isMainModule: | |
37 main() |