2010-07-31 06:23:38 +00:00
|
|
|
/* 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$
|
|
|
|
*
|
2010-07-31 09:53:02 +00:00
|
|
|
*/
|
|
|
|
|
2010-08-06 13:13:25 +00:00
|
|
|
/*
|
2010-07-31 09:53:02 +00:00
|
|
|
* This code is based on Broken Sword 2.5 engine
|
|
|
|
*
|
|
|
|
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
|
|
|
*
|
|
|
|
* Licensed under GNU GPL v2
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2010-07-31 06:23:38 +00:00
|
|
|
* 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
|
|
|
|
*/
|
2010-07-29 19:53:02 +00:00
|
|
|
|
2010-07-29 19:55:28 +00:00
|
|
|
#ifndef SWORD25_INPUTENGINE_H
|
|
|
|
#define SWORD25_INPUTENGINE_H
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
/// Includes
|
2010-07-29 19:55:28 +00:00
|
|
|
#include "sword25/kernel/common.h"
|
|
|
|
#include "sword25/kernel/service.h"
|
|
|
|
#include "sword25/kernel/persistable.h"
|
2010-08-05 10:16:21 +00:00
|
|
|
#include "sword25/kernel/callbackregistry.h"
|
2010-07-29 19:53:02 +00:00
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
namespace Sword25 {
|
|
|
|
|
|
|
|
/// Class definitions
|
|
|
|
|
2010-08-18 12:58:22 +00:00
|
|
|
class InputEngine : public Service, public Persistable {
|
2010-07-29 19:53:02 +00:00
|
|
|
public:
|
2010-08-18 12:58:22 +00:00
|
|
|
InputEngine(Kernel *pKernel);
|
2010-10-13 20:04:50 +00:00
|
|
|
~InputEngine() {}
|
2010-07-29 19:53:02 +00:00
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
// NOTE: These codes are registered in inputengine_script.cpp
|
|
|
|
// Any changes to these enums must also adjust the above file.
|
2010-08-06 13:13:25 +00:00
|
|
|
enum KEY_CODES {
|
|
|
|
KEY_BACKSPACE = 0x08,
|
|
|
|
KEY_TAB = 0x09,
|
|
|
|
KEY_CLEAR = 0x0C,
|
2010-07-29 19:53:02 +00:00
|
|
|
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,
|
2010-08-06 13:13:25 +00:00
|
|
|
KEY_PRINTSC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EY_NUMPAD6 = 0x66,
|
|
|
|
KEY_NUMPAD7 = 0x67,
|
|
|
|
KEY_NUMPAD8 = 0x68,
|
|
|
|
KEY_NUMPAD9 = 0x69,
|
|
|
|
KEY_MULTIPLY = 0x6A,
|
|
|
|
KEY_ADD = 0x6B,
|
|
|
|
KEY_SEPARATOR = 0x6C,
|
|
|
|
KEY_SUBTRACT = 0x6D,
|
|
|
|
KEY_DECIMAL = 0x6E,
|
|
|
|
KEY_DIVIDE = 0x6F,
|
|
|
|
KEY_F1 = 0x70,
|
|
|
|
KEY_F2 = 0x71,
|
|
|
|
KEY_F3 = 0x72,
|
|
|
|
KEY_F4 = 0x73,
|
|
|
|
KEY_F5 = 0x74,
|
|
|
|
KEY_F6 = 0x75,
|
|
|
|
KEY_F7 = 0x76,
|
|
|
|
KEY_F8 = 0x77,
|
|
|
|
KEY_F9 = 0x78,
|
|
|
|
KEY_F10 = 0x79,
|
|
|
|
KEY_F11 = 0x7A,
|
|
|
|
KEY_F12 = 0x7B,
|
|
|
|
KEY_NUMLOCK = 0x90,
|
|
|
|
KEY_SCROLL = 0x91,
|
|
|
|
KEY_LSHIFT = 0xA0,
|
|
|
|
KEY_RSHIFT = 0xA1,
|
|
|
|
KEY_LCONTROL = 0xA2,
|
2010-07-30 12:19:13 +00:00
|
|
|
KEY_RCONTROL = 0xA3
|
2010-07-29 19:53:02 +00:00
|
|
|
};
|
|
|
|
|
2010-08-06 13:13:25 +00:00
|
|
|
// NOTE: These codes are registered in inputengine_script.cpp.
|
2010-07-31 06:23:38 +00:00
|
|
|
// Any changes to these enums must also adjust the above file.
|
|
|
|
enum KEY_COMMANDS {
|
2010-07-29 19:53:02 +00:00
|
|
|
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,
|
2010-07-30 12:19:13 +00:00
|
|
|
KEY_COMMAND_DELETE = 9
|
2010-07-29 19:53:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// --------------------------------------------------------------
|
2010-07-31 06:23:38 +00:00
|
|
|
/// THESE METHODS MUST BE IMPLEMENTED BY THE INPUT ENGINE
|
2010-07-29 19:53:02 +00:00
|
|
|
/// --------------------------------------------------------------
|
2010-08-06 13:13:25 +00:00
|
|
|
|
2010-07-29 19:53:02 +00:00
|
|
|
/**
|
2010-07-31 06:23:38 +00:00
|
|
|
* Initialises the input engine
|
2010-08-06 13:13:25 +00:00
|
|
|
* @return Returns a true on success, otherwise false.
|
2010-07-31 06:23:38 +00:00
|
|
|
*/
|
2010-09-14 19:37:21 +00:00
|
|
|
bool Init();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-31 06:23:38 +00:00
|
|
|
* Performs a "tick" of the input engine.
|
2010-08-06 13:13:25 +00:00
|
|
|
*
|
2010-07-31 06:23:38 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
2010-09-14 19:37:21 +00:00
|
|
|
void Update();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-31 06:23:38 +00:00
|
|
|
* Returns true if the left mouse button is pressed
|
|
|
|
*/
|
2010-09-14 19:37:21 +00:00
|
|
|
bool IsLeftMouseDown();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-31 06:23:38 +00:00
|
|
|
* Returns true if the right mouse button is pressed.
|
2010-07-29 19:53:02 +00:00
|
|
|
*/
|
2010-09-14 19:37:21 +00:00
|
|
|
bool IsRightMouseDown();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-31 06:23:38 +00:00
|
|
|
* 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.
|
2010-07-29 19:53:02 +00:00
|
|
|
*/
|
2010-09-14 19:37:21 +00:00
|
|
|
bool WasLeftMouseDown();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-31 06:23:38 +00:00
|
|
|
* 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.
|
2010-07-29 19:53:02 +00:00
|
|
|
*/
|
2010-09-14 19:37:21 +00:00
|
|
|
bool WasRightMouseDown();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-31 06:23:38 +00:00
|
|
|
* Returns true if the left mouse button double click was done
|
|
|
|
*/
|
2010-09-14 19:37:21 +00:00
|
|
|
bool IsLeftDoubleClick();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-31 06:23:38 +00:00
|
|
|
* Returns the X position of the cursor in pixels
|
2010-07-29 19:53:02 +00:00
|
|
|
*/
|
2010-09-14 19:37:21 +00:00
|
|
|
int GetMouseX();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-31 06:23:38 +00:00
|
|
|
* Returns the Y position of the cursor in pixels
|
|
|
|
*/
|
2010-09-14 19:37:21 +00:00
|
|
|
int GetMouseY();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-31 06:23:38 +00:00
|
|
|
* Sets the X position of the cursor in pixels
|
|
|
|
*/
|
2010-09-14 19:37:21 +00:00
|
|
|
void SetMouseX(int PosX);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-31 06:23:38 +00:00
|
|
|
* Sets the Y position of the cursor in pixels
|
|
|
|
*/
|
2010-09-14 19:37:21 +00:00
|
|
|
void SetMouseY(int PosY);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-31 06:23:38 +00:00
|
|
|
* Returns true if a given key was pressed
|
2010-08-06 13:13:25 +00:00
|
|
|
* @param KeyCode The key code to be checked
|
|
|
|
* @return Returns true if the given key is done, otherwise false.
|
2010-07-31 06:23:38 +00:00
|
|
|
*/
|
2010-09-14 19:37:21 +00:00
|
|
|
bool IsKeyDown(uint KeyCode);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-31 06:23:38 +00:00
|
|
|
* 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.
|
2010-08-06 13:13:25 +00:00
|
|
|
* @param KeyCode The key code to be checked
|
2010-07-31 06:23:38 +00:00
|
|
|
*/
|
2010-09-14 19:37:21 +00:00
|
|
|
bool WasKeyDown(uint KeyCode);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
2010-08-05 10:16:21 +00:00
|
|
|
typedef CallbackPtr CharacterCallback;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-31 06:23:38 +00:00
|
|
|
* Registers a callback function for keyboard input.
|
|
|
|
*
|
|
|
|
* The callbacks that are registered with this function will be called whenever an
|
2010-08-06 13:13:25 +00:00
|
|
|
* 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:
|
2010-07-31 06:23:38 +00:00
|
|
|
* 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.
|
2010-08-06 13:13:25 +00:00
|
|
|
* @return Returns true if the function was registered, otherwise false.
|
2010-07-29 19:53:02 +00:00
|
|
|
*/
|
2010-09-14 19:37:21 +00:00
|
|
|
bool RegisterCharacterCallback(CallbackPtr Callback);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-31 06:23:38 +00:00
|
|
|
* De-registeres a previously registered callback function.
|
2010-08-06 13:13:25 +00:00
|
|
|
* @return Returns true if the function could be de-registered, otherwise false.
|
2010-07-31 06:23:38 +00:00
|
|
|
*/
|
2010-09-14 19:37:21 +00:00
|
|
|
bool UnregisterCharacterCallback(CallbackPtr Callback);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
2010-08-05 10:16:21 +00:00
|
|
|
typedef CallbackPtr CommandCallback;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-31 06:23:38 +00:00
|
|
|
* Registers a callback function for the input of commands that can have influence on the string input
|
|
|
|
*
|
2010-08-06 13:13:25 +00:00
|
|
|
* 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:
|
2010-07-31 06:23:38 +00:00
|
|
|
* Enter, End, Left, Right, ...
|
|
|
|
* The input of strings by the user through the use of callbacks should be implemented.
|
2010-08-06 13:13:25 +00:00
|
|
|
* @return Returns true if the function was registered, otherwise false.
|
2010-07-31 06:23:38 +00:00
|
|
|
*/
|
2010-09-14 19:37:21 +00:00
|
|
|
bool RegisterCommandCallback(CallbackPtr Callback);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-31 06:23:38 +00:00
|
|
|
* Un-register a callback function for the input of commands that can have an influence on the string input.
|
2010-08-06 13:13:25 +00:00
|
|
|
* @return Returns true if the function could be de-registered, otherwise false.
|
2010-07-31 06:23:38 +00:00
|
|
|
*/
|
2010-09-14 19:37:21 +00:00
|
|
|
bool UnregisterCommandCallback(CommandCallback Callback);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
2010-09-14 19:37:21 +00:00
|
|
|
void ReportCharacter(byte Character);
|
|
|
|
void ReportCommand(KEY_COMMANDS Command);
|
|
|
|
|
|
|
|
bool persist(OutputPersistenceBlock &writer);
|
|
|
|
bool unpersist(InputPersistenceBlock &reader);
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool registerScriptBindings();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
private:
|
2010-09-14 19:37:21 +00:00
|
|
|
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;
|
2010-07-29 19:53:02 +00:00
|
|
|
};
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
} // End of namespace Sword25
|
|
|
|
|
2010-07-29 19:53:02 +00:00
|
|
|
#endif
|