added mouse button down/up and mouse motion events
git-svn-id: svn://anubis/anaglym/trunk@111 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
978293a57e
commit
bd4eab495c
65
Engine.cc
65
Engine.cc
@ -321,13 +321,25 @@ void Engine::run()
|
|||||||
case SDL_KEYUP:
|
case SDL_KEYUP:
|
||||||
key_released_event(event.key.keysym.sym);
|
key_released_event(event.key.keysym.sym);
|
||||||
break;
|
break;
|
||||||
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
|
mousebutton_pressed_event(event.button.button,
|
||||||
|
event.button.x, event.button.y);
|
||||||
|
break;
|
||||||
|
case SDL_MOUSEBUTTONUP:
|
||||||
|
mousebutton_released_event(event.button.button,
|
||||||
|
event.button.x, event.button.y);
|
||||||
|
break;
|
||||||
|
case SDL_MOUSEMOTION:
|
||||||
|
mouse_motion_event(event.motion.x, event.motion.y,
|
||||||
|
event.motion.xrel, event.motion.yrel);
|
||||||
|
break;
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
goto RET;
|
goto RET;
|
||||||
break;
|
break;
|
||||||
case SDL_USEREVENT:
|
case SDL_USEREVENT:
|
||||||
if (event.user.code == 0)
|
if (event.user.code == 0)
|
||||||
{
|
{
|
||||||
update();
|
update_event();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -336,7 +348,7 @@ RET:
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::update()
|
void Engine::update_event()
|
||||||
{
|
{
|
||||||
m_drawing = true;
|
m_drawing = true;
|
||||||
if (m_autoPhysics)
|
if (m_autoPhysics)
|
||||||
@ -388,6 +400,55 @@ void Engine::key_released_event(int keysym)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Engine::mousebutton_pressed_event(int button, int x, int y)
|
||||||
|
{
|
||||||
|
if (m_event_mousebutton_pressed_present)
|
||||||
|
{
|
||||||
|
lua_getfield(m_luaState, LUA_GLOBALSINDEX,
|
||||||
|
AG_EVENT_PREFIX "mousebutton_pressed");
|
||||||
|
lua_pushinteger(m_luaState, button);
|
||||||
|
lua_pushnumber(m_luaState, x);
|
||||||
|
lua_pushnumber(m_luaState, y);
|
||||||
|
/* call the mouse button pressed event function
|
||||||
|
* This pops the function ref and arguments from the stack */
|
||||||
|
int s = lua_pcall(m_luaState, 3, LUA_MULTRET, 0);
|
||||||
|
reportErrors(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::mousebutton_released_event(int button, int x, int y)
|
||||||
|
{
|
||||||
|
if (m_event_mousebutton_released_present)
|
||||||
|
{
|
||||||
|
lua_getfield(m_luaState, LUA_GLOBALSINDEX,
|
||||||
|
AG_EVENT_PREFIX "mousebutton_released");
|
||||||
|
lua_pushinteger(m_luaState, button);
|
||||||
|
lua_pushnumber(m_luaState, x);
|
||||||
|
lua_pushnumber(m_luaState, y);
|
||||||
|
/* call the mouse button released event function
|
||||||
|
* This pops the function ref and arguments from the stack */
|
||||||
|
int s = lua_pcall(m_luaState, 3, LUA_MULTRET, 0);
|
||||||
|
reportErrors(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::mouse_motion_event(int x, int y, int xrel, int yrel)
|
||||||
|
{
|
||||||
|
if (m_event_mouse_motion_present)
|
||||||
|
{
|
||||||
|
lua_getfield(m_luaState, LUA_GLOBALSINDEX,
|
||||||
|
AG_EVENT_PREFIX "mouse_motion");
|
||||||
|
lua_pushnumber(m_luaState, x);
|
||||||
|
lua_pushnumber(m_luaState, y);
|
||||||
|
lua_pushnumber(m_luaState, xrel);
|
||||||
|
lua_pushnumber(m_luaState, yrel);
|
||||||
|
/* call the mouse motion event function
|
||||||
|
* This pops the function ref and arguments from the stack */
|
||||||
|
int s = lua_pcall(m_luaState, 4, LUA_MULTRET, 0);
|
||||||
|
reportErrors(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Engine::checkForFunctionFull(const std::string & lua_fn_name,
|
void Engine::checkForFunctionFull(const std::string & lua_fn_name,
|
||||||
const std::string & event_name, bool & presentFlag)
|
const std::string & event_name, bool & presentFlag)
|
||||||
{
|
{
|
||||||
|
5
Engine.h
5
Engine.h
@ -116,9 +116,12 @@ class Engine
|
|||||||
Uint32 updateCallback(Uint32 interval);
|
Uint32 updateCallback(Uint32 interval);
|
||||||
void registerLibraries();
|
void registerLibraries();
|
||||||
bool fileExists(const std::string & path);
|
bool fileExists(const std::string & path);
|
||||||
void update();
|
void update_event();
|
||||||
void key_pressed_event(int keysym);
|
void key_pressed_event(int keysym);
|
||||||
void key_released_event(int keysym);
|
void key_released_event(int keysym);
|
||||||
|
void mousebutton_pressed_event(int button, int x, int y);
|
||||||
|
void mousebutton_released_event(int button, int x, int y);
|
||||||
|
void mouse_motion_event(int x, int y, int xrel, int yrel);
|
||||||
Object * createObject(bool is_static, GLuint display_list,
|
Object * createObject(bool is_static, GLuint display_list,
|
||||||
float scale = 1.0f)
|
float scale = 1.0f)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user