From 8746e81fe46ee5a4044a931321d80f15f9c764d5 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 8 Nov 2009 04:33:25 +0000 Subject: [PATCH] added create*TextBox() methods for creating various types of text boxes git-svn-id: svn://anubis/anaglym/trunk@160 99a6e188-d820-4881-8870-2d33a10e2619 --- Engine.cc | 9 ++--- Engine.h | 5 +-- ag.cc | 85 ++++++++++++++++++++++++++++++++++++++++++++ ag.h | 3 ++ tests/ballstairs.lua | 3 ++ 5 files changed, 99 insertions(+), 6 deletions(-) diff --git a/Engine.cc b/Engine.cc index bd9daef..e12ef06 100644 --- a/Engine.cc +++ b/Engine.cc @@ -128,8 +128,8 @@ Engine::~Engine() { delete it->second; } - for (std::map::iterator it = m_texts.begin(); - it != m_texts.end(); + for (std::map::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; diff --git a/Engine.h b/Engine.h index 85dfee6..7ba3240 100644 --- a/Engine.h +++ b/Engine.h @@ -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 m_objects; int m_next_object_index; - std::map m_texts; + std::map m_textboxes; int m_next_text_index; GLdouble m_eye[3]; GLdouble m_center[3]; diff --git a/ag.cc b/ag.cc index 3451804..6730c6d 100644 --- a/ag.cc +++ b/ag.cc @@ -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 > args) { diff --git a/ag.h b/ag.h index 0a0a633..5706779 100644 --- a/ag.h +++ b/ag.h @@ -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); diff --git a/tests/ballstairs.lua b/tests/ballstairs.lua index 4324f18..7244a13 100755 --- a/tests/ballstairs.lua +++ b/tests/ballstairs.lua @@ -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)