mirror of
https://github.com/libretro/scummvm.git
synced 2025-03-06 18:27:26 +00:00
HPL1: merge interface and implementation for mouse
This commit is contained in:
parent
572f736f81
commit
578f75f9b9
@ -23,7 +23,6 @@
|
||||
#include "hpl1/engine/impl/LowLevelGraphicsSDL.h"
|
||||
#include "hpl1/engine/impl/LowLevelPhysicsNewton.h"
|
||||
#include "hpl1/engine/impl/LowLevelSoundOpenAL.h"
|
||||
#include "hpl1/engine/impl/MouseSDL.h"
|
||||
#include "hpl1/engine/impl/low_level_graphics_tgl.h"
|
||||
#include "hpl1/engine/input/LowLevelInput.h"
|
||||
#include "hpl1/engine/resources/low_level_resources.h"
|
||||
|
@ -1,190 +0,0 @@
|
||||
/* 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/impl/MouseSDL.h"
|
||||
#include "hpl1/engine/input/InputTypes.h"
|
||||
#include "hpl1/engine/input/LowLevelInput.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMouseSDL::cMouseSDL(LowLevelInput *apLowLevelInputSDL, iLowLevelGraphics *apLowLevelGraphics) : iMouse("SDL Portable 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 cMouseSDL::processEvent(const Common::Event &ev) {
|
||||
if (!Common::isMouseEvent(ev))
|
||||
return;
|
||||
// const cVector2f screenSize = _lowLevelGraphics->GetScreenSize();
|
||||
// const cVector2f virtualSize = _lowLevelGraphics->GetVirtualSize();
|
||||
if (ev.type == Common::EVENT_MOUSEMOVE) {
|
||||
_absMousePos = cVector2f(ev.mouse.x, ev.mouse.y);
|
||||
// mvMouseAbsPos = (mvMouseAbsPos / screenSize) * virtualSize;
|
||||
} else {
|
||||
setMouseState(ev.type, _buttonState);
|
||||
}
|
||||
_relMousePos = cVector2f(ev.relMouse.x, ev.relMouse.y);
|
||||
// mvMouseRelPos = (mvMouseRelPos / screenSize) * virtualSize;
|
||||
}
|
||||
|
||||
void cMouseSDL::Update() {
|
||||
for (const Common::Event &ev : _lowLevelInputSDL->_events)
|
||||
processEvent(ev);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cMouseSDL::ButtonIsDown(eMButton mButton) {
|
||||
return _buttonState.get(mButton);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cVector2f cMouseSDL::GetAbsPosition() {
|
||||
// Do a transform with the screen-size to the the float coordinates.
|
||||
cVector2f vPos = _absMousePos;
|
||||
|
||||
return vPos;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cVector2f cMouseSDL::GetRelPosition() {
|
||||
// Do a transform with the screen-size to the the float coordinates.
|
||||
cVector2f vPos = _relMousePos;
|
||||
// Ok this is?
|
||||
_relMousePos = cVector2f(0, 0);
|
||||
|
||||
return vPos;
|
||||
/*cVector2f vNew;
|
||||
|
||||
if((int)mlstMouseCoord.size() >= mlBufferSize)
|
||||
mlstMouseCoord.erase(mlstMouseCoord.begin());
|
||||
|
||||
mlstMouseCoord.push_back(vPos);
|
||||
|
||||
int lBufferSize = (int) mlstMouseCoord.size();
|
||||
|
||||
cVector2f vSum(0,0);
|
||||
float fPercent = mfMinPercent;
|
||||
float fPercentAdd = (mfMaxPercent - mfMinPercent)/((float)lBufferSize);
|
||||
float fTotalPercent=0;
|
||||
|
||||
tVector2fListIt It = mlstMouseCoord.begin();
|
||||
while(It != mlstMouseCoord.end())
|
||||
{
|
||||
vSum.x +=It->x*fPercent;
|
||||
vSum.y +=It->y*fPercent;
|
||||
fTotalPercent+=fPercent;
|
||||
fPercent+=fPercentAdd;
|
||||
|
||||
It++;
|
||||
}
|
||||
vNew.x = vSum.x/fTotalPercent;
|
||||
vNew.y = vSum.y/fTotalPercent;
|
||||
|
||||
return vNew;*/
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMouseSDL::Reset() {
|
||||
error("call to unimplemented function Mouse::Reset");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMouseSDL::SetSmoothProperties(float afMinPercent,
|
||||
float afMaxPercent, unsigned int alBufferSize) {
|
||||
mfMaxPercent = afMaxPercent;
|
||||
mfMinPercent = afMinPercent;
|
||||
mlBufferSize = alBufferSize;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
@ -1,89 +0,0 @@
|
||||
/* 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_SDL_H
|
||||
#define HPL_MOUSE_SDL_H
|
||||
|
||||
#include "common/bitarray.h"
|
||||
#include "hpl1/engine/input/Mouse.h"
|
||||
|
||||
namespace Common {
|
||||
struct Event;
|
||||
}
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class iLowLevelGraphics;
|
||||
class LowLevelInput;
|
||||
|
||||
class cMouseSDL : public iMouse {
|
||||
public:
|
||||
cMouseSDL(LowLevelInput *apLowLevelInputSDL, iLowLevelGraphics *apLowLevelGraphics);
|
||||
|
||||
bool ButtonIsDown(eMButton);
|
||||
|
||||
void Update();
|
||||
|
||||
/**
|
||||
* \todo Fix so it works and handles screen size
|
||||
* \return
|
||||
*/
|
||||
cVector2f GetAbsPosition();
|
||||
|
||||
/**
|
||||
* \todo Fix so it works and handles screen size
|
||||
* \return
|
||||
*/
|
||||
cVector2f GetRelPosition();
|
||||
|
||||
void Reset();
|
||||
|
||||
/**
|
||||
* Sets how much smoothening there will be in the RelPosition.
|
||||
* The percentages are just ratios, so min/max 1/10 equals 0.1/1
|
||||
* \param afMinPercent The influence of the oldest value
|
||||
* \param afMaxPercent The influence of the newest value
|
||||
* \param alBufferSize The number of values recorded
|
||||
*/
|
||||
void SetSmoothProperties(float afMinPercent,
|
||||
float afMaxPercent, unsigned int alBufferSize);
|
||||
|
||||
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_SDL_H
|
@ -27,9 +27,9 @@
|
||||
|
||||
#include "common/events.h"
|
||||
#include "common/system.h"
|
||||
#include "hpl1/engine/impl/MouseSDL.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 {
|
||||
@ -65,7 +65,7 @@ void LowLevelInput::EndInputUpdate() {
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iMouse *LowLevelInput::CreateMouse() {
|
||||
return hplNew(cMouseSDL, (this, _lowLevelGraphics));
|
||||
return hplNew(iMouse, (this, _lowLevelGraphics));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -39,7 +39,7 @@ class iLowLevelGraphics;
|
||||
|
||||
class LowLevelInput {
|
||||
friend class Keyboard;
|
||||
friend class cMouseSDL;
|
||||
friend class iMouse;
|
||||
|
||||
public:
|
||||
LowLevelInput(iLowLevelGraphics *graphics);
|
||||
|
@ -25,17 +25,122 @@
|
||||
* 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
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iMouse::iMouse(tString asName) : iInputDevice(asName, eInputDeviceType_Mouse) {
|
||||
iMouse::iMouse(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 iMouse::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 iMouse::Update() {
|
||||
for (const Common::Event &ev : _lowLevelInputSDL->_events)
|
||||
processEvent(ev);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool iMouse::ButtonIsDown(eMButton mButton) {
|
||||
return _buttonState.get(mButton);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cVector2f iMouse::GetAbsPosition() {
|
||||
cVector2f vPos = _absMousePos;
|
||||
|
||||
return vPos;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cVector2f iMouse::GetRelPosition() {
|
||||
cVector2f vPos = _relMousePos;
|
||||
_relMousePos = cVector2f(0, 0);
|
||||
return vPos;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iMouse::Reset() {
|
||||
error("call to unimplemented function Mouse::Reset");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iMouse::SetSmoothProperties(float afMinPercent,
|
||||
float afMaxPercent, unsigned int alBufferSize) {
|
||||
mfMaxPercent = afMaxPercent;
|
||||
mfMinPercent = afMinPercent;
|
||||
mlBufferSize = alBufferSize;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
|
@ -28,46 +28,67 @@
|
||||
#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 iMouse : public iInputDevice {
|
||||
public:
|
||||
iMouse(tString asName);
|
||||
virtual ~iMouse() {}
|
||||
iMouse(LowLevelInput *apLowLevelInputSDL, iLowLevelGraphics *apLowLevelGraphics);
|
||||
~iMouse() {}
|
||||
|
||||
/**
|
||||
* Check if a mouse button is down
|
||||
* \param eMButton the button to check
|
||||
* \return
|
||||
*/
|
||||
virtual bool ButtonIsDown(eMButton) = 0;
|
||||
bool ButtonIsDown(eMButton);
|
||||
/**
|
||||
* Get the absolute pos of the mouse.
|
||||
* \return
|
||||
*/
|
||||
virtual cVector2f GetAbsPosition() = 0;
|
||||
cVector2f GetAbsPosition();
|
||||
/**
|
||||
* Get the relative movement.
|
||||
* \return
|
||||
*/
|
||||
virtual cVector2f GetRelPosition() = 0;
|
||||
cVector2f GetRelPosition();
|
||||
|
||||
/**
|
||||
* Reset smoothing and relative movement.
|
||||
*/
|
||||
virtual void Reset() = 0;
|
||||
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
|
||||
*/
|
||||
virtual void SetSmoothProperties(float afMinPercent,
|
||||
float afMaxPercent, unsigned int alBufferSize) = 0;
|
||||
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
|
||||
|
@ -100,7 +100,6 @@ MODULE_OBJS := \
|
||||
engine/impl/MeshLoaderColladaHelpers.o \
|
||||
engine/impl/MeshLoaderColladaLoader.o \
|
||||
engine/impl/MeshLoaderMSH.o \
|
||||
engine/impl/MouseSDL.o \
|
||||
engine/impl/OcclusionQueryOGL.o \
|
||||
engine/impl/OpenALSoundChannel.o \
|
||||
engine/impl/OpenALSoundData.o \
|
||||
|
Loading…
x
Reference in New Issue
Block a user