added ag::drawLine()
git-svn-id: svn://anubis/anaglym/trunk@183 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
42762f4f3c
commit
27c0d4f7b9
16
Engine.cc
16
Engine.cc
@ -524,6 +524,22 @@ void Engine::getTextSize(const char * text, int ptsize,
|
||||
*height = box.Upper().Yf() - box.Lower().Yf();
|
||||
}
|
||||
|
||||
void Engine::drawLine(float r, float g, float b,
|
||||
float x1, float y1, float x2, float y2, float width)
|
||||
{
|
||||
glPushAttrib(GL_LINE_BIT | GL_ENABLE_BIT);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
glLineWidth(width);
|
||||
glBegin(GL_LINES);
|
||||
glColor3f(r, g, b);
|
||||
glVertex2f(x1, y1);
|
||||
glVertex2f(x2, y2);
|
||||
glEnd();
|
||||
glPopAttrib();
|
||||
}
|
||||
|
||||
/* called by SDL when the update timer expires */
|
||||
Uint32 Engine::updateCallback(Uint32 interval, void * param)
|
||||
{
|
||||
|
2
Engine.h
2
Engine.h
@ -143,6 +143,8 @@ class Engine
|
||||
int ptsize, float x, float y);
|
||||
void getTextSize(const char * text, int ptsize,
|
||||
float * width, float * height);
|
||||
void drawLine(float r, float g, float b,
|
||||
float x1, float y1, float x2, float y2, float width = 1.0f);
|
||||
|
||||
/* lua services */
|
||||
int setCamera(lua_State * L);
|
||||
|
29
ag.cc
29
ag.cc
@ -46,6 +46,7 @@ namespace ag
|
||||
{ "getScreenSize", getScreenSize },
|
||||
{ "drawText", drawText},
|
||||
{ "getTextSize", getTextSize},
|
||||
{ "drawLine", drawLine},
|
||||
|
||||
{ "createBox", createBox},
|
||||
{ "createStaticBox", createStaticBox},
|
||||
@ -391,6 +392,34 @@ namespace ag
|
||||
return 2;
|
||||
}
|
||||
|
||||
int drawLine(lua_State * L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
if (argc == 7 || argc == 8)
|
||||
{
|
||||
bool valid = true;
|
||||
for (int i = 1; i <= argc; i++)
|
||||
if (!lua_isnumber(L, i))
|
||||
valid = false;
|
||||
if (valid)
|
||||
{
|
||||
float width = 1.0f;
|
||||
if (argc == 8)
|
||||
width = lua_tonumber(L, 8);
|
||||
g_engine->drawLine(
|
||||
lua_tonumber(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),
|
||||
width);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void addManagedObject(lua_State * L, bool is_static,
|
||||
OdeWorld::GeomType geom_type, refptr< vector<float> > args)
|
||||
{
|
||||
|
1
ag.h
1
ag.h
@ -32,6 +32,7 @@ namespace ag
|
||||
int getScreenSize(lua_State * L);
|
||||
int drawText(lua_State * L);
|
||||
int getTextSize(lua_State * L);
|
||||
int drawLine(lua_State * L);
|
||||
|
||||
int createBox(lua_State * L);
|
||||
int createStaticBox(lua_State * L);
|
||||
|
@ -52,7 +52,9 @@ function key_down_event(key)
|
||||
end
|
||||
end
|
||||
|
||||
--function update_overlay_event(width, height)
|
||||
-- local tw, th = ag.getTextSize("Hi there", 18)
|
||||
-- ag.drawText("Hi there", 1, 1, 1, 18, width - tw - 4, height - th - 4)
|
||||
--end
|
||||
function update_overlay_event(width, height)
|
||||
local tw, th = ag.getTextSize("Hi there", 18)
|
||||
ag.drawText("Hi there", 1, 1, 1, 18, width - tw - 4, height - th - 4)
|
||||
ag.drawLine(1, 0, 0.3, 10, 10, 40, 60)
|
||||
ag.drawLine(1, 0.7, 1, 50, 10, 100, 60, 5)
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user