Mercurial > games > semicongine
comparison tests/test_font.nim @ 443:7629f85823a4
fix: font-api, allow consistent use of mesh-transform
author | Sam <sam@basx.dev> |
---|---|
date | Sat, 24 Feb 2024 14:31:15 +0700 |
parents | 36b907544820 |
children | 6406766a222d |
comparison
equal
deleted
inserted
replaced
442:637974701484 | 443:7629f85823a4 |
---|---|
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(size = newVec2f(0.01, 0.01)) | 15 var origin = initPanel(size = newVec2f(0.01, 0.01)) |
16 var main_text = font.initText("", maxLen = 255, color = newVec4f(1, 0.15, 0.15, 1), scale = 0.0005, maxWidth = 1.0) | 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""", scale = 0.0002, position = newVec2f(-0.9, -0.9), horizontalAlignment = Left, verticalAlignment = Top) | 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") |
34 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): | 34 while engine.updateInputs() == Running and not engine.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 if engine.windowWasResized(): | 37 if engine.windowWasResized(): |
38 var winSize = engine.getWindow().size | 38 var winSize = engine.getWindow().size |
39 main_text.aspect_ratio = winSize[0] / winSize[1] | |
40 origin.aspect_ratio = winSize[0] / winSize[1] | |
41 help_text.aspect_ratio = winSize[0] / winSize[1] | |
42 | 39 |
43 # add character | 40 # add character |
44 if main_text.text.len < main_text.maxLen - 1: | 41 if main_text.text.len < main_text.maxLen - 1: |
45 for c in [Key.A, Key.B, Key.C, Key.D, Key.E, Key.F, Key.G, Key.H, Key.I, | 42 for c in [Key.A, Key.B, Key.C, Key.D, Key.E, Key.F, Key.G, Key.H, Key.I, |
46 Key.J, Key.K, Key.L, Key.M, Key.N, Key.O, Key.P, Key.Q, Key.R, Key.S, | 43 Key.J, Key.K, Key.L, Key.M, Key.N, Key.O, Key.P, Key.Q, Key.R, Key.S, |