diff options
author | Eugene Sandulenko | 2010-08-06 13:13:25 +0000 |
---|---|---|
committer | Eugene Sandulenko | 2010-10-12 22:35:55 +0000 |
commit | 47904bc7b2992189bb554833f00a79ff0fea9fb8 (patch) | |
tree | 1cec51758c6741b970bd064fafee77607b9f884f /engines/sword25/input | |
parent | ca17def625154e5f758b797e4fc48c76b0566320 (diff) | |
download | scummvm-rg350-47904bc7b2992189bb554833f00a79ff0fea9fb8.tar.gz scummvm-rg350-47904bc7b2992189bb554833f00a79ff0fea9fb8.tar.bz2 scummvm-rg350-47904bc7b2992189bb554833f00a79ff0fea9fb8.zip |
SWORD25: Mass-astyle.
svn-id: r53222
Diffstat (limited to 'engines/sword25/input')
-rw-r--r-- | engines/sword25/input/inputengine.cpp | 2 | ||||
-rw-r--r-- | engines/sword25/input/inputengine.h | 120 | ||||
-rw-r--r-- | engines/sword25/input/inputengine_script.cpp | 84 | ||||
-rw-r--r-- | engines/sword25/input/scummvminput.cpp | 67 | ||||
-rw-r--r-- | engines/sword25/input/scummvminput.h | 38 |
5 files changed, 159 insertions, 152 deletions
diff --git a/engines/sword25/input/inputengine.cpp b/engines/sword25/input/inputengine.cpp index 5b26bb81ba..7552118e54 100644 --- a/engines/sword25/input/inputengine.cpp +++ b/engines/sword25/input/inputengine.cpp @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer diff --git a/engines/sword25/input/inputengine.h b/engines/sword25/input/inputengine.h index f88f67de38..c0f2b47bf5 100644 --- a/engines/sword25/input/inputengine.h +++ b/engines/sword25/input/inputengine.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -57,15 +57,15 @@ namespace Sword25 { class BS_InputEngine : public BS_Service, public BS_Persistable { public: - BS_InputEngine(BS_Kernel* pKernel); - virtual ~BS_InputEngine(){}; + BS_InputEngine(BS_Kernel *pKernel); + virtual ~BS_InputEngine() {}; // NOTE: These codes are registered in inputengine_script.cpp // Any changes to these enums must also adjust the above file. - enum KEY_CODES { - KEY_BACKSPACE = 0x08, - KEY_TAB = 0x09, - KEY_CLEAR = 0x0C, + enum KEY_CODES { + KEY_BACKSPACE = 0x08, + KEY_TAB = 0x09, + KEY_CLEAR = 0x0C, KEY_RETURN = 0x0D, KEY_PAUSE = 0x13, KEY_CAPSLOCK = 0x14, @@ -79,45 +79,45 @@ public: KEY_UP = 0x26, KEY_RIGHT = 0x27, KEY_DOWN = 0x28, - KEY_PRINTSCREEN = 0x2C, + KEY_PRINTSCREEN = 0x2C, KEY_INSERT = 0x2D, KEY_DELETE = 0x2E, - KEY_0 = 0x30, - KEY_1 = 0x31, - KEY_2 = 0x32, - KEY_3 = 0x33, - KEY_4 = 0x34, - KEY_5 = 0x35, - KEY_6 = 0x36, - KEY_7 = 0x37, - KEY_8 = 0x38, - KEY_9 = 0x39, - KEY_A = 0x41, - KEY_B = 0x42, - KEY_C = 0x43, - KEY_D = 0x44, - KEY_E = 0x45, - KEY_F = 0x46, - KEY_G = 0x47, - KEY_H = 0x48, - KEY_I = 0x49, - KEY_J = 0x4A, - KEY_K = 0x4B, - KEY_L = 0x4C, - KEY_M = 0x4D, - KEY_N = 0x4E, - KEY_O = 0x4F, - KEY_P = 0x50, - KEY_Q = 0x51, - KEY_R = 0x52, - KEY_S = 0x53, - KEY_T = 0x54, - KEY_U = 0x55, - KEY_V = 0x56, - KEY_W = 0x57, - KEY_X = 0x58, - KEY_Y = 0x59, - KEY_Z = 0x5A, + KEY_0 = 0x30, + KEY_1 = 0x31, + KEY_2 = 0x32, + KEY_3 = 0x33, + KEY_4 = 0x34, + KEY_5 = 0x35, + KEY_6 = 0x36, + KEY_7 = 0x37, + KEY_8 = 0x38, + KEY_9 = 0x39, + KEY_A = 0x41, + KEY_B = 0x42, + KEY_C = 0x43, + KEY_D = 0x44, + KEY_E = 0x45, + KEY_F = 0x46, + KEY_G = 0x47, + KEY_H = 0x48, + KEY_I = 0x49, + KEY_J = 0x4A, + KEY_K = 0x4B, + KEY_L = 0x4C, + KEY_M = 0x4D, + KEY_N = 0x4E, + KEY_O = 0x4F, + KEY_P = 0x50, + KEY_Q = 0x51, + KEY_R = 0x52, + KEY_S = 0x53, + KEY_T = 0x54, + KEY_U = 0x55, + KEY_V = 0x56, + KEY_W = 0x57, + KEY_X = 0x58, + KEY_Y = 0x59, + KEY_Z = 0x5A, KEY_NUMPAD0 = 0x60, KEY_NUMPAD1 = 0x61, KEY_NUMPAD2 = 0x62, @@ -154,7 +154,7 @@ public: KEY_RCONTROL = 0xA3 }; - // NOTE: These codes are registered in inputengine_script.cpp. + // NOTE: These codes are registered in inputengine_script.cpp. // Any changes to these enums must also adjust the above file. enum KEY_COMMANDS { KEY_COMMAND_ENTER = 1, @@ -171,16 +171,16 @@ public: /// -------------------------------------------------------------- /// THESE METHODS MUST BE IMPLEMENTED BY THE INPUT ENGINE /// -------------------------------------------------------------- - + /** * Initialises the input engine - * @return Returns a true on success, otherwise false. + * @return Returns a true on success, otherwise false. */ virtual bool Init() = 0; /** * Performs a "tick" of the input engine. - * + * * This method should be called once per frame. It can be used by implementations * of the input engine that are not running in their own thread, or to perform * additional administrative tasks that are needed. @@ -240,8 +240,8 @@ public: /** * Returns true if a given key was pressed - * @param KeyCode The key code to be checked - * @return Returns true if the given key is done, otherwise false. + * @param KeyCode The key code to be checked + * @return Returns true if the given key is done, otherwise false. */ virtual bool IsKeyDown(unsigned int KeyCode) = 0; @@ -251,7 +251,7 @@ public: * The difference between IsKeyDown() is that this only returns true after the key * has been released. This method facilitates the retrieval of keys, and reading * strings that users type. - * @param KeyCode The key code to be checked + * @param KeyCode The key code to be checked */ virtual bool WasKeyDown(unsigned int KeyCode) = 0; @@ -261,19 +261,19 @@ public: * Registers a callback function for keyboard input. * * The callbacks that are registered with this function will be called whenever an - * input key is pressed. A letter entry is different from the query using the - * methods IsKeyDown () and WasKeyDown () in the sense that are treated instead - * of actual scan-coded letters. These were taken into account, among other things: + * input key is pressed. A letter entry is different from the query using the + * methods IsKeyDown () and WasKeyDown () in the sense that are treated instead + * of actual scan-coded letters. These were taken into account, among other things: * the keyboard layout, the condition the Shift and Caps Lock keys and the repetition * of longer holding the key. * The input of strings by the user through use of callbacks should be implemented. - * @return Returns true if the function was registered, otherwise false. + * @return Returns true if the function was registered, otherwise false. */ virtual bool RegisterCharacterCallback(CallbackPtr Callback) = 0; /** * De-registeres a previously registered callback function. - * @return Returns true if the function could be de-registered, otherwise false. + * @return Returns true if the function could be de-registered, otherwise false. */ virtual bool UnregisterCharacterCallback(CallbackPtr Callback) = 0; @@ -282,17 +282,17 @@ public: /** * Registers a callback function for the input of commands that can have influence on the string input * - * The callbacks that are registered with this function will be called whenever the input service - * has a key that affects the character string input. This could be the following keys: + * The callbacks that are registered with this function will be called whenever the input service + * has a key that affects the character string input. This could be the following keys: * Enter, End, Left, Right, ... * The input of strings by the user through the use of callbacks should be implemented. - * @return Returns true if the function was registered, otherwise false. + * @return Returns true if the function was registered, otherwise false. */ virtual bool RegisterCommandCallback(CallbackPtr Callback) = 0; /** * Un-register a callback function for the input of commands that can have an influence on the string input. - * @return Returns true if the function could be de-registered, otherwise false. + * @return Returns true if the function could be de-registered, otherwise false. */ virtual bool UnregisterCommandCallback(CommandCallback Callback) = 0; diff --git a/engines/sword25/input/inputengine_script.cpp b/engines/sword25/input/inputengine_script.cpp index a7bd39481b..70c26e5282 100644 --- a/engines/sword25/input/inputengine_script.cpp +++ b/engines/sword25/input/inputengine_script.cpp @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -61,45 +61,47 @@ static void TheCharacterCallback(int Character); static void TheCommandCallback(int Command); namespace { - class CharacterCallbackClass : public BS_LuaCallback { - public: - CharacterCallbackClass(lua_State *L) : BS_LuaCallback(L) {}; - - Common::String Character; - - protected: - int PreFunctionInvokation(lua_State *L) { - lua_pushstring(L, Character.c_str()); - return 1; - } - }; - Common::SharedPtr<CharacterCallbackClass> CharacterCallbackPtr; - - // ----------------------------------------------------------------------------- - - class CommandCallbackClass : public BS_LuaCallback { - public: - CommandCallbackClass(lua_State *L) : BS_LuaCallback(L) { Command = BS_InputEngine::KEY_COMMAND_BACKSPACE; } - - BS_InputEngine::KEY_COMMANDS Command; - - protected: - int PreFunctionInvokation(lua_State *L) { - lua_pushnumber(L, Command); - return 1; - } - }; - Common::SharedPtr<CommandCallbackClass> CommandCallbackPtr; - - // ------------------------------------------------------------------------- - - struct CallbackfunctionRegisterer { - CallbackfunctionRegisterer() { - BS_CallbackRegistry::GetInstance().RegisterCallbackFunction("LuaCommandCB", TheCommandCallback); - BS_CallbackRegistry::GetInstance().RegisterCallbackFunction("LuaCharacterCB", TheCharacterCallback); - } - }; - static CallbackfunctionRegisterer Instance; +class CharacterCallbackClass : public BS_LuaCallback { +public: + CharacterCallbackClass(lua_State *L) : BS_LuaCallback(L) {}; + + Common::String Character; + +protected: + int PreFunctionInvokation(lua_State *L) { + lua_pushstring(L, Character.c_str()); + return 1; + } +}; +Common::SharedPtr<CharacterCallbackClass> CharacterCallbackPtr; + +// ----------------------------------------------------------------------------- + +class CommandCallbackClass : public BS_LuaCallback { +public: + CommandCallbackClass(lua_State *L) : BS_LuaCallback(L) { + Command = BS_InputEngine::KEY_COMMAND_BACKSPACE; + } + + BS_InputEngine::KEY_COMMANDS Command; + +protected: + int PreFunctionInvokation(lua_State *L) { + lua_pushnumber(L, Command); + return 1; + } +}; +Common::SharedPtr<CommandCallbackClass> CommandCallbackPtr; + +// ------------------------------------------------------------------------- + +struct CallbackfunctionRegisterer { + CallbackfunctionRegisterer() { + BS_CallbackRegistry::GetInstance().RegisterCallbackFunction("LuaCommandCB", TheCommandCallback); + BS_CallbackRegistry::GetInstance().RegisterCallbackFunction("LuaCharacterCB", TheCharacterCallback); + } +}; +static CallbackfunctionRegisterer Instance; } // ----------------------------------------------------------------------------- @@ -313,7 +315,7 @@ static const luaL_reg PACKAGE_FUNCTIONS[] = { "UnregisterCharacterCallback", UnregisterCharacterCallback, "RegisterCommandCallback", RegisterCommandCallback, "UnregisterCommandCallback", UnregisterCommandCallback, - 0, 0, + 0, 0, }; #define X(k) "KEY_" #k, BS_InputEngine::KEY_##k diff --git a/engines/sword25/input/scummvminput.cpp b/engines/sword25/input/scummvminput.cpp index 14c94bd226..76a7f0fe09 100644 --- a/engines/sword25/input/scummvminput.cpp +++ b/engines/sword25/input/scummvminput.cpp @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -54,19 +54,19 @@ namespace Sword25 { // ----------------------------------------------------------------------------- ScummVMInput::ScummVMInput(BS_Kernel *pKernel) : - m_CurrentState(0), - m_LeftMouseDown(false), - m_RightMouseDown(false), - m_MouseX(0), - m_MouseY(0), - m_LeftDoubleClick(false), - m_DoubleClickTime(DOUBLE_CLICK_TIME), - m_DoubleClickRectWidth(DOUBLE_CLICK_RECT_SIZE), - m_DoubleClickRectHeight(DOUBLE_CLICK_RECT_SIZE), - m_LastLeftClickTime(0), - m_LastLeftClickMouseX(0), - m_LastLeftClickMouseY(0), - BS_InputEngine(pKernel) { + m_CurrentState(0), + m_LeftMouseDown(false), + m_RightMouseDown(false), + m_MouseX(0), + m_MouseY(0), + m_LeftDoubleClick(false), + m_DoubleClickTime(DOUBLE_CLICK_TIME), + m_DoubleClickRectWidth(DOUBLE_CLICK_RECT_SIZE), + m_DoubleClickRectHeight(DOUBLE_CLICK_RECT_SIZE), + m_LastLeftClickTime(0), + m_LastLeftClickMouseX(0), + m_LastLeftClickMouseY(0), + BS_InputEngine(pKernel) { memset(m_KeyboardState[0], 0, sizeof(m_KeyboardState[0])); memset(m_KeyboardState[1], 0, sizeof(m_KeyboardState[1])); m_LeftMouseState[0] = false; @@ -80,7 +80,9 @@ ScummVMInput::~ScummVMInput() { // ----------------------------------------------------------------------------- -BS_Service *ScummVMInput_CreateObject(BS_Kernel *pKernel) { return new ScummVMInput(pKernel); } +BS_Service *ScummVMInput_CreateObject(BS_Kernel *pKernel) { + return new ScummVMInput(pKernel); +} // ----------------------------------------------------------------------------- @@ -102,18 +104,21 @@ void ScummVMInput::Update() { case Common::EVENT_LBUTTONDOWN: case Common::EVENT_LBUTTONUP: m_LeftMouseDown = event.type == Common::EVENT_LBUTTONDOWN; - m_MouseX = event.mouse.x; m_MouseY = event.mouse.y; + m_MouseX = event.mouse.x; + m_MouseY = event.mouse.y; handleEvents = false; break; case Common::EVENT_RBUTTONDOWN: case Common::EVENT_RBUTTONUP: m_RightMouseDown = event.type == Common::EVENT_RBUTTONDOWN; - m_MouseX = event.mouse.x; m_MouseY = event.mouse.y; + m_MouseX = event.mouse.x; + m_MouseY = event.mouse.y; handleEvents = false; break; case Common::EVENT_MOUSEMOVE: - m_MouseX = event.mouse.x; m_MouseY = event.mouse.y; + m_MouseX = event.mouse.x; + m_MouseY = event.mouse.y; break; case Common::EVENT_KEYDOWN: @@ -162,8 +167,8 @@ void ScummVMInput::TestForLeftDoubleClick() { // 1. The two clicks are close enough together // 2. The mouse cursor hasn't moved much if (Now - m_LastLeftClickTime <= m_DoubleClickTime && - ABS(m_MouseX - m_LastLeftClickMouseX) <= m_DoubleClickRectWidth / 2 && - ABS(m_MouseY - m_LastLeftClickMouseY) <= m_DoubleClickRectHeight / 2) { + ABS(m_MouseX - m_LastLeftClickMouseX) <= m_DoubleClickRectWidth / 2 && + ABS(m_MouseY - m_LastLeftClickMouseY) <= m_DoubleClickRectHeight / 2) { m_LeftDoubleClick = true; // Reset the time and position of the last click, so that clicking is not @@ -184,7 +189,7 @@ void ScummVMInput::TestForLeftDoubleClick() { // ----------------------------------------------------------------------------- void AlterKeyboardState(int keycode, byte newState) { - + } // ----------------------------------------------------------------------------- @@ -208,7 +213,7 @@ bool ScummVMInput::WasRightMouseDown() { // ----------------------------------------------------------------------------- int ScummVMInput::GetMouseX() { - return m_MouseX; + return m_MouseX; } // ----------------------------------------------------------------------------- @@ -226,8 +231,8 @@ bool ScummVMInput::IsKeyDown(unsigned int KeyCode) { // ----------------------------------------------------------------------------- bool ScummVMInput::WasKeyDown(unsigned int KeyCode) { - return ((m_KeyboardState[m_CurrentState][KeyCode] & 0x80) == 0) && - ((m_KeyboardState[m_CurrentState ^ 1][KeyCode] & 0x80) != 0); + return ((m_KeyboardState[m_CurrentState][KeyCode] & 0x80) == 0) && + ((m_KeyboardState[m_CurrentState ^ 1][KeyCode] & 0x80) != 0); } // ----------------------------------------------------------------------------- @@ -259,8 +264,8 @@ bool ScummVMInput::RegisterCharacterCallback(CharacterCallback Callback) { // ----------------------------------------------------------------------------- bool ScummVMInput::UnregisterCharacterCallback(CharacterCallback Callback) { - Common::List<CharacterCallback>::iterator CallbackIter = Common::find(m_CharacterCallbacks.begin(), - m_CharacterCallbacks.end(), Callback); + Common::List<CharacterCallback>::iterator CallbackIter = Common::find(m_CharacterCallbacks.begin(), + m_CharacterCallbacks.end(), Callback); if (CallbackIter != m_CharacterCallbacks.end()) { m_CharacterCallbacks.erase(CallbackIter); return true; @@ -285,8 +290,8 @@ bool ScummVMInput::RegisterCommandCallback(CommandCallback Callback) { // ----------------------------------------------------------------------------- bool ScummVMInput::UnregisterCommandCallback(CommandCallback Callback) { - Common::List<CommandCallback>::iterator CallbackIter = - Common::find(m_CommandCallbacks.begin(), m_CommandCallbacks.end(), Callback); + Common::List<CommandCallback>::iterator CallbackIter = + Common::find(m_CommandCallbacks.begin(), m_CommandCallbacks.end(), Callback); if (CallbackIter != m_CommandCallbacks.end()) { m_CommandCallbacks.erase(CallbackIter); return true; @@ -302,7 +307,7 @@ void ScummVMInput::ReportCharacter(unsigned char Character) { Common::List<CharacterCallback>::const_iterator CallbackIter = m_CharacterCallbacks.begin(); while (CallbackIter != m_CharacterCallbacks.end()) { // Iterator vor dem Aufruf erhöhen und im Folgendem auf einer Kopie arbeiten. - // Dieses Vorgehen ist notwendig da der Iterator möglicherweise von der Callbackfunktion durch das Deregistrieren des Callbacks + // Dieses Vorgehen ist notwendig da der Iterator möglicherweise von der Callbackfunktion durch das Deregistrieren des Callbacks // invalidiert wird. Common::List<CharacterCallback>::const_iterator CurCallbackIter = CallbackIter; ++CallbackIter; @@ -317,7 +322,7 @@ void ScummVMInput::ReportCommand(KEY_COMMANDS Command) { Common::List<CommandCallback>::const_iterator CallbackIter = m_CommandCallbacks.begin(); while (CallbackIter != m_CommandCallbacks.end()) { // Iterator vor dem Aufruf erhöhen und im Folgendem auf einer Kopie arbeiten. - // Dieses Vorgehen ist notwendig da der Iterator möglicherweise von der Callbackfunktion durch das Deregistrieren des Callbacks + // Dieses Vorgehen ist notwendig da der Iterator möglicherweise von der Callbackfunktion durch das Deregistrieren des Callbacks // invalidiert wird. Common::List<CommandCallback>::const_iterator CurCallbackIter = CallbackIter; ++CallbackIter; @@ -374,7 +379,7 @@ bool ScummVMInput::Unpersist(BS_InputPersistenceBlock &Reader) { Reader.Read(CallbackFunctionName); m_CommandCallbacks.push_back(reinterpret_cast<CommandCallback>( - BS_CallbackRegistry::GetInstance().ResolveCallbackFunction(CallbackFunctionName))); + BS_CallbackRegistry::GetInstance().ResolveCallbackFunction(CallbackFunctionName))); } // Character-Callbackliste leeren. diff --git a/engines/sword25/input/scummvminput.h b/engines/sword25/input/scummvminput.h index b38a54b757..b7f38df603 100644 --- a/engines/sword25/input/scummvminput.h +++ b/engines/sword25/input/scummvminput.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -51,7 +51,7 @@ class ScummVMInput : public BS_InputEngine { public: ScummVMInput(BS_Kernel *pKernel); virtual ~ScummVMInput(); - + virtual bool Init(); virtual void Update(); virtual bool IsLeftMouseDown(); @@ -79,23 +79,23 @@ private: void TestForLeftDoubleClick(); void AlterKeyboardState(int keycode, byte newState); - byte m_KeyboardState[2][256]; - bool m_LeftMouseState[2]; - bool m_RightMouseState[2]; - unsigned int m_CurrentState; - int m_MouseX; - int m_MouseY; - bool m_LeftMouseDown; - bool m_RightMouseDown; - bool m_LeftDoubleClick; - unsigned int m_DoubleClickTime; - int m_DoubleClickRectWidth; - int m_DoubleClickRectHeight; - unsigned int m_LastLeftClickTime; - int m_LastLeftClickMouseX; - int m_LastLeftClickMouseY; - Common::List<CommandCallback> m_CommandCallbacks; - Common::List<CharacterCallback> m_CharacterCallbacks; + byte m_KeyboardState[2][256]; + bool m_LeftMouseState[2]; + bool m_RightMouseState[2]; + unsigned int m_CurrentState; + int m_MouseX; + int m_MouseY; + bool m_LeftMouseDown; + bool m_RightMouseDown; + bool m_LeftDoubleClick; + unsigned int m_DoubleClickTime; + int m_DoubleClickRectWidth; + int m_DoubleClickRectHeight; + unsigned int m_LastLeftClickTime; + int m_LastLeftClickMouseX; + int m_LastLeftClickMouseY; + Common::List<CommandCallback> m_CommandCallbacks; + Common::List<CharacterCallback> m_CharacterCallbacks; }; } // End of namespace Sword25 |