Initial commit
This commit is contained in:
126
engines/hpl1/engine/input/Action.cpp
Normal file
126
engines/hpl1/engine/input/Action.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/input/Action.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iAction::iAction(tString asName) {
|
||||
msName = asName;
|
||||
|
||||
mbBecameTriggerd = false;
|
||||
mbIsTriggerd = false;
|
||||
|
||||
mfTimeCount = -1.0;
|
||||
|
||||
mbTriggerDown = false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool iAction::WasTriggerd() {
|
||||
if (mbBecameTriggerd && !IsTriggerd()) {
|
||||
mbBecameTriggerd = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool iAction::BecameTriggerd() {
|
||||
if (!mbIsTriggerd && IsTriggerd()) {
|
||||
mbIsTriggerd = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool iAction::DoubleTriggerd(float afLimit) {
|
||||
if (!mbTriggerDown && IsTriggerd()) {
|
||||
mbTriggerDown = true;
|
||||
|
||||
if (mfTimeCount < 0 || mfTimeCount > afLimit) {
|
||||
mfTimeCount = 0;
|
||||
return false;
|
||||
} else {
|
||||
mfTimeCount = 0;
|
||||
mbIsTriggerd = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iAction::Update(float afTimeStep) {
|
||||
UpdateLogic(afTimeStep);
|
||||
|
||||
if (!IsTriggerd()) {
|
||||
mbIsTriggerd = false;
|
||||
mbTriggerDown = false;
|
||||
|
||||
if (mfTimeCount >= 0)
|
||||
mfTimeCount += afTimeStep;
|
||||
} else {
|
||||
mbBecameTriggerd = true;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iAction::UpdateLogic(float afTimeStep) {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tString iAction::GetName() {
|
||||
return msName;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
109
engines/hpl1/engine/input/Action.h
Normal file
109
engines/hpl1/engine/input/Action.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_ACTION_H
|
||||
#define HPL_ACTION_H
|
||||
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class iAction {
|
||||
public:
|
||||
iAction(tString asName);
|
||||
virtual ~iAction() {}
|
||||
|
||||
/**
|
||||
*
|
||||
* \return returns true if the action just was triggered, else false
|
||||
*/
|
||||
bool WasTriggerd();
|
||||
|
||||
/**
|
||||
*
|
||||
* \return true if the action just became triggered, else false
|
||||
*/
|
||||
bool BecameTriggerd();
|
||||
|
||||
/**
|
||||
*
|
||||
* \return true if the action just was double triggered (double clicked), else false
|
||||
*/
|
||||
bool DoubleTriggerd(float afLimit);
|
||||
|
||||
/**
|
||||
*Update the Action, called by cInput
|
||||
*/
|
||||
void Update(float afTimeStep);
|
||||
|
||||
/**
|
||||
*
|
||||
* \return the name of the action.
|
||||
*/
|
||||
tString GetName();
|
||||
|
||||
/**
|
||||
* Update special logic for the action. Normally empty
|
||||
*/
|
||||
virtual void UpdateLogic(float afTimeStep);
|
||||
|
||||
/**
|
||||
* Filled in by the class that inherits from Action.
|
||||
* \return true if the action is being triggered
|
||||
*/
|
||||
virtual bool IsTriggerd() = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* \return A value from the input, ie the relative mouse x position.
|
||||
*/
|
||||
virtual float GetValue() = 0;
|
||||
|
||||
/**
|
||||
* The name of the input, ie for keyboard the name of the key is returned.
|
||||
*/
|
||||
virtual tString GetInputName() = 0;
|
||||
|
||||
/**
|
||||
* The name of the input type.
|
||||
*/
|
||||
virtual tString GetInputType() = 0;
|
||||
|
||||
private:
|
||||
tString msName;
|
||||
|
||||
bool mbBecameTriggerd;
|
||||
bool mbIsTriggerd;
|
||||
|
||||
bool mbTriggerDown;
|
||||
|
||||
double mfTimeCount;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_ACTION_H
|
||||
485
engines/hpl1/engine/input/ActionKeyboard.cpp
Normal file
485
engines/hpl1/engine/input/ActionKeyboard.cpp
Normal file
@@ -0,0 +1,485 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/input/ActionKeyboard.h"
|
||||
#include "hpl1/engine/input/Input.h"
|
||||
#include "hpl1/engine/input/Keyboard.h"
|
||||
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
namespace hpl {
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cActionKeyboard::IsTriggerd() {
|
||||
return mpInput->GetKeyboard()->KeyIsDown(_key.keycode) &&
|
||||
((mpInput->GetKeyboard()->GetModifier() & _key.flags) > 0 || _key.flags == 0);
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
float cActionKeyboard::GetValue() {
|
||||
if (IsTriggerd())
|
||||
return 1.0;
|
||||
else
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tString cActionKeyboard::GetInputName() {
|
||||
tString tsKey = "";
|
||||
if (_key.flags & Common::KBD_SHIFT) {
|
||||
tsKey += "Shift ";
|
||||
}
|
||||
if (_key.flags & Common::KBD_ALT) {
|
||||
tsKey += "Alt ";
|
||||
}
|
||||
if (_key.flags & Common::KBD_CTRL) {
|
||||
tsKey += "Control ";
|
||||
}
|
||||
if (_key.flags & Common::KBD_META) {
|
||||
#ifdef __APPLE__
|
||||
tsKey += "Command ";
|
||||
#else
|
||||
tsKey += "Windows ";
|
||||
#endif
|
||||
}
|
||||
|
||||
switch (_key.keycode) {
|
||||
case Common::KEYCODE_BACKSPACE:
|
||||
tsKey += "BackSpace";
|
||||
break;
|
||||
case Common::KEYCODE_TAB:
|
||||
tsKey += "Tab";
|
||||
break;
|
||||
case Common::KEYCODE_CLEAR:
|
||||
tsKey += "Clear";
|
||||
break;
|
||||
case Common::KEYCODE_RETURN:
|
||||
tsKey += "Return";
|
||||
break;
|
||||
case Common::KEYCODE_PAUSE:
|
||||
tsKey += "Pause";
|
||||
break;
|
||||
case Common::KEYCODE_ESCAPE:
|
||||
tsKey += "Escape";
|
||||
break;
|
||||
case Common::KEYCODE_SPACE:
|
||||
tsKey += "Space";
|
||||
break;
|
||||
case Common::KEYCODE_EXCLAIM:
|
||||
tsKey += "Exclaim";
|
||||
break;
|
||||
case Common::KEYCODE_QUOTEDBL:
|
||||
tsKey += "DblQoute";
|
||||
break;
|
||||
case Common::KEYCODE_HASH:
|
||||
tsKey += "Hash";
|
||||
break;
|
||||
case Common::KEYCODE_DOLLAR:
|
||||
tsKey += "Dollar";
|
||||
break;
|
||||
case Common::KEYCODE_AMPERSAND:
|
||||
tsKey += "Ampersand";
|
||||
break;
|
||||
case Common::KEYCODE_QUOTE:
|
||||
tsKey += "Quote";
|
||||
break;
|
||||
case Common::KEYCODE_LEFTPAREN:
|
||||
tsKey += "LeftParent";
|
||||
break;
|
||||
case Common::KEYCODE_RIGHTPAREN:
|
||||
tsKey += "RightParent";
|
||||
break;
|
||||
case Common::KEYCODE_ASTERISK:
|
||||
tsKey += "Asterisk";
|
||||
break;
|
||||
case Common::KEYCODE_PLUS:
|
||||
tsKey += "Plus";
|
||||
break;
|
||||
case Common::KEYCODE_COMMA:
|
||||
tsKey += "Comma";
|
||||
break;
|
||||
case Common::KEYCODE_MINUS:
|
||||
tsKey += "Minus";
|
||||
break;
|
||||
case Common::KEYCODE_PERIOD:
|
||||
tsKey += "Period";
|
||||
break;
|
||||
case Common::KEYCODE_SLASH:
|
||||
tsKey += "Slash";
|
||||
break;
|
||||
case Common::KEYCODE_0:
|
||||
tsKey += "0";
|
||||
break;
|
||||
case Common::KEYCODE_1:
|
||||
tsKey += "1";
|
||||
break;
|
||||
case Common::KEYCODE_2:
|
||||
tsKey += "2";
|
||||
break;
|
||||
case Common::KEYCODE_3:
|
||||
tsKey += "3";
|
||||
break;
|
||||
case Common::KEYCODE_4:
|
||||
tsKey += "4";
|
||||
break;
|
||||
case Common::KEYCODE_5:
|
||||
tsKey += "5";
|
||||
break;
|
||||
case Common::KEYCODE_6:
|
||||
tsKey += "6";
|
||||
break;
|
||||
case Common::KEYCODE_7:
|
||||
tsKey += "7";
|
||||
break;
|
||||
case Common::KEYCODE_8:
|
||||
tsKey += "8";
|
||||
break;
|
||||
case Common::KEYCODE_9:
|
||||
tsKey += "9";
|
||||
break;
|
||||
case Common::KEYCODE_COLON:
|
||||
tsKey += "Colon";
|
||||
break;
|
||||
case Common::KEYCODE_SEMICOLON:
|
||||
tsKey += "SemiColon";
|
||||
break;
|
||||
case Common::KEYCODE_LESS:
|
||||
tsKey += "Less";
|
||||
break;
|
||||
case Common::KEYCODE_EQUALS:
|
||||
tsKey += "Equals";
|
||||
break;
|
||||
case Common::KEYCODE_GREATER:
|
||||
tsKey += "Greater";
|
||||
break;
|
||||
case Common::KEYCODE_QUESTION:
|
||||
tsKey += "Question";
|
||||
break;
|
||||
case Common::KEYCODE_AT:
|
||||
tsKey += "At";
|
||||
break;
|
||||
case Common::KEYCODE_LEFTBRACKET:
|
||||
tsKey += "LeftBracket";
|
||||
break;
|
||||
case Common::KEYCODE_BACKSLASH:
|
||||
tsKey += "BackSlash";
|
||||
break;
|
||||
case Common::KEYCODE_RIGHTBRACKET:
|
||||
tsKey += "RightBracket";
|
||||
break;
|
||||
case Common::KEYCODE_CARET:
|
||||
tsKey += "Caret";
|
||||
break;
|
||||
case Common::KEYCODE_UNDERSCORE:
|
||||
tsKey += "Underscore";
|
||||
break;
|
||||
case Common::KEYCODE_BACKQUOTE:
|
||||
tsKey += "BackQuote";
|
||||
break;
|
||||
case Common::KEYCODE_a:
|
||||
tsKey += "A";
|
||||
break;
|
||||
case Common::KEYCODE_b:
|
||||
tsKey += "B";
|
||||
break;
|
||||
case Common::KEYCODE_c:
|
||||
tsKey += "C";
|
||||
break;
|
||||
case Common::KEYCODE_d:
|
||||
tsKey += "D";
|
||||
break;
|
||||
case Common::KEYCODE_e:
|
||||
tsKey += "E";
|
||||
break;
|
||||
case Common::KEYCODE_f:
|
||||
tsKey += "F";
|
||||
break;
|
||||
case Common::KEYCODE_g:
|
||||
tsKey += "G";
|
||||
break;
|
||||
case Common::KEYCODE_h:
|
||||
tsKey += "H";
|
||||
break;
|
||||
case Common::KEYCODE_i:
|
||||
tsKey += "I";
|
||||
break;
|
||||
case Common::KEYCODE_j:
|
||||
tsKey += "J";
|
||||
break;
|
||||
case Common::KEYCODE_k:
|
||||
tsKey += "K";
|
||||
break;
|
||||
case Common::KEYCODE_l:
|
||||
tsKey += "L";
|
||||
break;
|
||||
case Common::KEYCODE_m:
|
||||
tsKey += "M";
|
||||
break;
|
||||
case Common::KEYCODE_n:
|
||||
tsKey += "N";
|
||||
break;
|
||||
case Common::KEYCODE_o:
|
||||
tsKey += "O";
|
||||
break;
|
||||
case Common::KEYCODE_p:
|
||||
tsKey += "P";
|
||||
break;
|
||||
case Common::KEYCODE_q:
|
||||
tsKey += "Q";
|
||||
break;
|
||||
case Common::KEYCODE_r:
|
||||
tsKey += "R";
|
||||
break;
|
||||
case Common::KEYCODE_s:
|
||||
tsKey += "S";
|
||||
break;
|
||||
case Common::KEYCODE_t:
|
||||
tsKey += "T";
|
||||
break;
|
||||
case Common::KEYCODE_u:
|
||||
tsKey += "U";
|
||||
break;
|
||||
case Common::KEYCODE_v:
|
||||
tsKey += "V";
|
||||
break;
|
||||
case Common::KEYCODE_w:
|
||||
tsKey += "W";
|
||||
break;
|
||||
case Common::KEYCODE_x:
|
||||
tsKey += "X";
|
||||
break;
|
||||
case Common::KEYCODE_y:
|
||||
tsKey += "Y";
|
||||
break;
|
||||
case Common::KEYCODE_z:
|
||||
tsKey += "Z";
|
||||
break;
|
||||
case Common::KEYCODE_DELETE:
|
||||
tsKey += "Delete";
|
||||
break;
|
||||
case Common::KEYCODE_KP0:
|
||||
tsKey += "Kp0";
|
||||
break;
|
||||
case Common::KEYCODE_KP1:
|
||||
tsKey += "Kp1";
|
||||
break;
|
||||
case Common::KEYCODE_KP2:
|
||||
tsKey += "Kp2";
|
||||
break;
|
||||
case Common::KEYCODE_KP3:
|
||||
tsKey += "Kp3";
|
||||
break;
|
||||
case Common::KEYCODE_KP4:
|
||||
tsKey += "Kp4";
|
||||
break;
|
||||
case Common::KEYCODE_KP5:
|
||||
tsKey += "Kp5";
|
||||
break;
|
||||
case Common::KEYCODE_KP6:
|
||||
tsKey += "Kp6";
|
||||
break;
|
||||
case Common::KEYCODE_KP7:
|
||||
tsKey += "Kp7";
|
||||
break;
|
||||
case Common::KEYCODE_KP8:
|
||||
tsKey += "Kp8";
|
||||
break;
|
||||
case Common::KEYCODE_KP9:
|
||||
tsKey += "Kp9";
|
||||
break;
|
||||
case Common::KEYCODE_KP_PERIOD:
|
||||
tsKey += "Period";
|
||||
break;
|
||||
case Common::KEYCODE_KP_DIVIDE:
|
||||
tsKey += "Divide";
|
||||
break;
|
||||
case Common::KEYCODE_KP_MULTIPLY:
|
||||
tsKey += "Multiply";
|
||||
break;
|
||||
case Common::KEYCODE_KP_MINUS:
|
||||
tsKey += "Minus";
|
||||
break;
|
||||
case Common::KEYCODE_KP_PLUS:
|
||||
tsKey += "Plus";
|
||||
break;
|
||||
case Common::KEYCODE_KP_ENTER:
|
||||
tsKey += "Enter";
|
||||
break;
|
||||
case Common::KEYCODE_KP_EQUALS:
|
||||
tsKey += "Equals";
|
||||
break;
|
||||
case Common::KEYCODE_UP:
|
||||
tsKey += "Up";
|
||||
break;
|
||||
case Common::KEYCODE_DOWN:
|
||||
tsKey += "Down";
|
||||
break;
|
||||
case Common::KEYCODE_RIGHT:
|
||||
tsKey += "Right";
|
||||
break;
|
||||
case Common::KEYCODE_LEFT:
|
||||
tsKey += "Left";
|
||||
break;
|
||||
case Common::KEYCODE_INSERT:
|
||||
tsKey += "Insert";
|
||||
break;
|
||||
case Common::KEYCODE_HOME:
|
||||
tsKey += "Home";
|
||||
break;
|
||||
case Common::KEYCODE_END:
|
||||
tsKey += "End";
|
||||
break;
|
||||
case Common::KEYCODE_PAGEUP:
|
||||
tsKey += "PageUp";
|
||||
break;
|
||||
case Common::KEYCODE_PAGEDOWN:
|
||||
tsKey += "PageDown";
|
||||
break;
|
||||
case Common::KEYCODE_F1:
|
||||
tsKey += "F1";
|
||||
break;
|
||||
case Common::KEYCODE_F2:
|
||||
tsKey += "F2";
|
||||
break;
|
||||
case Common::KEYCODE_F3:
|
||||
tsKey += "F3";
|
||||
break;
|
||||
case Common::KEYCODE_F4:
|
||||
tsKey += "F4";
|
||||
break;
|
||||
case Common::KEYCODE_F5:
|
||||
tsKey += "F5";
|
||||
break;
|
||||
case Common::KEYCODE_F6:
|
||||
tsKey += "F6";
|
||||
break;
|
||||
case Common::KEYCODE_F7:
|
||||
tsKey += "F7";
|
||||
break;
|
||||
case Common::KEYCODE_F8:
|
||||
tsKey += "F8";
|
||||
break;
|
||||
case Common::KEYCODE_F9:
|
||||
tsKey += "F9";
|
||||
break;
|
||||
case Common::KEYCODE_F10:
|
||||
tsKey += "F10";
|
||||
break;
|
||||
case Common::KEYCODE_F11:
|
||||
tsKey += "F11";
|
||||
break;
|
||||
case Common::KEYCODE_F12:
|
||||
tsKey += "F12";
|
||||
break;
|
||||
case Common::KEYCODE_F13:
|
||||
tsKey += "F13";
|
||||
break;
|
||||
case Common::KEYCODE_F14:
|
||||
tsKey += "F14";
|
||||
break;
|
||||
case Common::KEYCODE_F15:
|
||||
tsKey += "F15";
|
||||
break;
|
||||
case Common::KEYCODE_NUMLOCK:
|
||||
tsKey += "NumLock";
|
||||
break;
|
||||
case Common::KEYCODE_CAPSLOCK:
|
||||
tsKey += "CapsLock";
|
||||
break;
|
||||
case Common::KEYCODE_SCROLLOCK:
|
||||
tsKey += "ScrollLock";
|
||||
break;
|
||||
case Common::KEYCODE_RSHIFT:
|
||||
tsKey += "RightShift";
|
||||
break;
|
||||
case Common::KEYCODE_LSHIFT:
|
||||
tsKey += "LeftShift";
|
||||
break;
|
||||
case Common::KEYCODE_RCTRL:
|
||||
tsKey += "RightControl";
|
||||
break;
|
||||
case Common::KEYCODE_LCTRL:
|
||||
tsKey += "LeftControl";
|
||||
break;
|
||||
case Common::KEYCODE_RALT:
|
||||
tsKey += "RightAlt";
|
||||
break;
|
||||
case Common::KEYCODE_LALT:
|
||||
tsKey += "LeftAlt";
|
||||
break;
|
||||
case Common::KEYCODE_RMETA:
|
||||
tsKey += "RightMeta";
|
||||
break;
|
||||
case Common::KEYCODE_LMETA:
|
||||
tsKey += "LeftMeta";
|
||||
break;
|
||||
case Common::KEYCODE_LSUPER:
|
||||
tsKey += "LeftSuper";
|
||||
break;
|
||||
case Common::KEYCODE_RSUPER:
|
||||
tsKey += "RightSuper";
|
||||
break;
|
||||
case Common::KEYCODE_MODE:
|
||||
tsKey += "Mode";
|
||||
break;
|
||||
case Common::KEYCODE_HELP:
|
||||
tsKey += "Help";
|
||||
break;
|
||||
case Common::KEYCODE_PRINT:
|
||||
tsKey += "Print";
|
||||
break;
|
||||
case Common::KEYCODE_SYSREQ:
|
||||
tsKey += "SysReq";
|
||||
break;
|
||||
case Common::KEYCODE_BREAK:
|
||||
tsKey += "Break";
|
||||
break;
|
||||
case Common::KEYCODE_MENU:
|
||||
tsKey += "Menu";
|
||||
break;
|
||||
case Common::KEYCODE_POWER:
|
||||
tsKey += "Power";
|
||||
break;
|
||||
case Common::KEYCODE_EURO:
|
||||
tsKey += "Euro";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (tsKey != "") {
|
||||
return tsKey;
|
||||
} else {
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
60
engines/hpl1/engine/input/ActionKeyboard.h
Normal file
60
engines/hpl1/engine/input/ActionKeyboard.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_ACTIONKEYBOARD_H
|
||||
#define HPL_ACTIONKEYBOARD_H
|
||||
|
||||
#include "common/keyboard.h"
|
||||
#include "hpl1/engine/input/Action.h"
|
||||
#include "hpl1/engine/input/InputTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cInput;
|
||||
|
||||
class cActionKeyboard : public iAction {
|
||||
public:
|
||||
cActionKeyboard(tString asName, cInput *apInput, Common::KeyState key) : iAction(asName), _key(key), mpInput(apInput) {}
|
||||
|
||||
bool IsTriggerd();
|
||||
float GetValue();
|
||||
|
||||
tString GetInputName();
|
||||
|
||||
tString GetInputType() { return "Keyboard"; }
|
||||
|
||||
Common::KeyCode GetKey() { return _key.keycode; }
|
||||
int GetModifier() { return _key.flags; }
|
||||
|
||||
private:
|
||||
Common::KeyState _key;
|
||||
cInput *mpInput;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_ACTIONKEYBOARD_H
|
||||
94
engines/hpl1/engine/input/ActionMouseButton.cpp
Normal file
94
engines/hpl1/engine/input/ActionMouseButton.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/input/ActionMouseButton.h"
|
||||
#include "hpl1/engine/input/Input.h"
|
||||
#include "hpl1/engine/input/Mouse.h"
|
||||
|
||||
namespace hpl {
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cActionMouseButton::cActionMouseButton(tString asName, cInput *apInput, eMButton aButton) : iAction(asName) {
|
||||
mButton = aButton;
|
||||
mpInput = apInput;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cActionMouseButton::IsTriggerd() {
|
||||
return mpInput->GetMouse()->ButtonIsDown(mButton);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
float cActionMouseButton::GetValue() {
|
||||
if (IsTriggerd())
|
||||
return 1.0;
|
||||
else
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tString cActionMouseButton::GetInputName() {
|
||||
switch (mButton) {
|
||||
case eMButton_Left:
|
||||
return "LeftMouse";
|
||||
case eMButton_Middle:
|
||||
return "MiddleMouse";
|
||||
case eMButton_Right:
|
||||
return "RightMouse";
|
||||
case eMButton_WheelUp:
|
||||
return "WheelUp";
|
||||
case eMButton_WheelDown:
|
||||
return "WheelDown";
|
||||
case eMButton_6:
|
||||
return "Mouse6";
|
||||
case eMButton_7:
|
||||
return "Mouse7";
|
||||
case eMButton_8:
|
||||
return "Mouse8";
|
||||
case eMButton_9:
|
||||
return "Mouse9";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
58
engines/hpl1/engine/input/ActionMouseButton.h
Normal file
58
engines/hpl1/engine/input/ActionMouseButton.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_ACTIONMOUSEBUTTON_H
|
||||
#define HPL_ACTIONMOUSEBUTTON_H
|
||||
|
||||
#include "hpl1/engine/input/Action.h"
|
||||
#include "hpl1/engine/input/InputTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cInput;
|
||||
|
||||
class cActionMouseButton : public iAction {
|
||||
public:
|
||||
cActionMouseButton(tString asName, cInput *apInput, eMButton mButton);
|
||||
|
||||
bool IsTriggerd();
|
||||
float GetValue();
|
||||
|
||||
tString GetInputName();
|
||||
|
||||
tString GetInputType() { return "MouseButton"; }
|
||||
|
||||
eMButton GetButton() { return mButton; }
|
||||
|
||||
private:
|
||||
eMButton mButton;
|
||||
cInput *mpInput;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_ACTIONMOUSEBUTTON_H
|
||||
233
engines/hpl1/engine/input/Input.cpp
Normal file
233
engines/hpl1/engine/input/Input.cpp
Normal file
@@ -0,0 +1,233 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/input/Action.h"
|
||||
#include "hpl1/engine/input/ActionKeyboard.h"
|
||||
#include "hpl1/engine/input/ActionMouseButton.h"
|
||||
#include "hpl1/engine/input/Input.h"
|
||||
#include "hpl1/engine/input/Keyboard.h"
|
||||
#include "hpl1/engine/input/LowLevelInput.h"
|
||||
#include "hpl1/engine/input/Mouse.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cInput::cInput(LowLevelInput *apLowLevelInput) : iUpdateable("HPL_Input") {
|
||||
mpLowLevelInput = apLowLevelInput;
|
||||
|
||||
mpKeyboard = mpLowLevelInput->CreateKeyboard();
|
||||
mpMouse = mpLowLevelInput->CreateMouse();
|
||||
|
||||
mlstInputDevices.push_back(mpMouse);
|
||||
mlstInputDevices.push_back(mpKeyboard);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cInput::~cInput() {
|
||||
Log("Exiting Input Module\n");
|
||||
Log("--------------------------------------------------------\n");
|
||||
|
||||
STLMapDeleteAll(m_mapActions);
|
||||
|
||||
if (mpKeyboard)
|
||||
hplDelete(mpKeyboard);
|
||||
if (mpMouse)
|
||||
hplDelete(mpMouse);
|
||||
|
||||
Log("--------------------------------------------------------\n\n");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cInput::Update(float afTimeStep) {
|
||||
mpLowLevelInput->BeginInputUpdate();
|
||||
|
||||
for (tInputDeviceListIt it = mlstInputDevices.begin(); it != mlstInputDevices.end(); ++it) {
|
||||
(*it)->Update();
|
||||
}
|
||||
|
||||
mpLowLevelInput->EndInputUpdate();
|
||||
|
||||
for (tActionMapIt it = m_mapActions.begin(); it != m_mapActions.end(); ++it) {
|
||||
it->second->Update(afTimeStep);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cInput::AddAction(iAction *apAction) {
|
||||
tString sName = apAction->GetName();
|
||||
tActionMap::value_type val = tActionMap::value_type(sName, apAction);
|
||||
m_mapActions.insert(val);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cInput::IsTriggerd(tString asName) {
|
||||
iAction *pAction = GetAction(asName);
|
||||
if (pAction == NULL) {
|
||||
return false;
|
||||
} // Log("doesn't exist!!!");return false;}
|
||||
|
||||
return pAction->IsTriggerd();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cInput::WasTriggerd(tString asName) {
|
||||
iAction *pAction = GetAction(asName);
|
||||
if (pAction == NULL)
|
||||
return false;
|
||||
|
||||
return pAction->WasTriggerd();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cInput::BecameTriggerd(tString asName) {
|
||||
iAction *pAction = GetAction(asName);
|
||||
if (pAction == NULL)
|
||||
return false;
|
||||
|
||||
return pAction->BecameTriggerd();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cInput::DoubleTriggerd(tString asName, float afLimit) {
|
||||
iAction *pAction = GetAction(asName);
|
||||
if (pAction == NULL)
|
||||
return false;
|
||||
|
||||
return pAction->DoubleTriggerd(afLimit);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
Keyboard *cInput::GetKeyboard() {
|
||||
return mpKeyboard;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
Mouse *cInput::GetMouse() {
|
||||
return mpMouse;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iAction *cInput::GetAction(tString asName) {
|
||||
tActionMapIt it = m_mapActions.find(asName);
|
||||
if (it == m_mapActions.end())
|
||||
return NULL;
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cInput::DestroyAction(tString asName) {
|
||||
iAction *pOldAction = GetAction(asName);
|
||||
if (pOldAction)
|
||||
hplDelete(pOldAction);
|
||||
m_mapActions.erase(asName);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cInput::CheckForInput() {
|
||||
//////////////////////
|
||||
// Keyboard
|
||||
for (int i = 0; i < Common::KEYCODE_LAST; ++i) {
|
||||
if (mpKeyboard->KeyIsDown(static_cast<Common::KeyCode>(i)))
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////
|
||||
// Mouse
|
||||
for (int i = 0; i < eMButton_LastEnum; ++i) {
|
||||
if (mpMouse->ButtonIsDown((eMButton)i))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iAction *cInput::InputToAction(const tString &asName) {
|
||||
iAction *pAction = NULL;
|
||||
|
||||
//////////////////////
|
||||
// Keyboard
|
||||
for (int i = 0; i < Common::KEYCODE_LAST; ++i) {
|
||||
Common::KeyCode key = static_cast<Common::KeyCode>(i);
|
||||
if (mpKeyboard->KeyIsDown(key)) {
|
||||
pAction = hplNew(cActionKeyboard, (asName, this, key));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////
|
||||
// Mouse
|
||||
if (pAction == NULL) {
|
||||
for (int i = 0; i < eMButton_LastEnum; ++i) {
|
||||
if (mpMouse->ButtonIsDown((eMButton)i)) {
|
||||
pAction = hplNew(cActionMouseButton, (asName, this, (eMButton)i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pAction) {
|
||||
iAction *pOldAction = GetAction(asName);
|
||||
if (pOldAction)
|
||||
hplDelete(pOldAction);
|
||||
|
||||
m_mapActions.erase(asName);
|
||||
|
||||
AddAction(pAction);
|
||||
}
|
||||
|
||||
return pAction;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
149
engines/hpl1/engine/input/Input.h
Normal file
149
engines/hpl1/engine/input/Input.h
Normal file
@@ -0,0 +1,149 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_INPUT_H
|
||||
#define HPL_INPUT_H
|
||||
|
||||
#include "common/list.h"
|
||||
#include "hpl1/engine/game/Updateable.h"
|
||||
#include "hpl1/engine/input/InputTypes.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
#include "common/stablemap.h"
|
||||
#include "common/multimap.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class Keyboard;
|
||||
class Mouse;
|
||||
class LowLevelInput;
|
||||
class iInputDevice;
|
||||
class iAction;
|
||||
|
||||
typedef Common::StableMap<tString, iAction *> tActionMap;
|
||||
typedef tActionMap::iterator tActionMapIt;
|
||||
|
||||
typedef Common::MultiMap<tString, iAction *> tActionMultiMap;
|
||||
typedef tActionMultiMap::iterator tActionMultiMapIt;
|
||||
|
||||
typedef Common::List<iInputDevice *> tInputDeviceList;
|
||||
typedef tInputDeviceList::iterator tInputDeviceListIt;
|
||||
|
||||
class cInput : public iUpdateable {
|
||||
public:
|
||||
cInput(LowLevelInput *apLowLevelInput);
|
||||
~cInput();
|
||||
|
||||
/**
|
||||
* Updates the input, called by cGame
|
||||
*/
|
||||
void Update(float afTimeStep);
|
||||
|
||||
/**
|
||||
* Add a new action.
|
||||
* \param *apAction The action to add.
|
||||
*/
|
||||
void AddAction(iAction *apAction);
|
||||
|
||||
/**
|
||||
* Check if an action is triggered.
|
||||
* \param asName
|
||||
* \return
|
||||
*/
|
||||
bool IsTriggerd(tString asName);
|
||||
/**
|
||||
*
|
||||
* \param asName name of the action.
|
||||
* \return
|
||||
*/
|
||||
bool WasTriggerd(tString asName);
|
||||
|
||||
/**
|
||||
*
|
||||
* \param asName name of the action.
|
||||
* \return
|
||||
*/
|
||||
bool BecameTriggerd(tString asName);
|
||||
|
||||
/**
|
||||
*
|
||||
* \param asName name of the action.
|
||||
* \return
|
||||
*/
|
||||
bool DoubleTriggerd(tString asName, float afLimit);
|
||||
|
||||
/**
|
||||
*
|
||||
* \return currently used keyboard
|
||||
*/
|
||||
Keyboard *GetKeyboard();
|
||||
|
||||
/**
|
||||
*
|
||||
* \return currently used mouse
|
||||
*/
|
||||
Mouse *GetMouse();
|
||||
|
||||
/**
|
||||
* Get action from map.
|
||||
* \param asName name of action.
|
||||
* \return Pointer to action, if not found NULL.
|
||||
*/
|
||||
iAction *GetAction(tString asName);
|
||||
|
||||
/**
|
||||
* Destroys an action if it exists.
|
||||
* \param asName
|
||||
*/
|
||||
void DestroyAction(tString asName);
|
||||
|
||||
/**
|
||||
* Checks if any input is given.
|
||||
* \return true if any input is given, else false.
|
||||
*/
|
||||
bool CheckForInput();
|
||||
|
||||
/**
|
||||
* Creates an action from the latest input made. Any action with the same name is destroyed.
|
||||
* \param &asName Name of action be be created.
|
||||
* \return NULL if no input was given.
|
||||
*/
|
||||
iAction *InputToAction(const tString &asName);
|
||||
|
||||
LowLevelInput *GetLowLevel() { return mpLowLevelInput; }
|
||||
|
||||
private:
|
||||
tActionMap m_mapActions;
|
||||
tInputDeviceList mlstInputDevices;
|
||||
|
||||
LowLevelInput *mpLowLevelInput;
|
||||
|
||||
Mouse *mpMouse;
|
||||
Keyboard *mpKeyboard;
|
||||
};
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_INPUT_H
|
||||
60
engines/hpl1/engine/input/InputDevice.cpp
Normal file
60
engines/hpl1/engine/input/InputDevice.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/input/InputDevice.h"
|
||||
|
||||
namespace hpl {
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iInputDevice::iInputDevice(tString asName, eInputDeviceType aType)
|
||||
: msName(asName), mType(aType) {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tString iInputDevice::GetName() {
|
||||
return msName;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
eInputDeviceType iInputDevice::GetType() {
|
||||
return mType;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
65
engines/hpl1/engine/input/InputDevice.h
Normal file
65
engines/hpl1/engine/input/InputDevice.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_INPUTDEVICE_H
|
||||
#define HPL_INPUTDEVICE_H
|
||||
|
||||
#include "hpl1/engine/input/InputTypes.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class iInputDevice {
|
||||
public:
|
||||
iInputDevice(tString asName, eInputDeviceType aType);
|
||||
virtual ~iInputDevice() {}
|
||||
|
||||
/**
|
||||
*
|
||||
* \return name of the device
|
||||
*/
|
||||
tString GetName();
|
||||
|
||||
/**
|
||||
*
|
||||
* \return type of device.
|
||||
*/
|
||||
eInputDeviceType GetType();
|
||||
|
||||
/**
|
||||
* Update the device, called by cInput
|
||||
*/
|
||||
virtual void Update() = 0;
|
||||
|
||||
private:
|
||||
tString msName;
|
||||
eInputDeviceType mType;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_INPUTDEVICE_H
|
||||
59
engines/hpl1/engine/input/InputTypes.h
Normal file
59
engines/hpl1/engine/input/InputTypes.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_INPUT_TYPES_H
|
||||
#define HPL_INPUT_TYPES_H
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//-------------------------------------------------
|
||||
|
||||
enum eInputDeviceType {
|
||||
eInputDeviceType_Keyboard,
|
||||
eInputDeviceType_Mouse,
|
||||
eInputDeviceType_Gamepad,
|
||||
eInputDeviceType_LastEnum
|
||||
};
|
||||
|
||||
//-------------------------------------------------
|
||||
|
||||
enum eMButton {
|
||||
eMButton_Left,
|
||||
eMButton_Middle,
|
||||
eMButton_Right,
|
||||
eMButton_WheelUp,
|
||||
eMButton_WheelDown,
|
||||
eMButton_6,
|
||||
eMButton_7,
|
||||
eMButton_8,
|
||||
eMButton_9,
|
||||
eMButton_LastEnum
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_INPUT_TYPES_H
|
||||
103
engines/hpl1/engine/input/Keyboard.cpp
Normal file
103
engines/hpl1/engine/input/Keyboard.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "common/events.h"
|
||||
#include "hpl1/debug.h"
|
||||
#include "hpl1/engine/input/Keyboard.h"
|
||||
#include "hpl1/engine/input/LowLevelInput.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
Keyboard::Keyboard(LowLevelInput *lowLevelInput) : iInputDevice("Keyboard", eInputDeviceType_Keyboard) {
|
||||
_lowLevelSystem = lowLevelInput;
|
||||
|
||||
_downKeys.set_size(Common::KEYCODE_LAST);
|
||||
_downKeys.clear();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void Keyboard::processEvent(const Common::Event &ev) {
|
||||
if (ev.type != Common::EVENT_KEYDOWN && ev.type != Common::EVENT_KEYUP)
|
||||
return;
|
||||
|
||||
if (ev.type == Common::EVENT_KEYDOWN) {
|
||||
_downKeys.set(ev.kbd.keycode);
|
||||
_modifiers = ev.kbd.flags;
|
||||
_pressedKeys.push(ev.kbd);
|
||||
} else {
|
||||
_downKeys.unset(ev.kbd.keycode);
|
||||
}
|
||||
}
|
||||
|
||||
void Keyboard::Update() {
|
||||
_pressedKeys.clear();
|
||||
for (const Common::Event &ev : _lowLevelSystem->_events)
|
||||
processEvent(ev);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool Keyboard::KeyIsDown(Common::KeyCode key) {
|
||||
return _downKeys.get(key);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
Common::KeyState Keyboard::GetKey() {
|
||||
return _pressedKeys.pop();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool Keyboard::KeyIsPressed() {
|
||||
return _pressedKeys.empty() == false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
int Keyboard::GetModifier() {
|
||||
return _modifiers;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tString Keyboard::KeyToString(Common::KeyCode eKey) {
|
||||
HPL1_UNIMPLEMENTED(Keyboard::KeyToString);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
Common::KeyCode Keyboard::StringToKey(tString) {
|
||||
HPL1_UNIMPLEMENTED(Keyboard::StringToKey);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
95
engines/hpl1/engine/input/Keyboard.h
Normal file
95
engines/hpl1/engine/input/Keyboard.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_KEYBOARD_H
|
||||
#define HPL_KEYBOARD_H
|
||||
|
||||
#include "common/bitarray.h"
|
||||
#include "common/keyboard.h"
|
||||
#include "common/queue.h"
|
||||
#include "hpl1/engine/input/InputDevice.h"
|
||||
#include "hpl1/engine/input/InputTypes.h"
|
||||
|
||||
namespace Common {
|
||||
struct Event;
|
||||
}
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class LowLevelInput;
|
||||
|
||||
class Keyboard : public iInputDevice {
|
||||
public:
|
||||
Keyboard(LowLevelInput *);
|
||||
|
||||
/**
|
||||
*
|
||||
* \param aKey The key to check
|
||||
* \return true if pressed else false
|
||||
*/
|
||||
bool KeyIsDown(Common::KeyCode aKey);
|
||||
/**
|
||||
* Can be checked many times to see all key presses
|
||||
* \return key that is currently pressed. eKey_NONE is no key.
|
||||
*/
|
||||
Common::KeyState GetKey();
|
||||
/**
|
||||
*
|
||||
* \return If ANY key is pressed
|
||||
*/
|
||||
bool KeyIsPressed();
|
||||
/**
|
||||
* \return The current modifiers.
|
||||
*/
|
||||
int GetModifier();
|
||||
/**
|
||||
* \todo Implement!
|
||||
* \param eKey The key to change to string.
|
||||
* \return The name of the key as a string.
|
||||
*/
|
||||
tString KeyToString(Common::KeyCode eKey);
|
||||
/**
|
||||
* \todo Implement!
|
||||
* \param tString NAme of the key
|
||||
* \return enum of the key.
|
||||
*/
|
||||
Common::KeyCode StringToKey(tString);
|
||||
|
||||
void Update();
|
||||
|
||||
private:
|
||||
void processEvent(const Common::Event &ev);
|
||||
|
||||
int _modifiers;
|
||||
Common::BitArray _downKeys;
|
||||
Common::Queue<Common::KeyState> _pressedKeys;
|
||||
LowLevelInput *_lowLevelSystem;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_KEYBOARD_H
|
||||
79
engines/hpl1/engine/input/LowLevelInput.cpp
Normal file
79
engines/hpl1/engine/input/LowLevelInput.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "common/events.h"
|
||||
#include "common/system.h"
|
||||
#include "hpl1/engine/input/Keyboard.h"
|
||||
#include "hpl1/engine/input/LowLevelInput.h"
|
||||
#include "hpl1/engine/input/Mouse.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
LowLevelInput::LowLevelInput(iLowLevelGraphics *apLowLevelGraphics) {
|
||||
_lowLevelGraphics = apLowLevelGraphics;
|
||||
LockInput(true);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void LowLevelInput::LockInput(bool abX) {
|
||||
g_system->lockMouse(abX);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void LowLevelInput::BeginInputUpdate() {
|
||||
Common::Event event;
|
||||
while (g_system->getEventManager()->pollEvent(event)) {
|
||||
_events.push_back(event);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void LowLevelInput::EndInputUpdate() {
|
||||
_events.clear();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
Mouse *LowLevelInput::CreateMouse() {
|
||||
return hplNew(Mouse, (this, _lowLevelGraphics));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
Keyboard *LowLevelInput::CreateKeyboard() {
|
||||
return hplNew(Keyboard, (this));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
71
engines/hpl1/engine/input/LowLevelInput.h
Normal file
71
engines/hpl1/engine/input/LowLevelInput.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_LOWLEVELINPUT_H
|
||||
#define HPL_LOWLEVELINPUT_H
|
||||
|
||||
#include "common/array.h"
|
||||
#include "common/events.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class Mouse;
|
||||
class Keyboard;
|
||||
class iLowLevelGraphics;
|
||||
|
||||
class LowLevelInput {
|
||||
friend class Keyboard;
|
||||
friend class Mouse;
|
||||
|
||||
public:
|
||||
LowLevelInput(iLowLevelGraphics *graphics);
|
||||
/**
|
||||
* Lock all input to current window.
|
||||
* \param abX
|
||||
* \return
|
||||
*/
|
||||
void LockInput(bool abX);
|
||||
/**
|
||||
* Called by cInput
|
||||
*/
|
||||
void BeginInputUpdate();
|
||||
/**
|
||||
* called by cInput
|
||||
*/
|
||||
void EndInputUpdate();
|
||||
|
||||
Mouse *CreateMouse();
|
||||
Keyboard *CreateKeyboard();
|
||||
|
||||
private:
|
||||
Common::Array<Common::Event> _events;
|
||||
iLowLevelGraphics *_lowLevelGraphics;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_LOWLEVELINPUT_H
|
||||
146
engines/hpl1/engine/input/Mouse.cpp
Normal file
146
engines/hpl1/engine/input/Mouse.cpp
Normal file
@@ -0,0 +1,146 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "common/bitarray.h"
|
||||
#include "common/events.h"
|
||||
#include "hpl1/engine/graphics/LowLevelGraphics.h"
|
||||
#include "hpl1/engine/input/InputTypes.h"
|
||||
#include "hpl1/engine/input/LowLevelInput.h"
|
||||
#include "hpl1/engine/input/Mouse.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
Mouse::Mouse(LowLevelInput *apLowLevelInputSDL, iLowLevelGraphics *apLowLevelGraphics) : iInputDevice("Mouse", eInputDeviceType_Mouse) {
|
||||
mfMaxPercent = 0.7f;
|
||||
mfMinPercent = 0.1f;
|
||||
mlBufferSize = 6;
|
||||
|
||||
_buttonState.set_size(eMButton_LastEnum);
|
||||
|
||||
_lowLevelInputSDL = apLowLevelInputSDL;
|
||||
_lowLevelGraphics = apLowLevelGraphics;
|
||||
|
||||
_relMousePos = cVector2f(0, 0);
|
||||
_absMousePos = cVector2f(0, 0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
static void setMouseState(const int state, Common::BitArray &states) {
|
||||
if (state != Common::EVENT_WHEELDOWN)
|
||||
states.unset(eMButton_WheelDown);
|
||||
if (state != Common::EVENT_WHEELUP)
|
||||
states.unset(eMButton_WheelUp);
|
||||
|
||||
switch (state) {
|
||||
case Common::EVENT_LBUTTONDOWN:
|
||||
return states.set(eMButton_Left);
|
||||
case Common::EVENT_LBUTTONUP:
|
||||
return states.unset(eMButton_Left);
|
||||
case Common::EVENT_RBUTTONDOWN:
|
||||
return states.set(eMButton_Right);
|
||||
case Common::EVENT_RBUTTONUP:
|
||||
return states.unset(eMButton_Right);
|
||||
case Common::EVENT_MBUTTONDOWN:
|
||||
return states.set(eMButton_Middle);
|
||||
case Common::EVENT_MBUTTONUP:
|
||||
return states.unset(eMButton_Middle);
|
||||
case Common::EVENT_WHEELUP:
|
||||
return states.set(eMButton_WheelUp);
|
||||
case Common::EVENT_WHEELDOWN:
|
||||
return states.set(eMButton_WheelDown);
|
||||
}
|
||||
}
|
||||
|
||||
void Mouse::processEvent(const Common::Event &ev) {
|
||||
if (!Common::isMouseEvent(ev))
|
||||
return;
|
||||
if (ev.type == Common::EVENT_MOUSEMOVE) {
|
||||
_absMousePos = cVector2f(ev.mouse.x, ev.mouse.y);
|
||||
} else {
|
||||
setMouseState(ev.type, _buttonState);
|
||||
}
|
||||
_relMousePos = cVector2f(ev.relMouse.x, ev.relMouse.y);
|
||||
}
|
||||
|
||||
void Mouse::Update() {
|
||||
for (const Common::Event &ev : _lowLevelInputSDL->_events)
|
||||
processEvent(ev);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool Mouse::ButtonIsDown(eMButton mButton) {
|
||||
return _buttonState.get(mButton);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cVector2f Mouse::GetAbsPosition() {
|
||||
cVector2f vPos = _absMousePos;
|
||||
|
||||
return vPos;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cVector2f Mouse::GetRelPosition() {
|
||||
cVector2f vPos = _relMousePos;
|
||||
_relMousePos = cVector2f(0, 0);
|
||||
return vPos;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void Mouse::Reset() {
|
||||
error("call to unimplemented function Mouse::Reset");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void Mouse::SetSmoothProperties(float afMinPercent,
|
||||
float afMaxPercent, unsigned int alBufferSize) {
|
||||
mfMaxPercent = afMaxPercent;
|
||||
mfMinPercent = afMinPercent;
|
||||
mlBufferSize = alBufferSize;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
96
engines/hpl1/engine/input/Mouse.h
Normal file
96
engines/hpl1/engine/input/Mouse.h
Normal file
@@ -0,0 +1,96 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_MOUSE_H
|
||||
#define HPL_MOUSE_H
|
||||
|
||||
#include "common/bitarray.h"
|
||||
#include "hpl1/engine/input/InputDevice.h"
|
||||
#include "hpl1/engine/input/InputTypes.h"
|
||||
#include "hpl1/engine/math/MathTypes.h"
|
||||
|
||||
namespace Common {
|
||||
struct Event;
|
||||
}
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class LowLevelInput;
|
||||
class iLowLevelGraphics;
|
||||
|
||||
class Mouse : public iInputDevice {
|
||||
public:
|
||||
Mouse(LowLevelInput *apLowLevelInputSDL, iLowLevelGraphics *apLowLevelGraphics);
|
||||
~Mouse() {}
|
||||
|
||||
/**
|
||||
* Check if a mouse button is down
|
||||
* \param eMButton the button to check
|
||||
* \return
|
||||
*/
|
||||
bool ButtonIsDown(eMButton);
|
||||
/**
|
||||
* Get the absolute pos of the mouse.
|
||||
* \return
|
||||
*/
|
||||
cVector2f GetAbsPosition();
|
||||
/**
|
||||
* Get the relative movement.
|
||||
* \return
|
||||
*/
|
||||
cVector2f GetRelPosition();
|
||||
|
||||
/**
|
||||
* Reset smoothing and relative movement.
|
||||
*/
|
||||
void Reset();
|
||||
/**
|
||||
* Set parameters for mouse smoothing
|
||||
* \param afMinPercent Influence of the oldest position.
|
||||
* \param afMaxPercent Influence of the latest position.
|
||||
* \param alBufferSize number of saved positions, 1 = no smoothing
|
||||
*/
|
||||
void SetSmoothProperties(float afMinPercent,
|
||||
float afMaxPercent, unsigned int alBufferSize);
|
||||
|
||||
void Update();
|
||||
|
||||
private:
|
||||
void processEvent(const Common::Event &ev);
|
||||
cVector2f _absMousePos;
|
||||
cVector2f _relMousePos;
|
||||
Common::BitArray _buttonState;
|
||||
float mfMaxPercent;
|
||||
float mfMinPercent;
|
||||
int mlBufferSize;
|
||||
LowLevelInput *_lowLevelInputSDL;
|
||||
iLowLevelGraphics *_lowLevelGraphics;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_MOUSE_H
|
||||
Reference in New Issue
Block a user