new input thingies

This commit is contained in:
Jakob Fries 2007-06-10 15:19:04 +00:00
parent 6523310be6
commit 7ad13ccb12
5 changed files with 58 additions and 62 deletions

View file

@ -1,6 +1,5 @@
#include <baselib/system.h>
#include <baselib/keys.h>
#include <baselib/mouse.h>
#include <baselib/input.h>
#include <baselib/audio.h>
#include <baselib/stream/file.h>
@ -68,15 +67,15 @@ void snap_decode_string(const int *src, char *dst, int max_length)
}
// --- input wrappers ---
static int keyboard_state[2][keys::last];
static int keyboard_state[2][input::last];
static int keyboard_current = 0;
static int keyboard_first = 1;
void inp_mouse_relative(int *x, int *y) { mouse::position(x, y); }
void inp_mouse_relative(int *x, int *y) { input::mouse_position(x, y); }
int inp_key_pressed(int key) { return keyboard_state[keyboard_current][key]; }
int inp_key_was_pressed(int key) { return keyboard_state[keyboard_current^1][key]; }
int inp_key_down(int key) { return inp_key_pressed(key)&&!inp_key_was_pressed(key); }
int inp_mouse_button_pressed(int button) { return mouse::pressed(button); }
int inp_button_pressed(int button) { return input::pressed(button); }
void inp_update()
{
@ -88,8 +87,8 @@ void inp_update()
}
keyboard_current = keyboard_current^1;
for(int i = 0; i < keys::last; i++)
keyboard_state[keyboard_current][i] = keys::pressed(i);
for(int i = 0; i < input::last; i++)
keyboard_state[keyboard_current][i] = input::pressed(i);
}
// --- input snapping ---
@ -479,7 +478,7 @@ public:
int64 reportinterval = time_freq()*1;
int frames = 0;
mouse::set_mode(mouse::mode_relative);
input::set_mouse_mode(input::mode_relative);
while (1)
{
@ -501,10 +500,10 @@ public:
inp_update();
//
if(keys::pressed(keys::f1))
mouse::set_mode(mouse::mode_absolute);
if(keys::pressed(keys::f2))
mouse::set_mode(mouse::mode_relative);
if(input::pressed(input::f1))
input::set_mouse_mode(input::mode_absolute);
if(input::pressed(input::f2))
input::set_mouse_mode(input::mode_relative);
// pump the network
pump_network();
@ -533,7 +532,7 @@ public:
conn.counter_reset();
}
if (keys::pressed(keys::esc))
if (input::pressed(input::esc))
if (get_state() == STATE_CONNECTING || get_state() == STATE_ONLINE)
disconnect();

View file

