comparison 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
comparison
equal deleted inserted replaced
893:a0826956dc5c 894:2aa26c23cc60
7 # setup engine 7 # setup engine
8 var engine = initEngine("Test panels") 8 var engine = initEngine("Test panels")
9 engine.initRenderer([]) 9 engine.initRenderer([])
10 10
11 # build scene 11 # build scene
12 var scene = Scene(name: "main") 12 var
13 var panel = Panel(position: newVec2f(0, 0), size: newVec2f(0.1, 0.1)) 13 font = loadFont("DejaVuSans.ttf", lineHeightPixels = 210'f32)
14 scene = Scene(name: "main")
15 origin = initPanel(size = newVec2f(0.01, 0.01), color = newVec4f(0, 0, 0, 1))
16 panel = initPanel(size = newVec2f(0.2, 0.2), color = newVec4f(1, 0, 0, 1))
17 help_text = font.initText("""Controls
18
19 Horizontal alignment:
20 F1: Left
21 F2: Center
22 F3: Right
23 Vertical alignment:
24 F4: Top
25 F5: Center
26 F6: Bottom""", scale = 0.0002, position = newVec2f(-0.9, -0.9), horizontalAlignment = Left, verticalAlignment = Top)
14 27
15 scene.add panel 28 scene.add panel
29 scene.add help_text
30 scene.add origin
16 engine.loadScene(scene) 31 engine.loadScene(scene)
17 32
18 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): 33 while engine.updateInputs() == Running and not engine.keyIsDown(Escape):
19 if engine.windowWasResized(): 34 if engine.windowWasResized():
20 var winSize = engine.getWindow().size 35 var winSize = engine.getWindow().size
21 panel.aspect_ratio = winSize[0] / winSize[1] 36 panel.aspect_ratio = winSize[0] / winSize[1]
37 origin.aspect_ratio = winSize[0] / winSize[1]
38 help_text.aspect_ratio = winSize[0] / winSize[1]
39
40 if engine.keyWasPressed(F1): panel.horizontalAlignment = Left
41 elif engine.keyWasPressed(F2): panel.horizontalAlignment = Center
42 elif engine.keyWasPressed(F3): panel.horizontalAlignment = Right
43 elif engine.keyWasPressed(F4): panel.verticalAlignment = Top
44 elif engine.keyWasPressed(F5): panel.verticalAlignment = Center
45 elif engine.keyWasPressed(F6): panel.verticalAlignment = Bottom
46
47 panel.refresh()
48 origin.refresh()
49 help_text.refresh()
22 50
23 engine.renderScene(scene) 51 engine.renderScene(scene)
24 engine.destroy() 52 engine.destroy()
25 53
26 54