diff --git a/Core/BaseMouseHandler.cpp b/Core/BaseMouseHandler.cpp index 58dd70fb..24927504 100644 --- a/Core/BaseMouseHandler.cpp +++ b/Core/BaseMouseHandler.cpp @@ -8,9 +8,9 @@ BaseMouseHandler::BaseMouseHandler() ,fDeltaY(0) ,MouseX(0) ,MouseY(0) - , view_width(750) - , view_height(750) - ,mouseButtons(core::NoButton) + ,view_width(750) + ,view_height(750) + ,mouseButtons(core::MouseButtons::NoButton) { } @@ -18,23 +18,23 @@ BaseMouseHandler::~BaseMouseHandler() { } -void BaseMouseHandler::mouseRelease(int button,int x,int y) +void BaseMouseHandler::mouseRelease(MouseButtons button, int x, int y) { - *((int*)&mouseButtons)&=(~button); + mouseButtons&=~button; MouseX=x; MouseY=y; UpdateViews(); } -void BaseMouseHandler::mousePress(int button,int x,int y) +void BaseMouseHandler::mousePress(MouseButtons button, int x, int y) { - *((int*)&mouseButtons)|=button; + mouseButtons|=button; MouseX=x; MouseY=y; UpdateViews(); } -void BaseMouseHandler::mouseDoubleClick(int ,int x,int y) +void BaseMouseHandler::mouseDoubleClick(MouseButtons, int x, int y) { MouseX=x; MouseY=y; @@ -81,17 +81,13 @@ void BaseMouseHandler::SetViewSize(int w, int h) } - -void BaseMouseHandler::KeyboardProc(unsigned int /*nChar*/, bool bKeyDown, bool ) +void BaseMouseHandler::KeyboardProc(KeyboardModifiers modifiers, bool bKeyDown) { - if(bKeyDown) - { - } if(updateViews) UpdateViews(); } -MouseButtons BaseMouseHandler::getMouseButtons() const +MouseButtons BaseMouseHandler::getMouseButtons() const { - return mouseButtons; + return mouseButtons; } \ No newline at end of file diff --git a/Core/BaseMouseHandler.h b/Core/BaseMouseHandler.h index 1d0efdd8..41b21ab1 100644 --- a/Core/BaseMouseHandler.h +++ b/Core/BaseMouseHandler.h @@ -3,6 +3,8 @@ #include #include "Platform/Core/Export.h" +#include "Platform/Core/EnumClassBitwiseOperators.h" + #ifdef _MSC_VER #pragma warning(disable:4251) #endif @@ -10,7 +12,7 @@ namespace platform { namespace core { - enum MouseButtons + enum class MouseButtons : uint16_t { NoButton = 0, LeftButton = 1, @@ -19,13 +21,14 @@ namespace platform Button4 = 8, Button5 = 16, }; - enum class KeyboardModifiers + enum class KeyboardModifiers : uint16_t { NoModifier = 0, Shift = 1, Alt = 2, Ctrl = 4, }; + // A simple render delegate, it will usually be a function partially bound with std::bind. typedef std::function VoidFnDelegate; class PLATFORM_CORE_EXPORT BaseMouseHandler @@ -33,17 +36,20 @@ namespace platform public: BaseMouseHandler(); virtual ~BaseMouseHandler(); - virtual void mousePress(int button, int x, int y); - virtual void mouseRelease(int button, int x, int y); - virtual void mouseDoubleClick(int button, int x, int y); + virtual void mousePress(MouseButtons button, int x, int y); + virtual void mouseRelease(MouseButtons button, int x, int y); + virtual void mouseDoubleClick(MouseButtons button, int x, int y); virtual void mouseMove(int x, int y); virtual void getMousePosition(int &x, int &y) const; virtual void mouseWheel(int delta, int modifiers); - virtual void KeyboardProc(unsigned int nChar, bool bKeyDown, bool bAltDown); - virtual MouseButtons getMouseButtons() const; + virtual void KeyboardProc(KeyboardModifiers modifiers, bool bKeyDown); + virtual MouseButtons getMouseButtons() const; void SetViewSize(int w, int h); + + public: VoidFnDelegate updateViews; VoidFnDelegate valuesChanged; + protected: float fDeltaX, fDeltaY; int MouseX, MouseY; diff --git a/Core/PropertyMacros.h b/Core/PropertyMacros.h index 332ef7d4..bbe80835 100644 --- a/Core/PropertyMacros.h +++ b/Core/PropertyMacros.h @@ -835,6 +835,7 @@ template void META_StaticLimit(T &t) #pragma warning(pop) #endif +#if 0 #define SIMUL_BIT_FLAG(Enum,T) \ inline Enum operator|(const Enum &a, const Enum &b) \ { \ @@ -859,4 +860,8 @@ inline Enum operator~(const Enum &a) \ Enum b = static_cast(~static_cast(a)); \ return b; \ } +#else +#define SIMUL_BIT_FLAG(Enum, T) +#endif +#include "Platform/Core/EnumClassBitwiseOperators.h" diff --git a/Core/Settings.h b/Core/Settings.h index 47ecb9f0..44de8045 100644 --- a/Core/Settings.h +++ b/Core/Settings.h @@ -1,8 +1,12 @@ #pragma once #include "Platform/Core/Export.h" -#include "Platform/Core/SimpleIni.h" #include "Platform/Core/RuntimeError.h" +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#include "Platform/Core/SimpleIni.h" + #ifdef _MSC_VER #pragma warning(disable : 4251) #endif diff --git a/CrossPlatform/MouseHandler.cpp b/CrossPlatform/MouseHandler.cpp index 9de27959..791eba74 100644 --- a/CrossPlatform/MouseHandler.cpp +++ b/CrossPlatform/MouseHandler.cpp @@ -114,17 +114,17 @@ void MouseHandler::getMousePosition(int &x,int &y) const bool MouseHandler::getLeftButton() const { - return (mouseButtons==core::LeftButton); + return (mouseButtons==core::MouseButtons::LeftButton); } bool MouseHandler::getRightButton() const { - return (mouseButtons==core::RightButton); + return (mouseButtons==core::MouseButtons::RightButton); } bool MouseHandler::getMiddleButton() const { - return (mouseButtons==core::MiddleButton); + return (mouseButtons==core::MouseButtons::MiddleButton); } void MouseHandler::mouseWheel(int delta,int modifiers) @@ -212,7 +212,7 @@ void MouseHandler::Update(float time_step) up_down_spd+=cam_spd*introduce; if(move_down) up_down_spd-=cam_spd*introduce; - if((mouseButtons&core::MiddleButton)||mouseButtons==(core::LeftButton|core::RightButton)) + if (mouseButtons == core::MouseButtons::MiddleButton || mouseButtons == (core::MouseButtons::LeftButton | core::MouseButtons::RightButton)) { static float slide_spd=100.f; right_left_spd +=slide_spd*fDeltaX*cam_spd*introduce; @@ -236,7 +236,7 @@ void MouseHandler::Update(float time_step) y_rotate*=retain; z_rotate*=retain; float tilt = y_vertical ? asin(camera->Orientation.Tx().y) : asin(camera->Orientation.Tx().z); - if(mouseButtons==core::RightButton) + if(mouseButtons == core::MouseButtons::RightButton) { if(!alt_down) { @@ -256,7 +256,7 @@ void MouseHandler::Update(float time_step) } } } - if(mouseButtons==core::MiddleButton) + if(mouseButtons == core::MouseButtons::MiddleButton) { //z_rotate-=fDeltaX*introduce; } @@ -344,7 +344,7 @@ void MouseHandler::Update(float time_step) up_down_spd += cam_spd * introduce; if (move_down) up_down_spd -= cam_spd * introduce; - if ((mouseButtons & core::MiddleButton) || mouseButtons == (core::LeftButton | core::RightButton)) + if (mouseButtons == core::MouseButtons::MiddleButton || mouseButtons == (core::MouseButtons::LeftButton | core::MouseButtons::RightButton)) { static float slide_spd = 100.f; right_left_spd += slide_spd * fDeltaX * cam_spd * introduce; @@ -393,7 +393,7 @@ void MouseHandler::Update(float time_step) y_rotate *= retain; z_rotate *= retain; float tilt = y_vertical ? asin(camera->Orientation.Tx().y) : asin(camera->Orientation.Tx().z); - if (mouseButtons == core::RightButton) + if (mouseButtons == core::MouseButtons::RightButton) { if (!alt_down) { @@ -413,7 +413,7 @@ void MouseHandler::Update(float time_step) } } } - if (mouseButtons == core::MiddleButton) + if (mouseButtons == core::MouseButtons::MiddleButton) { // z_rotate-=fDeltaX*introduce; } @@ -465,125 +465,149 @@ void MouseHandler::Update(float time_step) lastTimeStep = time_step; } +void MouseHandler::KeyboardProc(KeyboardModifiers modifiers, bool bKeyDown) +{ + switch (modifiers) + { + case KeyboardModifiers::NoModifier: + break; + case KeyboardModifiers::Shift: + shift_down = bKeyDown; + break; + case KeyboardModifiers::Alt: + alt_down = bKeyDown; + break; + case KeyboardModifiers::Ctrl: + ctrl_down = bKeyDown; + break; + default: + break; + } +} -void MouseHandler::KeyboardProc(unsigned int nChar, bool bKeyDown, bool bAltDown) +void MouseHandler::KeyboardProc(CameraMovements movements, bool bKeyDown) { - if(bKeyDown) + switch (movements) { - if(nChar==0x01000020||nChar==16) - { - shift_down=true; - } - if(nChar==18) - { - alt_down=true; - } - if(nChar==0x01000016||nChar==0x21) - { - move_up=true; - move_down=false; - } - if(nChar==0x01000017||nChar==0x22) - { - move_down=true; - move_up=false; - } - if(nChar=='w'||nChar=='W') - { - move_forward=true; - move_backward=false; - } - if(nChar=='s'||nChar=='S') - { - move_backward=true; - move_forward=false; - } - if(nChar=='a'||nChar=='A') - { - move_left=true; - move_right=false; - } - if(nChar=='d'||nChar=='D') - { - move_right=true; - move_left=false; - } - if (nChar == '5' ) - { - return; - } - if(nChar==37) // arrow left - { - return; - } - if(nChar==39) // arrow right - { - return; - } - if(nChar==38) // arrow up - { - return; - } - if(nChar==40) // arrow down - { - return; - } - if (nChar == 32) // space - { - return; - } + case CameraMovements::None: + { + break; } - else + case CameraMovements::Forward: { - if(nChar==18) + if (bKeyDown) { - alt_down=false; + move_forward = true; + move_backward = false; } - if(nChar==0x01000020||nChar==16) + else { - shift_down=false; + move_forward = false; } - if(nChar==0x01000016||nChar==0x21) + break; + } + case CameraMovements::Backward: + { + if (bKeyDown) { - move_up=false; + move_backward = true; + move_forward = false; } - if(nChar==0x01000017||nChar==0x22) + else { - move_down=false; + move_backward = false; } - if(nChar=='w'||nChar=='W') + break; + } + case CameraMovements::Left: + { + if (bKeyDown) { - move_forward=false; + move_left = true; + move_right = false; } - if(nChar=='s'||nChar=='S') + else { - move_backward=false; + move_left = false; } - if(nChar=='a'||nChar=='A') + break; + } + case CameraMovements::Right: + { + if (bKeyDown) { - move_left=false; + move_right = true; + move_left = false; } - if(nChar=='d'||nChar=='D') + else { - move_right=false; + move_right = false; } - if(nChar==37) // arrow left + break; + } + case CameraMovements::Up: + { + if (bKeyDown) { - step_rotate_x=-1; + move_up = true; + move_down = false; } - if(nChar==39) // arrow right + else { - step_rotate_x=1; + move_up = false; } - if(nChar==38) // arrow up + break; + } + case CameraMovements::Down: + { + if (bKeyDown) { - step_rotate_y=1; + move_down = true; + move_up = false; } - if(nChar==40) // arrow down + else { - step_rotate_y=-1; + move_down = false; } + break; + } + case CameraMovements::StepRotateXPos: + { + if (bKeyDown) + step_rotate_x = 1; + else + step_rotate_x = 0; + + break; } - if(updateViews) + case CameraMovements::StepRotateXNeg: + { + if (bKeyDown) + step_rotate_x = -1; + else + step_rotate_x = 0; + break; + } + case CameraMovements::StepRotateYPos: + { + if (bKeyDown) + step_rotate_y = 1; + else + step_rotate_y = 0; + break; + } + case CameraMovements::StepRotateYNeg: + { + if (bKeyDown) + step_rotate_y = -1; + else + step_rotate_y = 0; + break; + } + default: + break; + } + + if (updateViews) updateViews(); } diff --git a/CrossPlatform/MouseHandler.h b/CrossPlatform/MouseHandler.h index e2da54a2..c3f185a0 100644 --- a/CrossPlatform/MouseHandler.h +++ b/CrossPlatform/MouseHandler.h @@ -29,6 +29,21 @@ namespace platform CARTESIAN = EUCLIDEAN }; + enum class CameraMovements : uint16_t + { + None = 0, + Forward = 1, + Backward = 2, + Left = 4, + Right = 8, + Up = 16, + Down = 32, + StepRotateXPos = 64, + StepRotateXNeg = 128, + StepRotateYPos = 256, + StepRotateYNeg = 1024 + }; + class SIMUL_CROSSPLATFORM_EXPORT MouseHandler : public platform::core::BaseMouseHandler { public: @@ -47,9 +62,10 @@ namespace platform y_vertical = v; } - void mouseMove(int x, int y); - void mouseWheel(int delta, int modifiers); - void KeyboardProc(unsigned int nChar, bool bKeyDown, bool bAltDown); + void mouseMove(int x, int y) override; + void mouseWheel(int delta, int modifiers) override; + void KeyboardProc(core::KeyboardModifiers modifiers, bool bKeyDown) override; + void KeyboardProc(CameraMovements movements, bool bKeyDown); float getFov() const; void setFov(float f); @@ -62,7 +78,7 @@ namespace platform void SetSpeedFactor(float s); float GetSpeedFactor() const; platform::crossplatform::Camera *GetCamera(); - void getMousePosition(int &x, int &y) const; + void getMousePosition(int &x, int &y) const override; bool getLeftButton() const; bool getRightButton() const; bool getMiddleButton() const; @@ -86,7 +102,7 @@ namespace platform bool y_vertical = false; float aspect; platform::crossplatform::Camera *camera; - bool move_forward, move_backward, move_left, move_right, move_up, move_down, shift_down, alt_down; + bool move_forward, move_backward, move_left, move_right, move_up, move_down, shift_down, alt_down, ctrl_down; float up_down_spd; float forward_back_spd; float right_left_spd; @@ -95,7 +111,6 @@ namespace platform int wheel_forward=0; int wheel_backward=0; }; - } } diff --git a/Vulkan/DeviceManager.cpp b/Vulkan/DeviceManager.cpp index 1d28e299..de355691 100644 --- a/Vulkan/DeviceManager.cpp +++ b/Vulkan/DeviceManager.cpp @@ -1,14 +1,12 @@ #ifdef _MSC_VER #include #endif -#include "DeviceManager.h" -#include "Platform/CrossPlatform/Camera.h" +#include "DeviceManager.h" #include "Platform/Vulkan/RenderPlatform.h" #include "Platform/CrossPlatform/DeviceContext.h" -#include "Platform/CrossPlatform/HdrRenderer.h" #include "Platform/Vulkan/DisplaySurface.h" -#include "Platform/Core/Timer.h" + #include // for uintptr_t #include #include