@ -6,7 +6,7 @@
*/
// TODO: Move the definitions of these keys here
#include <baselib/keys.h>
#include <baselib/input.h>
enum
{
@ -331,22 +331,6 @@ bool snd_shutdown();
*/
void inp_mouse_relative(int *x, int *y);
/*
Function: inp_mouse_button_pressed
Checks if a mouse button is pressed.
Arguments:
button - Index to the button to check.
* 0 - Left mouse button.
* 1 - Right mouse button.
* 2 - Middle mouse button.
* Others over 2 is undefined mouse buttons.
Returns:
Returns 1 if the button is pressed, otherwise 0.
*/
int inp_mouse_button_pressed(int button);
/*
Function: inp_key_pressed
Checks if a key is pressed.

View file

@ -1742,10 +1742,10 @@ void modc_render()
input.angle = (int)(a*256.0f);
input.jump = inp_key_pressed(config.key_jump);
input.fire = inp_mouse_button_pressed(0);// | (oldinput.fire << 16);
input.fire = inp_key_pressed(input::mouse_1);// | (oldinput.fire << 16);
//oldinput.fire = input.fire & 0x0000ffff;
input.hook = inp_mouse_button_pressed(1) || inp_key_pressed(baselib::keys::lctrl); // be nice to mac users O.o
input.hook = inp_key_pressed(input::mouse_2) || inp_key_pressed(baselib::input::lctrl); // be nice to mac users O.o
input.blink = inp_key_pressed('S');
// Weapon switching
@ -1965,7 +1965,7 @@ void modc_render()
// render gui stuff
gfx_mapscreen(0,0,400,300);
// render score board
if(inp_key_pressed(baselib::keys::tab))
if(inp_key_pressed(baselib::input::tab))
{
gfx_texture_set(font_texture);
gfx_quads_text(10, 50, 8, "Score Board");

View file

@ -3,8 +3,7 @@
#include <string.h>
#include <baselib/system.h>
#include <baselib/keys.h>
#include <baselib/mouse.h>
#include <baselib/input.h>
#include <baselib/network.h>
#include <engine/interface.h>
@ -119,7 +118,6 @@ struct gui_part
{
int x, y;
int w, h;
bool stretch_x, stretch_y;
};
gui_part parts[] =
@ -427,24 +425,39 @@ struct server_list
int ui_do_key_reader(void *id, float x, float y, float w, float h, int key)
{
// process
static bool can_be_selected = true;
int inside = ui_mouse_inside(x, y, w, h);
int new_key = key;
if (inside)
{
ui_set_hot_item(id);
if (!ui_mouse_button(0) && !can_be_selected)
can_be_selected = true;
if (ui_mouse_button(0))
ui_set_active_item(id);
if (can_be_selected)
{
if (inside)
{
ui_set_hot_item(id);
if (ui_mouse_button(0) && ui_active_item() != id)
{
ui_set_active_item(id);
can_be_selected = false;
}
}
}
if (ui_active_item() == id)
if (can_be_selected)
{
int k = keys::last_key();
if (k)
if (ui_active_item() == id)
{
new_key = k;
ui_set_active_item(0);
int k = input::last_key();
dbg_msg("menu/-", "%i", k);
if (k)
{
new_key = k;
ui_set_active_item(0);
can_be_selected = false;
}
}
}
@ -452,7 +465,7 @@ int ui_do_key_reader(void *id, float x, float y, float w, float h, int key)
gui_composite_box_enum box_style = screen_info_box;
draw_box(box_style, tileset_regular, x, y, w, h);
const char *str = keys::key_name(key);
const char *str = input::key_name(key);
ui_do_label(x + 10, y, str, 36);
if (ui_active_item() == id)
{
@ -530,8 +543,8 @@ int ui_do_edit_box(void *id, float x, float y, float w, float h, char *str, int
if (ui_active_item() == id)
{
int c = keys::last_char();
int k = keys::last_key();
int c = input::last_char();
int k = input::last_key();
int len = strlen(str);
if (c >= 32 && c < 128)
@ -543,7 +556,7 @@ int ui_do_edit_box(void *id, float x, float y, float w, float h, char *str, int
}
}
if (k == keys::backspace)
if (k == input::backspace)
{
if (len > 0)
str[len-1] = 0;
@ -926,8 +939,8 @@ static int menu_render(netaddr4 *server_address)
void modmenu_init()
{
keys::enable_char_cache();
keys::enable_key_cache();
input::enable_char_cache();
input::enable_key_cache();
current_font->font_texture = gfx_load_texture("data/big_font.png");
@ -974,9 +987,9 @@ int modmenu_render(void *ptr)
mwy = mx*3.0f; // adjust to zoom and offset
int buttons = 0;
if(inp_mouse_button_pressed(0)) buttons |= 1;
if(inp_mouse_button_pressed(1)) buttons |= 2;
if(inp_mouse_button_pressed(2)) buttons |= 4;
if(inp_key_pressed(input::mouse_1)) buttons |= 1;
if(inp_key_pressed(input::mouse_2)) buttons |= 2;
if(inp_key_pressed(input::mouse_3)) buttons |= 4;
ui_update(mx,my,mx*3.0f,my*3.0f,buttons);
}
@ -1003,8 +1016,8 @@ int modmenu_render(void *ptr)
music_menu_id = -1;
}
keys::clear_char();
keys::clear_key();
input::clear_char();
input::clear_key();
return r;
}

View file

@ -1,8 +1,8 @@
MACRO_CONFIG_INT(screen_width, 800, 0, 0)
MACRO_CONFIG_INT(screen_height, 600, 0, 0)
MACRO_CONFIG_STR(player_name, 32, "nameless tee")
MACRO_CONFIG_INT(key_move_left, 65, 32, 127)
MACRO_CONFIG_INT(key_move_right, 68, 32, 127)
MACRO_CONFIG_INT(key_jump, 32, 32, 127)
MACRO_CONFIG_INT(key_fire, 33, 32, 127)
MACRO_CONFIG_INT(key_hook, 34, 32, 127)
MACRO_CONFIG_INT(key_move_left, 65, 32, 512)
MACRO_CONFIG_INT(key_move_right, 68, 32, 512)
MACRO_CONFIG_INT(key_jump, 32, 32, 512)
MACRO_CONFIG_INT(key_fire, 33, 32, 512)
MACRO_CONFIG_INT(key_hook, 34, 32, 512)