From c26a3e7debea01c1d2b16bceded76a7614a3e33d Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Fri, 13 Nov 2009 04:55:42 +0000 Subject: [PATCH] added Engine::getTextSize() git-svn-id: svn://anubis/anaglym/trunk@164 99a6e188-d820-4881-8870-2d33a10e2619 --- Engine.cc | 9 ++++++++- Engine.h | 3 ++- tests/cratestack.lua | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Engine.cc b/Engine.cc index 42b2879..87dd32b 100644 --- a/Engine.cc +++ b/Engine.cc @@ -477,7 +477,7 @@ void Engine::getScreenSize(int * width, int * height) } void Engine::drawText(const char * text, GLfloat r, GLfloat g, GLfloat b, - int ptsize, int x, int y) + int ptsize, float x, float y) { m_font->FaceSize(ptsize); glPushMatrix(); @@ -488,6 +488,13 @@ void Engine::drawText(const char * text, GLfloat r, GLfloat g, GLfloat b, glPopMatrix(); } +void Engine::getTextSize(const char * text, float * width, float * height) +{ + FTBBox box = m_font->BBox(text); + *width = box.Upper().Xf() - box.Lower().Xf(); + *height = box.Upper().Yf() - box.Lower().Yf(); +} + /* called by SDL when the update timer expires */ Uint32 Engine::updateCallback(Uint32 interval, void * param) { diff --git a/Engine.h b/Engine.h index 7078cd9..d509f83 100644 --- a/Engine.h +++ b/Engine.h @@ -137,7 +137,8 @@ class Engine void debug_hook(lua_Debug * debug); void getScreenSize(int * width, int * height); void drawText(const char * text, GLfloat r, GLfloat g, GLfloat b, - int ptsize, int x, int y); + int ptsize, float x, float y); + void getTextSize(const char * text, float * width, float * height); /* lua services */ int setCamera(lua_State * L); diff --git a/tests/cratestack.lua b/tests/cratestack.lua index 644ddf3..3054fc8 100644 --- a/tests/cratestack.lua +++ b/tests/cratestack.lua @@ -44,5 +44,5 @@ function mouse_moves(x, y, xrel, yrel) end function update_overlay_event() - ag.drawText("Hi there everyone!", 1, 0.7, 0, 16, 40, 40) + ag.drawText("Hi there everyone!", 1, 0.7, 0, 16, 0, 0) end