1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-07-03 06:24:32 +00:00

Add script functions:

+ createArialTextBig()
+ createArialTextSmall()
+ quad_getTexOffset()
+ quad_setTexOffset()
This commit is contained in:
fgenesis 2015-08-15 21:15:42 +02:00
parent 03f47b0480
commit e8dc99b30d
3 changed files with 61 additions and 8 deletions

View file

@ -1732,6 +1732,23 @@ luaFunc(quad_isRepeatTexture)
luaReturnBool(b ? b->isRepeatingTextureToFill() : false); luaReturnBool(b ? b->isRepeatingTextureToFill() : false);
} }
luaFunc(quad_setTexOffset)
{
Quad *b = getQuad(L);
if (b)
b->texOff = Vector(lua_tonumber(L, 2), lua_tonumber(L, 3));
luaReturnNil();
}
luaFunc(quad_getTexOffset)
{
Quad *b = getQuad(L);
Vector v;
if (b)
v = b->texOff;
luaReturnVec2(v.x, v.y);
}
luaFunc(quad_setRenderBorder) luaFunc(quad_setRenderBorder)
{ {
Quad *b = getQuad(L); Quad *b = getQuad(L);
@ -1891,7 +1908,9 @@ luaFunc(quad_getBorderAlpha)
Q_FUNC(getter, prefix, setRenderCenter ) \ Q_FUNC(getter, prefix, setRenderCenter ) \
Q_FUNC(getter, prefix, isRenderCenter ) \ Q_FUNC(getter, prefix, isRenderCenter ) \
Q_FUNC(getter, prefix, borderAlpha ) \ Q_FUNC(getter, prefix, borderAlpha ) \
Q_FUNC(getter, prefix, getBorderAlpha ) Q_FUNC(getter, prefix, getBorderAlpha ) \
Q_FUNC(getter, prefix, setTexOffset ) \
Q_FUNC(getter, prefix, getTexOffset )
// This should reflect the internal class hierarchy, // This should reflect the internal class hierarchy,
// e.g. a Beam is a Quad, so it can use quad_* functions // e.g. a Beam is a Quad, so it can use quad_* functions
@ -9134,7 +9153,7 @@ luaFunc(createDebugText)
luaFunc(createBitmapText) luaFunc(createBitmapText)
{ {
BmpFont *font = &dsq->smallFont; // make this configurable? BmpFont *font = &dsq->smallFont;
BitmapText *txt = new BitmapText(font); BitmapText *txt = new BitmapText(font);
txt->setText(getString(L, 1)); txt->setText(getString(L, 1));
txt->setFontSize(lua_tointeger(L, 2)); txt->setFontSize(lua_tointeger(L, 2));
@ -9143,6 +9162,27 @@ luaFunc(createBitmapText)
luaReturnPtr(txt); luaReturnPtr(txt);
} }
static int createArialText(lua_State *L, TTFFont *font)
{
TTFText *txt = new TTFText(font);
txt->setText(getString(L, 1));
//txt->setFontSize(lua_tointeger(L, 2)); // not supported; param is ignored for API compat with the create*Text functions
txt->position = Vector(lua_tonumber(L, 3), lua_tonumber(L, 4));
dsq->game->addRenderObject(txt, LR_HUD);
luaReturnPtr(txt);
}
luaFunc(createArialTextBig)
{
return createArialText(L, &dsq->fontArialBig);
}
luaFunc(createArialTextSmall)
{
return createArialText(L, &dsq->fontArialSmall);
}
luaFunc(text_setText) luaFunc(text_setText)
{ {
BaseText *txt = getText(L); BaseText *txt = getText(L);
@ -10285,6 +10325,8 @@ static const struct {
luaRegister(createDebugText), luaRegister(createDebugText),
luaRegister(createBitmapText), luaRegister(createBitmapText),
luaRegister(createArialTextBig),
luaRegister(createArialTextSmall),
luaRegister(text_setText), luaRegister(text_setText),
luaRegister(text_setFontSize), luaRegister(text_setFontSize),
luaRegister(text_setWidth), luaRegister(text_setWidth),

View file

@ -56,7 +56,7 @@ void TTFFont::create(const unsigned char *data, unsigned long datalen, int sz)
font->FaceSize(sz); font->FaceSize(sz);
} }
TTFText::TTFText(TTFFont *font) : RenderObject(), font(font) TTFText::TTFText(TTFFont *f) : font(f)
{ {
align = ALIGN_LEFT; align = ALIGN_LEFT;
hw = 0; hw = 0;
@ -97,9 +97,7 @@ void TTFText::updateAlign()
float TTFText::getWidth() float TTFText::getWidth()
{ {
float llx, lly, llz, urx, ury, urz; return getStringWidth(originalText);
font->font->BBox(originalText.c_str(), llx, lly, llz, urx, ury, urz);
return urx - llx;
} }
float TTFText::getHeight() float TTFText::getHeight()
@ -109,6 +107,13 @@ float TTFText::getHeight()
return ury - lly; return ury - lly;
} }
float TTFText::getStringWidth(const std::string& s)
{
float llx, lly, llz, urx, ury, urz;
font->font->BBox(s.c_str(), llx, lly, llz, urx, ury, urz);
return urx - llx;
}
float TTFText::getFullHeight() float TTFText::getFullHeight()
{ {
/* /*
@ -127,6 +132,10 @@ void TTFText::setWidth(int width)
updateFormatting(); updateFormatting();
} }
void TTFText::setFontSize(int)
{
}
void TTFText::updateFormatting() void TTFText::updateFormatting()
{ {
int start = 0, lastSpace = -1; int start = 0, lastSpace = -1;

View file

@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define BBGE_TTFFONT_H #define BBGE_TTFFONT_H
#include "Base.h" #include "Base.h"
#include "RenderObject.h" #include "BaseText.h"
#include <ft2build.h> #include <ft2build.h>
#include FT_FREETYPE_H #include FT_FREETYPE_H
@ -43,7 +43,7 @@ struct TTFFont
FTGLTextureFont *font; FTGLTextureFont *font;
}; };
class TTFText : public RenderObject class TTFText : public BaseText
{ {
public: public:
TTFText(TTFFont *font); TTFText(TTFFont *font);
@ -53,6 +53,8 @@ public:
float getWidth(); float getWidth();
float getHeight(); float getHeight();
float getFullHeight(); float getFullHeight();
void setFontSize(int); // dummy
float getStringWidth(const std::string& s);
bool shadow; bool shadow;
int findLine(const std::string &label); int findLine(const std::string &label);
int getLineHeight(); int getLineHeight();