mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2024-12-29 00:05:50 +00:00
Add script functions:
+ createArialTextBig() + createArialTextSmall() + quad_getTexOffset() + quad_setTexOffset()
This commit is contained in:
parent
03f47b0480
commit
e8dc99b30d
3 changed files with 61 additions and 8 deletions
|
@ -1732,6 +1732,23 @@ luaFunc(quad_isRepeatTexture)
|
|||
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)
|
||||
{
|
||||
Quad *b = getQuad(L);
|
||||
|
@ -1891,7 +1908,9 @@ luaFunc(quad_getBorderAlpha)
|
|||
Q_FUNC(getter, prefix, setRenderCenter ) \
|
||||
Q_FUNC(getter, prefix, isRenderCenter ) \
|
||||
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,
|
||||
// e.g. a Beam is a Quad, so it can use quad_* functions
|
||||
|
@ -9134,7 +9153,7 @@ luaFunc(createDebugText)
|
|||
|
||||
luaFunc(createBitmapText)
|
||||
{
|
||||
BmpFont *font = &dsq->smallFont; // make this configurable?
|
||||
BmpFont *font = &dsq->smallFont;
|
||||
BitmapText *txt = new BitmapText(font);
|
||||
txt->setText(getString(L, 1));
|
||||
txt->setFontSize(lua_tointeger(L, 2));
|
||||
|
@ -9143,6 +9162,27 @@ luaFunc(createBitmapText)
|
|||
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)
|
||||
{
|
||||
BaseText *txt = getText(L);
|
||||
|
@ -10285,6 +10325,8 @@ static const struct {
|
|||
|
||||
luaRegister(createDebugText),
|
||||
luaRegister(createBitmapText),
|
||||
luaRegister(createArialTextBig),
|
||||
luaRegister(createArialTextSmall),
|
||||
luaRegister(text_setText),
|
||||
luaRegister(text_setFontSize),
|
||||
luaRegister(text_setWidth),
|
||||
|
|
|
@ -56,7 +56,7 @@ void TTFFont::create(const unsigned char *data, unsigned long datalen, int sz)
|
|||
font->FaceSize(sz);
|
||||
}
|
||||
|
||||
TTFText::TTFText(TTFFont *font) : RenderObject(), font(font)
|
||||
TTFText::TTFText(TTFFont *f) : font(f)
|
||||
{
|
||||
align = ALIGN_LEFT;
|
||||
hw = 0;
|
||||
|
@ -97,9 +97,7 @@ void TTFText::updateAlign()
|
|||
|
||||
float TTFText::getWidth()
|
||||
{
|
||||
float llx, lly, llz, urx, ury, urz;
|
||||
font->font->BBox(originalText.c_str(), llx, lly, llz, urx, ury, urz);
|
||||
return urx - llx;
|
||||
return getStringWidth(originalText);
|
||||
}
|
||||
|
||||
float TTFText::getHeight()
|
||||
|
@ -109,6 +107,13 @@ float TTFText::getHeight()
|
|||
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()
|
||||
{
|
||||
/*
|
||||
|
@ -127,6 +132,10 @@ void TTFText::setWidth(int width)
|
|||
updateFormatting();
|
||||
}
|
||||
|
||||
void TTFText::setFontSize(int)
|
||||
{
|
||||
}
|
||||
|
||||
void TTFText::updateFormatting()
|
||||
{
|
||||
int start = 0, lastSpace = -1;
|
||||
|
|
|
@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#define BBGE_TTFFONT_H
|
||||
|
||||
#include "Base.h"
|
||||
#include "RenderObject.h"
|
||||
#include "BaseText.h"
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
@ -43,7 +43,7 @@ struct TTFFont
|
|||
FTGLTextureFont *font;
|
||||
};
|
||||
|
||||
class TTFText : public RenderObject
|
||||
class TTFText : public BaseText
|
||||
{
|
||||
public:
|
||||
TTFText(TTFFont *font);
|
||||
|
@ -53,6 +53,8 @@ public:
|
|||
float getWidth();
|
||||
float getHeight();
|
||||
float getFullHeight();
|
||||
void setFontSize(int); // dummy
|
||||
float getStringWidth(const std::string& s);
|
||||
bool shadow;
|
||||
int findLine(const std::string &label);
|
||||
int getLineHeight();
|
||||
|
|
Loading…
Reference in a new issue