diff --git a/Engine.cc b/Engine.cc index e12ef06..8cf80db 100644 --- a/Engine.cc +++ b/Engine.cc @@ -503,6 +503,15 @@ void Engine::getScreenSize(int * width, int * height) *height = m_video.getHeight(); } +void Engine::drawText(int id, int x, int y) +{ + if (m_textboxes.find(id) != m_textboxes.end()) + { + SDL_Rect dstrect = {x, y, 0, 0}; + SDL_BlitSurface(m_textboxes[id], NULL, m_video.getSurface(), &dstrect); + } +} + /* called by SDL when the update timer expires */ Uint32 Engine::updateCallback(Uint32 interval, void * param) { diff --git a/Engine.h b/Engine.h index 7ba3240..131d991 100644 --- a/Engine.h +++ b/Engine.h @@ -139,6 +139,7 @@ class Engine Uint8 r, Uint8 g, Uint8 b, Uint8 br = 0, Uint8 bg = 0, Uint8 bb = 0); void getScreenSize(int * width, int * height); + void drawText(int id, int x, int y); /* lua services */ int setCamera(lua_State * L); diff --git a/Video.h b/Video.h index 3ed6b01..0638d81 100644 --- a/Video.h +++ b/Video.h @@ -17,6 +17,7 @@ class Video void toggleFullScreen() { SDL_WM_ToggleFullScreen(m_surface); } int getWidth() { return m_width; } int getHeight() { return m_height; } + SDL_Surface * getSurface() { return m_surface; } protected: int m_defaultWidth; diff --git a/ag.cc b/ag.cc index 6730c6d..4528a53 100644 --- a/ag.cc +++ b/ag.cc @@ -359,6 +359,8 @@ namespace ag lua_newtable(L); lua_pushinteger(L, id); lua_setfield(L, -2, "id"); + lua_pushcfunction(L, textbox::draw); + lua_setfield(L, -2, "draw"); } else { @@ -853,4 +855,28 @@ namespace ag return 0; } } + + namespace textbox + { + int draw(lua_State * L) + { + int argc = lua_gettop(L); + if (argc == 3 + && lua_istable(L, 1) + && lua_isnumber(L, 2) + && lua_isnumber(L, 3)) + { + lua_getfield(L, 1, "id"); + if (lua_isnumber(L, -1)) + { + int id = lua_tonumber(L, -1); + g_engine->drawText(id, + lua_tonumber(L, 2), + lua_tonumber(L, 3)); + } + lua_pop(L, 1); + } + return 0; + } + } } diff --git a/ag.h b/ag.h index 5706779..2138aa7 100644 --- a/ag.h +++ b/ag.h @@ -61,6 +61,11 @@ namespace ag int setColor(lua_State * L); int setTexture(lua_State * L); } + + namespace textbox + { + int draw(lua_State * L); + } } #endif diff --git a/tests/ballstairs.lua b/tests/ballstairs.lua index 7244a13..98014b9 100755 --- a/tests/ballstairs.lua +++ b/tests/ballstairs.lua @@ -1,6 +1,9 @@ t = ag.createSolidTextBox("Hi there", 0, 0, 1) -ag.println("t: ", t) +t2 = ag.createShadedTextBox("Hi there", 0, 1, 1, 0, 0, 0) +t3 = ag.createBlendedTextBox("Hi there", 1, 1, 1) +ag.setAutoEndFrame(false) +ag.setAutoDrawObjects(false) function update_event() ballx, bally, ballz = ball:getPosition() @@ -8,6 +11,11 @@ function update_event() if (ag.isKeyDown("m")) then ball:setPosition(-7, 7.4, 12) end + ag.drawObjects() + ag.endFrame() + t:draw(10, 10) + t2:draw(10, 40) + t3:draw(10, 90) end function key_down_event(key)