Mercurial > games > semicongine
comparison tests/test_font.nim @ 436:36b907544820
fix: text-alignment, a few smaller fixes
| author | Sam <sam@basx.dev> |
|---|---|
| date | Sun, 11 Feb 2024 18:47:13 +0700 |
| parents | 2b373a03cf64 |
| children | 7629f85823a4 |
comparison
equal
deleted
inserted
replaced
| 435:065854cdba52 | 436:36b907544820 |
|---|---|
| 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(size = newVec2f(0.01, 0.01)) | |
| 15 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("", maxLen = 255, color = newVec4f(1, 0.15, 0.15, 1), scale = 0.0005, maxWidth = 1.0) |
| 16 var help_text = font.initText("""Controls | 17 var help_text = font.initText("""Controls |
| 17 | 18 |
| 18 Horizontal alignment: | 19 Horizontal alignment: |
| 19 F1: Left | 20 F1: Left |
| 21 F3: Right | 22 F3: Right |
| 22 Vertical alignment: | 23 Vertical alignment: |
| 23 F4: Top | 24 F4: Top |
| 24 F5: Center | 25 F5: Center |
| 25 F6: Bottom""", scale = 0.0002, position = newVec2f(-0.9, -0.9), horizontalAlignment = Left, verticalAlignment = Top) | 26 F6: Bottom""", scale = 0.0002, position = newVec2f(-0.9, -0.9), horizontalAlignment = Left, verticalAlignment = Top) |
| 27 scene.add origin | |
| 26 scene.add main_text | 28 scene.add main_text |
| 27 scene.add help_text | 29 scene.add help_text |
| 28 engine.loadScene(scene) | 30 engine.loadScene(scene) |
| 29 mixer[].loadSound("key", "key.ogg") | 31 mixer[].loadSound("key", "key.ogg") |
| 30 mixer[].setLevel(0.5) | 32 mixer[].setLevel(0.5) |
| 33 var t = cpuTime() | 35 var t = cpuTime() |
| 34 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) |
| 35 if engine.windowWasResized(): | 37 if engine.windowWasResized(): |
| 36 var winSize = engine.getWindow().size | 38 var winSize = engine.getWindow().size |
| 37 main_text.aspect_ratio = winSize[0] / winSize[1] | 39 main_text.aspect_ratio = winSize[0] / winSize[1] |
| 40 origin.aspect_ratio = winSize[0] / winSize[1] | |
| 38 help_text.aspect_ratio = winSize[0] / winSize[1] | 41 help_text.aspect_ratio = winSize[0] / winSize[1] |
| 39 | 42 |
| 40 # add character | 43 # add character |
| 41 if main_text.text.len < main_text.maxLen - 1: | 44 if main_text.text.len < main_text.maxLen - 1: |
| 42 for c in [Key.A, Key.B, Key.C, Key.D, Key.E, Key.F, Key.G, Key.H, Key.I, | 45 for c in [Key.A, Key.B, Key.C, Key.D, Key.E, Key.F, Key.G, Key.H, Key.I, |
| 66 elif engine.keyWasPressed(F3): main_text.horizontalAlignment = Right | 69 elif engine.keyWasPressed(F3): main_text.horizontalAlignment = Right |
| 67 elif engine.keyWasPressed(F4): main_text.verticalAlignment = Top | 70 elif engine.keyWasPressed(F4): main_text.verticalAlignment = Top |
| 68 elif engine.keyWasPressed(F5): main_text.verticalAlignment = Center | 71 elif engine.keyWasPressed(F5): main_text.verticalAlignment = Center |
| 69 elif engine.keyWasPressed(F6): main_text.verticalAlignment = Bottom | 72 elif engine.keyWasPressed(F6): main_text.verticalAlignment = Bottom |
| 70 | 73 |
| 74 origin.refresh() | |
| 71 main_text.text = main_text.text & Rune('_') | 75 main_text.text = main_text.text & Rune('_') |
| 72 main_text.refresh() | 76 main_text.refresh() |
| 73 main_text.text = main_text.text[0 ..< ^1] | 77 main_text.text = main_text.text[0 ..< ^1] |
| 74 help_text.refresh() | 78 help_text.refresh() |
| 75 engine.renderScene(scene) | 79 engine.renderScene(scene) |
