2010-04-05 23:38:59 +02:00
|
|
|
#ifndef _CONTROLLERBASE_H
|
|
|
|
#define _CONTROLLERBASE_H
|
|
|
|
|
|
|
|
#include "Engine.h"
|
|
|
|
|
|
|
|
namespace Engine {
|
|
|
|
|
|
|
|
class ModelBase;
|
|
|
|
class Console;
|
|
|
|
class Module;
|
|
|
|
|
2010-08-29 23:59:24 +02:00
|
|
|
/** \brief The IMGUI state
|
|
|
|
*
|
|
|
|
* See also http://sol.gfxile.net/imgui/
|
|
|
|
*/
|
|
|
|
struct UIState {
|
|
|
|
int hotitem;
|
|
|
|
int activeitem;
|
2010-09-11 02:28:50 +02:00
|
|
|
|
|
|
|
int kbditem;
|
|
|
|
SDLKey last_keysym;
|
|
|
|
Uint16 last_unicode;
|
|
|
|
|
|
|
|
int lastwidget;
|
2010-08-29 23:59:24 +02:00
|
|
|
};
|
|
|
|
|
2010-04-05 23:38:59 +02:00
|
|
|
/** \brief Defines the number of keys (keyboard + mous) that we can bind to.
|
|
|
|
*
|
|
|
|
* As the keysym enum of SDL has about 320 keys defined and we might have some
|
|
|
|
* more we set this define to 400 which should suffice. See also the file
|
|
|
|
* keytable.h
|
|
|
|
*/
|
|
|
|
#define BINDING_KEYS_LAST 400
|
|
|
|
|
|
|
|
/** \brief Converts a string into the corresponding keycode */
|
|
|
|
int convert_keystring (const char *key_val);
|
|
|
|
|
|
|
|
/** \brief All input is sent here and distributed from here
|
|
|
|
*
|
|
|
|
* Distributes and modifies the Model and indirectly the view by modifying the
|
|
|
|
* camera. It also holds the configuration of the keybindings and sends
|
|
|
|
* commands to the CommandQueue.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class ControllerBase : public Module {
|
|
|
|
public:
|
|
|
|
/** \brief Processes all inputs and performs all the controlling for the
|
|
|
|
* current frame. */
|
|
|
|
void Process ();
|
|
|
|
/** \brief Returns the current mouse position in screen coordinates */
|
|
|
|
void GetMouseScreenPosition (int *pos_out) {
|
|
|
|
pos_out[0] = mMouseScreenPosition[0];
|
|
|
|
pos_out[1] = mMouseScreenPosition[1];
|
|
|
|
}
|
|
|
|
void GetMouseWorldPosition (float *pos_out) {
|
|
|
|
pos_out[0] = mMouseWorldPosition[0];
|
|
|
|
pos_out[1] = mMouseWorldPosition[1];
|
|
|
|
pos_out[2] = mMouseWorldPosition[2];
|
|
|
|
}
|
2010-08-29 23:59:24 +02:00
|
|
|
bool GetButtonState (unsigned int key) {
|
|
|
|
assert (key < BINDING_KEYS_LAST);
|
|
|
|
return mButtonStates.test(key);
|
|
|
|
}
|
|
|
|
void SetButtonState (unsigned int key, bool state) {
|
|
|
|
assert (key < BINDING_KEYS_LAST);
|
|
|
|
mButtonStates.set (key, state);
|
|
|
|
}
|
2010-04-05 23:38:59 +02:00
|
|
|
bool BindKey (int key, const char *command);
|
|
|
|
|
2010-07-15 22:47:17 +02:00
|
|
|
/** \brief Activates or deactivates unicode processing and key delays of the keyboard inputs */
|
|
|
|
void EnableTextinput (bool textinput_state);
|
|
|
|
|
2010-08-29 23:59:24 +02:00
|
|
|
void IMGUIPrepare () {
|
|
|
|
uistate.hotitem = 0;
|
|
|
|
}
|
2010-09-11 02:28:50 +02:00
|
|
|
void IMGUIClear () {
|
|
|
|
LogMessage ("Called IMGUIClear()");
|
|
|
|
uistate.hotitem = 0;
|
|
|
|
uistate.kbditem = 0;
|
|
|
|
}
|
2010-08-29 23:59:24 +02:00
|
|
|
void IMGUIFinish ();
|
|
|
|
|
|
|
|
UIState uistate;
|
|
|
|
|
2010-04-05 23:38:59 +02:00
|
|
|
protected:
|
|
|
|
/** \brief Initializes the system */
|
|
|
|
virtual int OnInit (int argc, char* argv[]);
|
|
|
|
/** \brief Destroys the system (must be called!) */
|
|
|
|
virtual void OnDestroy ();
|
|
|
|
/** \brief Registering of the commands of the ControllerBase */
|
|
|
|
virtual void OnRegisterCommands ();
|
|
|
|
|
|
|
|
/** \brief Processes all Events reported by SDL_PollEvent */
|
|
|
|
virtual void ProcessEvents ();
|
|
|
|
|
|
|
|
/** \brief Keyboard processing */
|
|
|
|
bool OnKeyDown (const SDL_keysym &keysym);
|
|
|
|
/** \brief Keyboard processing */
|
|
|
|
bool OnKeyUp (const SDL_keysym &keysym);
|
|
|
|
|
|
|
|
/** \brief Mouse processing */
|
|
|
|
bool OnMouseButtonDown (Uint8 button, Uint16 xpos, Uint16 ypos);
|
|
|
|
/** \brief Mouse processing */
|
|
|
|
bool OnMouseButtonUp (Uint8 button, Uint16 xpos, Uint16 ypos);
|
|
|
|
/** \brief Mouse processing */
|
|
|
|
bool OnMouseMotion (const int xnew, const int ynew);
|
|
|
|
|
|
|
|
/** \brief Resizes the size of the View */
|
|
|
|
bool OnVideoResize (int width, int height);
|
|
|
|
|
|
|
|
/** \brief Needs the Model to modify it */
|
|
|
|
ModelBase * mModel;
|
|
|
|
/** \brief Input might be sent to the Console, hence it is here */
|
|
|
|
Console * mConsole;
|
|
|
|
/** \brief The View which can get modified by Controller */
|
|
|
|
ViewBase *mView;
|
|
|
|
|
|
|
|
/** \brief Stores the current mouse position in screen coordinates */
|
|
|
|
int mMouseScreenPosition[2];
|
2010-08-29 23:59:24 +02:00
|
|
|
/** \brief Stores the current mouse position on the y=0 plane in world coordinates */
|
2010-04-05 23:38:59 +02:00
|
|
|
float mMouseWorldPosition[3];
|
2010-08-29 23:59:24 +02:00
|
|
|
|
|
|
|
/** \brief Stores for each button of the mouse whether it is clicked
|
|
|
|
* \TODO [low] move it to a bitset and remove the fixed amount of buttons */
|
|
|
|
std::bitset<BINDING_KEYS_LAST> mButtonStates;
|
2010-04-05 23:38:59 +02:00
|
|
|
|
|
|
|
/** \brief Contains all the bindings for the keyboard */
|
|
|
|
std::string mBindings[BINDING_KEYS_LAST];
|
|
|
|
|
|
|
|
friend class Engine;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif // _CONTROLLERBASE_H
|