added create*TextBox() methods for creating various types of text boxes

git-svn-id: svn://anubis/anaglym/trunk@160 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2009-11-08 04:33:25 +00:00
parent 3f429be13b
commit 8746e81fe4
5 changed files with 99 additions and 6 deletions

View File

@ -128,8 +128,8 @@ Engine::~Engine()
{
delete it->second;
}
for (std::map<int, SDL_Surface *>::iterator it = m_texts.begin();
it != m_texts.end();
for (std::map<int, SDL_Surface *>::iterator it = m_textboxes.begin();
it != m_textboxes.end();
it++)
{
SDL_FreeSurface(it->second);
@ -469,7 +469,8 @@ void Engine::debug_hook(lua_Debug * debug)
}
}
int Engine::renderText(const char * text, int mode, Uint8 r, Uint8 g, Uint8 b,
int Engine::createTextBox(const char * text, int mode,
Uint8 r, Uint8 g, Uint8 b,
Uint8 br, Uint8 bg, Uint8 bb)
{
SDL_Surface * surf = NULL;
@ -490,7 +491,7 @@ int Engine::renderText(const char * text, int mode, Uint8 r, Uint8 g, Uint8 b,
if (surf != NULL)
{
int id = m_next_text_index++;
m_texts[id] = surf;
m_textboxes[id] = surf;
return id;
}
return 0;

View File

@ -135,7 +135,8 @@ class Engine
bool import(const char * name);
GLuint loadTexture(const char * name);
void debug_hook(lua_Debug * debug);
int renderText(const char * text, int mode, Uint8 r, Uint8 g, Uint8 b,
int createTextBox(const char * text, int mode,
Uint8 r, Uint8 g, Uint8 b,
Uint8 br = 0, Uint8 bg = 0, Uint8 bb = 0);
void getScreenSize(int * width, int * height);
@ -171,7 +172,7 @@ class Engine
OdeWorld m_world;
std::map<int, Object *> m_objects;
int m_next_object_index;
std::map<int, SDL_Surface *> m_texts;
std::map<int, SDL_Surface *> m_textboxes;
int m_next_text_index;
GLdouble m_eye[3];
GLdouble m_center[3];

85
ag.cc
View File

@ -44,6 +44,9 @@ namespace ag
{ "import", import },
{ "loadTexture", loadTexture },
{ "getScreenSize", getScreenSize },
{ "createSolidTextBox", createSolidTextBox},
{ "createShadedTextBox", createShadedTextBox},
{ "createBlendedTextBox", createBlendedTextBox},
{ "createBox", createBox},
{ "createStaticBox", createStaticBox},
@ -347,6 +350,88 @@ namespace ag
return 2;
}
static int createTextBoxCommon(lua_State * L, int type, const char * text,
Uint8 r, Uint8 g, Uint8 b, Uint8 br, Uint8 bg, Uint8 bb)
{
int id = g_engine->createTextBox(text, type, r, g, b, br, bg, bb);
if (id != 0)
{
lua_newtable(L);
lua_pushinteger(L, id);
lua_setfield(L, -2, "id");
}
else
{
lua_pushnil(L);
}
return 1;
}
int createSolidTextBox(lua_State * L)
{
int argc = lua_gettop(L);
if (argc == 4
&& lua_isstring(L, 1)
&& lua_isnumber(L, 2)
&& lua_isnumber(L, 3)
&& lua_isnumber(L, 4))
{
return createTextBoxCommon(L, 0,
lua_tostring(L, 1),
lua_tonumber(L, 2),
lua_tonumber(L, 3),
lua_tonumber(L, 4),
0, 0, 0);
}
lua_pushnil(L);
return 1;
}
int createShadedTextBox(lua_State * L)
{
int argc = lua_gettop(L);
if (argc == 7
&& lua_isstring(L, 1)
&& lua_isnumber(L, 2)
&& lua_isnumber(L, 3)
&& lua_isnumber(L, 4)
&& lua_isnumber(L, 5)
&& lua_isnumber(L, 6)
&& lua_isnumber(L, 7))
{
return createTextBoxCommon(L, 1,
lua_tostring(L, 1),
lua_tonumber(L, 2),
lua_tonumber(L, 3),
lua_tonumber(L, 4),
lua_tonumber(L, 5),
lua_tonumber(L, 6),
lua_tonumber(L, 7));
}
lua_pushnil(L);
return 1;
}
int createBlendedTextBox(lua_State * L)
{
int argc = lua_gettop(L);
if (argc == 4
&& lua_isstring(L, 1)
&& lua_isnumber(L, 2)
&& lua_isnumber(L, 3)
&& lua_isnumber(L, 4))
{
return createTextBoxCommon(L, 2,
lua_tostring(L, 1),
lua_tonumber(L, 2),
lua_tonumber(L, 3),
lua_tonumber(L, 4),
0, 0, 0);
}
lua_pushnil(L);
return 1;
}
static void addManagedObject(lua_State * L, bool is_static,
OdeWorld::GeomType geom_type, refptr< vector<float> > args)
{

3
ag.h
View File

@ -30,6 +30,9 @@ namespace ag
int import(lua_State * L);
int loadTexture(lua_State * L);
int getScreenSize(lua_State * L);
int createSolidTextBox(lua_State * L);
int createShadedTextBox(lua_State * L);
int createBlendedTextBox(lua_State * L);
int createBox(lua_State * L);
int createStaticBox(lua_State * L);

View File

@ -1,4 +1,7 @@
t = ag.createSolidTextBox("Hi there", 0, 0, 1)
ag.println("t: ", t)
function update_event()
ballx, bally, ballz = ball:getPosition()
ag.setCamera(7, -6, 15, ballx, bally, ballz, 0, 0, 1)