annotate tests/test_panel.nim @ 433:08b8facaf3b7

add: initial implementation of "panels"
author Sam <sam@basx.dev>
date Sat, 10 Feb 2024 15:55:05 +0700
parents e13b75bff00c
children 30cc1deda4c1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
430
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
1 import std/unicode
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
2
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
3 import semicongine
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
4
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
5
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
6 proc main() =
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
7 # setup engine
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
8 var engine = initEngine("Test panels")
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
9 engine.initRenderer([])
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
10
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
11 # build scene
433
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
12 var
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
13 font = loadFont("DejaVuSans.ttf", lineHeightPixels = 210'f32)
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
14 scene = Scene(name: "main")
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
15 origin = initPanel(size = newVec2f(0.01, 0.01), color = newVec4f(0, 0, 0, 1))
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
16 panel = initPanel(size = newVec2f(0.2, 0.2), color = newVec4f(1, 0, 0, 1))
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
17 help_text = font.initText("""Controls
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
18
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
19 Horizontal alignment:
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
20 F1: Left
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
21 F2: Center
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
22 F3: Right
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
23 Vertical alignment:
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
24 F4: Top
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
25 F5: Center
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
26 F6: Bottom""", scale = 0.0002, position = newVec2f(-0.9, -0.9), horizontalAlignment = Left, verticalAlignment = Top)
430
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
27
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
28 scene.add panel
433
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
29 scene.add help_text
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
30 scene.add origin
430
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
31 engine.loadScene(scene)
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
32
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
33 while engine.updateInputs() == Running and not engine.keyIsDown(Escape):
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
34 if engine.windowWasResized():
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
35 var winSize = engine.getWindow().size
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
36 panel.aspect_ratio = winSize[0] / winSize[1]
433
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
37 origin.aspect_ratio = winSize[0] / winSize[1]
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
38 help_text.aspect_ratio = winSize[0] / winSize[1]
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
39
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
40 if engine.keyWasPressed(F1): panel.horizontalAlignment = Left
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
41 elif engine.keyWasPressed(F2): panel.horizontalAlignment = Center
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
42 elif engine.keyWasPressed(F3): panel.horizontalAlignment = Right
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
43 elif engine.keyWasPressed(F4): panel.verticalAlignment = Top
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
44 elif engine.keyWasPressed(F5): panel.verticalAlignment = Center
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
45 elif engine.keyWasPressed(F6): panel.verticalAlignment = Bottom
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
46
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
47 panel.refresh()
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
48 origin.refresh()
08b8facaf3b7 add: initial implementation of "panels"
Sam <sam@basx.dev>
parents: 431
diff changeset
49 help_text.refresh()
430
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
50
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
51 engine.renderScene(scene)
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
52 engine.destroy()
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
53
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
54
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
55 when isMainModule:
c5999345f42c add: panels
Sam <sam@basx.dev>
parents:
diff changeset
56 main()