Mercurial > games > semicongine
comparison tests/test_panel.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 |
---|---|
26 const B = [0'u8, 0'u8, 0'u8, 255'u8] | 26 const B = [0'u8, 0'u8, 0'u8, 255'u8] |
27 const T = [0'u8, 0'u8, 0'u8, 0'u8] | 27 const T = [0'u8, 0'u8, 0'u8, 0'u8] |
28 # build scene | 28 # build scene |
29 # | 29 # |
30 var | 30 var |
31 font = loadFont("DejaVuSans.ttf", lineHeightPixels = 210'f32) | 31 font = LoadFont("DejaVuSans.ttf", lineHeightPixels = 210'f32) |
32 scene = Scene(name: "main") | 32 scene = Scene(name: "main") |
33 origin = initPanel( | 33 origin = InitPanel( |
34 transform = Scale(0.005, 0.005), | 34 transform = Scale(0.005, 0.005), |
35 color = NewVec4f(1, 1, 1, 1), | 35 color = NewVec4f(1, 1, 1, 1), |
36 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), |
37 ) | 37 ) |
38 button = initPanel( | 38 button = InitPanel( |
39 transform = Translate(0.2, 0.1) * Scale(0.3, 0.1), | 39 transform = Translate(0.2, 0.1) * Scale(0.3, 0.1), |
40 color = NewVec4f(1, 0, 0, 0.5), | 40 color = NewVec4f(1, 0, 0, 0.5), |
41 onMouseDown = click, | 41 onMouseDown = click, |
42 onMouseEnter = enter, | 42 onMouseEnter = enter, |
43 onMouseLeave = leave | 43 onMouseLeave = leave |
44 ) | 44 ) |
45 help_text = font.initText("""Controls | 45 help_text = font.InitText("""Controls |
46 | 46 |
47 Horizontal alignment: | 47 Horizontal alignment: |
48 F1: Left | 48 F1: Left |
49 F2: Center | 49 F2: Center |
50 F3: Right | 50 F3: Right |
54 F6: Bottom | 54 F6: Bottom |
55 Mouse: | 55 Mouse: |
56 Left click: Increase counter | 56 Left click: Increase counter |
57 Right click: Decrease counter""".toRunes, horizontalAlignment = Left, verticalAlignment = Top, transform = Translate(-0.9, -0.9) * Scale(0.0002, 0.0002)) | 57 Right click: Decrease counter""".toRunes, horizontalAlignment = Left, verticalAlignment = Top, transform = Translate(-0.9, -0.9) * Scale(0.0002, 0.0002)) |
58 | 58 |
59 counterText = font.initText(($counter).toRunes, maxLen = 99, transform = Translate(0.2, 0.1) * Scale(0.0004, 0.0004)) | 59 counterText = font.InitText(($counter).toRunes, maxLen = 99, transform = Translate(0.2, 0.1) * Scale(0.0004, 0.0004)) |
60 | 60 |
61 scene.add counterText | 61 scene.Add counterText |
62 scene.add button | 62 scene.Add button |
63 scene.add help_text | 63 scene.Add help_text |
64 scene.add origin | 64 scene.Add origin |
65 engine.LoadScene(scene) | 65 engine.LoadScene(scene) |
66 | 66 |
67 while engine.UpdateInputs() and not KeyIsDown(Escape): | 67 while engine.UpdateInputs() and not KeyIsDown(Escape): |
68 if KeyWasPressed(F1): | 68 if KeyWasPressed(F1): |
69 button.horizontalAlignment = Left | 69 button.horizontalAlignment = Left |
84 button.verticalAlignment = Bottom | 84 button.verticalAlignment = Bottom |
85 counterText.verticalAlignment = Bottom | 85 counterText.verticalAlignment = Bottom |
86 | 86 |
87 engine.ProcessEvents(button) | 87 engine.ProcessEvents(button) |
88 | 88 |
89 button.refresh() | 89 button.Refresh() |
90 counterText.refresh() | 90 counterText.Refresh() |
91 origin.refresh() | 91 origin.Refresh() |
92 help_text.refresh() | 92 help_text.Refresh() |
93 | 93 |
94 engine.RenderScene(scene) | 94 engine.RenderScene(scene) |
95 engine.Destroy() | 95 engine.Destroy() |
96 | 96 |
97 | 97 |