summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2011-08-20 17:18:09 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2011-08-20 17:18:09 (GMT)
commit99b67598aa7400300d7e548bc5d0293f09632c25 (patch)
treeb690bb37dab412500f7118077bd179891ac4b475 /src
parent03ee03ed1e735352082fa35a06444bbf389bf9c6 (diff)
downloadpowder-99b67598aa7400300d7e548bc5d0293f09632c25.zip
powder-99b67598aa7400300d7e548bc5d0293f09632c25.tar.gz
Changes to unify mouse and keyboard events for Lua
Diffstat (limited to 'src')
-rw-r--r--src/interface.c5
-rw-r--r--src/luaconsole.c23
-rw-r--r--src/main.c24
3 files changed, 36 insertions, 16 deletions
diff --git a/src/interface.c b/src/interface.c
index 5679a5f..0b8a2d2 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -26,7 +26,7 @@
#endif
SDLMod sdl_mod;
-int sdl_key, sdl_wheel, sdl_caps=0, sdl_ascii, sdl_zoom_trig=0;
+int sdl_key, sdl_rkey, sdl_wheel, sdl_caps=0, sdl_ascii, sdl_zoom_trig=0;
#if (defined(LIN32) || defined(LIN64)) && defined(SDL_VIDEO_DRIVER_X11)
SDL_SysWMinfo sdl_wminfo;
Atom XA_CLIPBOARD, XA_TARGETS;
@@ -2206,7 +2206,7 @@ int color_menu_ui(pixel *vid_buf, int i, int *cr, int *cg, int *cb, int b, int b
int sdl_poll(void)
{
SDL_Event event;
- sdl_key=sdl_wheel=sdl_ascii=0;
+ sdl_key=sdl_rkey=sdl_wheel=sdl_ascii=0;
while (SDL_PollEvent(&event))
{
switch (event.type)
@@ -2266,6 +2266,7 @@ int sdl_poll(void)
break;
case SDL_KEYUP:
+ sdl_rkey=event.key.keysym.sym;
if (event.key.keysym.sym == SDLK_CAPSLOCK)
sdl_caps = 0;
if (event.key.keysym.sym == 'z')
diff --git a/src/luaconsole.c b/src/luaconsole.c
index 186764d..1376252 100644
--- a/src/luaconsole.c
+++ b/src/luaconsole.c
@@ -39,6 +39,10 @@ void luacon_open(){
{"unregister_mouseclick", &luatpt_unregister_mouseclick},
{"register_keypress", &luatpt_register_keypress},
{"unregister_keypress", &luatpt_unregister_keypress},
+ {"register_mouseevent", &luatpt_register_mouseclick},
+ {"unregister_mouseevent", &luatpt_unregister_mouseclick},
+ {"register_keyevent", &luatpt_register_keypress},
+ {"unregister_keyevent", &luatpt_unregister_keypress},
{"input", &luatpt_input},
{"message_box", &luatpt_message_box},
{"get_numOfParts", &luatpt_get_numOfParts},
@@ -70,7 +74,7 @@ void luacon_open(){
lua_pushinteger(l, 0);
lua_setfield(l, tptProperties, "mousey");
}
-int luacon_keypress(char key, int modifier){
+int luacon_keyevent(char key, int modifier, int event){
int i = 0, kpcontinue = 1;
if(keypress_function_count){
for(i = 0; i < keypress_function_count && kpcontinue; i++){
@@ -78,7 +82,8 @@ int luacon_keypress(char key, int modifier){
lua_pushstring(l, &key);
lua_pushinteger(l, key);
lua_pushinteger(l, modifier);
- lua_pcall(l, 3, 1, 0);
+ lua_pushinteger(l, event);
+ lua_pcall(l, 4, 1, 0);
if(lua_isboolean(l, -1)){
kpcontinue = lua_toboolean(l, -1);
}
@@ -87,15 +92,15 @@ int luacon_keypress(char key, int modifier){
}
return kpcontinue;
}
-int luacon_mouseclick(int mx, int my, int mb, int mbq){
+int luacon_mouseevent(int mx, int my, int mb, int event){
int i = 0, mpcontinue = 1;
if(mouseclick_function_count){
for(i = 0; i < mouseclick_function_count && mpcontinue; i++){
lua_rawgeti(l, LUA_REGISTRYINDEX, mouseclick_functions[i]);
- lua_pushinteger(l, mbq);
- lua_pushinteger(l, mb);
lua_pushinteger(l, mx);
lua_pushinteger(l, my);
+ lua_pushinteger(l, mb);
+ lua_pushinteger(l, event);
lua_pcall(l, 4, 1, 0);
if(lua_isboolean(l, -1)){
mpcontinue = lua_toboolean(l, -1);
@@ -107,12 +112,12 @@ int luacon_mouseclick(int mx, int my, int mb, int mbq){
}
int luacon_step(int mx, int my){
int tempret = 0, tempb, i, callret;
+ lua_pushinteger(l, my);
+ lua_pushinteger(l, mx);
+ lua_setfield(l, tptProperties, "mousex");
+ lua_setfield(l, tptProperties, "mousey");
if(step_functions[0]){
//Set mouse globals
- lua_pushinteger(l, my);
- lua_pushinteger(l, mx);
- lua_setfield(l, tptProperties, "mousex");
- lua_setfield(l, tptProperties, "mousey");
for(i = 0; i<6; i++){
if(step_functions[i]){
lua_rawgeti(l, LUA_REGISTRYINDEX, step_functions[i]);
diff --git a/src/main.c b/src/main.c
index 6de8abe..e92c0a7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1576,7 +1576,7 @@ int main(int argc, char *argv[])
void *http_ver_check, *http_session_check = NULL;
char *ver_data=NULL, *check_data=NULL, *tmp;
//char console_error[255] = "";
- int result, i, j, bq, fire_fc=0, do_check=0, do_s_check=0, old_version=0, http_ret=0,http_s_ret=0, major, minor, old_ver_len, new_message_len=0;
+ int result, i, j, bq, bc, fire_fc=0, do_check=0, do_s_check=0, old_version=0, http_ret=0,http_s_ret=0, major, minor, old_ver_len, new_message_len=0;
#ifdef INTERNAL
int vs = 0;
#endif
@@ -2003,9 +2003,13 @@ int main(int argc, char *argv[])
}
#ifdef LUACONSOLE
if(sdl_key){
- if(!luacon_keypress(sdl_key, sdl_mod))
+ if(!luacon_keyevent(sdl_key, sdl_mod, LUACON_KDOWN))
sdl_key = 0;
}
+ if(sdl_rkey){
+ if(!luacon_keyevent(sdl_rkey, sdl_mod, LUACON_KUP))
+ sdl_rkey = 0;
+ }
#endif
#ifdef PYCONSOLE
if(sdl_key){
@@ -2515,11 +2519,21 @@ int main(int argc, char *argv[])
}
bq = b; // bq is previous mouse state
- b = SDL_GetMouseState(&x, &y); // b is current mouse state
+ bc = b = SDL_GetMouseState(&x, &y); // b is current mouse state
#ifdef LUACONSOLE
- if(b){
- if(!luacon_mouseclick(x/sdl_scale, y/sdl_scale, b, bq)){
+ if(bc && bq){
+ if(!luacon_mouseevent(x/sdl_scale, y/sdl_scale, bc, LUACON_MPRESS)){
+ b = 0;
+ }
+ }
+ else if(bc && !bq){
+ if(!luacon_mouseevent(x/sdl_scale, y/sdl_scale, bc, LUACON_MDOWN)){
+ b = 0;
+ }
+ }
+ else if(!bc && bq){
+ if(!luacon_mouseevent(x/sdl_scale, y/sdl_scale, bq, LUACON_MUP)){
b = 0;
}
}