comparison tests/test_font.nim @ 411:e50c57423567

did: image & font refactoring, add texture-atlas-packing
author Sam <sam@basx.dev>
date Sat, 20 Jan 2024 20:17:03 +0700
parents f054b8bacab8
children 262e771e2573
comparison
equal deleted inserted replaced
410:a408af667e29 411:e50c57423567
7 var engine = initEngine("Test fonts") 7 var engine = initEngine("Test fonts")
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", color=newVec4f(1, 0.5, 0.5, 1), resolution=20) 12 # var font = loadFont("DejaVuSans.ttf", lineHeightPixels=90'f32, charset="abcdefghijklmnopqrstuvwxyz ".toRunes)
13 var textbox = initTextbox(32, font, "") 13 var font = loadFont("DejaVuSans.ttf", lineHeightPixels=90'f32)
14 var textbox = initText(32, font, "", color=newVec4f(1, 0, 0, 1))
15 let fontscale = 0.005
14 scene.add textbox 16 scene.add textbox
15 textbox.mesh.transform = scale(0.01, 0.01) 17 textbox.mesh.transform = scale(fontscale, fontscale)
16 engine.loadScene(scene) 18 engine.loadScene(scene)
17 19
18 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): 20 while engine.updateInputs() == Running and not engine.keyIsDown(Escape):
19 if engine.windowWasResized(): 21 if engine.windowWasResized():
20 var winSize = engine.getWindow().size 22 var winSize = engine.getWindow().size
21 textbox.mesh.transform = scale(0.01 * (winSize[1] / winSize[0]), 0.01) 23 textbox.mesh.transform = scale(fontscale * (winSize[1] / winSize[0]), fontscale)
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]: 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]:
23 if engine.keyWasPressed(c): 25 if engine.keyWasPressed(c):
24 if engine.keyIsDown(ShiftL) or engine.keyIsDown(ShiftR): 26 if engine.keyIsDown(ShiftL) or engine.keyIsDown(ShiftR):
25 textbox.text = textbox.text & ($c).toRunes 27 textbox.text = textbox.text & ($c).toRunes
26 else: 28 else: