changeset 825:8a2fae96570c

add anykey-pressed api, extend default charset when loading fonts
author Sam <sam@basx.dev>
date Mon, 02 Oct 2023 10:15:09 +0700
parents 995e273157cd
children 7df5eacf84a0
files src/semicongine/engine.nim src/semicongine/resources.nim src/semicongine/text.nim
diffstat 3 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/semicongine/engine.nim	Sun Oct 01 20:53:35 2023 +0700
+++ b/src/semicongine/engine.nim	Mon Oct 02 10:15:09 2023 +0700
@@ -189,6 +189,7 @@
 # wrappers for internal things
 func keyIsDown*(engine: Engine, key: Key): auto = key in engine.input.keyIsDown
 func keyWasPressed*(engine: Engine, key: Key): auto = key in engine.input.keyWasPressed
+func keyWasPressed*(engine: Engine): auto = engine.input.keyWasPressed.len > 0
 func keyWasReleased*(engine: Engine, key: Key): auto = key in engine.input.keyWasReleased
 func mouseIsDown*(engine: Engine, button: MouseButton): auto = button in engine.input.mouseIsDown
 func mouseWasPressed*(engine: Engine, button: MouseButton): auto = button in engine.input.mouseWasPressed
--- a/src/semicongine/resources.nim	Sun Oct 01 20:53:35 2023 +0700
+++ b/src/semicongine/resources.nim	Mon Oct 02 10:15:09 2023 +0700
@@ -130,7 +130,7 @@
   var thename = name
   if thename == "":
     thename = path.splitFile().name
-  let defaultCharset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_=+[{]};:,<.>/? ".toRunes()
+  let defaultCharset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_=+[{]};:,<.>/? $!@#%^&*()\"'".toRunes()
   loadResource_intern(path).readTrueType(name, defaultCharset, color, resolution)
 
 proc loadMeshes*(path: string): seq[MeshTree] =
--- a/src/semicongine/text.nim	Sun Oct 01 20:53:35 2023 +0700
+++ b/src/semicongine/text.nim	Mon Oct 02 10:15:09 2023 +0700
@@ -7,6 +7,8 @@
 import ./vulkan/shader
 
 const SHADER_ATTRIB_PREFIX = "semicon_text_"
+var instanceCounter = 0
+
 type
   TextAlignment = enum
     Left
@@ -16,7 +18,7 @@
     maxLen*: int
     text: seq[Rune]
     dirty: bool
-    alignment*: TextAlignment
+    alignment*: TextAlignment = Center
     font*: Font
     mesh*: Mesh
 
@@ -103,7 +105,8 @@
     ]
 
   result = Textbox(maxLen: maxLen, text: text, font: font, dirty: true)
-  result.mesh = newMesh(positions = positions, indices = indices, uvs = uvs)
+  result.mesh = newMesh(positions = positions, indices = indices, uvs = uvs, name = &"textbox-{instanceCounter}")
+  inc instanceCounter
   result.mesh[].renameAttribute("position", POSITION_ATTRIB)
   result.mesh[].renameAttribute("uv", UV_ATTRIB)
   result.mesh.materials = @[Material(