1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-25 01:33:49 +00:00

Add two more font/text related Lua functions, and some more:

+ entity_getBoneByInternalId()
+ entity_getNumBones()
+ text_getLineHeight()
+ text_getNumLines()
This commit is contained in:
fgenesis 2015-11-16 03:59:47 +01:00
parent 3ebf99acfa
commit ed089f38f7
8 changed files with 54 additions and 2 deletions

View file

@ -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),

View file

@ -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

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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:

View file

@ -96,6 +96,10 @@ void TTFText::updateAlign()
}
}
int TTFText::getNumLines()
{
return (int)text.size();
}
float TTFText::getHeight()
{

View file

@ -61,6 +61,7 @@ public:
bool shadow;
int findLine(const std::string &label);
float getLineHeight();
int getNumLines();
protected:
float width;
float lineHeight;