Mercurial > games > semicongine
annotate old_tests/test_panel.nim @ 1212:518a952eccbf compiletime-tests
did: increase texture format compatability
author | sam <sam@basx.dev> |
---|---|
date | Wed, 17 Jul 2024 12:03:02 +0700 |
parents | 6360c8d17ce0 |
children |
rev | line source |
---|---|
430 | 1 import std/unicode |
2 | |
3 import semicongine | |
4 | |
434 | 5 var counter = 0 |
6 var counterText: Text | |
7 | |
8 proc click(panel: var Panel, buttons: set[MouseButton]) = | |
9 if buttons.contains(Mouse1): | |
10 counter.inc | |
11 if buttons.contains(Mouse3): | |
12 counter.dec | |
13 counterText.text = $counter | |
14 proc enter(panel: var Panel) = | |
1136 | 15 panel.mesh.transform = panel.mesh.transform * Scale(1.05, 1.05) |
16 panel.color = NewVec4f(1, 0, 0, 0.3) | |
434 | 17 proc leave(panel: var Panel) = |
1136 | 18 panel.mesh.transform = panel.mesh.transform * Scale(1 / 1.05, 1 / 1.05) |
19 panel.color = NewVec4f(1, 0, 0, 0.5) | |
430 | 20 |
21 proc main() = | |
22 # setup engine | |
1138 | 23 var engine = InitEngine("Test panels") |
24 engine.InitRenderer([]) | |
430 | 25 |
434 | 26 const B = [0'u8, 0'u8, 0'u8, 255'u8] |
27 const T = [0'u8, 0'u8, 0'u8, 0'u8] | |
430 | 28 # build scene |
434 | 29 # |
433 | 30 var |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
31 font = LoadFont("DejaVuSans.ttf", lineHeightPixels = 210'f32) |
433 | 32 scene = Scene(name: "main") |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
33 origin = InitPanel( |
1136 | 34 transform = Scale(0.005, 0.005), |
35 color = NewVec4f(1, 1, 1, 1), | |
1137 | 36 texture = Texture(isGrayscale: false, colorImage: NewImage[RGBAPixel](3, 3, [T, B, T, B, B, B, T, B, T]), sampler: NEAREST_SAMPLER), |
434 | 37 ) |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
38 button = InitPanel( |
1136 | 39 transform = Translate(0.2, 0.1) * Scale(0.3, 0.1), |
40 color = NewVec4f(1, 0, 0, 0.5), | |
434 | 41 onMouseDown = click, |
42 onMouseEnter = enter, | |
43 onMouseLeave = leave | |
44 ) | |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
45 help_text = font.InitText("""Controls |
433 | 46 |
47 Horizontal alignment: | |
48 F1: Left | |
49 F2: Center | |
50 F3: Right | |
51 Vertical alignment: | |
52 F4: Top | |
53 F5: Center | |
436
36b907544820
fix: text-alignment, a few smaller fixes
Sam <sam@basx.dev>
parents:
434
diff
changeset
|
54 F6: Bottom |
36b907544820
fix: text-alignment, a few smaller fixes
Sam <sam@basx.dev>
parents:
434
diff
changeset
|
55 Mouse: |
36b907544820
fix: text-alignment, a few smaller fixes
Sam <sam@basx.dev>
parents:
434
diff
changeset
|
56 Left click: Increase counter |
1136 | 57 Right click: Decrease counter""".toRunes, horizontalAlignment = Left, verticalAlignment = Top, transform = Translate(-0.9, -0.9) * Scale(0.0002, 0.0002)) |
430 | 58 |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
59 counterText = font.InitText(($counter).toRunes, maxLen = 99, transform = Translate(0.2, 0.1) * Scale(0.0004, 0.0004)) |
434 | 60 |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
61 scene.Add counterText |
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
62 scene.Add button |
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
63 scene.Add help_text |
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
64 scene.Add origin |
1138 | 65 engine.LoadScene(scene) |
430 | 66 |
1135
74957cbf589b
fix: update tests according to some API renaming
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
67 while engine.UpdateInputs() and not KeyIsDown(Escape): |
74957cbf589b
fix: update tests according to some API renaming
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
68 if KeyWasPressed(F1): |
444 | 69 button.horizontalAlignment = Left |
434 | 70 counterText.horizontalAlignment = Left |
1135
74957cbf589b
fix: update tests according to some API renaming
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
71 elif KeyWasPressed(F2): |
444 | 72 button.horizontalAlignment = Center |
434 | 73 counterText.horizontalAlignment = Center |
1135
74957cbf589b
fix: update tests according to some API renaming
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
74 elif KeyWasPressed(F3): |
444 | 75 button.horizontalAlignment = Right |
434 | 76 counterText.horizontalAlignment = Right |
1135
74957cbf589b
fix: update tests according to some API renaming
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
77 elif KeyWasPressed(F4): |
444 | 78 button.verticalAlignment = Top |
434 | 79 counterText.verticalAlignment = Top |
1135
74957cbf589b
fix: update tests according to some API renaming
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
80 elif KeyWasPressed(F5): |
444 | 81 button.verticalAlignment = Center |
434 | 82 counterText.verticalAlignment = Center |
1135
74957cbf589b
fix: update tests according to some API renaming
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
83 elif KeyWasPressed(F6): |
444 | 84 button.verticalAlignment = Bottom |
434 | 85 counterText.verticalAlignment = Bottom |
86 | |
1135
74957cbf589b
fix: update tests according to some API renaming
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
87 engine.ProcessEvents(button) |
433 | 88 |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
89 button.Refresh() |
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
90 counterText.Refresh() |
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
91 origin.Refresh() |
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
92 help_text.Refresh() |
430 | 93 |
1138 | 94 engine.RenderScene(scene) |
95 engine.Destroy() | |
430 | 96 |
97 | |
98 when isMainModule: | |
99 main() |