cleanups of input

This commit is contained in:
p.kosyh 2010-01-23 16:02:22 +00:00
parent 5375c44d4f
commit de7d54ddc1
2 changed files with 19 additions and 18 deletions

View file

@ -2135,7 +2135,7 @@ static int is_key(struct inp_event *ev, const char *name)
return strcmp(ev->sym, name); return strcmp(ev->sym, name);
} }
static int game_input(int down, const char *key, int x, int y) static int game_input(int down, const char *key, int x, int y, int mb)
{ {
char *p; char *p;
char buf[1024]; char buf[1024];
@ -2145,8 +2145,8 @@ static int game_input(int down, const char *key, int x, int y)
if (!p) if (!p)
return -1; return -1;
if (x == -1) if (mb == -1)
snprintf(buf, sizeof(buf), "return stead.input(%s, \"%s\")", snprintf(buf, sizeof(buf), "return stead.input(\"kbd\", %s, \"%s\")",
((down)?"true":"false"), p); ((down)?"true":"false"), p);
else { else {
float v = game_theme.scale; float v = game_theme.scale;
@ -2154,8 +2154,8 @@ static int game_input(int down, const char *key, int x, int y)
x = (int)((float)x / v); x = (int)((float)x / v);
y = (int)((float)y / v); y = (int)((float)y / v);
} }
snprintf(buf, sizeof(buf), "return stead.input(%s, \"%s\", %d, %d)", snprintf(buf, sizeof(buf), "return stead.input(\"mouse\", %s, %d, %d, %d)",
((down)?"true":"false"), p, x, y); ((down)?"true":"false"), x, y, mb);
} }
free(p); free(p);
if (instead_eval(buf)) { if (instead_eval(buf)) {
@ -2186,10 +2186,10 @@ int game_loop(void)
if (rc == -1) {/* close */ if (rc == -1) {/* close */
break; break;
} else if (curgame_dir && (ev.type == KEY_DOWN || ev.type == KEY_UP) } else if (curgame_dir && (ev.type == KEY_DOWN || ev.type == KEY_UP)
&& !game_input((ev.type == KEY_DOWN), ev.sym, -1, -1)) { && !game_input((ev.type == KEY_DOWN), ev.sym, -1, -1, -1)) {
; /* all is done in game_input */ ; /* all is done in game_input */
} else if (curgame_dir && (ev.type == MOUSE_DOWN || ev.type == MOUSE_UP) } else if (curgame_dir && (ev.type == MOUSE_DOWN || ev.type == MOUSE_UP)
&& !game_input((ev.type == MOUSE_DOWN), "mouse", ev.x, ev.y)) { && !game_input((ev.type == MOUSE_DOWN), "mouse", ev.x, ev.y, ev.code)) {
; /* all is done in game_input */ ; /* all is done in game_input */
} else if (((ev.type == KEY_DOWN) || (ev.type == KEY_UP)) && } else if (((ev.type == KEY_DOWN) || (ev.type == KEY_UP)) &&
(!is_key(&ev, "left alt") || !is_key(&ev, "right alt"))) { (!is_key(&ev, "left alt") || !is_key(&ev, "right alt"))) {

View file

@ -12,16 +12,17 @@ stead = {
end end
return return
end, end,
input = function(pressed, event, x, y) input = function(event, ...)
if type(input) == 'table' then if type(input) ~= 'table' then
if event == 'mouse' then return
if type(input.click) == 'function' then end
return input:click(pressed, x, y); if event == 'kbd' then
end if type(input.key) == 'function' then
else return input:key(unpack(arg)); -- pressed, event
if type(input.key) == 'function' then end
return input:key(pressed, event); elseif event == 'mouse' then
end if type(input.click) == 'function' then
return input:click(unpack(arg)); -- pressed, x, y, mb
end end
end end
return return
@ -1868,7 +1869,7 @@ input = obj { -- input object
--[[ key = function(s, down, key) --[[ key = function(s, down, key)
return return
end, ]] end, ]]
--[[ click = function(s, down, x, y) --[[ click = function(s, down, x, y, mb)
return return
end ]] end ]]
}; };