added ag::getTextSize(), varying text size demo in tests/cratestack.lua
git-svn-id: svn://anubis/anaglym/trunk@165 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
c26a3e7deb
commit
d4df124dcc
@ -488,8 +488,10 @@ void Engine::drawText(const char * text, GLfloat r, GLfloat g, GLfloat b,
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void Engine::getTextSize(const char * text, float * width, float * height)
|
||||
void Engine::getTextSize(const char * text, int ptsize,
|
||||
float * width, float * height)
|
||||
{
|
||||
m_font->FaceSize(ptsize);
|
||||
FTBBox box = m_font->BBox(text);
|
||||
*width = box.Upper().Xf() - box.Lower().Xf();
|
||||
*height = box.Upper().Yf() - box.Lower().Yf();
|
||||
|
3
Engine.h
3
Engine.h
@ -138,7 +138,8 @@ class Engine
|
||||
void getScreenSize(int * width, int * height);
|
||||
void drawText(const char * text, GLfloat r, GLfloat g, GLfloat b,
|
||||
int ptsize, float x, float y);
|
||||
void getTextSize(const char * text, float * width, float * height);
|
||||
void getTextSize(const char * text, int ptsize,
|
||||
float * width, float * height);
|
||||
|
||||
/* lua services */
|
||||
int setCamera(lua_State * L);
|
||||
|
16
ag.cc
16
ag.cc
@ -45,6 +45,7 @@ namespace ag
|
||||
{ "loadTexture", loadTexture },
|
||||
{ "getScreenSize", getScreenSize },
|
||||
{ "drawText", drawText},
|
||||
{ "getTextSize", getTextSize},
|
||||
|
||||
{ "createBox", createBox},
|
||||
{ "createStaticBox", createStaticBox},
|
||||
@ -371,6 +372,21 @@ namespace ag
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getTextSize(lua_State * L)
|
||||
{
|
||||
float width = 0.0f;
|
||||
float height = 0.0f;
|
||||
int argc = lua_gettop(L);
|
||||
if (argc == 2 && lua_isstring(L, 1) && lua_isnumber(L, 2))
|
||||
{
|
||||
g_engine->getTextSize(lua_tostring(L, 1), lua_tonumber(L, 2),
|
||||
&width, &height);
|
||||
}
|
||||
lua_pushnumber(L, width);
|
||||
lua_pushnumber(L, height);
|
||||
return 2;
|
||||
}
|
||||
|
||||
static void addManagedObject(lua_State * L, bool is_static,
|
||||
OdeWorld::GeomType geom_type, refptr< vector<float> > args)
|
||||
{
|
||||
|
1
ag.h
1
ag.h
@ -31,6 +31,7 @@ namespace ag
|
||||
int loadTexture(lua_State * L);
|
||||
int getScreenSize(lua_State * L);
|
||||
int drawText(lua_State * L);
|
||||
int getTextSize(lua_State * L);
|
||||
|
||||
int createBox(lua_State * L);
|
||||
int createStaticBox(lua_State * L);
|
||||
|
@ -44,5 +44,13 @@ function mouse_moves(x, y, xrel, yrel)
|
||||
end
|
||||
|
||||
function update_overlay_event()
|
||||
ag.drawText("Hi there everyone!", 1, 0.7, 0, 16, 0, 0)
|
||||
y = 4
|
||||
size = 16
|
||||
for i = 0, 17 do
|
||||
local message = "Hello there"
|
||||
local width, height = ag.getTextSize(message, size)
|
||||
ag.drawText(message, 1, 0.7, 0, size, 2, y)
|
||||
y = y + height + 4
|
||||
size = size + 4
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user