aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25/input/inputengine.h
diff options
context:
space:
mode:
authorJohannes Schickel2010-10-13 03:57:44 +0000
committerJohannes Schickel2010-10-13 03:57:44 +0000
commit75e8452b6e6a2bf4fb2f588aa00b428a60d873b5 (patch)
treef29541d55309487a94bd1d38e8b53bb3dde9aec6 /engines/sword25/input/inputengine.h
parent48ee83b88957dab86bc763e9ef21a70179fa8679 (diff)
parente9f50882ea5b6beeefa994040be9d3bab6a1f107 (diff)
downloadscummvm-rg350-75e8452b6e6a2bf4fb2f588aa00b428a60d873b5.tar.gz
scummvm-rg350-75e8452b6e6a2bf4fb2f588aa00b428a60d873b5.tar.bz2
scummvm-rg350-75e8452b6e6a2bf4fb2f588aa00b428a60d873b5.zip
OPENGL: Merged from trunk, from rev 52105 to 53396.
This includes an rather hacky attempt to merge all the recent gp2x backend changes into the branch. I suppose the gp2x backend and probably all new backends, i.e. gph, dingux etc., might not compile anymore. Since I have no way of testing those it would be nice if porters could look into getting those up to speed in this branch. svn-id: r53399
Diffstat (limited to 'engines/sword25/input/inputengine.h')
-rw-r--r--engines/sword25/input/inputengine.h333
1 files changed, 333 insertions, 0 deletions
diff --git a/engines/sword25/input/inputengine.h b/engines/sword25/input/inputengine.h
new file mode 100644
index 0000000000..540817b5ce
--- /dev/null
+++ b/engines/sword25/input/inputengine.h
@@ -0,0 +1,333 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program 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.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+/*
+ * This code is based on Broken Sword 2.5 engine
+ *
+ * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
+ *
+ * Licensed under GNU GPL v2
+ *
+ */
+
+/*
+ * BS_InputEngine
+ * -------------
+ * This is the input interface engine that contains all the methods that an
+ * input source must implement.
+ * All input engines must be derived from this class.
+ *
+ * Autor: Alex Arnst
+ */
+
+#ifndef SWORD25_INPUTENGINE_H
+#define SWORD25_INPUTENGINE_H
+
+/// Includes
+#include "sword25/kernel/common.h"
+#include "sword25/kernel/service.h"
+#include "sword25/kernel/persistable.h"
+#include "sword25/kernel/callbackregistry.h"
+
+namespace Sword25 {
+
+/// Class definitions
+
+class InputEngine : public Service, public Persistable {
+public:
+ InputEngine(Kernel *pKernel);
+ ~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,
+ KEY_RETURN = 0x0D,
+ KEY_PAUSE = 0x13,
+ KEY_CAPSLOCK = 0x14,
+ KEY_ESCAPE = 0x1B,
+ KEY_SPACE = 0x20,
+ KEY_PAGEUP = 0x21,
+ KEY_PAGEDOWN = 0x22,
+ KEY_END = 0x23,
+ KEY_HOME = 0x24,
+ KEY_LEFT = 0x25,
+ KEY_UP = 0x26,
+ KEY_RIGHT = 0x27,
+ KEY_DOWN = 0x28,
+ 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,
+ K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 KEY_RCONTROL = 0xA3
+ };
+
+ // 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,
+ KEY_COMMAND_LEFT = 2,
+ KEY_COMMAND_RIGHT = 3,
+ KEY_COMMAND_HOME = 4,
+ KEY_COMMAND_END = 5,
+ KEY_COMMAND_BACKSPACE = 6,
+ KEY_COMMAND_TAB = 7,
+ KEY_COMMAND_INSERT = 8,
+ KEY_COMMAND_DELETE = 9
+ };
+
+ /// --------------------------------------------------------------
+ /// THESE METHODS MUST BE IMPLEMENTED BY THE INPUT ENGINE
+ /// --------------------------------------------------------------
+
+ /**
+ * Initialises the input engine
+ * @return Returns a true on success, otherwise false.
+ */
+ bool Init();
+
+ /**
+ * 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.
+ */
+ void Update();
+
+ /**
+ * Returns true if the left mouse button is pressed
+ */
+ bool IsLeftMouseDown();
+
+ /**
+ * Returns true if the right mouse button is pressed.
+ */
+ bool IsRightMouseDown();
+
+ /**
+ * Returns true if the left mouse button was pressed and released.
+ *
+ * The difference between this and IsLeftMouseDown() is that this only returns
+ * true when the left mouse button is released.
+ */
+ bool WasLeftMouseDown();
+
+ /**
+ * Returns true if the right mouse button was pressed and released.
+ *
+ * The difference between this and IsRightMouseDown() is that this only returns
+ * true when the right mouse button is released.
+ */
+ bool WasRightMouseDown();
+
+ /**
+ * Returns true if the left mouse button double click was done
+ */
+ bool IsLeftDoubleClick();
+
+ /**
+ * Returns the X position of the cursor in pixels
+ */
+ int GetMouseX();
+
+ /**
+ * Returns the Y position of the cursor in pixels
+ */
+ int GetMouseY();
+
+ /**
+ * Sets the X position of the cursor in pixels
+ */
+ void SetMouseX(int PosX);
+
+ /**
+ * Sets the Y position of the cursor in pixels
+ */
+ void SetMouseY(int PosY);
+
+ /**
+ * 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.
+ */
+ bool IsKeyDown(uint KeyCode);
+
+ /**
+ * Returns true if a certain key was pushed and released.
+ *
+ * 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
+ */
+ bool WasKeyDown(uint KeyCode);
+
+ typedef CallbackPtr CharacterCallback;
+
+ /**
+ * 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:
+ * 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.
+ */
+ bool RegisterCharacterCallback(CallbackPtr Callback);
+
+ /**
+ * De-registeres a previously registered callback function.
+ * @return Returns true if the function could be de-registered, otherwise false.
+ */
+ bool UnregisterCharacterCallback(CallbackPtr Callback);
+
+ typedef CallbackPtr CommandCallback;
+
+ /**
+ * 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:
+ * 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.
+ */
+ bool RegisterCommandCallback(CallbackPtr Callback);
+
+ /**
+ * 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.
+ */
+ bool UnregisterCommandCallback(CommandCallback Callback);
+
+ void ReportCharacter(byte Character);
+ void ReportCommand(KEY_COMMANDS Command);
+
+ bool persist(OutputPersistenceBlock &writer);
+ bool unpersist(InputPersistenceBlock &reader);
+
+private:
+ bool registerScriptBindings();
+
+private:
+ void TestForLeftDoubleClick();
+ void AlterKeyboardState(int keycode, byte newState);
+
+ byte m_KeyboardState[2][256];
+ bool m_LeftMouseState[2];
+ bool m_RightMouseState[2];
+ uint m_CurrentState;
+ int m_MouseX;
+ int m_MouseY;
+ bool m_LeftMouseDown;
+ bool m_RightMouseDown;
+ bool m_LeftDoubleClick;
+ uint m_DoubleClickTime;
+ int m_DoubleClickRectWidth;
+ int m_DoubleClickRectHeight;
+ uint m_LastLeftClickTime;
+ int m_LastLeftClickMouseX;
+ int m_LastLeftClickMouseY;
+ Common::List<CommandCallback> m_CommandCallbacks;
+ Common::List<CharacterCallback> m_CharacterCallbacks;
+};
+
+} // End of namespace Sword25
+
+#endif