Mercurial > games > semicongine
comparison tests/test_panel.nim @ 444:f9d25bc331b3
did: same for panels
author | Sam <sam@basx.dev> |
---|---|
date | Sat, 24 Feb 2024 15:35:52 +0700 |
parents | 36b907544820 |
children | 73b572f82a1f |
comparison
equal
deleted
inserted
replaced
443:7629f85823a4 | 444:f9d25bc331b3 |
---|---|
10 counter.inc | 10 counter.inc |
11 if buttons.contains(Mouse3): | 11 if buttons.contains(Mouse3): |
12 counter.dec | 12 counter.dec |
13 counterText.text = $counter | 13 counterText.text = $counter |
14 proc enter(panel: var Panel) = | 14 proc enter(panel: var Panel) = |
15 panel.size = newVec2f(0.22, 0.22) | 15 panel.mesh.transform = panel.mesh.transform * scale(1.05, 1.05) |
16 panel.color = newVec4f(1, 0, 0, 0.3) | |
16 proc leave(panel: var Panel) = | 17 proc leave(panel: var Panel) = |
17 panel.size = newVec2f(0.2, 0.2) | 18 panel.mesh.transform = panel.mesh.transform * scale(1 / 1.05, 1 / 1.05) |
19 panel.color = newVec4f(1, 0, 0, 0.5) | |
18 | 20 |
19 proc main() = | 21 proc main() = |
20 # setup engine | 22 # setup engine |
21 var engine = initEngine("Test panels") | 23 var engine = initEngine("Test panels") |
22 engine.initRenderer([]) | 24 engine.initRenderer([]) |
27 # | 29 # |
28 var | 30 var |
29 font = loadFont("DejaVuSans.ttf", lineHeightPixels = 210'f32) | 31 font = loadFont("DejaVuSans.ttf", lineHeightPixels = 210'f32) |
30 scene = Scene(name: "main") | 32 scene = Scene(name: "main") |
31 origin = initPanel( | 33 origin = initPanel( |
32 size = newVec2f(0.005, 0.005), | 34 transform = scale(0.005, 0.005), |
33 color = newVec4f(1, 1, 1, 1), | 35 color = newVec4f(1, 1, 1, 1), |
34 texture = Texture(isGrayscale: false, colorImage: newImage[RGBAPixel](3, 3, [T, B, T, B, B, B, T, B, T]), sampler: NEAREST_SAMPLER), | 36 texture = Texture(isGrayscale: false, colorImage: newImage[RGBAPixel](3, 3, [T, B, T, B, B, B, T, B, T]), sampler: NEAREST_SAMPLER), |
35 ) | 37 ) |
36 panel = initPanel( | 38 button = initPanel( |
37 size = newVec2f(0.2, 0.2), | 39 transform = translate(0.2, 0.1) * scale(0.3, 0.1), |
38 color = newVec4f(1, 0, 0, 0.5), | 40 color = newVec4f(1, 0, 0, 0.5), |
39 onMouseDown = click, | 41 onMouseDown = click, |
40 onMouseEnter = enter, | 42 onMouseEnter = enter, |
41 onMouseLeave = leave | 43 onMouseLeave = leave |
42 ) | 44 ) |
50 F4: Top | 52 F4: Top |
51 F5: Center | 53 F5: Center |
52 F6: Bottom | 54 F6: Bottom |
53 Mouse: | 55 Mouse: |
54 Left click: Increase counter | 56 Left click: Increase counter |
55 Right click: Decrease counter""", scale = 0.0002, position = newVec2f(-0.9, -0.9), horizontalAlignment = Left, verticalAlignment = Top) | 57 Right click: Decrease counter""".toRunes, horizontalAlignment = Left, verticalAlignment = Top, transform = translate(-0.9, -0.9) * scale(0.0002, 0.0002)) |
56 | 58 |
57 counterText = font.initText($counter, maxLen = 99, scale = 0.0004) | 59 counterText = font.initText(($counter).toRunes, maxLen = 99, transform = translate(0.2, 0.1) * scale(0.0004, 0.0004)) |
58 | 60 |
59 scene.add counterText | 61 scene.add counterText |
60 scene.add panel | 62 scene.add button |
61 scene.add help_text | 63 scene.add help_text |
62 scene.add origin | 64 scene.add origin |
63 engine.loadScene(scene) | 65 engine.loadScene(scene) |
64 | 66 |
65 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): | 67 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): |
66 if engine.windowWasResized(): | |
67 var winSize = engine.getWindow().size | |
68 panel.aspect_ratio = winSize[0] / winSize[1] | |
69 counterText.aspect_ratio = winSize[0] / winSize[1] | |
70 origin.aspect_ratio = winSize[0] / winSize[1] | |
71 help_text.aspect_ratio = winSize[0] / winSize[1] | |
72 | |
73 if engine.keyWasPressed(F1): | 68 if engine.keyWasPressed(F1): |
74 panel.horizontalAlignment = Left | 69 button.horizontalAlignment = Left |
75 counterText.horizontalAlignment = Left | 70 counterText.horizontalAlignment = Left |
76 elif engine.keyWasPressed(F2): | 71 elif engine.keyWasPressed(F2): |
77 panel.horizontalAlignment = Center | 72 button.horizontalAlignment = Center |
78 counterText.horizontalAlignment = Center | 73 counterText.horizontalAlignment = Center |
79 elif engine.keyWasPressed(F3): | 74 elif engine.keyWasPressed(F3): |
80 panel.horizontalAlignment = Right | 75 button.horizontalAlignment = Right |
81 counterText.horizontalAlignment = Right | 76 counterText.horizontalAlignment = Right |
82 elif engine.keyWasPressed(F4): | 77 elif engine.keyWasPressed(F4): |
83 panel.verticalAlignment = Top | 78 button.verticalAlignment = Top |
84 counterText.verticalAlignment = Top | 79 counterText.verticalAlignment = Top |
85 elif engine.keyWasPressed(F5): | 80 elif engine.keyWasPressed(F5): |
86 panel.verticalAlignment = Center | 81 button.verticalAlignment = Center |
87 counterText.verticalAlignment = Center | 82 counterText.verticalAlignment = Center |
88 elif engine.keyWasPressed(F6): | 83 elif engine.keyWasPressed(F6): |
89 panel.verticalAlignment = Bottom | 84 button.verticalAlignment = Bottom |
90 counterText.verticalAlignment = Bottom | 85 counterText.verticalAlignment = Bottom |
91 | 86 |
92 engine.processEventsFor(panel) | 87 engine.processEvents(button) |
93 | 88 |
94 panel.refresh() | 89 button.refresh() |
95 counterText.refresh() | 90 counterText.refresh() |
96 origin.refresh() | 91 origin.refresh() |
97 help_text.refresh() | 92 help_text.refresh() |
98 | 93 |
99 engine.renderScene(scene) | 94 engine.renderScene(scene) |