diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/input.cc | 8 | ||||
-rw-r--r-- | src/client/joystick.cc | 48 | ||||
-rw-r--r-- | src/client/joystick.h | 2 | ||||
-rw-r--r-- | src/client/view.cc | 28 |
4 files changed, 73 insertions, 13 deletions
diff --git a/src/client/input.cc b/src/client/input.cc index aa4a954..7188de0 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -153,6 +153,11 @@ void func_view_prev(std::string const &args) } } +void func_list_joystick(std::string const &args) +{ + Joystick::list(); +} + void func_list_actions(std::string const &args) { if (keyboard) @@ -264,6 +269,9 @@ void init() func = core::Func::add("ui_control",func_ui_control); func->set_info("toggle mouse control"); + func = core::Func::add("list_joystick", func_list_joystick); + func->set_info("list joysticks"); + func = core::Func::add("list_actions", func_list_actions); func->set_info("list key action names"); diff --git a/src/client/joystick.cc b/src/client/joystick.cc index 5f09280..486542e 100644 --- a/src/client/joystick.cc +++ b/src/client/joystick.cc @@ -15,7 +15,6 @@ namespace client { core::Cvar *input_joystick = 0; - int current_joystick_number = 0; SDL_Joystick *current_joystick = 0; @@ -56,6 +55,49 @@ void Joystick::shutdown() SDL_QuitSubSystem(SDL_INIT_JOYSTICK); } +void Joystick::list() +{ + if (current_joystick) { + SDL_JoystickEventState(SDL_IGNORE); + SDL_JoystickClose(current_joystick); + current_joystick = 0; + } + /* + // reset makes glorious segfaults + //SDL_QuitSubSystem(SDL_INIT_JOYSTICK); + //SDL_InitSubSystem(SDL_INIT_JOYSTICK); + */ + int nbjoysticks = SDL_NumJoysticks(); + if (nbjoysticks) { + for (int i=0; i < nbjoysticks; i++) { + SDL_Joystick *joystick = SDL_JoystickOpen(i); + if (joystick) { + con_print << " joystick " << i+1 << ": " << + SDL_JoystickName(i) << " " << + SDL_JoystickNumAxes(joystick) << " axes " << + SDL_JoystickNumButtons(joystick) << " buttons " << std::endl; + + SDL_JoystickClose(joystick); + } + } + } + + current_joystick_number = (int) input_joystick->value(); + if ((current_joystick_number < 1) || (current_joystick_number > nbjoysticks)) { + current_joystick_number = 0; + } + (*input_joystick) = (float) current_joystick_number; + + if (current_joystick_number) { + current_joystick = SDL_JoystickOpen(current_joystick_number -1); + } + + if (current_joystick) { + con_debug << " using joystick " << SDL_JoystickName(current_joystick_number -1) << std::endl; + SDL_JoystickEventState(SDL_ENABLE); + } +} + bool Joystick::is_enabled() { return (current_joystick != 0); @@ -72,6 +114,10 @@ void Joystick::frame() } current_joystick_number = (int) input_joystick->value(); + if ((current_joystick_number < 1) || (current_joystick_number > SDL_NumJoysticks())) { + current_joystick_number = 0; + } + (*input_joystick) = (float) current_joystick_number; if (current_joystick_number) { current_joystick = SDL_JoystickOpen(current_joystick_number -1); diff --git a/src/client/joystick.h b/src/client/joystick.h index 9404cb3..a21e24e 100644 --- a/src/client/joystick.h +++ b/src/client/joystick.h @@ -17,6 +17,8 @@ public: static void shutdown(); + static void list(); + static void frame(); static bool is_enabled(); diff --git a/src/client/view.cc b/src/client/view.cc index 77e0906..a2bdfe1 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -702,22 +702,26 @@ void frame(float elapsed) render::Camera::ortho(); } - // draw the user interface gl::color(1.0f, 1.0f, 1.0f, 1.0f); gl::disable(GL_TEXTURE_2D); gl::enable(GL_BLEND); - draw_cursor(); - ui::root()->frame(); - - // draw the hud - TODO move as much as possible into ui:: - if (draw_ui->value() && !ui::root()->active()) { - gl::enable(GL_TEXTURE_2D); - gl::color(1.0f, 1.0f, 1.0f, 1.0f); - Text::setfont("gui", 12, 18); - - // draw the hud - draw_hud(); + // draw the user interface + if (draw_ui->value()) { + draw_cursor(); + ui::root()->frame(); + + // draw the hud - TODO move as much as possible into ui:: + if (draw_ui->value() && !ui::root()->active()) { + gl::enable(GL_TEXTURE_2D); + gl::color(1.0f, 1.0f, 1.0f, 1.0f); + Text::setfont("gui", 12, 18); + + // draw the hud + draw_hud(); + } + } else if (ui::console()->visible()) { + ui::console()->event_draw(); } gl::disable(GL_TEXTURE_2D); |