summaryrefslogtreecommitdiff
path: root/Runtime
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-11-20 17:32:55 +0800
committerchai <chaifix@163.com>2021-11-20 17:32:55 +0800
commitbb452bba78dc1870d6316b383180472fe3a8a06a (patch)
tree6084d6c608e00f28fe4b1437e0df228d68c268de /Runtime
parent74ca8143a7c2352425d549b681b2838bda5ee218 (diff)
*gui
Diffstat (limited to 'Runtime')
-rw-r--r--Runtime/Graphics/Shader.h2
-rw-r--r--Runtime/Lua/LuaHelper.cpp28
-rw-r--r--Runtime/Scripting/GUI/GUI.bind.cpp21
-rw-r--r--Runtime/Scripting/Rendering/Shader.bind.cpp17
4 files changed, 63 insertions, 5 deletions
diff --git a/Runtime/Graphics/Shader.h b/Runtime/Graphics/Shader.h
index 14d022b..8747a7b 100644
--- a/Runtime/Graphics/Shader.h
+++ b/Runtime/Graphics/Shader.h
@@ -53,7 +53,7 @@ private:
LUA_BIND_DECL_METHOD(_SetMatrix3);
LUA_BIND_DECL_METHOD(_SetMatrix4);
LUA_BIND_DECL_METHOD(_SetTexture);
- //LUA_BIND_DECL_METHOD(_SetColor);
+ LUA_BIND_DECL_METHOD(_SetColor);
};
diff --git a/Runtime/Lua/LuaHelper.cpp b/Runtime/Lua/LuaHelper.cpp
index 084d4f6..b7bf543 100644
--- a/Runtime/Lua/LuaHelper.cpp
+++ b/Runtime/Lua/LuaHelper.cpp
@@ -114,6 +114,34 @@ Color32 State::GetValue < Color32 >(int idx, const Color32 value)
}
template <>
+Color State::GetValue < Color >(int idx, const Color value)
+{
+ Color col = value;
+ if (LuaHelper::IsType(*this, "GameLab.Engine.Rendering.Color", idx))
+ {
+ col.r = GetField<float>(idx, "r", 0);
+ col.g = GetField<float>(idx, "g", 0);
+ col.b = GetField<float>(idx, "b", 0);
+ col.a = GetField<float>(idx, "a", 0);
+ }
+ else if (LuaHelper::IsType(*this, "GameLab.Engine.Rendering.Color32", idx))
+ {
+ col.r = GetField<int>(idx, "r", 0) / 255.f;
+ col.g = GetField<int>(idx, "g", 0) / 255.f;
+ col.b = GetField<int>(idx, "b", 0) / 255.f;
+ col.a = GetField<int>(idx, "a", 0) / 255.f;
+ }
+ else if (LuaHelper::IsType(*this, "table", idx))
+ {
+ col.r = GetField<float>(idx, 1, 0);
+ col.g = GetField<float>(idx, 2, 0);
+ col.b = GetField<float>(idx, 3, 0);
+ col.a = GetField<float>(idx, 4, 0);
+ }
+ return col;
+}
+
+template <>
Matrix44 State::GetValue < Matrix44 >(int idx, const Matrix44 value)
{
Matrix44 m4 = value;
diff --git a/Runtime/Scripting/GUI/GUI.bind.cpp b/Runtime/Scripting/GUI/GUI.bind.cpp
index e05d373..cc4ef88 100644
--- a/Runtime/Scripting/GUI/GUI.bind.cpp
+++ b/Runtime/Scripting/GUI/GUI.bind.cpp
@@ -12,6 +12,7 @@
#include "Runtime/Utilities/AutoInvoke.h"
#include "Editor/Win/Win.h"
#include "Runtime/GUI/UILine.h"
+#include "Runtime/GUI/UIQuad.h"
using namespace std;
using namespace LuaBind;
@@ -103,10 +104,26 @@ static int DrawLine(lua_State* L)
return 0;
}
+// GUI.DrawQuad(topleft, size)
+static int DrawQuad(lua_State* L)
+{
+ LUA_BIND_STATE(L);
+
+ Vector2f tl, size;
+ tl.RestoreFromLuaObject(state, 1);
+ size.RestoreFromLuaObject(state, 2);
+
+ UIQuad quad = UIQuad(tl.x, tl.x + size.x, tl.y, tl.y + size.y);
+ quad.Draw();
+
+ return 0;
+}
+
static luaL_Reg guiFuncs[] = {
{ "DrawText", DrawText },
- { "DrawLine", DrawLine },
- {0, 0}
+ { "DrawLine", DrawLine },
+ { "DrawQuad", DrawQuad },
+ {0, 0}
};
int luaopen_GameLab_Engine_GUI(lua_State* L)
diff --git a/Runtime/Scripting/Rendering/Shader.bind.cpp b/Runtime/Scripting/Rendering/Shader.bind.cpp
index 4c0c321..a001633 100644
--- a/Runtime/Scripting/Rendering/Shader.bind.cpp
+++ b/Runtime/Scripting/Rendering/Shader.bind.cpp
@@ -16,12 +16,11 @@ LUA_BIND_REGISTRY(Shader)
{ "IsValid", _IsValid },
{ "Use", _Use },
{ "Unuse", _UnUse },
- //{ "SetColor", _SetColor },
+ { "SetColor", _SetColor },
{ "SetTexture", _SetTexture },
{ "SetVector2", _SetVector2 },
{ "SetVector3", _SetVector3 },
{ "SetVector4", _SetVector4 },
- //{ "SetMatrix3", _SetMatrix3 },
{ "SetMatrix44", _SetMatrix4 }
);
}
@@ -165,6 +164,20 @@ LUA_BIND_IMPL_METHOD(Shader, _SetVector4)
return 1;
}
+// SetColor(name, color)
+LUA_BIND_IMPL_METHOD(Shader, _SetColor)
+{
+ LUA_BIND_PREPARE(L, Shader);
+ LUA_BIND_CHECK(L, "ST");
+
+ cc8* name = state.GetValue(1, "");
+ Color col = state.GetValue<Color>(2, Color());
+ Vector4 v = Vector4(col.r, col.g, col.b, col.a);
+
+ g_GfxDevice.SetUniformVec4(name, v);
+ return 1;
+}
+
// shader.SetMatrix4(name, mat4)
// shader.SetMatrix4(name, {})
LUA_BIND_IMPL_METHOD(Shader, _SetMatrix4)