Browse Source

Add files in the input folder to the input namespace

master
C. J. Howard 3 years ago
parent
commit
2db97b5d53
39 changed files with 524 additions and 434 deletions
  1. +1
    -0
      CMakeLists.txt
  2. +8
    -11
      src/application.cpp
  3. +13
    -13
      src/application.hpp
  4. +2
    -2
      src/ecs/systems/control-system.cpp
  5. +81
    -81
      src/ecs/systems/control-system.hpp
  6. +1
    -2
      src/ecs/systems/ui-system.cpp
  7. +3
    -3
      src/ecs/systems/ui-system.hpp
  8. +5
    -5
      src/event/input-events.cpp
  9. +20
    -23
      src/event/input-events.hpp
  10. +58
    -58
      src/game/bootloader.cpp
  11. +15
    -15
      src/game/game-context.hpp
  12. +1
    -1
      src/game/states/map-state.cpp
  13. +1
    -1
      src/game/states/splash-state.cpp
  14. +3
    -0
      src/input/control-set.cpp
  15. +7
    -3
      src/input/control-set.hpp
  16. +3
    -0
      src/input/control.cpp
  17. +7
    -5
      src/input/control.hpp
  18. +7
    -4
      src/input/device.cpp
  19. +9
    -7
      src/input/device.hpp
  20. +44
    -41
      src/input/event-router.cpp
  21. +12
    -8
      src/input/event-router.hpp
  22. +17
    -13
      src/input/game-controller.cpp
  23. +9
    -5
      src/input/game-controller.hpp
  24. +12
    -0
      src/input/input.hpp
  25. +7
    -4
      src/input/keyboard.cpp
  26. +9
    -5
      src/input/keyboard.hpp
  27. +16
    -12
      src/input/listener.cpp
  28. +8
    -5
      src/input/listener.hpp
  29. +18
    -15
      src/input/mapper.cpp
  30. +13
    -10
      src/input/mapper.hpp
  31. +21
    -18
      src/input/mapping.cpp
  32. +46
    -42
      src/input/mapping.hpp
  33. +11
    -8
      src/input/mouse.cpp
  34. +9
    -5
      src/input/mouse.hpp
  35. +7
    -3
      src/input/scancode.hpp
  36. +3
    -0
      src/input/sdl-game-controller-tables.cpp
  37. +7
    -3
      src/input/sdl-game-controller-tables.hpp
  38. +3
    -0
      src/input/sdl-scancode-table.cpp
  39. +7
    -3
      src/input/sdl-scancode-table.hpp

+ 1
- 0
CMakeLists.txt View File

@ -14,6 +14,7 @@ find_package(SDL2 REQUIRED COMPONENTS SDL2::SDL2-static SDL2::SDL2main CONFIG)
find_package(OpenAL REQUIRED CONFIG)
find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib")
# Determine dependencies
set(STATIC_LIBS
dr_wav

+ 8
- 11
src/application.cpp View File

@ -26,9 +26,6 @@
#include "input/scancode.hpp"
#include "input/sdl-game-controller-tables.hpp"
#include "input/sdl-scancode-table.hpp"
#include "input/keyboard.hpp"
#include "input/mouse.hpp"
#include "input/game-controller.hpp"
#include "resources/image.hpp"
#include <SDL2/SDL.h>
#include <glad/glad.h>
@ -208,9 +205,9 @@ application::application():
event_dispatcher = new ::event_dispatcher();
// Setup input
keyboard = new ::keyboard();
keyboard = new input::keyboard();
keyboard->set_event_dispatcher(event_dispatcher);
mouse = new ::mouse();
mouse = new input::mouse();
mouse->set_event_dispatcher(event_dispatcher);
// Setup frame scheduler
@ -481,10 +478,10 @@ void application::translate_sdl_events()
{
if (sdl_event.key.repeat == 0)
{
scancode scancode = scancode::unknown;
input::scancode scancode = input::scancode::unknown;
if (sdl_event.key.keysym.scancode <= SDL_SCANCODE_APP2)
{
scancode = sdl_scancode_table[sdl_event.key.keysym.scancode];
scancode = input::sdl_scancode_table[sdl_event.key.keysym.scancode];
}
if (sdl_event.type == SDL_KEYDOWN)
@ -526,7 +523,7 @@ void application::translate_sdl_events()
{
if (auto it = game_controller_map.find(sdl_event.cdevice.which); it != game_controller_map.end())
{
game_controller_button button = sdl_button_table[sdl_event.cbutton.button];
input::game_controller_button button = input::sdl_button_table[sdl_event.cbutton.button];
it->second->press(button);
}
}
@ -539,7 +536,7 @@ void application::translate_sdl_events()
{
if (auto it = game_controller_map.find(sdl_event.cdevice.which); it != game_controller_map.end())
{
game_controller_button button = sdl_button_table[sdl_event.cbutton.button];
input::game_controller_button button = input::sdl_button_table[sdl_event.cbutton.button];
it->second->release(button);
}
}
@ -552,7 +549,7 @@ void application::translate_sdl_events()
{
if (auto it = game_controller_map.find(sdl_event.cdevice.which); it != game_controller_map.end())
{
game_controller_axis axis = sdl_axis_table[sdl_event.caxis.axis];
input::game_controller_axis axis = input::sdl_axis_table[sdl_event.caxis.axis];
float value = sdl_event.caxis.value;
value /= (value < 0.0f) ? 32768.0f : 32767.0f;
it->second->move(axis, value);
@ -580,7 +577,7 @@ void application::translate_sdl_events()
{
logger->log("Connected game controller \"" + controller_name + "\"");
game_controller* controller = new game_controller();
input::game_controller* controller = new input::game_controller();
controller->set_event_dispatcher(event_dispatcher);
game_controllers.push_back(controller);
game_controller_map[sdl_event.cdevice.which] = controller;

+ 13
- 13
src/application.hpp View File

@ -26,15 +26,15 @@
#include <memory>
#include <unordered_map>
#include "gl/rasterizer.hpp"
#include "input/keyboard.hpp"
#include "input/mouse.hpp"
#include "input/game-controller.hpp"
// Forward declarations
typedef struct SDL_Window SDL_Window;
typedef void* SDL_GLContext;
class event_dispatcher;
class frame_scheduler;
class game_controller;
class keyboard;
class mouse;
class image;
namespace debug
@ -186,13 +186,13 @@ public:
debug::logger* get_logger();
/// Returns the virtual keyboard.
::keyboard* get_keyboard();
input::keyboard* get_keyboard();
/// Returns the virtual mouse.
::mouse* get_mouse();
input::mouse* get_mouse();
/// Returns the list of virtual game controllers.
const std::list<game_controller*>& get_game_controllers();
const std::list<input::game_controller*>& get_game_controllers();
/// Returns the application's event dispatcher.
event_dispatcher* get_event_dispatcher();
@ -232,10 +232,10 @@ private:
event_dispatcher* event_dispatcher;
// Input devices
keyboard* keyboard;
mouse* mouse;
std::list<game_controller*> game_controllers;
std::unordered_map<int, game_controller*> game_controller_map;
input::keyboard* keyboard;
input::mouse* mouse;
std::list<input::game_controller*> game_controllers;
std::unordered_map<int, input::game_controller*> game_controller_map;
};
inline debug::logger* application::get_logger()
@ -268,17 +268,17 @@ inline gl::rasterizer* application::get_rasterizer()
return rasterizer;
}
inline keyboard* application::get_keyboard()
inline input::keyboard* application::get_keyboard()
{
return keyboard;
}
inline mouse* application::get_mouse()
inline input::mouse* application::get_mouse()
{
return mouse;
}
inline const std::list<game_controller*>& application::get_game_controllers()
inline const std::list<input::game_controller*>& application::get_game_controllers()
{
return game_controllers;
}

+ 2
- 2
src/ecs/systems/control-system.cpp View File

@ -65,8 +65,8 @@ control_system::control_system(ecs::registry& registry):
control_set.add_control(&rewind_control);
// Set deadzone at 15% for all controls
const std::list<control*>* controls = control_set.get_controls();
for (control* control: *controls)
const std::list<input::control*>* controls = control_set.get_controls();
for (input::control* control: *controls)
{
control->set_deadzone(0.15f);
}

+ 81
- 81
src/ecs/systems/control-system.hpp View File

@ -59,65 +59,65 @@ public:
void set_viewport(const float4& viewport);
void set_underworld_camera(scene::camera* camera);
control_set* get_control_set();
control* get_move_forward_control();
control* get_move_back_control();
control* get_move_left_control();
control* get_move_right_control();
control* get_rotate_ccw_control();
control* get_rotate_cw_control();
control* get_tilt_up_control();
control* get_tilt_down_control();
control* get_zoom_in_control();
control* get_zoom_out_control();
control* get_adjust_camera_control();
control* get_ascend_control();
control* get_descend_control();
control* get_toggle_view_control();
control* get_tool_menu_control();
control* get_equip_lens_control();
control* get_equip_brush_control();
control* get_equip_forceps_control();
control* get_equip_marker_control();
control* get_equip_container_control();
control* get_equip_twig_control();
control* get_next_marker_control();
control* get_previous_marker_control();
control* get_use_tool_control();
control* get_fast_forward_control();
control* get_rewind_control();
input::control_set* get_control_set();
input::control* get_move_forward_control();
input::control* get_move_back_control();
input::control* get_move_left_control();
input::control* get_move_right_control();
input::control* get_rotate_ccw_control();
input::control* get_rotate_cw_control();
input::control* get_tilt_up_control();
input::control* get_tilt_down_control();
input::control* get_zoom_in_control();
input::control* get_zoom_out_control();
input::control* get_adjust_camera_control();
input::control* get_ascend_control();
input::control* get_descend_control();
input::control* get_toggle_view_control();
input::control* get_tool_menu_control();
input::control* get_equip_lens_control();
input::control* get_equip_brush_control();
input::control* get_equip_forceps_control();
input::control* get_equip_marker_control();
input::control* get_equip_container_control();
input::control* get_equip_twig_control();
input::control* get_next_marker_control();
input::control* get_previous_marker_control();
input::control* get_use_tool_control();
input::control* get_fast_forward_control();
input::control* get_rewind_control();
private:
virtual void handle_event(const mouse_moved_event& event);
virtual void handle_event(const window_resized_event& event);
control_set control_set;
control move_forward_control;
control move_back_control;
control move_left_control;
control move_right_control;
control rotate_ccw_control;
control rotate_cw_control;
control tilt_up_control;
control tilt_down_control;
control zoom_in_control;
control zoom_out_control;
control adjust_camera_control;
control ascend_control;
control descend_control;
control toggle_view_control;
control tool_menu_control;
control equip_lens_control;
control equip_brush_control;
control equip_forceps_control;
control equip_marker_control;
control equip_container_control;
control equip_twig_control;
control next_marker_control;
control previous_marker_control;
control use_tool_control;
control fast_forward_control;
control rewind_control;
input::control_set control_set;
input::control move_forward_control;
input::control move_back_control;
input::control move_left_control;
input::control move_right_control;
input::control rotate_ccw_control;
input::control rotate_cw_control;
input::control tilt_up_control;
input::control tilt_down_control;
input::control zoom_in_control;
input::control zoom_out_control;
input::control adjust_camera_control;
input::control ascend_control;
input::control descend_control;
input::control toggle_view_control;
input::control tool_menu_control;
input::control equip_lens_control;
input::control equip_brush_control;
input::control equip_forceps_control;
input::control equip_marker_control;
input::control equip_container_control;
input::control equip_twig_control;
input::control next_marker_control;
input::control previous_marker_control;
input::control use_tool_control;
input::control fast_forward_control;
input::control rewind_control;
float zoom_speed;
float min_elevation;
@ -152,137 +152,137 @@ private:
float flashlight_turns_f;
};
inline control_set* control_system::get_control_set()
inline input::control_set* control_system::get_control_set()
{
return &control_set;
}
inline control* control_system::get_move_forward_control()
inline input::control* control_system::get_move_forward_control()
{
return &move_forward_control;
}
inline control* control_system::get_move_back_control()
inline input::control* control_system::get_move_back_control()
{
return &move_back_control;
}
inline control* control_system::get_move_left_control()
inline input::control* control_system::get_move_left_control()
{
return &move_left_control;
}
inline control* control_system::get_move_right_control()
inline input::control* control_system::get_move_right_control()
{
return &move_right_control;
}
inline control* control_system::get_rotate_ccw_control()
inline input::control* control_system::get_rotate_ccw_control()
{
return &rotate_ccw_control;
}
inline control* control_system::get_rotate_cw_control()
inline input::control* control_system::get_rotate_cw_control()
{
return &rotate_cw_control;
}
inline control* control_system::get_tilt_up_control()
inline input::control* control_system::get_tilt_up_control()
{
return &tilt_up_control;
}
inline control* control_system::get_tilt_down_control()
inline input::control* control_system::get_tilt_down_control()
{
return &tilt_down_control;
}
inline control* control_system::get_zoom_in_control()
inline input::control* control_system::get_zoom_in_control()
{
return &zoom_in_control;
}
inline control* control_system::get_zoom_out_control()
inline input::control* control_system::get_zoom_out_control()
{
return &zoom_out_control;
}
inline control* control_system::get_adjust_camera_control()
inline input::control* control_system::get_adjust_camera_control()
{
return &adjust_camera_control;
}
inline control* control_system::get_ascend_control()
inline input::control* control_system::get_ascend_control()
{
return &ascend_control;
}
inline control* control_system::get_descend_control()
inline input::control* control_system::get_descend_control()
{
return &descend_control;
}
inline control* control_system::get_toggle_view_control()
inline input::control* control_system::get_toggle_view_control()
{
return &toggle_view_control;
}
inline control* control_system::get_tool_menu_control()
inline input::control* control_system::get_tool_menu_control()
{
return &tool_menu_control;
}
inline control* control_system::get_equip_lens_control()
inline input::control* control_system::get_equip_lens_control()
{
return &equip_lens_control;
}
inline control* control_system::get_equip_brush_control()
inline input::control* control_system::get_equip_brush_control()
{
return &equip_brush_control;
}
inline control* control_system::get_equip_forceps_control()
inline input::control* control_system::get_equip_forceps_control()
{
return &equip_forceps_control;
}
inline control* control_system::get_equip_marker_control()
inline input::control* control_system::get_equip_marker_control()
{
return &equip_marker_control;
}
inline control* control_system::get_equip_container_control()
inline input::control* control_system::get_equip_container_control()
{
return &equip_container_control;
}
inline control* control_system::get_equip_twig_control()
inline input::control* control_system::get_equip_twig_control()
{
return &equip_twig_control;
}
inline control* control_system::get_next_marker_control()
inline input::control* control_system::get_next_marker_control()
{
return &next_marker_control;
}
inline control* control_system::get_previous_marker_control()
inline input::control* control_system::get_previous_marker_control()
{
return &previous_marker_control;
}
inline control* control_system::get_use_tool_control()
inline input::control* control_system::get_use_tool_control()
{
return &use_tool_control;
}
inline control* control_system::get_fast_forward_control()
inline input::control* control_system::get_fast_forward_control()
{
return &fast_forward_control;
}
inline control* control_system::get_rewind_control()
inline input::control* control_system::get_rewind_control()
{
return &rewind_control;
}

+ 1
- 2
src/ecs/systems/ui-system.cpp View File

@ -18,7 +18,6 @@
*/
#include "ui-system.hpp"
#include "input/control.hpp"
#include "resources/resource-manager.hpp"
namespace ecs {
@ -85,7 +84,7 @@ void ui_system::set_viewport(const float4& viewport)
update_projection();
}
void ui_system::set_tool_menu_control(control* control)
void ui_system::set_tool_menu_control(input::control* control)
{
tool_menu_control = control;
tool_menu_control->set_activated_callback(std::bind(&ui_system::open_tool_menu, this));

+ 3
- 3
src/ecs/systems/ui-system.hpp View File

@ -31,8 +31,8 @@
#include "scene/billboard.hpp"
#include "renderer/material.hpp"
#include "math/math.hpp"
#include "input/control.hpp"
class control;
class resource_manager;
namespace ecs {
@ -47,7 +47,7 @@ public:
void update(float dt);
void set_viewport(const float4& viewport);
void set_tool_menu_control(control* control);
void set_tool_menu_control(input::control* control);
void set_camera(scene::camera* camera);
void set_scene(scene::collection* collection);
@ -81,7 +81,7 @@ private:
float4 viewport;
float2 viewport_center;
float2 tool_selection_vector;
control* tool_menu_control;
input::control* tool_menu_control;
};
} // namespace ecs

+ 5
- 5
src/event/input-events.cpp View File

@ -78,7 +78,7 @@ event_base* mouse_wheel_scrolled_event::clone() const
event_base* game_controller_connected_event::clone() const
{
game_controller_connected_event* event = new game_controller_connected_event();
event->game_controller = game_controller;
event->controller = controller;
event->reconnected = reconnected;
return event;
}
@ -86,14 +86,14 @@ event_base* game_controller_connected_event::clone() const
event_base* game_controller_disconnected_event::clone() const
{
game_controller_disconnected_event* event = new game_controller_disconnected_event();
event->game_controller = game_controller;
event->controller = controller;
return event;
}
event_base* game_controller_button_pressed_event::clone() const
{
game_controller_button_pressed_event* event = new game_controller_button_pressed_event();
event->game_controller = game_controller;
event->controller = controller;
event->button = button;
return event;
}
@ -101,7 +101,7 @@ event_base* game_controller_button_pressed_event::clone() const
event_base* game_controller_button_released_event::clone() const
{
game_controller_button_released_event* event = new game_controller_button_released_event();
event->game_controller = game_controller;
event->controller = controller;
event->button = button;
return event;
}
@ -109,7 +109,7 @@ event_base* game_controller_button_released_event::clone() const
event_base* game_controller_axis_moved_event::clone() const
{
game_controller_axis_moved_event* event = new game_controller_axis_moved_event();
event->game_controller = game_controller;
event->controller = controller;
event->axis = axis;
event->value = value;
return event;

+ 20
- 23
src/event/input-events.hpp View File

@ -21,13 +21,10 @@
#define ANTKEEPER_INPUT_EVENTS_HPP
#include "event/event.hpp"
enum class scancode;
enum class game_controller_axis;
enum class game_controller_button;
class keyboard;
class mouse;
class game_controller;
#include "input/scancode.hpp"
#include "input/keyboard.hpp"
#include "input/mouse.hpp"
#include "input/game-controller.hpp"
/**
* Input event which indicates a keyboard key has been pressed.
@ -37,8 +34,8 @@ class key_pressed_event: public event
public:
virtual event_base* clone() const;
keyboard* keyboard;
scancode scancode;
input::keyboard* keyboard;
input::scancode scancode;
};
/**
@ -49,8 +46,8 @@ class key_released_event: public event
public:
virtual event_base* clone() const;
keyboard* keyboard;
scancode scancode;
input::keyboard* keyboard;
input::scancode scancode;
};
/**
@ -61,7 +58,7 @@ class mouse_moved_event: public event
public:
virtual event_base* clone() const;
mouse* mouse;
input::mouse* mouse;
int x;
int y;
int dx;
@ -76,7 +73,7 @@ class mouse_button_pressed_event: public event
public:
virtual event_base* clone() const;
mouse* mouse;
input::mouse* mouse;
int button;
int x;
int y;
@ -90,7 +87,7 @@ class mouse_button_released_event: public event
public:
virtual event_base* clone() const;
mouse* mouse;
input::mouse* mouse;
int button;
int x;
int y;
@ -104,7 +101,7 @@ class mouse_wheel_scrolled_event: public event
public:
virtual event_base* clone() const;
mouse* mouse;
input::mouse* mouse;
int x;
int y;
};
@ -117,7 +114,7 @@ class game_controller_connected_event: public event
public:
virtual event_base* clone() const;
game_controller* game_controller;
input::game_controller* controller;
bool reconnected;
};
@ -129,7 +126,7 @@ class game_controller_disconnected_event: public event
public:
virtual event_base* clone() const;
game_controller* game_controller;
input::game_controller* controller;
};
/**
@ -140,8 +137,8 @@ class game_controller_button_pressed_event: public event
public:
virtual event_base* clone() const;
game_controller* game_controller;
game_controller_button button;
input::game_controller* controller;
input::game_controller_button button;
};
/**
@ -152,8 +149,8 @@ class game_controller_button_released_event: public event
public:
virtual event_base* clone() const;
game_controller* game_controller;
game_controller_button button;
input::game_controller* controller;
input::game_controller_button button;
};
/**
@ -164,8 +161,8 @@ class game_controller_axis_moved_event: public event
public:
virtual event_base* clone() const;
game_controller* game_controller;
game_controller_axis axis;
input::game_controller* controller;
input::game_controller_axis axis;
float value;
};

+ 58
- 58
src/game/bootloader.cpp View File

@ -80,9 +80,9 @@
#include "ecs/commands.hpp"
#include "utility/paths.hpp"
#include "event/event-dispatcher.hpp"
#include "input/input-event-router.hpp"
#include "input/input-mapper.hpp"
#include "input/input-listener.hpp"
#include "input/event-router.hpp"
#include "input/mapper.hpp"
#include "input/listener.hpp"
#include "input/game-controller.hpp"
#include "input/mouse.hpp"
#include "input/keyboard.hpp"
@ -933,19 +933,19 @@ void setup_controls(game_context* ctx)
event_dispatcher* event_dispatcher = ctx->app->get_event_dispatcher();
// Setup input event routing
ctx->input_event_router = new input_event_router();
ctx->input_event_router = new input::event_router();
ctx->input_event_router->set_event_dispatcher(event_dispatcher);
// Setup input mapper
ctx->input_mapper = new input_mapper();
ctx->input_mapper = new input::mapper();
ctx->input_mapper->set_event_dispatcher(event_dispatcher);
// Setup input listener
ctx->input_listener = new input_listener();
ctx->input_listener = new input::listener();
ctx->input_listener->set_event_dispatcher(event_dispatcher);
// Create toggle fullscreen control
ctx->toggle_fullscreen_control = new control();
ctx->toggle_fullscreen_control = new input::control();
ctx->toggle_fullscreen_control->set_activated_callback
(
[ctx]()
@ -965,7 +965,7 @@ void setup_controls(game_context* ctx)
);
// Create screenshot control
ctx->screenshot_control = new control();
ctx->screenshot_control = new input::control();
ctx->screenshot_control->set_activated_callback
(
[ctx]()
@ -976,22 +976,22 @@ void setup_controls(game_context* ctx)
);
// Create menu back control
ctx->menu_back_control = new control();
ctx->menu_back_control = new input::control();
ctx->menu_back_control->set_activated_callback
(
std::bind(&application::close, ctx->app, 0)
);
// Create menu select control
ctx->menu_select_control = new control();
ctx->menu_select_control = new input::control();
// Create application control set
ctx->application_controls = new control_set();
ctx->application_controls = new input::control_set();
ctx->application_controls->add_control(ctx->toggle_fullscreen_control);
ctx->application_controls->add_control(ctx->screenshot_control);
// Create menu control set
ctx->menu_controls = new control_set();
ctx->menu_controls = new input::control_set();
ctx->menu_controls->add_control(ctx->menu_back_control);
ctx->menu_controls->add_control(ctx->menu_select_control);
@ -1001,21 +1001,21 @@ void setup_controls(game_context* ctx)
ctx->camera_controls = ctx->control_system->get_control_set();
// Application control mappings
ctx->input_event_router->add_mapping(key_mapping(ctx->toggle_fullscreen_control, nullptr, scancode::f11));
ctx->input_event_router->add_mapping(key_mapping(ctx->screenshot_control, nullptr, scancode::f12));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->toggle_fullscreen_control, nullptr, input::scancode::f11));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->screenshot_control, nullptr, input::scancode::f12));
// Add menu control mappings
ctx->input_event_router->add_mapping(key_mapping(ctx->menu_back_control, nullptr, scancode::escape));
ctx->input_event_router->add_mapping(key_mapping(ctx->menu_back_control, nullptr, scancode::backspace));
ctx->input_event_router->add_mapping(game_controller_button_mapping(ctx->menu_back_control, nullptr, game_controller_button::b));
ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_tool_menu_control(), nullptr, scancode::left_shift));
ctx->input_event_router->add_mapping(game_controller_button_mapping(ctx->control_system->get_tool_menu_control(), nullptr, game_controller_button::x));
ctx->input_event_router->add_mapping(key_mapping(ctx->menu_select_control, nullptr, scancode::enter));
ctx->input_event_router->add_mapping(key_mapping(ctx->menu_select_control, nullptr, scancode::space));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->menu_back_control, nullptr, input::scancode::escape));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->menu_back_control, nullptr, input::scancode::backspace));
ctx->input_event_router->add_mapping(input::game_controller_button_mapping(ctx->menu_back_control, nullptr, input::game_controller_button::b));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_tool_menu_control(), nullptr, input::scancode::left_shift));
ctx->input_event_router->add_mapping(input::game_controller_button_mapping(ctx->control_system->get_tool_menu_control(), nullptr, input::game_controller_button::x));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->menu_select_control, nullptr, input::scancode::enter));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->menu_select_control, nullptr, input::scancode::space));
ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_toggle_view_control(), nullptr, scancode::tab));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_toggle_view_control(), nullptr, input::scancode::tab));
ctx->control_system->get_toggle_view_control()->set_activated_callback(
[ctx]()
{
@ -1051,42 +1051,42 @@ void setup_controls(game_context* ctx)
}
});
ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_move_forward_control(), nullptr, scancode::w));
ctx->input_event_router->add_mapping(game_controller_axis_mapping(ctx->control_system->get_move_forward_control(), nullptr, game_controller_axis::left_y, true));
ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_move_back_control(), nullptr, scancode::s));
ctx->input_event_router->add_mapping(game_controller_axis_mapping(ctx->control_system->get_move_back_control(), nullptr, game_controller_axis::left_y, false));
ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_move_left_control(), nullptr, scancode::a));
ctx->input_event_router->add_mapping(game_controller_axis_mapping(ctx->control_system->get_move_left_control(), nullptr, game_controller_axis::left_x, true));
ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_move_right_control(), nullptr, scancode::d));
ctx->input_event_router->add_mapping(game_controller_axis_mapping(ctx->control_system->get_move_right_control(), nullptr, game_controller_axis::left_x, false));
ctx->input_event_router->add_mapping(game_controller_axis_mapping(ctx->control_system->get_rotate_ccw_control(), nullptr, game_controller_axis::right_x, false));
ctx->input_event_router->add_mapping(game_controller_axis_mapping(ctx->control_system->get_rotate_cw_control(), nullptr, game_controller_axis::right_x, true));
ctx->input_event_router->add_mapping(game_controller_axis_mapping(ctx->control_system->get_tilt_up_control(), nullptr, game_controller_axis::right_y, false));
ctx->input_event_router->add_mapping(game_controller_axis_mapping(ctx->control_system->get_tilt_down_control(), nullptr, game_controller_axis::right_y, true));
ctx->input_event_router->add_mapping(mouse_wheel_mapping(ctx->control_system->get_zoom_in_control(), nullptr, mouse_wheel_axis::positive_y));
ctx->input_event_router->add_mapping(mouse_wheel_mapping(ctx->control_system->get_zoom_out_control(), nullptr, mouse_wheel_axis::negative_y));
ctx->input_event_router->add_mapping(mouse_button_mapping(ctx->control_system->get_adjust_camera_control(), nullptr, 3));
ctx->input_event_router->add_mapping(game_controller_button_mapping(ctx->control_system->get_ascend_control(), nullptr, game_controller_button::y));
ctx->input_event_router->add_mapping(game_controller_button_mapping(ctx->control_system->get_descend_control(), nullptr, game_controller_button::a));
ctx->input_event_router->add_mapping(game_controller_axis_mapping(ctx->control_system->get_zoom_out_control(), nullptr, game_controller_axis::trigger_left, false));
ctx->input_event_router->add_mapping(game_controller_axis_mapping(ctx->control_system->get_zoom_in_control(), nullptr, game_controller_axis::trigger_right, false));
ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_rotate_ccw_control(), nullptr, scancode::q));
ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_rotate_cw_control(), nullptr, scancode::e));
ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_fast_forward_control(), nullptr, scancode::dot));
ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_rewind_control(), nullptr, scancode::comma));
ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_equip_brush_control(), nullptr, scancode::one));
ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_equip_twig_control(), nullptr, scancode::two));
ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_equip_forceps_control(), nullptr, scancode::three));
ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_equip_container_control(), nullptr, scancode::four));
ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_equip_lens_control(), nullptr, scancode::five));
ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_equip_marker_control(), nullptr, scancode::six));
ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_next_marker_control(), nullptr, scancode::right_brace));
ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_previous_marker_control(), nullptr, scancode::left_brace));
ctx->input_event_router->add_mapping(mouse_button_mapping(ctx->control_system->get_use_tool_control(), nullptr, 1));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_move_forward_control(), nullptr, input::scancode::w));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->control_system->get_move_forward_control(), nullptr, input::game_controller_axis::left_y, true));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_move_back_control(), nullptr, input::scancode::s));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->control_system->get_move_back_control(), nullptr, input::game_controller_axis::left_y, false));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_move_left_control(), nullptr, input::scancode::a));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->control_system->get_move_left_control(), nullptr, input::game_controller_axis::left_x, true));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_move_right_control(), nullptr, input::scancode::d));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->control_system->get_move_right_control(), nullptr, input::game_controller_axis::left_x, false));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->control_system->get_rotate_ccw_control(), nullptr, input::game_controller_axis::right_x, false));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->control_system->get_rotate_cw_control(), nullptr, input::game_controller_axis::right_x, true));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->control_system->get_tilt_up_control(), nullptr, input::game_controller_axis::right_y, false));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->control_system->get_tilt_down_control(), nullptr, input::game_controller_axis::right_y, true));
ctx->input_event_router->add_mapping(input::mouse_wheel_mapping(ctx->control_system->get_zoom_in_control(), nullptr, input::mouse_wheel_axis::positive_y));
ctx->input_event_router->add_mapping(input::mouse_wheel_mapping(ctx->control_system->get_zoom_out_control(), nullptr, input::mouse_wheel_axis::negative_y));
ctx->input_event_router->add_mapping(input::mouse_button_mapping(ctx->control_system->get_adjust_camera_control(), nullptr, 3));
ctx->input_event_router->add_mapping(input::game_controller_button_mapping(ctx->control_system->get_ascend_control(), nullptr, input::game_controller_button::y));
ctx->input_event_router->add_mapping(input::game_controller_button_mapping(ctx->control_system->get_descend_control(), nullptr, input::game_controller_button::a));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->control_system->get_zoom_out_control(), nullptr, input::game_controller_axis::trigger_left, false));
ctx->input_event_router->add_mapping(input::game_controller_axis_mapping(ctx->control_system->get_zoom_in_control(), nullptr, input::game_controller_axis::trigger_right, false));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_rotate_ccw_control(), nullptr, input::scancode::q));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_rotate_cw_control(), nullptr, input::scancode::e));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_fast_forward_control(), nullptr, input::scancode::dot));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_rewind_control(), nullptr, input::scancode::comma));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_equip_brush_control(), nullptr, input::scancode::one));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_equip_twig_control(), nullptr, input::scancode::two));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_equip_forceps_control(), nullptr, input::scancode::three));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_equip_container_control(), nullptr, input::scancode::four));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_equip_lens_control(), nullptr, input::scancode::five));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_equip_marker_control(), nullptr, input::scancode::six));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_next_marker_control(), nullptr, input::scancode::right_brace));
ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_previous_marker_control(), nullptr, input::scancode::left_brace));
ctx->input_event_router->add_mapping(input::mouse_button_mapping(ctx->control_system->get_use_tool_control(), nullptr, 1));
ctx->control_system->get_use_tool_control()->set_activated_callback
(
[ctx]()

+ 15
- 15
src/game/game-context.hpp View File

@ -30,6 +30,11 @@
#include "gl/texture-2d.hpp"
#include "gl/rasterizer.hpp"
#include "gl/framebuffer.hpp"
#include "input/control.hpp"
#include "input/control-set.hpp"
#include "input/listener.hpp"
#include "input/mapper.hpp"
#include "input/event-router.hpp"
#include <optional>
#include <entt/entt.hpp>
#include <fstream>
@ -42,11 +47,8 @@ class bloom_pass;
class clear_pass;
class compositor;
class config_file;
class control;
class control_set;
class final_pass;
class material;
class input_listener;
class material_pass;
class orbit_cam;
class pheromone_matrix;
@ -57,8 +59,6 @@ class simple_render_pass;
class sky_pass;
class timeline;
class renderer;
class input_event_router;
class input_mapper;
class outline_pass;
struct biome;
@ -209,16 +209,16 @@ struct game_context
animation<float>* unequip_tool_animation;
// Controls
input_event_router* input_event_router;
input_mapper* input_mapper;
input_listener* input_listener;
control_set* application_controls;
control_set* camera_controls;
control_set* menu_controls;
control* menu_back_control;
control* menu_select_control;
control* screenshot_control;
control* toggle_fullscreen_control;
input::event_router* input_event_router;
input::mapper* input_mapper;
input::listener* input_listener;
input::control_set* application_controls;
input::control_set* camera_controls;
input::control_set* menu_controls;
input::control* menu_back_control;
input::control* menu_select_control;
input::control* screenshot_control;
input::control* toggle_fullscreen_control;
// Entities
ecs::registry* ecs_registry;

+ 1
- 1
src/game/states/map-state.cpp View File

@ -23,7 +23,7 @@
#include "application.hpp"
#include "debug/logger.hpp"
#include "game/game-context.hpp"
#include "input/input-listener.hpp"
#include "input/listener.hpp"
#include "event/input-events.hpp"
#include "gl/rasterizer.hpp"
#include "game/states/game-states.hpp"

+ 1
- 1
src/game/states/splash-state.cpp View File

@ -23,7 +23,7 @@
#include "application.hpp"
#include "debug/logger.hpp"
#include "game/game-context.hpp"
#include "input/input-listener.hpp"
#include "input/listener.hpp"
#include "event/input-events.hpp"
#include "gl/rasterizer.hpp"
#include "game/states/game-states.hpp"

+ 3
- 0
src/input/control-set.cpp View File

@ -20,6 +20,8 @@
#include "control-set.hpp"
#include "control.hpp"
namespace input {
void control_set::add_control(control* control)
{
controls.push_back(control);
@ -51,3 +53,4 @@ void control_set::set_callbacks_enabled(bool enabled)
}
}
} // namespace input

+ 7
- 3
src/input/control-set.hpp View File

@ -17,11 +17,13 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_CONTROL_SET_HPP
#define ANTKEEPER_CONTROL_SET_HPP
#ifndef ANTKEEPER_INPUT_CONTROL_SET_HPP
#define ANTKEEPER_INPUT_CONTROL_SET_HPP
#include <list>
namespace input {
class control;
/**
@ -77,5 +79,7 @@ inline const std::list* control_set::get_controls() const
return &controls;
}
#endif // ANTKEEPER_CONTROL_SET_HPP
} // namespace input
#endif // ANTKEEPER_INPUT_CONTROL_SET_HPP

+ 3
- 0
src/input/control.cpp View File

@ -19,6 +19,8 @@
#include "control.hpp"
namespace input {
control::control():
deadzone(0.0f),
current_value(0.0f),
@ -109,3 +111,4 @@ void control::set_value_changed_callback(std::function callback)
this->value_changed_callback = callback;
}
} // namespace input

+ 7
- 5
src/input/control.hpp View File

@ -17,15 +17,15 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_CONTROL_HPP
#define ANTKEEPER_CONTROL_HPP
#ifndef ANTKEEPER_INPUT_CONTROL_HPP
#define ANTKEEPER_INPUT_CONTROL_HPP
#include <functional>
namespace input {
/**
* A control can be bound to multiple types of input events.
*
* @ingroup input
*/
class control
{
@ -132,5 +132,7 @@ inline bool control::was_active() const
return previous_value > deadzone;
}
#endif // ANTKEEPER_CONTROL_HPP
} // namespace input
#endif // ANTKEEPER_INPUT_CONTROL_HPP

src/input/input-device.cpp → src/input/device.cpp View File

@ -17,14 +17,17 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "input-device.hpp"
#include "event/event-dispatcher.hpp"
#include "device.hpp"
input_device::input_device():
namespace input {
device::device():
event_dispatcher(nullptr)
{}
void input_device::set_event_dispatcher(::event_dispatcher* event_dispatcher)
void device::set_event_dispatcher(::event_dispatcher* event_dispatcher)
{
this->event_dispatcher = event_dispatcher;
}
} // namespace input

src/input/input-device.hpp → src/input/device.hpp View File

@ -20,18 +20,18 @@
#ifndef ANTKEEPER_INPUT_DEVICE_HPP
#define ANTKEEPER_INPUT_DEVICE_HPP
#include "input-device.hpp"
#include "event/event-dispatcher.hpp"
class event_dispatcher;
namespace input {
/**
* Base class for virtual devices which generate input events.
*/
class input_device
class device
{
public:
input_device();
virtual ~input_device() = default;
device();
virtual ~device() = default;
void set_event_dispatcher(event_dispatcher* event_dispatcher);
const event_dispatcher* get_event_dispatcher() const;
@ -41,15 +41,17 @@ protected:
event_dispatcher* event_dispatcher;
};
inline const event_dispatcher* input_device::get_event_dispatcher() const
inline const event_dispatcher* device::get_event_dispatcher() const
{
return event_dispatcher;
}
inline event_dispatcher* input_device::get_event_dispatcher()
inline event_dispatcher* device::get_event_dispatcher()
{
return event_dispatcher;
}
} // namespace input
#endif // ANTKEEPER_INPUT_DEVICE_HPP

src/input/input-event-router.cpp → src/input/event-router.cpp View File

@ -17,76 +17,78 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "input-event-router.hpp"
#include "event-router.hpp"
#include "control.hpp"
#include "input-mapping.hpp"
#include "mapping.hpp"
#include "mouse.hpp"
#include "event/event-dispatcher.hpp"
input_event_router::input_event_router():
namespace input {
event_router::event_router():
event_dispatcher(nullptr)
{}
input_event_router::~input_event_router()
event_router::~event_router()
{
remove_mappings();
set_event_dispatcher(nullptr);
}
void input_event_router::add_mapping(const input_mapping& mapping)
void event_router::add_mapping(const mapping& mapping)
{
control* control = mapping.control;
switch (mapping.get_type())
{
case input_mapping_type::key:
case mapping_type::key:
{
::key_mapping* key_mapping = new ::key_mapping(static_cast<const ::key_mapping&>(mapping));
input::key_mapping* key_mapping = new input::key_mapping(static_cast<const input::key_mapping&>(mapping));
key_mappings.push_back(key_mapping);
controls[control].push_back(key_mapping);
break;
}
case input_mapping_type::mouse_motion:
case mapping_type::mouse_motion:
{
::mouse_motion_mapping* mouse_motion_mapping = new ::mouse_motion_mapping(static_cast<const ::mouse_motion_mapping&>(mapping));
input::mouse_motion_mapping* mouse_motion_mapping = new input::mouse_motion_mapping(static_cast<const input::mouse_motion_mapping&>(mapping));
mouse_motion_mappings.push_back(mouse_motion_mapping);
controls[control].push_back(mouse_motion_mapping);
break;
}
case input_mapping_type::mouse_wheel:
case mapping_type::mouse_wheel:
{
::mouse_wheel_mapping* mouse_wheel_mapping = new ::mouse_wheel_mapping(static_cast<const ::mouse_wheel_mapping&>(mapping));
input::mouse_wheel_mapping* mouse_wheel_mapping = new input::mouse_wheel_mapping(static_cast<const input::mouse_wheel_mapping&>(mapping));
mouse_wheel_mappings.push_back(mouse_wheel_mapping);
controls[control].push_back(mouse_wheel_mapping);
break;
}
case input_mapping_type::mouse_button:
case mapping_type::mouse_button:
{
::mouse_button_mapping* mouse_button_mapping = new ::mouse_button_mapping(static_cast<const ::mouse_button_mapping&>(mapping));
input::mouse_button_mapping* mouse_button_mapping = new input::mouse_button_mapping(static_cast<const input::mouse_button_mapping&>(mapping));
mouse_button_mappings.push_back(mouse_button_mapping);
controls[control].push_back(mouse_button_mapping);
break;
}
case input_mapping_type::game_controller_axis:
case mapping_type::game_controller_axis:
{
::game_controller_axis_mapping* game_controller_axis_mapping = new ::game_controller_axis_mapping(static_cast<const ::game_controller_axis_mapping&>(mapping));
input::game_controller_axis_mapping* game_controller_axis_mapping = new input::game_controller_axis_mapping(static_cast<const input::game_controller_axis_mapping&>(mapping));
game_controller_axis_mappings.push_back(game_controller_axis_mapping);
controls[control].push_back(game_controller_axis_mapping);
break;
}
case input_mapping_type::game_controller_button:
case mapping_type::game_controller_button:
{
::game_controller_button_mapping* game_controller_button_mapping = new ::game_controller_button_mapping(static_cast<const ::game_controller_button_mapping&>(mapping));
input::game_controller_button_mapping* game_controller_button_mapping = new input::game_controller_button_mapping(static_cast<const input::game_controller_button_mapping&>(mapping));
game_controller_button_mappings.push_back(game_controller_button_mapping);
controls[control].push_back(game_controller_button_mapping);
@ -98,36 +100,36 @@ void input_event_router::add_mapping(const input_mapping& mapping)
}
}
void input_event_router::remove_mappings(control* control)
void event_router::remove_mappings(control* control)
{
auto it = controls.find(control);
if (it != controls.end())
{
for (input_mapping* mapping: it->second)
for (mapping* mapping: it->second)
{
switch (mapping->get_type())
{
case input_mapping_type::key:
case mapping_type::key:
key_mappings.remove(static_cast<key_mapping*>(mapping));
break;
case input_mapping_type::mouse_motion:
case mapping_type::mouse_motion:
mouse_motion_mappings.remove(static_cast<mouse_motion_mapping*>(mapping));
break;
case input_mapping_type::mouse_wheel:
case mapping_type::mouse_wheel:
mouse_wheel_mappings.remove(static_cast<mouse_wheel_mapping*>(mapping));
break;
case input_mapping_type::mouse_button:
case mapping_type::mouse_button:
mouse_button_mappings.remove(static_cast<mouse_button_mapping*>(mapping));
break;
case input_mapping_type::game_controller_axis:
case mapping_type::game_controller_axis:
game_controller_axis_mappings.remove(static_cast<game_controller_axis_mapping*>(mapping));
break;
case input_mapping_type::game_controller_button:
case mapping_type::game_controller_button:
game_controller_button_mappings.remove(static_cast<game_controller_button_mapping*>(mapping));
break;
@ -142,7 +144,7 @@ void input_event_router::remove_mappings(control* control)
}
}
void input_event_router::set_event_dispatcher(::event_dispatcher* event_dispatcher)
void event_router::set_event_dispatcher(::event_dispatcher* event_dispatcher)
{
if (this->event_dispatcher)
{
@ -173,11 +175,11 @@ void input_event_router::set_event_dispatcher(::event_dispatcher* event_dispatch
}
}
void input_event_router::remove_mappings()
void event_router::remove_mappings()
{
for (auto it = controls.begin(); it != controls.end(); ++it)
{
for (input_mapping* mapping: it->second)
for (mapping* mapping: it->second)
{
delete mapping;
}
@ -192,7 +194,7 @@ void input_event_router::remove_mappings()
game_controller_button_mappings.clear();
}
const std::list<input_mapping*>* input_event_router::get_mappings(control* control) const
const std::list<mapping*>* event_router::get_mappings(control* control) const
{
auto it = controls.find(control);
if (it == controls.end())
@ -203,7 +205,7 @@ const std::list* input_event_router::get_mappings(control* contr
return &it->second;
}
void input_event_router::handle_event(const key_pressed_event& event)
void event_router::handle_event(const key_pressed_event& event)
{
for (const key_mapping* mapping: key_mappings)
{
@ -214,7 +216,7 @@ void input_event_router::handle_event(const key_pressed_event& event)
}
}
void input_event_router::handle_event(const key_released_event& event)
void event_router::handle_event(const key_released_event& event)
{
for (const key_mapping* mapping: key_mappings)
{
@ -225,7 +227,7 @@ void input_event_router::handle_event(const key_released_event& event)
}
}
void input_event_router::handle_event(const mouse_moved_event& event)
void event_router::handle_event(const mouse_moved_event& event)
{
for (const mouse_motion_mapping* mapping: mouse_motion_mappings)
{
@ -251,7 +253,7 @@ void input_event_router::handle_event(const mouse_moved_event& event)
}
}
void input_event_router::handle_event(const mouse_wheel_scrolled_event& event)
void event_router::handle_event(const mouse_wheel_scrolled_event& event)
{
for (const mouse_wheel_mapping* mapping: mouse_wheel_mappings)
{
@ -277,7 +279,7 @@ void input_event_router::handle_event(const mouse_wheel_scrolled_event& event)
}
}
void input_event_router::handle_event(const mouse_button_pressed_event& event)
void event_router::handle_event(const mouse_button_pressed_event& event)
{
for (const mouse_button_mapping* mapping: mouse_button_mappings)
{
@ -288,7 +290,7 @@ void input_event_router::handle_event(const mouse_button_pressed_event& event)
}
}
void input_event_router::handle_event(const mouse_button_released_event& event)
void event_router::handle_event(const mouse_button_released_event& event)
{
for (const mouse_button_mapping* mapping: mouse_button_mappings)
{
@ -299,11 +301,11 @@ void input_event_router::handle_event(const mouse_button_released_event& event)
}
}
void input_event_router::handle_event(const game_controller_axis_moved_event& event)
void event_router::handle_event(const game_controller_axis_moved_event& event)
{
for (const game_controller_axis_mapping* mapping: game_controller_axis_mappings)
{
if ((!mapping->game_controller || mapping->game_controller == event.game_controller) && mapping->axis == event.axis)
if ((!mapping->controller || mapping->controller == event.controller) && mapping->axis == event.axis)
{
if (mapping->negative && event.value >= 0.0f || !mapping->negative && event.value <= 0.0f)
{
@ -317,25 +319,26 @@ void input_event_router::handle_event(const game_controller_axis_moved_event& ev
}
}
void input_event_router::handle_event(const game_controller_button_pressed_event& event)
void event_router::handle_event(const game_controller_button_pressed_event& event)
{
for (const game_controller_button_mapping* mapping: game_controller_button_mappings)
{
if ((!mapping->game_controller || mapping->game_controller == event.game_controller) && mapping->button == event.button)
if ((!mapping->controller || mapping->controller == event.controller) && mapping->button == event.button)
{
mapping->control->set_current_value(1.0f);
}
}
}
void input_event_router::handle_event(const game_controller_button_released_event& event)
void event_router::handle_event(const game_controller_button_released_event& event)
{
for (const game_controller_button_mapping* mapping: game_controller_button_mappings)
{
if ((!mapping->game_controller || mapping->game_controller == event.game_controller) && mapping->button == event.button)
if ((!mapping->controller || mapping->controller == event.controller) && mapping->button == event.button)
{
mapping->control->set_current_value(0.0f);
}
}
}
} // namespace input

src/input/input-event-router.hpp → src/input/event-router.hpp View File

@ -22,12 +22,14 @@
#include "event/input-events.hpp"
#include "event/event-handler.hpp"
#include "event/event-dispatcher.hpp"
#include <list>
#include <map>
namespace input {
class control;
class event_dispatcher;
class input_mapping;
class mapping;
class key_mapping;
class mouse_motion_mapping;
class mouse_wheel_mapping;
@ -40,7 +42,7 @@ enum class mouse_wheel_axis;
/**
* Uses input mappings to route input events to controls.
*/
class input_event_router:
class event_router:
public event_handler<key_pressed_event>,
public event_handler<key_released_event>,
public event_handler<mouse_moved_event>,
@ -55,19 +57,19 @@ public:
/**
* Creates an input router and subscribes it to the input events of the specified event dispatcher.
*/
input_event_router();
event_router();
/**
* Destroys an input router and unsubscribes it from input events.
*/
~input_event_router();
~event_router();
/**
* Adds an input mapping to the router.
*
* @param mapping Input mapping to add.
*/
void add_mapping(const input_mapping& mapping);
void add_mapping(const mapping& mapping);
/**
@ -88,7 +90,7 @@ public:
void remove_mappings();
/// Returns a list of mappings for the specified control, or nullptr if the control is unmapped.
const std::list<input_mapping*>* get_mappings(control* control) const;
const std::list<mapping*>* get_mappings(control* control) const;
private:
virtual void handle_event(const key_pressed_event& event);
@ -102,7 +104,7 @@ private:
virtual void handle_event(const game_controller_button_released_event& event);
event_dispatcher* event_dispatcher;
std::map<control*, std::list<input_mapping*>> controls;
std::map<control*, std::list<mapping*>> controls;
std::list<key_mapping*> key_mappings;
std::list<mouse_motion_mapping*> mouse_motion_mappings;
std::list<mouse_wheel_mapping*> mouse_wheel_mappings;
@ -111,5 +113,7 @@ private:
std::list<game_controller_button_mapping*> game_controller_button_mappings;
};
} // namespace input
#endif // ANTKEEER_INPUT_EVENT_ROUTER_HPP

+ 17
- 13
src/input/game-controller.cpp View File

@ -22,51 +22,53 @@
#include "event/event-dispatcher.hpp"
#include <cmath>
namespace input {
game_controller::game_controller():
connected(true)
{}
void game_controller::press(game_controller_button button)
{
if (!input_device::event_dispatcher)
if (!device::event_dispatcher)
{
return;
}
game_controller_button_pressed_event event;
event.game_controller = this;
event.controller = this;
event.button = button;
input_device::event_dispatcher->queue(event);
device::event_dispatcher->queue(event);
}
void game_controller::release(game_controller_button button)
{
if (!input_device::event_dispatcher)
if (!device::event_dispatcher)
{
return;
}
game_controller_button_released_event event;
event.game_controller = this;
event.controller = this;
event.button = button;
input_device::event_dispatcher->queue(event);
device::event_dispatcher->queue(event);
}
void game_controller::move(game_controller_axis axis, float value)
{
if (!input_device::event_dispatcher)
if (!device::event_dispatcher)
{
return;
}
game_controller_axis_moved_event event;
event.game_controller = this;
event.controller = this;
event.axis = axis;
event.value = value;
input_device::event_dispatcher->queue(event);
device::event_dispatcher->queue(event);
}
void game_controller::connect(bool reconnected)
@ -74,10 +76,10 @@ void game_controller::connect(bool reconnected)
connected = true;
game_controller_connected_event event;
event.game_controller = this;
event.controller = this;
event.reconnected = reconnected;
input_device::event_dispatcher->queue(event);
device::event_dispatcher->queue(event);
}
void game_controller::disconnect()
@ -85,7 +87,9 @@ void game_controller::disconnect()
connected = false;
game_controller_disconnected_event event;
event.game_controller = this;
event.controller = this;
input_device::event_dispatcher->queue(event);
device::event_dispatcher->queue(event);
}
} // namespace input

+ 9
- 5
src/input/game-controller.hpp View File

@ -17,10 +17,12 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_GAME_CONTROLLER_HPP
#define ANTKEEPER_GAME_CONTROLLER_HPP
#ifndef ANTKEEPER_INPUT_GAME_CONTROLLER_HPP
#define ANTKEEPER_INPUT_GAME_CONTROLLER_HPP
#include "input-device.hpp"
#include "device.hpp"
namespace input {
enum class game_controller_button
{
@ -56,7 +58,7 @@ enum class game_controller_axis
*
* @ingroup input
*/
class game_controller: public input_device
class game_controller: public device
{
public:
/**
@ -112,5 +114,7 @@ inline bool game_controller::is_connected() const
return connected;
}
#endif // ANTKEEPER_GAME_CONTROLLER_HPP
} // namespace input
#endif // ANTKEEPER_INPUT_GAME_CONTROLLER_HPP

+ 12
- 0
src/input/input.hpp View File

@ -23,4 +23,16 @@
/// Input devices and events.
namespace input {}
#include "control.hpp"
#include "control-set.hpp"
#include "device.hpp"
#include "event-router.hpp"
#include "game-controller.hpp"
#include "keyboard.hpp"
#include "listener.hpp"
#include "mapper.hpp"
#include "mapping.hpp"
#include "mouse.hpp"
#include "scancode.hpp"
#endif // ANTKEEPER_INPUT_HPP

+ 7
- 4
src/input/keyboard.cpp View File

@ -22,6 +22,8 @@
#include "event/event-dispatcher.hpp"
#include "event/input-events.hpp"
namespace input {
const char* keyboard::get_scancode_name(scancode scancode)
{
return scancode_names[static_cast<std::size_t>(scancode)];
@ -46,7 +48,7 @@ keyboard::~keyboard()
void keyboard::press(scancode scancode)
{
if (!input_device::event_dispatcher)
if (!device::event_dispatcher)
{
return;
}
@ -55,12 +57,12 @@ void keyboard::press(scancode scancode)
event.keyboard = this;
event.scancode = scancode;
input_device::event_dispatcher->queue(event);
device::event_dispatcher->queue(event);
}
void keyboard::release(scancode scancode)
{
if (!input_device::event_dispatcher)
if (!device::event_dispatcher)
{
return;
}
@ -69,7 +71,7 @@ void keyboard::release(scancode scancode)
event.keyboard = this;
event.scancode = scancode;
input_device::event_dispatcher->queue(event);
device::event_dispatcher->queue(event);
}
std::map<std::string, scancode> keyboard::build_scancode_map()
@ -339,3 +341,4 @@ const char* keyboard::scancode_names[] =
std::map<std::string, scancode> keyboard::scancode_map = keyboard::build_scancode_map();
} // namespace input

+ 9
- 5
src/input/keyboard.hpp View File

@ -17,19 +17,21 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_KEYBOARD_HPP
#define ANTKEEPER_KEYBOARD_HPP
#ifndef ANTKEEPER_INPUT_KEYBOARD_HPP
#define ANTKEEPER_INPUT_KEYBOARD_HPP
#include "input-device.hpp"
#include "device.hpp"
#include <map>
#include <string>
namespace input {
enum class scancode;
/**
* A virtual keyboard which can generate keyboard-related input events and pass them to an event dispatcher.
*/
class keyboard: public input_device
class keyboard: public device
{
public:
/**
@ -73,5 +75,7 @@ private:
static std::map<std::string, scancode> scancode_map;
};
#endif // ANTKEEPER_KEYBOARD_HPP
} // namespace input
#endif // ANTKEEPER_INPUT_KEYBOARD_HPP

src/input/input-listener.cpp → src/input/listener.cpp View File

@ -17,21 +17,23 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "input-listener.hpp"
#include "listener.hpp"
#include "event/event-dispatcher.hpp"
input_listener::input_listener():
namespace input {
listener::listener():
event_dispatcher(nullptr),
callback(nullptr),
enabled(false)
{}
input_listener::~input_listener()
listener::~listener()
{
set_event_dispatcher(nullptr);
}
void input_listener::set_event_dispatcher(::event_dispatcher* event_dispatcher)
void listener::set_event_dispatcher(::event_dispatcher* event_dispatcher)
{
if (this->event_dispatcher)
{
@ -56,17 +58,17 @@ void input_listener::set_event_dispatcher(::event_dispatcher* event_dispatcher)
}
}
void input_listener::set_callback(std::function<void(const event_base&)> callback)
void listener::set_callback(std::function<void(const event_base&)> callback)
{
this->callback = callback;
}
void input_listener::set_enabled(bool enabled)
void listener::set_enabled(bool enabled)
{
this->enabled = enabled;
}
void input_listener::handle_event(const key_pressed_event& event)
void listener::handle_event(const key_pressed_event& event)
{
if (!is_enabled() || !callback)
{
@ -76,7 +78,7 @@ void input_listener::handle_event(const key_pressed_event& event)
callback(event);
}
void input_listener::handle_event(const mouse_moved_event& event)
void listener::handle_event(const mouse_moved_event& event)
{
if (!is_enabled() || !callback)
{
@ -86,7 +88,7 @@ void input_listener::handle_event(const mouse_moved_event& event)
callback(event);
}
void input_listener::handle_event(const mouse_button_pressed_event& event)
void listener::handle_event(const mouse_button_pressed_event& event)
{
if (!is_enabled() || !callback)
{
@ -96,7 +98,7 @@ void input_listener::handle_event(const mouse_button_pressed_event& event)
callback(event);
}
void input_listener::handle_event(const mouse_wheel_scrolled_event& event)
void listener::handle_event(const mouse_wheel_scrolled_event& event)
{
if (!is_enabled() || !callback)
{
@ -106,7 +108,7 @@ void input_listener::handle_event(const mouse_wheel_scrolled_event& event)
callback(event);
}
void input_listener::handle_event(const game_controller_button_pressed_event& event)
void listener::handle_event(const game_controller_button_pressed_event& event)
{
if (!is_enabled() || !callback)
{
@ -116,7 +118,7 @@ void input_listener::handle_event(const game_controller_button_pressed_event& ev
callback(event);
}
void input_listener::handle_event(const game_controller_axis_moved_event& event)
void listener::handle_event(const game_controller_axis_moved_event& event)
{
if (!is_enabled() || !callback)
{
@ -125,3 +127,5 @@ void input_listener::handle_event(const game_controller_axis_moved_event& event)
callback(event);
}
} // namespace input

src/input/input-listener.hpp → src/input/listener.hpp View File

@ -22,11 +22,12 @@
#include "event/input-events.hpp"
#include "event/event-handler.hpp"
#include "event/event-dispatcher.hpp"
#include <functional>
class event_dispatcher;
namespace input {
class input_listener:
class listener:
public event_handler<key_pressed_event>,
public event_handler<mouse_moved_event>,
public event_handler<mouse_wheel_scrolled_event>,
@ -38,12 +39,12 @@ public:
/**
* Creates an input listener.
*/
input_listener();
listener();
/**
* Destroys an input listener.
*/
virtual ~input_listener();
virtual ~listener();
/**
* Sets the event dispatcher to which this input event router will subscribe itself.
@ -82,10 +83,12 @@ private:
bool enabled;
};
inline bool input_listener::is_enabled() const
inline bool listener::is_enabled() const
{
return enabled;
}
} // namespace input
#endif // ANTKEEPER_INPUT_LISTENER_HPP

src/input/input-mapper.cpp → src/input/mapper.cpp View File

@ -17,23 +17,25 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "input-mapper.hpp"
#include "mapper.hpp"
#include "mouse.hpp"
#include "event/event-dispatcher.hpp"
input_mapper::input_mapper():
namespace input {
mapper::mapper():
event_dispatcher(nullptr),
control(nullptr),
callback(nullptr),
enabled(false)
{}
input_mapper::~input_mapper()
mapper::~mapper()
{
set_event_dispatcher(nullptr);
}
void input_mapper::set_event_dispatcher(::event_dispatcher* event_dispatcher)
void mapper::set_event_dispatcher(::event_dispatcher* event_dispatcher)
{
if (this->event_dispatcher)
{
@ -58,22 +60,22 @@ void input_mapper::set_event_dispatcher(::event_dispatcher* event_dispatcher)
}
}
void input_mapper::set_control(::control* control)
void mapper::set_control(input::control* control)
{
this->control = control;
}
void input_mapper::set_callback(std::function<void(const input_mapping&)> callback)
void mapper::set_callback(std::function<void(const mapping&)> callback)
{
this->callback = callback;
}
void input_mapper::set_enabled(bool enabled)
void mapper::set_enabled(bool enabled)
{
this->enabled = enabled;
}
void input_mapper::handle_event(const key_pressed_event& event)
void mapper::handle_event(const key_pressed_event& event)
{
if (!is_enabled() || !callback)
{
@ -83,7 +85,7 @@ void input_mapper::handle_event(const key_pressed_event& event)
callback(key_mapping(control, event.keyboard, event.scancode));
}
void input_mapper::handle_event(const mouse_moved_event& event)
void mapper::handle_event(const mouse_moved_event& event)
{
if (!is_enabled() || !callback)
{
@ -103,7 +105,7 @@ void input_mapper::handle_event(const mouse_moved_event& event)
}
}
void input_mapper::handle_event(const mouse_button_pressed_event& event)
void mapper::handle_event(const mouse_button_pressed_event& event)
{
if (!is_enabled() || !callback)
{
@ -113,7 +115,7 @@ void input_mapper::handle_event(const mouse_button_pressed_event& event)
callback(mouse_button_mapping(control, event.mouse, event.button));
}
void input_mapper::handle_event(const mouse_wheel_scrolled_event& event)
void mapper::handle_event(const mouse_wheel_scrolled_event& event)
{
if (!is_enabled() || !callback)
{
@ -133,23 +135,24 @@ void input_mapper::handle_event(const mouse_wheel_scrolled_event& event)
}
}
void input_mapper::handle_event(const game_controller_button_pressed_event& event)
void mapper::handle_event(const game_controller_button_pressed_event& event)
{
if (!is_enabled() || !callback)
{
return;
}
callback(game_controller_button_mapping(control, event.game_controller, event.button));
callback(game_controller_button_mapping(control, event.controller, event.button));
}
void input_mapper::handle_event(const game_controller_axis_moved_event& event)
void mapper::handle_event(const game_controller_axis_moved_event& event)
{
if (!is_enabled() || !callback)
{
return;
}
callback(game_controller_axis_mapping(control, event.game_controller, event.axis, (event.value < 0.0f)));
callback(game_controller_axis_mapping(control, event.controller, event.axis, (event.value < 0.0f)));
}
} // namespace input

src/input/input-mapper.hpp → src/input/mapper.hpp View File

@ -20,17 +20,18 @@
#ifndef ANTKEEPER_INPUT_MAPPER_HPP
#define ANTKEEPER_INPUT_MAPPER_HPP
#include "input/input-mapping.hpp"
#include "input/mapping.hpp"
#include "event/input-events.hpp"
#include "event/event-handler.hpp"
#include "event/event-dispatcher.hpp"
#include <functional>
class event_dispatcher;
namespace input {
/**
* An input mapper takes a control and listens to input events then generates corresponding input mappings which can be added to an input router.
*/
class input_mapper:
class mapper:
public event_handler<key_pressed_event>,
public event_handler<mouse_moved_event>,
public event_handler<mouse_wheel_scrolled_event>,
@ -42,12 +43,12 @@ public:
/**
* Creates an input mapper.
*/
input_mapper();
mapper();
/**
* Destroys an input mapper.
*/
virtual ~input_mapper();
virtual ~mapper();
/**
* Sets the event dispatcher to which this input event router will subscribe itself.
@ -59,14 +60,14 @@ public:
*
* @param control ::control for which input mappings will be generated.
*/
void set_control(::control* control);
void set_control(input::control* control);
/**
* Sets the callback function to the input mappings generated by this input mapper.
*
* @param callback Callback function operates on an input mapping.
*/
void set_callback(std::function<void(const input_mapping&)> callback);
void set_callback(std::function<void(const mapping&)> callback);
/**
* Enables or disables the input mapping generation.
@ -89,15 +90,17 @@ private:
void handle_event(const game_controller_button_pressed_event& event);
event_dispatcher* event_dispatcher;
::control* control;
std::function<void(const input_mapping&)> callback;
control* control;
std::function<void(const mapping&)> callback;
bool enabled;
};
inline bool input_mapper::is_enabled() const
inline bool mapper::is_enabled() const
{
return enabled;
}
} // namespace input
#endif // ANTKEEPER_INPUT_MAPPER_HPP

src/input/input-mapping.cpp → src/input/mapping.cpp View File

@ -17,9 +17,11 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "input-mapping.hpp"
#include "mapping.hpp"
input_mapping::input_mapping(::control* control):
namespace input {
mapping::mapping(input::control* control):
control(control)
{}
@ -28,8 +30,8 @@ key_mapping::key_mapping(const key_mapping& mapping)
*this = mapping;
}
key_mapping::key_mapping(::control* control, ::keyboard* keyboard, ::scancode scancode):
input_mapping(control),
key_mapping::key_mapping(input::control* control, input::keyboard* keyboard, input::scancode scancode):
mapping(control),
keyboard(keyboard),
scancode(scancode)
{}
@ -47,8 +49,8 @@ mouse_motion_mapping::mouse_motion_mapping(const mouse_motion_mapping& mapping)
*this = mapping;
}
mouse_motion_mapping::mouse_motion_mapping(::control* control, ::mouse* mouse, mouse_motion_axis axis):
input_mapping(control),
mouse_motion_mapping::mouse_motion_mapping(input::control* control, input::mouse* mouse, mouse_motion_axis axis):
mapping(control),
mouse(mouse),
axis(axis)
{}
@ -66,8 +68,8 @@ mouse_wheel_mapping::mouse_wheel_mapping(const mouse_wheel_mapping& mapping)
*this = mapping;
}
mouse_wheel_mapping::mouse_wheel_mapping(::control* control, ::mouse* mouse, ::mouse_wheel_axis axis):
input_mapping(control),
mouse_wheel_mapping::mouse_wheel_mapping(input::control* control, input::mouse* mouse, mouse_wheel_axis axis):
mapping(control),
mouse(mouse),
axis(axis)
{}
@ -85,8 +87,8 @@ mouse_button_mapping::mouse_button_mapping(const mouse_button_mapping& mapping)
*this = mapping;
}
mouse_button_mapping::mouse_button_mapping(::control* control, ::mouse* mouse, int button):
input_mapping(control),
mouse_button_mapping::mouse_button_mapping(input::control* control, input::mouse* mouse, int button):
mapping(control),
mouse(mouse),
button(button)
{}
@ -104,9 +106,9 @@ game_controller_axis_mapping::game_controller_axis_mapping(const game_controller
*this = mapping;
}
game_controller_axis_mapping::game_controller_axis_mapping(::control* control, ::game_controller* game_controller, game_controller_axis axis, bool negative):
input_mapping(control),
game_controller(game_controller),
game_controller_axis_mapping::game_controller_axis_mapping(input::control* control, game_controller* controller, game_controller_axis axis, bool negative):
mapping(control),
controller(controller),
axis(axis),
negative(negative)
{}
@ -114,7 +116,7 @@ game_controller_axis_mapping::game_controller_axis_mapping(::control* control, :
game_controller_axis_mapping& game_controller_axis_mapping::operator=(const game_controller_axis_mapping& mapping)
{
control = mapping.control;
game_controller = mapping.game_controller;
controller = mapping.controller;
axis = mapping.axis;
negative = mapping.negative;
return *this;
@ -125,17 +127,18 @@ game_controller_button_mapping::game_controller_button_mapping(const game_contro
*this = mapping;
}
game_controller_button_mapping::game_controller_button_mapping(::control* control, ::game_controller* game_controller, game_controller_button button):
input_mapping(control),
game_controller(game_controller),
game_controller_button_mapping::game_controller_button_mapping(input::control* control, game_controller* controller, game_controller_button button):
mapping(control),
controller(controller),
button(button)
{}
game_controller_button_mapping& game_controller_button_mapping::operator=(const game_controller_button_mapping& mapping)
{
control = mapping.control;
game_controller = mapping.game_controller;
controller = mapping.controller;
button = mapping.button;
return *this;
}
} // namespace input

src/input/input-mapping.hpp → src/input/mapping.hpp View File

@ -20,6 +20,8 @@
#ifndef ANTKEEPER_INPUT_MAPPING_HPP
#define ANTKEEPER_INPUT_MAPPING_HPP
namespace input {
enum class mouse_motion_axis;
enum class mouse_wheel_axis;
enum class scancode;
@ -33,7 +35,7 @@ class game_controller;
/**
* Enumerates the supported types of control mappings.
*/
enum class input_mapping_type
enum class mapping_type
{
key,
mouse_motion,
@ -46,15 +48,15 @@ enum class input_mapping_type
/**
* Abstract base class for input mappings.
*/
class input_mapping
class mapping
{
public:
input_mapping() = default;
input_mapping(::control* control);
virtual ~input_mapping() = default;
mapping() = default;
mapping(input::control* control);
virtual ~mapping() = default;
/// Returns this control mapping's type.
virtual input_mapping_type get_type() const = 0;
virtual mapping_type get_type() const = 0;
control* control;
};
@ -62,112 +64,112 @@ public:
/**
* A mapping between a control and a keyboard key.
*/
class key_mapping: public input_mapping
class key_mapping: public mapping
{
public:
key_mapping() = default;
key_mapping(const key_mapping& mapping);
key_mapping(::control* control, keyboard* keyboard, scancode scancode);
key_mapping(input::control* control, input::keyboard* keyboard, scancode scancode);
virtual ~key_mapping() = default;
key_mapping& operator=(const key_mapping& mapping);
virtual input_mapping_type get_type() const;
virtual mapping_type get_type() const;
keyboard* keyboard;
input::keyboard* keyboard;
scancode scancode;
};
inline input_mapping_type key_mapping::get_type() const
inline mapping_type key_mapping::get_type() const
{
return input_mapping_type::key;
return mapping_type::key;
}
/**
* A mapping between a control and a mouse motion axis.
*/
class mouse_motion_mapping: public input_mapping
class mouse_motion_mapping: public mapping
{
public:
mouse_motion_mapping() = default;
mouse_motion_mapping(const mouse_motion_mapping& mapping);
mouse_motion_mapping(::control* control, ::mouse* mouse, mouse_motion_axis axis);
mouse_motion_mapping(input::control* control, input::mouse* mouse, mouse_motion_axis axis);
virtual ~mouse_motion_mapping() = default;
mouse_motion_mapping& operator=(const mouse_motion_mapping& mapping);
virtual input_mapping_type get_type() const;
virtual mapping_type get_type() const;
mouse* mouse;
input::mouse* mouse;
mouse_motion_axis axis;
};
inline input_mapping_type mouse_motion_mapping::get_type() const
inline mapping_type mouse_motion_mapping::get_type() const
{
return input_mapping_type::mouse_motion;
return mapping_type::mouse_motion;
}
/**
* A mapping between a control and a mouse wheel axis.
*/
class mouse_wheel_mapping: public input_mapping
class mouse_wheel_mapping: public mapping
{
public:
mouse_wheel_mapping() = default;
mouse_wheel_mapping(const mouse_wheel_mapping& mapping);
mouse_wheel_mapping(::control* control, mouse* mouse, mouse_wheel_axis axis);
mouse_wheel_mapping(input::control* control, input::mouse* mouse, mouse_wheel_axis axis);
virtual ~mouse_wheel_mapping() = default;
mouse_wheel_mapping& operator=(const mouse_wheel_mapping& mapping);
virtual input_mapping_type get_type() const;
virtual mapping_type get_type() const;
mouse* mouse;
input::mouse* mouse;
mouse_wheel_axis axis;
};
inline input_mapping_type mouse_wheel_mapping::get_type() const
inline mapping_type mouse_wheel_mapping::get_type() const
{
return input_mapping_type::mouse_wheel;
return mapping_type::mouse_wheel;
}
/**
* A mapping between a control and a mouse button.
*/
class mouse_button_mapping: public input_mapping
class mouse_button_mapping: public mapping
{
public:
mouse_button_mapping() = default;
mouse_button_mapping(const mouse_button_mapping& mapping);
mouse_button_mapping(::control* control, mouse* mouse, int button);
mouse_button_mapping(input::control* control, input::mouse* mouse, int button);
virtual ~mouse_button_mapping() = default;
mouse_button_mapping& operator=(const mouse_button_mapping& mapping);
virtual input_mapping_type get_type() const;
virtual mapping_type get_type() const;
mouse* mouse;
input::mouse* mouse;
int button;
};
inline input_mapping_type mouse_button_mapping::get_type() const
inline mapping_type mouse_button_mapping::get_type() const
{
return input_mapping_type::mouse_button;
return mapping_type::mouse_button;
}
/**
* A mapping between a control and a game controller axis.
*/
class game_controller_axis_mapping: public input_mapping
class game_controller_axis_mapping: public mapping
{
public:
game_controller_axis_mapping() = default;
game_controller_axis_mapping(const game_controller_axis_mapping& mapping);
game_controller_axis_mapping(::control* control, game_controller* game_controller, game_controller_axis axis, bool negative);
game_controller_axis_mapping(input::control* control, game_controller* controller, game_controller_axis axis, bool negative);
virtual ~game_controller_axis_mapping() = default;
game_controller_axis_mapping& operator=(const game_controller_axis_mapping& mapping);
virtual input_mapping_type get_type() const;
virtual mapping_type get_type() const;
game_controller* game_controller;
game_controller* controller;
game_controller_axis axis;
bool negative;
};
inline input_mapping_type game_controller_axis_mapping::get_type() const
inline mapping_type game_controller_axis_mapping::get_type() const
{
return input_mapping_type::game_controller_axis;
return mapping_type::game_controller_axis;
}
/**
@ -175,24 +177,26 @@ inline input_mapping_type game_controller_axis_mapping::get_type() const
*
* @ingroup input.
*/
class game_controller_button_mapping: public input_mapping
class game_controller_button_mapping: public mapping
{
public:
game_controller_button_mapping() = default;
game_controller_button_mapping(const game_controller_button_mapping& mapping);
game_controller_button_mapping(::control* control, game_controller* game_controller, game_controller_button button);
game_controller_button_mapping(input::control* control, game_controller* controller, game_controller_button button);
virtual ~game_controller_button_mapping() = default;
game_controller_button_mapping& operator=(const game_controller_button_mapping& mapping);
virtual input_mapping_type get_type() const;
virtual mapping_type get_type() const;
game_controller* game_controller;
game_controller* controller;
game_controller_button button;
};
inline input_mapping_type game_controller_button_mapping::get_type() const
inline mapping_type game_controller_button_mapping::get_type() const
{
return input_mapping_type::game_controller_button;
return mapping_type::game_controller_button;
}
} // namespace input
#endif // ANTKEEPER_INPUT_MAPPING_HPP

+ 11
- 8
src/input/mouse.cpp View File

@ -21,12 +21,14 @@
#include "event/input-events.hpp"
#include "event/event-dispatcher.hpp"
namespace input {
mouse::mouse()
{}
void mouse::press(int button, int x, int y)
{
if (!input_device::event_dispatcher)
if (!device::event_dispatcher)
{
return;
}
@ -37,12 +39,12 @@ void mouse::press(int button, int x, int y)
event.x = x;
event.y = y;
input_device::event_dispatcher->queue(event);
device::event_dispatcher->queue(event);
}
void mouse::release(int button, int x, int y)
{
if (!input_device::event_dispatcher)
if (!device::event_dispatcher)
{
return;
}
@ -53,7 +55,7 @@ void mouse::release(int button, int x, int y)
event.x = x;
event.y = y;
input_device::event_dispatcher->queue(event);
device::event_dispatcher->queue(event);
}
void mouse::move(int x, int y, int dx, int dy)
@ -61,7 +63,7 @@ void mouse::move(int x, int y, int dx, int dy)
previous_position = current_position;
current_position = {x, y};
if (!input_device::event_dispatcher)
if (!device::event_dispatcher)
{
return;
}
@ -73,12 +75,12 @@ void mouse::move(int x, int y, int dx, int dy)
event.dx = dx;
event.dy = dy;
input_device::event_dispatcher->queue(event);
device::event_dispatcher->queue(event);
}
void mouse::scroll(int x, int y)
{
if (!input_device::event_dispatcher)
if (!device::event_dispatcher)
{
return;
}
@ -88,6 +90,7 @@ void mouse::scroll(int x, int y)
event.x = x;
event.y = y;
input_device::event_dispatcher->queue(event);
device::event_dispatcher->queue(event);
}
} // namespace input

+ 9
- 5
src/input/mouse.hpp View File

@ -17,12 +17,14 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_MOUSE_HPP
#define ANTKEEPER_MOUSE_HPP
#ifndef ANTKEEPER_INPUT_MOUSE_HPP
#define ANTKEEPER_INPUT_MOUSE_HPP
#include "input-device.hpp"
#include "device.hpp"
#include <tuple>
namespace input {
/**
* Enumerates the mouse motion axes.
*/
@ -62,7 +64,7 @@ enum class mouse_wheel_axis
/**
* A virtual mouse which can generate mouse-related input events and pass them to an event dispatcher.
*/
class mouse: public input_device
class mouse: public device
{
public:
/**
@ -127,5 +129,7 @@ inline const std::tuple& mouse::get_previous_position() const
return previous_position;
}
#endif // ANTKEEPER_MOUSE_HPP
} // namespace input
#endif // ANTKEEPER_INPUT_MOUSE_HPP

+ 7
- 3
src/input/scancode.hpp View File

@ -17,8 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_SCANCODE_HPP
#define ANTKEEPER_SCANCODE_HPP
#ifndef ANTKEEPER_INPUT_SCANCODE_HPP
#define ANTKEEPER_INPUT_SCANCODE_HPP
namespace input {
/**
* Enumerates keyboard scancodes.
@ -273,5 +275,7 @@ enum class scancode
audio_fast_forward
};
#endif // ANTKEEPER_SCANCODE_HPP
} // namespace input
#endif // ANTKEEPER_INPUT_SCANCODE_HPP

+ 3
- 0
src/input/sdl-game-controller-tables.cpp View File

@ -20,6 +20,8 @@
#include "sdl-game-controller-tables.hpp"
#include "game-controller.hpp"
namespace input {
const game_controller_button sdl_button_table[15] =
{
game_controller_button::a, // SDL_CONTROLLER_BUTTON_A,
@ -49,3 +51,4 @@ const game_controller_axis sdl_axis_table[6] =
game_controller_axis::trigger_right, // SDL_CONTROLLER_AXIS_TRIGGERRIGHT,
};
} // namespace input

+ 7
- 3
src/input/sdl-game-controller-tables.hpp View File

@ -17,8 +17,10 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_SDL_GAME_CONTROLLER_TABLES_HPP
#define ANTKEEPER_SDL_GAME_CONTROLLER_TABLES_HPP
#ifndef ANTKEEPER_INPUT_SDL_GAME_CONTROLLER_TABLES_HPP
#define ANTKEEPER_INPUT_SDL_GAME_CONTROLLER_TABLES_HPP
namespace input {
enum class game_controller_button;
enum class game_controller_axis;
@ -26,5 +28,7 @@ enum class game_controller_axis;
extern const game_controller_button sdl_button_table[15];
extern const game_controller_axis sdl_axis_table[6];
#endif // ANTKEEPER_SDL_GAME_CONTROLLER_TABLES_HPP
} // namespace input
#endif // ANTKEEPER_INPUT_SDL_GAME_CONTROLLER_TABLES_HPP

+ 3
- 0
src/input/sdl-scancode-table.cpp View File

@ -20,6 +20,8 @@
#include "sdl-scancode-table.hpp"
#include "scancode.hpp"
namespace input {
const scancode sdl_scancode_table[287] =
{
scancode::unknown, // SDL_SCANCODE_UNKNOWN = 0,
@ -311,3 +313,4 @@ const scancode sdl_scancode_table[287] =
scancode::audio_fast_forward, // SDL_SCANCODE_AUDIOFASTFORWARD = 286,
};
} // namespace input

+ 7
- 3
src/input/sdl-scancode-table.hpp View File

@ -17,12 +17,16 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_SDL_SCANCODE_TABLE_HPP
#define ANTKEEPER_SDL_SCANCODE_TABLE_HPP
#ifndef ANTKEEPER_INPUT_SDL_SCANCODE_TABLE_HPP
#define ANTKEEPER_INPUT_SDL_SCANCODE_TABLE_HPP
namespace input {
enum class scancode;
extern const scancode sdl_scancode_table[287];
#endif // ANTKEEPER_SDL_SCANCODE_TABLE_HPP
} // namespace input
#endif // ANTKEEPER_INPUT_SDL_SCANCODE_TABLE_HPP

Loading…
Cancel
Save