diff options
Diffstat (limited to 'Runtime')
-rw-r--r-- | Runtime/GUI/Font.cpp | 11 | ||||
-rw-r--r-- | Runtime/GUI/Font.h | 34 | ||||
-rw-r--r-- | Runtime/GUI/TextMesh.cpp | 0 | ||||
-rw-r--r-- | Runtime/GUI/TextMesh.h | 24 | ||||
-rw-r--r-- | Runtime/GUI/TextMeshGenerator.cpp | 0 | ||||
-rw-r--r-- | Runtime/GUI/TextMeshGenerator.h | 20 | ||||
-rw-r--r-- | Runtime/GUI/utf8.cpp | 415 | ||||
-rw-r--r-- | Runtime/GUI/utf8.h | 113 | ||||
-rw-r--r-- | Runtime/Graphics/DynamicVertexBuffer.h | 4 | ||||
-rw-r--r-- | Runtime/Graphics/VertexBuffer.h | 2 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindClass.hpp | 25 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindState.h | 3 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindUtility.h | 12 | ||||
-rw-r--r-- | Runtime/Math/Math.h | 6 | ||||
-rw-r--r-- | Runtime/Scripting/GUI/Font.bind.cpp | 53 | ||||
-rw-r--r-- | Runtime/Scripting/GUI/GUI.bind.cpp | 6 | ||||
-rw-r--r-- | Runtime/Utilities/IIncrementalTask.h (renamed from Runtime/Utilities/IncrementalTask.h) | 6 |
17 files changed, 672 insertions, 62 deletions
diff --git a/Runtime/GUI/Font.cpp b/Runtime/GUI/Font.cpp index 67a2e3b..e5444f1 100644 --- a/Runtime/GUI/Font.cpp +++ b/Runtime/GUI/Font.cpp @@ -75,7 +75,7 @@ Font::Font(DataBuffer* db, TextGeneratingSettings settings) } } -Font::Font(DataBuffer* db, LuaBind::VM* vm, std::string path, TextGeneratingSettings settings) +Font::Font(LuaBind::VM* vm, DataBuffer* db, TextGeneratingSettings settings) : LuaBind::NativeClass<Font>(vm) { m_AtlasMargin = settings.margin; @@ -124,6 +124,15 @@ void Font::RenderCharacters(character::Codepoint* codepoint, int n, int pixelSiz } } +void Font::RenderCharacters(std::vector<character::Codepoint>& codepoint, int pixelSize) +{ + int n = codepoint.size(); + for (int i = 0; i < n; ++i) + { + RenderCharacter(codepoint[i], pixelSize); + } +} + void Font::RenderCharacter(character::Codepoint codepoint, int pixelSize) { character::Hash hash = GetHash(codepoint, pixelSize); diff --git a/Runtime/GUI/Font.h b/Runtime/GUI/Font.h index 242bd19..344cc00 100644 --- a/Runtime/GUI/Font.h +++ b/Runtime/GUI/Font.h @@ -5,24 +5,29 @@ #include "freetype.h" #include "Runtime/Lua/LuaHelper.h" #include "Runtime/Common/DataBuffer.h" +#include "Runtime/Math/Math.h" #include <string> #include <unordered_map> #include <exception> #include <vector> -//https://learnopengl.com/In-Practice/Text-Rendering +//https://github.com/kaienfr/Font struct Character { unsigned int atlas; // atlas索引 - Internal::Rect position; // 在altas里的位置 - Internal::Vector2 bearing; // 左上角相对于原点的偏移 + Rect position; // 在altas里的位置 + Vector2 bearing; // 左上角相对于原点的偏移 unsigned int advance; // 总宽,算上了间隔 }; namespace character { +#if GAMELAB_WIN typedef unsigned short Codepoint; // unicode Codepoint(BMP,U+0000至U+FFFF) +#else + typedef unsigned int Codepoint; // unicode Codepoint(BMP,U+0000至U+FFFF) +#endif union Hash { unsigned int hashCode; @@ -55,13 +60,13 @@ struct GlyphAtals Texture* altas; // 贴图 int width, height; // 尺寸 - Internal::Vector2 cursor; // 游标,从左上角(0,0)开始 + Vector2 cursor; // 游标,从左上角(0,0)开始 int rowHeight; // 当前行的高度 }; struct TextGeneratingSettings { - Internal::Vector2 atlasSize; // atlas的尺寸 + Vector2 atlasSize; // atlas的尺寸 int margin; // atlas的边界 int padding; // glyph相互之间的间距,防止采样的时候越界 }; @@ -89,20 +94,21 @@ public: Font(std::string path, TextGeneratingSettings setting)/*throw FontException*/; Font(LuaBind::VM* vm, std::string path, TextGeneratingSettings setting)/*throw FontException*/; Font(DataBuffer* db, TextGeneratingSettings setting)/*throw FontException*/; - Font(DataBuffer* db, LuaBind::VM* vm, std::string path, TextGeneratingSettings setting)/*throw FontException*/; + Font(LuaBind::VM* vm, DataBuffer* db, TextGeneratingSettings setting)/*throw FontException*/; const Character* GetCharacter(character::Codepoint codepoint, int pixelSize); const GlyphAtals* GetGlyphAtlas(int index); // pre-bake void RenderCharacter(character::Codepoint codepoint, int pixelSize); - void RenderCharacters(character::Codepoint* codepoint, int n, int pixelSize); + void RenderCharacters(character::Codepoint* codepoint, int n, int pixelSize); + void RenderCharacters(std::vector<character::Codepoint>& codepoint, int pixelSize); private: Texture* CreateAtlas(); - GlyphAtals* RequestAtlas(int pixelSize, Internal::Vector2 preferSize); - Internal::Rect GetRenderChartAndMove(GlyphAtals* atlas, Internal::Vector2 preferSize); - bool HasEnoughSpace(GlyphAtals* atlas, Internal::Vector2 preferSize); + 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); //------------------------------------------------------------------------- @@ -114,9 +120,9 @@ private: bool m_IsEnabled; - Internal::Vector2 m_AtlasSize; - int m_AtlasMargin; - int m_GlyphPadding; + Vector2 m_AtlasSize; + int m_AtlasMargin; + int m_GlyphPadding; FT_Library m_FTLibrary; FT_Face m_FTFace; @@ -132,8 +138,6 @@ private: }; -//#define g_TextGenerator (*Font::Instance()) - namespace TextHelper { diff --git a/Runtime/GUI/TextMesh.cpp b/Runtime/GUI/TextMesh.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Runtime/GUI/TextMesh.cpp diff --git a/Runtime/GUI/TextMesh.h b/Runtime/GUI/TextMesh.h new file mode 100644 index 0000000..7f37e5e --- /dev/null +++ b/Runtime/GUI/TextMesh.h @@ -0,0 +1,24 @@ +#pragma once
+
+enum ETextAnchor
+{
+ TextAnchor_UpperLeft, + TextAnchor_UpperCenter, + TextAnchor_UpperRight, + TextAnchor_MiddleLeft, + TextAnchor_MiddleCenter, + TextAnchor_MiddleRight, + TextAnchor_LowerLeft, + TextAnchor_LowerCenter, + TextAnchor_LowerRight, + TextAnchor_DontCare
+};
+
+enum ETextAlignment { + TextAlignment_Left, + TextAlignment_Center, + TextAlignment_Right, + TextAlignment_Auto, +}; + + diff --git a/Runtime/GUI/TextMeshGenerator.cpp b/Runtime/GUI/TextMeshGenerator.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Runtime/GUI/TextMeshGenerator.cpp diff --git a/Runtime/GUI/TextMeshGenerator.h b/Runtime/GUI/TextMeshGenerator.h new file mode 100644 index 0000000..c5992bd --- /dev/null +++ b/Runtime/GUI/TextMeshGenerator.h @@ -0,0 +1,20 @@ +#pragma once
+
+#include "Runtime/Utilities/IIncrementalTask.h"
+
+// 回收长期没有被使用的text mesh
+class GraduallyReleaseTextMesh : public IIncrementalTask
+{
+public:
+ void Execute() override
+ {
+
+ }
+
+ bool IsDone() override
+ {
+
+ }
+
+};
+
diff --git a/Runtime/GUI/utf8.cpp b/Runtime/GUI/utf8.cpp new file mode 100644 index 0000000..8a3a086 --- /dev/null +++ b/Runtime/GUI/utf8.cpp @@ -0,0 +1,415 @@ +/* + * Description: UTF-8 瀛楃涓茬殑瑙g爜鍜岀紪鐮佸嚱鏁 + * unicode 瀛楃澶勭悊鍑芥暟 + * History: yang@haipo.me, 2013/05/29, create + * + * This code is in the public domain. + * You may use this code any way you wish, private, educational, + * or commercial. It's free. + */ + +# include <stdint.h> +# include <stddef.h> + +# include "utf8.h" + +namespace utf8 +{ + + ucs4_t getu8c(char **src, int *illegal) + { + static char umap[256] = { 0 }; + static int umap_init_flag = 0; + + if (umap_init_flag == 0) + { + int i; + + for (i = 0; i < 0x100; ++i) + { + if (i < 0x80) + { + umap[i] = 1; + } + else if (i >= 0xc0 && i < 0xe0) + { + umap[i] = 2; + } + else if (i >= 0xe0 && i < 0xf0) + { + umap[i] = 3; + } + else if (i >= 0xf0 && i < 0xf8) + { + umap[i] = 4; + } + else if (i >= 0xf8 && i < 0xfc) + { + umap[i] = 5; + } + else if (i >= 0xfc && i < 0xfe) + { + umap[i] = 6; + } + else + { + umap[i] = 0; + } + } + + umap_init_flag = 1; + } + + uint8_t *s = (uint8_t *)(*src); + int r_illegal = 0; + + while (umap[*s] == 0) + { + ++s; + ++r_illegal; + } + + uint8_t *t; + int byte_num; + uint32_t uc; + int i; + + repeat_label: + t = s; + byte_num = umap[*s]; + uc = *s++ & (0xff >> byte_num); + + for (i = 1; i < byte_num; ++i) + { + if (umap[*s]) + { + r_illegal += s - t; + goto repeat_label; + } + else + { + uc = (uc << 6) + (*s & 0x3f); + s += 1; + } + } + + *src = (char *)s; + if (illegal) + { + *illegal = r_illegal; + } + + return uc; + } + + size_t u8decode(char const *str, ucs4_t *des, size_t n, int *illegal) + { + if (n == 0) + return 0; + + char *s = (char *)str; + size_t i = 0; + ucs4_t uc = 0; + int r_illegal_all = 0, r_illegal; + + while ((uc = getu8c(&s, &r_illegal))) + { + if (i < (n - 1)) + { + des[i++] = uc; + r_illegal_all += r_illegal; + } + else + { + break; + } + } + + des[i] = 0; + if (illegal) + { + *illegal = r_illegal_all + r_illegal; + } + + return i; + } + +# define IF_CAN_HOLD(left, n) do { \ + size_t m = (size_t)(n); \ + if ((size_t)(left) < (m + 1)) return -2; \ + (left) -= m; \ +} while (0) + + int putu8c(ucs4_t uc, char **des, size_t *left) + { + if (uc < 0) + return -1; + + if (uc < (0x1 << 7)) + { + IF_CAN_HOLD(*left, 1); + + **des = (char)uc; + *des += 1; + **des = 0; + + return 1; + } + + int byte_num; + + if (uc < (0x1 << 11)) + { + byte_num = 2; + } + else if (uc < (0x1 << 16)) + { + byte_num = 3; + } + else if (uc < (0x1 << 21)) + { + byte_num = 4; + } + else if (uc < (0x1 << 26)) + { + byte_num = 5; + } + else + { + byte_num = 6; + } + + IF_CAN_HOLD(*left, byte_num); + + int i; + for (i = byte_num - 1; i > 0; --i) + { + *(uint8_t *)(*des + i) = (uc & 0x3f) | 0x80; + uc >>= 6; + } + + *(uint8_t *)(*des) = uc | (0xff << (8 - byte_num)); + + *des += byte_num; + **des = 0; + + return byte_num; + } + + size_t u8encode(ucs4_t *us, char *des, size_t n, int *illegal) + { + if (n == 0) + return 0; + + char *s = des; + size_t left = n; + size_t len = 0; + int r_illegal = 0; + + *s = 0; + while (*us) + { + int ret = putu8c(*us, &s, &left); + if (ret > 0) + { + len += ret; + } + else if (ret == -1) + { + r_illegal += 1; + } + else + { + break; + } + + ++us; + } + + if (illegal) + { + *illegal = r_illegal; + } + + return len; + } + + /* 鍏ㄨ瀛楃 */ + int isufullwidth(ucs4_t uc) + { + if (uc == 0x3000) + return 1; + + if (uc >= 0xff01 && uc <= 0xff5e) + return 1; + + return 0; + } + + /* 鍏ㄨ瀛楁瘝 */ + int isufullwidthalpha(ucs4_t uc) + { + if (uc >= 0xff21 && uc <= 0xff3a) + return 1; + + if (uc >= 0xff41 && uc <= 0xff5a) + return 2; + + return 0; + } + + /* 鍏ㄨ鏁板瓧 */ + int isufullwidthdigit(ucs4_t uc) + { + if (uc >= 0xff10 && uc <= 0xff19) + return 1; + + return 0; + } + + /* 鍏ㄨ杞崐瑙 */ + ucs4_t ufull2half(ucs4_t uc) + { + if (uc == 0x3000) + return ' '; + + if (uc >= 0xff01 && uc <= 0xff5e) + return uc - 0xfee0; + + return uc; + } + + /* 鍗婅杞叏瑙 */ + ucs4_t uhalf2full(ucs4_t uc) + { + if (uc == ' ') + return 0x3000; + + if (uc >= 0x21 && uc <= 0x7e) + return uc + 0xfee0; + + return uc; + } + + /* 涓棩闊╄秺缁熶竴琛ㄦ剰鏂囧瓧 */ + int isuchiness(ucs4_t uc) + { + /* 鏈鍒濇湡缁熶竴姹夊瓧 */ + if (uc >= 0x4e00 && uc <= 0x9fcc) + return 1; + + /* 鎵╁睍 A 鍖 */ + if (uc >= 0x3400 && uc <= 0x4db5) + return 2; + + /* 鎵╁睍 B 鍖 */ + if (uc >= 0x20000 && uc <= 0x2a6d6) + return 3; + + /* 鎵╁睍 C 鍖 */ + if (uc >= 0x2a700 && uc <= 0x2b734) + return 4; + + /* 鎵╁睍 D 鍖 */ + if (uc >= 0x2b740 && uc <= 0x2b81f) + return 5; + + /* 鎵╁睍 E 鍖 */ + if (uc >= 0x2b820 && uc <= 0x2f7ff) + return 6; + + /* 鍙版咕鍏煎姹夊瓧 */ + if (uc >= 0x2f800 && uc <= 0x2fa1d) + return 7; + + /* 鍖楁湞椴滃吋瀹规眽瀛 */ + if (uc >= 0xfa70 && uc <= 0xfad9) + return 8; + + /* 鍏煎姹夊瓧 */ + if (uc >= 0xf900 && uc <= 0xfa2d) + return 9; + + /* 鍏煎姹夊瓧 */ + if (uc >= 0xfa30 && uc <= 0xfa6d) + return 10; + + return 0; + } + + /* 涓枃鏍囩偣 */ + int isuzhpunct(ucs4_t uc) + { + if (uc >= 0x3001 && uc <= 0x3002) + return 1; + + if (uc >= 0x3008 && uc <= 0x300f) + return 1; + + if (uc >= 0xff01 && uc <= 0xff0f) + return 1; + + if (uc >= 0xff1a && uc <= 0xff20) + return 1; + + if (uc >= 0xff3b && uc <= 0xff40) + return 1; + + if (uc >= 0xff5b && uc <= 0xff5e) + return 1; + + if (uc >= 0x2012 && uc <= 0x201f) + return 1; + + if (uc >= 0xfe41 && uc <= 0xfe44) + return 1; + + if (uc >= 0xfe49 && uc <= 0xfe4f) + return 1; + + if (uc >= 0x3010 && uc <= 0x3017) + return 1; + + return 0; + } + + /* 鏃ユ枃骞冲亣鍚 */ + int isuhiragana(ucs4_t uc) + { + if (uc >= 0x3040 && uc <= 0x309f) + return 1; + + return 0; + } + + /* 鏃ユ枃鐗囧亣鍚 */ + int isukatakana(ucs4_t uc) + { + if (uc >= 0x30a0 && uc <= 0x30ff) + return 1; + + if (uc >= 0x31f0 && uc <= 0x31ff) + return 2; + + return 0; + } + + /* 闊╂枃 */ + int isukorean(ucs4_t uc) + { + /* 闊╂枃鎷奸煶 */ + if (uc >= 0xac00 && uc <= 0xd7af) + return 1; + + /* 闊╂枃瀛楁瘝 */ + if (uc >= 0x1100 && uc <= 0x11ff) + return 2; + + /* 闊╂枃鍏煎瀛楁瘝 */ + if (uc >= 0x3130 && uc <= 0x318f) + return 3; + + return 0; + } + +} diff --git a/Runtime/GUI/utf8.h b/Runtime/GUI/utf8.h new file mode 100644 index 0000000..b561b44 --- /dev/null +++ b/Runtime/GUI/utf8.h @@ -0,0 +1,113 @@ +/* + * Description: UTF-8 瀛楃涓茬殑瑙g爜鍜岀紪鐮佸嚱鏁 + * unicode 瀛楃澶勭悊鍑芥暟 + * History: yang@haipo.me, 2013/05/29, create + * + * This code is in the public domain. + * You may use this code any way you wish, private, educational, + * or commercial. It's free. + */ + +# pragma once + +# include <stdint.h> +# include <stddef.h> + +namespace utf8 +{ + + + /* + * 鏍囧噯 C 骞舵病鏈夎瀹 wchar_t 鐨勪綅鏁般備絾 GNU C Lib 淇濊瘉 wchar_t 鏄 32 浣嶇殑锛 + * 鎵浠ュ彲浠ョ敤 wchar.h 涓畾涔夌殑鍑芥暟鏉ュ儚 wchar_t 涓鏍锋搷绾 ucs4_t. + * http://www.gnu.org/software/libc/manual/html_node/Extended-Char-Intro.html + */ + typedef int32_t ucs4_t; + + /* + * 浠 UTF-8 缂栫爜鐨勫瓧绗︿覆 *src 涓鍙栦竴涓 unicode 瀛楃锛屽苟鏇存柊 *src 鐨勫笺 + * + * 濡傛灉閬囧埌闈炴硶 UTF-8 缂栫爜锛屽垯璺宠繃闈炴硶閮ㄥ垎銆 + * 濡傛灉 illegal 鍙傛暟涓嶄负 NULL, 鍒 *illegal 琛ㄧず闈炴硶 UTF-8 缂栫爜瀛楄妭鏁般 + */ + ucs4_t getu8c(char **src, int *illegal); + + /* + * 灏 src 鎸囧悜鐨 UTF-8 缂栫爜瀛楃涓茶В鐮佷负 unicode锛屾斁鍦ㄩ暱搴︿负 n 鐨勬暟缁 des 涓紝 + * 骞跺湪鏈熬娣诲姞 0. 濡傛灉 des 涓嶈冻浠ュ瓨鏀炬墍鏈夌殑瀛楃锛屽垯鏈澶氫繚瀛 n - 1 涓 unicode + * 瀛楃骞惰ˉ 0. + * + * 濡傛灉閬囧埌闈炴硶 UTF-8 缂栫爜锛屽垯璺宠繃闈炴硶閮ㄥ垎銆 + * 濡傛灉 illegal 涓嶄负 NULL, 鍒 *illegal 琛ㄧず闈炴硶 UTF-8 缂栫爜鐨勫瓧鑺傛暟銆 + */ + size_t u8decode(char const *str, ucs4_t *des, size_t n, int *illegal); + + /* + * 灏 unicode 瀛楃 uc 缂栫爜涓 UTF-8 缂栫爜锛屾斁鍒伴暱搴︿负 *left 鐨勫瓧绗︿覆 *des 涓 + * + * 濡傛灉 *des 涓嶈冻浠ュ瓨鏀 uc 瀵瑰簲鐨 UTF-8 瀛楃涓诧紝杩斿洖涓涓礋鍊笺 + * 濡傛灉鎴愬姛锛屾洿鏂 *des 鍜 *left 鐨勫笺 + */ + int putu8c(ucs4_t uc, char **des, size_t *left); + + /* + * 灏嗕互 0 缁撳熬鐨 unicode 鏁扮粍 us 缂栫爜涓 UTF-8 瀛楃涓诧紝鏀惧埌闀垮害涓 n 鐨勫瓧绗︿覆 des 涓 + * + * 璐熸暟涓洪潪娉曠殑 unicode 瀛楃銆 + * 濡傛灉 illegal 涓嶄负 NULL锛屽垯 *illegal 琛ㄧず闈炴硶鐨 unicode 瀛楃鏁般 + */ + size_t u8encode(ucs4_t *us, char *des, size_t n, int *illegal); + + /* + * 鍒ゆ柇鏄惁涓哄叏瑙掑瓧绗 + */ + int isufullwidth(ucs4_t uc); + + /* + * 鍒ゆ柇鏄惁涓哄叏瑙掑瓧姣 + */ + int isufullwidthalpha(ucs4_t uc); + + /* + * 鍒ゆ柇鏄惁涓哄叏瑙掓暟瀛 + */ + int isufullwidthdigit(ucs4_t uc); + + /* + * 鍏ㄨ瀛楃杞崐瑙掑瓧绗︺ + * 濡傛灉 uc 涓哄叏瑙掑瓧绗︼紝鍒欒繑鍥炲搴旂殑鍗婅瀛楃锛屽惁鍒欒繑鍥 uc 鏈韩銆 + */ + ucs4_t ufull2half(ucs4_t uc); + + /* + * 鍗婅瀛楃杞叏瑙掑瓧绗 + * 濡傛灉 uc 涓哄崐瑙掑瓧绗︼紝鍒欒繑鍥炲搴旂殑鍏ㄨ瀛楃锛屽惁鍒欒繑鍥 uc 鏈韩銆 + */ + ucs4_t uhalf2full(ucs4_t uc); + + /* + * 鍒ゆ柇鏄惁涓烘眽瀛楀瓧绗︼紙涓棩闊╄秺缁熶竴琛ㄦ剰鏂囧瓧锛 + */ + int isuchiness(ucs4_t uc); + + /* + * 鍒ゆ柇鏄惁涓轰腑鏂囨爣鐐 + */ + int isuzhpunct(ucs4_t uc); + + /* + * 鍒ゆ柇鏄惁涓烘棩鏂囧钩鍋囧悕瀛楃 + */ + int isuhiragana(ucs4_t uc); + + /* + * 鍒ゆ柇鏄惁涓烘棩鏂囩墖鍋囧悕瀛楃 + */ + int isukatakana(ucs4_t uc); + + /* + * 鍒ゆ柇鏄惁涓洪煩鏂囧瓧绗 + */ + int isukorean(ucs4_t uc); + +} diff --git a/Runtime/Graphics/DynamicVertexBuffer.h b/Runtime/Graphics/DynamicVertexBuffer.h index b520d1b..12aa48c 100644 --- a/Runtime/Graphics/DynamicVertexBuffer.h +++ b/Runtime/Graphics/DynamicVertexBuffer.h @@ -46,8 +46,8 @@ private: EPrimitive m_CurPrimitive; - uint m_CurAttrMask; // default layout - uint m_CurStride; // default layout + uint m_CurAttrMask; // default layout only + uint m_CurStride; // default layout only uint m_CurVertexCount; uint m_CurIndexCount; diff --git a/Runtime/Graphics/VertexBuffer.h b/Runtime/Graphics/VertexBuffer.h index e6fd9ee..b03df3b 100644 --- a/Runtime/Graphics/VertexBuffer.h +++ b/Runtime/Graphics/VertexBuffer.h @@ -34,4 +34,6 @@ private: GPU::DataBuffer* m_VB; GPU::DataBuffer* m_IB; + EPrimitive m_Primitive; + }; diff --git a/Runtime/Lua/LuaBind/LuaBindClass.hpp b/Runtime/Lua/LuaBind/LuaBindClass.hpp index aed4741..dff4d30 100644 --- a/Runtime/Lua/LuaBind/LuaBindClass.hpp +++ b/Runtime/Lua/LuaBind/LuaBindClass.hpp @@ -102,7 +102,6 @@ namespace LuaBind friend class State; static void RegisterClassShared(State& state); - static void RegisterNativeClass(State& state); static void SetClassTableRef(State& state, int idx); static void PushClassTable(State& state); @@ -122,7 +121,6 @@ namespace LuaBind // 工厂类相关 static int __gc (lua_State*); - static int _GetRefTable (lua_State*); //--------------------------------------------------------------------------------// @@ -179,18 +177,6 @@ namespace LuaBind state.RegisterMethods(regTable); } - // 工厂类的成员,注册在class table - template<class TYPE, class BASE> - void NativeClass<TYPE, BASE>::RegisterNativeClass(State& state) - { - luaL_Reg regTable[] = { - { "GetRefTable", _GetRefTable }, - { NULL, NULL } - }; - - state.RegisterMethods(regTable); - } - template<class TYPE, class BASE> void NativeClass<TYPE, BASE>::SetClassTableRef(State& state, int idx) { @@ -560,17 +546,6 @@ namespace LuaBind return 1; } - template<class TYPE, class BASE> - int NativeClass<TYPE, BASE>::_GetRefTable(lua_State* L) - { - LUA_BIND_STATE(L); - TYPE* self = state.GetUserdata<TYPE>(1); - bool success = self->PushRefTable(state); - if (!success) - lua_pushnil(L); - return 1; - } - } #endif
\ No newline at end of file diff --git a/Runtime/Lua/LuaBind/LuaBindState.h b/Runtime/Lua/LuaBind/LuaBindState.h index 528c81a..21cde0d 100644 --- a/Runtime/Lua/LuaBind/LuaBindState.h +++ b/Runtime/Lua/LuaBind/LuaBindState.h @@ -273,8 +273,7 @@ namespace LuaBind lua_newtable(L); int clsIdx = lua_gettop(L); TYPE::RegisterClassShared(state); - TYPE::RegisterNativeClass(state); - TYPE::RegisterClass(state); + TYPE::RegisterClass_(state); // 自定义注册内容 if (onRegisterNativeClass) diff --git a/Runtime/Lua/LuaBind/LuaBindUtility.h b/Runtime/Lua/LuaBind/LuaBindUtility.h index b890b57..bf138e4 100644 --- a/Runtime/Lua/LuaBind/LuaBindUtility.h +++ b/Runtime/Lua/LuaBind/LuaBindUtility.h @@ -5,19 +5,15 @@ // RegisterClass 注册类的方法和成员,比如枚举、常量等到class table GetNativeClassName 获得工厂的类名, // 同时用来避免注册时错误注册为了singleton,通过编译时报错避免 +// RegisterClass和win32的宏冲突,所以加个下划线 #define LUA_BIND_DECL_CLASS(type, ...) \ friend class LuaBind::State; \ friend class LuaBind::NativeClass<type,##__VA_ARGS__>; \ - static void RegisterClass(LuaBind::State&); \ + static void RegisterClass_(LuaBind::State&); \ static void RegisterPostprocess(LuaBind::State&); \ static const char* GetNativeClassName() { return #type; }; //static const char* GetClassName() { return #type; }; -// 作为基类的抽象工厂类可以使用此宏,注册一个入口,在派生类的注册函数中调用,注册基类的这些方法。 -#define LUA_BIND_DECL_ABSTRACT_CLASS() \ - static void RegisterClass(::State&);\ - static void RegisterPostprocess(::State&) - #define LUA_BIND_DECL_METHOD(mtd) static int mtd(lua_State* L) #define LUA_BIND_DECL_ENUM(e, under_line_index) @@ -26,7 +22,7 @@ #define LUA_BIND_IMPL_METHOD(type, f) int type::f(lua_State* L) // 由应用程序实现的两个接口。上下文里有一个state。 -#define LUA_BIND_REGISTRY(type) void type::RegisterClass(LuaBind::State& state) +#define LUA_BIND_REGISTRY(type) void type::RegisterClass_(LuaBind::State& state) #define LUA_BIND_POSTPROCESS(type) void type::RegisterPostprocess(LuaBind::State& state) // 用来注册的宏。之前这里忘了用可变宏,导致没有luaclastable ref没有注册对。 @@ -53,8 +49,6 @@ return 0;\ } -#define LUA_BIND_INHERIT(state, type) type::RegisterClass(state) - #define luaxport private #endif
\ No newline at end of file diff --git a/Runtime/Math/Math.h b/Runtime/Math/Math.h index 7f61544..aaeb264 100644 --- a/Runtime/Math/Math.h +++ b/Runtime/Math/Math.h @@ -9,3 +9,9 @@ #define max(a, b)\ (a)>(b)?(a):(b) + +typedef Internal::Vector2 Vector2; +typedef Internal::Vector3 Vector3; +typedef Internal::Vector4 Vector4; +typedef Internal::Matrix44 Matrix44; +typedef Internal::Rect Rect; diff --git a/Runtime/Scripting/GUI/Font.bind.cpp b/Runtime/Scripting/GUI/Font.bind.cpp index 73fb7e6..8259a60 100644 --- a/Runtime/Scripting/GUI/Font.bind.cpp +++ b/Runtime/Scripting/GUI/Font.bind.cpp @@ -3,12 +3,21 @@ #include "Runtime/Debug/Log.h" #include "Runtime/Graphics/GfxDevice.h" #include "Runtime/Common/DataBuffer.h"
+#include "Runtime/GUI/utf8.h"
+#include "Runtime/Utilities/StaticInitiator.h"
+
+static std::vector<character::Codepoint>* s_Codepoints;
+
+InitializeStaticVariables([](){
+ s_Codepoints = new std::vector<character::Codepoint>();
+});
LUA_BIND_REGISTRY(Font) { LUA_BIND_REGISTER_METHODS(state, { "New", _New }, { "GetCharacter", _GetCharacter }, + { "GetCharacters", _GetCharacters }, { "GetGlyphAtlas", _GetGlyphAtlas } ); } @@ -33,7 +42,7 @@ LUA_BIND_IMPL_METHOD(Font, _New) setting.margin = state.GetValue<int>(3, 0);
setting.padding = state.GetValue<int>(4, 0);
try {
- font = new Font(path, setting);
+ font = new Font(state.GetVM(), path, setting);
}
catch (FontException& e)
{
@@ -56,7 +65,7 @@ LUA_BIND_IMPL_METHOD(Font, _New) setting.margin = state.GetValue<int>(3, 0);
setting.padding = state.GetValue<int>(4, 0);
try {
- font = new Font(buffer, setting);
+ font = new Font(state.GetVM(), buffer, setting);
}
catch (FontException& e)
{
@@ -75,7 +84,6 @@ LUA_BIND_IMPL_METHOD(Font, _New) LUA_BIND_IMPL_METHOD(Font, _GetCharacter) {
LUA_BIND_PREPARE(L, Font);
-// Character character = self->GetCharacter(character);
return 1;
}
@@ -83,8 +91,43 @@ LUA_BIND_IMPL_METHOD(Font, _GetCharacter) LUA_BIND_IMPL_METHOD(Font, _GetCharacters) {
LUA_BIND_PREPARE(L, Font);
-// Character character = self->GetCharacter(character);
- return 1;
+ LUA_BIND_CHECK(L, "USN*");
+
+ char* buf = (char*)state.GetValue<const char*>(2, "");
+ int size = state.GetValue<int>(3, 12);
+ int encoding = state.GetValue<int>(4, EEncoding::Encoding_UTF8);
+
+ s_Codepoints->clear();
+ if (encoding == EEncoding::Encoding_UTF8)
+ {
+ while (*buf != 0) {
+ int err;
+ s_Codepoints->push_back(utf8::getu8c(&buf, &err));
+ if (err != 0)
+ {
+ log_warning("Illegal utf8 bytes %d", err);
+ }
+ }
+ }
+ else if (encoding == EEncoding::Encoding_UTF16)
+ {
+ while (*buf != 0) {
+ unsigned short* s = (unsigned short*)(buf);
+ s_Codepoints->push_back(*s);
+ buf += 2;
+ }
+ }
+ else if (encoding == EEncoding::Encoding_ASCII)
+ {
+ while (*buf != 0) {
+ s_Codepoints->push_back(*buf);
+ buf += 1;
+ }
+ }
+
+ self->RenderCharacters(*s_Codepoints, size);
+
+ return 0;
}
// font:GetAtlas(i)
diff --git a/Runtime/Scripting/GUI/GUI.bind.cpp b/Runtime/Scripting/GUI/GUI.bind.cpp index 4f6ed7a..fcc2848 100644 --- a/Runtime/Scripting/GUI/GUI.bind.cpp +++ b/Runtime/Scripting/GUI/GUI.bind.cpp @@ -20,5 +20,11 @@ int luaopen_GameLab_Engine_GUI(lua_State* L) state.RegisterNativeClass<Font>(); + LUA_BIND_REGISTER_ENUM(state, "EEncoding", + { "ASCII", EEncoding::Encoding_ASCII }, + { "UTF8", EEncoding::Encoding_UTF8 }, + { "UTF16", EEncoding::Encoding_UTF16 } + ); + return 1; }
\ No newline at end of file diff --git a/Runtime/Utilities/IncrementalTask.h b/Runtime/Utilities/IIncrementalTask.h index 741e55a..3762430 100644 --- a/Runtime/Utilities/IncrementalTask.h +++ b/Runtime/Utilities/IIncrementalTask.h @@ -1,11 +1,11 @@ #pragma once
// 增量式多任务处理
-class IncrementalTask
+class IIncrementalTask
{
public:
- IncrementalTask() {};
- virtual ~IncrementalTask() {};
+ IIncrementalTask() {};
+ virtual ~IIncrementalTask() {};
virtual void Execute() = 0;
virtual bool IsDone() = 0;
|