| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- /*
- * Copyright (C) 2022 The V-Gears Team
- *
- * This file is part of V-Gears
- *
- * V-Gears is free software: you can redistribute it and/or modify it under
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, version 3.0 (GPLv3) of the License.
- *
- * V-Gears is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
- #pragma once
- #include <OgreSingleton.h>
- #include <OgreString.h>
- #include <OIS/OIS.h>
- #include <vector>
- #include "Event.h"
- typedef std::vector<QGears::Event> InputEventArray;
- typedef std::vector<int> ButtonList;
- class ConfigCmd;
- /**
- * The input manager.
- *
- * It handles input events and creates {@see Event}s.
- */
- class InputManager : public Ogre::Singleton<InputManager>{
- public:
- /**
- * Constructor.
- */
- InputManager();
- /**
- * Destructor.
- */
- virtual ~InputManager();
- /**
- * Triggered when a keyboard button is pressed or released.
- *
- * Creates an {@Event}.
- *
- * @param button[in] Pressed button ID.
- * @param text[in] @todo The key code? It gets assigned to parameter 1
- * of the generated event.
- * @param down[in] True if the button has been pressed, false if it has
- * been released. It gets assigned to parameter 2 of the event.
- */
- void ButtonPressed(int button, char text, bool down);
- /**
- * Triggered when a mouse button is pressed or released.
- *
- * Creates an {@Event}.
- *
- * @param button[in] Pressed button ID.
- * @param down[in] True if the button has been pressed, false if it has
- * been released. It gets assigned to parameter 1 of the event.
- */
- void MousePressed(int button, bool down);
- /**
- * Triggered when a mouse moves.
- *
- * Creates an {@Event}.
- *
- * @param x[in] New mouse's X coordinate. It gets assigned to parameter
- * 1 of the event.
- * @param y[in] New mouse's Y coordinate. It gets assigned to parameter
- * 2 of the event.
- */
- void MouseMoved(int x, int y);
- /**
- * Triggered when a mouse scrolls.
- *
- * Creates an {@Event}.
- *
- * @param value[in] Number of lines scrolled. Positive for scroll down,
- * negative for scroll up. It gets assigned to parameter 1 of the
- * event.
- */
- void MouseScrolled(int value);
- /**
- * Resets all keyboard and mouse events to their default state.
- *
- * Keyboard and mouse are considered to not pressed, the mouse movement
- * and scroll are considered 0.
- */
- void Reset();
- /**
- * Update keyboard and mouse buttons, movements and scroll status.
- */
- void Update();
- bool IsButtonPressed(int button) const;
- /**
- * Retrieves the current input events.
- *
- * The input event queue will be empty after calling this function.
- *
- * @param input_events[out] The current events will be loaded here.
- */
- void GetInputEvents(InputEventArray& input_events);
- /**
- * Initializes all command bindings.
- */
- void InitCmd();
- /**
- * Binds a command to an input event.
- *
- * @param cmd[in] Command to bind.
- * @param params[in] Command arguments.
- * @param buttons[in] Buttons to bind to the command.
- */
- void BindCommand(
- ConfigCmd* cmd, const Ogre::StringVector& params,
- const ButtonList& buttons
- );
- /**
- * Binds a game event to an input event.
- *
- * @param event[in] The game event to bind.
- * @param buttons[in] Buttons to bind to the event.
- */
- void BindGameEvent(
- const Ogre::String& event, const ButtonList& buttons
- );
- /**
- * Activates all bindings for a button.
- *
- * @param button[in] ID of the button.
- */
- void ActivateBinds(const int button);
- /**
- * @tdo Understand and document.
- *
- * @param button[in] ID of the button.
- * @param type[in] Event type.
- */
- void AddGameEvents(const int button, const QGears::EventType type);
- private:
- /**
- * The state of eahc button.
- */
- bool button_state_[256];
- /**
- * The text of each button.
- *
- * @todo The text is the keycode?
- */
- char button_text_[256];
- /**
- * Indicates if a key holded down is waiting to repeat events.
- *
- * @todo Verify this.
- */
- bool repeat_first_wait_;
- /**
- * The time a key has been pressed.
- */
- float repeat_timer_;
- /**
- * The event queue.
- */
- InputEventArray event_queue_;
- /**
- * A command binding.
- */
- struct BindInfo{
- /**
- * Constructor.
- */
- BindInfo(): cmd(NULL){}
- /**
- * The bind command.
- */
- ConfigCmd* cmd;
- /**
- * The command parameters.
- */
- Ogre::StringVector params;
- /**
- * The buttons bond to the command.
- */
- ButtonList buttons;
- };
- /**
- * List of command bindings.
- */
- std::vector<BindInfo> binds_;
- /**
- * A game event binding
- */
- struct BindGameEventInfo{
- /**
- * The game event.
- */
- Ogre::String event;
- /**
- * The buttons bond to the command.
- */
- ButtonList buttons;
- };
- /**
- * List of game event bindings.
- */
- std::vector<BindGameEventInfo> bind_game_events_;
- };
|