diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index de0db1c..f6281e7 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -159,6 +159,9 @@ DSQ::DSQ(const std::string& fileSystem, const std::string& extraDataDir) assert(!dsq); dsq = this; + mouse.actionToLeft = ACTION_PRIMARY; + mouse.actionToRight = ACTION_SECONDARY; + cutscene_bg = 0; cutscene_text = 0; cutscene_text2 = 0; @@ -3927,7 +3930,11 @@ void DSQ::onUpdate(float dt) os << "invGlobalScale: " << core->invGlobalScale; os << std::endl; os << "globalScale: " << core->globalScale.x << std::endl; - os << "mousePos:(" << core->mouse.position.x << ", " << core->mouse.position.y << ") mouseChange:(" << core->mouse.change.x << ", " << core->mouse.change.y << ")\n"; + os << "mouse[" + << (mouse.buttons.left ? 'L' : '-') + << (mouse.buttons.middle ? 'M' : '-') + << (mouse.buttons.right ? 'R' : '-') + << "]:pos(" << core->mouse.position.x << ", " << core->mouse.position.y << ") change:(" << core->mouse.change.x << ", " << core->mouse.change.y << ")\n"; /*for(size_t i = 0; i < getNumJoysticks(); ++i) if(Joystick *j = getJoystick(i)) { diff --git a/Aquaria/InGameMenu.cpp b/Aquaria/InGameMenu.cpp index 6f1fe6b..671cc13 100644 --- a/Aquaria/InGameMenu.cpp +++ b/Aquaria/InGameMenu.cpp @@ -2993,8 +2993,6 @@ void InGameMenu::onCook() // do animationy stuff. - core->mouse.buttonsEnabled = false; - bool longAnim = true; int cooks = dsq->continuity.getFlag(FLAG_COOKS); @@ -3132,8 +3130,6 @@ void InGameMenu::onCook() if (haveLeftovers) updatePreviewRecipe(); } - - core->mouse.buttonsEnabled = true; } else { diff --git a/BBGE/ActionMapper.h b/BBGE/ActionMapper.h index 652d240..82b846d 100644 --- a/BBGE/ActionMapper.h +++ b/BBGE/ActionMapper.h @@ -78,7 +78,7 @@ protected: { importInput(&a[0], N); } - void importInput(const NamedAction *actions, size_t N);*/ + void importInput(const NamedAction *actions, size_t N);*/ // TODO controllerfixup: remove this everywhere std::vector createdEvents; diff --git a/BBGE/Core.cpp b/BBGE/Core.cpp index ae2e99e..e4a0a2c 100644 --- a/BBGE/Core.cpp +++ b/BBGE/Core.cpp @@ -636,11 +636,10 @@ void Core::onUpdate(float dt) pollEvents(dt); - - ActionMapper::onUpdate(dt); StateManager::onUpdate(dt); + mouse.update(dt); onMouseInput(); globalScale.update(dt); diff --git a/BBGE/Core.h b/BBGE/Core.h index 5847353..3df7e24 100644 --- a/BBGE/Core.h +++ b/BBGE/Core.h @@ -34,6 +34,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "GameKeys.h" #include "InputMapperRaw.h" +#include "VirtualMouse.h" class ParticleEffect; class Joystick; @@ -70,37 +71,6 @@ class Texture; const int baseVirtualWidth = 800; const int baseVirtualHeight = 600; -enum ButtonState { UP = 0, DOWN }; - -struct MouseButtons -{ - MouseButtons () - { - left = UP; - right = UP; - middle = UP; - } - - ButtonState left, right, middle; -}; - -struct Mouse -{ - Mouse() - { - scrollWheelChange = 0; - buttonsEnabled = true; - } - Vector position, lastPosition; - MouseButtons buttons; - MouseButtons pure_buttons; - unsigned rawButtonMask; - Vector change; - bool buttonsEnabled; //KILL - - int scrollWheelChange; -}; - enum FollowCameraLock { FCL_NONE = 0, @@ -325,7 +295,7 @@ public: int fps; bool loopDone; - Mouse mouse; + VirtualMouse mouse; AfterEffectManager *afterEffectManager; diff --git a/BBGE/VirtualMouse.cpp b/BBGE/VirtualMouse.cpp new file mode 100644 index 0000000..f7f63a1 --- /dev/null +++ b/BBGE/VirtualMouse.cpp @@ -0,0 +1,29 @@ +#include "VirtualMouse.h" +#include + +VirtualMouse::VirtualMouse() +: buttons(_buttons), pure_buttons(_pure_buttons) +, actionToLeft(-1), actionToRight(-1) +{ +} + +VirtualMouse::update(float dt) +{ + int x, int y; + Uint32 mousestate = SDL_GetMouseState(&x, &y); + pure_buttons.left = mousestate & SDL_BUTTON_LMASK; + pure_buttons.right = mousestate & SDL_BUTTON_MMASK; + pure_buttons.middle = mousestate & SDL_BUTTON_RMASK; + + buttons = pure_buttons; + + ActionMapper::onUpdate(dt); + + if(actionToLeft >= 0 && isActing(actionToLeft)) + buttons.left = true; + if(actionToRight> 0 && isActing(actionToRight)) + buttons.right = true; + + // TODO: controller to mouse? +} + diff --git a/BBGE/VirtualMouse.h b/BBGE/VirtualMouse.h new file mode 100644 index 0000000..17da701 --- /dev/null +++ b/BBGE/VirtualMouse.h @@ -0,0 +1,34 @@ +#ifndef VIRTUALMOUSE_H +#define VIRTUALMOUSE_H + +#include "ActionMapper.h" + +class VirtualMouse : public ActionMapper +{ + VirtualMouse(); + + struct Buttons + { + bool left, middle, right; + }; + + // externally set to actions that are to be handled as a button press + int actionToLeft, actionToRight; + + // const references to keep the "API" for the rest of the code + // but make sure that nothing can be externally modified + const Buttons &buttons, &pure_buttons; + + Vector position, lastPosition; + Vector change; + + void update(float dt); + + // override + virtual void action(int actionID, int state, int playerID, InputDeviceType device); + +private: + Buttons _buttons, _pure_buttons; +}; + +#endif diff --git a/win/vc90/BBGE.vcproj b/win/vc90/BBGE.vcproj index 39d6ad7..ef52c03 100644 --- a/win/vc90/BBGE.vcproj +++ b/win/vc90/BBGE.vcproj @@ -729,6 +729,14 @@ RelativePath="..\..\BBGE\Vector.h" > + + + +