diff options
author | chai <chaifix@163.com> | 2021-11-03 18:52:30 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-11-03 18:52:30 +0800 |
commit | 08ddd44b634d4da78edd0964f539a310544c7883 (patch) | |
tree | 108317d9138c3e8a19f3cc3f2ffcfba4768f22d5 | |
parent | 6f62a3d5ad405dbab5ac031fb8eeb03bdb395904 (diff) |
! UI9Slicing
24 files changed, 215 insertions, 47 deletions
diff --git a/Data/Resources/Font/latin.txt b/Data/Configs/latin.txt index e69de29..e69de29 100644 --- a/Data/Resources/Font/latin.txt +++ b/Data/Configs/latin.txt diff --git a/Data/Resources/Font/zh3500.txt b/Data/Configs/zh3500.txt index 154917c..154917c 100644 --- a/Data/Resources/Font/zh3500.txt +++ b/Data/Configs/zh3500.txt diff --git a/Data/DefaultContent/Resources/Images/tile.png b/Data/DefaultContent/Resources/Images/tile.png Binary files differnew file mode 100644 index 0000000..9105f17 --- /dev/null +++ b/Data/DefaultContent/Resources/Images/tile.png diff --git a/Data/Resources/Images/brickwall_small.jpg b/Data/Resources/Images/brickwall_small.jpg Binary files differnew file mode 100644 index 0000000..8a762a2 --- /dev/null +++ b/Data/Resources/Images/brickwall_small.jpg diff --git a/Data/Resources/Images/tile.png b/Data/Resources/Images/tile.png Binary files differnew file mode 100644 index 0000000..8933ea6 --- /dev/null +++ b/Data/Resources/Images/tile.png diff --git a/Data/Resources/Shaders/Editor-UI.glsl b/Data/Resources/Shaders/Editor-UI.glsl index 91aeb01..b831d6c 100644 --- a/Data/Resources/Shaders/Editor-UI.glsl +++ b/Data/Resources/Shaders/Editor-UI.glsl @@ -1,32 +1,46 @@ + #version 330 core -VSH_BEGIN +CMD_BEGIN +Cull Off +Blend SrcAlpha OneMinusSrcAlpha +DepthTest Off +CMD_END + +uniform mat4 gamelab_mat_mvp; +uniform sampler2D gamelab_main_tex; +uniform vec2 gamelab_ui_position; +VSH_BEGIN layout (location = 0) in vec2 vPos; layout (location = 1) in vec2 vUV; - -uniform mat4 mvp; +layout (location = 2) in vec4 vColor; out vec2 uv; +out vec4 color; void main() { - vec4 clip = mvp * vec4(vPos, -1, 1.0); + vec2 pos = vPos + gamelab_ui_position; + vec4 clip = gamelab_mat_mvp * vec4(pos, -1, 1.0); gl_Position = clip; uv = vUV; + color = vColor; } - VSH_END FSH_BEGIN -uniform sampler2D uiTex; - in vec2 uv; +in vec4 color; out vec4 FragColor; void main() { - FragColor = texture(uiTex, uv); + //vec2 uv = vec2(uv.x, 1 - uv.y); + vec4 sampled = texture(gamelab_main_tex, uv); + // sampled *= color; + //sampled = vec4(1,1,1,1); + FragColor = sampled; } FSH_END diff --git a/Data/Scripts/Editor/AssetBrowser.lua b/Data/Scripts/Editor/AssetBrowser.lua index 8d8efa6..177d073 100644 --- a/Data/Scripts/Editor/AssetBrowser.lua +++ b/Data/Scripts/Editor/AssetBrowser.lua @@ -17,7 +17,8 @@ local tex AssetBrowser.OnGUI = function(self)
if tex == nil then
- tex = Engine.Resource.LoadTexture("./Resources/Images/brickwall.jpg")
+ tex = Engine.Resource.LoadTexture("./Resources/Images/tile.png")
+ --tex = Engine.Resource.LoadTexture("./Resources/Images/brickwall_small.jpg")
end
if shader == nil then
@@ -30,15 +31,16 @@ AssetBrowser.OnGUI = function(self) ortho:SetOrtho(0, 400, 400, 0, 0.1, 10)
Debug.Log("AssetBrowser.OnGUI()")
- GL.ClearColor({0.1,0.1,0.1,1})
+ GL.ClearColor({0.13, 0.13, 0.13, 1})
GL.Clear(GL.EBufferType.ColorBuffer)
Engine.Rendering.UseShader(shader)
Engine.Rendering.SetMatrix44("gamelab_mat_mvp", ortho)
Engine.Rendering.SetVector2("gamelab_ui_position", {0, 0})
--Engine.Rendering.SetTexture("gamelab_main_tex", tex)
- --Engine.Rendering.DrawUIQuad({0, 0, 10, 20})
- _G["default_font"]:GetCharacters("你好世界!Hello,World! Project Window Properties", 12)
+ --Engine.Rendering.DrawUIQuad({0, 0, 200, 200})
+ _G["default_font"]:GetCharacters("你好世界!Hello,World! Project Window Properties", 12)
+ --Engine.Rendering.DrawUI9Slicing(1, {25, 25}, {25, 25}, {80, 80}, {200, 200} )
Engine.Rendering.ResetUniformState()
end
diff --git a/Data/Scripts/EditorApplication.lua b/Data/Scripts/EditorApplication.lua index 0aae504..535136b 100644 --- a/Data/Scripts/EditorApplication.lua +++ b/Data/Scripts/EditorApplication.lua @@ -113,7 +113,7 @@ local fsh = [[ BeforeMainLoop() -local font = Engine.GUI.Font.New("./Resources/Font/simsun.ttc", {512, 512}, 5, 5) +local font = Engine.GUI.Font.New("./Resources/Font/msyh.ttc", {512, 512}, 5, 5) _G["default_font"] = font while true do diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj b/Projects/VisualStudio/Editor/Editor.vcxproj index 9b2fbe0..6df4713 100644 --- a/Projects/VisualStudio/Editor/Editor.vcxproj +++ b/Projects/VisualStudio/Editor/Editor.vcxproj @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
@@ -181,6 +181,7 @@ <ClCompile Include="..\..\..\Runtime\FileSystem\ImageJobs.cpp" />
<ClCompile Include="..\..\..\Runtime\FileSystem\Path.cpp" />
<ClCompile Include="..\..\..\Runtime\FileSystem\Unzip.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\Color.cpp" />
<ClCompile Include="..\..\..\Runtime\Graphics\CustomVertexLayout.cpp" />
<ClCompile Include="..\..\..\Runtime\Graphics\DefaultVertexLayout.cpp" />
<ClCompile Include="..\..\..\Runtime\Graphics\GfxDevice.cpp" />
diff --git a/Runtime/GUI/Font.cpp b/Runtime/GUI/Font.cpp index 8a5acea..1993126 100644 --- a/Runtime/GUI/Font.cpp +++ b/Runtime/GUI/Font.cpp @@ -16,7 +16,7 @@ using namespace character; static std::string s_FontError; static std::vector<unsigned char> s_PixelBuffer; -static int s_SizePerPixel = sizeof(unsigned char); +static const int s_SizePerPixel = sizeof(unsigned char); Font::Font(std::string path, TextGeneratingSettings settings) : LuaBind::NativeClass<Font>() @@ -98,7 +98,7 @@ Font::Font(LuaBind::VM* vm, DataBuffer* db, TextGeneratingSettings settings) } } -character::Hash Font::GetHash(Codepoint codepoint, int pixelSize) +character::Hash Font::GetHash(Unicode codepoint, int pixelSize) { character::Hash hash; hash.codepoint = codepoint; @@ -106,7 +106,7 @@ character::Hash Font::GetHash(Codepoint codepoint, int pixelSize) return hash; } -const Character* Font::GetCharacter(character::Codepoint codepoint, int pixelSize) +const Character* Font::GetCharacter(character::Unicode codepoint, int pixelSize) { character::Hash hash = GetHash(codepoint, pixelSize); auto iter = m_Characters.find(hash); @@ -125,7 +125,7 @@ const Character* Font::GetCharacter(character::Codepoint codepoint, int pixelSiz return &iter->second; } -void Font::RenderCharacters(character::Codepoint* codepoint, int n, int pixelSize) +void Font::RenderCharacters(character::Unicode* codepoint, int n, int pixelSize) { for (int i = 0; i < n; ++i) { @@ -133,7 +133,7 @@ void Font::RenderCharacters(character::Codepoint* codepoint, int n, int pixelSiz } } -void Font::RenderCharacters(std::vector<character::Codepoint>& codepoint, int pixelSize) +void Font::RenderCharacters(std::vector<character::Unicode>& codepoint, int pixelSize) { int n = codepoint.size(); for (int i = 0; i < n; ++i) @@ -142,7 +142,7 @@ void Font::RenderCharacters(std::vector<character::Codepoint>& codepoint, int pi } } -bool Font::RenderCharacter(character::Codepoint codepoint, int pixelSize) +bool Font::RenderCharacter(character::Unicode codepoint, int pixelSize) { character::Hash hash = GetHash(codepoint, pixelSize); if (m_Characters.count(hash) != 0) @@ -318,7 +318,7 @@ bool Font::HasEnoughSpace(GlyphAtals* atlas, Internal::Vector2 preferSize) return false; } -Character GetCharacter(character::Codepoint Codepoint, int pixelSize) +Character GetCharacter(character::Unicode Unicode, int pixelSize) { return Character(); } diff --git a/Runtime/GUI/Font.h b/Runtime/GUI/Font.h index 067a364..5fbe981 100644 --- a/Runtime/GUI/Font.h +++ b/Runtime/GUI/Font.h @@ -24,15 +24,15 @@ struct Character { namespace character { #if GAMELAB_WIN - typedef unsigned short Codepoint; // unicode CodepointBMPU+0000U+FFFF) + typedef unsigned short Unicode; // unicode codepointBMPU+0000U+FFFF) #else - typedef unsigned int Codepoint; // unicode CodepointBMPU+0000U+FFFF) + typedef unsigned int Unicode; // unicode codepointBMPU+0000U+FFFF) #endif union Hash { unsigned int hashCode; struct { - Codepoint codepoint; + Unicode codepoint; unsigned short size;//С }; bool operator==(const Hash &other) const @@ -44,7 +44,7 @@ namespace character struct UnicodeString { - character::Codepoint* str; + character::Unicode* str; int length; }; @@ -104,13 +104,13 @@ public: Font(DataBuffer* db, TextGeneratingSettings setting)/*throw FontException*/; Font(LuaBind::VM* vm, DataBuffer* db, TextGeneratingSettings setting)/*throw FontException*/; - const Character* GetCharacter(character::Codepoint codepoint, int pixelSize); + const Character* GetCharacter(character::Unicode codepoint, int pixelSize); const GlyphAtals* GetGlyphAtlas(int index); // pre-bake - bool RenderCharacter(character::Codepoint codepoint, int pixelSize); - void RenderCharacters(character::Codepoint* codepoint, int n, int pixelSize); - void RenderCharacters(std::vector<character::Codepoint>& codepoint, int pixelSize); + bool RenderCharacter(character::Unicode codepoint, int pixelSize); + void RenderCharacters(character::Unicode* codepoint, int n, int pixelSize); + void RenderCharacters(std::vector<character::Unicode>& codepoint, int pixelSize); GET(Vector2, AtlasSize, m_AtlasSize); @@ -119,7 +119,7 @@ private: GlyphAtals* RequestAtlas(int pixelSize, Vector2 preferSize); Rect GetRenderChartAndMove(GlyphAtals* atlas, Vector2 preferSize); bool HasEnoughSpace(GlyphAtals* atlas, Vector2 preferSize); - character::Hash GetHash(character::Codepoint Codepoint, int pixelSize); + character::Hash GetHash(character::Unicode Unicode, int pixelSize); //------------------------------------------------------------------------- diff --git a/Runtime/GUI/UI9Slicing.cpp b/Runtime/GUI/UI9Slicing.cpp index 01a0143..d4c48ca 100644 --- a/Runtime/GUI/UI9Slicing.cpp +++ b/Runtime/GUI/UI9Slicing.cpp @@ -1,6 +1,13 @@ #include "UI9Slicing.h" +#include "Runtime/Math/MathHelper.h" +#include <cstring> -UI9Slicing::UI9Slicing(ESlicing mode, Vector2 horizontal, Vector2 vertical, Vector2 texPixelSize, Vector2 size) +using namespace std; + +static vector<UIVertexLayout> s_Vertices; +static vector<UIIndex> s_Indices; + +UI9Slicing::UI9Slicing(int mode, Vector2 horizontal, Vector2 vertical, Vector2 texPixelSize, Vector2 size) { m_Slicing = mode; m_Horizontal = horizontal.Clamp(0, texPixelSize.x, 0, texPixelSize.x); @@ -16,15 +23,87 @@ UI9Slicing::UI9Slicing(ESlicing mode, Vector2 horizontal, Vector2 vertical, Vect void UI9Slicing::Draw() { + s_Indices.clear(); + s_Vertices.clear(); + Vector2 tileSize = Vector2(m_TexSize.x - m_Horizontal[0] - m_Horizontal[1], m_TexSize.y - m_Vertical[0] - m_Vertical[1]); + Vector2 fillSize = Vector2(m_Size.x - m_Horizontal[0] - m_Horizontal[1], m_Size.y - m_Vertical[0] - m_Vertical[1]); + // horizonalverticalӦuvעuv½ǣmeshϽ + Vector2 tileUVx = Vector2(m_Horizontal[0] / m_TexSize.x, (m_TexSize.x - m_Horizontal[1]) / m_TexSize.x); + Vector2 tileUVy = Vector2((m_TexSize.y - m_Vertical[0]) / m_TexSize.y, m_Vertical[1] / m_TexSize.y); - uint8* vb; - uint16* ib; + // fill vertices + int row = 2 + ((fillSize.y <= 0) ? 0 : (m_Slicing == Slicing_Simple ? 2 : ceilf((float)fillSize.y / tileSize.y) + 1)); + int colum = 2 + ((fillSize.x <= 0) ? 0 : (m_Slicing == Slicing_Simple ? 2 : ceilf((float)fillSize.x / tileSize.x) + 1)); - g_SharedVBO.GetChunk(sizeof(UIVertexLayout), sizeof(uint16), 4, 6, Primitive_Triangle, (void**)&vb, (void**)&ib); + for (int r = 0; r < row; ++r) + { + UIVertexLayout vert; + vert.color = Color32::white; + if (r == 0) + { + vert.position.y = 0; + vert.uv.y = 1; + } + else if (r == row - 1) + { + vert.position.y = m_Size.y; + vert.uv.y = 0; + } + else { + if (m_Slicing == Slicing_Tiled) { + vert.position.y = clamp(m_Vertical[0] + (r - 1) * tileSize.y, m_Vertical[0], m_Size.y - m_Vertical[1]); + vert.uv.y = odd(r - 1) ? tileUVy[1] : tileUVy[0]; + } else { + vert.position.y = odd(r - 1) ? m_Size.y - m_Vertical[1] : m_Vertical[0]; + vert.uv.y = odd(r - 1) ? tileUVy[1] : tileUVy[0]; + } + } + for (int c = 0; c < colum; ++c) + { + if (c == 0) + { + vert.position.x = 0; + vert.uv.x = 0; + } + else if (c == colum - 1) + { + vert.position.x = m_Size.x; + vert.uv.x = 1; + } + else { + if (m_Slicing == Slicing_Tiled) { + vert.position.x = clamp(m_Horizontal[0] + (c - 1) * tileSize.x, m_Horizontal[0], m_Size.x - m_Horizontal[0]); + vert.uv.x = odd(c - 1) ? tileUVx[1] : tileUVx[0]; + } else { + vert.position.x = odd(c - 1) ? (m_Size.x - m_Horizontal[1]) : m_Horizontal[0]; + vert.uv.x = odd(c - 1) ? tileUVx[1] : tileUVx[0]; + } + } + s_Vertices.push_back(vert); + if (c < colum - 1 && r < row - 1) { + int index = c + r * colum; + s_Indices.push_back(index); s_Indices.push_back(index + colum); s_Indices.push_back(index + colum + 1); + s_Indices.push_back(index + colum + 1); s_Indices.push_back(index + 1); s_Indices.push_back(index); + } + } + } + void* vb; + void* ib; - g_SharedVBO.ReleaseChunk(4, 6); - g_SharedVBO.DrawChunk(UIMesh::s_UIVertexLayout); -} + int vertCount = s_Vertices.size(); + int indicesCount = s_Indices.size(); + + g_SharedVBO.GetChunk(sizeof(UIVertexLayout), sizeof(UIIndex), vertCount, indicesCount, Primitive_Triangle, &vb, &ib); + + memcpy(vb, &s_Vertices[0], vertCount * sizeof(UIVertexLayout)); + memcpy(ib, &s_Indices[0], indicesCount* sizeof(UIIndex)); + + s_Indices.resize(0); + s_Vertices.resize(0); + + g_SharedVBO.ReleaseChunk(vertCount, indicesCount); + g_SharedVBO.DrawChunk(s_UIVertexLayout); +}
\ No newline at end of file diff --git a/Runtime/GUI/UI9Slicing.h b/Runtime/GUI/UI9Slicing.h index c88ba05..98d8cf8 100644 --- a/Runtime/GUI/UI9Slicing.h +++ b/Runtime/GUI/UI9Slicing.h @@ -12,14 +12,14 @@ enum ESlicing class UI9Slicing : public UIMesh { public: - UI9Slicing(ESlicing mode, Vector2 horizontal, Vector2 vertical, Vector2 texPixelSize, Vector2 size)/*throw UIMeshException*/; + UI9Slicing(int mode, Vector2 horizontal, Vector2 vertical, Vector2 texPixelSize, Vector2 size)/*throw UIMeshException*/; void Draw() override; private: - ESlicing m_Slicing; - Vector2 m_Horizontal; // иߵߺұߵľ - Vector2 m_Vertical; // ͬ + int m_Slicing; + Vector2 m_Horizontal; // иߵߺұߵľ + Vector2 m_Vertical; // иߵµľ Vector2 m_TexSize; Vector2 m_Size; }; diff --git a/Runtime/GUI/UIMesh.h b/Runtime/GUI/UIMesh.h index dd83e6e..8b6b56d 100644 --- a/Runtime/GUI/UIMesh.h +++ b/Runtime/GUI/UIMesh.h @@ -11,11 +11,20 @@ struct UIVertexLayout { + UIVertexLayout(Vector2 pos = Vector2::zero, Vector2 texCoord = Vector2::zero, Color32 col = Color32()) + { + position = pos; + uv = texCoord; + color = col; + } + Vector2 position; Vector2 uv; Color32 color; }; +typedef uint16 UIIndex; + CustomException(UIMeshException); // еUIMeshϽΪԭ diff --git a/Runtime/GUI/UITextMesh.cpp b/Runtime/GUI/UITextMesh.cpp index 823335f..abb5231 100644 --- a/Runtime/GUI/UITextMesh.cpp +++ b/Runtime/GUI/UITextMesh.cpp @@ -69,7 +69,7 @@ UITextMesh::UITextMesh(const UnicodeString& str, Font* font,int pixelSize, EText float offset = 0; for (int i = 0; i < str.length; ++i) { - character::Codepoint c = str.str[i]; + character::Unicode c = str.str[i]; const Character* ch = font->GetCharacter(c, pixelSize); if (ch == NULL) continue; diff --git a/Runtime/Graphics/Color.cpp b/Runtime/Graphics/Color.cpp new file mode 100644 index 0000000..7e792e6 --- /dev/null +++ b/Runtime/Graphics/Color.cpp @@ -0,0 +1,4 @@ +#include "Color.h"
+
+const Color32 Color32::white = Color32(255, 255, 255, 255); +
diff --git a/Runtime/Graphics/Color.h b/Runtime/Graphics/Color.h index ebccafe..41ca2a4 100644 --- a/Runtime/Graphics/Color.h +++ b/Runtime/Graphics/Color.h @@ -41,6 +41,8 @@ namespace Internal this->a = a; } unsigned char r, g, b, a; + + static const Color32 white; }; } diff --git a/Runtime/Graphics/GPUDataBuffer.cpp b/Runtime/Graphics/GPUDataBuffer.cpp index 707cacb..f5149d9 100644 --- a/Runtime/Graphics/GPUDataBuffer.cpp +++ b/Runtime/Graphics/GPUDataBuffer.cpp @@ -12,6 +12,7 @@ namespace GPU DataBuffer::DataBuffer() { glGenBuffers(1, &m_Handle); + m_Size = 0; } DataBuffer::~DataBuffer() diff --git a/Runtime/Graphics/RenderCommands.h b/Runtime/Graphics/RenderCommands.h index 123e6f0..ecb0904 100644 --- a/Runtime/Graphics/RenderCommands.h +++ b/Runtime/Graphics/RenderCommands.h @@ -70,6 +70,7 @@ struct Cmd_Blend : RenderCommand if (!enable) glDisable(GL_BLEND); glEnable(GL_BLEND); + glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
GLenum src, dst; switch (srcFac) { diff --git a/Runtime/Graphics/Texture.cpp b/Runtime/Graphics/Texture.cpp index a1f4181..0cabd07 100644 --- a/Runtime/Graphics/Texture.cpp +++ b/Runtime/Graphics/Texture.cpp @@ -84,7 +84,22 @@ void Texture::Init(TextureSetting setting, ImageData* imgData) break;
}
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, imgData->width, imgData->height, 0, GL_RGB, GL_UNSIGNED_BYTE, imgData->pixels);
+ GLint srcFormat = GL_RGB;
+ switch (imgData->format)
+ {
+ case PixelFormat_R: srcFormat = GL_RED; break;
+ case PixelFormat_RGB: srcFormat = GL_RGB; break;
+ case PixelFormat_RGBA: srcFormat = GL_RGBA; break;
+ default: Assert(false);
+ }
+ GLint srcType = GL_UNSIGNED_BYTE;
+ switch (imgData->type)
+ {
+ case PixelType_UNSIGNED_BYTE: srcType = GL_UNSIGNED_BYTE; break;
+ default: Assert(false);
+ }
+
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imgData->width, imgData->height, 0, srcFormat, srcType, imgData->pixels);
CheckGLError(
glDeleteTextures(1, &m_GPUID);
diff --git a/Runtime/Math/MathHelper.h b/Runtime/Math/MathHelper.h index 3f8754a..c41eec9 100644 --- a/Runtime/Math/MathHelper.h +++ b/Runtime/Math/MathHelper.h @@ -9,3 +9,6 @@ #define clamp(v, lo, hi)\ max((lo), min((v), (hi))) +// 10 +#define odd(n) \ +(((n)&1)?1:0) diff --git a/Runtime/Scripting/GUI/Font.bind.cpp b/Runtime/Scripting/GUI/Font.bind.cpp index 2d01925..7172027 100644 --- a/Runtime/Scripting/GUI/Font.bind.cpp +++ b/Runtime/Scripting/GUI/Font.bind.cpp @@ -7,10 +7,10 @@ #include "Runtime/Utilities/StaticInitiator.h"
#include "Runtime/GUI/UITextMesh.h"
-static std::vector<character::Codepoint>* s_Codepoints;
+static std::vector<character::Unicode>* s_Codepoints;
InitializeStaticVariables([](){
- s_Codepoints = new std::vector<character::Codepoint>();
+ s_Codepoints = new std::vector<character::Unicode>();
});
LUA_BIND_REGISTRY(Font) diff --git a/Runtime/Scripting/Rendering/Rendering.bind.cpp b/Runtime/Scripting/Rendering/Rendering.bind.cpp index 0b00fa3..c9332f8 100644 --- a/Runtime/Scripting/Rendering/Rendering.bind.cpp +++ b/Runtime/Scripting/Rendering/Rendering.bind.cpp @@ -3,6 +3,7 @@ #include "Runtime/Graphics/ImageData.h" #include "Runtime/Graphics/GfxDevice.h" #include "Runtime/GUI/UIQuad.h" +#include "Runtime/GUI/UI9Slicing.h" // Rendering.DrawUIQuad({}) static int DrawUIQuad(lua_State* L) @@ -20,8 +21,27 @@ static int ResetUniformState(lua_State* L) return 0; } +// mode, horizontal, vertical, texSize, quadSize +static int DrawUI9Slicing(lua_State* L) +{ + LUA_BIND_STATE(L); + + int mode = state.GetValue<int>(1, ESlicing::Slicing_Simple); + Vector2 horizontal = state.GetValue<Vector2>(2, Vector2::zero); + Vector2 vertical = state.GetValue<Vector2>(3, Vector2::zero); + Vector2 texSize = state.GetValue<Vector2>(4, Vector2::zero); + Vector2 quadSize = state.GetValue<Vector2>(5, Vector2::zero); + + UI9Slicing slicing = UI9Slicing(mode, horizontal, vertical, texSize, quadSize); + + slicing.Draw(); + + return 0; +} + static luaL_Reg funcs[] = { {"DrawUIQuad", DrawUIQuad}, + {"DrawUI9Slicing", DrawUI9Slicing}, {"ResetUniformState", ResetUniformState}, {0, 0} }; diff --git a/Runtime/Scripting/Resource/Resource.bind.cpp b/Runtime/Scripting/Resource/Resource.bind.cpp index a09460e..a10ed69 100644 --- a/Runtime/Scripting/Resource/Resource.bind.cpp +++ b/Runtime/Scripting/Resource/Resource.bind.cpp @@ -32,8 +32,25 @@ int LoadImageData(lua_State* L) ImageData* data = new ImageData(state.GetVM()); int channels; data->pixels = stbi_load(path, &data->width, &data->height, &channels, 0); - data->format = EPixelFormat::PixelFormat_RGB; - data->type = EPixelElementType::PixelType_UNSIGNED_BYTE; + if (channels == 1) + { + data->format = EPixelFormat::PixelFormat_R; + data->type = EPixelElementType::PixelType_UNSIGNED_BYTE; + } + else if (channels == 3) + { + data->format = EPixelFormat::PixelFormat_RGB; + data->type = EPixelElementType::PixelType_UNSIGNED_BYTE; + } + else if(channels == 4) + { + data->format = EPixelFormat::PixelFormat_RGBA; + data->type = EPixelElementType::PixelType_UNSIGNED_BYTE; + } + else + { + Assert(false); // ʱ֧ʽ + } data->PushUserdata(state); return 1; |