comparison tests/test_text.nim @ 1238:03634915bbdb

add: tests for updating texts, does not pass validation atm
author sam <sam@basx.dev>
date Sun, 21 Jul 2024 11:31:11 +0700
parents 97813ac43cfb
children 69489a678141
comparison
equal deleted inserted replaced
1237:97813ac43cfb 1238:03634915bbdb
1 import std/os 1 import std/os
2 import std/strutils
2 import std/sequtils 3 import std/sequtils
3 import std/monotimes 4 import std/monotimes
4 import std/times 5 import std/times
5 import std/options 6 import std/options
6 import std/random 7 import std/random
46 var labels = [ 47 var labels = [
47 InitTextbox( 48 InitTextbox(
48 renderdata, 49 renderdata,
49 pipeline.descriptorSetLayouts[0], 50 pipeline.descriptorSetLayouts[0],
50 font1, 51 font1,
51 "0", 52 " 0",
52 color = NewVec4f(0, 1, 1, 1), 53 color = NewVec4f(0, 1, 1, 1),
53 scale = 0.004, 54 scale = 0.004,
54 position = NewVec3f(-0.3, 0.5) 55 position = NewVec3f(-0.3, 0.5)
55 ), 56 ),
56 InitTextbox( 57 InitTextbox(
57 renderdata, 58 renderdata,
58 pipeline.descriptorSetLayouts[0], 59 pipeline.descriptorSetLayouts[0],
59 font2, 60 font2,
60 "1", 61 " 1",
61 color = NewVec4f(1, 0, 1, 1), 62 color = NewVec4f(1, 0, 1, 1),
62 scale = 0.001, 63 scale = 0.001,
63 position = NewVec3f(0, 0) 64 position = NewVec3f(0, 0)
64 ), 65 ),
65 InitTextbox( 66 InitTextbox(
66 renderdata, 67 renderdata,
67 pipeline.descriptorSetLayouts[0], 68 pipeline.descriptorSetLayouts[0],
68 font3, 69 font3,
69 "2", 70 " 2",
70 color = NewVec4f(1, 1, 0, 1), 71 color = NewVec4f(1, 1, 0, 1),
71 scale = 0.001, 72 scale = 0.001,
72 position = NewVec3f(0.3, -0.5) 73 position = NewVec3f(0.3, -0.5)
73 ) 74 )
74 ] 75 ]
75 76
76 var start = getMonoTime() 77 var start = getMonoTime()
78 var p = 0
77 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: 79 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time:
78 let progress = ((getMonoTime() - start).inMilliseconds().int / 1000) / time 80 let progress = ((getMonoTime() - start).inMilliseconds().int / 1000) / time
79 for i in 0 ..< labels.len: 81 for i in 0 ..< labels.len:
80 var c = labels[i].Color 82 var c = labels[i].Color
81 c[i] = progress 83 c[i] = progress
82 labels[i].Color = c 84 labels[i].Color = c
83 labels[i].Scale = labels[i].Scale * 1.002 85 labels[i].Scale = labels[i].Scale * (1.0 + (i + 1).float * 0.001)
84 labels[i].Position = labels[i].Position + NewVec3f(0.001 * (i.float - 1'f)) 86 labels[i].Position = labels[i].Position + NewVec3f(0.001 * (i.float - 1'f))
87 labels[i].text = $(p + i)
85 labels[i].Refresh(swapchain.GetAspectRatio()) 88 labels[i].Refresh(swapchain.GetAspectRatio())
89 inc p
86 WithNextFrame(swapchain, framebuffer, commandbuffer): 90 WithNextFrame(swapchain, framebuffer, commandbuffer):
87 WithRenderPass(swapchain.renderPass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)): 91 WithRenderPass(swapchain.renderPass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)):
88 WithPipeline(commandbuffer, pipeline): 92 WithPipeline(commandbuffer, pipeline):
89 for label in labels: 93 for label in labels:
90 Render(label, commandbuffer, pipeline, swapchain.currentFiF) 94 Render(label, commandbuffer, pipeline, swapchain.currentFiF)