comparison tests/test_font.nim @ 1139:114f395b9144

did: finish refactoring and updated all tests accordingly
author sam <sam@basx.dev>
date Sat, 08 Jun 2024 14:58:25 +0700
parents 02e1d2658ff5
children
comparison
equal deleted inserted replaced
1138:02e1d2658ff5 1139:114f395b9144
9 var engine = InitEngine("Test fonts") 9 var engine = InitEngine("Test fonts")
10 engine.InitRenderer([]) 10 engine.InitRenderer([])
11 11
12 # build scene 12 # build scene
13 var scene = Scene(name: "main") 13 var scene = Scene(name: "main")
14 var font = loadFont("DejaVuSans.ttf", lineHeightPixels = 210'f32) 14 var font = LoadFont("DejaVuSans.ttf", lineHeightPixels = 210'f32)
15 var origin = initPanel(transform = Scale(0.01, 0.01)) 15 var origin = InitPanel(transform = Scale(0.01, 0.01))
16 var main_text = font.initText("".toRunes, maxLen = 255, color = NewVec4f(1, 0.15, 0.15, 1), maxWidth = 1.0, transform = Scale(0.0005, 0.0005)) 16 var main_text = font.InitText("".toRunes, maxLen = 255, color = NewVec4f(1, 0.15, 0.15, 1), maxWidth = 1.0, transform = Scale(0.0005, 0.0005))
17 var help_text = font.initText("""Controls 17 var help_text = font.InitText("""Controls
18 18
19 Horizontal alignment: 19 Horizontal alignment:
20 F1: Left 20 F1: Left
21 F2: Center 21 F2: Center
22 F3: Right 22 F3: Right
23 Vertical alignment: 23 Vertical alignment:
24 F4: Top 24 F4: Top
25 F5: Center 25 F5: Center
26 F6: Bottom""".toRunes, horizontalAlignment = Left, verticalAlignment = Top, transform = Translate(-0.9, -0.9) * Scale(0.0002, 0.0002)) 26 F6: Bottom""".toRunes, horizontalAlignment = Left, verticalAlignment = Top, transform = Translate(-0.9, -0.9) * Scale(0.0002, 0.0002))
27 scene.add origin 27 scene.Add origin
28 scene.add main_text 28 scene.Add main_text
29 scene.add help_text 29 scene.Add help_text
30 engine.LoadScene(scene) 30 engine.LoadScene(scene)
31 mixer[].LoadSound("key", "key.ogg") 31 mixer[].LoadSound("key", "key.ogg")
32 mixer[].SetLevel(0.5) 32 mixer[].SetLevel(0.5)
33 33
34 while engine.UpdateInputs() and not KeyIsDown(Escape): 34 while engine.UpdateInputs() and not KeyIsDown(Escape):
35 var t = cpuTime() 35 var t = cpuTime()
36 main_text.color = NewVec4f(sin(t) * 0.5 + 0.5, 0.15, 0.15, 1) 36 main_text.Color = NewVec4f(sin(t) * 0.5 + 0.5, 0.15, 0.15, 1)
37 37
38 # add character 38 # add character
39 if main_text.text.len < main_text.maxLen - 1: 39 if main_text.text.len < main_text.maxLen - 1:
40 for c in [Key.A, Key.B, Key.C, Key.D, Key.E, Key.F, Key.G, Key.H, Key.I, 40 for c in [Key.A, Key.B, Key.C, Key.D, Key.E, Key.F, Key.G, Key.H, Key.I,
41 Key.J, Key.K, Key.L, Key.M, Key.N, Key.O, Key.P, Key.Q, Key.R, Key.S, 41 Key.J, Key.K, Key.L, Key.M, Key.N, Key.O, Key.P, Key.Q, Key.R, Key.S,
64 elif KeyWasPressed(F3): main_text.horizontalAlignment = Right 64 elif KeyWasPressed(F3): main_text.horizontalAlignment = Right
65 elif KeyWasPressed(F4): main_text.verticalAlignment = Top 65 elif KeyWasPressed(F4): main_text.verticalAlignment = Top
66 elif KeyWasPressed(F5): main_text.verticalAlignment = Center 66 elif KeyWasPressed(F5): main_text.verticalAlignment = Center
67 elif KeyWasPressed(F6): main_text.verticalAlignment = Bottom 67 elif KeyWasPressed(F6): main_text.verticalAlignment = Bottom
68 68
69 origin.refresh() 69 origin.Refresh()
70 main_text.text = main_text.text & Rune('_') 70 main_text.text = main_text.text & Rune('_')
71 main_text.refresh() 71 main_text.Refresh()
72 main_text.text = main_text.text[0 ..< ^1] 72 main_text.text = main_text.text[0 ..< ^1]
73 help_text.refresh() 73 help_text.Refresh()
74 engine.RenderScene(scene) 74 engine.RenderScene(scene)
75 engine.Destroy() 75 engine.Destroy()
76 76
77 77
78 when isMainModule: 78 when isMainModule: