From ed089f38f70bd6eb935e43d233902762cbc398ac Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 16 Nov 2015 03:59:47 +0100 Subject: [PATCH] Add two more font/text related Lua functions, and some more: + entity_getBoneByInternalId() + entity_getNumBones() + text_getLineHeight() + text_getNumLines() --- Aquaria/ScriptInterface.cpp | 35 ++++++++++++++++++++++++++++++++++- BBGE/BaseText.h | 2 ++ BBGE/BitmapFont.cpp | 5 +++++ BBGE/BitmapFont.h | 3 ++- BBGE/DebugFont.cpp | 5 +++++ BBGE/DebugFont.h | 1 + BBGE/TTFFont.cpp | 4 ++++ BBGE/TTFFont.h | 1 + 8 files changed, 54 insertions(+), 2 deletions(-) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index de1cd06..d847a50 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -6203,7 +6203,7 @@ luaFunc(entity_getBoneByIdx) int n = 0; if (lua_isnumber(L, 2)) { - n = lua_tonumber(L, 2); + n = lua_tointeger(L, 2); b = e->skeletalSprite.getBoneByIdx(n); } } @@ -6216,6 +6216,23 @@ luaFunc(entity_getBoneByName) luaReturnPtr(e ? e->skeletalSprite.getBoneByName(getString(L, 2)) : NULL); } +luaFunc(entity_getBoneByInternalId) +{ + Entity *e = entity(L); + if(!e) + luaReturnPtr(NULL); + size_t i = lua_tointeger(L, 1); + if(i >= e->skeletalSprite.bones.size()) + luaReturnPtr(NULL); + luaReturnPtr(e->skeletalSprite.bones[i]); +} + +luaFunc(entity_getNumBones) +{ + Entity *e = entity(L); + luaReturnInt(e ? (int)e->skeletalSprite.bones.size() : 0); +} + luaFunc(bone_getIndex) { Bone *b = bone(L); @@ -9221,6 +9238,18 @@ luaFunc(text_getHeight) luaReturnNum(txt ? txt->getHeight() : 0.0f); } +luaFunc(text_getLineHeight) +{ + BaseText *txt = getText(L); + luaReturnNum(txt ? txt->getLineHeight() : 0.0f); +} + +luaFunc(text_getNumLines) +{ + BaseText *txt = getText(L); + luaReturnInt(txt ? txt->getNumLines() : 0); +} + luaFunc(text_getStringWidth) { BaseText *txt = getText(L); @@ -10122,6 +10151,8 @@ static const struct { luaRegister(entity_getBoneByIdx), luaRegister(entity_getBoneByName), + luaRegister(entity_getBoneByInternalId), + luaRegister(entity_getNumBones), @@ -10340,6 +10371,8 @@ static const struct { luaRegister(text_getHeight), luaRegister(text_getStringWidth), luaRegister(text_getActualWidth), + luaRegister(text_getLineHeight), + luaRegister(text_getNumLines), luaRegister(loadShader), luaRegister(createShader), diff --git a/BBGE/BaseText.h b/BBGE/BaseText.h index 75716f5..5fc4d5f 100644 --- a/BBGE/BaseText.h +++ b/BBGE/BaseText.h @@ -13,6 +13,8 @@ public: virtual void setWidth(float width) = 0; virtual void setFontSize(float sz) = 0; virtual void setAlign(Align a) = 0; + virtual float getLineHeight() = 0; + virtual int getNumLines() = 0; virtual float getHeight() = 0; // total height virtual float getStringWidth(const std::string& text) = 0; // width of string when not auto-wrapped virtual float getActualWidth() = 0; // width of text after wrapping diff --git a/BBGE/BitmapFont.cpp b/BBGE/BitmapFont.cpp index 7c646b8..51efc2b 100644 --- a/BBGE/BitmapFont.cpp +++ b/BBGE/BitmapFont.cpp @@ -148,6 +148,11 @@ float BitmapText::getHeight() return lines.size()*sz; } +float BitmapText::getLineHeight() +{ + return bmpFont->font.GetCharHeight('A') * bmpFont->scale; +} + void BitmapText::formatText() { std::string text; diff --git a/BBGE/BitmapFont.h b/BBGE/BitmapFont.h index eb293a2..5ba302f 100644 --- a/BBGE/BitmapFont.h +++ b/BBGE/BitmapFont.h @@ -77,8 +77,9 @@ public: void reloadDevice(); float getStringWidth(const std::string& text); float getActualWidth() { return maxW; } - + float getLineHeight(); int getNumLines(); + protected: float scrollSpeed; BmpFont *bmpFont; diff --git a/BBGE/DebugFont.cpp b/BBGE/DebugFont.cpp index abcf507..d2699b5 100644 --- a/BBGE/DebugFont.cpp +++ b/BBGE/DebugFont.cpp @@ -53,6 +53,11 @@ float DebugFont::getHeight() return fontDrawSize * lines.size() * 1.5f; // vspc in render() } +float DebugFont::getLineHeight() +{ + return fontDrawSize * 1.5f; // vspc in render() +} + float DebugFont::getStringWidth(const std::string& text) { int maxchars = 0; diff --git a/BBGE/DebugFont.h b/BBGE/DebugFont.h index 7258a77..a7d0b07 100644 --- a/BBGE/DebugFont.h +++ b/BBGE/DebugFont.h @@ -34,6 +34,7 @@ public: int getNumLines() { return lines.size(); } virtual void setAlign(Align align); virtual float getHeight(); + virtual float getLineHeight(); virtual float getStringWidth(const std::string& text); virtual float getActualWidth(); protected: diff --git a/BBGE/TTFFont.cpp b/BBGE/TTFFont.cpp index e7cdc27..dd0d7d3 100644 --- a/BBGE/TTFFont.cpp +++ b/BBGE/TTFFont.cpp @@ -96,6 +96,10 @@ void TTFText::updateAlign() } } +int TTFText::getNumLines() +{ + return (int)text.size(); +} float TTFText::getHeight() { diff --git a/BBGE/TTFFont.h b/BBGE/TTFFont.h index d675117..bc56b5e 100644 --- a/BBGE/TTFFont.h +++ b/BBGE/TTFFont.h @@ -61,6 +61,7 @@ public: bool shadow; int findLine(const std::string &label); float getLineHeight(); + int getNumLines(); protected: float width; float lineHeight;