Mercurial > games > semicongine
changeset 429:740d2f0d1264
did: small fix with materials & cleanup
author | Sam <sam@basx.dev> |
---|---|
date | Mon, 05 Feb 2024 00:23:30 +0700 |
parents | 545b4c58601f |
children | c5999345f42c |
files | semicongine/core/utils.nim semicongine/material.nim semicongine/renderer.nim semicongine/text.nim tests/test_font.nim |
diffstat | 5 files changed, 21 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/semicongine/core/utils.nim Sun Feb 04 22:07:54 2024 +0700 +++ b/semicongine/core/utils.nim Mon Feb 05 00:23:30 2024 +0700 @@ -2,6 +2,16 @@ import std/strutils import std/strformat +type + HorizontalAlignment* = enum + Left + Center + Right + VerticalAlignment* = enum + Top + Center + Bottom + func cleanString*(str: openArray[char]): string = for i in 0 ..< len(str): if str[i] == char(0):
--- a/semicongine/material.nim Sun Feb 04 22:07:54 2024 +0700 +++ b/semicongine/material.nim Mon Feb 05 00:23:30 2024 +0700 @@ -11,7 +11,7 @@ vertexAttributes*: Table[string, DataType] instanceAttributes*: Table[string, DataType] attributes*: Table[string, DataType] - MaterialData* = object + MaterialData* = ref object # needs to be ref, so we can update stuff from other locations theType*: MaterialType name*: string attributes: Table[string, DataList]
--- a/semicongine/renderer.nim Sun Feb 04 22:07:54 2024 +0700 +++ b/semicongine/renderer.nim Mon Feb 05 00:23:30 2024 +0700 @@ -343,8 +343,6 @@ assert scene in renderer.scenedata let dirty = scene.dirtyShaderGlobals - # if not forceAll and dirty.len == 0: - # return if forceAll: debug "Update uniforms because 'forceAll' was given"
--- a/semicongine/text.nim Sun Feb 04 22:07:54 2024 +0700 +++ b/semicongine/text.nim Mon Feb 05 00:23:30 2024 +0700 @@ -15,18 +15,9 @@ var instanceCounter = 0 type - HorizontalAlignment* = enum - Left - Center - Right - VerticalAlignment* = enum - Top - Center - Bottom Text* = object maxLen*: int font*: Font - color*: Vec4f maxWidth: float32 = 0 # properties: text: seq[Rune] @@ -236,9 +227,14 @@ text.position = value text.dirty = true +proc color*(text: Text): Vec4f = + text.mesh.material["color", 0, Vec4f] +proc `color=`*(text: var Text, value: Vec4f) = + if value != text.color: + text.mesh.material["color", 0] = value + proc horizontalAlignment*(text: Text): HorizontalAlignment = text.horizontalAlignment - proc `horizontalAlignment=`*(text: var Text, value: HorizontalAlignment) = if value != text.horizontalAlignment: text.horizontalAlignment = value
--- a/tests/test_font.nim Sun Feb 04 22:07:54 2024 +0700 +++ b/tests/test_font.nim Mon Feb 05 00:23:30 2024 +0700 @@ -1,3 +1,4 @@ +import std/times import std/unicode import semicongine @@ -26,13 +27,15 @@ scene.add help_text engine.loadScene(scene) mixer[].loadSound("key", "key.ogg") + mixer[].setLevel(0.5) while engine.updateInputs() == Running and not engine.keyIsDown(Escape): + var t = cpuTime() + main_text.color = newVec4f(sin(t) * 0.5 + 0.5, 0.15, 0.15, 1) if engine.windowWasResized(): var winSize = engine.getWindow().size main_text.aspect_ratio = winSize[0] / winSize[1] help_text.aspect_ratio = winSize[0] / winSize[1] - help_text.position = newVec2f(-0.99, -0.99) # add character if main_text.text.len < main_text.maxLen - 1: