Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. /////////////////// FILE KeyboardKey.hh
  2.  
  3. #pragma once
  4.  
  5. #include <SDL.h>
  6. #include <action/KeyboardKey.forw.hpp>
  7. #include <action/InputController.forw.hpp>
  8. #include <action/Key.hpp>
  9. #include <event/KeyDownEvent.hpp>
  10. #include <event/KeyUpEvent.hpp>
  11. #include <msg/message_bus.hh>
  12. #include <vector>
  13.  
  14. namespace action {
  15.  
  16. class KeyboardKey : public Key {
  17.     friend class InputController;
  18.  
  19. private:
  20.     SDL_Keycode _keycode;
  21.     InputController& _controller;
  22. public:
  23.     KeyboardKey(InputController& input,
  24.                 SDL_Keycode code) : _keycode(code), _controller(input) {} // <- THIS sets a wrong value
  25.  
  26.     KeyboardKey(KeyboardKey& key) = delete;
  27.  
  28.     KeyboardKey(KeyboardKey&& key)
  29.             : _keycode(key._keycode), _controller(key._controller) {}
  30.  
  31.     KeyboardKey&
  32.     operator=(KeyboardKey& other) = delete;
  33.  
  34.     KeyboardKey&
  35.     operator=(KeyboardKey&& other) {
  36.         _keycode = other._keycode;
  37.         _controller = std::move(other._controller);
  38.         return *this;
  39.     }
  40.  
  41.     virtual bool
  42.     is_pressed() override;
  43.  
  44.     virtual msg::listener_handle<event::KeyDownEvent>
  45.     listen_down(std::function<void(event::KeyDownEvent*)> func) override;
  46.  
  47.     virtual msg::listener_handle<event::KeyUpEvent>
  48.     listen_up(std::function<void(event::KeyUpEvent*)> func) override;
  49. };
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement