finished textbox implementation and it does not work -- apparently blitting to an OpenGL surface does not work for any font type... i'll have to switch to FTGL or something else

git-svn-id: svn://anubis/anaglym/trunk@161 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2009-11-08 05:02:06 +00:00
parent 8746e81fe4
commit 8425807f99
6 changed files with 51 additions and 1 deletions

View File

@ -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)
{

View File

@ -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);

View File

@ -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;

26
ag.cc
View File

@ -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;
}
}
}

5
ag.h
View File

@ -61,6 +61,11 @@ namespace ag
int setColor(lua_State * L);
int setTexture(lua_State * L);
}
namespace textbox
{
int draw(lua_State * L);
}
}
#endif

View File

@ -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)