annotate tests/test_panel.nim @ 894:2aa26c23cc60

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