430
|
1 import std/unicode
|
|
2
|
|
3 import semicongine
|
|
4
|
|
5
|
|
6 proc main() =
|
|
7 # setup engine
|
|
8 var engine = initEngine("Test panels")
|
|
9 engine.initRenderer([])
|
|
10
|
|
11 # build scene
|
433
|
12 var
|
|
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)
|
430
|
27
|
|
28 scene.add panel
|
433
|
29 scene.add help_text
|
|
30 scene.add origin
|
430
|
31 engine.loadScene(scene)
|
|
32
|
|
33 while engine.updateInputs() == Running and not engine.keyIsDown(Escape):
|
|
34 if engine.windowWasResized():
|
|
35 var winSize = engine.getWindow().size
|
|
36 panel.aspect_ratio = winSize[0] / winSize[1]
|
433
|
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()
|
430
|
50
|
|
51 engine.renderScene(scene)
|
|
52 engine.destroy()
|
|
53
|
|
54
|
|
55 when isMainModule:
|
|
56 main()
|