# HG changeset patch # User Sam # Date 1707067410 -25200 # Node ID 740d2f0d1264ae129f24c19979001cf243600475 # Parent 545b4c58601f1d168d3cdacd140877dbe5ec8e01 did: small fix with materials & cleanup diff -r 545b4c58601f -r 740d2f0d1264 semicongine/core/utils.nim --- 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): diff -r 545b4c58601f -r 740d2f0d1264 semicongine/material.nim --- 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] diff -r 545b4c58601f -r 740d2f0d1264 semicongine/renderer.nim --- 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" diff -r 545b4c58601f -r 740d2f0d1264 semicongine/text.nim --- 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 diff -r 545b4c58601f -r 740d2f0d1264 tests/test_font.nim --- 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: