changeset 431:e13b75bff00c

intermediate commit :P
author Sam <sam@basx.dev>
date Fri, 09 Feb 2024 20:02:55 +0700
parents c5999345f42c
children 2b373a03cf64
files semicongine.nim semicongine/panel.nim tests/test_panel.nim
diffstat 3 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/semicongine.nim	Mon Feb 05 23:11:22 2024 +0700
+++ b/semicongine.nim	Fri Feb 09 20:02:55 2024 +0700
@@ -13,6 +13,7 @@
 import semicongine/material
 import semicongine/mesh
 import semicongine/noise
+import semicongine/panel
 import semicongine/renderer
 import semicongine/resources
 import semicongine/settings
@@ -29,6 +30,7 @@
 export material
 export mesh
 export noise
+export panel
 export renderer
 export resources
 export settings
--- a/semicongine/panel.nim	Mon Feb 05 23:11:22 2024 +0700
+++ b/semicongine/panel.nim	Fri Feb 09 20:02:55 2024 +0700
@@ -1,8 +1,11 @@
+import std/strformat
+
 import ./core
+import ./mesh
 
 const
-  SHADER_ATTRIB_PREFIX = "semicon_text_"
-  MAX_TEXT_MATERIALS = 10
+  SHADER_ATTRIB_PREFIX = "semicon_panel_"
+  MAX_PANEL_MATERIALS = 10
 
 var instanceCounter = 0
 
@@ -12,13 +15,27 @@
     size: Vec2f
     color*: Vec4f
 
+    texture: Texture
     horizontalAlignment: HorizontalAlignment = Center
     verticalAlignment: VerticalAlignment = Center
     aspect_ratio: float32
-    texture: Vec4f
     dirty: bool
     mesh: Mesh
 
+proc initPanel*(position = newVec2f(), size = newVec2f(), color = newVec4f(1, 1, 1, 1), texture = EMPTY_TEXTURE, horizontalAlignment = HorizontalAlignment.Center, verticalAlignment = VerticalAlignment.Center): Panel =
+
+  result = Panel(position: position, size: size, color: color, texture: texture, horizontalAlignment: horizontalAlignment, verticalAlignment: verticalAlignment, aspect_ratio: 1)
+
+  inc instanceCounter
+  var
+    positions = newSeq[Vec3f](4)
+    indices = @[
+      [uint16(0), uint16(1), uint16(2)],
+      [uint16(2), uint16(3), uint16(0)],
+    ]
+    uvs = newSeq[Vec2f](4)
+  result.mesh = newMesh(positions = positions, indices = indices, uvs = uvs, name = &"panel-{instanceCounter}")
+
 proc position*(panel: Panel): Vec2f =
   panel.position
 proc `position=`*(panel: var Panel, value: Vec2f) =
--- a/tests/test_panel.nim	Mon Feb 05 23:11:22 2024 +0700
+++ b/tests/test_panel.nim	Fri Feb 09 20:02:55 2024 +0700
@@ -10,7 +10,7 @@
 
   # build scene
   var scene = Scene(name: "main")
-  var panel = initPanel(position: newVec2f(0, 0), size: newVec2f(0.1, 0.1))
+  var panel = Panel(position: newVec2f(0, 0), size: newVec2f(0.1, 0.1))
 
   scene.add panel
   engine.loadScene(scene)